diff options
author | Steve Smokowski <ss835w@att.com> | 2020-04-29 15:34:49 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-04-29 15:34:49 +0000 |
commit | 37a2d93feb1dc910e7b09443369083fd49766f89 (patch) | |
tree | 978967c265228a9166165c11a618d0e729896177 /bpmn/so-bpmn-tasks/src/test | |
parent | 23c402203aa8bba6fd2f93e9d95871a40f22b4ed (diff) | |
parent | 4f774eeef8c1797c7073754412535be47ea1a8d7 (diff) |
Merge "move aai-client into its own project"
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/test')
12 files changed, 450 insertions, 5 deletions
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNOHealthCheckResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNOHealthCheckResourcesTest.java index 265bb5d3b5..a2a1c8a949 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNOHealthCheckResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/SDNOHealthCheckResourcesTest.java @@ -21,9 +21,8 @@ package org.onap.so.client.orchestration; import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doReturn; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doReturn; import java.util.UUID; import org.junit.Before; import org.junit.Test; @@ -32,9 +31,9 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.onap.so.bpmn.common.data.TestDataSetup; -import org.onap.so.bpmn.common.InjectionHelper; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.client.helper.TasksInjectionHelper; import org.onap.so.client.sdno.SDNOValidator; @RunWith(MockitoJUnitRunner.Silent.class) @@ -49,7 +48,7 @@ public class SDNOHealthCheckResourcesTest extends TestDataSetup { protected SDNOValidator MOCK_sdnoValidator; @Mock - protected InjectionHelper MOCK_injectionHelper; + protected TasksInjectionHelper MOCK_injectionHelper; @Before public void before() { diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdno/SDNOHealthCheckClientTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdno/SDNOHealthCheckClientTest.java new file mode 100644 index 0000000000..750e578558 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdno/SDNOHealthCheckClientTest.java @@ -0,0 +1,94 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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.client.sdno; + +import static org.junit.Assert.assertEquals; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Optional; +import org.junit.Test; +import org.onap.so.client.sdno.beans.SDNO; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class SDNOHealthCheckClientTest { + + + + private final String fileLocation = "src/test/resources/org/onap/so/client/sdno/health-check/"; + private static final String userId = "test-user"; + private static final Optional<String> clliCode = Optional.of("test-clli"); + private static final String requestId = "test-request-id"; + private static final String configurationId = "test-configuration-id"; + private static final String interfaceId = "test-interface-id"; + + @Test + public void verfyLPortMirrorPreCheckRequest() throws IOException { + String content = this.getJson("custom-lport-mirror-pre-check-request.json"); + ObjectMapper mapper = new ObjectMapper(); + SDNO expected = mapper.readValue(content, SDNO.class); + SDNOHealthCheckClient client = new SDNOHealthCheckClient(); + String actual = + client.buildLPortMirrorCheckPreRequest(userId, requestId, clliCode, configurationId, interfaceId); + assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual); + } + + @Test + public void verfyLPortMirrorPostCheckRequest() throws IOException { + String content = this.getJson("custom-lport-mirror-post-check-request.json"); + ObjectMapper mapper = new ObjectMapper(); + SDNO expected = mapper.readValue(content, SDNO.class); + SDNOHealthCheckClient client = new SDNOHealthCheckClient(); + String actual = + client.buildLPortMirrorCheckPostRequest(userId, requestId, clliCode, configurationId, interfaceId); + assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual); + } + + + @Test + public void verifyPortMirrorPostCheckRequest() throws IOException { + String content = this.getJson("custom-port-mirror-post-check-request.json"); + ObjectMapper mapper = new ObjectMapper(); + SDNO expected = mapper.readValue(content, SDNO.class); + SDNOHealthCheckClient client = new SDNOHealthCheckClient(); + String actual = client.buildPortMirrorPostCheckRequest(userId, requestId, clliCode, configurationId); + + assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual); + + } + + @Test + public void verifyPortMirrorPreCheckRequest() throws IOException { + String content = this.getJson("custom-port-mirror-pre-check-request.json"); + ObjectMapper mapper = new ObjectMapper(); + SDNO expected = mapper.readValue(content, SDNO.class); + SDNOHealthCheckClient client = new SDNOHealthCheckClient(); + String actual = client.buildPortMirrorPreCheckRequest(userId, requestId, clliCode, configurationId); + + assertEquals("payloads are equal", mapper.writeValueAsString(expected), actual); + + } + + private String getJson(String filename) throws IOException { + return new String(Files.readAllBytes(Paths.get(fileLocation + filename))); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdno/SDNOValidatorIT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdno/SDNOValidatorIT.java new file mode 100644 index 0000000000..b91f83c1b7 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdno/SDNOValidatorIT.java @@ -0,0 +1,124 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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.client.sdno; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.UUID; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.onap.aai.domain.yang.GenericVnf; +import org.onap.so.BaseIntegrationTest; +import org.onap.so.client.dmaap.Consumer; +import org.onap.so.client.dmaap.exceptions.DMaaPConsumerFailure; +import org.onap.so.client.exceptions.SDNOException; +import org.onap.so.client.sdno.beans.SDNO; +import org.onap.so.client.sdno.dmaap.SDNOHealthCheckDmaapConsumer; +import com.fasterxml.jackson.databind.ObjectMapper; + + + +public class SDNOValidatorIT extends BaseIntegrationTest { + + + @Mock + private Consumer mrConsumer; + private SDNOHealthCheckDmaapConsumer dmaapConsumer; + private final String fileLocation = "src/test/resources/org/onap/so/client/sdno/"; + private final String uuid = "xyz123"; + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Before + public void setUpTests() { + MockitoAnnotations.initMocks(this); + + } + + @Test + public void success() throws IOException, Exception { + dmaapConsumer = spy(new SDNOHealthCheckDmaapConsumer()); + when(dmaapConsumer.getConsumer()).thenReturn(mrConsumer); + when(mrConsumer.fetch()) + .thenReturn(Arrays.asList(new String[] {getJson("response.json"), getJson("output-success.json")})); + + SDNOValidatorImpl validator = new SDNOValidatorImpl(); + SDNOValidatorImpl spy = spy(validator); + when(dmaapConsumer.getRequestId()).thenReturn("xyz123"); + doReturn(dmaapConsumer).when(spy).getConsumer(any(String.class)); + boolean result = spy.pollForResponse("xyz123"); + assertEquals("result is true", result, true); + } + + @Test + public void failure() throws IOException, Exception { + dmaapConsumer = spy(new SDNOHealthCheckDmaapConsumer()); + + when(dmaapConsumer.getConsumer()).thenReturn(mrConsumer); + when(mrConsumer.fetch()) + .thenReturn(Arrays.asList(new String[] {getJson("response.json"), getJson("output-failure.json")})); + + SDNOValidatorImpl validator = new SDNOValidatorImpl(); + SDNOValidatorImpl spy = spy(validator); + when(dmaapConsumer.getRequestId()).thenReturn("xyz123"); + doReturn(dmaapConsumer).when(spy).getConsumer(any(String.class)); + thrown.expect(SDNOException.class); + thrown.expectMessage(containsString("my error message")); + boolean result = spy.pollForResponse("xyz123"); + + } + + @Ignore + @Test + public void run() throws Exception { + SDNOValidatorImpl validator = new SDNOValidatorImpl(); + UUID uuid = UUID.randomUUID(); + GenericVnf vnf = new GenericVnf(); + vnf.setVnfId("test"); + vnf.setIpv4OamAddress("1.2.3.4"); + vnf.setNfRole("VPE"); + SDNO request = validator.buildRequestDiagnostic(vnf, uuid, "mechid"); + ObjectMapper mapper = new ObjectMapper(); + String json = mapper.writeValueAsString(request); + validator.submitRequest(json); + thrown.expect(DMaaPConsumerFailure.class); + boolean result = validator.pollForResponse(uuid.toString()); + System.out.println(json); + + } + + private String getJson(String filename) throws IOException { + return new String(Files.readAllBytes(Paths.get(fileLocation + filename))); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdno/SDNOValidatorImplTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdno/SDNOValidatorImplTest.java new file mode 100644 index 0000000000..c2278c26f9 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdno/SDNOValidatorImplTest.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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.client.sdno; + +import static org.junit.Assert.assertEquals; +import java.util.UUID; +import org.junit.Test; +import org.onap.aai.domain.yang.GenericVnf; +import org.onap.so.client.sdno.beans.RequestHealthDiagnostic; +import org.onap.so.client.sdno.beans.SDNO; + +public class SDNOValidatorImplTest { + + @Test + public void buildRequestDiagnosticTest() throws Exception { + SDNOValidatorImpl validator = new SDNOValidatorImpl(); + UUID uuid = UUID.randomUUID(); + GenericVnf vnf = new GenericVnf(); + vnf.setVnfName("VNFNAME"); + vnf.setVnfId("test"); + vnf.setIpv4OamAddress("1.2.3.4"); + vnf.setNfRole("VPE"); + SDNO request = validator.buildRequestDiagnostic(vnf, uuid, "mechid"); + assertEquals(request.getNodeType(), "VPE"); + assertEquals(request.getOperation(), "health-diagnostic"); + + RequestHealthDiagnostic innerRequest = request.getBody().getInput().getRequestHealthDiagnostic(); + assertEquals(innerRequest.getRequestClientName(), "MSO"); + assertEquals(innerRequest.getRequestNodeName(), "VNFNAME"); + assertEquals(innerRequest.getRequestNodeUuid(), "test"); + assertEquals(innerRequest.getRequestNodeType(), "VPE"); + assertEquals(innerRequest.getRequestNodeIp(), "1.2.3.4"); + assertEquals(innerRequest.getRequestUserId(), "mechid"); + assertEquals(innerRequest.getRequestId(), uuid.toString()); + assertEquals(innerRequest.getHealthDiagnosticCode(), "default"); + + } +} 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 199274e94c..b64fc3318b 100644 --- a/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml +++ b/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml @@ -205,7 +205,15 @@ spring: naming-strategy: org.hibernate.cfg.ImprovedNamingStrategy enable-lazy-load-no-trans: true database-platform: org.hibernate.dialect.MySQL5InnoDBDialect - +sdno: + health-check: + dmaap: + password: password + publisher: + topic: sdno.test-health-diagnostic-v02 + subscriber: + topic: sdno.test-health-diagnostic-v02 + username: username mariaDB4j: dataDir: port: 3307 diff --git a/bpmn/so-bpmn-tasks/src/test/resources/org/onap/so/client/sdno/health-check/custom-lport-mirror-post-check-request.json b/bpmn/so-bpmn-tasks/src/test/resources/org/onap/so/client/sdno/health-check/custom-lport-mirror-post-check-request.json new file mode 100644 index 0000000000..2c46b5a8cb --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/org/onap/so/client/sdno/health-check/custom-lport-mirror-post-check-request.json @@ -0,0 +1,27 @@ +{ + "body": { + "input": { + "request-hd-custom": { + "request-client-name": "MSO", + "request-user-id": "test-user", + "request-id": "test-request-id", + "health-diagnostic-code": "VROUTER000004", + "operation-type": "lport_mirroring_check", + "send-detailed-cmd-response": "false", + "aai-param-list": [ + { + "key": "configuration-id", + "value": "test-configuration-id" + }, + { + "key": "interface-id", + "value": "test-interface-id" + } + ] + } + } + }, + "operation": "health-diagnostic-custom", + "nodeLoc": "test-clli", + "nodeType": "VROUTER" +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-tasks/src/test/resources/org/onap/so/client/sdno/health-check/custom-lport-mirror-pre-check-request.json b/bpmn/so-bpmn-tasks/src/test/resources/org/onap/so/client/sdno/health-check/custom-lport-mirror-pre-check-request.json new file mode 100644 index 0000000000..bf168b0028 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/org/onap/so/client/sdno/health-check/custom-lport-mirror-pre-check-request.json @@ -0,0 +1,27 @@ +{ + "body": { + "input": { + "request-hd-custom": { + "request-client-name": "MSO", + "request-user-id": "test-user", + "request-id": "test-request-id", + "health-diagnostic-code": "VROUTER000003", + "operation-type": "lport_mirroring_check", + "send-detailed-cmd-response": "false", + "aai-param-list": [ + { + "key": "configuration-id", + "value": "test-configuration-id" + }, + { + "key": "interface-id", + "value": "test-interface-id" + } + ] + } + } + }, + "operation": "health-diagnostic-custom", + "nodeLoc": "test-clli", + "nodeType": "VROUTER" +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-tasks/src/test/resources/org/onap/so/client/sdno/health-check/custom-port-mirror-post-check-request.json b/bpmn/so-bpmn-tasks/src/test/resources/org/onap/so/client/sdno/health-check/custom-port-mirror-post-check-request.json new file mode 100644 index 0000000000..89e505e7d0 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/org/onap/so/client/sdno/health-check/custom-port-mirror-post-check-request.json @@ -0,0 +1,23 @@ +{ + "body": { + "input": { + "request-hd-custom": { + "request-client-name": "MSO", + "request-user-id": "test-user", + "request-id": "test-request-id", + "health-diagnostic-code": "VROUTER000004", + "operation-type": "mirroring_check", + "send-detailed-cmd-response": "false", + "aai-param-list": [ + { + "key": "configuration-id", + "value": "test-configuration-id" + } + ] + } + } + }, + "operation": "health-diagnostic-custom", + "nodeLoc": "test-clli", + "nodeType": "VROUTER" +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-tasks/src/test/resources/org/onap/so/client/sdno/health-check/custom-port-mirror-pre-check-request.json b/bpmn/so-bpmn-tasks/src/test/resources/org/onap/so/client/sdno/health-check/custom-port-mirror-pre-check-request.json new file mode 100644 index 0000000000..86897c8a1f --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/org/onap/so/client/sdno/health-check/custom-port-mirror-pre-check-request.json @@ -0,0 +1,23 @@ +{ + "body": { + "input": { + "request-hd-custom": { + "request-client-name": "MSO", + "request-user-id": "test-user", + "request-id": "test-request-id", + "health-diagnostic-code": "VROUTER000003", + "operation-type": "mirroring_check", + "send-detailed-cmd-response": "false", + "aai-param-list": [ + { + "key": "configuration-id", + "value": "test-configuration-id" + } + ] + } + } + }, + "operation": "health-diagnostic-custom", + "nodeLoc": "test-clli", + "nodeType": "VROUTER" +} diff --git a/bpmn/so-bpmn-tasks/src/test/resources/org/onap/so/client/sdno/output-failure.json b/bpmn/so-bpmn-tasks/src/test/resources/org/onap/so/client/sdno/output-failure.json new file mode 100644 index 0000000000..8cf0a820cd --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/org/onap/so/client/sdno/output-failure.json @@ -0,0 +1,25 @@ +{ + "body": { + "output": { + "response-hd-custom": { + "response-status": "Failure", + "cached-data": "false", + "response-interface-type": "ansible", + "response-id": "191bf423-8473-4f7c-9fbb-e5dcbb40a12b", + "remote_end_time": "2017-10-13T14:51:53.490+0000", + "response-client-name": "MSO", + "user_id": "xxxxxx", + "remote_start_time": "2017-10-13T14:51:53.173+0000", + "error-message": "my error message", + "connection-failure-msg": "SDNO was unable to connect to an Ansible REST API server; Please ensure Ansible REST server is running" + } + } + }, + "result-info": { + "code": "200", + "status": "SUCCESS", + "request-id": "xyz123", + "client-name": "MSO", + "processing-host": "sdno-sdno-mtsnjv9sdno01" + } +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-tasks/src/test/resources/org/onap/so/client/sdno/output-success.json b/bpmn/so-bpmn-tasks/src/test/resources/org/onap/so/client/sdno/output-success.json new file mode 100644 index 0000000000..a6794327d8 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/org/onap/so/client/sdno/output-success.json @@ -0,0 +1,22 @@ +{ + "body": { + "output": { + "response-healthdiagnostic": { + "response-node-ip": "192.20.127.76", + "response-id": "xyz123", + "response-node-name": "mtvnjv9aads11", + "response-status": "Success", + "response-interface-type": "ssh", + "response-details-json": "result", + "cached-data": "false" + } + } + }, + "result-info": { + "client-name": "MSO", + "code": "200", + "processing-host": "sdno1-host01", + "request-id": "xyz123", + "status": "SUCCESS" + } +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-tasks/src/test/resources/org/onap/so/client/sdno/response.json b/bpmn/so-bpmn-tasks/src/test/resources/org/onap/so/client/sdno/response.json new file mode 100644 index 0000000000..2355e86938 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/org/onap/so/client/sdno/response.json @@ -0,0 +1,17 @@ +{ + + "result-info": { + + "client-name": "MSO", + + "code": "202", + + "processing-host": "sdno1-host01", + + "request-id": "xyz123", + + "status": "ACCEPTED" + + } + +}
\ No newline at end of file |