X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=blueprints-processor%2Fadaptors%2Frest-adaptor-provider%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fccsdk%2Ffeatures%2Frest%2Fadaptor%2Fservice%2FGenericRestClientServiceTest.java;fp=blueprints-processor%2Fadaptors%2Frest-adaptor-provider%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fccsdk%2Ffeatures%2Frest%2Fadaptor%2Fservice%2FGenericRestClientServiceTest.java;h=0000000000000000000000000000000000000000;hb=032ce4ec7c3d7ac138555dfe980ca53ebbf39f01;hp=36599cc6f47f021a00164abf0d29239f0095c55b;hpb=4903545aae48b6b8169b8716ba5bce7f0cd8d7ba;p=ccsdk%2Ffeatures.git 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 deleted file mode 100644 index 36599cc6f..000000000 --- a/blueprints-processor/adaptors/rest-adaptor-provider/src/test/java/org/onap/ccsdk/features/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.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.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"); - } -}