From 81aef70267474eaa2a212958e9b17d424e5d8480 Mon Sep 17 00:00:00 2001 From: Eylon Malin Date: Sun, 6 Oct 2019 08:44:02 +0300 Subject: all rest calls of AAIRestInterface use doRest method Issue-ID: VID-253 Signed-off-by: Eylon Malin Change-Id: Ie25a8be8d649fe322698c81a969c720dc123c629 Signed-off-by: Eylon Malin --- .../onap/vid/aai/util/AAIRestInterfaceTest.java | 56 +++------------------- 1 file changed, 6 insertions(+), 50 deletions(-) (limited to 'vid-app-common/src/test/java/org/onap/vid/aai/util/AAIRestInterfaceTest.java') diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/util/AAIRestInterfaceTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/util/AAIRestInterfaceTest.java index bf8a5a1bc..2076d83ef 100644 --- a/vid-app-common/src/test/java/org/onap/vid/aai/util/AAIRestInterfaceTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/aai/util/AAIRestInterfaceTest.java @@ -22,7 +22,6 @@ package org.onap.vid.aai.util; import static javax.ws.rs.core.Response.Status.BAD_REQUEST; -import static javax.ws.rs.core.Response.Status.NOT_FOUND; import static javax.ws.rs.core.Response.Status.OK; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; @@ -166,12 +165,12 @@ public class AAIRestInterfaceTest { Entity entity = Entity.entity(payload, MediaType.APPLICATION_JSON); // when + when(builder.build(any(), any())).thenReturn(invocation); + when(invocation.invoke()).thenReturn(response); when(builder.post(Mockito.any(Entity.class))).thenReturn(response); when(response.getStatusInfo()).thenReturn(OK); Response finalResponse = testSubject.RestPost("", PATH, payload, false); - // then - verify(builder).post(entity); Assert.assertEquals(response, finalResponse); } @@ -182,13 +181,13 @@ public class AAIRestInterfaceTest { Entity entity = Entity.entity(payload, MediaType.APPLICATION_JSON); // when - when(builder.post(Mockito.any(Entity.class))).thenReturn(response); + when(builder.build(any(), any())).thenReturn(invocation); + when(invocation.invoke()).thenReturn(response); when(response.getStatusInfo()).thenReturn(BAD_REQUEST); when(response.getStatus()).thenReturn(BAD_REQUEST.getStatusCode()); Response finalResponse = testSubject.RestPost("", PATH, payload, false); // then - verify(builder).post(entity); Assert.assertEquals(response, finalResponse); } @@ -199,57 +198,14 @@ public class AAIRestInterfaceTest { Entity entity = Entity.entity(payload, MediaType.APPLICATION_JSON); // when - when(builder.post(Mockito.any(Entity.class))).thenThrow(new RuntimeException()); + when(builder.build(any(), any())).thenReturn(invocation); + when(invocation.invoke()).thenThrow(new RuntimeException()); Response finalResponse = testSubject.RestPost("", PATH, payload, false); // then - verify(builder).post(entity); Assert.assertNull(finalResponse); } - @Test - public void shouldExecuteRestDeleteMethodWithResponse400() { - // given - // when - when(builder.delete()).thenReturn(response); - when(response.getStatusInfo()).thenReturn(BAD_REQUEST); - String reason = "Any reason"; - when(response.readEntity(String.class)).thenReturn(reason); - when(response.getStatus()).thenReturn(BAD_REQUEST.getStatusCode()); - boolean finalResponse = testSubject.Delete("", "", PATH); - - // then - verify(builder).delete(); - Assert.assertFalse(finalResponse); - } - - @Test - public void shouldExecuteRestDeleteMethodWithResponse404() { - // given - // when - when(builder.delete()).thenReturn(response); - when(response.getStatusInfo()).thenReturn(NOT_FOUND); - String reason = "Any reason"; - when(response.readEntity(String.class)).thenReturn(reason); - when(response.getStatus()).thenReturn(NOT_FOUND.getStatusCode()); - boolean finalResponse = testSubject.Delete("", "", PATH); - - // then - verify(builder).delete(); - Assert.assertFalse(finalResponse); - } - - @Test - public void shouldFailWhenRestDeleteExecuted() { - // given - // when - when(builder.delete()).thenThrow(new RuntimeException()); - boolean finalResponse = testSubject.Delete("", "", PATH); - // then - verify(builder).delete(); - Assert.assertFalse(finalResponse); - } - @Test public void shouldExecuteRestGetMethodWithResponse200() { // given -- cgit 1.2.3-korg