diff options
author | 2019-07-12 15:49:30 +0000 | |
---|---|---|
committer | 2019-07-12 15:49:30 +0000 | |
commit | 9e4e4474ee079176b26ed0af7105a4b23540d585 (patch) | |
tree | 80d7ad4b1172447a7703af4f27fd2b7ed5293548 /plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java | |
parent | 8916bd3e643daeba1b09f6b04f831ac92962537d (diff) |
add status filter in restclient and restrequestor
Issue-ID: POLICY-1742
Change-Id: Ib4984b18c0353cddb12c13c352277728be691bf5
Signed-off-by: Henry.Sun <henry.a.sun@est.tech>
Diffstat (limited to 'plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java')
3 files changed, 81 insertions, 81 deletions
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumerTest.java index ac1af67dd..07818d068 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumerTest.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumerTest.java @@ -25,23 +25,23 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; +import java.util.Properties; + import org.junit.Test; import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; import org.onap.policy.apex.service.engine.event.ApexEventException; import org.onap.policy.apex.service.engine.event.ApexEventReceiver; -import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException; import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters; import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode; -import java.util.Properties; - /** * Test the ApexRestRequestorConsumer class. * */ public class ApexRestRequestorConsumerTest { + @Test - public void testApexRestRequestorConsumerSetup() { + public void testApexRestRequestorConsumerSetup() throws ApexEventException { ApexRestRequestorConsumer consumer = new ApexRestRequestorConsumer(); assertNotNull(consumer); @@ -88,13 +88,10 @@ public class ApexRestRequestorConsumerTest { rrctp.setHttpMethod(RestRequestorCarrierTechnologyParameters.HttpMethod.GET); rrctp.setUrl("http://www.onap.org"); + rrctp.setHttpCodeFilter("[1-5][0][0-5]"); consumerParameters.setPeerTimeout(EventHandlerPeeredMode.REQUESTOR, 0); - try { - consumer.init(consumerName, consumerParameters, incomingEventReceiver); - } catch (ApexEventException aee) { - fail("test should not throw an exception"); - } + consumer.init(consumerName, consumerParameters, incomingEventReceiver); try { consumer.processRestRequest(null); @@ -110,7 +107,7 @@ public class ApexRestRequestorConsumerTest { } @Test - public void testApexRestRequestorConsumerRequest() { + public void testApexRestRequestorConsumerRequest() throws ApexEventException { ApexRestRequestorConsumer consumer = new ApexRestRequestorConsumer(); assertNotNull(consumer); @@ -123,24 +120,21 @@ public class ApexRestRequestorConsumerTest { consumerParameters.setPeeredMode(EventHandlerPeeredMode.REQUESTOR, true); rrctp.setHttpMethod(RestRequestorCarrierTechnologyParameters.HttpMethod.GET); rrctp.setUrl("http://www.onap.org"); + rrctp.setHttpCodeFilter("[1-5][0][0-5]"); consumerParameters.setPeerTimeout(EventHandlerPeeredMode.REQUESTOR, 0); // Test should time out requests - try { - consumer.init(consumerName, consumerParameters, incomingEventReceiver); - consumer.start(); - ApexRestRequest request = new ApexRestRequest(123, null,"EventName", "Event body"); - consumer.processRestRequest(request); - ThreadUtilities.sleep(2000); - consumer.stop(); - assertEquals(0, consumer.getEventsReceived()); - } catch (ApexEventException aee) { - fail("test should not throw an exception"); - } + consumer.init(consumerName, consumerParameters, incomingEventReceiver); + consumer.start(); + ApexRestRequest request = new ApexRestRequest(123, null, "EventName", "Event body"); + consumer.processRestRequest(request); + ThreadUtilities.sleep(200); + consumer.stop(); + assertEquals(0, consumer.getEventsReceived()); } @Test - public void testApexRestRequestorConsumerUrlUpdate() { + public void testApexRestRequestorConsumerUrlUpdate() throws ApexEventException { ApexRestRequestorConsumer consumer = new ApexRestRequestorConsumer(); assertNotNull(consumer); @@ -158,21 +152,18 @@ public class ApexRestRequestorConsumerTest { Properties properties = new Properties(); properties.put("site", "onap"); properties.put("net", "org"); - try { - consumer.init(consumerName, consumerParameters, incomingEventReceiver); - consumer.start(); - ApexRestRequest request = new ApexRestRequest(123, properties,"EventName", "Event body"); - consumer.processRestRequest(request); - ThreadUtilities.sleep(2000); - consumer.stop(); - assertEquals(0, consumer.getEventsReceived()); - } catch (Exception aee) { - fail("test should not throw an exception"); - } + + consumer.init(consumerName, consumerParameters, incomingEventReceiver); + consumer.start(); + ApexRestRequest request = new ApexRestRequest(123, properties,"EventName", "Event body"); + consumer.processRestRequest(request); + ThreadUtilities.sleep(2000); + consumer.stop(); + assertEquals(0, consumer.getEventsReceived()); } @Test - public void testApexRestRequestorConsumerUrlUpdateError() { + public void testApexRestRequestorConsumerUrlUpdateError() throws ApexEventException { ApexRestRequestorConsumer consumer = new ApexRestRequestorConsumer(); assertNotNull(consumer); @@ -189,16 +180,13 @@ public class ApexRestRequestorConsumerTest { consumerParameters.setPeerTimeout(EventHandlerPeeredMode.REQUESTOR, 2000); Properties properties = new Properties(); properties.put("site", "onap"); - try { - consumer.init(consumerName, consumerParameters, incomingEventReceiver); - consumer.start(); - ApexRestRequest request = new ApexRestRequest(123, properties,"EventName", "Event body"); - consumer.processRestRequest(request); - ThreadUtilities.sleep(2000); - consumer.stop(); - assertEquals(0, consumer.getEventsReceived()); - } catch (Exception aee) { - fail("test should not throw an exception"); - } + + consumer.init(consumerName, consumerParameters, incomingEventReceiver); + consumer.start(); + ApexRestRequest request = new ApexRestRequest(123, properties,"EventName", "Event body"); + consumer.processRestRequest(request); + ThreadUtilities.sleep(2000); + consumer.stop(); + assertEquals(0, consumer.getEventsReceived()); } } diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorProducerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorProducerTest.java index 5222f5bdb..af0074794 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorProducerTest.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorProducerTest.java @@ -39,7 +39,7 @@ import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMo public class ApexRestRequestorProducerTest { @Test - public void testApexRestRequestorProducerMethods() { + public void testApexRestRequestorProducerMethods() throws ApexEventException { ApexRestRequestorProducer producer = new ApexRestRequestorProducer(); assertNotNull(producer); @@ -83,12 +83,8 @@ public class ApexRestRequestorProducerTest { } rrctp.setHttpMethod(null); - try { - producer.init(producerName, producerParameters); - producer.stop(); - } catch (ApexEventException aee) { - fail("test should not throw an exception here"); - } + producer.init(producerName, producerParameters); + producer.stop(); assertEquals("ProducerName", producer.getName()); assertEquals(0, producer.getEventsSent()); @@ -96,7 +92,7 @@ public class ApexRestRequestorProducerTest { } @Test - public void testApexRestRequestorProducerRequest() { + public void testApexRestRequestorProducerRequest() throws ApexEventException { ApexRestRequestorProducer producer = new ApexRestRequestorProducer(); String producerName = "ProducerName"; @@ -108,12 +104,8 @@ public class ApexRestRequestorProducerTest { rrctp.setUrl(null); rrctp.setHttpMethod(null); - try { - producer.init(producerName, producerParameters); - producer.stop(); - } catch (ApexEventException aee) { - fail("test should not throw an exception here"); - } + producer.init(producerName, producerParameters); + producer.stop(); String eventName = "EventName"; String event = "This is the event"; diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorCarrierTechnologyParametersTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorCarrierTechnologyParametersTest.java index 68c6811b4..3044907fb 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorCarrierTechnologyParametersTest.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorCarrierTechnologyParametersTest.java @@ -87,26 +87,40 @@ public class RestRequestorCarrierTechnologyParametersTest { } @Test - public void testRestRequestorCarrierTechnologyParametersOk() { + public void testRestRequestorCarrierTechnologyParametersOk() throws ParameterException { ApexCommandLineArguments arguments = new ApexCommandLineArguments(); arguments.setConfigurationFilePath("src/test/resources/prodcons/RESTRequestorWithHTTPHeaderOK.json"); arguments.setRelativeFileRoot("."); + ApexParameters parameters = new ApexParameterHandler().getParameters(arguments); + + RestRequestorCarrierTechnologyParameters rrctp0 = (RestRequestorCarrierTechnologyParameters) parameters + .getEventInputParameters().get("RestRequestorConsumer0").getCarrierTechnologyParameters(); + assertEquals(0, rrctp0.getHttpHeaders().length); + + RestRequestorCarrierTechnologyParameters rrctp1 = (RestRequestorCarrierTechnologyParameters) parameters + .getEventInputParameters().get("RestRequestorConsumer1").getCarrierTechnologyParameters(); + assertEquals(3, rrctp1.getHttpHeaders().length); + assertEquals("bbb", rrctp1.getHttpHeadersAsMultivaluedMap().get("aaa").get(0)); + assertEquals("ddd", rrctp1.getHttpHeadersAsMultivaluedMap().get("ccc").get(0)); + assertEquals("fff", rrctp1.getHttpHeadersAsMultivaluedMap().get("eee").get(0)); + } + + @Test + public void testRestClientCarrierTechnologyParameterFilterInvalid() { + ApexCommandLineArguments arguments = new ApexCommandLineArguments(); + arguments.setConfigurationFilePath("src/test/resources/prodcons/RESTClientWithHTTPFilterInvalid.json"); + arguments.setRelativeFileRoot("."); + try { + new ApexParameterHandler().getParameters(arguments); ApexParameters parameters = new ApexParameterHandler().getParameters(arguments); RestRequestorCarrierTechnologyParameters rrctp0 = (RestRequestorCarrierTechnologyParameters) parameters - .getEventInputParameters().get("RestRequestorConsumer0").getCarrierTechnologyParameters(); - assertEquals(0, rrctp0.getHttpHeaders().length); - - RestRequestorCarrierTechnologyParameters rrctp1 = (RestRequestorCarrierTechnologyParameters) parameters - .getEventInputParameters().get("RestRequestorConsumer1").getCarrierTechnologyParameters(); - assertEquals(3, rrctp1.getHttpHeaders().length); - assertEquals("bbb", rrctp1.getHttpHeadersAsMultivaluedMap().get("aaa").get(0)); - assertEquals("ddd", rrctp1.getHttpHeadersAsMultivaluedMap().get("ccc").get(0)); - assertEquals("fff", rrctp1.getHttpHeadersAsMultivaluedMap().get("eee").get(0)); + .getEventInputParameters().get("RestRequestorConsumer0").getCarrierTechnologyParameters(); + fail("test should throw an exception here"); } catch (ParameterException pe) { - fail("test should not throw an exception"); + assertTrue(pe.getMessage().contains("Invalid HTTP code filter, the filter must be specified as a three digit regular expression: ")); } } @@ -114,9 +128,15 @@ public class RestRequestorCarrierTechnologyParametersTest { public void testGettersAndSetters() { RestRequestorCarrierTechnologyParameters rrctp = new RestRequestorCarrierTechnologyParameters(); + rrctp.setHttpHeaders(null); + assertEquals(null,rrctp.getHttpHeadersAsMultivaluedMap()); + rrctp.setUrl("http://some.where"); assertEquals("http://some.where", rrctp.getUrl()); + rrctp.setHttpCodeFilter("[1-5][0][0-5]"); + assertEquals("[1-5][0][0-5]",rrctp.getHttpCodeFilter()); + String[][] httpHeaders = new String[2][2]; httpHeaders[0][0] = "aaa"; httpHeaders[0][1] = "bbb"; @@ -143,8 +163,8 @@ public class RestRequestorCarrierTechnologyParametersTest { assertEquals(RestRequestorCarrierTechnologyParameters.HttpMethod.DELETE, rrctp.getHttpMethod()); assertEquals("RESTRequestorCarrierTechnologyParameters " - + "[url=http://some.where, httpMethod=DELETE, httpHeaders=[[aaa, bbb], [ccc, ddd]]]", - rrctp.toString()); + + "[url=http://some.where, httpMethod=DELETE, httpHeaders=[[aaa, bbb], [ccc, ddd]]," + + " httpCodeFilter=[1-5][0][0-5]]", rrctp.toString()); } @Test @@ -167,10 +187,10 @@ public class RestRequestorCarrierTechnologyParametersTest { assertEquals("ccc", rrctp.getHttpHeaders()[1][0]); assertEquals("ddd", rrctp.getHttpHeaders()[1][1]); - assertEquals(true, rrctp.validateTagInUrl()); + assertEquals(true, rrctp.validate().isValid()); rrctp.setUrl("http://{place}.{that}/is{that}.{one}"); - assertEquals(true, rrctp.validateTagInUrl()); + assertEquals(true, rrctp.validate().isValid()); Set<String> keymap = rrctp.getKeysFromUrl(); assertEquals(true, keymap.contains("place")); @@ -178,19 +198,19 @@ public class RestRequestorCarrierTechnologyParametersTest { assertEquals(true, keymap.contains("one")); rrctp.setUrl("http://{place.{that}/{is}.{not}/{what}.{exist}"); - assertEquals(false, rrctp.validateTagInUrl()); + assertEquals(false, rrctp.validate().isValid()); rrctp.setUrl("http://{place}.{that}/{is}.{not}/{what}.{exist"); - assertEquals(false, rrctp.validateTagInUrl()); + assertEquals(false, rrctp.validate().isValid()); rrctp.setUrl("http://place.that/is.not/what.{exist"); - assertEquals(false, rrctp.validateTagInUrl()); + assertEquals(false, rrctp.validate().isValid()); rrctp.setUrl("http://place}.{that}/{is}.{not}/{what}.{exist}"); - assertEquals(false, rrctp.validateTagInUrl()); + assertEquals(false, rrctp.validate().isValid()); rrctp.setUrl("http://{place}.{that}/is}.{not}/{what}.{exist}"); - assertEquals(false, rrctp.validateTagInUrl()); + assertEquals(false, rrctp.validate().isValid()); rrctp.setUrl("http://{place}.{that}/{}.{not}/{what}.{exist}"); - assertEquals(false, rrctp.validateTagInUrl()); + assertEquals(false, rrctp.validate().isValid()); rrctp.setUrl("http://{place}.{that}/{ }.{not}/{what}.{exist}"); - assertEquals(false, rrctp.validateTagInUrl()); + assertEquals(false, rrctp.validate().isValid()); } } |