From f86d08ca5598571410386372f3f06d5c8c686c74 Mon Sep 17 00:00:00 2001 From: "a.sreekumar" Date: Tue, 9 Feb 2021 18:21:49 +0000 Subject: Changes related to multi policy handling improvement in APEX This review fixes an issue identified during testing the changes done for improving multiple policy handling in APEX. Changes done to a few test files in the previous review are reverted as well. Change-Id: I98324da708239d314aadd4c45dc377137fd552ba Issue-ID: POLICY-2883 Signed-off-by: a.sreekumar --- .../carrier/restrequestor/RestRequestorTest.java | 49 +++++++++++++--------- 1 file changed, 30 insertions(+), 19 deletions(-) (limited to 'plugins/plugins-event/plugins-event-carrier') diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java index 013046444..40e900413 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java @@ -22,10 +22,9 @@ package org.onap.policy.apex.plugins.event.carrier.restrequestor; -import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; import com.google.gson.Gson; import java.io.ByteArrayOutputStream; @@ -36,6 +35,7 @@ import java.util.concurrent.TimeUnit; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.core.Response; +import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; @@ -94,11 +94,22 @@ public class RestRequestorTest { } /** - * Reset counters. + * Before test. */ @Before - public void resetCounters() { + public void beforeTest() { SupportRestRequestorEndpoint.resetCounters(); + System.setOut(new PrintStream(outContent)); + System.setErr(new PrintStream(errContent)); + } + + /** + * After test. + */ + @After + public void afterTest() { + System.setOut(stdout); + System.setErr(stderr); } /** @@ -269,14 +280,23 @@ public class RestRequestorTest { /** * Test REST requestor producer alone. + * + * @throws MessagingException the messaging exception + * @throws ApexException the apex exception + * @throws IOException Signals that an I/O exception has occurred. */ @Test - public void testRestRequestorProducerAlone() { + public void testRestRequestorProducerAlone() throws MessagingException, ApexException, IOException { + final String[] args = {"src/test/resources/prodcons/File2RESTRequest2FileGetProducerAlone.json"}; - assertThatThrownBy(() -> new ApexMain(args)) - .hasRootCauseMessage("REST Requestor producer (RestRequestorProducer) " - + "must run in peered requestor mode with a REST Requestor consumer"); + ApexMain apexMain = new ApexMain(args); + apexMain.shutdown(); + + final String outString = outContent.toString(); + + assertThat(outString).contains("REST Requestor producer (RestRequestorProducer) " + + "must run in peered requestor mode with a REST Requestor consumer"); } /** @@ -288,21 +308,12 @@ public class RestRequestorTest { */ @Test public void testRestRequestorConsumerAlone() throws MessagingException, ApexException, IOException { - System.setOut(new PrintStream(outContent)); - System.setErr(new PrintStream(errContent)); - final String[] args = {"src/test/resources/prodcons/File2RESTRequest2FileGetConsumerAlone.json"}; - ApexMain apexMain = new ApexMain(args); apexMain.shutdown(); - final String outString = outContent.toString(); - - System.setOut(stdout); - System.setErr(stderr); - - assertTrue(outString.contains("peer \"RestRequestorProducer for peered mode REQUESTOR " - + "does not exist or is not defined with the same peered mode")); + assertThat(outString).contains("peer \"RestRequestorProducer for peered mode REQUESTOR " + + "does not exist or is not defined with the same peered mode"); } private double getStatsFromServer(final Client client, final String statToGet) { -- cgit 1.2.3-korg