aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java3
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/controller/AsyncInstantiationController.java9
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/model/ServiceInstanceSearchResult.java47
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/roles/AlwaysValidRoleValidator.java2
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/roles/PermissionProperties.kt17
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/roles/RoleValidator.java2
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorByOwningEntity.java2
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorBySubscriberAndServiceType.java19
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java35
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/controller/ServicePermissionsTest.java3
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/model/ServiceInstanceSearchResultTest.java188
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/roles/AlwaysValidRoleValidatorTest.java2
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/roles/RoleValidatorByOwningEntityTest.java2
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/roles/RoleValidatorBySubscriberAndServiceTypeTest.java26
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java2
15 files changed, 113 insertions, 246 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java b/vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java
index 6431282e7..dcbd9b9e4 100644
--- a/vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java
+++ b/vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java
@@ -33,6 +33,7 @@ import org.onap.vid.model.aaiTree.Network;
import org.onap.vid.model.aaiTree.RelatedVnf;
import org.onap.vid.model.aaiTree.VpnBinding;
import org.onap.vid.properties.Features;
+import org.onap.vid.roles.PermissionProperties;
import org.onap.vid.roles.RoleProvider;
import org.onap.vid.services.AaiService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -94,7 +95,7 @@ public class AaiController2 extends VidRestrictedBaseController {
final boolean isEditPermitted = roleProvider
.getUserRolesValidator(request)
- .isServicePermitted(subscriberId, serviceType);
+ .isServicePermitted(new PermissionProperties(subscriberId, serviceType));
return new Permissions(isEditPermitted);
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/AsyncInstantiationController.java b/vid-app-common/src/main/java/org/onap/vid/controller/AsyncInstantiationController.java
index 6c8a37262..4b03ea4d9 100644
--- a/vid-app-common/src/main/java/org/onap/vid/controller/AsyncInstantiationController.java
+++ b/vid-app-common/src/main/java/org/onap/vid/controller/AsyncInstantiationController.java
@@ -33,7 +33,9 @@ import org.onap.vid.model.ServiceInfo;
import org.onap.vid.model.serviceInstantiation.ServiceInstantiation;
import org.onap.vid.mso.MsoResponseWrapper2;
import org.onap.vid.properties.Features;
+import org.onap.vid.roles.PermissionProperties;
import org.onap.vid.roles.RoleProvider;
+import org.onap.vid.roles.RoleValidator;
import org.onap.vid.services.AsyncInstantiationBusinessLogic;
import org.onap.vid.services.AuditService;
import org.onap.vid.utils.SystemPropertiesWrapper;
@@ -165,8 +167,11 @@ public class AsyncInstantiationController extends VidRestrictedBaseController {
}
private void throwExceptionIfAccessDenied(ServiceInstantiation request, HttpServletRequest httpServletRequest, String userId) {
- if (featureManager.isActive(Features.FLAG_1906_INSTANTIATION_API_USER_VALIDATION) && !roleProvider.getUserRolesValidator(httpServletRequest).isServicePermitted(request.getGlobalSubscriberId(), request.getSubscriptionServiceType())) {
- throw new AccessDeniedException(String.format("User %s is not allowed to make this request", userId));
+ if (featureManager.isActive(Features.FLAG_1906_INSTANTIATION_API_USER_VALIDATION)) {
+ RoleValidator roleValidator = roleProvider.getUserRolesValidator(httpServletRequest);
+ if (!roleValidator.isServicePermitted(new PermissionProperties(request.getGlobalSubscriberId(), request.getSubscriptionServiceType()))) {
+ throw new AccessDeniedException(String.format("User %s is not allowed to make this request", userId));
+ }
}
}
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/model/ServiceInstanceSearchResult.java b/vid-app-common/src/main/java/org/onap/vid/model/ServiceInstanceSearchResult.java
index 259405c4e..01cc11d95 100644
--- a/vid-app-common/src/main/java/org/onap/vid/model/ServiceInstanceSearchResult.java
+++ b/vid-app-common/src/main/java/org/onap/vid/model/ServiceInstanceSearchResult.java
@@ -20,11 +20,17 @@
package org.onap.vid.model;
-public class ServiceInstanceSearchResult {
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.commons.lang3.StringUtils;
+import org.onap.vid.roles.WithPermissionProperties;
+
+public class ServiceInstanceSearchResult implements WithPermissionProperties {
+
+ private final String SUBSCRIBER_ID_FRONTEND_ALIAS = "globalCustomerId";
private String serviceInstanceId;
- private String globalCustomerId;
+ private String subscriberId;
private String serviceType;
@@ -39,13 +45,13 @@ public class ServiceInstanceSearchResult {
private boolean isPermitted;
public ServiceInstanceSearchResult(){
-
}
- public ServiceInstanceSearchResult(String serviceInstanceId, String globalCustomerId, String serviceType,
+
+ public ServiceInstanceSearchResult(String serviceInstanceId, String subscriberId, String serviceType,
String serviceInstanceName, String subscriberName, String aaiModelInvariantId,
String aaiModelVersionId, boolean isPermitted) {
this.serviceInstanceId = serviceInstanceId;
- this.globalCustomerId = globalCustomerId;
+ this.subscriberId = subscriberId;
this.serviceType = serviceType;
this.serviceInstanceName = serviceInstanceName;
this.subscriberName = subscriberName;
@@ -62,14 +68,17 @@ public class ServiceInstanceSearchResult {
this.serviceInstanceId = serviceInstanceId;
}
- public String getGlobalCustomerId() {
- return globalCustomerId;
+ @Override
+ @JsonProperty(SUBSCRIBER_ID_FRONTEND_ALIAS)
+ public String getSubscriberId() {
+ return subscriberId;
}
- public void setGlobalCustomerId(String globalCustomerId) {
- this.globalCustomerId = globalCustomerId;
+ public void setSubscriberId(String subscriberId) {
+ this.subscriberId = subscriberId;
}
+ @Override
public String getServiceType() {
return serviceType;
}
@@ -119,21 +128,21 @@ public class ServiceInstanceSearchResult {
}
@Override
- public boolean equals(Object other){
- if (other instanceof ServiceInstanceSearchResult) {
- ServiceInstanceSearchResult serviceInstanceSearchResultOther = (ServiceInstanceSearchResult) other;
- if (this.getServiceInstanceId().equals(serviceInstanceSearchResultOther.getServiceInstanceId())) {
- return true;
- }
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
}
- return false;
+ ServiceInstanceSearchResult that = (ServiceInstanceSearchResult) o;
+
+ return StringUtils.equals(serviceInstanceId, that.serviceInstanceId);
}
@Override
public int hashCode() {
- int result = 17;
- result = 31 * result + serviceInstanceId.hashCode();
- return result;
+ return serviceInstanceId != null ? serviceInstanceId.hashCode() : 0;
}
}
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
index 4e5340fc2..e12f5403f 100644
--- 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
@@ -32,7 +32,7 @@ public class AlwaysValidRoleValidator implements RoleValidator {
}
@Override
- public boolean isServicePermitted(String subscriberName, String serviceType) {
+ public boolean isServicePermitted(WithPermissionProperties permissionProperties) {
return true;
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/roles/PermissionProperties.kt b/vid-app-common/src/main/java/org/onap/vid/roles/PermissionProperties.kt
new file mode 100644
index 000000000..f62b98aef
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/roles/PermissionProperties.kt
@@ -0,0 +1,17 @@
+package org.onap.vid.roles
+
+import org.onap.vid.aai.ServiceSubscription
+
+
+interface WithPermissionProperties {
+ val subscriberId: String?
+ val serviceType: String?
+}
+
+data class PermissionProperties(
+ override val subscriberId: String,
+ override val serviceType: String
+) : WithPermissionProperties {
+ constructor(serviceSubscription: ServiceSubscription, subscriberId: String) : this(subscriberId, serviceSubscription.serviceType)
+}
+
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 f0ee26b0b..4ad168c4f 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
@@ -40,7 +40,7 @@ public interface RoleValidator {
boolean isSubscriberPermitted(String subscriberName);
- boolean isServicePermitted(String subscriberName, String serviceType);
+ boolean isServicePermitted(WithPermissionProperties serviceInstanceSearchResult);
boolean isTenantPermitted(String globalCustomerId, String serviceType, String tenantName);
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorByOwningEntity.java b/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorByOwningEntity.java
index e615c1302..726567cc6 100644
--- a/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorByOwningEntity.java
+++ b/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorByOwningEntity.java
@@ -33,7 +33,7 @@ public class RoleValidatorByOwningEntity implements RoleValidator{
}
@Override
- public boolean isServicePermitted(String subscriberName, String serviceType) {
+ public boolean isServicePermitted(WithPermissionProperties permissionProperties) {
return false;
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorBySubscriberAndServiceType.java b/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorBySubscriberAndServiceType.java
index 244610c89..95d8a1627 100644
--- a/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorBySubscriberAndServiceType.java
+++ b/vid-app-common/src/main/java/org/onap/vid/roles/RoleValidatorBySubscriberAndServiceType.java
@@ -21,8 +21,6 @@
package org.onap.vid.roles;
import java.util.List;
-import java.util.Map;
-import org.onap.vid.mso.rest.RequestDetails;
public class RoleValidatorBySubscriberAndServiceType implements RoleValidator {
@@ -43,9 +41,9 @@ public class RoleValidatorBySubscriberAndServiceType implements RoleValidator {
}
@Override
- public boolean isServicePermitted(String subscriberName, String serviceType) {
+ public boolean isServicePermitted(WithPermissionProperties permissionProperties) {
for (Role role : userRoles) {
- if (role.getSubscribeName().equals(subscriberName) && role.getServiceType().equals(serviceType)) {
+ if (role.getSubscribeName().equals(permissionProperties.getSubscriberId()) && role.getServiceType().equals(permissionProperties.getServiceType())) {
return true;
}
}
@@ -64,17 +62,4 @@ public class RoleValidatorBySubscriberAndServiceType implements RoleValidator {
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/java/org/onap/vid/services/AaiServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java
index b3ac16884..66c0e6c04 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
@@ -85,6 +85,7 @@ import org.onap.vid.model.aaiTree.NodeType;
import org.onap.vid.model.aaiTree.RelatedVnf;
import org.onap.vid.model.aaiTree.VpnBinding;
import org.onap.vid.model.aaiTree.VpnBindingKt;
+import org.onap.vid.roles.PermissionProperties;
import org.onap.vid.roles.RoleValidator;
import org.onap.vid.utils.Intersection;
import org.onap.vid.utils.Logging;
@@ -217,11 +218,11 @@ public class AaiServiceImpl implements AaiService {
} else if (key.equals(SERVICE_TYPE)) {
serviceInstanceSearchResult.setServiceType(relationshipData.getRelationshipValue());
} else if (key.equals(CUSTOMER_ID)) {
- serviceInstanceSearchResult.setGlobalCustomerId(relationshipData.getRelationshipValue());
+ serviceInstanceSearchResult.setSubscriberId(relationshipData.getRelationshipValue());
}
}
- boolean isPermitted = roleValidator.isServicePermitted(serviceInstanceSearchResult.getSubscriberName(), serviceInstanceSearchResult.getServiceType());
+ boolean isPermitted = roleValidator.isServicePermitted(serviceInstanceSearchResult);
serviceInstanceSearchResult.setIsPermitted(isPermitted);
}
}
@@ -265,10 +266,9 @@ public class AaiServiceImpl implements AaiService {
@Override
public AaiResponse getSubscriberData(String subscriberId, RoleValidator roleValidator, boolean omitServiceInstances) {
AaiResponse<Services> subscriberResponse = aaiClient.getSubscriberData(subscriberId, omitServiceInstances);
- String subscriberGlobalId = subscriberResponse.getT().globalCustomerId;
for (ServiceSubscription serviceSubscription : subscriberResponse.getT().serviceSubscriptions.serviceSubscription) {
- String serviceType = serviceSubscription.serviceType;
- serviceSubscription.isPermitted = roleValidator.isServicePermitted(subscriberGlobalId, serviceType);
+ serviceSubscription.isPermitted = roleValidator.isServicePermitted(
+ new PermissionProperties(serviceSubscription, subscriberResponse.getT().globalCustomerId));
}
return subscriberResponse;
@@ -298,38 +298,43 @@ public class AaiServiceImpl implements AaiService {
private List<ServiceInstanceSearchResult> getServicesBySubscriber(String subscriberId, String instanceIdentifier, RoleValidator roleValidator) {
AaiResponse<Services> subscriberResponse = aaiClient.getSubscriberData(subscriberId, false);
- String subscriberGlobalId = subscriberResponse.getT().globalCustomerId;
String subscriberName = subscriberResponse.getT().subscriberName;
ServiceSubscriptions serviceSubscriptions = subscriberResponse.getT().serviceSubscriptions;
- return getSearchResultsForSubscriptions(serviceSubscriptions, subscriberId, instanceIdentifier, roleValidator, subscriberGlobalId, subscriberName);
-
+ return getSearchResultsForSubscriptions(serviceSubscriptions, subscriberId, instanceIdentifier, roleValidator, subscriberName);
}
- private ArrayList<ServiceInstanceSearchResult> getSearchResultsForSubscriptions(ServiceSubscriptions serviceSubscriptions, String subscriberId, String instanceIdentifier, RoleValidator roleValidator, String subscriberGlobalId, String subscriberName) {
+ private ArrayList<ServiceInstanceSearchResult> getSearchResultsForSubscriptions(
+ ServiceSubscriptions serviceSubscriptions, String subscriberId, String instanceIdentifier,
+ RoleValidator roleValidator, String subscriberName) {
ArrayList<ServiceInstanceSearchResult> results = new ArrayList<>();
if (serviceSubscriptions != null) {
for (ServiceSubscription serviceSubscription : serviceSubscriptions.serviceSubscription) {
- String serviceType = serviceSubscription.serviceType;
- serviceSubscription.isPermitted = roleValidator.isServicePermitted(subscriberGlobalId, serviceType);
- ArrayList<ServiceInstanceSearchResult> resultsForSubscription = getSearchResultsForSingleSubscription(serviceSubscription, subscriberId, instanceIdentifier, subscriberName, serviceType);
- results.addAll(resultsForSubscription);
+ serviceSubscription.isPermitted = roleValidator.isServicePermitted(new PermissionProperties(serviceSubscription, subscriberId));
+ results.addAll(getSearchResultsForSingleSubscription(
+ serviceSubscription, subscriberId, instanceIdentifier, subscriberName,
+ serviceSubscription.serviceType, roleValidator)
+ );
}
}
return results;
}
- private ArrayList<ServiceInstanceSearchResult> getSearchResultsForSingleSubscription(ServiceSubscription serviceSubscription, String subscriberId, String instanceIdentifier, String subscriberName, String serviceType) {
+ private ArrayList<ServiceInstanceSearchResult> getSearchResultsForSingleSubscription(
+ ServiceSubscription serviceSubscription, String subscriberId, String instanceIdentifier, String subscriberName,
+ String serviceType, RoleValidator roleValidator) {
ArrayList<ServiceInstanceSearchResult> results = new ArrayList<>();
if (serviceSubscription.serviceInstances != null) {
for (ServiceInstance serviceInstance : serviceSubscription.serviceInstances.serviceInstance) {
ServiceInstanceSearchResult serviceInstanceSearchResult =
new ServiceInstanceSearchResult(serviceInstance.serviceInstanceId, subscriberId, serviceType, serviceInstance.serviceInstanceName,
- subscriberName, serviceInstance.modelInvariantId, serviceInstance.modelVersionId, serviceSubscription.isPermitted);
+ subscriberName, serviceInstance.modelInvariantId, serviceInstance.modelVersionId, false);
+
+ serviceInstanceSearchResult.setIsPermitted(roleValidator.isServicePermitted(serviceInstanceSearchResult));
if ((instanceIdentifier == null) || (serviceInstanceMatchesIdentifier(instanceIdentifier, serviceInstance))){
results.add(serviceInstanceSearchResult);
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 ac3da50ab..9f436b703 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
@@ -31,6 +31,7 @@ import static org.mockito.Mockito.when;
import org.jetbrains.annotations.NotNull;
import org.onap.vid.aai.model.Permissions;
+import org.onap.vid.roles.PermissionProperties;
import org.onap.vid.roles.RoleProvider;
import org.onap.vid.roles.RoleValidator;
import org.springframework.mock.web.MockHttpServletRequest;
@@ -53,7 +54,7 @@ public class ServicePermissionsTest {
RoleProvider roleProvider = mock(RoleProvider.class);
RoleValidator roleValidator = mock(RoleValidator.class);
when(roleProvider.getUserRolesValidator(any())).thenReturn(roleValidator);
- when(roleValidator.isServicePermitted(subscriberId, serviceType)).thenReturn(expected);
+ when(roleValidator.isServicePermitted(new PermissionProperties(subscriberId, serviceType))).thenReturn(expected);
AaiController2 aaiController2 = new AaiController2(null, roleProvider, null, null);
diff --git a/vid-app-common/src/test/java/org/onap/vid/model/ServiceInstanceSearchResultTest.java b/vid-app-common/src/test/java/org/onap/vid/model/ServiceInstanceSearchResultTest.java
index 5168a5c63..b777375ef 100644
--- a/vid-app-common/src/test/java/org/onap/vid/model/ServiceInstanceSearchResultTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/model/ServiceInstanceSearchResultTest.java
@@ -20,183 +20,47 @@
package org.onap.vid.model;
-import org.junit.Test;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanConstructor;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanEqualsFor;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanHashCodeFor;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+import static net.javacrumbs.jsonunit.JsonMatchers.jsonNodeAbsent;
+import static net.javacrumbs.jsonunit.JsonMatchers.jsonPartEquals;
+import static org.apache.commons.lang3.ArrayUtils.toArray;
+import static org.hamcrest.CoreMatchers.allOf;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import org.testng.annotations.Test;
public class ServiceInstanceSearchResultTest {
- private ServiceInstanceSearchResult createTestSubject() {
- return new ServiceInstanceSearchResult();
- }
-
- @Test
- public void testGetServiceInstanceId() throws Exception {
- ServiceInstanceSearchResult testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getServiceInstanceId();
- }
-
- @Test
- public void testSetServiceInstanceId() throws Exception {
- ServiceInstanceSearchResult testSubject;
- String serviceInstanceId = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setServiceInstanceId(serviceInstanceId);
- }
-
- @Test
- public void testGetGlobalCustomerId() throws Exception {
- ServiceInstanceSearchResult testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getGlobalCustomerId();
- }
-
- @Test
- public void testSetGlobalCustomerId() throws Exception {
- ServiceInstanceSearchResult testSubject;
- String globalCustomerId = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setGlobalCustomerId(globalCustomerId);
- }
-
- @Test
- public void testGetServiceType() throws Exception {
- ServiceInstanceSearchResult testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getServiceType();
- }
-
- @Test
- public void testSetServiceType() throws Exception {
- ServiceInstanceSearchResult testSubject;
- String serviceType = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setServiceType(serviceType);
- }
-
- @Test
- public void testGetServiceInstanceName() throws Exception {
- ServiceInstanceSearchResult testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getServiceInstanceName();
- }
-
- @Test
- public void testSetServiceInstanceName() throws Exception {
- ServiceInstanceSearchResult testSubject;
- String serviceInstanceName = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setServiceInstanceName(serviceInstanceName);
- }
-
- @Test
- public void testGetSubscriberName() throws Exception {
- ServiceInstanceSearchResult testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getSubscriberName();
- }
-
- @Test
- public void testSetSubscriberName() throws Exception {
- ServiceInstanceSearchResult testSubject;
- String subscriberName = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setSubscriberName(subscriberName);
- }
-
@Test
- public void testGetAaiModelInvariantId() throws Exception {
- ServiceInstanceSearchResult testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getAaiModelInvariantId();
- }
-
- @Test
- public void testSetAaiModelInvariantId() throws Exception {
- ServiceInstanceSearchResult testSubject;
- String aaiModelInvariantId = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setAaiModelInvariantId(aaiModelInvariantId);
- }
-
- @Test
- public void testGetAaiModelVersionId() throws Exception {
- ServiceInstanceSearchResult testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getAaiModelVersionId();
+ public void shouldHaveValidGettersAndSetters() {
+ assertThat(ServiceInstanceSearchResult.class, hasValidGettersAndSetters());
}
@Test
- public void testSetAaiModelVersionId() throws Exception {
- ServiceInstanceSearchResult testSubject;
- String aaiModelVersionId = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setAaiModelVersionId(aaiModelVersionId);
- }
-
- @Test
- public void testGetIsPermitted() throws Exception {
- ServiceInstanceSearchResult testSubject;
- boolean result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getIsPermitted();
+ public void shouldHaveValidConstructor() {
+ assertThat(ServiceInstanceSearchResult.class, hasValidBeanConstructor());
}
@Test
- public void testSetIsPermitted() throws Exception {
- ServiceInstanceSearchResult testSubject;
- boolean isPermitted = false;
+ public void shouldHaveValidEqualsAndHashCode() {
+ String[] propertiesToEqualBy = toArray("serviceInstanceId");
- // default test
- testSubject = createTestSubject();
- testSubject.setIsPermitted(isPermitted);
+ assertThat(ServiceInstanceSearchResult.class, allOf(
+ hasValidBeanHashCodeFor(propertiesToEqualBy),
+ hasValidBeanEqualsFor(propertiesToEqualBy))
+ );
}
@Test
- public void testEquals() throws Exception {
- ServiceInstanceSearchResult testSubject;
- Object other = null;
- boolean result;
+ public void subscriberId_shouldBeSerializedAsGlobalCustomerId() {
+ ServiceInstanceSearchResult underTest = new ServiceInstanceSearchResult();
+ underTest.setSubscriberId("example");
- // default test
- testSubject = createTestSubject();
- result = testSubject.equals(other);
+ assertThat(underTest, jsonPartEquals("globalCustomerId", "example"));
+ assertThat(underTest, jsonNodeAbsent("subscriberId"));
}
}
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
index 363c6ff76..4b511fe52 100644
--- 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
@@ -33,7 +33,7 @@ public class AlwaysValidRoleValidatorTest {
@Test
public void testIsServicePermitted() {
- assertTrue(new AlwaysValidRoleValidator().isServicePermitted("any", "any"));
+ assertTrue(new AlwaysValidRoleValidator().isServicePermitted(new PermissionProperties("any", "any")));
}
@Test
diff --git a/vid-app-common/src/test/java/org/onap/vid/roles/RoleValidatorByOwningEntityTest.java b/vid-app-common/src/test/java/org/onap/vid/roles/RoleValidatorByOwningEntityTest.java
index 713099148..8d7a1b97a 100644
--- a/vid-app-common/src/test/java/org/onap/vid/roles/RoleValidatorByOwningEntityTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/roles/RoleValidatorByOwningEntityTest.java
@@ -53,7 +53,7 @@ public class RoleValidatorByOwningEntityTest {
@Test
public void testIsServicePermitted() {
- assertFalse(roleValidatorByOwningEntity.isServicePermitted(SUBSCRIBER_NAME, SERVICE_TYPE));
+ assertFalse(roleValidatorByOwningEntity.isServicePermitted(new PermissionProperties(SUBSCRIBER_NAME, SERVICE_TYPE)));
}
@Test
diff --git a/vid-app-common/src/test/java/org/onap/vid/roles/RoleValidatorBySubscriberAndServiceTypeTest.java b/vid-app-common/src/test/java/org/onap/vid/roles/RoleValidatorBySubscriberAndServiceTypeTest.java
index 77e5088e5..39928ef9d 100644
--- a/vid-app-common/src/test/java/org/onap/vid/roles/RoleValidatorBySubscriberAndServiceTypeTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/roles/RoleValidatorBySubscriberAndServiceTypeTest.java
@@ -66,19 +66,19 @@ public class RoleValidatorBySubscriberAndServiceTypeTest {
@Test
public void shouldPermitServiceWhenNamesMatches() {
- assertThat(roleValidatorBySubscriberAndServiceType.isServicePermitted(SAMPLE_SUBSCRIBER, SAMPLE_SERVICE_TYPE)).isTrue();
+ assertThat(roleValidatorBySubscriberAndServiceType.isServicePermitted(new PermissionProperties(SAMPLE_SUBSCRIBER, SAMPLE_SERVICE_TYPE))).isTrue();
}
@Test
public void shouldNotPermitServiceWhenSubscriberNameNotMatches() {
assertThat(
- roleValidatorBySubscriberAndServiceType.isServicePermitted(NOT_MATCHING_SUBSCRIBER, SAMPLE_SERVICE_TYPE)).isFalse();
+ roleValidatorBySubscriberAndServiceType.isServicePermitted(new PermissionProperties(NOT_MATCHING_SUBSCRIBER, SAMPLE_SERVICE_TYPE))).isFalse();
}
@Test
public void shouldNotPermitServiceWhenServiceTypeNotMatches() {
- assertThat(roleValidatorBySubscriberAndServiceType.isServicePermitted(SAMPLE_SUBSCRIBER, NOT_MATCHING_SUBSCRIBER)).isFalse();
+ assertThat(roleValidatorBySubscriberAndServiceType.isServicePermitted(new PermissionProperties(SAMPLE_SUBSCRIBER, NOT_MATCHING_SUBSCRIBER))).isFalse();
}
@Test
@@ -94,24 +94,4 @@ public class RoleValidatorBySubscriberAndServiceTypeTest {
.isTenantPermitted(SAMPLE_SUBSCRIBER, SAMPLE_SERVICE_TYPE, NOT_MATCHING_TENANT)).isFalse();
}
- @Test
- public void shouldValidateProperlySORequest() {
- requestDetails.setAdditionalProperty("requestDetails", requestDetailsProperties);
-
- assertThat(roleValidatorBySubscriberAndServiceType.isMsoRequestValid(requestDetails)).isTrue();
- }
-
- @Test
- public void shouldValidateUnknownSORequest() {
- assertThat(roleValidatorBySubscriberAndServiceType.isMsoRequestValid(new RequestDetails())).isTrue();
- }
-
- @Test
- public void shouldRejectSORequestWhenSubscriberNotMatches() {
- Map<String, Object> subscriberInfo = ImmutableMap.of("globalSubscriberId", "sample");
- Map<String, Object> requestDetailsProperties = ImmutableMap.of("subscriberInfo", subscriberInfo, "requestParameters", requestParameters);
- requestDetails.setAdditionalProperty("requestDetails", requestDetailsProperties);
-
- assertThat(roleValidatorBySubscriberAndServiceType.isMsoRequestValid(requestDetails)).isFalse();
- }
}
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 d3b2a48b1..a37482624 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
@@ -183,7 +183,7 @@ public class AaiServiceImplTest {
AaiResponse<Services> aaiResponseServices = new AaiResponse<>(services, null, HttpStatus.SC_OK);
when(aaiClient.getSubscriberData(SUBSCRIBER_ID, false)).thenReturn(aaiResponseServices);
- when(roleValidator.isServicePermitted(eq(GLOBAL_CUSTOMER_ID), anyString())).thenReturn(Boolean.TRUE);
+ when(roleValidator.isServicePermitted(any())).thenReturn(Boolean.TRUE);
AaiResponse actualResponse = aaiService.getSubscriberData(SUBSCRIBER_ID, roleValidator, false);
List<ServiceSubscription> actualServiceSubscriptions = ((AaiResponse<Services>) actualResponse)