aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common
diff options
context:
space:
mode:
Diffstat (limited to 'vid-app-common')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/PombaClientImpl.java5
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/AAITreeConverterTest.java (renamed from vid-app-common/src/test/java/org/onap/vid/services/AAITreeConverterTest.java)19
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientServerTest.java17
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientTest.java12
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/AaiResponseTranslatorTest.java (renamed from vid-app-common/src/test/java/org/onap/vid/services/AaiResponseTranslatorTest.java)8
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/PombaClientImplTest.java4
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/PombaRestInterfaceTest.java127
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/util/HttpsAuthClientTest.java15
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/util/SingleAAIRestInterfaceTest.java16
9 files changed, 184 insertions, 39 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/PombaClientImpl.java b/vid-app-common/src/main/java/org/onap/vid/aai/PombaClientImpl.java
index e22040157..1ee4da0b4 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/PombaClientImpl.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/PombaClientImpl.java
@@ -3,13 +3,14 @@
* VID
* ================================================================================
* Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 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.
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AAITreeConverterTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/AAITreeConverterTest.java
index 5abe8e426..8bcadd139 100644
--- a/vid-app-common/src/test/java/org/onap/vid/services/AAITreeConverterTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/AAITreeConverterTest.java
@@ -3,13 +3,14 @@
* VID
* ================================================================================
* Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 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.
@@ -18,14 +19,18 @@
* ============LICENSE_END=========================================================
*/
-package org.opencomp.vid.services;
+package org.onap.vid.aai;
import com.google.common.collect.ImmutableList;
import org.mockito.InjectMocks;
import org.mockito.MockitoAnnotations;
import org.onap.vid.aai.util.AAITreeConverter;
import org.onap.vid.model.Action;
-import org.onap.vid.model.aaiTree.*;
+import org.onap.vid.model.aaiTree.AAITreeNode;
+import org.onap.vid.model.aaiTree.Network;
+import org.onap.vid.model.aaiTree.ServiceInstance;
+import org.onap.vid.model.aaiTree.VfModule;
+import org.onap.vid.model.aaiTree.Vnf;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@@ -33,7 +38,11 @@ import org.testng.annotations.Test;
import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.*;
+import static org.hamcrest.Matchers.emptyOrNullString;
+import static org.hamcrest.Matchers.hasKey;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
import static org.onap.vid.asdc.parser.ToscaParserImpl2.Constants.A_LA_CARTE;
public class AAITreeConverterTest {
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientServerTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientServerTest.java
index fce9fa211..dd7b26c12 100644
--- a/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientServerTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientServerTest.java
@@ -28,20 +28,20 @@ import org.assertj.core.api.Assertions;
import org.glassfish.grizzly.http.util.HttpStatus;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
import org.onap.vid.aai.model.ResourceType;
import org.onap.vid.client.SyncRestClient;
import org.onap.vid.model.SubscriberList;
import org.onap.vid.testUtils.StubServerUtil;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import java.io.IOException;
-@RunWith(MockitoJUnitRunner.class)
+import static org.mockito.MockitoAnnotations.initMocks;
+
public class AaiOverTLSClientServerTest {
@Mock
@@ -100,6 +100,11 @@ public class AaiOverTLSClientServerTest {
serverUtil.stopServer();
}
+ @BeforeMethod
+ public void setUp(){
+ initMocks(this);
+ }
+
@Test
public void shouldSearchNodeTypeByName() throws IOException, ParseException {
ObjectMapper objectMapper = getFasterXmlObjectMapper();
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientTest.java
index 702a9e0a8..43fb5a3bb 100644
--- a/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientTest.java
@@ -21,24 +21,23 @@
package org.onap.vid.aai;
import com.google.common.collect.ImmutableMap;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
+
import org.onap.vid.aai.model.ResourceType;
import org.onap.vid.client.SyncRestClient;
import org.onap.vid.model.SubscriberList;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import java.util.Collections;
import java.util.Map;
import static org.mockito.ArgumentMatchers.contains;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.MockitoAnnotations.initMocks;
-@RunWith(MockitoJUnitRunner.class)
public class AaiOverTLSClientTest {
private static final String SEARCH_NODES_QUERY_SEARCH_NODE_TYPE = "nodes/generic-vnfs?vnf-name=name";
@@ -50,8 +49,9 @@ public class AaiOverTLSClientTest {
@Mock
private AaiOverTLSPropertySupplier propertySupplier;
- @Before
+ @BeforeMethod
public void setUp() {
+ initMocks(this);
aaiRestClient = new AaiOverTLSClient(syncRestClient, propertySupplier);
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AaiResponseTranslatorTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/AaiResponseTranslatorTest.java
index cc6f99fc6..12f7429eb 100644
--- a/vid-app-common/src/test/java/org/onap/vid/services/AaiResponseTranslatorTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/AaiResponseTranslatorTest.java
@@ -3,13 +3,14 @@
* VID
* ================================================================================
* Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 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.
@@ -18,11 +19,10 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.vid.services;
+package org.onap.vid.aai;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
-import org.onap.vid.aai.AaiResponseTranslator;
import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigData;
import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigDataError;
import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigDataOk;
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/PombaClientImplTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/PombaClientImplTest.java
index 483feec91..222bf1e5b 100644
--- a/vid-app-common/src/test/java/org/onap/vid/aai/PombaClientImplTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/PombaClientImplTest.java
@@ -7,9 +7,9 @@
* 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.
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/PombaRestInterfaceTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/PombaRestInterfaceTest.java
new file mode 100644
index 000000000..b409c1f46
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/PombaRestInterfaceTest.java
@@ -0,0 +1,127 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2019 Nokia
+ * ================================================================================
+ * 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;
+
+
+import org.mockito.Mock;
+import org.onap.vid.aai.util.HttpClientMode;
+import org.onap.vid.aai.util.HttpsAuthClient;
+import org.onap.vid.aai.util.ServletRequestHelper;
+import org.onap.vid.aai.util.SystemPropertyHelper;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.Invocation;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import java.io.IOException;
+import java.security.GeneralSecurityException;
+import java.util.UUID;
+import java.util.regex.Pattern;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.matches;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+import static org.onap.vid.aai.AaiOverTLSClientInterface.HEADERS.FROM_APP_ID_HEADER;
+import static org.onap.vid.aai.AaiOverTLSClientInterface.HEADERS.TRANSACTION_ID_HEADER;
+import static org.onap.vid.utils.Logging.REQUEST_ID_HEADER_KEY;
+
+public class PombaRestInterfaceTest {
+ private static final String UUID_REGEX = "[a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12}";
+ private static final String SAMPLE_APP_ID = "vid";
+ private static final String SAMPLE_URL = "sampleUrl";
+ private static final String SAMPLE_PAYLOAD = "samplePayload";
+ private static final Pattern UUID_PATTERN = Pattern.compile(UUID_REGEX);
+
+ @Mock
+ private HttpsAuthClient authClient;
+
+ @Mock
+ private ServletRequestHelper requestHelper;
+
+ @Mock
+ private SystemPropertyHelper systemPropertyHelper;
+
+ @Mock
+ private Client client;
+
+ @Mock
+ private WebTarget webTarget;
+
+ @Mock
+ private Invocation.Builder builder;
+
+ @Mock
+ private Response response;
+
+ private PombaRestInterface pombaRestInterface;
+
+ @BeforeMethod
+ public void setUp() throws GeneralSecurityException, IOException {
+ initMocks(this);
+
+ when(requestHelper.extractOrGenerateRequestId()).thenReturn(UUID.randomUUID().toString());
+ when(authClient.getClient(HttpClientMode.WITH_KEYSTORE)).thenReturn(client);
+ setUpBuilder();
+ pombaRestInterface = new PombaRestInterface(authClient, requestHelper, systemPropertyHelper);
+ }
+
+
+ @Test
+ public void shouldProperlySendRequestWithAllRequiredHeaders() {
+ Response actualResponse = pombaRestInterface.RestPost(SAMPLE_APP_ID, SAMPLE_URL, SAMPLE_PAYLOAD);
+
+ assertThat(actualResponse).isEqualTo(response);
+
+ verify(builder).accept(MediaType.APPLICATION_JSON);
+ verify(builder).header(FROM_APP_ID_HEADER, SAMPLE_APP_ID);
+ verify(builder).header(matches(TRANSACTION_ID_HEADER), matches(UUID_PATTERN));
+ verify(builder).header(matches(REQUEST_ID_HEADER_KEY), matches(UUID_PATTERN));
+ verify(builder).post(any(Entity.class));
+ }
+
+ @Test
+ public void shouldReturnNullWhenExceptionWasRaised() {
+ doThrow(new RuntimeException()).when(client).target(anyString());
+
+ Response actualResponse = pombaRestInterface.RestPost(SAMPLE_APP_ID, SAMPLE_URL, SAMPLE_PAYLOAD);
+
+ assertThat(actualResponse).isNull();
+ }
+
+ private void setUpBuilder() {
+ when(client.target(anyString())).thenReturn(webTarget);
+ when(webTarget.request()).thenReturn(builder);
+ when(builder.accept(MediaType.APPLICATION_JSON)).thenReturn(builder);
+ when(builder.header(anyString(), any())).thenReturn(builder);
+ when(builder.post(any(Entity.class))).thenReturn(response);
+ when(response.getStatusInfo()).thenReturn(Response.Status.OK);
+ }
+} \ No newline at end of file
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/util/HttpsAuthClientTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/util/HttpsAuthClientTest.java
index aff6c7f76..3336a8af9 100644
--- a/vid-app-common/src/test/java/org/onap/vid/aai/util/HttpsAuthClientTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/util/HttpsAuthClientTest.java
@@ -21,13 +21,13 @@
package org.onap.vid.aai.util;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+
import org.onap.vid.aai.exceptions.HttpClientBuilderException;
import org.onap.vid.exceptions.GenericUncheckedException;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import org.togglz.core.manager.FeatureManager;
import javax.net.ssl.SSLContext;
@@ -35,8 +35,8 @@ import java.util.Optional;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.*;
+import static org.mockito.MockitoAnnotations.initMocks;
-@RunWith(MockitoJUnitRunner.class)
public class HttpsAuthClientTest {
@Mock
private SystemPropertyHelper systemPropertyHelper;
@@ -51,14 +51,15 @@ public class HttpsAuthClientTest {
return new HttpsAuthClient(CERT_FILE_PATH, systemPropertyHelper, sslContextProvider, mock(FeatureManager.class));
}
- @Before
+ @BeforeMethod
public void setUp() throws Exception {
+ initMocks(this);
when(systemPropertyHelper.getAAITruststoreFilename()).thenReturn(Optional.of("filename"));
when(systemPropertyHelper.getDecryptedKeystorePassword()).thenReturn("password");
when(systemPropertyHelper.getDecryptedTruststorePassword()).thenReturn("password");
}
- @Test(expected = HttpClientBuilderException.class)
+ @Test(expectedExceptions = {HttpClientBuilderException.class})
public void testHttpClientBuilderExceptionOnGetClient() throws Exception {
//when
when(systemPropertyHelper.isClientCertEnabled()).thenReturn(true);
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/util/SingleAAIRestInterfaceTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/util/SingleAAIRestInterfaceTest.java
index 69e8ddcec..3393aa7c1 100644
--- a/vid-app-common/src/test/java/org/onap/vid/aai/util/SingleAAIRestInterfaceTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/util/SingleAAIRestInterfaceTest.java
@@ -20,18 +20,18 @@
package org.onap.vid.aai.util;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
+
import org.onap.vid.aai.ExceptionWithRequestInfo;
import org.onap.vid.aai.exceptions.InvalidPropertyException;
import org.onap.vid.exceptions.GenericUncheckedException;
import org.onap.vid.utils.Unchecked;
import org.springframework.http.HttpMethod;
import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.client.Client;
@@ -51,8 +51,9 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+
-@RunWith(MockitoJUnitRunner.class)
public class SingleAAIRestInterfaceTest {
private static final String PATH = "path";
@@ -78,8 +79,9 @@ public class SingleAAIRestInterfaceTest {
private AAIRestInterface testSubject;
- @Before
+ @BeforeMethod
public void setUp() throws Exception {
+ initMocks(this);
mockSystemProperties();
testSubject = createTestSubject();
when(client.target(HTTP_LOCALHOST+PATH)).thenReturn(webTarget);
@@ -130,7 +132,7 @@ public class SingleAAIRestInterfaceTest {
Assert.assertEquals(response, finalResponse);
}
- @Test(expected = ExceptionWithRequestInfo.class)
+ @Test(expectedExceptions = {ExceptionWithRequestInfo.class})
public void testFailedRestJsonPut() {
// given
String methodName = "RestPut";