diff options
author | kurczews <krzysztof.kurczewski@nokia.com> | 2018-02-19 09:05:47 +0100 |
---|---|---|
committer | Patrick Brady <pb071s@att.com> | 2018-02-21 21:10:09 +0000 |
commit | 8ba7c91f8109e7aea319f3e1fcb128319f7beab5 (patch) | |
tree | 295df2690487e6614d017aeead40144b96ed61dd /appc-config/appc-flow-controller/provider/src/test | |
parent | 727219e6e6ed97c78805cae34031857c77563887 (diff) |
Improve coverage flow/controller/node #2
* Extract TransactionHandler util class
* Minor cleanup
Issue-ID: APPC-440
Change-Id: I73d2ced81713daf36523e6b9d7de3bf19c98c9a1
Signed-off-by: kurczews <krzysztof.kurczewski@nokia.com>
Diffstat (limited to 'appc-config/appc-flow-controller/provider/src/test')
2 files changed, 80 insertions, 9 deletions
diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/ResourceUriExtractorTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/ResourceUriExtractorTest.java index d7a853d2e..06f86c56f 100644 --- a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/ResourceUriExtractorTest.java +++ b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/ResourceUriExtractorTest.java @@ -20,18 +20,20 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicContext; public class ResourceUriExtractorTest { private Properties prop; + private SvcLogicContext ctx; @Rule public ExpectedException expectedException = ExpectedException.none(); @Before public void setUp() { - prop = new Properties(); + ctx = mock(SvcLogicContext.class); + prop = mock(Properties.class); } @Test public void should_return_input_url_if_exist() throws Exception { - SvcLogicContext ctx = mock(SvcLogicContext.class); + ctx = mock(SvcLogicContext.class); when(ctx.getAttribute(INPUT_URL)).thenReturn("test resource uri"); String resourceUri = ResourceUriExtractor.extractResourceUri(ctx, prop); @@ -41,8 +43,6 @@ public class ResourceUriExtractorTest { @Test public void should_extract_url_input_if_context_input_provided() throws Exception { - SvcLogicContext ctx = mock(SvcLogicContext.class); - when(ctx.getAttribute(INPUT_URL)).thenReturn(""); when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost"); when(ctx.getAttribute(INPUT_PORT_NUMBER)).thenReturn("8080"); @@ -57,7 +57,6 @@ public class ResourceUriExtractorTest { @Test public void should_extract_url_input_if_request_action_provided() throws Exception { - SvcLogicContext ctx = mock(SvcLogicContext.class); when(ctx.getAttribute(INPUT_URL)).thenReturn(""); when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost"); @@ -66,8 +65,8 @@ public class ResourceUriExtractorTest { when(ctx.getAttribute(INPUT_REQUEST_ACTION)).thenReturn("request-action"); when(ctx.getAttribute(INPUT_REQUEST_ACTION)).thenReturn("request-action"); - prop.put("request-action.context", "ra-context"); - prop.put("request-action.sub-context", "ra-sub-context"); + when(prop.getProperty("request-action.context")).thenReturn("ra-context"); + when(prop.getProperty("request-action.sub-context")).thenReturn("ra-sub-context"); String resourceUri = ResourceUriExtractor.extractResourceUri(ctx, prop); @@ -76,14 +75,13 @@ public class ResourceUriExtractorTest { @Test public void should_throw_exception_if_missing_context() throws Exception { - SvcLogicContext ctx = mock(SvcLogicContext.class); - when(ctx.getAttribute(INPUT_URL)).thenReturn(""); when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost"); when(ctx.getAttribute(INPUT_PORT_NUMBER)).thenReturn("8080"); expectedException.expect(Exception.class); expectedException.expectMessage("Could Not found the context for operation null"); + ResourceUriExtractor.extractResourceUri(ctx, prop); } diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/TransactionHandlerTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/TransactionHandlerTest.java new file mode 100644 index 000000000..5cdb062f4 --- /dev/null +++ b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/TransactionHandlerTest.java @@ -0,0 +1,73 @@ +package org.onap.appc.flow.controller.node; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_REQUEST_ACTION; +import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_REQUEST_ACTION_TYPE; + +import java.util.Properties; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.appc.flow.controller.data.Transaction; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + +public class TransactionHandlerTest { + + private static final String RESOURCE_URI = "some uri"; + + private SvcLogicContext ctx; + private Properties prop; + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @Before + public void setUp() { + ctx = mock(SvcLogicContext.class); + prop = mock(Properties.class); + } + + @Test + public void should_throw_exception_when_input_request_action_type_missing() throws Exception { + + when(ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE)).thenReturn(""); + + expectedException.expect(IllegalArgumentException.class); + expectedException.expectMessage("Don't know REST operation for Action"); + TransactionHandler.buildTransaction(ctx, prop, RESOURCE_URI); + } + + @Test + public void should_throw_exception_when_input_request_action_missing() throws Exception { + + when(ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE)).thenReturn("foo"); + + expectedException.expect(IllegalArgumentException.class); + expectedException.expectMessage("Don't know request-action request-action"); + TransactionHandler.buildTransaction(ctx, prop, "some uri"); + } + + @Test + public void should_return_proper_transaction() throws Exception { + + when(ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE)).thenReturn("input-ra-type"); + when(ctx.getAttribute(INPUT_REQUEST_ACTION)).thenReturn("input-ra"); + + when(prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION).concat(".default-rest-user"))) + .thenReturn("rest-user"); + when(prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION).concat(".default-rest-pass"))) + .thenReturn("rest-pass"); + + Transaction transaction = TransactionHandler.buildTransaction(ctx, prop, "some uri"); + + Assert.assertEquals(INPUT_REQUEST_ACTION, transaction.getAction()); + Assert.assertEquals("input-ra-type", transaction.getExecutionRPC()); + Assert.assertEquals("some uri", transaction.getExecutionEndPoint()); + Assert.assertEquals("rest-user", transaction.getId()); + Assert.assertEquals("rest-pass", transaction.getPswd()); + } + +}
\ No newline at end of file |