aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSingal, Kapil (ks220y) <ks220y@att.com>2018-09-04 13:24:11 -0400
committerSingal, Kapil (ks220y) <ks220y@att.com>2018-09-04 13:24:11 -0400
commitbdfac35395b153ed239b84f6095f559ba2d1fa50 (patch)
treebce45a2f44ca94296a010c13c487a2b92881f56f
parent7d05e51e3c9d1eeb799c4255f3dea2533e2002d8 (diff)
SDN Controller Blueprints Rest Adaptor
Creating SDN Controller Blueprints Rest Adaptor Junit Tests Change-Id: Id388b0905d570a75b6842cc69b52f2d26e3b060e Issue-ID: CCSDK-512 Signed-off-by: Singal, Kapil (ks220y) <ks220y@att.com>
-rw-r--r--blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/service/AbstractConfigRestClientAdapterTest.java53
-rw-r--r--blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/service/GenericRestClientServiceTest.java116
-rw-r--r--blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/service/SSLClientServiceTest.java116
-rw-r--r--blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/utils/RestTemplateFactoryTest.java32
-rw-r--r--blueprints-processor/adaptors/rest-adaptor-provider/src/test/resources/config-rest-adaptor.properties29
-rw-r--r--blueprints-processor/adaptors/rest-adaptor-provider/src/test/resources/keystore.client.p12bin0 -> 1456 bytes
-rw-r--r--blueprints-processor/adaptors/rest-adaptor-provider/src/test/resources/truststore.client.jksbin0 -> 1228 bytes
7 files changed, 346 insertions, 0 deletions
diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/service/AbstractConfigRestClientAdapterTest.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/service/AbstractConfigRestClientAdapterTest.java
new file mode 100644
index 000000000..e698567a0
--- /dev/null
+++ b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/service/AbstractConfigRestClientAdapterTest.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * 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.
+ */
+
+package org.onap.ccsdk.config.rest.adaptor.service;
+
+import java.io.FileInputStream;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.stream.Collectors;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class AbstractConfigRestClientAdapterTest {
+
+ Map<String, String> properties = new HashMap<>();
+
+ @Before
+ public void setup() throws Exception {
+ String propertyfile = "src/test/resources/config-rest-adaptor.properties";
+
+ Properties restProperties = new Properties();
+ restProperties.load(new FileInputStream(propertyfile));
+
+ properties.putAll(restProperties.entrySet().stream()
+ .collect(Collectors.toMap(e -> e.getKey().toString(), e -> e.getValue().toString())));
+ }
+
+ @Test
+ public void testInitGenericRestClient() throws Exception {
+ ConfigRestClientServiceAdapter genericRestClient = new GenericRestClientAdapterImpl(properties, "modelservice");
+ Assert.assertNotNull(genericRestClient);
+ }
+
+ @Test
+ public void testInitSSLClient() throws Exception {
+ ConfigRestClientServiceAdapter sslClient = new SSLRestClientAdapterImpl(properties, "aai");
+ Assert.assertNotNull(sslClient);
+ }
+
+}
diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/service/GenericRestClientServiceTest.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/service/GenericRestClientServiceTest.java
new file mode 100644
index 000000000..65a90429d
--- /dev/null
+++ b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/service/GenericRestClientServiceTest.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * 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.
+ */
+
+package org.onap.ccsdk.config.rest.adaptor.service;
+
+import static org.powermock.api.mockito.PowerMockito.mock;
+import static org.powermock.api.mockito.PowerMockito.when;
+import static org.powermock.api.mockito.PowerMockito.whenNew;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mockito;
+import org.onap.ccsdk.config.rest.adaptor.ConfigRestAdaptorException;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.RestTemplate;
+
+@SuppressWarnings("unchecked")
+@RunWith(PowerMockRunner.class)
+@PowerMockIgnore("javax.net.ssl.*")
+@PrepareForTest({AbstractConfigRestClientAdapter.class})
+public class GenericRestClientServiceTest {
+
+ ConfigRestAdaptorService configRestAdaptorService;
+
+ RestTemplate mockRestTemplate = mock(RestTemplate.class);
+
+ String path = "path";
+
+ @Before
+ public void before() throws Exception {
+ whenNew(RestTemplate.class).withAnyArguments().thenReturn(mockRestTemplate);
+
+ String propertyDir = "src/test/resources";
+ configRestAdaptorService = new ConfigRestAdaptorServiceImpl(propertyDir);
+ }
+
+ @Test
+ public void testGetResource() throws Exception {
+ String responseBody = "sampleBodyString";
+ ResponseEntity<Object> response = new ResponseEntity<Object>(responseBody, HttpStatus.OK);
+ when(mockRestTemplate.exchange(Matchers.endsWith(path), Matchers.eq(HttpMethod.GET), Matchers.any(),
+ Matchers.any(Class.class))).thenReturn(response);
+
+ String body = configRestAdaptorService.getResource("modelservice", path, String.class);
+
+ Assert.assertEquals(responseBody, body);
+ }
+
+ @Test
+ public void testPostResource() throws Exception {
+ String responseBody = "sampleBodyString";
+ ResponseEntity<Object> response = new ResponseEntity<Object>(responseBody, HttpStatus.OK);
+ when(mockRestTemplate.exchange(Matchers.endsWith(path), Matchers.eq(HttpMethod.POST), Matchers.any(),
+ Matchers.any(Class.class))).thenReturn(response);
+
+ String body = configRestAdaptorService.postResource("modelservice", path, null, String.class);
+
+ Assert.assertEquals(responseBody, body);
+ }
+
+ @Test
+ public void testExchange() throws Exception {
+ String responseBody = "sampleBodyString";
+ ResponseEntity<Object> response = new ResponseEntity<Object>(responseBody, HttpStatus.OK);
+ when(mockRestTemplate.exchange(Matchers.endsWith(path), Matchers.eq(HttpMethod.GET), Matchers.any(),
+ Matchers.any(Class.class))).thenReturn(response);
+
+ String body = configRestAdaptorService.exchangeResource("modelservice", path, null, String.class, "GET");
+
+ Assert.assertEquals(responseBody, body);
+ }
+
+ @Test(expected = ConfigRestAdaptorException.class)
+ public void testGetResourceError() throws Exception {
+ ResponseEntity<Object> response = new ResponseEntity<Object>("", HttpStatus.INTERNAL_SERVER_ERROR);
+ when(mockRestTemplate.getForEntity(Matchers.endsWith(path), Matchers.any())).thenReturn(response);
+
+ configRestAdaptorService.getResource("modelservice", path, String.class);
+ }
+
+ @Test(expected = ConfigRestAdaptorException.class)
+ public void testPostResourceError() throws Exception {
+ ResponseEntity<Object> response = new ResponseEntity<Object>("", HttpStatus.INTERNAL_SERVER_ERROR);
+ when(mockRestTemplate.postForEntity(Matchers.endsWith(path), Matchers.anyObject(), Matchers.any()))
+ .thenReturn(response);
+
+ configRestAdaptorService.postResource("modelservice", path, null, String.class);
+ }
+
+ @Test(expected = ConfigRestAdaptorException.class)
+ public void testExchangeError() throws Exception {
+ ResponseEntity<Object> response = new ResponseEntity<Object>("", HttpStatus.INTERNAL_SERVER_ERROR);
+ when(mockRestTemplate.exchange(Matchers.endsWith(path), Matchers.eq(HttpMethod.GET), Matchers.any(),
+ Matchers.any(Class.class))).thenReturn(response);
+
+ configRestAdaptorService.exchangeResource("modelservice", path, null, String.class, "GET");
+ }
+}
diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/service/SSLClientServiceTest.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/service/SSLClientServiceTest.java
new file mode 100644
index 000000000..4592de819
--- /dev/null
+++ b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/service/SSLClientServiceTest.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * 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.
+ */
+
+package org.onap.ccsdk.config.rest.adaptor.service;
+
+import static org.powermock.api.mockito.PowerMockito.mock;
+import static org.powermock.api.mockito.PowerMockito.when;
+import static org.powermock.api.mockito.PowerMockito.whenNew;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mockito;
+import org.onap.ccsdk.config.rest.adaptor.ConfigRestAdaptorException;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.RestTemplate;
+
+@SuppressWarnings("unchecked")
+@RunWith(PowerMockRunner.class)
+@PowerMockIgnore("javax.net.ssl.*")
+@PrepareForTest({AbstractConfigRestClientAdapter.class})
+public class SSLClientServiceTest {
+
+ ConfigRestAdaptorService configRestAdaptorService;
+
+ RestTemplate mockRestTemplate = mock(RestTemplate.class);
+
+ String path = "path";
+
+ @Before
+ public void before() throws Exception {
+ whenNew(RestTemplate.class).withAnyArguments().thenReturn(mockRestTemplate);
+
+ String propertyDir = "src/test/resources";
+ configRestAdaptorService = new ConfigRestAdaptorServiceImpl(propertyDir);
+ }
+
+ @Test
+ public void testGetResource() throws Exception {
+ String responseBody = "sampleBodyString";
+ ResponseEntity<Object> response = new ResponseEntity<Object>(responseBody, HttpStatus.OK);
+ when(mockRestTemplate.exchange(Matchers.endsWith(path), Matchers.eq(HttpMethod.GET), Matchers.any(),
+ Matchers.any(Class.class))).thenReturn(response);
+
+ String body = configRestAdaptorService.getResource("aai", path, String.class);
+
+ Assert.assertEquals(responseBody, body);
+ }
+
+ @Test
+ public void testPostResource() throws Exception {
+ String responseBody = "sampleBodyString";
+ ResponseEntity<Object> response = new ResponseEntity<Object>(responseBody, HttpStatus.OK);
+ when(mockRestTemplate.exchange(Matchers.endsWith(path), Matchers.eq(HttpMethod.POST), Matchers.any(),
+ Matchers.any(Class.class))).thenReturn(response);
+
+ String body = configRestAdaptorService.postResource("aai", path, null, String.class);
+
+ Assert.assertEquals(responseBody, body);
+ }
+
+ @Test
+ public void testExchange() throws Exception {
+ String responseBody = "sampleBodyString";
+ ResponseEntity<Object> response = new ResponseEntity<Object>(responseBody, HttpStatus.OK);
+ when(mockRestTemplate.exchange(Matchers.endsWith(path), Matchers.eq(HttpMethod.GET), Matchers.any(),
+ Matchers.any(Class.class))).thenReturn(response);
+
+ String body = configRestAdaptorService.exchangeResource("aai", path, null, String.class, "GET");
+
+ Assert.assertEquals(responseBody, body);
+ }
+
+ @Test(expected = ConfigRestAdaptorException.class)
+ public void testGetResourceError() throws Exception {
+ ResponseEntity<Object> response = new ResponseEntity<Object>("", HttpStatus.INTERNAL_SERVER_ERROR);
+ when(mockRestTemplate.getForEntity(Matchers.endsWith(path), Matchers.any())).thenReturn(response);
+
+ configRestAdaptorService.getResource("aai", path, String.class);
+ }
+
+ @Test(expected = ConfigRestAdaptorException.class)
+ public void testPostResourceError() throws Exception {
+ ResponseEntity<Object> response = new ResponseEntity<Object>("", HttpStatus.INTERNAL_SERVER_ERROR);
+ when(mockRestTemplate.postForEntity(Matchers.endsWith(path), Matchers.anyObject(), Matchers.any()))
+ .thenReturn(response);
+
+ configRestAdaptorService.postResource("aai", path, null, String.class);
+ }
+
+ @Test(expected = ConfigRestAdaptorException.class)
+ public void testExchangeError() throws Exception {
+ ResponseEntity<Object> response = new ResponseEntity<Object>("", HttpStatus.INTERNAL_SERVER_ERROR);
+ when(mockRestTemplate.exchange(Matchers.endsWith(path), Matchers.eq(HttpMethod.GET), Matchers.any(),
+ Matchers.any(Class.class))).thenReturn(response);
+
+ configRestAdaptorService.exchangeResource("aai", path, null, String.class, "GET");
+ }
+}
diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/utils/RestTemplateFactoryTest.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/utils/RestTemplateFactoryTest.java
new file mode 100644
index 000000000..a01630d62
--- /dev/null
+++ b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/utils/RestTemplateFactoryTest.java
@@ -0,0 +1,32 @@
+package org.onap.ccsdk.config.rest.adaptor.utils;
+
+import org.onap.ccsdk.config.rest.adaptor.ConfigRestAdaptorConstants;
+import org.onap.ccsdk.config.rest.adaptor.ConfigRestAdaptorException;
+import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorServiceImpl;
+
+@SuppressWarnings("squid:S2187")
+public class RestTemplateFactoryTest {
+
+ public static void main(String[] args) {
+
+ String propertyFile = RestTemplateFactoryTest.class.getClassLoader().getResource(".").getPath();
+ System.out.println(" Property : " + propertyFile);
+
+ try {
+ ConfigRestAdaptorServiceImpl configRestAdaptorServiceImpl = new ConfigRestAdaptorServiceImpl(propertyFile);
+ String restconfResponse = genericRestGetMDSALOperation(args, configRestAdaptorServiceImpl);
+ System.out.println("RestTemplateFactoryTest.main Completed with response :" + restconfResponse);
+ } catch (ConfigRestAdaptorException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static String genericRestGetMDSALOperation(String[] args,
+ ConfigRestAdaptorServiceImpl configRestAdaptorServiceImpl) throws ConfigRestAdaptorException {
+ String path = "config/Dummy-API:services/service-list/dummy-1234";
+ String restconfResponse = configRestAdaptorServiceImpl.getResource(ConfigRestAdaptorConstants.SELECTOR_RESTCONF,
+ path, String.class);
+ return restconfResponse;
+ }
+
+}
diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/test/resources/config-rest-adaptor.properties b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/resources/config-rest-adaptor.properties
new file mode 100644
index 000000000..725e48429
--- /dev/null
+++ b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/resources/config-rest-adaptor.properties
@@ -0,0 +1,29 @@
+#
+# Configuration file for SDNC Controller Module
+#
+
+org.onap.ccsdk.config.rest.adaptors.envtype=solo
+
+# Config Generator Microservices
+org.onap.ccsdk.config.rest.adaptors.modelservice.type=generic
+org.onap.ccsdk.config.rest.adaptors.modelservice.enable=true
+org.onap.ccsdk.config.rest.adaptors.modelservice.url=http://localhost:8080/configgenerator/service/
+org.onap.ccsdk.config.rest.adaptors.modelservice.user=admin
+org.onap.ccsdk.config.rest.adaptors.modelservice.passwd=admin
+
+# Generic RESTCONF Adaptor
+org.onap.ccsdk.config.rest.adaptors.restconf.type=generic
+org.onap.ccsdk.config.rest.adaptors.restconf.enable=true
+org.onap.ccsdk.config.rest.adaptors.restconf.user=admin
+org.onap.ccsdk.config.rest.adaptors.restconf.passwd=admin
+org.onap.ccsdk.config.rest.adaptors.restconf.url=http://localhost:8181/restconf/
+
+# SSL AAI Adaptor
+org.onap.ccsdk.config.rest.adaptors.aai.propertyfile=aai.properties
+org.onap.ccsdk.config.rest.adaptors.aai.type=ssl
+org.onap.ccsdk.config.rest.adaptors.aai.enable=true
+org.onap.ccsdk.config.rest.adaptors.aai.url=https://localhost:8443/onap-aai/
+org.onap.ccsdk.config.rest.adaptors.aai.ssl.trust=src/test/resources/truststore.client.jks
+org.onap.ccsdk.config.rest.adaptors.aai.ssl.trust.psswd=changeme
+org.onap.ccsdk.config.rest.adaptors.aai.ssl.key=src/test/resources/keystore.client.p12
+org.onap.ccsdk.config.rest.adaptors.aai.ssl.key.psswd=changeme
diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/test/resources/keystore.client.p12 b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/resources/keystore.client.p12
new file mode 100644
index 000000000..c28c8cb79
--- /dev/null
+++ b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/resources/keystore.client.p12
Binary files differ
diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/test/resources/truststore.client.jks b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/resources/truststore.client.jks
new file mode 100644
index 000000000..d38a5e57d
--- /dev/null
+++ b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/resources/truststore.client.jks
Binary files differ