diff options
author | 2020-01-28 05:55:11 +0000 | |
---|---|---|
committer | 2020-01-28 05:55:11 +0000 | |
commit | 657353741044c8cda2bbca64e2fc235837428f25 (patch) | |
tree | f479513d31f3d9ff209c4eeaf45531af5b925245 /vid-app-common/src/test | |
parent | ae5156453ebf0c8c81c5aa2f791bb527dbf344ad (diff) | |
parent | e95a7b89aaac965e89d96eba59968a351cb77f40 (diff) |
Merge "Introduce WithPermissionProperties as validation-points for RoleValidator"
Diffstat (limited to 'vid-app-common/src/test')
6 files changed, 34 insertions, 189 deletions
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) |