diff options
Diffstat (limited to 'vespaclient-java/src/test/java/com/yahoo/vespaget/DocumentRetrieverTest.java')
-rw-r--r-- | vespaclient-java/src/test/java/com/yahoo/vespaget/DocumentRetrieverTest.java | 82 |
1 files changed, 39 insertions, 43 deletions
diff --git a/vespaclient-java/src/test/java/com/yahoo/vespaget/DocumentRetrieverTest.java b/vespaclient-java/src/test/java/com/yahoo/vespaget/DocumentRetrieverTest.java index ce555e2c0f5..24e303d6fce 100644 --- a/vespaclient-java/src/test/java/com/yahoo/vespaget/DocumentRetrieverTest.java +++ b/vespaclient-java/src/test/java/com/yahoo/vespaget/DocumentRetrieverTest.java @@ -15,11 +15,9 @@ import com.yahoo.messagebus.Error; import com.yahoo.messagebus.Reply; import com.yahoo.vespaclient.ClusterDef; import com.yahoo.vespaclient.ClusterList; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatcher; import java.io.ByteArrayOutputStream; @@ -31,8 +29,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.mock; @@ -60,11 +57,7 @@ public class DocumentRetrieverTest { private PrintStream oldOut; private PrintStream oldErr; - @SuppressWarnings("deprecation") - @Rule - public final ExpectedException exception = ExpectedException.none(); - - @Before + @BeforeEach public void setUpStreams() { oldOut = System.out; oldErr = System.err; @@ -72,7 +65,7 @@ public class DocumentRetrieverTest { System.setErr(new PrintStream(errContent)); } - @Before + @BeforeEach public void prepareMessageBusMocks() { this.mockedFactory = mock(DocumentAccessFactory.class); this.mockedDocumentAccess = mock(MessageBusDocumentAccess.class); @@ -81,7 +74,7 @@ public class DocumentRetrieverTest { when(mockedDocumentAccess.createSyncSession(any())).thenReturn(mockedSession); } - @After + @AfterEach public void cleanUpStreams() { System.setOut(oldOut); System.setErr(oldErr); @@ -129,9 +122,10 @@ public class DocumentRetrieverTest { params); } + // TODO: Remove on Vespa 9 @Test - @SuppressWarnings("removal") // TODO: Remove on Vespa 9 - public void testSendSingleMessage() throws DocumentRetrieverException { + @SuppressWarnings("removal") + void testSendSingleMessage() throws DocumentRetrieverException { ClientParameters params = createParameters() .setDocumentIds(asIterator(DOC_ID_1)) .setPriority(DocumentProtocol.Priority.HIGH_1) @@ -148,12 +142,12 @@ public class DocumentRetrieverTest { verify(mockedSession, times(1)).syncSend(argThat((ArgumentMatcher<GetDocumentMessage>) o -> o.getPriority().equals(DocumentProtocol.Priority.HIGH_1) && // TODO remove on Vespa 9 - !o.getRetryEnabled())); + !o.getRetryEnabled())); assertContainsDocument(DOC_ID_1); } @Test - public void testMultipleMessages() throws DocumentRetrieverException { + void testMultipleMessages() throws DocumentRetrieverException { ClientParameters params = createParameters() .setDocumentIds(asIterator(DOC_ID_1, DOC_ID_2, DOC_ID_3)) .build(); @@ -173,7 +167,7 @@ public class DocumentRetrieverTest { } @Test - public void testJsonOutput() throws DocumentRetrieverException, IOException { + void testJsonOutput() throws DocumentRetrieverException, IOException { ClientParameters params = createParameters() .setDocumentIds(asIterator(DOC_ID_1, DOC_ID_2, DOC_ID_3)) .setJsonOutput(true) @@ -197,7 +191,7 @@ public class DocumentRetrieverTest { } @Test - public void testShutdownHook() throws DocumentRetrieverException { + void testShutdownHook() throws DocumentRetrieverException { ClientParameters params = createParameters() .setDocumentIds(asIterator(DOC_ID_1)) .build(); @@ -213,7 +207,7 @@ public class DocumentRetrieverTest { } @Test - public void testClusterLookup() throws DocumentRetrieverException { + void testClusterLookup() throws DocumentRetrieverException { final String cluster = "storage", expectedRoute = "[Content:cluster=storage]"; @@ -230,35 +224,37 @@ public class DocumentRetrieverTest { } @Test - public void testInvalidClusterName() throws DocumentRetrieverException { - exception.expect(DocumentRetrieverException.class); - exception.expectMessage("The Vespa cluster contains the content clusters storage, not invalidclustername. Please select a valid vespa cluster."); + void testInvalidClusterName() throws DocumentRetrieverException { + Throwable exception = assertThrows(DocumentRetrieverException.class, () -> { - ClientParameters params = createParameters() - .setCluster("invalidclustername") - .build(); + ClientParameters params = createParameters() + .setCluster("invalidclustername") + .build(); - ClusterList clusterList = new ClusterList(Collections.singletonList(new ClusterDef("storage"))); + ClusterList clusterList = new ClusterList(Collections.singletonList(new ClusterDef("storage"))); - DocumentRetriever documentRetriever = createDocumentRetriever(params, clusterList); - documentRetriever.retrieveDocuments(); + DocumentRetriever documentRetriever = createDocumentRetriever(params, clusterList); + documentRetriever.retrieveDocuments(); + }); + assertTrue(exception.getMessage().contains("The Vespa cluster contains the content clusters storage, not invalidclustername. Please select a valid vespa cluster.")); } @Test - public void testEmtpyClusterList() throws DocumentRetrieverException { - exception.expect(DocumentRetrieverException.class); - exception.expectMessage("The Vespa cluster does not have any content clusters declared."); + void testEmtpyClusterList() throws DocumentRetrieverException { + Throwable exception = assertThrows(DocumentRetrieverException.class, () -> { - ClientParameters params = createParameters() - .setCluster("invalidclustername") - .build(); + ClientParameters params = createParameters() + .setCluster("invalidclustername") + .build(); - DocumentRetriever documentRetriever = createDocumentRetriever(params); - documentRetriever.retrieveDocuments(); + DocumentRetriever documentRetriever = createDocumentRetriever(params); + documentRetriever.retrieveDocuments(); + }); + assertTrue(exception.getMessage().contains("The Vespa cluster does not have any content clusters declared.")); } @Test - public void testHandlingErrorFromMessageBus() throws DocumentRetrieverException { + void testHandlingErrorFromMessageBus() throws DocumentRetrieverException { ClientParameters params = createParameters() .setDocumentIds(asIterator(DOC_ID_1)) .build(); @@ -274,7 +270,7 @@ public class DocumentRetrieverTest { } @Test - public void testShowDocSize() throws DocumentRetrieverException { + void testShowDocSize() throws DocumentRetrieverException { ClientParameters params = createParameters() .setDocumentIds(asIterator(DOC_ID_1)) .setShowDocSize(true) @@ -290,7 +286,7 @@ public class DocumentRetrieverTest { } @Test - public void testPrintIdOnly() throws DocumentRetrieverException { + void testPrintIdOnly() throws DocumentRetrieverException { ClientParameters params = createParameters() .setDocumentIds(asIterator(DOC_ID_1)) .setPrintIdsOnly(true) @@ -305,7 +301,7 @@ public class DocumentRetrieverTest { } @Test - public void testDocumentNotFound() throws DocumentRetrieverException { + void testDocumentNotFound() throws DocumentRetrieverException { ClientParameters params = createParameters() .setDocumentIds(asIterator(DOC_ID_1)) .setPrintIdsOnly(true) @@ -321,7 +317,7 @@ public class DocumentRetrieverTest { } @Test - public void testTrace() throws DocumentRetrieverException { + void testTrace() throws DocumentRetrieverException { final int traceLevel = 9; ClientParameters params = createParameters() .setDocumentIds(asIterator(DOC_ID_1)) |