summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xepsdk-app-onap/src/main/webapp/WEB-INF/conf/system.properties2
-rwxr-xr-xepsdk-app-onap/src/main/webapp/WEB-INF/conf/system_template.properties2
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/AaiGetVnfResponse.java8
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/SubscriberListWithFilterData.java7
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/RelationshipList.java11
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/VnfResult.java19
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/util/AAIRestInterface.java2
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java88
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/roles/AlwaysValidRoleValidator.java43
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/roles/RoleProvider.java15
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/roles/RoleValidator.java75
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorByRoles.java80
-rw-r--r--vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.controller.js31
-rw-r--r--vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.controller.test.js22
-rw-r--r--vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.html2
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/AaiGetVnfResponseTest.java88
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/OperationalEnvironmentTest.java28
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/SubscriberAaiResponseTest.java36
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/SubscriberFilteredResultsTest.java86
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/model/ServicePropertiesTest.java (renamed from vid-app-common/src/test/java/org/onap/vid/aai/ServicePropertiesTest.java)6
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/model/VnfResultTest.java (renamed from vid-app-common/src/test/java/org/onap/vid/aai/VnfResultTest.java)7
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/util/AAIRestInterfaceTest.java302
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/util/SingleAAIRestInterfaceTest.java315
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/bl/AaiServiceTest.java28
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java48
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/controller/ControllersUtilsTest.java31
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/controller/ServicePermissionsTest.java16
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/roles/AlwaysValidRoleValidatorTest.java43
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/roles/RoleValidatorByRolesTest.java (renamed from vid-app-common/src/test/java/org/onap/vid/roles/RoleValidatorTest.java)16
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java5
-rw-r--r--vid-app-common/src/test/resources/WEB-INF/conf/system.properties2
-rw-r--r--vid-ext-services-simulator/src/main/resources/preset_registration/changeManagement/mso_get_manual_task.json2
32 files changed, 861 insertions, 605 deletions
diff --git a/epsdk-app-onap/src/main/webapp/WEB-INF/conf/system.properties b/epsdk-app-onap/src/main/webapp/WEB-INF/conf/system.properties
index 9310da082..a14aa49df 100755
--- a/epsdk-app-onap/src/main/webapp/WEB-INF/conf/system.properties
+++ b/epsdk-app-onap/src/main/webapp/WEB-INF/conf/system.properties
@@ -107,6 +107,8 @@ decryption_key = AGLDdG4D04BKm2IxIWEr8o==
element_map_file_path = app/fusionapp/files/
element_map_icon_path = app/fusionapp/icons/
+role_management_activated = false
+
#aai related properties
#aai.server.url.base=https://aai.api.openecomp.org:8443/aai/
#aai.server.url=https://aai.api.openecomp.org:8443/aai/v8/
diff --git a/epsdk-app-onap/src/main/webapp/WEB-INF/conf/system_template.properties b/epsdk-app-onap/src/main/webapp/WEB-INF/conf/system_template.properties
index f5955a50c..b7b8f93d8 100755
--- a/epsdk-app-onap/src/main/webapp/WEB-INF/conf/system_template.properties
+++ b/epsdk-app-onap/src/main/webapp/WEB-INF/conf/system_template.properties
@@ -64,6 +64,8 @@ decryption_key = ${VID_DECRYPTION_KEY}
element_map_file_path = /tmp
element_map_icon_path = app/vid/icons/
+role_management_activated = false
+
#aai related properties
aai.server.url.base=${VID_AAI_URL}/aai/
aai.server.url=${VID_AAI_URL}/aai/v13/
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiGetVnfResponse.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiGetVnfResponse.java
index 3938b164c..a62076073 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/AaiGetVnfResponse.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiGetVnfResponse.java
@@ -48,6 +48,14 @@ public class AaiGetVnfResponse {
this.additionalProperties.put(name, value);
}
+ public List<VnfResult> getResults() {
+ return results;
+ }
+
+ public void setResults(List<VnfResult> results) {
+ this.results = results;
+ }
+
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/SubscriberListWithFilterData.java b/vid-app-common/src/main/java/org/onap/vid/aai/SubscriberListWithFilterData.java
index 6059eec74..d03362ba8 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/SubscriberListWithFilterData.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/SubscriberListWithFilterData.java
@@ -34,7 +34,7 @@ public class SubscriberListWithFilterData {
public SubscriberListWithFilterData(SubscriberList subscriberList, RoleValidator roleValidator){
List<Subscriber> subscribers = subscriberList != null ? subscriberList.customer : new ArrayList<>();
- List<SubscriberWithFilter> subscribersWithFilter = new ArrayList<>();
+ customer = new ArrayList<>();
for (Subscriber subscriber :subscribers){
SubscriberWithFilter subscriberWithFilter = new SubscriberWithFilter();
subscriberWithFilter.setIsPermitted(roleValidator.isSubscriberPermitted(subscriber.globalCustomerId));
@@ -42,10 +42,9 @@ public class SubscriberListWithFilterData {
subscriberWithFilter.resourceVersion = subscriber.resourceVersion;
subscriberWithFilter.subscriberName = subscriber.subscriberName;
subscriberWithFilter.globalCustomerId = subscriber.globalCustomerId;
- subscribersWithFilter.add(subscriberWithFilter);
+ customer.add(subscriberWithFilter);
}
- this.customer = subscribersWithFilter;
- }
+ }
public List<SubscriberWithFilter> customer;
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/RelationshipList.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/RelationshipList.java
index c30570d22..d6eb0526f 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/model/RelationshipList.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/RelationshipList.java
@@ -27,20 +27,17 @@ import java.util.List;
@JsonIgnoreProperties(ignoreUnknown = true)
public class RelationshipList {
-
+
+ public List<Relationship> relationship;
+
@JsonProperty("relationship")
public List<Relationship> getRelationship() {
return relationship;
}
-
+
@JsonProperty("relationship")
public void setRelationship(List<Relationship> relationship) {
this.relationship = relationship;
}
- public List<Relationship> relationship;
-
-
-
-
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/VnfResult.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/VnfResult.java
index 677602be1..6cbd8cdbf 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/model/VnfResult.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/VnfResult.java
@@ -25,6 +25,7 @@ import com.fasterxml.jackson.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
@JsonInclude(JsonInclude.Include.NON_NULL)
@@ -83,4 +84,22 @@ public class VnfResult {
public void setJsonAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ VnfResult vnfResult = (VnfResult) o;
+ return Objects.equals(id, vnfResult.id) &&
+ Objects.equals(nodeType, vnfResult.nodeType) &&
+ Objects.equals(url, vnfResult.url) &&
+ Objects.equals(properties, vnfResult.properties) &&
+ Objects.equals(relatedTo, vnfResult.relatedTo) &&
+ Objects.equals(additionalProperties, vnfResult.additionalProperties);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id, nodeType, url, properties, relatedTo, additionalProperties);
+ }
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/util/AAIRestInterface.java b/vid-app-common/src/main/java/org/onap/vid/aai/util/AAIRestInterface.java
index 8f53fcdbf..92d8de757 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/util/AAIRestInterface.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/util/AAIRestInterface.java
@@ -133,7 +133,7 @@ public class AAIRestInterface {
*
* @param baseURL the base URL
*/
- public void SetRestSrvrBaseURL(String baseURL)
+ public void setRestSrvrBaseURL(String baseURL)
{
if (baseURL == null) {
logger.info(EELFLoggerDelegate.errorLogger, "REST Server base URL cannot be null.");
diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java b/vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java
index e2a914004..3aff7fea7 100644
--- a/vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java
+++ b/vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java
@@ -3,6 +3,7 @@
* VID
* ================================================================================
* Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications 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.
@@ -20,7 +21,19 @@
package org.onap.vid.controller;
+import static org.onap.vid.utils.Logging.getMethodName;
+
import com.fasterxml.jackson.databind.ObjectMapper;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.stream.Collectors;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.onap.portalsdk.core.controller.RestrictedBaseController;
@@ -47,25 +60,15 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.ModelAndView;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.DefaultValue;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Response;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import java.util.stream.Collectors;
-
-import static org.onap.vid.utils.Logging.getMethodName;
-
/**
* Controller to handle a&ai requests.
*/
@@ -73,35 +76,26 @@ import static org.onap.vid.utils.Logging.getMethodName;
@RestController
public class AaiController extends RestrictedBaseController {
- /**
- * The from app id.
- */
- private String fromAppId = "VidAaiController";
- /**
- * The logger.
- */
private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(AaiController.class);
- /**
- * The model.
- */
- private Map<String, Object> model = new HashMap<>();
- /**
- * The servlet context.
- */
- @Autowired
- private ServletContext servletContext;
- /**
- * aai service
- */
- @Autowired
+ private static final String FROM_APP_ID = "VidAaiController";
+
private AaiService aaiService;
- @Autowired
- private RoleProvider roleProvider;
- @Autowired
private AAIRestInterface aaiRestInterface;
- @Autowired
+ private RoleProvider roleProvider;
private SystemPropertiesWrapper systemPropertiesWrapper;
+ @Autowired
+ public AaiController(AaiService aaiService,
+ AAIRestInterface aaiRestInterface,
+ RoleProvider roleProvider,
+ SystemPropertiesWrapper systemPropertiesWrapper) {
+
+ this.aaiService = aaiService;
+ this.aaiRestInterface = aaiRestInterface;
+ this.roleProvider = roleProvider;
+ this.systemPropertiesWrapper = systemPropertiesWrapper;
+ }
+
/**
* Welcome method.
*
@@ -155,7 +149,7 @@ public class AaiController extends RestrictedBaseController {
*/
@RequestMapping(value = "/aai_get_services", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> doGetServices(HttpServletRequest request) throws IOException {
- RoleValidator roleValidator = new RoleValidator(roleProvider.getUserRoles(request));
+ RoleValidator roleValidator = RoleValidator.by(roleProvider.getUserRoles(request));
AaiResponse subscriberList = aaiService.getServices(roleValidator);
return aaiResponseToResponseEntity(subscriberList);
@@ -279,7 +273,7 @@ public class AaiController extends RestrictedBaseController {
public ResponseEntity<String> getFullSubscriberList(HttpServletRequest request) throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
ResponseEntity<String> responseEntity;
- RoleValidator roleValidator = new RoleValidator(roleProvider.getUserRoles(request));
+ RoleValidator roleValidator = RoleValidator.by(roleProvider.getUserRoles(request));
SubscriberFilteredResults subscriberList = aaiService.getFullSubscriberList(roleValidator);
if (subscriberList.getHttpCode() == 200) {
responseEntity = new ResponseEntity<>(objectMapper.writeValueAsString(subscriberList.getSubscriberList()), HttpStatus.OK);
@@ -342,7 +336,7 @@ public class AaiController extends RestrictedBaseController {
ObjectMapper objectMapper = new ObjectMapper();
ResponseEntity responseEntity;
List<Role> roles = roleProvider.getUserRoles(request);
- RoleValidator roleValidator = new RoleValidator(roles);
+ RoleValidator roleValidator = RoleValidator.by(roles);
AaiResponse subscriberData = aaiService.getSubscriberData(subscriberId, roleValidator);
String httpMessage = subscriberData.getT() != null ?
objectMapper.writeValueAsString(subscriberData.getT()) :
@@ -371,7 +365,7 @@ public class AaiController extends RestrictedBaseController {
ResponseEntity responseEntity;
List<Role> roles = roleProvider.getUserRoles(request);
- RoleValidator roleValidator = new RoleValidator(roles);
+ RoleValidator roleValidator = RoleValidator.by(roles);
AaiResponse<ServiceInstancesSearchResults> searchResult = aaiService.getServiceInstanceSearchResults(subscriberId, instanceIdentifier, roleValidator, owningEntities, projects);
@@ -533,7 +527,7 @@ public class AaiController extends RestrictedBaseController {
try {
ObjectMapper objectMapper = new ObjectMapper();
List<Role> roles = roleProvider.getUserRoles(request);
- RoleValidator roleValidator = new RoleValidator(roles);
+ RoleValidator roleValidator = RoleValidator.by(roles);
AaiResponse<GetTenantsResponse[]> response = aaiService.getTenants(globalCustomerId, serviceType, roleValidator);
if (response.getHttpCode() == 200) {
responseEntity = new ResponseEntity<String>(objectMapper.writeValueAsString(response.getT()), HttpStatus.OK);
@@ -620,7 +614,7 @@ public class AaiController extends RestrictedBaseController {
try {
- resp = aaiRestInterface.RestGet(fromAppId, transId, Unchecked.toURI(uri), xml).getResponse();
+ resp = aaiRestInterface.RestGet(FROM_APP_ID, transId, Unchecked.toURI(uri), xml).getResponse();
} catch (WebApplicationException e) {
final String message = e.getResponse().readEntity(String.class);
@@ -649,7 +643,7 @@ public class AaiController extends RestrictedBaseController {
Response resp = null;
try {
- resp = aaiRestInterface.RestPost(fromAppId, uri, payload, xml);
+ resp = aaiRestInterface.RestPost(FROM_APP_ID, uri, payload, xml);
} catch (Exception e) {
LOGGER.info(EELFLoggerDelegate.errorLogger, "<== " + "." + methodName + e.toString());
diff --git a/vid-app-common/src/main/java/org/onap/vid/roles/AlwaysValidRoleValidator.java b/vid-app-common/src/main/java/org/onap/vid/roles/AlwaysValidRoleValidator.java
new file mode 100644
index 000000000..4e5340fc2
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/roles/AlwaysValidRoleValidator.java
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. 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.roles;
+
+public class AlwaysValidRoleValidator implements RoleValidator {
+
+ AlwaysValidRoleValidator() {
+ // package visibility, only for RoleValidator's factory
+ }
+
+ @Override
+ public boolean isSubscriberPermitted(String subscriberName) {
+ return true;
+ }
+
+ @Override
+ public boolean isServicePermitted(String subscriberName, String serviceType) {
+ return true;
+ }
+
+ @Override
+ public boolean isTenantPermitted(String globalCustomerId, String serviceType, String tenantName) {
+ return true;
+ }
+}
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 d3d2b80e2..6c0fd3f52 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
@@ -24,6 +24,14 @@ package org.onap.vid.roles;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.joshworks.restclient.http.HttpResponse;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import javax.servlet.http.HttpServletRequest;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.portalsdk.core.web.support.UserUtils;
import org.onap.vid.aai.exceptions.RoleParsingException;
@@ -34,11 +42,6 @@ import org.onap.vid.services.AaiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import javax.servlet.http.HttpServletRequest;
-import java.util.*;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-
/**
* Created by Oren on 7/1/17.
@@ -159,7 +162,7 @@ public class RoleProvider {
}
public RoleValidator getUserRolesValidator(HttpServletRequest request) {
- return new RoleValidator(getUserRoles(request));
+ return RoleValidator.by(getUserRoles(request));
}
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidator.java b/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidator.java
index 315e22dd7..d37477610 100644
--- a/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidator.java
+++ b/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidator.java
@@ -3,13 +3,14 @@
* VID
* ================================================================================
* Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications 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.
@@ -20,70 +21,24 @@
package org.onap.vid.roles;
-import org.onap.vid.mso.rest.RequestDetails;
-
import java.util.List;
-import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
+import org.onap.portalsdk.core.util.SystemProperties;
-/**
- * Created by Oren on 7/12/17.
- */
-public class RoleValidator {
+public interface RoleValidator {
- private boolean disableRoles = true;
- private List<Role> userRoles;
+ static RoleValidator by(List<Role> roles) {
+ boolean disableRoles =
+ StringUtils.equals(SystemProperties.getProperty("role_management_activated"), "false");
- public RoleValidator(List<Role> roles) {
- this.userRoles = roles;
+ return disableRoles
+ ? new AlwaysValidRoleValidator()
+ : new RoleValidatorByRoles(roles);
}
- public boolean isSubscriberPermitted(String subscriberName) {
- if (this.disableRoles) return true;
-
- for (Role role : userRoles) {
- if (role.getSubscribeName().equals(subscriberName))
- return true;
- }
- return false;
- }
-
- public boolean isServicePermitted(String subscriberName, String serviceType) {
- if (this.disableRoles) return true;
-
- for (Role role : userRoles) {
- if (role.getSubscribeName().equals(subscriberName) && role.getServiceType().equals(serviceType))
- return true;
- }
- return false;
- }
+ boolean isSubscriberPermitted(String subscriberName);
- public boolean isMsoRequestValid(RequestDetails mso_request) {
- if (this.disableRoles) return true;
+ boolean isServicePermitted(String subscriberName, String serviceType);
- try {
- String globalSubscriberIdRequested = (String) ((Map) ((Map) mso_request.getAdditionalProperties().get("requestDetails")).get("subscriberInfo")).get("globalSubscriberId");
- String serviceType = (String) ((Map) ((Map) mso_request.getAdditionalProperties().get("requestDetails")).get("requestParameters")).get("subscriptionServiceType");
- return isServicePermitted(globalSubscriberIdRequested, serviceType);
- } catch (Exception e) {
- //Until we'll get the exact information regarding the tenants and the global customer id, we'll return true on unknown requests to mso
- return true;
- }
- }
-
- public boolean isTenantPermitted(String globalCustomerId, String serviceType, String tenantName) {
- if (this.disableRoles) return true;
-
- for (Role role : userRoles) {
- if (role.getSubscribeName().equals(globalCustomerId)
- && role.getServiceType().equals(serviceType)
- && (role.getTenant() == null || role.getTenant().equalsIgnoreCase(tenantName))) {
- return true;
- }
- }
- return false;
- }
-
- void enableRoles() {
- this.disableRoles = false;
- }
+ boolean isTenantPermitted(String globalCustomerId, String serviceType, String tenantName);
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorByRoles.java b/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorByRoles.java
new file mode 100644
index 000000000..ad5b519c4
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorByRoles.java
@@ -0,0 +1,80 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. 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.roles;
+
+import java.util.List;
+import java.util.Map;
+import org.onap.vid.mso.rest.RequestDetails;
+
+public class RoleValidatorByRoles implements RoleValidator {
+
+ private final List<Role> userRoles;
+
+ RoleValidatorByRoles(List<Role> roles) {
+ this.userRoles = roles;
+ }
+
+ @Override
+ public boolean isSubscriberPermitted(String subscriberName) {
+ for (Role role : userRoles) {
+ if (role.getSubscribeName().equals(subscriberName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean isServicePermitted(String subscriberName, String serviceType) {
+ for (Role role : userRoles) {
+ if (role.getSubscribeName().equals(subscriberName) && role.getServiceType().equals(serviceType)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean isTenantPermitted(String globalCustomerId, String serviceType, String tenantName) {
+ for (Role role : userRoles) {
+ if (role.getSubscribeName().equals(globalCustomerId)
+ && role.getServiceType().equals(serviceType)
+ && (role.getTenant() == null || role.getTenant().equalsIgnoreCase(tenantName))) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ boolean isMsoRequestValid(RequestDetails msoRequest) {
+ try {
+ String globalSubscriberIdRequested = (String) ((Map) ((Map) msoRequest.getAdditionalProperties()
+ .get("requestDetails")).get("subscriberInfo")).get("globalSubscriberId");
+ String serviceType = (String) ((Map) ((Map) msoRequest.getAdditionalProperties().get("requestDetails"))
+ .get("requestParameters")).get("subscriptionServiceType");
+ return isServicePermitted(globalSubscriberIdRequested, serviceType);
+ } catch (Exception e) {
+ //Until we'll get the exact information regarding the tenants and the global customer id, we'll return true on unknown requests to mso
+ return true;
+ }
+ }
+
+}
diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.controller.js b/vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.controller.js
index c4f8f14a9..38096a581 100644
--- a/vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.controller.js
+++ b/vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.controller.js
@@ -22,9 +22,9 @@
'use strict';
appDS2.controller("changeManagementManualTasksController", ["$uibModalInstance", "jobInfo", "MsoService", "COMPONENT",
- "$log", changeManagementManualTasksController]);
+ "$log", "moment", changeManagementManualTasksController]);
- function changeManagementManualTasksController($uibModalInstance, jobInfo, MsoService, COMPONENT, $log) {
+ function changeManagementManualTasksController($uibModalInstance, jobInfo, MsoService, COMPONENT, $log, moment) {
var vm = this;
vm.manualTasks = [];
@@ -75,6 +75,33 @@
return vm.manualTasks.includes(task);
};
+ vm.timeoutHumanized = function() {
+ // moment.duration() can parse ISO 8601 time-intervals,
+ // e.g. "P1Y2M10DT2H30M"
+ // https://en.wikipedia.org/wiki/ISO_8601#Time_intervals
+ let duration = moment.duration(vm.timeout);
+
+ return isDurationValid()
+ ? durationAsHoursAndMinutes() + ' hours (' + vm.timeout + ')'
+ : vm.timeout;
+
+
+ function isDurationValid() {
+ return duration.isValid() && duration.toISOString() !== 'P0D';
+ }
+
+ function durationAsHoursAndMinutes() {
+ return ''
+ + Math.floor(duration.asHours())
+ + ':'
+ + withLeadingZero(duration.minutes());
+ }
+
+ function withLeadingZero(x) {
+ return ("00" + Math.round(x)).slice(-2);
+ }
+ };
+
vm.__test_only__ = {
loadAvailableTasks: loadAvailableTasks,
};
diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.controller.test.js b/vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.controller.test.js
index 93bc1c2de..deefca7e1 100644
--- a/vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.controller.test.js
+++ b/vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.controller.test.js
@@ -20,6 +20,7 @@
require('./change-management-manual-tasks.controller');
const jestMock = require('jest-mock');
+const moment = require('moment');
describe('changeManagementManualTasksController testing', () => {
let $controller;
@@ -41,6 +42,7 @@ describe('changeManagementManualTasksController testing', () => {
"MsoService": $MsoService,
"$uibModalInstance": $uibModalInstance,
"$log": $log,
+ "moment": moment,
"jobInfo": {
requestState: job.requestStatus.requestState,
details: job.requestStatus.statusMessage,
@@ -141,6 +143,26 @@ describe('changeManagementManualTasksController testing', () => {
});
});
+ test('should humanize timeout if proper ISO-8601', () => {
+ $controller.timeout = 'PT3350S';
+ expect($controller.timeoutHumanized()).toEqual('0:55 hours (PT3350S)');
+ });
+
+ test('should humanize timeout if proper ISO-8601', () => {
+ $controller.timeout = 'P3DT1H1M';
+ expect($controller.timeoutHumanized()).toEqual('73:01 hours (P3DT1H1M)');
+ });
+
+ test('should drive-through timeout if not proper ISO-8601', () => {
+ $controller.timeout = '56 minutes';
+ expect($controller.timeoutHumanized()).toEqual('56 minutes');
+ });
+
+ test('should drive-through timeout if undefined', () => {
+ $controller.timeout = undefined;
+ expect($controller.timeoutHumanized()).toEqual(undefined);
+ });
+
test('should find manual task using isTaskAvailable', () => {
expect($controller.isTaskAvailable('abort')).toBeTruthy();
expect($controller.isTaskAvailable('resume')).toBeTruthy();
diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.html b/vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.html
index 099a6ad7b..031146e91 100644
--- a/vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.html
+++ b/vid-app-common/src/main/webapp/app/vid/scripts/modals/change-management-manual-tasks-controller/change-management-manual-tasks.html
@@ -20,7 +20,7 @@
<div class="modal-body">
<span id="in-progress-modal-description" ng-if="vm.description">{{vm.description}}</span>
- <span id="in-progress-modal-timeout" ng-if="vm.timeout">({{vm.timeout}})</span>
+ <span id="in-progress-modal-timeout" ng-if="vm.timeout" class="text-danger"><strong>(task will time out in {{vm.timeoutHumanized()}})</strong></span>
</div>
<div class="modal-footer">
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/AaiGetVnfResponseTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/AaiGetVnfResponseTest.java
index 5eb47a1ff..9d8734b39 100644
--- a/vid-app-common/src/test/java/org/onap/vid/aai/AaiGetVnfResponseTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/AaiGetVnfResponseTest.java
@@ -20,34 +20,88 @@
package org.onap.vid.aai;
-import java.util.Map;
+import java.io.IOException;
+import java.util.*;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import org.junit.Before;
import org.junit.Test;
+import org.onap.vid.aai.model.VnfResult;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.*;
public class AaiGetVnfResponseTest {
- private AaiGetVnfResponse createTestSubject() {
- return new AaiGetVnfResponse();
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+
+ private static final String VNF_RESULT =
+ "{\n" +
+ " \"id\": \"1\",\n" +
+ " \"nodetype\": \"testNodeType\",\n" +
+ " \"url\": \"test/url\",\n" +
+ " \"serviceProperties\": {},\n" +
+ " \"relatedTo\": []\n" +
+ "}\n";
+
+ private static final String AAI_GET_VNF_RESPONSE_TEST = "{ \n" +
+ " \"results\": \n" +
+ " [\n" +
+ VNF_RESULT +
+ " ]\n" +
+ "}";
+
+
+ private AaiGetVnfResponse aaiGetVnfResponse;
+ private VnfResult expectedVnfResult;
+ private List<VnfResult> expectedList;
+
+ @Before
+ public void setUp() throws IOException {
+ expectedVnfResult = OBJECT_MAPPER.readValue(VNF_RESULT, VnfResult.class);
+ expectedList = Collections.singletonList(expectedVnfResult);
+
}
@Test
- public void testGetAdditionalProperties() throws Exception {
- AaiGetVnfResponse testSubject;
- Map<String, Object> result;
+ public void shouldHaveProperSetters() {
+ aaiGetVnfResponse = new AaiGetVnfResponse();
+ aaiGetVnfResponse.setAdditionalProperty("key","value");
+ aaiGetVnfResponse.setResults(expectedList);
+
+ assertEquals(aaiGetVnfResponse.getAdditionalProperties().size(), 1);
+ assertTrue(aaiGetVnfResponse.getAdditionalProperties().containsKey("key"));
+ assertTrue(aaiGetVnfResponse.getAdditionalProperties().containsValue("value"));
+ assertEquals(aaiGetVnfResponse.getResults().size(), 1);
+ assertEquals(aaiGetVnfResponse.getResults().get(0), expectedVnfResult);
+ }
+
+ @Test
+ public void shouldProperlyConvertJsonToAiiGetVnfResponse() throws IOException {
+ aaiGetVnfResponse = OBJECT_MAPPER.readValue(AAI_GET_VNF_RESPONSE_TEST, AaiGetVnfResponse.class);
+ assertThat(aaiGetVnfResponse.getResults(), is(expectedList));
+ }
+
+ @Test
+ public void shouldReturnProperToString(){
+ aaiGetVnfResponse = new AaiGetVnfResponse();
+ aaiGetVnfResponse.setAdditionalProperty("testKey","testValue");
+ aaiGetVnfResponse.setResults(expectedList);
+ Map<String,Object> expectedMap = new HashMap<>();
+ expectedMap.put("testKey", "testValue");
+
+ String expectedOutput = "AaiGetVnfResponse{" +
+ "results=" + expectedList +
+ ", additionalProperties="+expectedMap+"}";
- // default test
- testSubject = createTestSubject();
- result = testSubject.getAdditionalProperties();
+ assertEquals(aaiGetVnfResponse.toString(), expectedOutput);
}
@Test
- public void testSetAdditionalProperty() throws Exception {
- AaiGetVnfResponse testSubject;
- String name = "";
- Object value = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setAdditionalProperty(name, value);
+ public void shouldAddAdditionalProperty(){
+ aaiGetVnfResponse = new AaiGetVnfResponse();
+ aaiGetVnfResponse.setAdditionalProperty("key", "value");
+ assertTrue(aaiGetVnfResponse.getAdditionalProperties().containsKey("key"));
}
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/OperationalEnvironmentTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/OperationalEnvironmentTest.java
index 7f5e362ba..c331b3252 100644
--- a/vid-app-common/src/test/java/org/onap/vid/aai/OperationalEnvironmentTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/OperationalEnvironmentTest.java
@@ -23,10 +23,14 @@ package org.onap.vid.aai;
import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.Assert;
+import org.onap.vid.aai.model.RelationshipList;
import org.testng.annotations.Test;
import java.io.IOException;
+import java.util.ArrayList;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
import static org.assertj.core.api.Assertions.assertThat;
@@ -48,8 +52,29 @@ public class OperationalEnvironmentTest {
"}";
@Test
+ public void shouldCreateProperOperationalEnvironmentWithConstructor(){
+ RelationshipList relationshipList = new RelationshipList();
+ relationshipList.relationship = new ArrayList<>();
+
+ OperationalEnvironment operationalEnvironment = new OperationalEnvironment("testId",
+ "testEnvName", "testEnvType",
+ "testEnvStatus", "testTenant", "testWorkload",
+ "testResource", relationshipList);
+
+ assertThat(operationalEnvironment.getOperationalEnvironmentId()).isEqualTo("testId");
+ assertThat(operationalEnvironment.getWorkloadContext()).isEqualTo("testWorkload");
+ assertThat(operationalEnvironment.getRelationshipList().getRelationship()).hasSize(0);
+ assertThat(operationalEnvironment.getResourceVersion()).isEqualTo("testResource");
+ assertThat(operationalEnvironment.getTenantContext()).isEqualTo("testTenant");
+ assertThat(operationalEnvironment.getOperationalEnvironmentType()).isEqualTo("testEnvType");
+ assertThat(operationalEnvironment.getOperationalEnvironmentStatus()).isEqualTo("testEnvStatus");
+ assertThat(operationalEnvironment.getOperationalEnvironmentName()).isEqualTo("testEnvName");
+ }
+
+ @Test
public void shouldProperlyConvertJsonToOperationalEnvironment() throws IOException {
- OperationalEnvironment operationalEnvironment = OBJECT_MAPPER.readValue(OPERATIONAL_ENVIRONMENT_TEST, OperationalEnvironment.class);
+ OperationalEnvironment operationalEnvironment =
+ OBJECT_MAPPER.readValue(OPERATIONAL_ENVIRONMENT_TEST, OperationalEnvironment.class);
assertThat(operationalEnvironment.getOperationalEnvironmentId()).isEqualTo("environmentId");
assertThat(operationalEnvironment.getWorkloadContext()).isEqualTo("workloadContext");
@@ -60,4 +85,5 @@ public class OperationalEnvironmentTest {
assertThat(operationalEnvironment.getOperationalEnvironmentStatus()).isEqualTo("environmentStatus");
assertThat(operationalEnvironment.getOperationalEnvironmentName()).isEqualTo("environmentName");
}
+
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/SubscriberAaiResponseTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/SubscriberAaiResponseTest.java
index ef2220c2d..b8dd2cfa7 100644
--- a/vid-app-common/src/test/java/org/onap/vid/aai/SubscriberAaiResponseTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/SubscriberAaiResponseTest.java
@@ -20,23 +20,39 @@
package org.onap.vid.aai;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
+import org.onap.vid.model.Subscriber;
import org.onap.vid.model.SubscriberList;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
public class SubscriberAaiResponseTest {
- private SubscriberAaiResponse createTestSubject() {
- return new SubscriberAaiResponse(new SubscriberList(), "", 0);
- }
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+
+ private static final String SUBSCRIBER_JSON_EXAMPLE = "{\n" +
+ " \"global-customer-id\": \"id\",\n" +
+ " \"subscriber-name\": \"name\",\n" +
+ " \"subscriber-type\": \"type\",\n" +
+ " \"resource-version\": \"version\"\n" +
+ "}";
-
@Test
- public void testGetSubscriberList() throws Exception {
- SubscriberAaiResponse testSubject;
- SubscriberList result;
+ public void shouldGetSubscriberList() throws IOException {
+ Subscriber sampleSubscriber =
+ OBJECT_MAPPER.readValue(SUBSCRIBER_JSON_EXAMPLE, Subscriber.class);
+ List<Subscriber> expectedListOfSubscribers = Arrays.asList(sampleSubscriber);
+ SubscriberList expectedSubscriberList = new SubscriberList(expectedListOfSubscribers);
+ SubscriberAaiResponse subscriberAaiResponse = new SubscriberAaiResponse(expectedSubscriberList, "msg", 200);
+
+ assertEquals(subscriberAaiResponse.getSubscriberList(), expectedSubscriberList);
+ assertEquals(subscriberAaiResponse.getSubscriberList().customer.size(), 1);
+ assertEquals(subscriberAaiResponse.getSubscriberList().customer.get(0), sampleSubscriber);
- // default test
- testSubject = createTestSubject();
- result = testSubject.getSubscriberList();
}
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/SubscriberFilteredResultsTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/SubscriberFilteredResultsTest.java
index 4655292c6..f9668c960 100644
--- a/vid-app-common/src/test/java/org/onap/vid/aai/SubscriberFilteredResultsTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/SubscriberFilteredResultsTest.java
@@ -20,45 +20,89 @@
package org.onap.vid.aai;
+import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.Before;
import org.junit.Test;
+import org.onap.vid.model.Subscriber;
import org.onap.vid.model.SubscriberList;
import org.onap.vid.roles.EcompRole;
import org.onap.vid.roles.Role;
import org.onap.vid.roles.RoleValidator;
+import static org.junit.Assert.assertEquals;
+
public class SubscriberFilteredResultsTest {
- private SubscriberFilteredResults createTestSubject() {
- ArrayList<Role> list = new ArrayList<Role>();
- list.add(new Role(EcompRole.READ, "a", "a", "a"));
- RoleValidator rl=new RoleValidator(list);
- SubscriberList sl = new SubscriberList();
- sl.customer = new ArrayList<org.onap.vid.model.Subscriber>();
- sl.customer.add(new org.onap.vid.model.Subscriber());
- return new SubscriberFilteredResults(rl, sl, "OK", 200);
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+ private SubscriberFilteredResults subscriberFilteredResults;
+ private RoleValidator roleValidator;
+ private SubscriberList subscriberList;
+ private SubscriberListWithFilterData subscriberListWithFilterData;
+
+ private static final String SUBSCRIBER_JSON_EXAMPLE = "{\n" +
+ " \"global-customer-id\": \"id\",\n" +
+ " \"subscriber-name\": \"name\",\n" +
+ " \"subscriber-type\": \"type\",\n" +
+ " \"resource-version\": \"version\"\n" +
+ "}";
+
+ @Before
+ public void setUp() throws IOException {
+ createTestSubject();
}
@Test
- public void testGetSubscriberList() throws Exception {
- SubscriberFilteredResults testSubject;
- SubscriberListWithFilterData result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getSubscriberList();
+ public void testGetSubscriberList(){
+ assertEquals(subscriberFilteredResults.getSubscriberList(), subscriberListWithFilterData);
}
@Test
public void testSetSubscriberList() throws Exception {
- SubscriberFilteredResults testSubject;
- SubscriberListWithFilterData subscriberList = null;
+ subscriberList.customer = new ArrayList<>();
+ subscriberList.customer.add(new Subscriber());
+ SubscriberListWithFilterData expectedList = createSubscriberList(subscriberList,roleValidator);
+ subscriberFilteredResults.setSubscriberList(expectedList);
+
+ assertEquals(subscriberFilteredResults.getSubscriberList(), expectedList);
+ }
+
+ private void createTestSubject() throws IOException {
+ prepareRoleValidator();
+ prepareSubscriberList();
+ prepareSubscriberListWithFilterData();
+ createSubscriberFilteredResults();
+ }
+
+ private void createSubscriberFilteredResults() {
+ subscriberFilteredResults =
+ new SubscriberFilteredResults(roleValidator, subscriberList, "OK", 200);
+ subscriberFilteredResults.setSubscriberList(subscriberListWithFilterData);
+ }
+
+ private void prepareSubscriberListWithFilterData() {
+ subscriberListWithFilterData = createSubscriberList(subscriberList, roleValidator);
+ }
+
+ private void prepareRoleValidator() {
+ ArrayList<Role> list = new ArrayList<>();
+ list.add(new Role(EcompRole.READ, "a", "a", "a"));
+ roleValidator = RoleValidator.by(list);
+ }
+
+ private void prepareSubscriberList() throws IOException {
+ Subscriber sampleSubscriber =
+ OBJECT_MAPPER.readValue(SUBSCRIBER_JSON_EXAMPLE, Subscriber.class);
+ List<Subscriber> expectedListOfSubscribers = Collections.singletonList(sampleSubscriber);
+ subscriberList = new SubscriberList(expectedListOfSubscribers);
+ }
- // default test
- testSubject = createTestSubject();
- //testSubject.setSubscriberList(subscriberList);
- testSubject.getSubscriberList();
+ private SubscriberListWithFilterData createSubscriberList(SubscriberList subscriberList,
+ RoleValidator roleValidator){
+ return new SubscriberListWithFilterData(subscriberList,roleValidator);
}
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/ServicePropertiesTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/model/ServicePropertiesTest.java
index 4c0875320..3eccba9b6 100644
--- a/vid-app-common/src/test/java/org/onap/vid/aai/ServicePropertiesTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/model/ServicePropertiesTest.java
@@ -18,12 +18,11 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.vid.aai;
+package org.onap.vid.aai.model;
import java.io.IOException;
import com.fasterxml.jackson.databind.ObjectMapper;
-import org.onap.vid.aai.model.ServiceProperties;
import org.testng.annotations.Test;
import static org.assertj.core.api.Assertions.assertThat;
@@ -82,10 +81,9 @@ public class ServicePropertiesTest {
}
@Test
- public void shouldProperlyAddAdditionalProperty() throws IOException {
+ public void shouldAddAdditionalProperty() throws IOException {
ServiceProperties serviceProperties = OBJECT_MAPPER.readValue(SERVICE_PROPERTIES_JSON, ServiceProperties.class);
-
serviceProperties.setAdditionalProperty("additional", "property");
assertThat(serviceProperties.getAdditionalProperties())
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/VnfResultTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/model/VnfResultTest.java
index 7ee3b6152..075d29f28 100644
--- a/vid-app-common/src/test/java/org/onap/vid/aai/VnfResultTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/model/VnfResultTest.java
@@ -18,14 +18,16 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.vid.aai;
+package org.onap.vid.aai.model;
import com.fasterxml.jackson.databind.ObjectMapper;
-import org.onap.vid.aai.model.VnfResult;
+import org.junit.Assert;
import org.testng.annotations.Test;
import java.io.IOException;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanEquals;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
import static org.assertj.core.api.Assertions.assertThat;
@@ -68,7 +70,6 @@ public class VnfResultTest {
"\t}]\n" +
"}";
-
@Test
public void shouldProperlyConvertJsonToVnfResult() throws IOException {
VnfResult vnfResult = OBJECT_MAPPER.readValue(VNF_RESULT_JSON, VnfResult.class);
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 3ed59ed38..e64b2ac55 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* VID
* ================================================================================
- * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * 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.
@@ -20,80 +20,276 @@
package org.onap.vid.aai.util;
-import org.junit.Test;
+
+import org.mockito.Mock;
+import org.mockito.Mockito;
+
+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;
+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.UnsupportedEncodingException;
+import java.net.URI;
+import java.util.Optional;
+import java.util.UUID;
+
+import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanConstructor;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+import static javax.ws.rs.core.Response.Status.*;
+import static junit.framework.TestCase.assertSame;
+import static junit.framework.TestCase.fail;
+import static org.junit.Assert.assertThat;
+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;
+
public class AAIRestInterfaceTest {
- /*
- TO BE IMPLEMENTED
-
+ 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 Invocation invocation;
+ @Mock
+ private ServletRequestHelper servletRequestHelper;
+ @Mock
+ private HttpsAuthClient httpsAuthClient;
+ @Mock
+ private HttpServletRequest httpServletRequest;
+ @Mock
+ private Response response;
+ @Mock
+ private SystemPropertyHelper systemPropertyHelper;
+
+ private AAIRestInterface testSubject;
+
+ @BeforeMethod
+ public void setUp() throws Exception {
+ 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(builder.build(Mockito.anyString())).thenReturn(invocation);
+ when(builder.build(Mockito.anyString(), any(Entity.class))).thenReturn(invocation);
+ when(invocation.invoke()).thenReturn(response);
+ when(servletRequestHelper.extractOrGenerateRequestId()).thenReturn(UUID.randomUUID().toString());
+ }
+
private AAIRestInterface createTestSubject() {
- return new AAIRestInterface("");
+ return new AAIRestInterface(Optional.of(client), httpsAuthClient, servletRequestHelper, systemPropertyHelper);
}
@Test
- public void testEncodeURL() throws Exception {
- AAIRestInterface testSubject;
- String nodeKey = "";
- String result;
+ public void shouldEncodeURL() throws Exception {
+ String nodeKey = "some unusual uri";
+ String nodeKey2 = "some/usual/uri";
+ Assert.assertEquals(testSubject.encodeURL(nodeKey), "some%20unusual%20uri");
+ Assert.assertEquals(testSubject.encodeURL(nodeKey2), "some%2Fusual%2Furi");
+ }
- // default test
- testSubject = createTestSubject();
- result = testSubject.encodeURL(nodeKey);
+ @Test
+ public void shouldSetRestSrvrBaseURL() {
+ String baseUrl = "anything";
+ testSubject.setRestSrvrBaseURL(baseUrl);
+ Assert.assertEquals(testSubject.getRestSrvrBaseURL(), baseUrl);
}
@Test
- public void testSetRestSrvrBaseURL() throws Exception {
- AAIRestInterface testSubject;
- String baseURL = "";
+ public void shouldExecuteRestJsonPutMethodWithResponse200() {
+ // given
+ String payload = "{\"id\": 1}";
+ Entity<String> entity = Entity.entity(payload, MediaType.APPLICATION_JSON);
- // test 1
- testSubject = createTestSubject();
- baseURL = null;
- testSubject.SetRestSrvrBaseURL(baseURL);
+ // when
+ when(response.getStatusInfo()).thenReturn(OK);
+ Response finalResponse = testSubject.RestPut("", PATH, payload, false, true).getResponse();
- // test 2
- testSubject = createTestSubject();
- baseURL = "";
- testSubject.SetRestSrvrBaseURL(baseURL);
+ // then
+ verify(builder).build(HttpMethod.PUT.name(), entity);
+ Assert.assertEquals(response, finalResponse);
+ }
+
+ @Test(expectedExceptions = {ExceptionWithRequestInfo.class})
+ public void shouldFailWhenRestJsonPutMethodExecuted() {
+ // given
+ String payload = "{\"id\": 1}";
+
+ // when
+ when(builder.build(eq(HttpMethod.PUT.name()), any(Entity.class))).thenThrow(new GenericUncheckedException("msg"));
+ testSubject.RestPut("", PATH, payload, false, true);
+
+ //then
}
@Test
- public void testGetRestSrvrBaseURL() throws Exception {
- AAIRestInterface testSubject;
- String result;
+ public void shouldExecuteRestJsonPutMethodWithResponse400() {
+ // given
+ String payload = "{\"id\": 1}";
+ Entity<String> entity = Entity.entity(payload, MediaType.APPLICATION_JSON);
- // default test
- testSubject = createTestSubject();
- result = testSubject.getRestSrvrBaseURL();
+ // when
+ when(response.getStatusInfo()).thenReturn(BAD_REQUEST);
+ when(response.getStatus()).thenReturn(BAD_REQUEST.getStatusCode());
+ Response finalResponse = testSubject.RestPut("", PATH, payload, false, true).getResponse();
+
+ // then
+ verify(builder).build(HttpMethod.PUT.name(), entity);
+ Assert.assertEquals(response, finalResponse);
}
+ @Test
+ public void shouldExecuteRestPostMethodWithResponse200() {
+ // given
+ String payload = "{\"id\": 1}";
+ Entity<String> entity = Entity.entity(payload, MediaType.APPLICATION_JSON);
+
+ // when
+ 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);
+ }
@Test
- public void testRestPut() throws Exception {
- AAIRestInterface testSubject;
- String fromAppId = "";
- String transId = "";
- String path = "";
- String payload = "";
- boolean xml = false;
-
- // default test
- testSubject = createTestSubject();
- testSubject.RestPut(fromAppId, transId, path, payload, xml);
+ public void shouldExecuteRestPostMethodWithResponse400() {
+ // given
+ String payload = "{\"id\": 1}";
+ Entity<String> entity = Entity.entity(payload, MediaType.APPLICATION_JSON);
+
+ // when
+ when(builder.post(Mockito.any(Entity.class))).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);
}
@Test
- public void testRestPost() throws Exception {
- AAIRestInterface testSubject;
- String fromAppId = "";
- String transId = "";
- String path = "";
- String payload = "";
- boolean xml = false;
-
- // default test
- testSubject = createTestSubject();
- testSubject.RestPost(fromAppId, transId, path, payload, xml);
- }*/
+ public void shouldFailWhenRestPostMethodExecuted() {
+ // given
+ String payload = "{\"id\": 1}";
+ Entity<String> entity = Entity.entity(payload, MediaType.APPLICATION_JSON);
+
+ // when
+ when(builder.post(Mockito.any(Entity.class))).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
+ when(response.getStatusInfo()).thenReturn(OK);
+ Response finalResponse = testSubject.RestGet("", "", Unchecked.toURI(PATH), false).getResponse();
+
+ // then
+ Assert.assertEquals(response, finalResponse);
+ }
+
+ @Test
+ public void shouldExecuteRestGetMethodWithResponse400() {
+ // given
+ // when
+ when(response.getStatusInfo()).thenReturn(BAD_REQUEST);
+ when(response.getStatus()).thenReturn(BAD_REQUEST.getStatusCode());
+ Response finalResponse = testSubject.RestGet("", "", Unchecked.toURI(PATH), false).getResponse();
+
+ // then
+ Assert.assertEquals(response, finalResponse);
+ }
+
+ @Test
+ public void shouldFailWhenRestGetMethodExecuted() {
+ // given
+ // when
+ when(builder.build(HttpMethod.GET.name())).thenThrow(new RuntimeException());
+ Response finalResponse = testSubject.RestGet("", "", Unchecked.toURI(PATH), false).getResponse();
+
+ // then
+ Assert.assertNull(finalResponse);
+ }
+
+ private void mockSystemProperties() throws UnsupportedEncodingException, InvalidPropertyException {
+ when(systemPropertyHelper.getEncodedCredentials()).thenReturn("someCredentials");
+ when(systemPropertyHelper.getFullServicePath(Mockito.anyString())).thenReturn("http://localhost/path");
+ when(systemPropertyHelper.getFullServicePath(Mockito.any(URI.class))).thenReturn("http://localhost/path");
+ when(systemPropertyHelper.getServiceBasePath(Mockito.anyString())).thenReturn("http://localhost/path");
+ }
+
}
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
deleted file mode 100644
index 3393aa7c1..000000000
--- a/vid-app-common/src/test/java/org/onap/vid/aai/util/SingleAAIRestInterfaceTest.java
+++ /dev/null
@@ -1,315 +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 org.mockito.Mock;
-import org.mockito.Mockito;
-
-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;
-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.UnsupportedEncodingException;
-import java.net.URI;
-import java.util.Optional;
-import java.util.UUID;
-
-import static javax.ws.rs.core.Response.Status.*;
-import static junit.framework.TestCase.fail;
-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;
-
-
-public class SingleAAIRestInterfaceTest {
-
- 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 Invocation invocation;
- @Mock
- private ServletRequestHelper servletRequestHelper;
- @Mock
- private HttpsAuthClient httpsAuthClient;
- @Mock
- private HttpServletRequest httpServletRequest;
- @Mock
- private Response response;
- @Mock
- private SystemPropertyHelper systemPropertyHelper;
-
- private AAIRestInterface testSubject;
-
- @BeforeMethod
- public void setUp() throws Exception {
- 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(builder.build(Mockito.anyString())).thenReturn(invocation);
- when(builder.build(Mockito.anyString(), any(Entity.class))).thenReturn(invocation);
- when(invocation.invoke()).thenReturn(response);
- when(servletRequestHelper.extractOrGenerateRequestId()).thenReturn(UUID.randomUUID().toString());
- }
-
- private AAIRestInterface createTestSubject() {
- return new AAIRestInterface(Optional.of(client), httpsAuthClient, servletRequestHelper, systemPropertyHelper);
- }
-
- @Test
- public void testEncodeURL() throws Exception {
- String nodeKey = "some unusual uri";
- Assert.assertEquals(testSubject.encodeURL(nodeKey), "some%20unusual%20uri");
- }
-
- @Test
- public void testSetRestSrvrBaseURLWithNullValue() {
- testSubject.SetRestSrvrBaseURL(null);
- }
-
- @Test
- public void testSetRestSrvrBaseURL() {
- String baseUrl = "anything";
- testSubject.SetRestSrvrBaseURL(baseUrl);
- Assert.assertEquals(testSubject.getRestSrvrBaseURL(), baseUrl);
- }
-
- @Test
- public void testRestJsonPutWithResponse200() {
- // given
- String methodName = "RestPut";
- String payload = "{\"id\": 1}";
- Entity<String> entity = Entity.entity(payload, MediaType.APPLICATION_JSON);
-
- // when
- when(response.getStatusInfo()).thenReturn(OK);
- Response finalResponse = testSubject.RestPut("", PATH, payload, false, true).getResponse();
-
- // then
- verify(builder).build(HttpMethod.PUT.name(), entity);
- Assert.assertEquals(response, finalResponse);
- }
-
- @Test(expectedExceptions = {ExceptionWithRequestInfo.class})
- public void testFailedRestJsonPut() {
- // given
- String methodName = "RestPut";
- String payload = "{\"id\": 1}";
- Entity<String> entity = Entity.entity(payload, MediaType.APPLICATION_JSON);
-
- // when
- when(builder.build(eq(HttpMethod.PUT.name()), any(Entity.class))).thenThrow(new GenericUncheckedException("msg"));
- Response finalResponse = testSubject.RestPut("", PATH, payload, false, true).getResponse();
-
- // then
- fail("expected unreachable: exception to be thrown");
- }
-
- @Test
- public void testRestJsonPutWithResponse400() {
- // given
- String methodName = "RestPut";
- String payload = "{\"id\": 1}";
- Entity<String> entity = Entity.entity(payload, MediaType.APPLICATION_JSON);
-
- // when
- when(response.getStatusInfo()).thenReturn(BAD_REQUEST);
- when(response.getStatus()).thenReturn(BAD_REQUEST.getStatusCode());
- Response finalResponse = testSubject.RestPut("", PATH, payload, false, true).getResponse();
-
- // then
- verify(builder).build(HttpMethod.PUT.name(), entity);
- Assert.assertEquals(response, finalResponse);
- }
-
- @Test
- public void testRestPostWithResponse200() {
- // given
- String methodName = "RestPost";
- String payload = "{\"id\": 1}";
- Entity<String> entity = Entity.entity(payload, MediaType.APPLICATION_JSON);
-
- // when
- 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);
- }
-
- @Test
- public void testRestPostWithResponse400() {
- // given
- String methodName = "RestPost";
- String payload = "{\"id\": 1}";
- Entity<String> entity = Entity.entity(payload, MediaType.APPLICATION_JSON);
-
- // when
- when(builder.post(Mockito.any(Entity.class))).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);
- }
-
- @Test
- public void testFailedRestPost() {
- // given
- String methodName = "RestPost";
- String payload = "{\"id\": 1}";
- Entity<String> entity = Entity.entity(payload, MediaType.APPLICATION_JSON);
-
- // when
- when(builder.post(Mockito.any(Entity.class))).thenThrow(new RuntimeException());
- Response finalResponse = testSubject.RestPost("", PATH, payload, false);
-
- // then
- verify(builder).post(entity);
- Assert.assertEquals(finalResponse, null);
- }
-
- @Test
- public void testRestDeleteWithResponse400() {
- // given
- String methodName = "Delete";
-
- // 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 testRestDeleteWithResponse404() {
- // given
- String methodName = "Delete";
-
- // 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 testFailedRestDelete() {
- // given
- String methodName = "Delete";
-
- // when
- when(builder.delete()).thenThrow(new RuntimeException());
- boolean finalResponse = testSubject.Delete("", "", PATH);
-
- // then
- verify(builder).delete();
- Assert.assertFalse(finalResponse);
- }
-
- @Test
- public void testRestJsonGetWithResponse200() {
- // given
- String methodName = "RestGet";
-
- // when
- when(response.getStatusInfo()).thenReturn(OK);
- Response finalResponse = testSubject.RestGet("", "", Unchecked.toURI(PATH), false).getResponse();
-
- // then
- Assert.assertEquals(response, finalResponse);
- }
-
- @Test
- public void testRestJsonGetWithResponse400() {
- // given
- String methodName = "RestGet";
-
- // when
- when(response.getStatusInfo()).thenReturn(BAD_REQUEST);
- when(response.getStatus()).thenReturn(BAD_REQUEST.getStatusCode());
- Response finalResponse = testSubject.RestGet("", "", Unchecked.toURI(PATH), false).getResponse();
-
- // then
- Assert.assertEquals(response, finalResponse);
- }
-
- @Test
- public void testFailedRestGet() {
- // given
- String methodName = "RestGet";
-
- // when
- when(builder.build(HttpMethod.GET.name())).thenThrow(new RuntimeException());
- Response finalResponse = testSubject.RestGet("", "", Unchecked.toURI(PATH), false).getResponse();
-
- // then
- Assert.assertEquals(finalResponse, null);
- }
-
- private void mockSystemProperties() throws UnsupportedEncodingException, InvalidPropertyException {
- when(systemPropertyHelper.getEncodedCredentials()).thenReturn("someCredentials");
- when(systemPropertyHelper.getFullServicePath(Mockito.anyString())).thenReturn("http://localhost/path");
- when(systemPropertyHelper.getFullServicePath(Mockito.any(URI.class))).thenReturn("http://localhost/path");
- when(systemPropertyHelper.getServiceBasePath(Mockito.anyString())).thenReturn("http://localhost/path");
- }
-
-}
diff --git a/vid-app-common/src/test/java/org/onap/vid/bl/AaiServiceTest.java b/vid-app-common/src/test/java/org/onap/vid/bl/AaiServiceTest.java
index 9f1dc84c0..1b50681fc 100644
--- a/vid-app-common/src/test/java/org/onap/vid/bl/AaiServiceTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/bl/AaiServiceTest.java
@@ -20,15 +20,29 @@
package org.onap.vid.bl;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.arrayWithSize;
+import static org.hamcrest.Matchers.equalTo;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.onap.vid.aai.AaiClientInterface;
import org.onap.vid.aai.AaiResponse;
-import org.onap.vid.aai.model.*;
+import org.onap.vid.aai.model.AaiGetPnfResponse;
import org.onap.vid.aai.model.AaiGetPnfs.Pnf;
import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse;
+import org.onap.vid.aai.model.LogicalLinkResponse;
+import org.onap.vid.aai.model.Relationship;
+import org.onap.vid.aai.model.RelationshipData;
+import org.onap.vid.aai.model.RelationshipList;
+import org.onap.vid.aai.model.ServiceRelationships;
import org.onap.vid.roles.Role;
import org.onap.vid.roles.RoleValidator;
import org.onap.vid.services.AaiServiceImpl;
@@ -36,16 +50,6 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.arrayWithSize;
-import static org.hamcrest.Matchers.equalTo;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-
public class AaiServiceTest {
@InjectMocks
@@ -164,7 +168,7 @@ public class AaiServiceTest {
AaiResponse<GetTenantsResponse[]> aaiResponse = new AaiResponse<>(getTenantsResponses, null, 200);
Mockito.doReturn(aaiResponse).when(aaiClientInterface).getTenants(serviceGlobalCustomerId, serviceServiceType);
Role role = new Role(null, userGlobalCustomerId, userServiceType, userTenantName);
- RoleValidator roleValidator = new RoleValidator(Collections.singletonList(role));
+ RoleValidator roleValidator = RoleValidator.by(Collections.singletonList(role));
AaiResponse<GetTenantsResponse[]> actualTenants = aaiService.getTenants(serviceGlobalCustomerId, serviceServiceType, roleValidator);
assertThat(actualTenants.getT(), arrayWithSize(1));
diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java
index 6d4508dbf..0abf6cd57 100644
--- a/vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java
@@ -3,13 +3,14 @@
* VID
* ================================================================================
* Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications 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.
@@ -20,33 +21,41 @@
package org.onap.vid.controller;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
-import org.mockito.InjectMocks;
+import java.util.Map;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
import org.onap.vid.aai.AaiResponseTranslator;
+import org.onap.vid.aai.util.AAIRestInterface;
+import org.onap.vid.roles.RoleProvider;
import org.onap.vid.services.AaiService;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import java.util.Map;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.Is.is;
+import org.onap.vid.utils.SystemPropertiesWrapper;
+@RunWith(MockitoJUnitRunner.class)
public class AaiControllerTest {
- @InjectMocks
- AaiController aaiController = new AaiController();
-
@Mock
- AaiService aaiService;
+ private AaiService aaiService;
+ @Mock
+ private AAIRestInterface aaiRestInterface;
+ @Mock
+ private RoleProvider roleProvider;
+ @Mock
+ private SystemPropertiesWrapper systemPropertiesWrapper;
- @BeforeMethod
- public void initMocks(){
- MockitoAnnotations.initMocks(this);
+ private AaiController aaiController;
+
+ @Before
+ public void setUp(){
+ aaiController = new AaiController(aaiService, aaiRestInterface, roleProvider, systemPropertiesWrapper);
}
@Test
@@ -70,7 +79,4 @@ public class AaiControllerTest {
"c", toBeReturnedForC
)));
}
-
-
-
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/ControllersUtilsTest.java b/vid-app-common/src/test/java/org/onap/vid/controller/ControllersUtilsTest.java
index f084b3dec..80836d155 100644
--- a/vid-app-common/src/test/java/org/onap/vid/controller/ControllersUtilsTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/controller/ControllersUtilsTest.java
@@ -21,16 +21,25 @@ package org.onap.vid.controller;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
+import static org.mockito.BDDMockito.then;
+import static org.mockito.Mockito.mock;
import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+import org.apache.commons.lang.exception.ExceptionUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.portalsdk.core.domain.User;
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.portalsdk.core.util.SystemProperties;
+import org.onap.vid.model.ExceptionResponse;
import org.onap.vid.utils.SystemPropertiesWrapper;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
@RunWith(MockitoJUnitRunner.class)
public class ControllersUtilsTest {
@@ -110,4 +119,26 @@ public class ControllersUtilsTest {
// THEN
assertThat(loginId).isEmpty();
}
+
+ @Test
+ public void shouldCreateResponseEntity_fromGivenException() {
+ // GIVEN
+ EELFLoggerDelegate eelfLoggerDelegate = mock(EELFLoggerDelegate.class);
+ Response response = mock(Response.class);
+ given(response.getStatus()).willReturn(HttpStatus.OK.value());
+ WebApplicationException webApplicationException = new WebApplicationException("ErrorMessage", response);
+
+ // WHEN
+ ResponseEntity responseEntity = ControllersUtils
+ .handleWebApplicationException(webApplicationException, eelfLoggerDelegate);
+
+ // THEN
+ assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
+ assertThat(responseEntity.getBody())
+ .isInstanceOfSatisfying(ExceptionResponse.class,
+ er -> assertThat(er.getMessage()).isEqualTo("ErrorMessage (Request id: null)"));
+ then(eelfLoggerDelegate).should()
+ .error(EELFLoggerDelegate.errorLogger, "{}: {}", "handleWebApplicationException",
+ ExceptionUtils.getMessage(webApplicationException), webApplicationException);
+ }
} \ No newline at end of file
diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/ServicePermissionsTest.java b/vid-app-common/src/test/java/org/onap/vid/controller/ServicePermissionsTest.java
index abdf31572..36af92c0c 100644
--- a/vid-app-common/src/test/java/org/onap/vid/controller/ServicePermissionsTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/controller/ServicePermissionsTest.java
@@ -20,14 +20,6 @@
package org.onap.vid.controller;
-import org.jetbrains.annotations.NotNull;
-import org.onap.vid.aai.model.Permissions;
-import org.onap.vid.roles.RoleProvider;
-import org.onap.vid.roles.RoleValidator;
-import org.springframework.mock.web.MockHttpServletRequest;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
-
import static java.lang.Boolean.FALSE;
import static java.lang.Boolean.TRUE;
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
@@ -37,6 +29,14 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import org.jetbrains.annotations.NotNull;
+import org.onap.vid.aai.model.Permissions;
+import org.onap.vid.roles.RoleProvider;
+import org.onap.vid.roles.RoleValidator;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
public class ServicePermissionsTest {
@DataProvider
diff --git a/vid-app-common/src/test/java/org/onap/vid/roles/AlwaysValidRoleValidatorTest.java b/vid-app-common/src/test/java/org/onap/vid/roles/AlwaysValidRoleValidatorTest.java
new file mode 100644
index 000000000..363c6ff76
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/roles/AlwaysValidRoleValidatorTest.java
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. 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.roles;
+
+import static org.testng.Assert.assertTrue;
+
+import org.testng.annotations.Test;
+
+public class AlwaysValidRoleValidatorTest {
+
+ @Test
+ public void testIsSubscriberPermitted() {
+ assertTrue(new AlwaysValidRoleValidator().isSubscriberPermitted("any"));
+ }
+
+ @Test
+ public void testIsServicePermitted() {
+ assertTrue(new AlwaysValidRoleValidator().isServicePermitted("any", "any"));
+ }
+
+ @Test
+ public void testIsTenantPermitted() {
+ assertTrue(new AlwaysValidRoleValidator().isTenantPermitted("any", "any", "any"));
+ }
+} \ No newline at end of file
diff --git a/vid-app-common/src/test/java/org/onap/vid/roles/RoleValidatorTest.java b/vid-app-common/src/test/java/org/onap/vid/roles/RoleValidatorByRolesTest.java
index 69ec3458e..9362ec9d7 100644
--- a/vid-app-common/src/test/java/org/onap/vid/roles/RoleValidatorTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/roles/RoleValidatorByRolesTest.java
@@ -21,18 +21,17 @@
package org.onap.vid.roles;
+import static org.assertj.core.api.Assertions.assertThat;
+
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import java.util.List;
+import java.util.Map;
import org.onap.vid.mso.rest.RequestDetails;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import java.util.List;
-import java.util.Map;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class RoleValidatorTest {
+public class RoleValidatorByRolesTest {
private static final String SAMPLE_SUBSCRIBER = "sampleSubscriber";
private static final String NOT_MATCHING_SUBSCRIBER = "notMatchingSubscriber";
@@ -47,12 +46,11 @@ public class RoleValidatorTest {
private Map<String, Object> requestParameters = ImmutableMap.of("subscriptionServiceType", SAMPLE_SERVICE_TYPE);
private Map<String, Object> requestDetailsProperties = ImmutableMap.of("subscriberInfo", subscriberInfo, "requestParameters", requestParameters);
private RequestDetails requestDetails;
- private RoleValidator roleValidator;
+ private RoleValidatorByRoles roleValidator;
@BeforeMethod
public void setUp() {
- roleValidator = new RoleValidator(roles);
- roleValidator.enableRoles();
+ roleValidator = new RoleValidatorByRoles(roles);
requestDetails = new RequestDetails();
}
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 59cee89b2..e9f94ca0e 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
@@ -44,6 +44,7 @@ import org.onap.vid.aai.model.AaiGetServicesRequestModel.GetServicesAAIRespone;
import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse;
import org.onap.vid.aai.model.VnfResult;
import org.onap.vid.roles.RoleValidator;
+import org.onap.vid.roles.RoleValidatorByRoles;
public class AaiServiceImplTest {
@@ -137,7 +138,7 @@ public class AaiServiceImplTest {
when(response.getT()).thenReturn(new GetTenantsResponse[]{ permittedTenant, unpermittedTenant });
when(aaiClient.getTenants(globalCustomerId, serviceType)).thenReturn(response);
- RoleValidator roleValidator = mock(RoleValidator.class);
+ RoleValidator roleValidator = mock(RoleValidatorByRoles.class);
when(roleValidator.isTenantPermitted(globalCustomerId, serviceType, "permitted_tenant")).thenReturn(true);
when(roleValidator.isTenantPermitted(globalCustomerId, serviceType, "unpermitted_tenant")).thenReturn(false);
@@ -202,7 +203,7 @@ public class AaiServiceImplTest {
@SuppressWarnings("unchecked")
public void getServicesShouldMarkAllServicesAsPermitted() {
// given
- RoleValidator roleValidator = modelGenerator.nextObject(RoleValidator.class);
+ RoleValidator roleValidator = modelGenerator.nextObject(RoleValidatorByRoles.class);
GetServicesAAIRespone inputPayload = modelGenerator.nextObject(GetServicesAAIRespone.class);
assertThat(inputPayload.service.stream().allMatch(service -> service.isPermitted)).isFalse();
diff --git a/vid-app-common/src/test/resources/WEB-INF/conf/system.properties b/vid-app-common/src/test/resources/WEB-INF/conf/system.properties
index fce0d1aeb..a0f0dbe19 100644
--- a/vid-app-common/src/test/resources/WEB-INF/conf/system.properties
+++ b/vid-app-common/src/test/resources/WEB-INF/conf/system.properties
@@ -71,6 +71,8 @@ application_name = Virtual Infrastructure Deployment
element_map_file_path = app/fusionapp/files/
element_map_icon_path = app/fusionapp/icons/
+role_management_activated = false
+
#aai related properties
#dev server
#ist servers
diff --git a/vid-ext-services-simulator/src/main/resources/preset_registration/changeManagement/mso_get_manual_task.json b/vid-ext-services-simulator/src/main/resources/preset_registration/changeManagement/mso_get_manual_task.json
index 7fab6c6ff..9c4481e69 100644
--- a/vid-ext-services-simulator/src/main/resources/preset_registration/changeManagement/mso_get_manual_task.json
+++ b/vid-ext-services-simulator/src/main/resources/preset_registration/changeManagement/mso_get_manual_task.json
@@ -21,7 +21,7 @@
"errorCode": "404",
"errorMessage": "Failed in A&AI 404",
"description": "Manually restart VM id vm8776da8-4c8cbe860422, then verify logs still contain task id daf4dd84-b77a-42da-a051-3239b7a9392c",
- "timeout": "PT3000S",
+ "timeout": "P3DT1H1M",
"validResponses": [
"rollback",
"abort",