summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgolabek <tomasz.golabek@nokia.com>2018-08-29 15:29:56 +0200
committergolabek <tomasz.golabek@nokia.com>2018-11-15 10:43:56 +0100
commit34f18a178b4b38632f435e776e15ce2f79d58094 (patch)
tree7bb78584134cbbe35f2db7f0f30ee0cd9ca7065b
parentf4766e0a53cb3e8408d56aaa113e6350024566b3 (diff)
Get subscribers rewritten to new rest client
Should be merged after: I561f8a5d95ec35fdddc648b24965dd9dac03c9a4 It contains cherry-picked changes from that review Change-Id: I22a9e9ce709ae4dd3abcf7a9cda6354a4f656b00 Issue-ID: VID-269 Signed-off-by: golabek <tomasz.golabek@nokia.com>
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClient.java7
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClientInterface.java5
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/controllers/WebConfig.java44
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/roles/RoleProvider.java10
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/AaiService.java24
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java43
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java7
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/RoleGenaratorServiceImpl.java39
-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
13 files changed, 306 insertions, 139 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClient.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClient.java
index 58bf3f360..4f98bd37c 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClient.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClient.java
@@ -39,6 +39,7 @@ import org.onap.vid.aai.model.AaiNodeQueryResponse;
import org.onap.vid.aai.model.ResourceType;
import org.onap.vid.aai.util.AAIProperties;
import org.onap.vid.client.SyncRestClientInterface;
+import org.onap.vid.model.SubscriberList;
public class AaiOverTLSClient implements AaiOverTLSClientInterface {
@@ -69,6 +70,12 @@ public class AaiOverTLSClient implements AaiOverTLSClientInterface {
return syncRestClient.get(uri, getRequestHeaders(), Collections.emptyMap(), AaiNodeQueryResponse.class);
}
+ @Override
+ public HttpResponse<SubscriberList> getAllSubscribers() {
+ val uri = urlBase + String.format(URIS.SUBSCRIBERS, 0);
+ return syncRestClient.get(uri, getRequestHeaders(), Collections.emptyMap(), SubscriberList.class);
+ }
+
private Map<String, String> getRequestHeaders() {
val result = HashMap.of(
TRANSACTION_ID_HEADER, propertySupplier.getRandomUUID(),
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClientInterface.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClientInterface.java
index 252fed887..ad43746ca 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClientInterface.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClientInterface.java
@@ -24,10 +24,13 @@ import io.joshworks.restclient.http.HttpResponse;
import org.onap.portalsdk.core.util.SystemProperties;
import org.onap.vid.aai.model.AaiNodeQueryResponse;
import org.onap.vid.aai.model.ResourceType;
+import org.onap.vid.model.SubscriberList;
public interface AaiOverTLSClientInterface {
class URIS {
+
+ static final String SUBSCRIBERS = "business/customers?subscriber-type=INFRA&depth=%s";
static final String NODE_TYPE_BY_NAME = "search/nodes-query?search-node-type=%s&filter=%s:EQUALS:%s";
}
@@ -43,4 +46,6 @@ public interface AaiOverTLSClientInterface {
HttpResponse<AaiNodeQueryResponse> searchNodeTypeByName(String name, ResourceType type);
+ HttpResponse<SubscriberList> getAllSubscribers();
+
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/controllers/WebConfig.java b/vid-app-common/src/main/java/org/onap/vid/controllers/WebConfig.java
index fb8b5195c..56dce9ac7 100644
--- a/vid-app-common/src/main/java/org/onap/vid/controllers/WebConfig.java
+++ b/vid-app-common/src/main/java/org/onap/vid/controllers/WebConfig.java
@@ -22,7 +22,7 @@
package org.onap.vid.controllers;
import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import io.joshworks.restclient.http.mapper.ObjectMapper;
import java.io.IOException;
import org.onap.vid.aai.AaiClient;
import org.onap.vid.aai.AaiClientInterface;
@@ -70,8 +70,8 @@ public class WebConfig {
* @return the object mapper
*/
@Bean
- public ObjectMapper getObjectMapper() {
- return new ObjectMapper();
+ public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper() {
+ return new com.fasterxml.jackson.databind.ObjectMapper();
}
@@ -166,13 +166,41 @@ public class WebConfig {
return new SchedulerRestInterface();
}
+ @Bean(name = "aaiClientForFasterXmlMapping")
+ public AaiOverTLSClientInterface getAaiClientForFasterXmlMapping(){
+ ObjectMapper objectMapper = new ObjectMapper() {
- @Bean
- public AaiOverTLSClientInterface getAaiOverTLSClientInterface() {
+ com.fasterxml.jackson.databind.ObjectMapper om = new com.fasterxml.jackson.databind.ObjectMapper();
- io.joshworks.restclient.http.mapper.ObjectMapper objectMapper = new io.joshworks.restclient.http.mapper.ObjectMapper() {
+ @Override
+ public <T> T readValue(String s, Class<T> aClass) {
+ try {
+ return om.readValue(s, aClass);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
- ObjectMapper om = new ObjectMapper();
+ @Override
+ public String writeValue(Object o) {
+ try {
+ return om.writeValueAsString(o);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ };
+
+ return new AaiOverTLSClient(new SyncRestClient(objectMapper), new AaiOverTLSPropertySupplier());
+ }
+
+
+ @Bean(name = "aaiClientForCodehausMapping")
+ public AaiOverTLSClientInterface getAaiClientForCodehausMapping() {
+
+ ObjectMapper objectMapper = new ObjectMapper() {
+
+ org.codehaus.jackson.map.ObjectMapper om = new org.codehaus.jackson.map.ObjectMapper();
@Override
public <T> T readValue(String s, Class<T> aClass) {
@@ -187,7 +215,7 @@ public class WebConfig {
public String writeValue(Object o) {
try {
return om.writeValueAsString(o);
- } catch (JsonProcessingException e) {
+ } catch (IOException e) {
throw new RuntimeException(e);
}
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/roles/RoleProvider.java b/vid-app-common/src/main/java/org/onap/vid/roles/RoleProvider.java
index 5c1ee9e89..b83f751fe 100644
--- a/vid-app-common/src/main/java/org/onap/vid/roles/RoleProvider.java
+++ b/vid-app-common/src/main/java/org/onap/vid/roles/RoleProvider.java
@@ -2,7 +2,8 @@
* ============LICENSE_START=======================================================
* VID
* ================================================================================
- * Modifications Copyright 2018 Nokia
+ * 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.
@@ -22,6 +23,7 @@ package org.onap.vid.roles;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
+import io.joshworks.restclient.http.HttpResponse;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.portalsdk.core.web.support.UserUtils;
import org.onap.vid.aai.AaiResponse;
@@ -58,8 +60,8 @@ public class RoleProvider {
public void init() {
LOG.debug(EELFLoggerDelegate.debugLogger, "Role provider => init method started");
- AaiResponse<SubscriberList> subscribersResponse = aaiService.getFullSubscriberList();
- subscribers = subscribersResponse.getT();
+ HttpResponse<SubscriberList> subscribersResponse = aaiService.getFullSubscriberList();
+ subscribers = subscribersResponse.getBody();
LOG.debug(EELFLoggerDelegate.debugLogger, "Role provider => init method finished");
}
@@ -69,7 +71,7 @@ public class RoleProvider {
LOG.debug(EELFLoggerDelegate.debugLogger, logPrefix + "Entering to get user role for user " + UserUtils.getUserId(request));
List<Role> roleList = new ArrayList<>();
-
+
Map roles = UserUtils.getRoles(request);
for (Object role : roles.keySet()) {
org.onap.portalsdk.core.domain.Role sdkRol = (org.onap.portalsdk.core.domain.Role) roles.get(role);
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AaiService.java b/vid-app-common/src/main/java/org/onap/vid/services/AaiService.java
index f3e0bfdab..d2ee32cbc 100644
--- a/vid-app-common/src/main/java/org/onap/vid/services/AaiService.java
+++ b/vid-app-common/src/main/java/org/onap/vid/services/AaiService.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 org.onap.vid.aai.AaiResponse;
import org.onap.vid.aai.AaiResponseTranslator;
import org.onap.vid.aai.SubscriberFilteredResults;
@@ -28,7 +50,7 @@ public interface AaiService {
AaiResponse getServiceInstanceSearchResults(String subscriberId, String instanceIdentifier, RoleValidator roleProvider, List<String> owningEntities, List<String> projects);
- AaiResponse<SubscriberList> getFullSubscriberList();
+ HttpResponse<SubscriberList> getFullSubscriberList();
AaiResponse getServices(RoleValidator roleValidator);
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java
index 4de2cc740..c5bee2448 100644
--- a/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java
+++ b/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.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 org.apache.http.HttpStatus;
import org.codehaus.jackson.JsonNode;
import org.onap.vid.aai.*;
@@ -30,6 +52,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
+import org.springframework.beans.factory.annotation.Qualifier;
/**
* Created by Oren on 7/4/17.
@@ -45,6 +68,10 @@ public class AaiServiceImpl implements AaiService {
private AaiClientInterface aaiClient;
@Autowired
+ @Qualifier("aaiClientForCodehausMapping")
+ private AaiOverTLSClientInterface aaiOverTLSClient;
+
+ @Autowired
private AaiResponseTranslator aaiResponseTranslator;
private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(AaiServiceImpl.class);
@@ -162,11 +189,13 @@ public class AaiServiceImpl implements AaiService {
@Override
public SubscriberFilteredResults getFullSubscriberList(RoleValidator roleValidator) {
- AaiResponse<SubscriberList> subscriberResponse = aaiClient.getAllSubscribers();
-
- return new SubscriberFilteredResults(roleValidator, subscriberResponse.getT(),
- subscriberResponse.getErrorMessage(),
- subscriberResponse.getHttpCode());
+ HttpResponse<SubscriberList> allSubscribers = aaiOverTLSClient.getAllSubscribers();
+ return new SubscriberFilteredResults(
+ roleValidator,
+ allSubscribers.getBody(),
+ allSubscribers.getStatusText(),
+ allSubscribers.getStatus()
+ );
}
@Override
@@ -175,8 +204,8 @@ public class AaiServiceImpl implements AaiService {
}
@Override
- public AaiResponse<SubscriberList> getFullSubscriberList() {
- return aaiClient.getAllSubscribers();
+ public HttpResponse<SubscriberList> getFullSubscriberList() {
+ return aaiOverTLSClient.getAllSubscribers();
}
@Override
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java
index 871f56460..df8e92d66 100644
--- a/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java
+++ b/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java
@@ -60,6 +60,7 @@ import org.onap.vid.utils.DaoUtils;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.portalsdk.core.service.DataAccessService;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import java.sql.Timestamp;
@@ -85,8 +86,6 @@ public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBu
private SessionFactory sessionFactory;
- private AaiClientInterface aaiClient;
-
private AaiOverTLSClientInterface aaiOverTLSClient;
private int maxRetriesGettingFreeNameFromAai = MAX_RETRIES_GETTING_FREE_NAME_FROM_AAI;
@@ -110,13 +109,11 @@ public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBu
JobAdapter jobAdapter,
JobsBrokerService jobService,
SessionFactory sessionFactory,
- AaiClientInterface aaiClient,
- AaiOverTLSClientInterface aaiOverTLSClient) {
+ @Qualifier("aaiClientForFasterXmlMapping") AaiOverTLSClientInterface aaiOverTLSClient) {
this.dataAccessService = dataAccessService;
this.jobAdapter = jobAdapter;
this.jobService = jobService;
this.sessionFactory = sessionFactory;
- this.aaiClient = aaiClient;
this.aaiOverTLSClient = aaiOverTLSClient;
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/RoleGenaratorServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/RoleGenaratorServiceImpl.java
index 635cb4855..500f5ac7f 100644
--- a/vid-app-common/src/main/java/org/onap/vid/services/RoleGenaratorServiceImpl.java
+++ b/vid-app-common/src/main/java/org/onap/vid/services/RoleGenaratorServiceImpl.java
@@ -1,7 +1,30 @@
+/*-
+ * ============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 jline.internal.Log;
import org.onap.vid.aai.AaiClientInterface;
+import org.onap.vid.aai.AaiOverTLSClientInterface;
import org.onap.vid.aai.AaiResponse;
import org.onap.vid.aai.ServiceSubscription;
import org.onap.vid.aai.Services;
@@ -9,6 +32,7 @@ import org.onap.vid.model.ModelConstants;
import org.onap.vid.model.Subscriber;
import org.onap.vid.model.SubscriberList;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import java.util.HashMap;
@@ -17,9 +41,14 @@ import java.util.HashMap;
public class RoleGenaratorServiceImpl implements RoleGeneratorService {
public static final String ROLE_ID_COLUMN = "ROLE_ID";
+
@Autowired
AaiClientInterface client;
+ @Autowired
+ @Qualifier("aaiClientForCodehausMapping")
+ AaiOverTLSClientInterface aaiOverTLSClient;
+
public static final String DB_NAME = "vid_portal";
public static final String TBL_NAME = "fn_role";
public static final String TEMP_DELIMITER ="***";
@@ -30,11 +59,11 @@ public class RoleGenaratorServiceImpl implements RoleGeneratorService {
String query = "USE " + DB_NAME + ";\r\n" +
"SET SQL_SAFE_UPDATES = 0;\r\n";
try {
- AaiResponse<SubscriberList> subscribers = client.getAllSubscribers();
+ HttpResponse<SubscriberList> allSubscribers = aaiOverTLSClient.getAllSubscribers();
if (firstRun) {
- query += replaceRolesToTempDelimiter("subscriber",buildSubscribersValuesForMappingsTable(subscribers.getT()));
+ query += replaceRolesToTempDelimiter("subscriber",buildSubscribersValuesForMappingsTable(allSubscribers.getBody()));
}
- query += addAvailableRolesCombination(firstRun, subscribers);
+ query += addAvailableRolesCombination(firstRun, allSubscribers.getBody());
}
catch (Exception e) {
@@ -43,10 +72,10 @@ public class RoleGenaratorServiceImpl implements RoleGeneratorService {
return query;
}
- private String addAvailableRolesCombination(Boolean firstRun, AaiResponse<SubscriberList> subscribers) {
+ private String addAvailableRolesCombination(Boolean firstRun, SubscriberList subscribers) {
String query, availableRoles="";
HashMap<String,String> servicesNames = new HashMap<String,String>();
- for (Subscriber subscriber: subscribers.getT().customer) {
+ for (Subscriber subscriber: subscribers.customer) {
AaiResponse<Services> subscriberResponse = client.getSubscriberData(subscriber.globalCustomerId);
for(ServiceSubscription service: subscriberResponse.getT().serviceSubscriptions.serviceSubscription) {
servicesNames.put(service.serviceType,"");
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() {