summaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'vid-app-common/src/test')
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientServerTest.java180
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientTest.java15
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/config/JobCommandsConfigWithMockedMso.java4
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java24
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java43
5 files changed, 157 insertions, 109 deletions
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 f2b26a801..7ae8ac832 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
@@ -25,9 +25,6 @@ import com.xebialabs.restito.semantics.Action;
import io.joshworks.restclient.http.HttpResponse;
import io.joshworks.restclient.http.mapper.ObjectMapper;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringWriter;
-import org.apache.commons.io.IOUtils;
import org.assertj.core.api.Assertions;
import org.glassfish.grizzly.http.util.HttpStatus;
import org.json.simple.parser.JSONParser;
@@ -41,6 +38,7 @@ import org.mockito.runners.MockitoJUnitRunner;
import org.onap.vid.aai.model.AaiNodeQueryResponse;
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;
@RunWith(MockitoJUnitRunner.class)
@@ -51,7 +49,7 @@ public class AaiOverTLSClientServerTest {
private static StubServerUtil serverUtil;
- private String responsePayload =
+ private String searchNodesQueryResponsePayload =
"{\n"
+ "\"result-data\": [\n"
+ " {\n"
@@ -60,86 +58,6 @@ public class AaiOverTLSClientServerTest {
+ "},\n"
+ " {\n"
+ "\"resource-type\": \"generic-vnf\",\n"
- + "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/35305ca7-ad59-4b9b-9d21-1dd2b5103968\"\n"
- + "},\n"
- + " {\n"
- + "\"resource-type\": \"generic-vnf\",\n"
- + "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/1ed7a7ef-e9b8-4fad-8e10-92d0f714acc6\"\n"
- + "},\n"
- + " {\n"
- + "\"resource-type\": \"generic-vnf\",\n"
- + "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/5054bf7f-7913-4307-8bcd-aecce8b7539c\"\n"
- + "},\n"
- + " {\n"
- + "\"resource-type\": \"generic-vnf\",\n"
- + "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/7b484da9-8ac1-406c-9c3f-ffcf0437047d\"\n"
- + "},\n"
- + " {\n"
- + "\"resource-type\": \"generic-vnf\",\n"
- + "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/8e4ac9cb-c1d3-4a4b-9b1b-3bc60dc4c22d\"\n"
- + "},\n"
- + " {\n"
- + "\"resource-type\": \"generic-vnf\",\n"
- + "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/b04f78e2-2f09-4dd5-bd9d-c6045036966f\"\n"
- + "},\n"
- + " {\n"
- + "\"resource-type\": \"generic-vnf\",\n"
- + "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/e1e44c20-8803-416d-a4ba-c665de36f1aa\"\n"
- + "},\n"
- + " {\n"
- + "\"resource-type\": \"generic-vnf\",\n"
- + "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/823f40cc-683a-4591-b82a-d6457a18e1bb\"\n"
- + "},\n"
- + " {\n"
- + "\"resource-type\": \"generic-vnf\",\n"
- + "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/76f8282a-6099-4d2c-9f8b-b636ba486c23\"\n"
- + "},\n"
- + " {\n"
- + "\"resource-type\": \"generic-vnf\",\n"
- + "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/c6039a4b-54e8-40a5-817d-84d8e87387e8\"\n"
- + "},\n"
- + " {\n"
- + "\"resource-type\": \"generic-vnf\",\n"
- + "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/5ba68684-1c61-48b9-872f-de483fdc5cdb\"\n"
- + "},\n"
- + " {\n"
- + "\"resource-type\": \"generic-vnf\",\n"
- + "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/b0400a1f-4dad-434a-bb36-ac13ef6afbc3\"\n"
- + "},\n"
- + " {\n"
- + "\"resource-type\": \"generic-vnf\",\n"
- + "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/1142a64e-dd13-425e-a218-bf562365dfc9\"\n"
- + "},\n"
- + " {\n"
- + "\"resource-type\": \"generic-vnf\",\n"
- + "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/98c34cbf-da33-4659-9797-4729d2a481df\"\n"
- + "},\n"
- + " {\n"
- + "\"resource-type\": \"generic-vnf\",\n"
- + "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/b043e61c-a73a-446b-83ee-4751cac700e3\"\n"
- + "},\n"
- + " {\n"
- + "\"resource-type\": \"generic-vnf\",\n"
- + "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/82ae1189-c4b9-45e4-870b-95160be90dae\"\n"
- + "},\n"
- + " {\n"
- + "\"resource-type\": \"generic-vnf\",\n"
- + "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/75ddc2c9-d61b-49d9-9d57-22473fd0b7fe\"\n"
- + "},\n"
- + " {\n"
- + "\"resource-type\": \"generic-vnf\",\n"
- + "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/b4443ed1-cfb5-4cc0-aa78-598942354285\"\n"
- + "},\n"
- + " {\n"
- + "\"resource-type\": \"generic-vnf\",\n"
- + "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/c72519e2-3b76-494f-b742-524abd82b6d0\"\n"
- + "},\n"
- + " {\n"
- + "\"resource-type\": \"generic-vnf\",\n"
- + "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/f6561cb3-7a23-44cc-98e3-3a6275e5f340\"\n"
- + "},\n"
- + " {\n"
- + "\"resource-type\": \"generic-vnf\",\n"
+ "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/e3766bc5-40a7-4dbe-9d4a-1d8c8f284913\"\n"
+ "},\n"
+ " {\n"
@@ -157,6 +75,35 @@ public class AaiOverTLSClientServerTest {
+ "],\n"
+ "}";
+ private String subscribersResponsePayload =
+ "{\n"
+ + "\"customer\": [\n"
+ + " {\n"
+ + "\"global-customer-id\": \"DemoCust_752df078-d8e9-4731-abf6-8ae7348075bb\",\n"
+ + "\"subscriber-name\": \"DemoCust_752df078-d8e9-4731-abf6-8ae7348075bb\",\n"
+ + "\"subscriber-type\": \"INFRA\",\n"
+ + "\"resource-version\": \"1536158347585\"\n"
+ + "},\n"
+ + " {\n"
+ + "\"global-customer-id\": \"DemoCust_62bf43a3-4888-4c82-ae98-3ebc3d782761\",\n"
+ + "\"subscriber-name\": \"DemoCust_62bf43a3-4888-4c82-ae98-3ebc3d782761\",\n"
+ + "\"subscriber-type\": \"INFRA\",\n"
+ + "\"resource-version\": \"1536240894581\"\n"
+ + "},\n"
+ + " {\n"
+ + "\"global-customer-id\": \"DemoCust_e84256d6-ef3e-4a28-9741-9987019c3a8f\",\n"
+ + "\"subscriber-name\": \"DemoCust_e84256d6-ef3e-4a28-9741-9987019c3a8f\",\n"
+ + "\"subscriber-type\": \"INFRA\",\n"
+ + "\"resource-version\": \"1536330956393\"\n"
+ + "},\n"
+ + " {\n"
+ + "\"global-customer-id\": \"ETE_Customer_377bb124-2638-4025-a315-cdae04f52bce\",\n"
+ + "\"subscriber-name\": \"ETE_Customer_377bb124-2638-4025-a315-cdae04f52bce\",\n"
+ + "\"subscriber-type\": \"INFRA\",\n"
+ + "\"resource-version\": \"1536088625538\"\n"
+ + "}\n"
+ + "],\n"
+ + "}";
@BeforeClass
public static void setUpClass(){
@@ -171,9 +118,37 @@ public class AaiOverTLSClientServerTest {
@Test
public void shouldSearchNodeTypeByName() throws IOException, ParseException {
- ObjectMapper objectMapper = new ObjectMapper() {
+ ObjectMapper objectMapper = getFasterXmlObjectMapper();
+ AaiOverTLSClient aaiOverTLSClient = new AaiOverTLSClient(new SyncRestClient(objectMapper), propertySupplier, serverUtil.constructTargetUrl("http", ""));
- com.fasterxml.jackson.databind.ObjectMapper om = new com.fasterxml.jackson.databind.ObjectMapper();
+ serverUtil.prepareGetCall("/search/nodes-query", new JSONParser().parse(searchNodesQueryResponsePayload), Action.status(HttpStatus.OK_200));
+
+ HttpResponse<AaiNodeQueryResponse> aaiNodeQueryResponseHttpResponse = aaiOverTLSClient
+ .searchNodeTypeByName("any", ResourceType.GENERIC_VNF);
+
+ AaiNodeQueryResponse body = aaiNodeQueryResponseHttpResponse.getBody();
+ Assertions.assertThat(body.resultData.size()).isEqualTo(5);
+ Assertions.assertThat(aaiNodeQueryResponseHttpResponse.getStatus()).isEqualTo(200);
+ }
+
+ @Test
+ public void shouldGetSubscribers() throws ParseException, JsonProcessingException {
+ ObjectMapper objectMapper = getCodehausObjectMapper();
+ AaiOverTLSClient aaiOverTLSClient = new AaiOverTLSClient(new SyncRestClient(objectMapper), propertySupplier, serverUtil.constructTargetUrl("http", ""));
+
+ serverUtil.prepareGetCall("/business/customers", new JSONParser().parse(subscribersResponsePayload), Action.status(HttpStatus.OK_200));
+
+ HttpResponse<SubscriberList> allSubscribers = aaiOverTLSClient.getAllSubscribers();
+
+ SubscriberList subscriberList = allSubscribers.getBody();
+ Assertions.assertThat(subscriberList.customer.size()).isEqualTo(4);
+ Assertions.assertThat(allSubscribers.getStatus()).isEqualTo(200);
+ }
+
+ private ObjectMapper getCodehausObjectMapper() {
+ return new ObjectMapper() {
+
+ org.codehaus.jackson.map.ObjectMapper om = new org.codehaus.jackson.map.ObjectMapper();
@Override
public <T> T readValue(String s, Class<T> aClass) {
@@ -188,23 +163,36 @@ public class AaiOverTLSClientServerTest {
public String writeValue(Object o) {
try {
return om.writeValueAsString(o);
- } catch (JsonProcessingException e) {
+ } catch (IOException e) {
throw new RuntimeException(e);
}
}
};
- AaiOverTLSClient aaiOverTLSClient = new AaiOverTLSClient(new SyncRestClient(objectMapper), propertySupplier, serverUtil.constructTargetUrl("http", ""));
-
- serverUtil.prepareGetCall("/search/nodes-query", new JSONParser().parse(responsePayload), Action.status(HttpStatus.OK_200));
+ }
- HttpResponse<AaiNodeQueryResponse> aaiNodeQueryResponseHttpResponse = aaiOverTLSClient
- .searchNodeTypeByName("any", ResourceType.GENERIC_VNF);
+ private ObjectMapper getFasterXmlObjectMapper() {
+ return new ObjectMapper() {
- AaiNodeQueryResponse body = aaiNodeQueryResponseHttpResponse.getBody();
- Assertions.assertThat(body.resultData.size()).isEqualTo(25);
- Assertions.assertThat(aaiNodeQueryResponseHttpResponse.getStatus()).isEqualTo(200);
- }
+ com.fasterxml.jackson.databind.ObjectMapper om = new com.fasterxml.jackson.databind.ObjectMapper();
+ @Override
+ public <T> T readValue(String s, Class<T> aClass) {
+ try {
+ return om.readValue(s, aClass);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ @Override
+ public String writeValue(Object o) {
+ try {
+ return om.writeValueAsString(o);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ };
+ }
}
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 5b631a643..4e0e70e89 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
@@ -33,11 +33,13 @@ import org.mockito.runners.MockitoJUnitRunner;
import org.onap.vid.aai.model.AaiNodeQueryResponse;
import org.onap.vid.aai.model.ResourceType;
import org.onap.vid.client.SyncRestClient;
+import org.onap.vid.model.SubscriberList;
@RunWith(MockitoJUnitRunner.class)
public class AaiOverTLSClientTest {
- public static final String SEARCH_NODES_QUERY_SEARCH_NODE_TYPE = "search/nodes-query?search-node-type=generic-vnf&filter=vnf-name:EQUALS:name";
+ private static final String SEARCH_NODES_QUERY_SEARCH_NODE_TYPE = "search/nodes-query?search-node-type=generic-vnf&filter=vnf-name:EQUALS:name";
+ private static final String SUBSCRIBERS = "business/customers?subscriber-type=INFRA&depth=0";
private AaiOverTLSClient aaiRestClient;
@Mock
@@ -51,7 +53,7 @@ public class AaiOverTLSClientTest {
}
@Test
- public void searchNodeTypeByName() {
+ public void testSearchNodeTypeByName() {
mockPropertyReader();
aaiRestClient.searchNodeTypeByName("name", ResourceType.GENERIC_VNF);
@@ -59,6 +61,15 @@ public class AaiOverTLSClientTest {
Matchers.eq(getHeaders()), Matchers.eq(Collections.emptyMap()), Matchers.eq(AaiNodeQueryResponse.class));
}
+ @Test
+ public void testGetAllSubscribers(){
+ mockPropertyReader();
+
+ aaiRestClient.getAllSubscribers();
+ Mockito.verify(syncRestClient).get(Matchers.contains(SUBSCRIBERS),
+ Matchers.eq(getHeaders()), Matchers.eq(Collections.emptyMap()), Matchers.eq(SubscriberList.class));
+ }
+
private void mockPropertyReader() {
Mockito.when(propertySupplier.getPassword()).thenReturn("Pass");
Mockito.when(propertySupplier.getUsername()).thenReturn("User");
diff --git a/vid-app-common/src/test/java/org/onap/vid/config/JobCommandsConfigWithMockedMso.java b/vid-app-common/src/test/java/org/onap/vid/config/JobCommandsConfigWithMockedMso.java
index e5b3c365a..c1ac6a219 100644
--- a/vid-app-common/src/test/java/org/onap/vid/config/JobCommandsConfigWithMockedMso.java
+++ b/vid-app-common/src/test/java/org/onap/vid/config/JobCommandsConfigWithMockedMso.java
@@ -27,7 +27,6 @@ import java.io.IOException;
import org.hibernate.SessionFactory;
import org.mockito.Mockito;
import org.onap.portalsdk.core.service.DataAccessService;
-import org.onap.vid.aai.AaiClientInterface;
import org.onap.vid.aai.AaiOverTLSClient;
import org.onap.vid.aai.AaiOverTLSClientInterface;
import org.onap.vid.aai.AaiOverTLSPropertySupplier;
@@ -123,9 +122,8 @@ public class JobCommandsConfigWithMockedMso {
JobAdapter jobAdapter,
JobsBrokerService jobsBrokerService,
SessionFactory sessionFactory,
- AaiClientInterface aaiClient,
AaiOverTLSClientInterface aaiOverTLSClientInterface) {
- return new AsyncInstantiationBusinessLogicImpl(dataAccessService, jobAdapter, jobsBrokerService, sessionFactory, aaiClient, aaiOverTLSClientInterface);
+ return new AsyncInstantiationBusinessLogicImpl(dataAccessService, jobAdapter, jobsBrokerService, sessionFactory, aaiOverTLSClientInterface);
}
@Bean
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java
index ae6c2ccca..70a454a75 100644
--- a/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java
@@ -1,5 +1,27 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018 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.services;
+import io.joshworks.restclient.http.HttpResponse;
import java.util.Collection;
import java.util.List;
@@ -55,7 +77,7 @@ public class AaiServiceImplTest {
@Test
public void testGetFullSubscriberList_1() throws Exception {
AaiServiceImpl testSubject;
- AaiResponse<SubscriberList> result;
+ HttpResponse<SubscriberList> result;
// default test
try {
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java
index c3d01283d..7ad49a968 100644
--- a/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java
@@ -1,8 +1,36 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018 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.services;
import com.google.common.collect.ImmutableMap;
+import io.joshworks.restclient.http.HttpResponse;
+import java.io.UnsupportedEncodingException;
import jersey.repackaged.com.google.common.collect.ImmutableList;
-import org.onap.vid.aai.AaiClientInterface;
+import org.apache.http.HttpStatus;
+import org.apache.http.HttpVersion;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.DefaultHttpResponseFactory;
+import org.apache.http.message.BasicStatusLine;
+import org.onap.vid.aai.AaiOverTLSClientInterface;
import org.onap.vid.aai.AaiResponse;
import org.onap.vid.aai.model.AaiNodeQueryResponse;
import org.onap.vid.aai.model.ResourceType;
@@ -13,8 +41,6 @@ import org.onap.vid.model.serviceInstantiation.VfModule;
import org.onap.vid.model.serviceInstantiation.Vnf;
import org.onap.vid.mso.RestObject;
import org.onap.vid.mso.rest.AsyncRequestStatus;
-import org.onap.vid.services.AsyncInstantiationBusinessLogic;
-import org.onap.vid.services.AsyncInstantiationBusinessLogicTest;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.togglz.core.manager.FeatureManager;
@@ -48,7 +74,7 @@ public class AsyncInstantiationBaseTest extends AbstractTestNGSpringContextTests
protected FeatureManager featureManager;
@Inject
- protected AaiClientInterface aaiClient;
+ protected AaiOverTLSClientInterface aaiClient;
public ServiceInstantiation generateMockServiceInstantiationPayload(boolean isPause, Map<String, Vnf> vnfs, int bulkSize, boolean isUserProvidedNaming, String projectName, boolean rollbackOnFailure) {
ModelInfo modelInfo = createModelInfo();
@@ -174,12 +200,15 @@ public class AsyncInstantiationBaseTest extends AbstractTestNGSpringContextTests
return restObject;
}
- protected void mockAaiClientAnyNameFree() {
+ protected void mockAaiClientAnyNameFree() throws UnsupportedEncodingException {
when(aaiClient.searchNodeTypeByName(any(), any())).thenReturn(aaiNodeQueryResponseNameFree());
}
- protected AaiResponse<AaiNodeQueryResponse> aaiNodeQueryResponseNameFree() {
- return new AaiResponse<>(new AaiNodeQueryResponse(null),"", 200);
+ protected HttpResponse<AaiNodeQueryResponse> aaiNodeQueryResponseNameFree() throws UnsupportedEncodingException {
+ org.apache.http.HttpResponse response = new DefaultHttpResponseFactory().newHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, null), null);
+ response.setEntity(new StringEntity(""));
+
+ return HttpResponse.fallback(new AaiNodeQueryResponse(null));
}
protected AaiResponse<AaiNodeQueryResponse> aaiNodeQueryBadResponse() {