aboutsummaryrefslogtreecommitdiffstats
path: root/common/src/test
diff options
context:
space:
mode:
authorByung-Woo Jun <byung-woo.jun@est.tech>2019-04-02 15:13:04 +0000
committerGerrit Code Review <gerrit@onap.org>2019-04-02 15:13:04 +0000
commit4a74d94ea4604504325b320d499e2f3708ef1514 (patch)
tree1a2112aa64a992195c7fce055215940e6611c0fe /common/src/test
parent3b0c3e9ea3412cebd18ba74adaaa4fc69ff0eb17 (diff)
parent44a205e0d5fd357bd24c4298a01c74197b79efe3 (diff)
Merge "Check for existing VNF in VNFM"
Diffstat (limited to 'common/src/test')
-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);