diff options
author | Eylon Malin <eylon.malin@intl.att.com> | 2019-10-03 08:17:28 +0300 |
---|---|---|
committer | Eylon Malin <eylon.malin@intl.att.com> | 2019-10-03 08:17:28 +0300 |
commit | 70998db210b9969a9012fcaba79198e69b9abb5b (patch) | |
tree | c1a12b25f75fa9e5c3604d6834e00a485569ee3d /vid-app-common | |
parent | ab9cd4374e918187907e19a57585bc57b72f1bc7 (diff) |
remove unused interface and unused methods
Issue-ID: VID-253
Signed-off-by: Eylon Malin <eylon.malin@intl.att.com>
Change-Id: I75b554a6221e9736bb8d360225c3d7e20e69a6ab
Diffstat (limited to 'vid-app-common')
4 files changed, 2 insertions, 334 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/RestMsoImplementation.java b/vid-app-common/src/main/java/org/onap/vid/mso/RestMsoImplementation.java index ae04dbcfd..91b288998 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/RestMsoImplementation.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/RestMsoImplementation.java @@ -38,16 +38,12 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.Response; import org.apache.commons.codec.binary.Base64; -import org.apache.http.HttpException; import org.eclipse.jetty.util.security.Password; import org.glassfish.jersey.client.ClientProperties; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.onap.vid.aai.ExceptionWithRequestInfo; import org.onap.vid.aai.util.HttpClientMode; import org.onap.vid.aai.util.HttpsAuthClient; import org.onap.vid.client.HttpBasicClient; -import org.onap.vid.exceptions.GenericUncheckedException; -import org.onap.vid.mso.rest.RestInterface; import org.onap.vid.utils.Logging; import org.onap.vid.utils.SystemPropertiesWrapper; import org.springframework.beans.factory.annotation.Autowired; @@ -56,7 +52,7 @@ import org.springframework.http.HttpMethod; /** * Created by pickjonathan on 26/06/2017. */ -public class RestMsoImplementation implements RestInterface { +public class RestMsoImplementation { /** @@ -139,52 +135,6 @@ public class RestMsoImplementation implements RestInterface { return commonHeaders; } - public <T> RestObjectWithRequestInfo<T> Get(T t, String path, RestObject<T> restObject, boolean warpException) { - String methodName = "Get"; - - logger.debug(EELFLoggerDelegate.debugLogger, methodName + START_LOG); - - String url = null; - String rawData = null; - Integer status = null; - - try { - restObject.set(t); - url = systemProperties.getProperty(MsoProperties.MSO_SERVER_URL) + path; - - MultivaluedHashMap<String, Object> commonHeaders = initMsoClient(); - loggingService.logRequest(outgoingRequestsLogger, HttpMethod.GET, url); - final Response cres = client.target(url) - .request() - .accept(APPLICATION_JSON) - .headers(commonHeaders) - .get(); - loggingService.logResponse(outgoingRequestsLogger, HttpMethod.GET, url, cres); - - cres.bufferEntity(); - status = cres.getStatus(); - rawData = cres.readEntity(String.class); - - restObject.setStatusCode(status); - - if (status == 200 || status == 202) { - t = (T) cres.readEntity(t.getClass()); - restObject.set(t); - logger.debug(EELFLoggerDelegate.debugLogger, methodName + REST_API_SUCCESSFULL_LOG); - - } else { - throw new GenericUncheckedException(new HttpException(methodName + WITH_STATUS + status + " (200 or 202 expected), url= " + url)); - } - - logger.debug(EELFLoggerDelegate.debugLogger, methodName + " received status=" + status); - - return new RestObjectWithRequestInfo<>(HttpMethod.GET, url, restObject, status, rawData); - } catch (RuntimeException e) { - throw warpException ? new ExceptionWithRequestInfo(HttpMethod.GET, url, rawData, status, e) : e; - } - } - - @Override public <T> RestObject<T> GetForObject(String path, Class<T> clazz) { final String methodName = getMethodName(); logger.debug(EELFLoggerDelegate.debugLogger, "start {}->{}({}, {})", getMethodCallerName(), methodName, path, clazz); @@ -219,17 +169,6 @@ public class RestMsoImplementation implements RestInterface { return restCall(HttpMethod.POST, clazz, requestDetails, path); } - public <T> RestObject<T> DeleteForObject(Object requestDetails, String path, Class<T> clazz) { - logger.debug(EELFLoggerDelegate.debugLogger, REST_MSG_TEMPLATE, getMethodCallerName(), getMethodName(), requestDetails, path, clazz); - return restCall(HttpMethod.DELETE, clazz, requestDetails, path); - } - - @Override - public void Post(String t, Object r, String path, RestObject<String> restObject) { - logger.debug(EELFLoggerDelegate.debugLogger, REST_MSG_TEMPLATE, getMethodCallerName(), getMethodName(), t.getClass(), r, path); - restObject.copyFrom(restCall(HttpMethod.POST, String.class, r, path)); - } - public Invocation.Builder prepareClient(String path, String methodName) { MultivaluedHashMap<String, Object> commonHeaders = initMsoClient(); @@ -311,56 +250,4 @@ public class RestMsoImplementation implements RestInterface { return restObject; } - @Override - public <T> void Put(T t, org.onap.vid.changeManagement.RequestDetailsWrapper r, String path, RestObject<T> restObject) { - - String methodName = "Put"; - String url=""; - - logger.debug(EELFLoggerDelegate.debugLogger,"<== " + methodName + START_LOG); - - try { - - MultivaluedHashMap<String, Object> commonHeaders = initMsoClient(); - - url = systemProperties.getProperty(MsoProperties.MSO_SERVER_URL) + path; - loggingService.logRequest(outgoingRequestsLogger, HttpMethod.PUT, url, r); - // Change the content length - final Response cres = client.target(url) - .request() - .accept(APPLICATION_JSON) - .headers(commonHeaders) - //.header("content-length", 201) - .put(Entity.entity(r, MediaType.APPLICATION_JSON)); - - loggingService.logResponse(outgoingRequestsLogger, HttpMethod.PUT, url, cres); - - try { - t = (T) cres.readEntity(t.getClass()); - restObject.set(t); - } - catch ( Exception e ) { - logger.debug(EELFLoggerDelegate.debugLogger,"<== " + methodName + NO_RESPONSE_ENTITY_LOG - + e.getMessage()); - throw e; - } - - int status = cres.getStatus(); - restObject.setStatusCode (status); - - if ( status >= 200 && status <= 299 ) { - logger.info(EELFLoggerDelegate.errorLogger, "<== " + methodName + REST_API_SUCCESSFULL_LOG); - logger.debug(EELFLoggerDelegate.debugLogger,"<== " + methodName + REST_API_SUCCESSFULL_LOG); - - } else { - logger.debug(EELFLoggerDelegate.debugLogger,"<== " + methodName + WITH_STATUS +status+ URL_LOG +url); - } - - } catch (Exception e) - { - logger.debug(EELFLoggerDelegate.debugLogger,"<== " + methodName + WITH_URL_LOG +url+ EXCEPTION_LOG + e.toString()); - throw e; - - } - } } diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/rest/RestInterface.java b/vid-app-common/src/main/java/org/onap/vid/mso/rest/RestInterface.java deleted file mode 100644 index 2cc8e67b8..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/mso/rest/RestInterface.java +++ /dev/null @@ -1,69 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 - 2019 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.vid.mso.rest; - -import org.onap.vid.changeManagement.RequestDetailsWrapper; -import org.onap.vid.mso.RestObject; -import org.onap.vid.mso.RestObjectWithRequestInfo; - -/** - * Created by pickjonathan on 26/06/2017. - */ -public interface RestInterface { - - /** - * Gets the. - * - * @param <T> the generic type - * @param t the t - * @param path the path - * @param restObject the rest object - * @param warpException - * @throws Exception the exception - */ - <T> RestObjectWithRequestInfo<T> Get(T t, String path, RestObject<T> restObject, boolean warpException); - - /** - * Post. - * - * @param t the t - * @param r the r - * @param path the path - * @param restObject the rest object - * @throws Exception the exception - */ - void Post(String t, Object r, String path, RestObject<String> restObject); - - /** - * Put. - * - * @param <T> the generic type - * @param t the t - * @param r the r - * @param path the path - * @param restObject the rest object - * @throws Exception the exception - */ - <T> void Put(T t, RequestDetailsWrapper r, String path, RestObject<T> restObject); - - <T> RestObject<T> GetForObject(String path, Class<T> clazz); - -} diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/RestMsoImplementationTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/RestMsoImplementationTest.java index ea83fde29..792435002 100644 --- a/vid-app-common/src/test/java/org/onap/vid/mso/RestMsoImplementationTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/mso/RestMsoImplementationTest.java @@ -43,8 +43,6 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.onap.vid.aai.util.HttpClientMode; import org.onap.vid.aai.util.HttpsAuthClient; -import org.onap.vid.changeManagement.RequestDetailsWrapper; -import org.onap.vid.exceptions.GenericUncheckedException; import org.onap.vid.mso.rest.RequestDetails; import org.onap.vid.utils.Logging; import org.onap.vid.utils.SystemPropertiesWrapper; @@ -105,46 +103,6 @@ public class RestMsoImplementationTest { assertThat(result).doesNotContainKey("notExistingKey"); } - @Test - public void shouldProperlyGetRestObjectWithRequestInfo() { - // given - RestObject<HttpRequest> restObject = new RestObject<>(); - - prepareMocks(rawData, HttpStatus.ACCEPTED.value(),""); - - // when - RestObjectWithRequestInfo<HttpRequest> response = restMsoImplementation.Get(httpRequest, path, restObject,false); - - // then - assertThat(response.getRequestedUrl()).contains(path); - assertThat(response.getRawData()).isEqualTo(rawData); - assertThat(response.getHttpCode()).isEqualTo(HttpStatus.ACCEPTED.value()); - assertThat(response.getHttpMethod()).isEqualTo(HttpMethod.GET); - } - - @Test( expectedExceptions = GenericUncheckedException.class) - public void shouldThrowExceptionWhenGetRestObjectWithRequestInfoGetsWrongStatus() { - // given - RestObject<HttpRequest> restObject = new RestObject<>(); - - prepareMocks("",HttpStatus.BAD_REQUEST.value(),""); - - // when - restMsoImplementation.Get(httpRequest, "", restObject,false); - } - - @Test( expectedExceptions = MsoTestException.class) - public void shouldThrowExceptionWhenGetRestObjectWithRequestInfoGetsWrongParameters() { - // given - RestObject<HttpRequest> restObject = new RestObject<>(); - - prepareMocks("",HttpStatus.ACCEPTED.value(),""); - when(systemProperties.getProperty(MsoProperties.MSO_SERVER_URL)).thenReturn("SAMPLE_URL"); - when(mockClient.target("SAMPLE_URL")).thenThrow(new MsoTestException("test-target-exception")); - - // when - restMsoImplementation.Get(httpRequest, "", restObject,false); - } @Test() public void shouldProperlyGetRestObjectForObjectWithRequestInfoAndAcceptCode() { @@ -192,43 +150,6 @@ public class RestMsoImplementationTest { } @Test - public void shouldProperlyDeleteForObject() { - // given - RequestDetails requestDetails = new RequestDetails(); - - RestObject<HttpRequest> expectedResponse = new RestObject<>(); - expectedResponse.setStatusCode(HttpStatus.ACCEPTED.value()); - expectedResponse.setRaw(rawData); - - prepareMocks(rawData,HttpStatus.ACCEPTED.value(),"DELETE"); - - // when - RestObject<HttpRequest> response = restMsoImplementation.DeleteForObject(requestDetails, path, HttpRequest.class); - - // then - assertThat(response).isEqualToComparingFieldByField(expectedResponse); - } - - @Test - public void shouldProperlyPost() { - // given - RequestDetails requestDetails = new RequestDetails(); - RestObject<String> response = new RestObject<>(); - - RestObject<String> expectedResponse = new RestObject<>(); - expectedResponse.setStatusCode(HttpStatus.ACCEPTED.value()); - expectedResponse.setRaw(rawData); - - prepareMocks(rawData,HttpStatus.ACCEPTED.value(),"POST"); - - // when - restMsoImplementation.Post(rawData,requestDetails, path, response); - - // then - assertThat(response).isEqualToComparingFieldByField(expectedResponse); - } - - @Test public void shouldProperlyPrepareClient() { // given String method = "POST"; @@ -267,70 +188,6 @@ public class RestMsoImplementationTest { restMsoImplementation.restCall(HttpMethod.GET, String.class, null, "", Optional.empty()); } - @Test - public void shouldProperlyPutRestObjectWithProperParametersAndStatusAccepted() { - // given - String method = "PUT"; - prepareMocks(rawData,HttpStatus.ACCEPTED.value(),method); - - org.onap.vid.changeManagement.RequestDetailsWrapper requestDetailsWrapper = new RequestDetailsWrapper(); - RestObject<String> response = new RestObject<>(); - - RestObject<String> expectedResponse = new RestObject<>(); - expectedResponse.setStatusCode(HttpStatus.ACCEPTED.value()); - expectedResponse.set(rawData); - - // when - restMsoImplementation.Put("testPutBody", requestDetailsWrapper , path, response); - - // then - assertThat(response).isEqualToComparingFieldByField(expectedResponse); - } - - @Test - public void shouldProperlyPutRestObjectWithProperParametersAndStatusMultipleChoices() { - // given - String method = "PUT"; - prepareMocks(rawData,HttpStatus.MULTIPLE_CHOICES.value(),method); - - org.onap.vid.changeManagement.RequestDetailsWrapper requestDetailsWrapper = new RequestDetailsWrapper(); - RestObject<String> response = new RestObject<>(); - - RestObject<String> expectedResponse = new RestObject<>(); - expectedResponse.setStatusCode(HttpStatus.MULTIPLE_CHOICES.value()); - expectedResponse.set(rawData); - - // when - restMsoImplementation.Put("testPutBody", requestDetailsWrapper , path, response); - - // then - assertThat(response).isEqualToComparingFieldByField(expectedResponse); - } - - @Test( expectedExceptions = MsoTestException.class) - public void shouldThrowExceptionWhenCallsPutWithWrongParameters() { - // given - when(mockClient.target(any(String.class))).thenThrow(new MsoTestException("testDeleteException")); - org.onap.vid.changeManagement.RequestDetailsWrapper requestDetailsWrapper = new RequestDetailsWrapper(); - - // when - restMsoImplementation.Put(null, requestDetailsWrapper, "", null); - } - - @Test( expectedExceptions = NullPointerException.class) - public void shouldThrowExceptionWhenCallsPutWithWrongObjectType() { - // given - RestObject<HttpRequest> restObject = new RestObject<>(); - org.onap.vid.changeManagement.RequestDetailsWrapper requestDetailsWrapper = new RequestDetailsWrapper(); - - prepareMocks(rawData,HttpStatus.ACCEPTED.value(),"DELETE"); - - // when - restMsoImplementation.Put(null, requestDetailsWrapper, path, restObject); - } - - - private void prepareMocks(String rawData,int status,String httpMethod) { when(mockClient.target(any(String.class))).thenReturn(webTarget); diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestHeadersTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestHeadersTest.java index 8c5634fbe..c27d6e4e1 100644 --- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestHeadersTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestHeadersTest.java @@ -56,12 +56,10 @@ import org.onap.vid.aai.util.AAIRestInterface; import org.onap.vid.aai.util.HttpsAuthClient; import org.onap.vid.aai.util.ServletRequestHelper; import org.onap.vid.aai.util.SystemPropertyHelper; -import org.onap.vid.changeManagement.RequestDetailsWrapper; import org.onap.vid.controller.filter.PromiseRequestIdFilter; import org.onap.vid.logging.Headers; import org.onap.vid.mso.MsoProperties; import org.onap.vid.mso.RestMsoImplementation; -import org.onap.vid.mso.RestObject; import org.onap.vid.testUtils.TestUtils; import org.onap.vid.utils.Logging; import org.onap.vid.utils.SystemPropertiesWrapper; @@ -124,13 +122,8 @@ public class OutgoingRequestHeadersTest { @DataProvider public Object[][] msoMethods() { return Stream.<ThrowingConsumer<RestMsoImplementation>>of( - - client -> client.Get(new Object(), "/any path", new RestObject<>(), false), client -> client.GetForObject("/any path", Object.class), - client -> client.Post("", "some payload", "/any path", new RestObject<>()), - client -> client.PostForObject("some payload", "/any path", Object.class), - client -> client.Put(Object.class, new RequestDetailsWrapper(), "/any path", new RestObject<>()) - + client -> client.PostForObject("some payload", "/any path", Object.class) ).map(l -> ImmutableList.of(l).toArray()).collect(Collectors.toList()).toArray(new Object[][]{}); } |