summaryrefslogtreecommitdiffstats
path: root/appc-config/appc-flow-controller/provider
diff options
context:
space:
mode:
Diffstat (limited to 'appc-config/appc-flow-controller/provider')
-rw-r--r--appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/data/Transaction.java2
-rw-r--r--appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/executorImpl/RestExecutor.java2
-rw-r--r--appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/ResourceUriExtractor.java3
-rw-r--r--appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/RestServiceNode.java28
-rw-r--r--appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/TransactionHandler.java44
-rw-r--r--appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/ResourceUriExtractorTest.java16
-rw-r--r--appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/TransactionHandlerTest.java73
7 files changed, 128 insertions, 40 deletions
diff --git a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/data/Transaction.java b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/data/Transaction.java
index a267baf2d..2eb75ff7a 100644
--- a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/data/Transaction.java
+++ b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/data/Transaction.java
@@ -77,7 +77,7 @@ public class Transaction {
private String status = "PENDING";
- public String getuId() {
+ public String getId() {
return uId;
}
diff --git a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/executorImpl/RestExecutor.java b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/executorImpl/RestExecutor.java
index 011ac973a..2f64a21c6 100644
--- a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/executorImpl/RestExecutor.java
+++ b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/executorImpl/RestExecutor.java
@@ -65,7 +65,7 @@ public class RestExecutor implements FlowExecutorInterface {
HTTPSProperties.PROPERTY_HTTPS_PROPERTIES,
new HTTPSProperties(getHostnameVerifier(), sslContext));
client = createClient(defaultClientConfig);
- client.addFilter(new HTTPBasicAuthFilter(transaction.getuId(), transaction.getPswd()));
+ client.addFilter(new HTTPBasicAuthFilter(transaction.getId(), transaction.getPswd()));
WebResource webResource = client.resource(new URI(transaction.getExecutionEndPoint()));
webResource.setProperty("Content-Type", "application/json;charset=UTF-8");
diff --git a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/ResourceUriExtractor.java b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/ResourceUriExtractor.java
index 3cfea31a2..0745f20ea 100644
--- a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/ResourceUriExtractor.java
+++ b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/ResourceUriExtractor.java
@@ -21,8 +21,7 @@ class ResourceUriExtractor {
private static final EELFLogger log = EELFManager.getInstance().getLogger(RestServiceNode.class);
- private ResourceUriExtractor() {
- }
+ private ResourceUriExtractor() {}
static String extractResourceUri(SvcLogicContext ctx, Properties prop) throws Exception {
String resourceUri = ctx.getAttribute(INPUT_URL);
diff --git a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/RestServiceNode.java b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/RestServiceNode.java
index 9d7f6e879..3597e0d18 100644
--- a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/RestServiceNode.java
+++ b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/RestServiceNode.java
@@ -24,8 +24,6 @@ package org.onap.appc.flow.controller.node;
import static org.onap.appc.flow.controller.utils.FlowControllerConstants.APPC_FLOW_CONTROLLER;
import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_PARAM_RESPONSE_PREFIX;
-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 static org.onap.appc.flow.controller.utils.FlowControllerConstants.OUTPUT_PARAM_ERROR_MESSAGE;
import static org.onap.appc.flow.controller.utils.FlowControllerConstants.OUTPUT_PARAM_STATUS;
import static org.onap.appc.flow.controller.utils.FlowControllerConstants.OUTPUT_STATUS_FAILURE;
@@ -85,31 +83,7 @@ public class RestServiceNode implements SvcLogicJavaPlugin {
String resourceUri = ResourceUriExtractor.extractResourceUri(ctx, prop);
log.info("Rest Constructed URL : " + resourceUri);
- Transaction transaction = new Transaction();
- transaction.setExecutionEndPoint(resourceUri);
- transaction
- .setExecutionRPC(ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE));
- transaction.setAction(INPUT_REQUEST_ACTION);
- if (ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE) == null
- || ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE).isEmpty()) {
- throw new Exception("Dont know REST operation for Action " + transaction.getExecutionRPC());
- }
- if (ctx.getAttribute(INPUT_REQUEST_ACTION) == null
- || ctx.getAttribute(INPUT_REQUEST_ACTION).isEmpty()) {
- throw new Exception("Dont know request-action " + transaction.getAction());
- }
-
- //This code need to get changed to get the UserID and pass from a common place.
- if (transaction.getuId() == null) {
- transaction
- .setuId(prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION)
- .concat(".default-rest-user")));
- }
- if (transaction.getPswd() == null) {
- transaction
- .setPswd(prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION)
- .concat(".default-rest-pass")));
- }
+ Transaction transaction = TransactionHandler.buildTransaction(ctx, prop, resourceUri);
RestExecutor restRequestExecutor = new RestExecutor();
Map<String, String> output = restRequestExecutor.execute(transaction, ctx);
diff --git a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/TransactionHandler.java b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/TransactionHandler.java
new file mode 100644
index 000000000..8d10b3c7f
--- /dev/null
+++ b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/node/TransactionHandler.java
@@ -0,0 +1,44 @@
+package org.onap.appc.flow.controller.node;
+
+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.apache.commons.lang3.StringUtils;
+import org.onap.appc.flow.controller.data.Transaction;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+
+/**
+ * Helper class for RestServiceNode
+ */
+class TransactionHandler {
+
+ private TransactionHandler() {}
+
+ static Transaction buildTransaction(SvcLogicContext ctx, Properties prop,
+ String resourceUri) throws Exception {
+
+ String inputRequestAction = ctx.getAttribute(INPUT_REQUEST_ACTION);
+ String inputRequestActionType = ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE);
+
+ if (StringUtils.isBlank(inputRequestActionType)) {
+ throw new IllegalArgumentException(
+ "Don't know REST operation for Action " + inputRequestActionType);
+ }
+ if (StringUtils.isBlank(inputRequestAction)) {
+ throw new IllegalArgumentException("Don't know request-action " + INPUT_REQUEST_ACTION);
+ }
+
+ Transaction transaction = new Transaction();
+ transaction.setExecutionEndPoint(resourceUri);
+ transaction.setExecutionRPC(inputRequestActionType);
+ transaction.setAction(INPUT_REQUEST_ACTION);
+
+ //This code need to get changed to get the UserID and pass from a common place.
+ transaction.setuId(prop.getProperty(inputRequestAction.concat(".default-rest-user")));
+ transaction.setPswd(prop.getProperty(inputRequestAction.concat(".default-rest-pass")));
+
+ return transaction;
+ }
+
+} \ No newline at end of file
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