@Override public List<ProfileFilterDto> compute(AppProfileVersionsKey key) { LOG.debug("Fetching result for getFilters"); ApplicationDto appDto = applicationService.findAppByApplicationToken( key.getApplicationToken()); List<ProfileFilterDto> value = profileService.findProfileFiltersByAppIdAndVersionsCombination(appDto.getId(), key.getEndpointProfileSchemaVersion(), key.getServerProfileSchemaVersion()); return value; } });
@Test public void findProfileFilterByAppIdAndVersionTest() { List<ProfileFilterDto> generated = generateFilterDto(null, null, null, 1, true); ProfileFilterDto first = generated.get(0); List<ProfileFilterDto> filters = profileService.findProfileFiltersByAppIdAndVersionsCombination(first.getApplicationId(), first.getEndpointProfileSchemaVersion(), first.getServerProfileSchemaVersion()); Assert.assertNotNull(filters); Assert.assertFalse(filters.isEmpty()); }
@Test public void saveMoreFiltersTest() { List<EndpointProfileSchemaDto> schemas = generateProfSchemaDto(null, null, 1); EndpointProfileSchemaDto schema = schemas.get(0); ApplicationDto app = applicationService.findAppById(schema.getApplicationId()); ServerProfileSchemaDto serverSchema = generateServerProfileSchema(app.getId(), app.getTenantId(), 1); generateFilterDto(schema.getId(), serverSchema.getId(), null, 10, true); List<ProfileFilterDto> filters = profileService.findProfileFiltersByAppIdAndVersionsCombination(schema.getApplicationId(), schema.getVersion(), serverSchema.getVersion()); Assert.assertFalse(filters.isEmpty()); Assert.assertEquals(filters.get(0).getStatus(), UpdateStatus.ACTIVE); Assert.assertEquals(schema.getId(), filters.get(0).getEndpointProfileSchemaId()); Assert.assertEquals(serverSchema.getId(), filters.get(0).getServerProfileSchemaId()); }
@Test public void saveFiltersWithDiferentGroupsTest() { ApplicationDto application = generateApplicationDto(null); EndpointGroupDto groupDto = generateEndpointGroupDto(application.getId()); EndpointGroupDto groupDto2 = generateEndpointGroupDto(application.getId(), "OTHER_GROUP"); EndpointProfileSchemaDto schema = generateProfSchemaDto(application.getTenantId(), application.getId(), 1).get(0); ServerProfileSchemaDto serverSchema = generateServerProfileSchema(application.getId(), application.getTenantId()); ProfileFilterDto filterDto = generateFilterDto(schema.getId(), serverSchema.getId(), groupDto.getId(), 1, false).get(0); Assert.assertNotNull(filterDto); filterDto.setId(null); filterDto.setEndpointGroupId(groupDto.getId()); ProfileFilterDto savedOne = profileService.saveProfileFilter(filterDto); Assert.assertNotNull(savedOne); ChangeProfileFilterNotification activeOne = profileService.activateProfileFilter(savedOne.getId(), null); Assert.assertNotNull(activeOne); filterDto.setId(null); filterDto.setEndpointGroupId(groupDto2.getId()); ProfileFilterDto savedTwo = profileService.saveProfileFilter(filterDto); Assert.assertNotNull(savedTwo); ChangeProfileFilterNotification activeTwo = profileService.activateProfileFilter(savedTwo.getId(), null); Assert.assertNotNull(activeTwo); List<ProfileFilterDto> activeList = profileService.findProfileFiltersByAppIdAndVersionsCombination(application.getId(), schema.getVersion(), serverSchema.getVersion()); Assert.assertFalse(activeList.isEmpty()); Set<String> groupIds = new HashSet<>(); for (ProfileFilterDto dto : activeList) { Assert.assertEquals(dto.getStatus(), UpdateStatus.ACTIVE); groupIds.add(dto.getEndpointGroupId()); } Assert.assertEquals(2, groupIds.size()); }
@Test public void deactivateProfileFilterTest() { List<ProfileFilterDto> filterList = generateFilterDto(null, null, null, 1, true); ProfileFilterDto pf = filterList.get(0); String appId = pf.getApplicationId(); List<ProfileFilterDto> filters = profileService.findProfileFiltersByAppIdAndVersionsCombination(pf.getApplicationId(), pf.getEndpointProfileSchemaVersion(), pf.getServerProfileSchemaVersion()); Assert.assertNotNull(filters); ProfileFilterDto filter = filters.get(0); filter.setId(null); EndpointGroupDto group = generateEndpointGroupDto(appId); filter.setEndpointGroupId(group.getId()); ProfileFilterDto dto = profileService.saveProfileFilter(filter); ChangeProfileFilterNotification change = profileService.activateProfileFilter(dto.getId(), null); Assert.assertNotNull(change); Assert.assertEquals(UpdateStatus.ACTIVE, change.getProfileFilterDto().getStatus()); change = profileService.deactivateProfileFilter(dto.getId(), null); Assert.assertNotNull(change); Assert.assertEquals(UpdateStatus.DEPRECATED, change.getProfileFilterDto().getStatus()); }