aboutsummaryrefslogtreecommitdiffstats
path: root/so-sdn-clients/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'so-sdn-clients/src/test/java')
-rw-r--r--so-sdn-clients/src/test/java/org/onap/so/BaseIntegrationTest.java60
-rw-r--r--so-sdn-clients/src/test/java/org/onap/so/EmbeddedMariaDbConfig.java60
-rw-r--r--so-sdn-clients/src/test/java/org/onap/so/IntegrationTestSuite.java31
-rw-r--r--so-sdn-clients/src/test/java/org/onap/so/TestApplication.java43
-rw-r--r--so-sdn-clients/src/test/java/org/onap/so/UnitTestSuite.java32
-rw-r--r--so-sdn-clients/src/test/java/org/onap/so/client/sdn/common/SdnCommonTasksTest.java104
-rw-r--r--so-sdn-clients/src/test/java/org/onap/so/client/sdnc/SDNCClientIT.java79
-rw-r--r--so-sdn-clients/src/test/java/org/onap/so/client/sdno/SDNOHealthCheckClientTest.java94
-rw-r--r--so-sdn-clients/src/test/java/org/onap/so/client/sdno/SDNOValidatorIT.java124
-rw-r--r--so-sdn-clients/src/test/java/org/onap/so/client/sdno/SDNOValidatorImplTest.java56
10 files changed, 683 insertions, 0 deletions
diff --git a/so-sdn-clients/src/test/java/org/onap/so/BaseIntegrationTest.java b/so-sdn-clients/src/test/java/org/onap/so/BaseIntegrationTest.java
new file mode 100644
index 0000000000..9c25b1f002
--- /dev/null
+++ b/so-sdn-clients/src/test/java/org/onap/so/BaseIntegrationTest.java
@@ -0,0 +1,60 @@
+/*-
+ * ============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;
+
+import java.io.IOException;
+import java.io.InputStream;
+import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.onap.so.client.sdnc.SDNCClient;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.mock.mockito.SpyBean;
+import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringRunner;
+import com.github.tomakehurst.wiremock.WireMockServer;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@ActiveProfiles("test")
+@ContextConfiguration
+@AutoConfigureWireMock(port = 0)
+public abstract class BaseIntegrationTest {
+
+ @Value("${wiremock.server.port}")
+ protected String wireMockPort;
+
+ @SpyBean
+ protected SDNCClient SPY_sdncClient;
+
+ @Autowired
+ protected WireMockServer wireMockServer;
+
+ @Before
+ public void baseTestBefore() {
+ wireMockServer.resetAll();
+ }
+
+}
+
+
diff --git a/so-sdn-clients/src/test/java/org/onap/so/EmbeddedMariaDbConfig.java b/so-sdn-clients/src/test/java/org/onap/so/EmbeddedMariaDbConfig.java
new file mode 100644
index 0000000000..62d9ecee44
--- /dev/null
+++ b/so-sdn-clients/src/test/java/org/onap/so/EmbeddedMariaDbConfig.java
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2018 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;
+
+import ch.vorburger.exec.ManagedProcessException;
+import ch.vorburger.mariadb4j.DBConfigurationBuilder;
+import ch.vorburger.mariadb4j.springframework.MariaDB4jSpringService;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.jdbc.DataSourceBuilder;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Profile;
+import javax.sql.DataSource;
+
+@Configuration
+@Profile({"test"})
+public class EmbeddedMariaDbConfig {
+
+ @Bean
+ MariaDB4jSpringService mariaDB4jSpringService() {
+ MariaDB4jSpringService service = new MariaDB4jSpringService();
+
+
+ service.getConfiguration().addArg("--lower_case_table_names=1");
+ return service;
+ }
+
+ @Bean
+ DataSource dataSource(MariaDB4jSpringService mariaDB4jSpringService,
+ @Value("${mariaDB4j.databaseName}") String databaseName,
+ @Value("${spring.datasource.username}") String datasourceUsername,
+ @Value("${spring.datasource.password}") String datasourcePassword,
+ @Value("${spring.datasource.driver-class-name}") String datasourceDriver) throws ManagedProcessException {
+ // Create our database with default root user and no password
+ mariaDB4jSpringService.getDB().createDB(databaseName);
+
+ DBConfigurationBuilder config = mariaDB4jSpringService.getConfiguration();
+
+ return DataSourceBuilder.create().username(datasourceUsername).password(datasourcePassword)
+ .url(config.getURL(databaseName)).driverClassName(datasourceDriver).build();
+ }
+}
diff --git a/so-sdn-clients/src/test/java/org/onap/so/IntegrationTestSuite.java b/so-sdn-clients/src/test/java/org/onap/so/IntegrationTestSuite.java
new file mode 100644
index 0000000000..50bbc1845f
--- /dev/null
+++ b/so-sdn-clients/src/test/java/org/onap/so/IntegrationTestSuite.java
@@ -0,0 +1,31 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2018 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;
+
+import org.junit.runner.RunWith;
+import com.googlecode.junittoolbox.SuiteClasses;
+import com.googlecode.junittoolbox.WildcardPatternSuite;
+
+@RunWith(WildcardPatternSuite.class)
+@SuiteClasses({"**/*IT.class"})
+public class IntegrationTestSuite {
+
+}
diff --git a/so-sdn-clients/src/test/java/org/onap/so/TestApplication.java b/so-sdn-clients/src/test/java/org/onap/so/TestApplication.java
new file mode 100644
index 0000000000..fe965b4444
--- /dev/null
+++ b/so-sdn-clients/src/test/java/org/onap/so/TestApplication.java
@@ -0,0 +1,43 @@
+package org.onap.so;
+/*-
+ * ============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=========================================================
+ */
+
+
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.ComponentScan.Filter;
+import org.springframework.context.annotation.FilterType;
+import org.springframework.context.annotation.Profile;
+
+@SpringBootApplication
+@Profile("test")
+@ComponentScan(basePackages = {"org.onap.so"},
+ excludeFilters = {@Filter(type = FilterType.ANNOTATION, classes = SpringBootApplication.class)})
+public class TestApplication {
+ public static void main(String... args) {
+ SpringApplication.run(TestApplication.class, args);
+ System.getProperties().setProperty("mso.db", "MARIADB");
+ System.getProperties().setProperty("server.name", "Springboot");
+
+
+ }
+}
diff --git a/so-sdn-clients/src/test/java/org/onap/so/UnitTestSuite.java b/so-sdn-clients/src/test/java/org/onap/so/UnitTestSuite.java
new file mode 100644
index 0000000000..890c81daeb
--- /dev/null
+++ b/so-sdn-clients/src/test/java/org/onap/so/UnitTestSuite.java
@@ -0,0 +1,32 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2018 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;
+
+
+import org.junit.runner.RunWith;
+import com.googlecode.junittoolbox.SuiteClasses;
+import com.googlecode.junittoolbox.WildcardPatternSuite;
+
+@RunWith(WildcardPatternSuite.class)
+@SuiteClasses({"**/*Test.class"})
+public class UnitTestSuite {
+
+}
diff --git a/so-sdn-clients/src/test/java/org/onap/so/client/sdn/common/SdnCommonTasksTest.java b/so-sdn-clients/src/test/java/org/onap/so/client/sdn/common/SdnCommonTasksTest.java
new file mode 100644
index 0000000000..a8816e1b04
--- /dev/null
+++ b/so-sdn-clients/src/test/java/org/onap/so/client/sdn/common/SdnCommonTasksTest.java
@@ -0,0 +1,104 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2018 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.sdn.common;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import java.util.LinkedHashMap;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onap.so.client.exception.BadResponseException;
+import org.onap.so.client.exception.MapperException;
+import org.onap.so.client.sdnc.SdnCommonTasks;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+
+
+public class SdnCommonTasksTest {
+
+
+ SdnCommonTasks sdnCommonTasks = new SdnCommonTasks();
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ @Test
+ public void buildJsonRequestTest() throws MapperException {
+ String jsonStr = sdnCommonTasks.buildJsonRequest("");
+ Assert.assertNotNull(jsonStr);
+ }
+
+ @Test
+ public void buildJsonRequestTestException() throws MapperException {
+ expectedException.expect(MapperException.class);
+ sdnCommonTasks.buildJsonRequest(new Object());
+ }
+
+ @Test
+ public void getHttpHeadersTest() {
+ HttpHeaders result = sdnCommonTasks.getHttpHeaders("auth", true);
+
+ assertEquals("auth", result.getFirst("Authorization"));
+ assertEquals(MediaType.APPLICATION_JSON.toString(), result.getFirst("Content-Type"));
+ assertEquals(MediaType.APPLICATION_JSON.toString(), result.getFirst("Accept"));
+ }
+
+ @Test
+ public void getHttpHeadersGetRequestTest() {
+ HttpHeaders result = sdnCommonTasks.getHttpHeaders("auth", false);
+
+ assertEquals("auth", result.getFirst("Authorization"));
+ assertEquals(MediaType.APPLICATION_JSON.toString(), result.getFirst("Accept"));
+ assertFalse(result.containsKey("Content-Type"));
+ }
+
+ @Test
+ public void validateSDNResponseTest() throws BadResponseException {
+ String jsonResponse = "{\"output\":{\"response-code\":\"0\",\"response-message\":\"success\"}}";
+ LinkedHashMap<String, Object> responseMap = new LinkedHashMap<>();
+ LinkedHashMap<String, Object> output = new LinkedHashMap<>();
+ output.put("response-code", "0");
+ output.put("response-message", "success");
+ responseMap.put("output", output);
+ assertEquals(jsonResponse, sdnCommonTasks.validateSDNResponse(responseMap));
+ }
+
+ @Test
+ public void validateSDNResponseTestException() throws BadResponseException {
+ expectedException.expect(BadResponseException.class);
+ LinkedHashMap responseMap = new LinkedHashMap();
+ Assert.assertNotNull(sdnCommonTasks.validateSDNResponse(responseMap));
+ }
+
+ @Test
+ public void validateSDNResponseTestRespCodeNot200() throws BadResponseException {
+ expectedException.expect(BadResponseException.class);
+ LinkedHashMap<String, Object> responseMap = new LinkedHashMap<>();
+ LinkedHashMap<String, Object> output = new LinkedHashMap<>();
+ output.put("response-code", "300");
+ output.put("response-message", "Failed");
+ responseMap.put("output", output);
+ sdnCommonTasks.validateSDNResponse(responseMap);
+ }
+
+}
diff --git a/so-sdn-clients/src/test/java/org/onap/so/client/sdnc/SDNCClientIT.java b/so-sdn-clients/src/test/java/org/onap/so/client/sdnc/SDNCClientIT.java
new file mode 100644
index 0000000000..0b338bde1d
--- /dev/null
+++ b/so-sdn-clients/src/test/java/org/onap/so/client/sdnc/SDNCClientIT.java
@@ -0,0 +1,79 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2018 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.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.post;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import org.junit.Test;
+import org.onap.so.BaseIntegrationTest;
+import org.onap.so.client.exception.BadResponseException;
+import org.onap.so.client.exception.MapperException;
+import org.onap.so.client.sdnc.endpoint.SDNCTopology;
+import org.skyscreamer.jsonassert.JSONAssert;
+
+public class SDNCClientIT extends BaseIntegrationTest {
+ private final static String JSON_FILE_LOCATION = "src/test/resources/__files/";
+
+ @Test
+ public void getTest() throws BadResponseException, MapperException, IOException {
+ String responseJson =
+ new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "SDNCClientGetResponse.json")));
+ String queryLink = "/topologyQuery";
+
+ wireMockServer.stubFor(get(urlEqualTo(queryLink)).willReturn(
+ aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(responseJson)));
+ String response = SPY_sdncClient.get(queryLink);
+ JSONAssert.assertEquals(responseJson, response, false);
+ }
+
+ @Test(expected = BadResponseException.class)
+ public void post404Test() throws BadResponseException, MapperException, IOException {
+ String responseJson =
+ new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "SDNCClientPut404Response.json")));
+
+ String queryLink = "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation/";
+
+ wireMockServer.stubFor(post(urlMatching(queryLink)).willReturn(
+ aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(responseJson)));
+
+ SPY_sdncClient.post("", SDNCTopology.NETWORK);
+ }
+
+ @Test
+ public void post200Test() throws BadResponseException, MapperException, IOException {
+ String responseJson =
+ new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "SDNCClientPut200Response.json")));
+
+ String queryLink = "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation/";
+
+ wireMockServer.stubFor(post(urlMatching(queryLink)).willReturn(
+ aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(responseJson)));
+
+ String response = SPY_sdncClient.post("", SDNCTopology.NETWORK);
+ JSONAssert.assertEquals(responseJson, response, true);
+ }
+}
diff --git a/so-sdn-clients/src/test/java/org/onap/so/client/sdno/SDNOHealthCheckClientTest.java b/so-sdn-clients/src/test/java/org/onap/so/client/sdno/SDNOHealthCheckClientTest.java
new file mode 100644
index 0000000000..7345b8161b
--- /dev/null
+++ b/so-sdn-clients/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/__files/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/so-sdn-clients/src/test/java/org/onap/so/client/sdno/SDNOValidatorIT.java b/so-sdn-clients/src/test/java/org/onap/so/client/sdno/SDNOValidatorIT.java
new file mode 100644
index 0000000000..8d2993ec43
--- /dev/null
+++ b/so-sdn-clients/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/__files/sdno/client/";
+ 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/so-sdn-clients/src/test/java/org/onap/so/client/sdno/SDNOValidatorImplTest.java b/so-sdn-clients/src/test/java/org/onap/so/client/sdno/SDNOValidatorImplTest.java
new file mode 100644
index 0000000000..c2278c26f9
--- /dev/null
+++ b/so-sdn-clients/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");
+
+ }
+}