aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/bpmn/CreateAndActivatePnfResourceTest.java16
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/InformDmaapClient.java10
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/BaseClient.java13
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/SDNCClient.java6
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/SniroClient.java5
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/BaseClientTest.java50
-rw-r--r--common/src/main/java/org/onap/so/client/RestClientSSL.java14
7 files changed, 81 insertions, 33 deletions
diff --git a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/bpmn/CreateAndActivatePnfResourceTest.java b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/bpmn/CreateAndActivatePnfResourceTest.java
index d42717f5c1..b514c38d47 100644
--- a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/bpmn/CreateAndActivatePnfResourceTest.java
+++ b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/bpmn/CreateAndActivatePnfResourceTest.java
@@ -30,18 +30,17 @@ import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableName
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.history.HistoricVariableInstance;
import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.camunda.bpm.engine.test.Deployment;
import org.camunda.bpm.engine.test.ProcessEngineRule;
import org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareTests;
-import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.so.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl;
+import org.onap.so.bpmn.infrastructure.pnf.delegate.DmaapClientTestImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@@ -61,6 +60,9 @@ public class CreateAndActivatePnfResourceTest {
@Autowired
private AaiConnectionTestImpl aaiConnection;
+ @Autowired
+ private DmaapClientTestImpl dmaapClientTestImpl;
+
@Test
@Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"})
public void shouldSaveCurrentIpToVariableIfItAlreadyExistsInAai() throws Exception {
@@ -96,9 +98,8 @@ public class CreateAndActivatePnfResourceTest {
ProcessInstance instance = runtimeService
.startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables);
assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage");
- runtimeService.createMessageCorrelation("WorkflowMessage")
- .processInstanceBusinessKey("businessKey")
- .correlateWithResult();
+ dmaapClientTestImpl.sendMessage();
+
// then
assertThat(instance).isEnded().hasPassedInOrder(
"CreateAndActivatePnf_StartEvent",
@@ -125,9 +126,8 @@ public class CreateAndActivatePnfResourceTest {
ProcessInstance instance = runtimeService
.startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables);
assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage");
- runtimeService.createMessageCorrelation("WorkflowMessage")
- .processInstanceBusinessKey("businessKey")
- .correlateWithResult();
+ dmaapClientTestImpl.sendMessage();
+
// then
assertThat(instance).isEnded().hasPassedInOrder(
"CreateAndActivatePnf_StartEvent",
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/InformDmaapClient.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/InformDmaapClient.java
index bb490a06e4..61b1ca4cae 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/InformDmaapClient.java
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/InformDmaapClient.java
@@ -20,6 +20,7 @@
package org.onap.so.bpmn.infrastructure.pnf.delegate;
+import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.onap.so.bpmn.infrastructure.pnf.dmaap.DmaapClient;
@@ -30,12 +31,15 @@ public class InformDmaapClient implements JavaDelegate {
private DmaapClient dmaapClient;
@Override
- public void execute(DelegateExecution execution) throws Exception {
+ public void execute(DelegateExecution execution) {
String correlationId = (String) execution.getVariable(ExecutionVariableNames.CORRELATION_ID);
- dmaapClient.registerForUpdate(correlationId, () -> execution.getProcessEngineServices().getRuntimeService()
+ RuntimeService runtimeService = execution.getProcessEngineServices().getRuntimeService();
+ dmaapClient.registerForUpdate(correlationId, () ->
+ runtimeService
.createMessageCorrelation("WorkflowMessage")
.processInstanceBusinessKey(execution.getProcessBusinessKey())
- .correlateWithResult());
+ .correlateWithResult()
+ );
}
@Autowired
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/BaseClient.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/BaseClient.java
index 5a63d2097b..50137cf985 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/BaseClient.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/BaseClient.java
@@ -52,20 +52,19 @@ public class BaseClient<I,O> {
this.targetUrl = targetUrl;
}
- public O get(I data, Object... uriVariables) throws RestClientException {
- return run(data, HttpMethod.GET, uriVariables);
+ public O get(I data, ParameterizedTypeReference<O> typeRef, Object... uriVariables) throws RestClientException {
+ return run(data, HttpMethod.GET, typeRef, uriVariables);
}
- public O post(I data, Object... uriVariables) throws RestClientException {
- return run(data, HttpMethod.POST, uriVariables);
+ public O post(I data, ParameterizedTypeReference<O> typeRef, Object... uriVariables) throws RestClientException {
+ return run(data, HttpMethod.POST, typeRef, uriVariables);
}
- public O run(I data, HttpMethod method, Object... uriVariables) throws RestClientException {
+ public O run(I data, HttpMethod method, ParameterizedTypeReference<O> typeRef, Object... uriVariables) throws RestClientException {
HttpEntity<I> requestEntity = new HttpEntity<I>(data, getHttpHeader());
RestTemplate restTemplate = new RestTemplate();
restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory()));
- ParameterizedTypeReference<O> output = new ParameterizedTypeReference<O>() {};
- ResponseEntity<O> responseEntity = restTemplate.exchange(getTargetUrl(), method, requestEntity, output,
+ ResponseEntity<O> responseEntity = restTemplate.exchange(getTargetUrl(), method, requestEntity, typeRef,
uriVariables);
return responseEntity.getBody();
}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/SDNCClient.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/SDNCClient.java
index 1f0d654a85..9e60196426 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/SDNCClient.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/SDNCClient.java
@@ -21,6 +21,7 @@
package org.onap.so.client.sdnc;
import java.util.LinkedHashMap;
+
import javax.ws.rs.core.UriBuilder;
import org.onap.so.client.exception.BadResponseException;
@@ -29,6 +30,7 @@ import org.onap.so.client.sdnc.beans.SDNCProperties;
import org.onap.so.client.sdnc.endpoint.SDNCTopology;
import org.onap.so.logger.MsoLogger;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component;
@@ -58,7 +60,7 @@ public class SDNCClient {
HttpHeaders httpHeader = sdnCommonTasks.getHttpHeaders(properties.getAuth());
STOClient.setHttpHeader(httpHeader);
msoLogger.info("Running SDNC CLIENT for TargetUrl: " + targetUrl);
- LinkedHashMap<?, ?> output = STOClient.post(jsonRequest);
+ LinkedHashMap<?, ?> output = STOClient.post(jsonRequest, new ParameterizedTypeReference<LinkedHashMap<? ,?>>() {});
msoLogger.info("Validating output...");
return sdnCommonTasks.validateSDNResponse(output);
}
@@ -84,7 +86,7 @@ public class SDNCClient {
HttpHeaders httpHeader = sdnCommonTasks.getHttpHeaders(properties.getAuth());
STOClient.setHttpHeader(httpHeader);
msoLogger.info("Running SDNC CLIENT...");
- LinkedHashMap<?, ?> output = STOClient.get(jsonRequest);
+ LinkedHashMap<?, ?> output = STOClient.get(jsonRequest, new ParameterizedTypeReference<LinkedHashMap<? ,?>>() {});
msoLogger.info("Validating output...");
return sdnCommonTasks.validateSDNGetResponse(output);
}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/SniroClient.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/SniroClient.java
index 979b9e5e80..cee94e28bd 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/SniroClient.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/SniroClient.java
@@ -31,6 +31,7 @@ import org.onap.so.client.sniro.beans.SniroConductorRequest;
import org.onap.so.client.sniro.beans.SniroManagerRequest;
import org.onap.so.logger.MsoLogger;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
@@ -76,7 +77,7 @@ public class SniroClient {
baseClient.setTargetUrl(url);
baseClient.setHttpHeader(header);
- LinkedHashMap<?, ?> response = baseClient.post(homingRequest.toJsonString());
+ LinkedHashMap<?, ?> response = baseClient.post(homingRequest.toJsonString(), new ParameterizedTypeReference<LinkedHashMap<? ,?>>() {});
validator.validateDemandsResponse(response);
log.trace("Completed Sniro Client Post Demands");
}
@@ -106,7 +107,7 @@ public class SniroClient {
baseClient.setTargetUrl(url);
baseClient.setHttpHeader(header);
- LinkedHashMap<?, ?> response = baseClient.post(releaseRequest.toJsonString());
+ LinkedHashMap<?, ?> response = baseClient.post(releaseRequest.toJsonString(), new ParameterizedTypeReference<LinkedHashMap<? ,?>>() {});
SniroValidator v = new SniroValidator();
v.validateReleaseResponse(response);
log.trace("Completed Sniro Client Post Release");
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/BaseClientTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/BaseClientTest.java
new file mode 100644
index 0000000000..a564d8a21d
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/BaseClientTest.java
@@ -0,0 +1,50 @@
+package org.onap.so.client.sdnc;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
+import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+import java.util.Map;
+
+import javax.ws.rs.core.UriBuilder;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.springframework.core.ParameterizedTypeReference;
+
+import com.github.tomakehurst.wiremock.junit.WireMockRule;
+
+import wiremock.org.apache.http.entity.ContentType;
+public class BaseClientTest {
+
+
+ @Rule
+ public WireMockRule wm = new WireMockRule(options().dynamicPort());
+
+ @Test
+ public void verifyString() {
+ BaseClient<String, String> client = new BaseClient<>();
+ String response = "{\"hello\" : \"world\"}";
+ client.setTargetUrl(UriBuilder.fromUri("http://localhost/test").port(wm.port()).build().toString());
+ wm.stubFor(get(urlEqualTo("/test"))
+ .willReturn(aResponse().withStatus(200).withBody(response).withHeader("Content-Type", ContentType.APPLICATION_JSON.toString())));
+
+ String result = client.get("", new ParameterizedTypeReference<String>() {});
+ assertThat(result, equalTo(response));
+ }
+
+ @Test
+ public void verifyMap() {
+ BaseClient<String, Map<String, Object>> client = new BaseClient<>();
+ String response = "{\"hello\" : \"world\"}";
+ client.setTargetUrl(UriBuilder.fromUri("http://localhost/test").port(wm.port()).build().toString());
+ wm.stubFor(get(urlEqualTo("/test"))
+ .willReturn(aResponse().withStatus(200).withBody(response).withHeader("Content-Type", ContentType.APPLICATION_JSON.toString())));
+
+ Map<String, Object> result = client.get("", new ParameterizedTypeReference<Map<String, Object>>() {});
+ assertThat("world", equalTo(result.get("hello")));
+ }
+}
diff --git a/common/src/main/java/org/onap/so/client/RestClientSSL.java b/common/src/main/java/org/onap/so/client/RestClientSSL.java
index 461bb5832c..8eaeee97ee 100644
--- a/common/src/main/java/org/onap/so/client/RestClientSSL.java
+++ b/common/src/main/java/org/onap/so/client/RestClientSSL.java
@@ -72,23 +72,15 @@ public abstract class RestClientSSL extends RestClient {
private KeyStore getKeyStore() {
KeyStore ks = null;
char[] password = System.getProperty(RestClientSSL.SSL_KEY_STORE_PASSWORD_KEY).toCharArray();
- FileInputStream fis = null;
- try {
+ try(FileInputStream fis = new FileInputStream(System.getProperty(RestClientSSL.SSL_KEY_STORE_KEY))) {
ks = KeyStore.getInstance(KeyStore.getDefaultType());
- fis = new FileInputStream(System.getProperty(RestClientSSL.SSL_KEY_STORE_KEY));
+
ks.load(fis, password);
}
catch(Exception e) {
return null;
}
- finally {
- if (fis != null) {
- try {
- fis.close();
- }
- catch(Exception e) {}
- }
- }
+
return ks;
}
}