+++ /dev/null
-/*\r
- * Copyright © 2017-2018 AT&T Intellectual Property.\r
- * Modifications Copyright © 2018 IBM.\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.onap.ccsdk.features.rest.adaptor.service;\r
-\r
-import static org.powermock.api.mockito.PowerMockito.mock;\r
-import static org.powermock.api.mockito.PowerMockito.when;\r
-import static org.powermock.api.mockito.PowerMockito.whenNew;\r
-import org.junit.Assert;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.junit.runner.RunWith;\r
-import org.mockito.Matchers;\r
-import org.onap.ccsdk.features.rest.adaptor.ConfigRestAdaptorException;\r
-import org.powermock.core.classloader.annotations.PowerMockIgnore;\r
-import org.powermock.core.classloader.annotations.PrepareForTest;\r
-import org.powermock.modules.junit4.PowerMockRunner;\r
-import org.springframework.http.HttpMethod;\r
-import org.springframework.http.HttpStatus;\r
-import org.springframework.http.ResponseEntity;\r
-import org.springframework.web.client.RestTemplate;\r
-\r
-@SuppressWarnings("unchecked")\r
-@RunWith(PowerMockRunner.class)\r
-@PowerMockIgnore("javax.net.ssl.*")\r
-@PrepareForTest({AbstractConfigRestClientAdapter.class})\r
-public class GenericRestClientServiceTest {\r
-\r
- ConfigRestAdaptorService configRestAdaptorService;\r
-\r
- RestTemplate mockRestTemplate = mock(RestTemplate.class);\r
-\r
- String path = "path";\r
-\r
- @Before\r
- public void before() throws Exception {\r
- whenNew(RestTemplate.class).withAnyArguments().thenReturn(mockRestTemplate);\r
-\r
- String propertyDir = "src/test/resources";\r
- configRestAdaptorService = new ConfigRestAdaptorServiceImpl(propertyDir);\r
- }\r
-\r
- @Test\r
- public void testGetResource() throws Exception {\r
- String responseBody = "sampleBodyString";\r
- ResponseEntity<Object> response = new ResponseEntity<Object>(responseBody, HttpStatus.OK);\r
- when(mockRestTemplate.exchange(Matchers.endsWith(path), Matchers.eq(HttpMethod.GET), Matchers.any(),\r
- Matchers.any(Class.class))).thenReturn(response);\r
-\r
- String body = configRestAdaptorService.getResource("modelservice", path, String.class);\r
-\r
- Assert.assertEquals(responseBody, body);\r
- }\r
-\r
- @Test\r
- public void testPostResource() throws Exception {\r
- String responseBody = "sampleBodyString";\r
- ResponseEntity<Object> response = new ResponseEntity<Object>(responseBody, HttpStatus.OK);\r
- when(mockRestTemplate.exchange(Matchers.endsWith(path), Matchers.eq(HttpMethod.POST), Matchers.any(),\r
- Matchers.any(Class.class))).thenReturn(response);\r
-\r
- String body = configRestAdaptorService.postResource("modelservice", path, null, String.class);\r
-\r
- Assert.assertEquals(responseBody, body);\r
- }\r
-\r
- @Test\r
- public void testExchange() throws Exception {\r
- String responseBody = "sampleBodyString";\r
- ResponseEntity<Object> response = new ResponseEntity<Object>(responseBody, HttpStatus.OK);\r
- when(mockRestTemplate.exchange(Matchers.endsWith(path), Matchers.eq(HttpMethod.GET), Matchers.any(),\r
- Matchers.any(Class.class))).thenReturn(response);\r
-\r
- String body = configRestAdaptorService.exchangeResource("modelservice", path, null, String.class, "GET");\r
-\r
- Assert.assertEquals(responseBody, body);\r
- }\r
-\r
- @Test(expected = ConfigRestAdaptorException.class)\r
- public void testGetResourceError() throws Exception {\r
- ResponseEntity<Object> response = new ResponseEntity<Object>("", HttpStatus.INTERNAL_SERVER_ERROR);\r
- when(mockRestTemplate.getForEntity(Matchers.endsWith(path), Matchers.any())).thenReturn(response);\r
-\r
- configRestAdaptorService.getResource("modelservice", path, String.class);\r
- }\r
-\r
- @Test(expected = ConfigRestAdaptorException.class)\r
- public void testPostResourceError() throws Exception {\r
- ResponseEntity<Object> response = new ResponseEntity<Object>("", HttpStatus.INTERNAL_SERVER_ERROR);\r
- when(mockRestTemplate.postForEntity(Matchers.endsWith(path), Matchers.anyObject(), Matchers.any()))\r
- .thenReturn(response);\r
-\r
- configRestAdaptorService.postResource("modelservice", path, null, String.class);\r
- }\r
-\r
- @Test(expected = ConfigRestAdaptorException.class)\r
- public void testExchangeError() throws Exception {\r
- ResponseEntity<Object> response = new ResponseEntity<Object>("", HttpStatus.INTERNAL_SERVER_ERROR);\r
- when(mockRestTemplate.exchange(Matchers.endsWith(path), Matchers.eq(HttpMethod.GET), Matchers.any(),\r
- Matchers.any(Class.class))).thenReturn(response);\r
-\r
- configRestAdaptorService.exchangeResource("modelservice", path, null, String.class, "GET");\r
- }\r
-}\r