summaryrefslogtreecommitdiffstats
path: root/appc-config/appc-flow-controller/provider/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'appc-config/appc-flow-controller/provider/src/test/java')
-rw-r--r--appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/ResourceUriExtractorTest.java117
-rw-r--r--appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/TestRestServiceNode.java277
2 files changed, 193 insertions, 201 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 e3f108e4a..34227587a 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
@@ -3,12 +3,14 @@
* ONAP : APPC
* ================================================================================
* Copyright (C) 2018 Nokia. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -23,11 +25,13 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_CONTEXT;
import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_HOST_IP_ADDRESS;
-import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_PORT_NUMBER;
import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_REQUEST_ACTION;
import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_SUB_CONTEXT;
import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_URL;
-
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.REST_CONTEXT_URL;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.REST_PORT;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.REST_PROTOCOL;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNF_TYPE;
import java.util.Properties;
import org.junit.Assert;
import org.junit.Before;
@@ -38,73 +42,74 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
public class ResourceUriExtractorTest {
- private Properties prop;
- private SvcLogicContext ctx;
-
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
- private ResourceUriExtractor resourceUriExtractor;
-
- @Before
- public void setUp() {
- ctx = mock(SvcLogicContext.class);
- prop = mock(Properties.class);
- resourceUriExtractor = new ResourceUriExtractor();
- }
+ private Properties prop;
+ private SvcLogicContext ctx;
- @Test
- public void should_return_input_url_if_exist() throws Exception {
- ctx = mock(SvcLogicContext.class);
- when(ctx.getAttribute(INPUT_URL)).thenReturn("http://localhost:8080");
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+ private ResourceUriExtractor resourceUriExtractor;
- resourceUriExtractor = new ResourceUriExtractor();
- String resourceUri = resourceUriExtractor.extractResourceUri(ctx, prop);
+ @Before
+ public void setUp() {
+ ctx = mock(SvcLogicContext.class);
+ prop = mock(Properties.class);
+ resourceUriExtractor = new ResourceUriExtractor();
+ }
- Assert.assertEquals("http://localhost:8080", resourceUri);
- }
+ @Test
+ public void should_return_input_url_if_exist() throws Exception {
+ ctx = mock(SvcLogicContext.class);
+ when(ctx.getAttribute(INPUT_URL)).thenReturn("http://localhost:8080");
- @Test
- public void should_extract_url_input_if_context_input_provided() throws Exception {
- when(ctx.getAttribute(INPUT_URL)).thenReturn("");
- when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost");
- when(ctx.getAttribute(INPUT_PORT_NUMBER)).thenReturn("8080");
+ resourceUriExtractor = new ResourceUriExtractor();
+ String resourceUri = resourceUriExtractor.extractResourceUri(ctx, prop);
- when(ctx.getAttribute(INPUT_CONTEXT)).thenReturn("input-context");
- when(ctx.getAttribute(INPUT_SUB_CONTEXT)).thenReturn("input-sub-context");
+ Assert.assertEquals("http://localhost:8080", resourceUri);
+ }
- String resourceUri = resourceUriExtractor.extractResourceUri(ctx, prop);
+ @Test
+ public void should_extract_url_input_if_context_input_provided() throws Exception {
+ when(ctx.getAttribute(INPUT_URL)).thenReturn("");
+ when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost");
+ when(prop.getProperty(ctx.getAttribute(VNF_TYPE) + "." + (REST_PROTOCOL) + "."
+ + ctx.getAttribute(INPUT_REQUEST_ACTION) + "." + (REST_PORT))).thenReturn("8080");
- Assert.assertEquals("http://localhost:8080/input-context/input-sub-context", resourceUri);
- }
+ when(ctx.getAttribute(INPUT_CONTEXT)).thenReturn("input-context");
+ when(ctx.getAttribute(INPUT_SUB_CONTEXT)).thenReturn("input-sub-context");
- @Test
- public void should_extract_url_input_if_request_action_provided() throws Exception {
+ String resourceUri = resourceUriExtractor.extractResourceUri(ctx, prop);
- when(ctx.getAttribute(INPUT_URL)).thenReturn("");
- when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost");
- when(ctx.getAttribute(INPUT_PORT_NUMBER)).thenReturn("8080");
+ Assert.assertEquals("http://localhost:8080/input-context/input-sub-context", resourceUri);
+ }
- when(ctx.getAttribute(INPUT_REQUEST_ACTION)).thenReturn("request-action");
- when(ctx.getAttribute(INPUT_REQUEST_ACTION)).thenReturn("request-action");
+ @Test
+ public void should_extract_url_input_if_request_action_provided() throws Exception {
+ when(ctx.getAttribute(INPUT_REQUEST_ACTION)).thenReturn("request-action");
+ when(ctx.getAttribute(INPUT_URL)).thenReturn("");
+ when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost");
+ when(prop.getProperty(ctx.getAttribute(VNF_TYPE) + "." + (REST_PROTOCOL) + "."
+ + ctx.getAttribute(INPUT_REQUEST_ACTION) + "." + (REST_PORT))).thenReturn("8080");
- when(prop.getProperty("request-action.context")).thenReturn("ra-context");
- when(prop.getProperty("request-action.sub-context")).thenReturn("ra-sub-context");
+ when(prop.getProperty(ctx.getAttribute(VNF_TYPE) + "." + REST_PROTOCOL + "."
+ + ctx.getAttribute(INPUT_REQUEST_ACTION) + "." + REST_CONTEXT_URL)).thenReturn("ra-context");
+ when(prop.getProperty("request-action.sub-context")).thenReturn("ra-sub-context");
- String resourceUri = resourceUriExtractor.extractResourceUri(ctx, prop);
+ String resourceUri = resourceUriExtractor.extractResourceUri(ctx, prop);
- Assert.assertEquals("http://localhost:8080/ra-context/ra-sub-context", resourceUri);
- }
+ Assert.assertEquals("http://localhost:8080/ra-context/ra-sub-context", resourceUri);
+ }
- @Test
- public void should_throw_exception_if_missing_context() throws Exception {
- when(ctx.getAttribute(INPUT_URL)).thenReturn("");
- when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost");
- when(ctx.getAttribute(INPUT_PORT_NUMBER)).thenReturn("8080");
+ @Test
+ public void should_throw_exception_if_missing_context() throws Exception {
+ when(ctx.getAttribute(INPUT_URL)).thenReturn("");
+ when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost");
+ when(prop.getProperty(ctx.getAttribute(VNF_TYPE) + "." + (REST_PROTOCOL) + "."
+ + ctx.getAttribute(INPUT_REQUEST_ACTION) + "." + (REST_PORT))).thenReturn("8080");
- expectedException.expect(Exception.class);
- expectedException.expectMessage("Could Not found the context for operation null");
+ expectedException.expect(Exception.class);
+ expectedException.expectMessage("Could not find the context for operation null");
- resourceUriExtractor.extractResourceUri(ctx, prop);
- }
+ resourceUriExtractor.extractResourceUri(ctx, prop);
+ }
-} \ No newline at end of file
+}
diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/TestRestServiceNode.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/TestRestServiceNode.java
index fdf665a8e..001581402 100644
--- a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/TestRestServiceNode.java
+++ b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/TestRestServiceNode.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP : APPC
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,9 +15,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
+ * * ============LICENSE_END=========================================================
*/
package org.onap.appc.flow.controller.node;
@@ -27,10 +25,9 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
-import static org.onap.appc.flow.controller.node.InputParamsCollector.SDNC_CONFIG_DIR_VAR;
+import static org.onap.appc.flow.controller.node.RestServiceNode.APPC_CONFIG_DIR_VAR;
import static org.onap.appc.flow.controller.node.RestServiceNode.REST_RESPONSE;
import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_PARAM_RESPONSE_PREFIX;
-
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
@@ -47,144 +44,134 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicException;
public class TestRestServiceNode {
- private static final String RESOURCE_URI = "resource-uri";
- private static final String REST_BODY_RESPONSE = "{ 'state' : 'TEST' }";
-
- private RestServiceNode restServiceNode;
-
- private ResourceUriExtractor uriExtractorMock;
- private TransactionHandler transactionHandlerMock;
- private RestExecutor restExecutorMock;
-
- private SvcLogicContext ctxMock;
- private Transaction transaction;
- private Map<String, String> params;
-
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
- @Before
- public void setUp() throws Exception {
-
- uriExtractorMock = mock(ResourceUriExtractor.class);
- transactionHandlerMock = mock(TransactionHandler.class);
- restExecutorMock = mock(RestExecutor.class);
- ctxMock = mock(SvcLogicContext.class);
- transaction = mock(Transaction.class);
-
- // given
- params = new HashMap<>();
-
- HashMap<String, String> restResponseMap = new HashMap<>();
- restResponseMap.put(REST_RESPONSE, REST_BODY_RESPONSE.replaceAll("'", "\""));
-
- when(uriExtractorMock
- .extractResourceUri(any(SvcLogicContext.class), any(Properties.class)))
- .thenReturn(RESOURCE_URI);
- when(transactionHandlerMock
- .buildTransaction(any(SvcLogicContext.class), any(Properties.class), eq(RESOURCE_URI)))
- .thenReturn(transaction);
- when(restExecutorMock.execute(eq(transaction), any(SvcLogicContext.class)))
- .thenReturn(restResponseMap);
-
- EnvVariables envVariables = mock(EnvVariables.class);
- when(envVariables.getenv(SDNC_CONFIG_DIR_VAR)).thenReturn("src/test/resources");
- restServiceNode = new RestServiceNode(transactionHandlerMock, restExecutorMock, uriExtractorMock, envVariables);
- }
-
- @Test
- public void should_send_request() throws Exception {
- // given
- params.put(INPUT_PARAM_RESPONSE_PREFIX, "some-prefix");
-
- // when
- restServiceNode.sendRequest(params, ctxMock);
-
- // then
- verify(uriExtractorMock)
- .extractResourceUri(eq(ctxMock), any(Properties.class));
- verify(transactionHandlerMock)
- .buildTransaction(eq(ctxMock), any(Properties.class), eq(RESOURCE_URI));
- verify(restExecutorMock)
- .execute(transaction, ctxMock);
- verifyNoMoreInteractions(uriExtractorMock, transactionHandlerMock, restExecutorMock);
- }
-
- @Test
- public void should_rethrow_exception_from_uri_extractor() throws Exception {
- when(uriExtractorMock
- .extractResourceUri(eq(ctxMock), any(Properties.class)))
- .thenThrow(new Exception("resource uri exception"));
-
- expectedException.expect(SvcLogicException.class);
- expectedException.expectMessage("resource uri exception");
-
- restServiceNode.sendRequest(params, ctxMock);
- }
-
- @Test
- public void should_rethrow_exception_from_transaction_handler() throws Exception {
- when(transactionHandlerMock
- .buildTransaction(eq(ctxMock), any(Properties.class), eq(RESOURCE_URI)))
- .thenThrow(new Exception("transaction exception"));
-
- expectedException.expect(SvcLogicException.class);
- expectedException.expectMessage("transaction exception");
-
- restServiceNode.sendRequest(params, ctxMock);
- }
-
- @Test
- public void should_rethrow_exception_from_rest_executor() throws Exception {
- when(restExecutorMock
- .execute(transaction, ctxMock))
- .thenThrow(new Exception("rest executor exception"));
-
- expectedException.expect(SvcLogicException.class);
- expectedException.expectMessage("rest executor exception");
-
- restServiceNode.sendRequest(params, ctxMock);
- }
-
- @Ignore("missing asserts")
- @Test(expected = Exception.class)
- public void testRestServiceNode() throws Exception {
-
- SvcLogicContext ctx = new SvcLogicContext();
- ctx.setAttribute(FlowControllerConstants.VNF_TYPE, "vUSP - vDBE-IPX HUB");
- ctx.setAttribute(FlowControllerConstants.REQUEST_ACTION, "healthcheck");
- ctx.setAttribute(FlowControllerConstants.VNFC_TYPE, "TESTVNFC-CF");
- ctx.setAttribute(FlowControllerConstants.REQUEST_ID, "TESTCOMMONFRMWK");
- ctx.setAttribute("host-ip-address", "127.0.0.1");
- ctx.setAttribute("port-number", "8888");
- ctx.setAttribute("request-action-type", "GET");
- ctx.setAttribute("context", "loader/restconf/operations/appc-provider-lcm:health-check");
-
- HashMap<String, String> inParams = new HashMap<String, String>();
- RestServiceNode rsn = new RestServiceNode();
- inParams.put("output-state", "state");
- inParams.put("responsePrefix", "healthcheck");
- rsn.sendRequest(inParams, ctx);
-
- for (Object key : ctx.getAttributeKeySet()) {
- String parmName = (String) key;
- String parmValue = ctx.getAttribute(parmName);
+ private static final String RESOURCE_URI = "resource-uri";
+ private static final String REST_BODY_RESPONSE = "{ 'state' : 'TEST' }";
+
+ private RestServiceNode restServiceNode;
+
+ private ResourceUriExtractor uriExtractorMock;
+ private TransactionHandler transactionHandlerMock;
+ private RestExecutor restExecutorMock;
+
+ private SvcLogicContext ctxMock;
+ private Transaction transaction;
+ private Map<String, String> params;
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ @Before
+ public void setUp() throws Exception {
+
+ uriExtractorMock = mock(ResourceUriExtractor.class);
+ transactionHandlerMock = mock(TransactionHandler.class);
+ restExecutorMock = mock(RestExecutor.class);
+ ctxMock = mock(SvcLogicContext.class);
+ transaction = mock(Transaction.class);
+
+ // given
+ params = new HashMap<>();
+
+ HashMap<String, String> restResponseMap = new HashMap<>();
+ restResponseMap.put(REST_RESPONSE, REST_BODY_RESPONSE.replaceAll("'", "\""));
+
+ when(uriExtractorMock.extractResourceUri(any(SvcLogicContext.class), any(Properties.class)))
+ .thenReturn(RESOURCE_URI);
+ when(transactionHandlerMock.buildTransaction(any(SvcLogicContext.class), any(Properties.class),
+ eq(RESOURCE_URI))).thenReturn(transaction);
+ when(restExecutorMock.execute(eq(transaction), any(SvcLogicContext.class))).thenReturn(restResponseMap);
+
+ EnvVariables envVariables = mock(EnvVariables.class);
+ when(envVariables.getenv(APPC_CONFIG_DIR_VAR)).thenReturn("src/test/resources");
+ restServiceNode = new RestServiceNode(transactionHandlerMock, restExecutorMock, uriExtractorMock, envVariables);
+ }
+
+ @Test
+ public void should_send_request() throws Exception {
+ // given
+ params.put(INPUT_PARAM_RESPONSE_PREFIX, "some-prefix");
+
+ // when
+ restServiceNode.sendRequest(params, ctxMock);
+
+ // then
+ verify(uriExtractorMock).extractResourceUri(eq(ctxMock), any(Properties.class));
+ verify(transactionHandlerMock).buildTransaction(eq(ctxMock), any(Properties.class), eq(RESOURCE_URI));
+ verify(restExecutorMock).execute(transaction, ctxMock);
+ verifyNoMoreInteractions(uriExtractorMock, transactionHandlerMock, restExecutorMock);
+ }
+
+ @Test
+ public void should_rethrow_exception_from_uri_extractor() throws Exception {
+ when(uriExtractorMock.extractResourceUri(eq(ctxMock), any(Properties.class)))
+ .thenThrow(new Exception("resource uri exception"));
+
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage("resource uri exception");
+
+ restServiceNode.sendRequest(params, ctxMock);
+ }
+
+ @Test
+ public void should_rethrow_exception_from_transaction_handler() throws Exception {
+ when(transactionHandlerMock.buildTransaction(eq(ctxMock), any(Properties.class), eq(RESOURCE_URI)))
+ .thenThrow(new Exception("transaction exception"));
+
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage("transaction exception");
+
+ restServiceNode.sendRequest(params, ctxMock);
+ }
+
+ @Test
+ public void should_rethrow_exception_from_rest_executor() throws Exception {
+ when(restExecutorMock.execute(transaction, ctxMock)).thenThrow(new Exception("rest executor exception"));
+
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage("rest executor exception");
+
+ restServiceNode.sendRequest(params, ctxMock);
+ }
+
+ @Ignore("missing asserts")
+ @Test(expected = Exception.class)
+ public void testRestServiceNode() throws Exception {
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute(FlowControllerConstants.VNF_TYPE, "vUSP - vDBE-IPX HUB");
+ ctx.setAttribute(FlowControllerConstants.REQUEST_ACTION, "healthcheck");
+ ctx.setAttribute(FlowControllerConstants.VNFC_TYPE, "TESTVNFC-CF");
+ ctx.setAttribute(FlowControllerConstants.REQUEST_ID, "TESTCOMMONFRMWK");
+ ctx.setAttribute("host-ip-address", "127.0.0.1");
+ ctx.setAttribute("port-number", "8888");
+ ctx.setAttribute("request-action-type", "GET");
+ ctx.setAttribute("context", "loader/restconf/operations/appc-provider-lcm:health-check");
+
+ HashMap<String, String> inParams = new HashMap<String, String>();
+ RestServiceNode rsn = new RestServiceNode();
+ inParams.put("output-state", "state");
+ inParams.put("responsePrefix", "healthcheck");
+ rsn.sendRequest(inParams, ctx);
+
+ for (Object key : ctx.getAttributeKeySet()) {
+ String parmName = (String) key;
+ String parmValue = ctx.getAttribute(parmName);
+ }
+ }
+
+ @Ignore("missing asserts")
+ @Test(expected = Exception.class)
+ public void testInputParamsRestServiceNode() throws Exception {
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("vnf-id", "test");
+ ctx.setAttribute("tmp.vnfInfo.vm-count", "1");
+ ctx.setAttribute("tmp.vnfInfo.vm[0].vnfc-count", "1");
+ RestExecutor restExe = new RestExecutor();
+ Transaction transaction = new Transaction();
+
+ FlowControlNode node = new FlowControlNode();
+ Map<String, String> flowSeq = restExe.execute(transaction, ctx);
+ String flowSequnce = flowSeq.get("restResponse");
+
}
- }
-
- @Ignore("missing asserts")
- @Test(expected = Exception.class)
- public void testInputParamsRestServiceNode() throws Exception {
- SvcLogicContext ctx = new SvcLogicContext();
- ctx.setAttribute("vnf-id", "test");
- ctx.setAttribute("tmp.vnfInfo.vm-count", "1");
- ctx.setAttribute("tmp.vnfInfo.vm[0].vnfc-count", "1");
- RestExecutor restExe = new RestExecutor();
- Transaction transaction = new Transaction();
-
- FlowControlNode node = new FlowControlNode();
- Map<String, String> flowSeq = restExe.execute(transaction, ctx);
- String flowSequnce = flowSeq.get("restResponse");
-
- }
}