summaryrefslogtreecommitdiffstats
path: root/common/src/test/java/org
diff options
context:
space:
mode:
authorMichaelMorris <michael.morris@est.tech>2019-04-02 13:46:47 +0000
committerMichaelMorris <michael.morris@est.tech>2019-04-02 13:46:47 +0000
commit44a205e0d5fd357bd24c4298a01c74197b79efe3 (patch)
treecbcbe32c4e6fac94e58da308ac29d20a9adb3aa0 /common/src/test/java/org
parent1f8531ddb54b133ed0b25628d43ec698caa9b087 (diff)
Check for existing VNF in VNFM
Issue-ID: SO-1622 Change-Id: I6aa6af3c6988032f436c5da79c0140370469439e Signed-off-by: MichaelMorris <michael.morris@est.tech>
Diffstat (limited to 'common/src/test/java/org')
-rw-r--r--common/src/test/java/org/onap/so/rest/service/HttpRestServiceProviderImplTest.java45
1 files changed, 40 insertions, 5 deletions
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);