aboutsummaryrefslogtreecommitdiffstats
path: root/adapters/mso-oof-adapter/src/test
diff options
context:
space:
mode:
authorPriyadharshini <priyadharshini.b96@wipro.com>2020-08-27 04:05:09 -0700
committerPriyadharshini <priyadharshini.b96@wipro.com>2020-08-27 05:08:15 -0700
commiteb6d3d34320cb233ab68ee1e7621a3030b7f63bd (patch)
treed17a8a249d2dfe726cc7591561c2b70eab14773d /adapters/mso-oof-adapter/src/test
parent5c3ea2186fd45b6168ab9792c1554b09b37add2e (diff)
Implement so-oof-adapter to handle OOF Callback
- Add NSI/NST selection callback for Networkslicing Issue-ID: SO-3205 Signed-off-by: Priyadharshini <priyadharshini.b96@wipro.com> Change-Id: Ica88d503495949ecce8b897c3a990fbdaa5d4f0e
Diffstat (limited to 'adapters/mso-oof-adapter/src/test')
-rw-r--r--adapters/mso-oof-adapter/src/test/java/org/onap/so/adapters/oof/rest/OofCallbackHandlerTest.java85
-rw-r--r--adapters/mso-oof-adapter/src/test/java/org/onap/so/adapters/oof/rest/OofClientTest.java86
-rw-r--r--adapters/mso-oof-adapter/src/test/java/org/onap/so/adapters/oof/utils/OofUtilsTest.java76
-rw-r--r--adapters/mso-oof-adapter/src/test/resources/testInputs/NsiSelectionOofRequest.json84
-rw-r--r--adapters/mso-oof-adapter/src/test/resources/testInputs/NsiSelectionResponse.json20
5 files changed, 351 insertions, 0 deletions
diff --git a/adapters/mso-oof-adapter/src/test/java/org/onap/so/adapters/oof/rest/OofCallbackHandlerTest.java b/adapters/mso-oof-adapter/src/test/java/org/onap/so/adapters/oof/rest/OofCallbackHandlerTest.java
new file mode 100644
index 0000000000..3a2f7f5e11
--- /dev/null
+++ b/adapters/mso-oof-adapter/src/test/java/org/onap/so/adapters/oof/rest/OofCallbackHandlerTest.java
@@ -0,0 +1,85 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Wipro Limited. 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.oof.rest;
+
+import static org.mockito.Mockito.when;
+import java.io.File;
+import java.io.IOException;
+import org.junit.Before;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import org.onap.so.adapters.oof.utils.OofUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.boot.test.web.client.TestRestTemplate;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.RestTemplate;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+
+@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
+class OofCallbackHandlerTest {
+
+ @Autowired
+ TestRestTemplate restTemplate;
+
+ @MockBean
+ OofUtils oofutils;
+
+ @MockBean
+ RestTemplate mockrestTemplate;
+
+ @Before
+ void prepareMocks() throws Exception {
+ ResponseEntity<Object> responseEntity = new ResponseEntity<>(HttpStatus.OK);
+ when(oofutils.getCamundaHeaders()).thenReturn(new HttpHeaders());
+ when(oofutils.getCamundaMsgUrl(Mockito.anyString(), Mockito.anyString())).thenReturn("oofurl");
+ when(mockrestTemplate.postForEntity(Mockito.anyString(), Mockito.any(), Mockito.any()))
+ .thenReturn(responseEntity);
+ }
+
+ @Test
+ void processCallbackTest() throws Exception {
+ Object request = prepareOofResponse();
+ HttpHeaders headers = new HttpHeaders();
+ headers.setContentType(MediaType.APPLICATION_JSON);
+ HttpEntity<Object> entity = new HttpEntity<Object>(request, headers);
+ ResponseEntity<String> response = restTemplate.postForEntity(
+ "/so/adapters/oof/callback/v1/NSISelectionResponse/d88da85c-d9e8-4f73-b837-3a72a431622a", entity,
+ String.class);
+ Assertions.assertEquals(HttpStatus.OK, response.getStatusCode());
+ }
+
+ private Object prepareOofResponse() throws IOException {
+ File file = new ClassPathResource("testInputs/NsiSelectionResponse.json").getFile();
+ ObjectMapper objectMapper = new ObjectMapper();
+ return objectMapper.readValue(file, Object.class);
+ }
+
+}
diff --git a/adapters/mso-oof-adapter/src/test/java/org/onap/so/adapters/oof/rest/OofClientTest.java b/adapters/mso-oof-adapter/src/test/java/org/onap/so/adapters/oof/rest/OofClientTest.java
new file mode 100644
index 0000000000..ff38a9af63
--- /dev/null
+++ b/adapters/mso-oof-adapter/src/test/java/org/onap/so/adapters/oof/rest/OofClientTest.java
@@ -0,0 +1,86 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Wipro Limited. 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.oof.rest;
+
+import static org.mockito.Mockito.when;
+import java.io.File;
+import java.io.IOException;
+import org.junit.Before;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.onap.so.adapters.oof.model.OofRequest;
+import org.onap.so.adapters.oof.utils.OofUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.boot.test.web.client.TestRestTemplate;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.RestTemplate;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
+class OofClientTest {
+
+ @Autowired
+ TestRestTemplate restTemplate;
+
+ @MockBean
+ OofUtils oofutils;
+
+ @MockBean
+ RestTemplate mockrestTemplate;
+
+ @Before
+ void prepareMocks() throws Exception {
+ ResponseEntity<Object> responseEntity = new ResponseEntity<>(HttpStatus.OK);
+ when(oofutils.getOofHttpHeaders()).thenReturn(new HttpHeaders());
+ when(oofutils.getOofurl(Mockito.anyString())).thenReturn("oofurl");
+ when(mockrestTemplate.postForEntity(Mockito.anyString(), Mockito.any(), Mockito.any()))
+ .thenReturn(responseEntity);
+ }
+
+ @Test
+ void callOofTest() throws Exception {
+ OofRequest request = prepareOofRequest();
+ System.out.println(request);
+ HttpHeaders headers = new HttpHeaders();
+ headers.setContentType(MediaType.APPLICATION_JSON);
+ HttpEntity<OofRequest> entity = new HttpEntity<OofRequest>(request, headers);
+ ResponseEntity<String> response = restTemplate.postForEntity("/so/adapters/oof/v1", entity, String.class);
+ Assertions.assertEquals(HttpStatus.OK, response.getStatusCode());
+ }
+
+ private OofRequest prepareOofRequest() throws IOException {
+ File file = new ClassPathResource("testInputs/NsiSelectionOofRequest.json").getFile();
+ ObjectMapper objectMapper = new ObjectMapper();
+ return objectMapper.readValue(file, OofRequest.class);
+ }
+
+
+}
diff --git a/adapters/mso-oof-adapter/src/test/java/org/onap/so/adapters/oof/utils/OofUtilsTest.java b/adapters/mso-oof-adapter/src/test/java/org/onap/so/adapters/oof/utils/OofUtilsTest.java
new file mode 100644
index 0000000000..e68fa10c3e
--- /dev/null
+++ b/adapters/mso-oof-adapter/src/test/java/org/onap/so/adapters/oof/utils/OofUtilsTest.java
@@ -0,0 +1,76 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Wipro Limited. 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.oof.utils;
+
+import static org.mockito.Mockito.when;
+import java.security.GeneralSecurityException;
+import javax.xml.bind.DatatypeConverter;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.onap.so.utils.CryptoUtils;
+import org.springframework.core.env.Environment;
+import org.springframework.http.HttpHeaders;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+
+@ExtendWith(SpringExtension.class)
+class OofUtilsTest {
+
+ @InjectMocks
+ OofUtils oofUtils;
+
+ @Mock
+ Environment env;
+
+ @Test
+ void testGetCamundaMsgUrl() {
+ when(env.getRequiredProperty(Mockito.anyString())).thenReturn("dummyString");
+ String camundamsgUrl = oofUtils.getCamundaMsgUrl("samplemessage", "sampleCorrelator");
+ Assertions.assertNotNull(camundamsgUrl);
+ }
+
+
+ void testGetCamundaHeaders() throws GeneralSecurityException {
+ when(env.getRequiredProperty(Mockito.anyString())).thenReturn("dummyString");
+ when(CryptoUtils.decrypt(Mockito.anyString(), Mockito.anyString())).thenReturn("decryptedString");
+ HttpHeaders headers = oofUtils.getCamundaHeaders();
+ Assertions.assertNotNull(headers);
+ }
+
+
+ @Test
+ void testGetOofHttpHeaders() throws Exception {
+ when(env.getRequiredProperty(Mockito.anyString())).thenReturn("dummyString");
+ HttpHeaders headers = oofUtils.getOofHttpHeaders();
+ Assertions.assertNotNull(headers);
+ }
+
+ @Test
+ void testGetOofurl() {
+ when(env.getRequiredProperty(Mockito.anyString())).thenReturn("dummyString");
+ String oofurl = oofUtils.getOofurl("/api/v1/");
+ Assertions.assertNotNull(oofurl);
+ }
+
+}
diff --git a/adapters/mso-oof-adapter/src/test/resources/testInputs/NsiSelectionOofRequest.json b/adapters/mso-oof-adapter/src/test/resources/testInputs/NsiSelectionOofRequest.json
new file mode 100644
index 0000000000..569aae9f38
--- /dev/null
+++ b/adapters/mso-oof-adapter/src/test/resources/testInputs/NsiSelectionOofRequest.json
@@ -0,0 +1,84 @@
+{
+ "apiPath":"/api/oof/selection/nsi/v1",
+ "requestDetails":{
+ "serviceProfile":{
+ "blob":"content"
+ },
+ "requestInfo":{
+ "transactionId":"d290f1ee-6c54-4b01-90e6-d701748f0851",
+ "requestId":"d290f1ee-6c54-4b01-90e6-d701748f0851",
+ "callbackUrl":"myDomain.com/myCallback",
+ "callbackHeader":{
+ "blob":"content"
+ },
+ "sourceId":"d290f1ee-6c54-4b01-90e6-d701748f0851",
+ "timeout":5,
+ "numSolutions":1
+ },
+ "NSTInfo":{
+ "UUID":"3fa85f64-5717-4562-b3fc-2c963f66afa1",
+ "invariantUUID":"7ua85f64-5717-4562-b3fc-2c963f66afa6",
+ "name":"embb-nst"
+ },
+ "NSSTInfo":[
+ {
+ "UUID":"3fa85f64-5717-4562-b3fc-2c963f66afa2",
+ "invariantUUID":"2fa85f64-5717-4562-b3fc-2c963f66afa6",
+ "name":"embb-an-nf"
+ },
+ {
+ "UUID":"3fa85f64-5717-4562-b3fc-2c963f66afa3",
+ "invariantUUID":"4fa85f64-5717-4562-b3fc-2c963f66afa6",
+ "name":"embb-cn"
+ },
+ {
+ "UUID":"3fa85f64-5717-4562-b3fc-2c963f66afa4",
+ "invariantUUID":"5ta85f64-5717-4562-b3fc-2c963f66afa6",
+ "name":"embb-tn-fh"
+ },
+ {
+ "UUID":"3fa85f64-5717-4562-b3fc-2c963f66afa5",
+ "invariantUUID":"6ya85f64-5717-4562-b3fc-2c963f66afa6",
+ "name":"embb-tn-mh"
+ },
+ {
+ "UUID":"3fa85f64-5717-4562-b3fc-2c963f66afa7",
+ "invariantUUID":"7ua85f64-5717-4562-b3fc-2c963f66afa6",
+ "name":"embb-tn-bh"
+ }
+ ],
+ "preferReuse":false,
+ "subnetCapabilities":[
+ {
+ "domainType":"AN-NF",
+ "capabilityDetails":{
+ "blob":"content"
+ }
+ },
+ {
+ "domainType":"CN",
+ "capabilityDetails":{
+ "blob":"content"
+ }
+ },
+ {
+ "domainType":"TN-FH",
+ "capabilityDetails":{
+ "blob":"content"
+ }
+ },
+ {
+ "domainType":"TN-MH",
+ "capabilityDetails":{
+ "blob":"content"
+ }
+ },
+ {
+ "domainType":"TN-BH",
+ "capabilityDetails":{
+ "blob":"content"
+ }
+ }
+ ]
+}
+} \ No newline at end of file
diff --git a/adapters/mso-oof-adapter/src/test/resources/testInputs/NsiSelectionResponse.json b/adapters/mso-oof-adapter/src/test/resources/testInputs/NsiSelectionResponse.json
new file mode 100644
index 0000000000..4ddca3eaf9
--- /dev/null
+++ b/adapters/mso-oof-adapter/src/test/resources/testInputs/NsiSelectionResponse.json
@@ -0,0 +1,20 @@
+{
+ "transactionId": "s4r0f1ee-6c54-4b01-90e6-d701748f0851",
+ "requestId": "r500f1ee-6c54-4b01-90e6-d701748f0851",
+ "requestStatus": "completed",
+ "solutions": [
+ {
+ "existingNSI": false,
+ "newNSISolution": {
+ "sliceProfiles": [
+ {
+ "domainType":"CN"
+ }
+ ],
+ "matchLevel": {
+ "blob": "content"
+ }
+ }
+ }
+ ]
+}