From 280a0f6c73ab1c1aed9ee87fbd053d01d3838d70 Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Wed, 12 Sep 2018 16:26:03 -0400 Subject: Controller Blueprints Nitrogen to Oxygen Migration Changing package structure from org.onap.ccsdk.config to org.onap.ccsdk.features Change-Id: I7d52b498f11ed892d547220cc4354298b6182c77 Issue-ID: CCSDK-560 Signed-off-by: Singal, Kapil (ks220y) --- .../AbstractConfigRestClientAdapterTest.java | 56 ---------- .../service/GenericRestClientServiceTest.java | 118 -------------------- .../rest/adaptor/service/SSLClientServiceTest.java | 118 -------------------- .../adaptor/utils/RestTemplateFactoryTest.java | 49 --------- .../AbstractConfigRestClientAdapterTest.java | 59 ++++++++++ .../service/GenericRestClientServiceTest.java | 121 +++++++++++++++++++++ .../rest/adaptor/service/SSLClientServiceTest.java | 121 +++++++++++++++++++++ .../adaptor/utils/RestTemplateFactoryTest.java | 49 +++++++++ .../test/resources/config-rest-adaptor.properties | 38 +++---- 9 files changed, 369 insertions(+), 360 deletions(-) delete mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/service/AbstractConfigRestClientAdapterTest.java delete mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/service/GenericRestClientServiceTest.java delete mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/service/SSLClientServiceTest.java delete mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/utils/RestTemplateFactoryTest.java create mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/features/rest/adaptor/service/AbstractConfigRestClientAdapterTest.java create mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/features/rest/adaptor/service/GenericRestClientServiceTest.java create mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/features/rest/adaptor/service/SSLClientServiceTest.java create mode 100644 blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/features/rest/adaptor/utils/RestTemplateFactoryTest.java (limited to 'blueprints-processor/adaptors/rest-adaptor-provider/src/test') 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 deleted file mode 100644 index 6c7f114eb..000000000 --- a/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/service/AbstractConfigRestClientAdapterTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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 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 deleted file mode 100644 index 7e7f52261..000000000 --- a/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/service/GenericRestClientServiceTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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.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 response = new ResponseEntity(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 response = new ResponseEntity(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 response = new ResponseEntity(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 response = new ResponseEntity("", 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 response = new ResponseEntity("", 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 response = new ResponseEntity("", 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 deleted file mode 100644 index a5e757213..000000000 --- a/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/service/SSLClientServiceTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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.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 response = new ResponseEntity(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 response = new ResponseEntity(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 response = new ResponseEntity(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 response = new ResponseEntity("", 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 response = new ResponseEntity("", 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 response = new ResponseEntity("", 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 deleted file mode 100644 index e1d0268e1..000000000 --- a/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/config/rest/adaptor/utils/RestTemplateFactoryTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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.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/java/org/onap/ccsdk/features/rest/adaptor/service/AbstractConfigRestClientAdapterTest.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/features/rest/adaptor/service/AbstractConfigRestClientAdapterTest.java new file mode 100644 index 000000000..2e091591b --- /dev/null +++ b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/features/rest/adaptor/service/AbstractConfigRestClientAdapterTest.java @@ -0,0 +1,59 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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.features.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; +import org.onap.ccsdk.features.rest.adaptor.service.ConfigRestClientServiceAdapter; +import org.onap.ccsdk.features.rest.adaptor.service.GenericRestClientAdapterImpl; +import org.onap.ccsdk.features.rest.adaptor.service.SSLRestClientAdapterImpl; + +public class AbstractConfigRestClientAdapterTest { + + Map 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/features/rest/adaptor/service/GenericRestClientServiceTest.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/features/rest/adaptor/service/GenericRestClientServiceTest.java new file mode 100644 index 000000000..f660cca10 --- /dev/null +++ b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/features/rest/adaptor/service/GenericRestClientServiceTest.java @@ -0,0 +1,121 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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.features.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.onap.ccsdk.features.rest.adaptor.ConfigRestAdaptorException; +import org.onap.ccsdk.features.rest.adaptor.service.AbstractConfigRestClientAdapter; +import org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorService; +import org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorServiceImpl; +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 response = new ResponseEntity(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 response = new ResponseEntity(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 response = new ResponseEntity(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 response = new ResponseEntity("", 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 response = new ResponseEntity("", 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 response = new ResponseEntity("", 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/features/rest/adaptor/service/SSLClientServiceTest.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/features/rest/adaptor/service/SSLClientServiceTest.java new file mode 100644 index 000000000..e8b3a02ed --- /dev/null +++ b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/features/rest/adaptor/service/SSLClientServiceTest.java @@ -0,0 +1,121 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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.features.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.onap.ccsdk.features.rest.adaptor.ConfigRestAdaptorException; +import org.onap.ccsdk.features.rest.adaptor.service.AbstractConfigRestClientAdapter; +import org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorService; +import org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorServiceImpl; +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 response = new ResponseEntity(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 response = new ResponseEntity(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 response = new ResponseEntity(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 response = new ResponseEntity("", 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 response = new ResponseEntity("", 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 response = new ResponseEntity("", 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/features/rest/adaptor/utils/RestTemplateFactoryTest.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/features/rest/adaptor/utils/RestTemplateFactoryTest.java new file mode 100644 index 000000000..cee91d297 --- /dev/null +++ b/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/features/rest/adaptor/utils/RestTemplateFactoryTest.java @@ -0,0 +1,49 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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.features.rest.adaptor.utils; + +import org.onap.ccsdk.features.rest.adaptor.ConfigRestAdaptorConstants; +import org.onap.ccsdk.features.rest.adaptor.ConfigRestAdaptorException; +import org.onap.ccsdk.features.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 index 4527e8977..22748259b 100644 --- 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 @@ -18,28 +18,28 @@ # Configuration file for SDNC Controller Module # -org.onap.ccsdk.config.rest.adaptors.envtype=solo +org.onap.ccsdk.features.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 +org.onap.ccsdk.features.rest.adaptors.modelservice.type=generic +org.onap.ccsdk.features.rest.adaptors.modelservice.enable=true +org.onap.ccsdk.features.rest.adaptors.modelservice.url=http://localhost:8080/configgenerator/service/ +org.onap.ccsdk.features.rest.adaptors.modelservice.user=admin +org.onap.ccsdk.features.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/ +org.onap.ccsdk.features.rest.adaptors.restconf.type=generic +org.onap.ccsdk.features.rest.adaptors.restconf.enable=true +org.onap.ccsdk.features.rest.adaptors.restconf.user=admin +org.onap.ccsdk.features.rest.adaptors.restconf.passwd=admin +org.onap.ccsdk.features.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 +org.onap.ccsdk.features.rest.adaptors.aai.propertyfile=aai.properties +org.onap.ccsdk.features.rest.adaptors.aai.type=ssl +org.onap.ccsdk.features.rest.adaptors.aai.enable=true +org.onap.ccsdk.features.rest.adaptors.aai.url=https://localhost:8443/onap-aai/ +org.onap.ccsdk.features.rest.adaptors.aai.ssl.trust=src/test/resources/truststore.client.jks +org.onap.ccsdk.features.rest.adaptors.aai.ssl.trust.psswd=changeme +org.onap.ccsdk.features.rest.adaptors.aai.ssl.key=src/test/resources/keystore.client.p12 +org.onap.ccsdk.features.rest.adaptors.aai.ssl.key.psswd=changeme -- cgit 1.2.3-korg