diff options
author | 2018-07-29 16:13:45 +0300 | |
---|---|---|
committer | 2018-07-29 16:20:34 +0300 | |
commit | 5b593496b8f1b8e8be8d7d2dbcc223332e65a49b (patch) | |
tree | 2f9dfc45191e723da69cf74be7829784e9741b94 /catalog-be/src/test/java/org/openecomp/sdc/be/servlets/GroupTypesEndpointTest.java | |
parent | 9200382f2ce7b4bb729aa287d0878004b2d2b4f9 (diff) |
re base code
Change-Id: I12a5ca14a6d8a87e9316b9ff362eb131105f98a5
Issue-ID: SDC-1566
Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'catalog-be/src/test/java/org/openecomp/sdc/be/servlets/GroupTypesEndpointTest.java')
-rw-r--r-- | catalog-be/src/test/java/org/openecomp/sdc/be/servlets/GroupTypesEndpointTest.java | 104 |
1 files changed, 77 insertions, 27 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/GroupTypesEndpointTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/GroupTypesEndpointTest.java index 2d30616ebb..1af04ac207 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/GroupTypesEndpointTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/GroupTypesEndpointTest.java @@ -11,20 +11,25 @@ import org.glassfish.jersey.server.ResourceConfig; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.openecomp.sdc.be.DummyConfigurationManager; import org.openecomp.sdc.be.components.impl.GroupTypeBusinessLogic; -import org.openecomp.sdc.be.components.impl.ResponseFormatManager; import org.openecomp.sdc.be.components.utils.GroupTypeBuilder; import org.openecomp.sdc.be.components.validation.UserValidations; import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.dao.jsongraph.TitanDao; +import org.openecomp.sdc.be.dao.titan.TitanGenericDao; +import org.openecomp.sdc.be.datatypes.elements.GroupTypeDataDefinition; +import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.GroupTypeDefinition; import org.openecomp.sdc.be.model.User; -import org.openecomp.sdc.be.model.operations.impl.GroupTypeOperation; +import org.openecomp.sdc.be.model.operations.api.DerivedFromOperation; +import org.openecomp.sdc.be.model.operations.impl.*; +import org.openecomp.sdc.be.resources.data.GroupTypeData; +import org.openecomp.sdc.common.api.ConfigurationSource; import org.openecomp.sdc.common.api.Constants; +import org.openecomp.sdc.common.impl.ExternalConfiguration; +import org.openecomp.sdc.common.impl.FSConfigurationSource; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import javax.ws.rs.client.Invocation; @@ -38,27 +43,34 @@ import java.util.stream.Stream; import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.anyBoolean; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; public class GroupTypesEndpointTest extends JerseySpringBaseTest { private static final String USER_ID = "a001"; - private static final String INVALID_USER_ID = "a002"; private static final GroupTypeDefinition EMPTY_GROUP_TYPE = new GroupTypeDefinition(); private static final String COMPONENT_TYPE = "VF"; private static final HashSet<String> EXCLUDED_TYPES = Sets.newHashSet("Root", "Heat"); private static ComponentsUtils componentsUtils; - private static GroupTypeOperation groupTypeOperation; + private static TitanGenericDao titanGenericDao; + private static CapabilityTypeOperation capabilityTypeOperation; + private static DerivedFromOperation derivedFromOperation; private static TitanDao titanDao; + private static PropertyOperation propertyOperation; + private static CapabilityOperation capabilityOperation; private static UserValidations userValidations; + private static OperationUtils operationUtils; private static User user; - @Configuration + static ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"); + static ConfigurationManager configurationManager = new ConfigurationManager(configurationSource); + + @org.springframework.context.annotation.Configuration @Import(BaseTestConfig.class) static class GroupTypesTestConfig { @@ -69,27 +81,31 @@ public class GroupTypesEndpointTest extends JerseySpringBaseTest { @Bean GroupTypeBusinessLogic groupTypeBusinessLogic() { - return new GroupTypeBusinessLogic(groupTypeOperation, titanDao, userValidations); + return new GroupTypeBusinessLogic(groupTypeOperation(), titanDao, userValidations, componentsUtils); + } + + @Bean + GroupTypeOperation groupTypeOperation() { + return new GroupTypeOperation(titanGenericDao, propertyOperation, capabilityTypeOperation, capabilityOperation, derivedFromOperation, operationUtils); } } @BeforeClass public static void initClass() { componentsUtils = mock(ComponentsUtils.class); - groupTypeOperation = mock(GroupTypeOperation.class); + propertyOperation = mock(PropertyOperation.class); + capabilityTypeOperation = mock(CapabilityTypeOperation.class); titanDao = mock(TitanDao.class); + titanGenericDao = mock(TitanGenericDao.class); userValidations = mock(UserValidations.class); + operationUtils = mock(OperationUtils.class); user = mock(User.class); } @Before public void init() { - new DummyConfigurationManager(); - when(ConfigurationManager.getConfigurationManager().getConfiguration().getExcludedGroupTypesMapping()).thenReturn(buildExcludeGroupTypesMap()); - ResponseFormatManager responseFormatManager = ResponseFormatManager.getInstance(); - when(userValidations.validateUserExists(eq(USER_ID), anyString(), anyBoolean())).thenReturn(Either.left(user)); - // TODO: handle for invalid user test -// when(userValidations.validateUserExists(eq(INVALID_USER_ID), anyString(), anyBoolean())).thenReturn(Either.right(???))); + when(userValidations.validateUserExists(eq(USER_ID), anyString(), anyBoolean())).thenReturn(user); + when(titanGenericDao.getByCriteriaWithPredicate(eq(NodeTypeEnum.GroupType), any(), eq(GroupTypeData.class))).thenReturn(Either.left(buildGroupTypeDataList())); } @Override @@ -105,26 +121,31 @@ public class GroupTypesEndpointTest extends JerseySpringBaseTest { } @Test + public void verifyExclusionMapIsCaseInsensitive() { + Map<String, Set<String>> excludedGroupTypesMapping = configurationManager.getConfiguration().getExcludedGroupTypesMapping(); + assertThat(excludedGroupTypesMapping.get(COMPONENT_TYPE)).hasSameElementsAs(excludedGroupTypesMapping.get(COMPONENT_TYPE.toLowerCase())); + } + + @Test public void getGroupTypes_validUser_Success() { List<GroupTypeDefinition> testConfigGroupTypes = buildGroupTypesList(); - when(groupTypeOperation.getAllGroupTypes(EXCLUDED_TYPES)).thenReturn(buildGroupTypesList()); - List<GroupTypeDefinition> fetchedGroupTypes = buildGetGroupTypesCall(USER_ID).get(new GenericType<List<GroupTypeDefinition>>(){}); + List<GroupTypeDefinition> fetchedGroupTypes = buildGetGroupTypesCall(USER_ID, COMPONENT_TYPE).get(new GenericType<List<GroupTypeDefinition>>(){}); verifyGroupTypesList(testConfigGroupTypes, fetchedGroupTypes); } @Test public void getGroupTypes_whenNoInteranlComponentType_passEmptyAsExcludedTypes() { List<GroupTypeDefinition> testConfigGroupTypes = buildGroupTypesList(); - when(groupTypeOperation.getAllGroupTypes(null)).thenReturn(buildGroupTypesList()); List<GroupTypeDefinition> fetchedGroupTypes = buildGetGroupTypesCallNoInternalComponent(USER_ID).get(new GenericType<List<GroupTypeDefinition>>(){}); verifyGroupTypesList(testConfigGroupTypes, fetchedGroupTypes); } private void verifyGroupTypesList(List<GroupTypeDefinition> groupTypes, List<GroupTypeDefinition> fetchedGroupTypes) { + String[] expectedReturnFields = {"version", "type", "uniqueId", "name", "icon"}; assertThat(fetchedGroupTypes) - .usingElementComparatorOnFields("version", "type", "uniqueId") + .usingElementComparatorOnFields(expectedReturnFields) .isEqualTo(groupTypes); - verifyOnlySpecificFieldsInResponse(fetchedGroupTypes, "version", "type", "uniqueId"); + verifyOnlySpecificFieldsInResponse(fetchedGroupTypes, expectedReturnFields); } private void verifyOnlySpecificFieldsInResponse(List<GroupTypeDefinition> fetchedGroupTypes, String ... fields) { @@ -133,9 +154,9 @@ public class GroupTypesEndpointTest extends JerseySpringBaseTest { .containsOnly(EMPTY_GROUP_TYPE); } - private Invocation.Builder buildGetGroupTypesCall(String userId) { + private Invocation.Builder buildGetGroupTypesCall(String userId, String componentType) { return target("/v1/catalog/groupTypes") - .queryParam("internalComponentType", COMPONENT_TYPE) + .queryParam("internalComponentType", componentType) .request(MediaType.APPLICATION_JSON) .header(Constants.USER_ID_HEADER, userId); } @@ -157,14 +178,43 @@ public class GroupTypesEndpointTest extends JerseySpringBaseTest { private List<GroupTypeDefinition> buildGroupTypesList() { GroupTypeDefinition type1 = GroupTypeBuilder.create() .setDerivedFrom("root") - .setType("VFModule") + .setType("org.openecomp.groups.VfModule") .setUniqueId("id1") .setVersion("1.0") + .setName("vf module") + .setIcon("vf module icon") + .build(); + GroupTypeDefinition type2 = GroupTypeBuilder.create() + .setDerivedFrom("root") + .setType("org.openecomp.groups.NetworkCollection") + .setUniqueId("id2") + .setVersion("1.0") + .setName("network collection") + .setIcon("network collection icon") .build(); - GroupTypeDefinition type2 = GroupTypeBuilder.create().setDerivedFrom("root").setType("Heat").setUniqueId("id2").build(); return asList(type1, type2); } + private List<GroupTypeData> buildGroupTypeDataList() { + GroupTypeDataDefinition d1 = new GroupTypeDataDefinition(); + d1.setType("org.openecomp.groups.VfModule"); + d1.setDerivedFrom("root"); + d1.setUniqueId("id1"); + d1.setVersion("1.0"); + d1.setName("vf module"); + d1.setIcon("vf module icon"); + GroupTypeData gt1 = new GroupTypeData(d1); + GroupTypeDataDefinition d2 = new GroupTypeDataDefinition(); + d2.setType("org.openecomp.groups.NetworkCollection"); + d2.setDerivedFrom("root"); + d2.setUniqueId("id2"); + d2.setVersion("1.0"); + d2.setName("network collection"); + d2.setIcon("network collection icon"); + GroupTypeData gt2 = new GroupTypeData(d2); + return asList(gt1, gt2); + } + private GroupTypeDefinition[] listOfEmptyGroupTypes(int size) { return Stream.generate(GroupTypeDefinition::new).limit(size).toArray(GroupTypeDefinition[]::new); } |