summaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test
diff options
context:
space:
mode:
authorEylon Malin <eylon.malin@intl.att.com>2019-10-06 08:44:02 +0300
committerEylon Malin <eylon.malin@intl.att.com>2019-10-06 11:00:23 +0300
commit81aef70267474eaa2a212958e9b17d424e5d8480 (patch)
treee507bd95219af9e3bc17fa006cc454f96b0b0579 /vid-app-common/src/test
parent39b185a11e5978991eedd4763415eed51b7c9462 (diff)
all rest calls of AAIRestInterface use doRest method
Issue-ID: VID-253 Signed-off-by: Eylon Malin <eylon.malin@intl.att.com> Change-Id: Ie25a8be8d649fe322698c81a969c720dc123c629 Signed-off-by: Eylon Malin <eylon.malin@intl.att.com>
Diffstat (limited to 'vid-app-common/src/test')
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/util/AAIRestInterfaceTest.java56
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/util/ParametrizedAAIRestInterfaceTest.java123
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestHeadersTest.java1
3 files changed, 6 insertions, 174 deletions
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<String> 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<String> 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,58 +198,15 @@ public class AAIRestInterfaceTest {
Entity<String> 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
// when
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/util/ParametrizedAAIRestInterfaceTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/util/ParametrizedAAIRestInterfaceTest.java
deleted file mode 100644
index c0d3b962f..000000000
--- a/vid-app-common/src/test/java/org/onap/vid/aai/util/ParametrizedAAIRestInterfaceTest.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * VID
- * ================================================================================
- * Copyright (C) 2018 - 2019 Nokia. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.vid.aai.util;
-
-import static javax.ws.rs.core.Response.Status.NO_CONTENT;
-import static javax.ws.rs.core.Response.Status.OK;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.io.UnsupportedEncodingException;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Optional;
-import java.util.UUID;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.Invocation;
-import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.Response;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.onap.vid.aai.exceptions.InvalidPropertyException;
-import org.onap.vid.utils.Logging;
-import org.testng.Assert;
-
-@RunWith(Parameterized.class)
-public class ParametrizedAAIRestInterfaceTest {
-
- private static final String PATH = "path";
- private static final String HTTP_LOCALHOST = "http://localhost/";
- @Mock
- private Client client;
- @Mock
- private WebTarget webTarget;
- @Mock
- private Invocation.Builder builder;
- @Mock
- private ServletRequestHelper servletRequestHelper;
- @Mock
- private HttpsAuthClient httpsAuthClient;
- @Mock
- private HttpServletRequest httpServletRequest;
- @Mock
- private Response response;
- @Mock
- private SystemPropertyHelper systemPropertyHelper;
- @Mock
- private Logging loggingService;
-
- private AAIRestInterface testSubject;
- private Response.Status status;
-
- @Parameterized.Parameters
- public static Collection<Object> data() {
- return Arrays.asList(OK, NO_CONTENT);
- }
-
- @Before
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
- mockSystemProperties();
- testSubject = createTestSubject();
- when(client.target(HTTP_LOCALHOST+PATH)).thenReturn(webTarget);
- when(webTarget.request()).thenReturn(builder);
- when(builder.accept(Mockito.anyString())).thenReturn(builder);
- when(builder.header(Mockito.anyString(), Mockito.anyString())).thenReturn(builder);
- when(servletRequestHelper.extractOrGenerateRequestId()).thenReturn(UUID.randomUUID().toString());
- }
-
- public ParametrizedAAIRestInterfaceTest(Response.Status status) {
- this.status = status;
- }
-
- private AAIRestInterface createTestSubject() {
- return new AAIRestInterface(Optional.of(client), httpsAuthClient, servletRequestHelper, systemPropertyHelper, loggingService);
- }
-
- @Test
- public void testRestDeleteWithValidResponse() {
-
- // when
- when(builder.delete()).thenReturn(response);
- when(response.getStatusInfo()).thenReturn(status);
- boolean finalResponse = testSubject.Delete("", "", PATH);
-
- // then
- verify(builder).delete();
- Assert.assertTrue(finalResponse);
- }
-
- private void mockSystemProperties() throws UnsupportedEncodingException, InvalidPropertyException {
- when(systemPropertyHelper.getAAIServerUrl()).thenReturn(Optional.of(HTTP_LOCALHOST));
- when(systemPropertyHelper.getAAIUseClientCert()).thenReturn(Optional.of("cert"));
- when(systemPropertyHelper.getAAIVIDPasswd()).thenReturn(Optional.of("passwd"));
- when(systemPropertyHelper.getAAIVIDUsername()).thenReturn(Optional.of("user"));
- when(systemPropertyHelper.getEncodedCredentials()).thenReturn("someCredentials");
- when(systemPropertyHelper.getFullServicePath(Mockito.anyString())).thenReturn("http://localhost/path");
- }
-
-}
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestHeadersTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestHeadersTest.java
index 422443510..3fd92ee90 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestHeadersTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestHeadersTest.java
@@ -250,7 +250,6 @@ public class OutgoingRequestHeadersTest {
return Stream.<ThrowingConsumer<AAIRestInterface>>of(
client -> client.RestGet("from app id", "some transId", Unchecked.toURI("/any path"), false),
- client -> client.Delete("whatever source id", "some transId", "/any path"),
client -> client.RestPost("from app id", "/any path", "some payload", false),
client -> client.RestPut("from app id", "/any path", "some payload", false, false)