From 44a205e0d5fd357bd24c4298a01c74197b79efe3 Mon Sep 17 00:00:00 2001 From: MichaelMorris Date: Tue, 2 Apr 2019 13:46:47 +0000 Subject: Check for existing VNF in VNFM Issue-ID: SO-1622 Change-Id: I6aa6af3c6988032f436c5da79c0140370469439e Signed-off-by: MichaelMorris --- .../service/HttpRestServiceProviderImplTest.java | 45 +++++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) (limited to 'common/src/test/java') 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 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 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); -- cgit 1.2.3-korg