diff options
Diffstat (limited to 'vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/OperationHandlerImplTest.java')
-rw-r--r-- | vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/OperationHandlerImplTest.java | 59 |
1 files changed, 12 insertions, 47 deletions
diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/OperationHandlerImplTest.java b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/OperationHandlerImplTest.java index 61bbe1e7030..5735e84f3fe 100644 --- a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/OperationHandlerImplTest.java +++ b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/OperationHandlerImplTest.java @@ -14,7 +14,10 @@ import org.junit.Test; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.net.URI; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; import java.util.concurrent.atomic.AtomicReference; import static org.hamcrest.CoreMatchers.containsString; @@ -30,31 +33,27 @@ public class OperationHandlerImplTest { @Test(expected = IllegalArgumentException.class) public void missingClusterDef() throws RestApiException { List<ClusterDef> clusterDef = new ArrayList<>(); - OperationHandlerImpl.resolveClusterDef(Optional.empty(), clusterDef); + OperationHandlerImpl.resolveClusterRoute(Optional.empty(), clusterDef); } @Test(expected = IllegalArgumentException.class) public void missingClusterDefSpecifiedCluster() throws RestApiException { List<ClusterDef> clusterDef = new ArrayList<>(); - OperationHandlerImpl.resolveClusterDef(Optional.of("cluster"), clusterDef); + OperationHandlerImpl.resolveClusterRoute(Optional.of("cluster"), clusterDef); } @Test(expected = RestApiException.class) public void oneClusterPresentNotMatching() throws RestApiException { List<ClusterDef> clusterDef = new ArrayList<>(); clusterDef.add(new ClusterDef("foo", "configId")); - OperationHandlerImpl.resolveClusterDef(Optional.of("cluster"), clusterDef); - } - - private static String toRoute(ClusterDef clusterDef) { - return OperationHandlerImpl.clusterDefToRoute(clusterDef); + OperationHandlerImpl.resolveClusterRoute(Optional.of("cluster"), clusterDef); } @Test() public void oneClusterMatching() throws RestApiException { List<ClusterDef> clusterDef = new ArrayList<>(); clusterDef.add(new ClusterDef("foo", "configId")); - assertThat(toRoute(OperationHandlerImpl.resolveClusterDef(Optional.of("foo"), clusterDef)), + assertThat(OperationHandlerImpl.resolveClusterRoute(Optional.of("foo"), clusterDef), is("[Storage:cluster=foo;clusterconfigid=configId]")); } @@ -64,18 +63,18 @@ public class OperationHandlerImplTest { clusterDef.add(new ClusterDef("foo2", "configId2")); clusterDef.add(new ClusterDef("foo", "configId")); clusterDef.add(new ClusterDef("foo3", "configId2")); - assertThat(toRoute(OperationHandlerImpl.resolveClusterDef(Optional.of("foo"), clusterDef)), + assertThat(OperationHandlerImpl.resolveClusterRoute(Optional.of("foo"), clusterDef), is("[Storage:cluster=foo;clusterconfigid=configId]")); } @Test() - public void unknown_target_cluster_throws_exception() throws RestApiException, IOException { + public void checkErrorMessage() throws RestApiException, IOException { List<ClusterDef> clusterDef = new ArrayList<>(); clusterDef.add(new ClusterDef("foo2", "configId2")); clusterDef.add(new ClusterDef("foo", "configId")); clusterDef.add(new ClusterDef("foo3", "configId2")); try { - OperationHandlerImpl.resolveClusterDef(Optional.of("wrong"), clusterDef); + OperationHandlerImpl.resolveClusterRoute(Optional.of("wrong"), clusterDef); } catch(RestApiException e) { String errorMsg = renderRestApiExceptionAsString(e); assertThat(errorMsg, is("{\"errors\":[{\"description\":" + @@ -97,12 +96,6 @@ public class OperationHandlerImplTest { AtomicReference<VisitorParameters> assignedParameters = new AtomicReference<>(); VisitorControlHandler.CompletionCode completionCode = VisitorControlHandler.CompletionCode.SUCCESS; int bucketsVisited = 0; - Map<String, String> bucketSpaces = new HashMap<>(); - - OperationHandlerImplFixture() { - bucketSpaces.put("foo", "global"); - bucketSpaces.put("document-type", "default"); - } OperationHandlerImpl createHandler() throws Exception { VisitorSession visitorSession = mock(VisitorSession.class); @@ -122,8 +115,7 @@ public class OperationHandlerImplTest { return visitorSession; }); OperationHandlerImpl.ClusterEnumerator clusterEnumerator = () -> Arrays.asList(new ClusterDef("foo", "configId")); - OperationHandlerImpl.BucketSpaceResolver bucketSpaceResolver = (configId, docType) -> Optional.ofNullable(bucketSpaces.get(docType)); - return new OperationHandlerImpl(documentAccess, clusterEnumerator, bucketSpaceResolver, MetricReceiver.nullImplementation); + return new OperationHandlerImpl(documentAccess, clusterEnumerator, MetricReceiver.nullImplementation); } } @@ -183,33 +175,6 @@ public class OperationHandlerImplTest { } @Test - public void document_type_is_mapped_to_correct_bucket_space() throws Exception { - OperationHandlerImplFixture fixture = new OperationHandlerImplFixture(); - fixture.bucketSpaces.put("document-type", "langbein"); - OperationHandlerImpl handler = fixture.createHandler(); - handler.visit(dummyVisitUri(), "", emptyVisitOptions()); - - VisitorParameters parameters = fixture.assignedParameters.get(); - assertEquals("langbein", parameters.getBucketSpace()); - } - - @Test - public void unknown_bucket_space_mapping_throws_exception() throws Exception { - OperationHandlerImplFixture fixture = new OperationHandlerImplFixture(); - fixture.bucketSpaces.remove("document-type"); - try { - OperationHandlerImpl handler = fixture.createHandler(); - handler.visit(dummyVisitUri(), "", emptyVisitOptions()); - } catch (RestApiException e) { - assertThat(e.getResponse().getStatus(), is(400)); - String errorMsg = renderRestApiExceptionAsString(e); - // FIXME isn't this really more of a case of unknown document type..? - assertThat(errorMsg, is("{\"errors\":[{\"description\":" + - "\"UNKNOWN_BUCKET_SPACE Document type 'document-type' in cluster 'foo' is not mapped to a known bucket space\",\"id\":-9}]}")); - } - } - - @Test public void provided_wanted_document_count_is_propagated_to_visitor_parameters() throws Exception { VisitorParameters params = generatedParametersFromVisitOptions(visitOptionsWithWantedDocumentCount(123)); assertThat(params.getMaxTotalHits(), is((long)123)); |