summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/src/main/java/org/onap/so/client/RestRequest.java5
-rw-r--r--common/src/main/java/org/onap/so/rest/service/HttpRestServiceProvider.java9
-rw-r--r--common/src/main/java/org/onap/so/rest/service/HttpRestServiceProviderImpl.java12
-rw-r--r--common/src/test/java/org/onap/so/client/HttpClientTest.java11
-rw-r--r--common/src/test/java/org/onap/so/client/aai/AAIConfigurationClientTest.java25
-rw-r--r--common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java2
-rw-r--r--common/src/test/java/org/onap/so/client/aai/AAIResourcesClientWithServiceInstanceUriTest.java5
-rw-r--r--common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java3
8 files changed, 34 insertions, 38 deletions
diff --git a/common/src/main/java/org/onap/so/client/RestRequest.java b/common/src/main/java/org/onap/so/client/RestRequest.java
index 6f0d71cabf..3864f2e5cc 100644
--- a/common/src/main/java/org/onap/so/client/RestRequest.java
+++ b/common/src/main/java/org/onap/so/client/RestRequest.java
@@ -25,6 +25,7 @@ package org.onap.so.client;
import java.util.Optional;
import java.util.concurrent.Callable;
+import javax.ws.rs.HttpMethod;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Response;
@@ -60,8 +61,8 @@ public class RestRequest implements Callable<Response> {
response = this.client.getBuilder().accept(this.client.getAccept()).delete();
} else {
- response = this.client.getBuilder().header("X-HTTP-Method-Override", "DELETE").accept(this.client.getAccept())
- .post(Entity.entity(entity, this.client.getContentType()));
+ response = this.client.getBuilder().accept(this.client.getAccept())
+ .build(HttpMethod.DELETE, Entity.entity(entity, this.client.getContentType())).invoke();
}
} else if ("PUT".equals(method)) {
response = this.client.getBuilder().accept(this.client.getAccept()).put(Entity.entity(entity, this.client.getContentType()));
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 43b2fb4292..282c87a736 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
@@ -68,5 +68,14 @@ public interface HttpRestServiceProvider {
*/
public <T> ResponseEntity<T> postHttpRequest(final Object object, final String url, final Class<T> clazz);
+ /**
+ * Execute the HTTP DELETE 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> deleteHttpRequest(final String url, final Class<T> clazz);
+
}
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 032df84a98..164d48bc5e 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
@@ -138,6 +138,18 @@ public class HttpRestServiceProviderImpl implements HttpRestServiceProvider {
}
}
+ @Override
+ public <T> ResponseEntity<T> deleteHttpRequest(final String url, final Class<T> clazz) {
+ try {
+ final HttpEntity<?> request = new HttpEntity<>(getHttpHeaders());
+ return restTemplate.exchange(url, HttpMethod.DELETE, request, clazz);
+
+ } catch (final RestClientException restClientException) {
+ LOGGER.error("Unable to invoke HTTP DELETE using url: " + url, restClientException);
+ throw new InvalidRestRequestException("Unable to invoke HTTP DELETE using URL: " + url, restClientException);
+ }
+ }
+
private HttpHeaders getHttpHeaders() {
return httpHeadersProvider.getHttpHeaders();
}
diff --git a/common/src/test/java/org/onap/so/client/HttpClientTest.java b/common/src/test/java/org/onap/so/client/HttpClientTest.java
index 75ce5f322f..346bf1426d 100644
--- a/common/src/test/java/org/onap/so/client/HttpClientTest.java
+++ b/common/src/test/java/org/onap/so/client/HttpClientTest.java
@@ -25,18 +25,19 @@ import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
import static com.github.tomakehurst.wiremock.client.WireMock.exactly;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
-import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
-import com.github.tomakehurst.wiremock.junit.WireMockRule;
import java.net.MalformedURLException;
import java.net.URL;
+
import org.junit.Rule;
import org.junit.Test;
import org.onap.so.utils.TargetEntity;
+import com.github.tomakehurst.wiremock.junit.WireMockRule;
+
public class HttpClientTest{
@@ -47,7 +48,7 @@ public class HttpClientTest{
@Test
public void testPost_success() throws MalformedURLException{
- stubFor(post(urlEqualTo("/services/sdnc/post"))
+ wireMockRule.stubFor(post(urlEqualTo("/services/sdnc/post"))
.willReturn(aResponse().withStatus(200)
.withHeader("Content-Type", "application/json")
.withBody("")));
@@ -66,7 +67,7 @@ public class HttpClientTest{
@Test
public void testPost_nullHeader() throws MalformedURLException{
- stubFor(post(urlEqualTo("/services/sdnc/post"))
+ wireMockRule.stubFor(post(urlEqualTo("/services/sdnc/post"))
.willReturn(aResponse().withStatus(200)
.withHeader("Content-Type", "application/json")
.withBody("")));
@@ -86,7 +87,7 @@ public class HttpClientTest{
@Test
public void testPost_nullBasicAuth() throws MalformedURLException{
- stubFor(post(urlEqualTo("/services/sdnc/post"))
+ wireMockRule.stubFor(post(urlEqualTo("/services/sdnc/post"))
.willReturn(aResponse().withStatus(200)
.withHeader("Content-Type", "application/json")
.withBody("")));
diff --git a/common/src/test/java/org/onap/so/client/aai/AAIConfigurationClientTest.java b/common/src/test/java/org/onap/so/client/aai/AAIConfigurationClientTest.java
index f30d2e17aa..525dff7562 100644
--- a/common/src/test/java/org/onap/so/client/aai/AAIConfigurationClientTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/AAIConfigurationClientTest.java
@@ -20,10 +20,6 @@
package org.onap.so.client.aai;
-import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
-import static com.github.tomakehurst.wiremock.client.WireMock.get;
-import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
-import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.doNothing;
@@ -34,7 +30,6 @@ import static org.mockito.Mockito.verify;
import java.util.Optional;
import java.util.UUID;
-import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
@@ -42,18 +37,12 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.so.client.aai.entities.Configuration;
import org.onap.so.client.aai.entities.uri.AAIResourceUri;
-import org.onap.so.client.aai.entities.uri.AAIUri;
import org.onap.so.client.aai.entities.uri.AAIUriFactory;
import org.onap.so.serviceinstancebeans.ModelInfo;
import org.onap.so.serviceinstancebeans.RequestDetails;
-
-import com.github.tomakehurst.wiremock.junit.WireMockRule;
@RunWith(MockitoJUnitRunner.class)
public class AAIConfigurationClientTest {
- @Rule
- public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(8443));
-
@Mock
AAIResourcesClient aaiClient;
@@ -163,18 +152,4 @@ public class AAIConfigurationClientTest {
AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, uuid);
assertEquals(uri, aaiConfigurationClient.getConfigurationURI(uuid));
}
-
- @Test
- public void verifyNotExists() {
- AAIUri path = AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, "test2");
- wireMockRule.stubFor(get(
- urlMatching("/aai/v[0-9]+" + path.build() + ".*"))
- .willReturn(
- aResponse()
- .withHeader("Content-Type", "text/plain")
- .withBody("hello")
- .withStatus(404)));
- boolean result = aaiConfigurationClient.configurationExists("test2");
- assertEquals("path not found", false, result);
- }
}
diff --git a/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java b/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java
index 174c76b1ef..c63d602bca 100644
--- a/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java
@@ -150,7 +150,7 @@ public class AAIResourcesClientTest {
AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test2");
AAIResourceUri path2 = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test3");
- wireMockRule.stubFor(post(
+ wireMockRule.stubFor(delete(
urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build() + "/relationship-list/relationship"))
.willReturn(
aResponse()
diff --git a/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientWithServiceInstanceUriTest.java b/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientWithServiceInstanceUriTest.java
index 5493d6778e..46e4c98b3e 100644
--- a/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientWithServiceInstanceUriTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientWithServiceInstanceUriTest.java
@@ -55,7 +55,7 @@ import com.github.tomakehurst.wiremock.junit.WireMockRule;
public class AAIResourcesClientWithServiceInstanceUriTest {
@Rule
- public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(8443));
+ public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
@Rule
public ExpectedException thrown = ExpectedException.none();
@@ -69,8 +69,7 @@ public class AAIResourcesClientWithServiceInstanceUriTest {
private ServiceInstanceUri uri;
@Before
public void setUp() {
-
- doReturn(new DefaultAAIPropertiesImpl()).when(client).getRestProperties();
+ doReturn(new DefaultAAIPropertiesImpl(wireMockRule.port())).when(client).getRestProperties();
wireMockRule.stubFor(get(urlMatching("/aai/v[0-9]+/nodes.*"))
.willReturn(aResponse()
.withStatus(404)
diff --git a/common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java b/common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java
index 979ca39489..c369767e38 100644
--- a/common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java
@@ -22,7 +22,6 @@ package org.onap.so.client.aai.entities.uri;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
-import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -197,7 +196,7 @@ public class ServiceInstanceUriTest {
ServiceInstanceUri spy = spy(instance);
AAIResourcesClient client = aaiClient;
doReturn(client).when(spy).getResourcesClient();
- stubFor(get(urlPathMatching("/aai/v[0-9]+/nodes/service-instances/service-instance/key3"))
+ wireMockRule.stubFor(get(urlPathMatching("/aai/v[0-9]+/nodes/service-instances/service-instance/key3"))
.willReturn(aResponse()
.withStatus(404)
.withHeader("Content-Type", "application/json")