summaryrefslogtreecommitdiffstats
path: root/prh-app-server/src/test
diff options
context:
space:
mode:
authorJoanna Jeremicz <joanna.jeremicz@nokia.com>2019-06-12 09:24:24 +0200
committerJoanna Jeremicz <joanna.jeremicz@nokia.com>2019-06-13 11:47:36 +0200
commit93bed2156ac39eb3e829dd1a163ff90e05f9525a (patch)
tree1cc8e445341e86809ad2251ae54b9bac841e04b6 /prh-app-server/src/test
parentdc3940018875d8064c1eb51afdc39768a033328a (diff)
Logical links creation bug
Fixed issues: Second PNF registration with same attachment point doesn't send output to PNF_READ Second PNF registration with different attachmentPoint doesn't replace previous Logical Link Change-Id: I238a8aa6d3f360da3451c720dc5cb1fa2e1ebd75 Issue-ID: DCAEGEN2-1611 Signed-off-by: Joanna Jeremicz <joanna.jeremicz@nokia.com>
Diffstat (limited to 'prh-app-server/src/test')
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/BbsActionsTaskTest.java131
-rw-r--r--prh-app-server/src/test/resources/BbsActionsTaskTestFiles/oldLogicalLink.json21
-rw-r--r--prh-app-server/src/test/resources/BbsActionsTaskTestFiles/pnfWithLogicalLink.json25
-rw-r--r--prh-app-server/src/test/resources/BbsActionsTaskTestFiles/pnfWithoutLinks.json10
4 files changed, 164 insertions, 23 deletions
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/BbsActionsTaskTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/BbsActionsTaskTest.java
index 3733a48c..5af78afa 100644
--- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/BbsActionsTaskTest.java
+++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/BbsActionsTaskTest.java
@@ -20,10 +20,28 @@
package org.onap.dcaegen2.services.prh.tasks;
+import static io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR;
+import static io.netty.handler.codec.http.HttpResponseStatus.OK;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpMethod.DELETE;
+import static org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpMethod.GET;
+import static org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpMethod.PUT;
+
import com.google.gson.JsonObject;
import io.netty.handler.codec.http.HttpResponseStatus;
+import java.util.List;
+import java.util.Scanner;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
+import org.mockito.ArgumentMatchers;
import org.onap.dcaegen2.services.prh.TestAppConfiguration;
import org.onap.dcaegen2.services.prh.configuration.CbsConfiguration;
import org.onap.dcaegen2.services.prh.exceptions.AaiFailureException;
@@ -36,21 +54,24 @@ import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.ImmutableHttpR
import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient;
import reactor.core.publisher.Mono;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.*;
-
class BbsActionsTaskTest {
- private static final String AAI_URL = "https://aai.onap.svc.cluster.local:8443/aai/v12/network/logical-links/logical-link/some-link";
+ private static final String AAI_URL = "https://aai.onap.svc.cluster.local:8443/aai/v12/network";
+ private static final String PNF_URL = "/pnfs/pnf";
+ private static final String LOGICAL_LINK_URL = "/logical-links/logical-link";
+ private static final String ATTACHMENT_POINT = "attachment-point";
+
+ private static final String PNF_WITHOUT_LINK_JSON = "BbsActionsTaskTestFiles/pnfWithoutLinks.json";
+ private static final String PNF_WITH_LINK_JSON = "BbsActionsTaskTestFiles/pnfWithLogicalLink.json";
+ private static final String LOGICAL_LINK_JSON = "BbsActionsTaskTestFiles/oldLogicalLink.json";
+
private CbsConfiguration cbsConfiguration = mock(CbsConfiguration.class);
private AaiClientConfiguration aaiClientConfiguration = TestAppConfiguration.createDefaultAaiClientConfiguration();
private RxHttpClient httpClient = mock(RxHttpClient.class);
+ private ClassLoader loader = getClass().getClassLoader();
+
@Test
void whenPassedObjectDoesntHaveAdditionalFields_ReturnPayloadTransparently() {
// given
@@ -71,7 +92,7 @@ class BbsActionsTaskTest {
given(cbsConfiguration.getAaiClientConfiguration()).willReturn(aaiClientConfiguration);
JsonObject additionalFields = new JsonObject();
- additionalFields.addProperty("attachment-point", "");
+ additionalFields.addProperty(ATTACHMENT_POINT, "");
ConsumerDmaapModel consumerDmaapModel = buildConsumerDmaapModel(additionalFields);
// when
@@ -83,15 +104,18 @@ class BbsActionsTaskTest {
}
@Test
- void whenPassedObjectHasLogicalLink_createLogicalLink_and_associateWithPnf_and_ReturnPayloadTransparently() {
+ void whenPassedObjectHasLogicalLink_and_pnfHasNoLogicalLink_createLogicalLink_and_associateWithPnf_and_ReturnPayloadTransparently() {
// given
given(cbsConfiguration.getAaiClientConfiguration()).willReturn(aaiClientConfiguration);
JsonObject additionalFields = new JsonObject();
- additionalFields.addProperty("attachment-point", "some-link");
+ String linkName = "some-link";
+ additionalFields.addProperty(ATTACHMENT_POINT, linkName);
ConsumerDmaapModel consumerDmaapModel = buildConsumerDmaapModel(additionalFields);
- given(httpClient.call(any())).willReturn(Mono.just(buildAaiResponse(HttpResponseStatus.OK)));
+ given(httpClient.call(any()))
+ .willReturn(Mono.just(buildAaiResponse(OK, getBodyJson(PNF_WITHOUT_LINK_JSON))),
+ Mono.just(buildAaiResponse(OK, "")));
// when
Mono<ConsumerDmaapModel> response = new BbsActionsTaskImpl(cbsConfiguration, httpClient).execute(consumerDmaapModel);
@@ -99,37 +123,94 @@ class BbsActionsTaskTest {
// then
assertEquals(consumerDmaapModel, response.block());
+ ArgumentCaptor<HttpRequest> captor = ArgumentCaptor.forClass(HttpRequest.class);
+ verify(httpClient, times(2)).call(captor.capture());
+
+ List<HttpRequest> args = captor.getAllValues();
+ assertEquals(2, args.size());
+
+ HttpRequest pnfGet = args.get(0);
+ HttpRequest linkPut = args.get(1);
+
+ assertEquals(AAI_URL + PNF_URL + "/Nokia123", pnfGet.url());
+ assertEquals(GET, pnfGet.method());
+ assertEquals(AAI_URL + LOGICAL_LINK_URL + "/" + linkName, linkPut.url());
+ assertEquals(PUT, linkPut.method());
}
@Test
- void whenPassedObjectHasLogicalLink_butAaiQueryFails_returnError() {
+ void whenPassedObjectHasLogicalLink_and_pnfHasLogicalLink_deleteOldLogicalLink_and_createLogicalLink_and_associateWithPnf_and_ReturnPayloadTransparently() {
// given
given(cbsConfiguration.getAaiClientConfiguration()).willReturn(aaiClientConfiguration);
JsonObject additionalFields = new JsonObject();
- additionalFields.addProperty("attachment-point", "some-link");
+ String linkName = "some-link";
+ additionalFields.addProperty(ATTACHMENT_POINT, linkName);
ConsumerDmaapModel consumerDmaapModel = buildConsumerDmaapModel(additionalFields);
- given(httpClient.call(any())).willReturn(Mono.just(buildAaiResponse(HttpResponseStatus.INTERNAL_SERVER_ERROR)));
+ given(httpClient.call(any()))
+ .willReturn(Mono.just(buildAaiResponse(OK, getBodyJson(PNF_WITH_LINK_JSON))),
+ Mono.just(buildAaiResponse(OK, "")),
+ Mono.just(buildAaiResponse(OK, getBodyJson(LOGICAL_LINK_JSON))),
+ Mono.just(buildAaiResponse(OK, "")));
// when
Mono<ConsumerDmaapModel> response = new BbsActionsTaskImpl(cbsConfiguration, httpClient).execute(consumerDmaapModel);
// then
+ assertEquals(consumerDmaapModel, response.block());
+
ArgumentCaptor<HttpRequest> captor = ArgumentCaptor.forClass(HttpRequest.class);
- verify(httpClient).call(captor.capture());
- verifyNoMoreInteractions(httpClient);
+ verify(httpClient, times(4)).call(captor.capture());
+
+ List<HttpRequest> args = captor.getAllValues();
+ assertEquals(4, args.size());
+
+ HttpRequest pnfGet = args.get(0);
+ HttpRequest linkPut = args.get(1);
+ HttpRequest linkGet = args.get(2);
+ HttpRequest linkDelete = args.get(3);
+
+ assertEquals(AAI_URL + PNF_URL + "/Nokia123", pnfGet.url());
+ assertEquals(GET, pnfGet.method());
+ assertEquals(AAI_URL + LOGICAL_LINK_URL + "/" + linkName, linkPut.url());
+ assertEquals(PUT, linkPut.method());
+ assertEquals(AAI_URL + LOGICAL_LINK_URL + "/" + linkName, linkGet.url());
+ assertEquals(GET, linkGet.method());
+ assertEquals(AAI_URL + LOGICAL_LINK_URL + "/" + linkName + "?resource-version=1560171816043", linkDelete.url());
+ assertEquals(DELETE, linkDelete.method());
+ }
+
+ @Test
+ void whenPassedObjectHasLogicalLink_butAaiQueryFails_returnError() {
+ // given
+ given(cbsConfiguration.getAaiClientConfiguration()).willReturn(aaiClientConfiguration);
- HttpRequest request = captor.getValue();
- assertThat(request.url()).isEqualTo(AAI_URL);
- assertThatThrownBy(response::block).hasCauseInstanceOf(AaiFailureException.class);
+ JsonObject additionalFields = new JsonObject();
+ String linkName = "some-link";
+ additionalFields.addProperty(ATTACHMENT_POINT, linkName);
+ ConsumerDmaapModel consumerDmaapModel = buildConsumerDmaapModel(additionalFields);
+
+ given(httpClient.call(
+ ArgumentMatchers.argThat(argument -> argument.url().equals(AAI_URL + PNF_URL + "/Nokia123")
+ || argument.url().equals(AAI_URL + LOGICAL_LINK_URL + "/" + linkName))))
+ .willReturn(Mono.just(buildAaiResponse(INTERNAL_SERVER_ERROR, "")));
+
+ // when
+ Mono<ConsumerDmaapModel> response = new BbsActionsTaskImpl(cbsConfiguration, httpClient)
+ .execute(consumerDmaapModel);
+
+ // then
+ assertThatThrownBy(response::block).hasCauseInstanceOf(AaiFailureException.class).hasMessage(
+ "org.onap.dcaegen2.services.prh.exceptions.AaiFailureException: "
+ + "Incorrect response when performing BBS-related actions: 500. Occurred in GET PNF request. Pnf name: Nokia123");
}
private ConsumerDmaapModel buildConsumerDmaapModel(JsonObject additionalFields) {
return ImmutableConsumerDmaapModel.builder()
.ipv4("10.16.123.234")
.ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
- .correlationId("NOKQTFCOC540002E")
+ .correlationId("Nokia123")
.serialNumber("QTFCOC540002E")
.equipVendor("nokia")
.equipModel("3310")
@@ -140,12 +221,16 @@ class BbsActionsTaskTest {
.build();
}
- private HttpResponse buildAaiResponse(HttpResponseStatus status) {
+ private HttpResponse buildAaiResponse(HttpResponseStatus status, String body) {
return ImmutableHttpResponse
.builder()
.statusCode(status.code())
.url("")
- .rawBody("".getBytes())
+ .rawBody(body.getBytes())
.build();
}
+
+ private String getBodyJson(String filename) {
+ return new Scanner(loader.getResourceAsStream(filename)).useDelimiter("\\A").next();
+ }
} \ No newline at end of file
diff --git a/prh-app-server/src/test/resources/BbsActionsTaskTestFiles/oldLogicalLink.json b/prh-app-server/src/test/resources/BbsActionsTaskTestFiles/oldLogicalLink.json
new file mode 100644
index 00000000..7d3f02df
--- /dev/null
+++ b/prh-app-server/src/test/resources/BbsActionsTaskTestFiles/oldLogicalLink.json
@@ -0,0 +1,21 @@
+{
+ "link-name": "some-link",
+ "in-maint": false,
+ "link-type": "attachment-point",
+ "resource-version": "1560171816043",
+ "relationship-list": {
+ "relationship": [
+ {
+ "related-to": "pnf",
+ "relationship-label": "org.onap.relationships.inventory.BridgedTo",
+ "related-link": "/aai/v14/network/pnfs/pnf/Nokia123",
+ "relationship-data": [
+ {
+ "relationship-key": "pnf.pnf-name",
+ "relationship-value": "Nokia123"
+ }
+ ]
+ }
+ ]
+ }
+} \ No newline at end of file
diff --git a/prh-app-server/src/test/resources/BbsActionsTaskTestFiles/pnfWithLogicalLink.json b/prh-app-server/src/test/resources/BbsActionsTaskTestFiles/pnfWithLogicalLink.json
new file mode 100644
index 00000000..6f4690d6
--- /dev/null
+++ b/prh-app-server/src/test/resources/BbsActionsTaskTestFiles/pnfWithLogicalLink.json
@@ -0,0 +1,25 @@
+{
+ "pnf-name": "Nokia123",
+ "pnf-name2-source": "",
+ "pnf-id": "Nokia123",
+ "equip-type": "",
+ "equip-vendor": "",
+ "management-option": "",
+ "in-maint": false,
+ "resource-version": "1560153116694",
+ "relationship-list": {
+ "relationship": [
+ {
+ "related-to": "logical-link",
+ "relationship-label": "org.onap.relationships.inventory.BridgedTo",
+ "related-link": "/aai/v14/network/logical-links/logical-link/some-link",
+ "relationship-data": [
+ {
+ "relationship-key": "logical-link.link-name",
+ "relationship-value": "some-link"
+ }
+ ]
+ }
+ ]
+ }
+} \ No newline at end of file
diff --git a/prh-app-server/src/test/resources/BbsActionsTaskTestFiles/pnfWithoutLinks.json b/prh-app-server/src/test/resources/BbsActionsTaskTestFiles/pnfWithoutLinks.json
new file mode 100644
index 00000000..1f614d40
--- /dev/null
+++ b/prh-app-server/src/test/resources/BbsActionsTaskTestFiles/pnfWithoutLinks.json
@@ -0,0 +1,10 @@
+{
+ "pnf-name": "Nokia123",
+ "pnf-name2-source": "",
+ "pnf-id": "Nokia123",
+ "equip-type": "",
+ "equip-vendor": "",
+ "management-option": "",
+ "in-maint": false,
+ "resource-version": "1560153116694"
+}