aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-tasks/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/test')
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingClientTest.java99
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingRequestObjectBuilderTest.java10
-rw-r--r--bpmn/so-bpmn-tasks/src/test/resources/__files/NamingClient/AssignResponse.json14
-rw-r--r--bpmn/so-bpmn-tasks/src/test/resources/__files/NamingClient/ErrorResponse.json6
-rw-r--r--bpmn/so-bpmn-tasks/src/test/resources/__files/NamingClient/UnassignResponse.json14
-rw-r--r--bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml2
6 files changed, 139 insertions, 6 deletions
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingClientTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingClientTest.java
new file mode 100644
index 0000000000..c1769e3680
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingClientTest.java
@@ -0,0 +1,99 @@
+package org.onap.so.client.namingservice;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.delete;
+import static com.github.tomakehurst.wiremock.client.WireMock.post;
+import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.http.HttpStatus;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onap.namingservice.model.Deleteelement;
+import org.onap.namingservice.model.Element;
+import org.onap.namingservice.model.NameGenDeleteRequest;
+import org.onap.namingservice.model.NameGenRequest;
+import org.onap.so.BaseIntegrationTest;
+import org.onap.so.client.exception.BadResponseException;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+
+public class NamingClientTest extends BaseIntegrationTest{
+ @Autowired
+ NamingClient client;
+ @Autowired
+ NamingRequestObjectBuilder requestBuilder;
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void assignNameGenRequest() throws BadResponseException, IOException{
+ stubFor(post(urlPathEqualTo("/web/service/v1/genNetworkElementName"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBodyFile("NamingClient/AssignResponse.json")
+ .withStatus(HttpStatus.SC_ACCEPTED)));
+
+ NameGenRequest request = assignSetup();
+ String response = client.postNameGenRequest(request);
+ assertTrue(response.equals("$vnf-name"));
+ }
+ @Test
+ public void assignNameGenRequestError() throws BadResponseException, IOException{
+ stubFor(post(urlPathEqualTo("/web/service/v1/genNetworkElementName"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBodyFile("NamingClient/ErrorResponse.json")
+ .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
+
+ thrown.expect(BadResponseException.class);
+ thrown.expectMessage("Error from Naming Service: External Key is required and must be unique");
+ NameGenRequest request = assignSetup();
+ client.postNameGenRequest(request);
+ }
+ @Test
+ public void unassignNameGenRequest() throws BadResponseException, IOException{
+ stubFor(delete(urlPathEqualTo("/web/service/v1/genNetworkElementName"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBodyFile("NamingClient/UnassignResponse.json")
+ .withStatus(HttpStatus.SC_ACCEPTED)));
+
+ String response = client.deleteNameGenRequest(unassignSetup());
+ assertTrue(response.equals(""));
+ }
+ @Test
+ public void unassignNameGenRequestError() throws BadResponseException, IOException{
+ stubFor(delete(urlPathEqualTo("/web/service/v1/genNetworkElementName"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBodyFile("NamingClient/ErrorResponse.json")
+ .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR)));
+
+ thrown.expect(BadResponseException.class);
+ thrown.expectMessage("Error from Naming Service: External Key is required and must be unique");
+ client.deleteNameGenRequest(unassignSetup());
+ }
+
+ public NameGenRequest assignSetup() throws JsonProcessingException{
+ NameGenRequest request = new NameGenRequest();
+ List<Element> elements = new ArrayList<>();
+ Element testElement = new Element();
+ testElement = requestBuilder.elementMapper("SomeUniqueValue", "SDNC_Policy.Config_MS_1806SRIOV_VNATJson.4.xml", "VNF", "nfNamingCode", "vnf_name");
+ elements.add(testElement);
+ request = requestBuilder.nameGenRequestMapper(elements);
+ return request;
+ }
+ public NameGenDeleteRequest unassignSetup() throws JsonProcessingException{
+ NameGenDeleteRequest request = new NameGenDeleteRequest();
+ List<Deleteelement> deleteElements = new ArrayList<>();
+ Deleteelement testElement = new Deleteelement();
+ testElement = requestBuilder.deleteElementMapper("instanceGroupId");
+ deleteElements.add(testElement);
+ request = requestBuilder.nameGenDeleteRequestMapper(deleteElements);
+ return request;
+ }
+} \ No newline at end of file
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingRequestObjectBuilderTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingRequestObjectBuilderTest.java
index 0a2dc1e4fa..27839d665b 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingRequestObjectBuilderTest.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingRequestObjectBuilderTest.java
@@ -26,11 +26,11 @@ public class NamingRequestObjectBuilderTest {
public void elementMapperTest(){
// Expected element
Element expected = new Element();
- expected.setExternalKey(instanceGroupId);
- expected.setPolicyInstanceName(policyInstanceName);
- expected.setNamingType(namingType);
- expected.setResourceName(instanceGroupName);
- expected.setNamingIngredientsZeroOrMore(nfNamingCode);
+ expected.put("external-key", instanceGroupId);
+ expected.put("policy-instance-name", policyInstanceName);
+ expected.put("naming-type", namingType);
+ expected.put("resource-name", instanceGroupName);
+ expected.put("nf-naming-code", nfNamingCode);
// Actual element
Element actual = mapper.elementMapper(instanceGroupId, policyInstanceName, namingType, nfNamingCode, instanceGroupName);
diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/NamingClient/AssignResponse.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/NamingClient/AssignResponse.json
new file mode 100644
index 0000000000..b065c21339
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/NamingClient/AssignResponse.json
@@ -0,0 +1,14 @@
+{
+ "elements": [
+ {
+ "external-key": "$vnf-id",
+ "resource-name": "instance-group-name",
+ "resource-value": "$vnf-name"
+ },
+ {
+ "external-key": "$vnf-id",
+ "resource-name": "vm-name",
+ "resource-value": "$vm-name"
+ }
+ ]
+}
diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/NamingClient/ErrorResponse.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/NamingClient/ErrorResponse.json
new file mode 100644
index 0000000000..8bac7cd1f9
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/NamingClient/ErrorResponse.json
@@ -0,0 +1,6 @@
+{
+ "error": {
+ "errorId": "NELGEN-0003",
+ "message": "External Key is required and must be unique"
+ }
+} \ No newline at end of file
diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/NamingClient/UnassignResponse.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/NamingClient/UnassignResponse.json
new file mode 100644
index 0000000000..b065c21339
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/NamingClient/UnassignResponse.json
@@ -0,0 +1,14 @@
+{
+ "elements": [
+ {
+ "external-key": "$vnf-id",
+ "resource-name": "instance-group-name",
+ "resource-value": "$vnf-name"
+ },
+ {
+ "external-key": "$vnf-id",
+ "resource-name": "vm-name",
+ "resource-value": "$vm-name"
+ }
+ ]
+}
diff --git a/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml b/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml
index 3d45caddce..fed2aa69c7 100644
--- a/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml
+++ b/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml
@@ -43,7 +43,7 @@ pnf:
mso:
naming:
endpoint: http://localhost:${wiremock.server.port}/web/service/v1/genNetworkElementName
- auth: Basic YnBlbDptc28tZGItMTUwNyE=
+ auth: Basic YnBlbDptc28tZGItMTUwNyE=
adapters:
requestDb:
auth: Basic YnBlbDptc28tZGItMTUwNyE=