summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/src/main/java/org/onap/so/client/aai/AAINamespaceConstants.java14
-rw-r--r--common/src/main/java/org/onap/so/client/aai/AAIObjectType.java7
-rw-r--r--common/src/main/java/org/onap/so/rest/service/HttpRestServiceProvider.java39
-rw-r--r--common/src/main/java/org/onap/so/rest/service/HttpRestServiceProviderImpl.java81
-rw-r--r--common/src/test/java/org/onap/so/rest/service/HttpRestServiceProviderImplTest.java45
5 files changed, 121 insertions, 65 deletions
diff --git a/common/src/main/java/org/onap/so/client/aai/AAINamespaceConstants.java b/common/src/main/java/org/onap/so/client/aai/AAINamespaceConstants.java
index 9d2c3a8b1b..1225bb3fd5 100644
--- a/common/src/main/java/org/onap/so/client/aai/AAINamespaceConstants.java
+++ b/common/src/main/java/org/onap/so/client/aai/AAINamespaceConstants.java
@@ -7,9 +7,9 @@
* 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.
@@ -22,10 +22,10 @@ package org.onap.so.client.aai;
public class AAINamespaceConstants {
- public static final String CLOUD_INFRASTRUCTURE = "/cloud-infrastructure";
- public static final String NETWORK = "/network";
- public static final String BUSINESS = "/business";
- public static final String SERVICE_DESIGN_AND_CREATION = "/service-design-and-creation";
-
+ public static final String CLOUD_INFRASTRUCTURE = "/cloud-infrastructure";
+ public static final String NETWORK = "/network";
+ public static final String BUSINESS = "/business";
+ public static final String SERVICE_DESIGN_AND_CREATION = "/service-design-and-creation";
+ public static final String EXTERNAL_SYSTEM = "/external-system";
}
diff --git a/common/src/main/java/org/onap/so/client/aai/AAIObjectType.java b/common/src/main/java/org/onap/so/client/aai/AAIObjectType.java
index 34d560210c..f6aa2fdb19 100644
--- a/common/src/main/java/org/onap/so/client/aai/AAIObjectType.java
+++ b/common/src/main/java/org/onap/so/client/aai/AAIObjectType.java
@@ -37,6 +37,9 @@ import org.onap.aai.domain.yang.Configuration;
import org.onap.aai.domain.yang.Connector;
import org.onap.aai.domain.yang.Customer;
import org.onap.aai.domain.yang.Device;
+import org.onap.aai.domain.yang.EsrSystemInfoList;
+import org.onap.aai.domain.yang.EsrVnfm;
+import org.onap.aai.domain.yang.EsrVnfmList;
import org.onap.aai.domain.yang.ExtAaiNetwork;
import org.onap.aai.domain.yang.Flavor;
import org.onap.aai.domain.yang.GenericVnf;
@@ -139,6 +142,10 @@ public class AAIObjectType implements GraphInventoryObjectType, Serializable {
public static final AAIObjectType FLAVOR = new AAIObjectType(AAIObjectType.CLOUD_REGION.uriTemplate(), Flavor.class);
public static final AAIObjectType UNKNOWN = new AAIObjectType("", "", "unknown");
public static final AAIObjectType DSL = new AAIObjectType("/dsl", "", "dsl");
+ public static final AAIObjectType VNFM = new AAIObjectType(AAINamespaceConstants.EXTERNAL_SYSTEM + "/esr-vnfm-list/esr-vnfm/{vnfm-id}", EsrVnfm.class);
+ public static final AAIObjectType VNFM_LIST = new AAIObjectType(AAINamespaceConstants.EXTERNAL_SYSTEM, "/esr-vnfm-list", "vnfm-list");
+ public static final AAIObjectType VNFM_ESR_SYSTEM_INFO_LIST = new AAIObjectType(AAINamespaceConstants.EXTERNAL_SYSTEM + "/esr-vnfm-list", "/esr-vnfm/{vnfm-id}/esr-system-info-list", "vnfm-esr-system-info-list");
+
private final String uriTemplate;
private final String parentUri;
diff --git a/common/src/main/java/org/onap/so/rest/service/HttpRestServiceProvider.java b/common/src/main/java/org/onap/so/rest/service/HttpRestServiceProvider.java
index 282c87a736..a3d16175bc 100644
--- a/common/src/main/java/org/onap/so/rest/service/HttpRestServiceProvider.java
+++ b/common/src/main/java/org/onap/so/rest/service/HttpRestServiceProvider.java
@@ -20,9 +20,8 @@
package org.onap.so.rest.service;
-import org.springframework.http.ResponseEntity;
-
import com.google.common.base.Optional;
+import org.springframework.http.ResponseEntity;
/**
* @author waqas.ikram@est.tech
@@ -31,42 +30,62 @@ public interface HttpRestServiceProvider {
/**
* Execute the HTTP GET to the given URI template
- *
+ *
* @param url the URL
* @param clazz the type of the return value
* @return Returns the body of this entity.
*/
- public <T> Optional<T> get(final String url, final Class<T> clazz);
+ <T> Optional<T> get(final String url, final Class<T> clazz);
/**
* Execute the HTTP GET to the given URI template
- *
+ *
* @param url the URL
* @param clazz the type of the return value
* @return Returns the {@link ResponseEntity}.
*/
- public <T> ResponseEntity<T> getHttpResponse(final String url, final Class<T> clazz);
+ <T> ResponseEntity<T> getHttpResponse(final String url, final Class<T> clazz);
/**
* Execute the HTTP POST to the given URI template
- *
+ *
* @param object the entity (i.e. body) to write to the request
* @param url the URL
* @param clazz the type of the return value
* @return Returns the body of this entity.
*/
- public <T> Optional<T> post(final Object object, final String url, final Class<T> clazz);
+ <T> Optional<T> post(final Object object, final String url, final Class<T> clazz);
/**
* Execute the HTTP POST to the given URI template
- *
+ *
+ * @param object the entity (i.e. body) to write to the request
+ * @param url the URL
+ * @param clazz the type of the return value
+ * @return Returns the {@link ResponseEntity}.
+ */
+ <T> ResponseEntity<T> postHttpRequest(final Object object, final String url, final Class<T> clazz);
+
+ /**
+ * Execute the HTTP PUT to the given URI template
+ *
+ * @param object the entity (i.e. body) to write to the request
+ * @param url the URL
+ * @param clazz the type of the return value
+ * @return Returns the body of this entity.
+ */
+ <T> Optional<T> put(final Object object, final String url, final Class<T> clazz);
+
+ /**
+ * Execute the HTTP PUT to the given URI template
+ *
* @param object the entity (i.e. body) to write to the request
* @param url the URL
* @param clazz the type of the return value
* @return Returns the {@link ResponseEntity}.
*/
- public <T> ResponseEntity<T> postHttpRequest(final Object object, final String url, final Class<T> clazz);
+ <T> ResponseEntity<T> putHttpRequest(final Object object, final String url, final Class<T> clazz);
/**
* Execute the HTTP DELETE to the given URI template
diff --git a/common/src/main/java/org/onap/so/rest/service/HttpRestServiceProviderImpl.java b/common/src/main/java/org/onap/so/rest/service/HttpRestServiceProviderImpl.java
index 164d48bc5e..029431c86e 100644
--- a/common/src/main/java/org/onap/so/rest/service/HttpRestServiceProviderImpl.java
+++ b/common/src/main/java/org/onap/so/rest/service/HttpRestServiceProviderImpl.java
@@ -20,6 +20,7 @@
package org.onap.so.rest.service;
+import com.google.common.base.Optional;
import org.onap.so.configuration.rest.BasicHttpHeadersProvider;
import org.onap.so.configuration.rest.HttpHeadersProvider;
import org.onap.so.rest.exceptions.InvalidRestRequestException;
@@ -35,11 +36,9 @@ import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
-import com.google.common.base.Optional;
-
/**
* A Service to perform HTTP requests
- *
+ *
* @author waqas.ikram@est.tech
*/
public class HttpRestServiceProviderImpl implements HttpRestServiceProvider {
@@ -61,49 +60,45 @@ public class HttpRestServiceProviderImpl implements HttpRestServiceProvider {
@Override
public <T> Optional<T> get(final String url, final Class<T> clazz) {
final ResponseEntity<T> response = getHttpResponse(url, clazz);
- if (!response.getStatusCode().equals(HttpStatus.OK)) {
- final String message =
- "Unable to invoke HTTP GET using URL: " + url + ", Response Code: " + response.getStatusCode();
- LOGGER.error(message);
- return Optional.absent();
- }
-
- if (response.hasBody()) {
- return Optional.of(response.getBody());
- }
- return Optional.absent();
+ return createOptional(response, url, HttpMethod.GET);
}
@Override
public <T> ResponseEntity<T> getHttpResponse(final String url, final Class<T> clazz) {
- LOGGER.trace("Will invoke HTTP GET using URL: {}", url);
- try {
- final HttpEntity<?> request = new HttpEntity<>(getHttpHeaders());
- return restTemplate.exchange(url, HttpMethod.GET, request, clazz);
-
- } catch (final HttpClientErrorException httpClientErrorException) {
- final String message = "Unable to invoke HTTP GET using url: " + url + ", Response: "
- + httpClientErrorException.getRawStatusCode();
- LOGGER.error(message, httpClientErrorException);
- final int rawStatusCode = httpClientErrorException.getRawStatusCode();
- if (rawStatusCode == HttpStatus.BAD_REQUEST.value() || rawStatusCode == HttpStatus.NOT_FOUND.value()) {
- throw new InvalidRestRequestException("No result found for given url: " + url);
- }
- throw new RestProcessingException("Unable to invoke HTTP GET using URL: " + url);
-
- } catch (final RestClientException restClientException) {
- LOGGER.error("Unable to invoke HTTP GET using url: {}", url, restClientException);
- throw new RestProcessingException("Unable to invoke HTTP GET using URL: " + url, restClientException);
- }
+ final HttpEntity<?> request = new HttpEntity<>(getHttpHeaders());
+ return invokeHttpRequest(request, HttpMethod.GET, url, clazz);
}
@Override
public <T> Optional<T> post(final Object object, final String url, final Class<T> clazz) {
final ResponseEntity<T> response = postHttpRequest(object, url, clazz);
+ return createOptional(response, url, HttpMethod.POST);
+ }
+
+ @Override
+ public <T> ResponseEntity<T> postHttpRequest(final Object object, final String url, final Class<T> clazz) {
+ final HttpEntity<?> request = new HttpEntity<>(object, getHttpHeaders());
+ return invokeHttpRequest(request, HttpMethod.POST, url, clazz);
+ }
+
+ @Override
+ public <T> Optional<T> put(final Object object, final String url, final Class<T> clazz) {
+ final ResponseEntity<T> response = putHttpRequest(object, url, clazz);
+ return createOptional(response, url, HttpMethod.PUT);
+ }
+
+ @Override
+ public <T> ResponseEntity<T> putHttpRequest(final Object object, final String url, final Class<T> clazz) {
+ final HttpEntity<?> request = new HttpEntity<>(object, getHttpHeaders());
+ return invokeHttpRequest(request, HttpMethod.PUT, url, clazz);
+ }
+
+ private <T> Optional<T> createOptional(final ResponseEntity<T> response, final String url,
+ final HttpMethod httpMethod) {
if (!response.getStatusCode().equals(HttpStatus.OK)) {
- final String message =
- "Unable to invoke HTTP GET using URL: " + url + ", Response Code: " + response.getStatusCode();
+ final String message = "Unable to invoke HTTP " + httpMethod + " using URL: " + url + ", Response Code: "
+ + response.getStatusCode();
LOGGER.error(message);
return Optional.absent();
}
@@ -115,26 +110,26 @@ public class HttpRestServiceProviderImpl implements HttpRestServiceProvider {
return Optional.absent();
}
-
- @Override
- public <T> ResponseEntity<T> postHttpRequest(final Object object, final String url, final Class<T> clazz) {
+ private <T> ResponseEntity<T> invokeHttpRequest(final HttpEntity<?> request, final HttpMethod httpMethod,
+ final String url, final Class<T> clazz) {
+ LOGGER.trace("Will invoke HTTP {} using URL: {}", httpMethod, url);
try {
- final HttpEntity<?> request = new HttpEntity<>(object, getHttpHeaders());
- return restTemplate.exchange(url, HttpMethod.POST, request, clazz);
+ return restTemplate.exchange(url, httpMethod, request, clazz);
} catch (final HttpClientErrorException httpClientErrorException) {
- final String message = "Unable to invoke HTTP POST using url: " + url + ", Response: "
+ final String message = "Unable to invoke HTTP " + httpMethod + " using url: " + url + ", Response: "
+ httpClientErrorException.getRawStatusCode();
LOGGER.error(message, httpClientErrorException);
final int rawStatusCode = httpClientErrorException.getRawStatusCode();
if (rawStatusCode == HttpStatus.BAD_REQUEST.value() || rawStatusCode == HttpStatus.NOT_FOUND.value()) {
throw new InvalidRestRequestException("No result found for given url: " + url);
}
- throw new RestProcessingException("Unable to invoke HTTP GET using URL: " + url);
+ throw new RestProcessingException("Unable to invoke HTTP " + httpMethod + " using URL: " + url);
} catch (final RestClientException restClientException) {
LOGGER.error("Unable to invoke HTTP POST using url: {}", url, restClientException);
- throw new RestProcessingException("Unable to invoke HTTP GET using URL: " + url, restClientException);
+ throw new RestProcessingException("Unable to invoke HTTP " + httpMethod + " using URL: " + url,
+ restClientException);
}
}
diff --git a/common/src/test/java/org/onap/so/rest/service/HttpRestServiceProviderImplTest.java b/common/src/test/java/org/onap/so/rest/service/HttpRestServiceProviderImplTest.java
index a738afe565..978c016dec 100644
--- a/common/src/test/java/org/onap/so/rest/service/HttpRestServiceProviderImplTest.java
+++ b/common/src/test/java/org/onap/so/rest/service/HttpRestServiceProviderImplTest.java
@@ -27,7 +27,7 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-
+import com.google.common.base.Optional;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -42,8 +42,6 @@ import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
-import com.google.common.base.Optional;
-
/**
* @author waqas.ikram@est.tech
@@ -180,6 +178,43 @@ public class HttpRestServiceProviderImplTest {
eq(String.class));
}
+ @Test
+ public void test_put_returnOptionalPresentIfResponseIsOKAndHasBody() {
+
+ final HttpRestServiceProvider objUnderTest = new HttpRestServiceProviderImpl(mockRestTemplate);
+
+ when(mockRestTemplate.exchange(eq(DUMMY_URL), eq(HttpMethod.PUT), any(HttpEntity.class), eq(String.class)))
+ .thenReturn(mockEntity);
+
+ when(mockEntity.getStatusCode()).thenReturn(HttpStatus.OK);
+ when(mockEntity.hasBody()).thenReturn(true);
+ when(mockEntity.getBody()).thenReturn(BODY);
+
+ final Optional<String> actual = objUnderTest.put(BODY, DUMMY_URL, String.class);
+
+ assertTrue(actual.isPresent());
+ verify(mockRestTemplate, atLeastOnce()).exchange(eq(DUMMY_URL), eq(HttpMethod.PUT), any(HttpEntity.class),
+ eq(String.class));
+ }
+
+ @Test
+ public void test_put_returnOptionalPresentIfResponseIsOKAndHasNoBody() {
+
+ final HttpRestServiceProvider objUnderTest = new HttpRestServiceProviderImpl(mockRestTemplate);
+
+ when(mockRestTemplate.exchange(eq(DUMMY_URL), eq(HttpMethod.PUT), any(HttpEntity.class), eq(String.class)))
+ .thenReturn(mockEntity);
+
+ when(mockEntity.getStatusCode()).thenReturn(HttpStatus.OK);
+ when(mockEntity.hasBody()).thenReturn(false);
+
+ final Optional<String> actual = objUnderTest.put(BODY, DUMMY_URL, String.class);
+
+ assertFalse(actual.isPresent());
+ verify(mockRestTemplate, atLeastOnce()).exchange(eq(DUMMY_URL), eq(HttpMethod.PUT), any(HttpEntity.class),
+ eq(String.class));
+ }
+
@Test
public void test_post_returnOptionalPresentIfResponseIsNotOKAndHasBody() {
@@ -197,7 +232,7 @@ public class HttpRestServiceProviderImplTest {
verify(mockRestTemplate, atLeastOnce()).exchange(eq(DUMMY_URL), eq(HttpMethod.POST), any(HttpEntity.class),
eq(String.class));
}
-
+
@Test(expected = InvalidRestRequestException.class)
public void test_post_ThrowsInvalidRestRequestExceptionifHttpClientErrorExceptionWithHttpStatusBadRequest() {
assertPostErrorScenario(HttpStatus.BAD_REQUEST);
@@ -208,7 +243,7 @@ public class HttpRestServiceProviderImplTest {
public void test_post_ThrowsInvalidRestRequestExceptionifHttpClientErrorExceptionWithHttpStatusNotFoundHttpStatus() {
assertPostErrorScenario(HttpStatus.NOT_FOUND);
}
-
+
@Test(expected = RestProcessingException.class)
public void test_post_ThrowsInvalidRestRequestExceptionifHttpClientErrorExceptionOccured() {
final HttpRestServiceProvider objUnderTest = new HttpRestServiceProviderImpl(mockRestTemplate);