@Override public EndpointProfileSchemaDto editProfileSchema(EndpointProfileSchemaDto profileSchema) throws ControlServiceException { return profileService.saveProfileSchema(profileSchema); }
@Override public List<ProfileFilterRecordDto> getProfileFilterRecordsByEndpointGroupId( String endpointGroupId, boolean includeDeprecated) throws ControlServiceException { return new ArrayList<>(profileService.findAllProfileFilterRecordsByEndpointGroupId( endpointGroupId, includeDeprecated)); }
@Override public ProfileFilterDto getProfileFilter(String profileFilterId) throws ControlServiceException { return profileService.findProfileFilterById(profileFilterId); }
@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()); }
@Test public void saveProfileSchemaTest() { String schemaId = generateProfSchemaDto(null, null, 1).get(0).getId(); EndpointProfileSchemaDto schemaDto = profileService.findProfileSchemaById(schemaId); Assert.assertNotNull(schemaDto); int version = schemaDto.getVersion(); schemaDto.setId(null); EndpointProfileSchemaDto saved = profileService.saveProfileSchema(schemaDto); Assert.assertNotNull(saved); Assert.assertNotEquals(version, saved.getVersion()); Assert.assertNotEquals(schemaId, saved.getId()); }
@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()); }
schemaDto = generateProfSchemaDto(null, null, 1).get(0); } else { schemaDto = profileService.findProfileSchemaById(schemaId); dto.setServerProfileSchemaVersion(serverProfileSchemaDto.getVersion()); dto.setApplicationId(schemaDto.getApplicationId()); ProfileFilterDto saved = profileService.saveProfileFilter(dto); Assert.assertNotNull(saved); if (activate) { ChangeProfileFilterNotification notification = profileService.activateProfileFilter(saved.getId(), schemaDto.getCreatedUsername()); saved = notification.getProfileFilterDto();
@Test(expected = IncorrectParameterException.class) public void invalidProfileFilterActivationTest() { String id = "-1"; profileService.activateProfileFilter(id, null); }
@Test public void findAllProfileFilterRecordsByEndpointGroupIdTest() { ApplicationDto app = generateApplicationDto(null); String appId = app.getId(); EndpointGroupDto groupDto = generateEndpointGroupDto(appId); EndpointProfileSchemaDto schema = generateProfSchemaDto(app.getTenantId(), appId, 1).get(0); ServerProfileSchemaDto serverProfileSchema = generateServerProfileSchema(app.getId(), app.getTenantId()); ProfileFilterDto filter = generateFilterDto(schema.getId(), serverProfileSchema.getId(), groupDto.getId(), 3, true).get(2); Assert.assertEquals(UpdateStatus.ACTIVE, filter.getStatus()); profileService.deactivateProfileFilter(filter.getId(), null); List<ProfileFilterRecordDto> records = (List<ProfileFilterRecordDto>) profileService.findAllProfileFilterRecordsByEndpointGroupId(groupDto.getId(), true); Assert.assertNotNull(records); Assert.assertEquals(1, records.size()); Assert.assertEquals(UpdateStatus.DEPRECATED, records.get(0).getActiveStructureDto().getStatus()); }
@Test(expected = UpdateStatusConflictException.class) public void updateDefaultProfileFilter() { ApplicationDto app = generateApplicationDto(null); EndpointProfileSchemaDto schema = generateProfSchemaDto(app.getTenantId(), app.getId(), 1).get(0); ServerProfileSchemaDto serverSchema = generateServerProfileSchema(app.getId(), app.getTenantId()); EndpointGroupDto defaultGroup = endpointService.findDefaultGroup(app.getId()); ProfileFilterDto filter = new ProfileFilterDto(); filter.setApplicationId(app.getId()); filter.setBody("true"); filter.setEndpointProfileSchemaId(schema.getId()); filter.setServerProfileSchemaId(serverSchema.getId()); filter.setEndpointGroupId(defaultGroup.getId()); filter = profileService.saveProfileFilter(filter); profileService.activateProfileFilter(filter.getId(), "test"); }
@Override public List<EndpointProfileSchemaDto> getProfileSchemasByApplicationId( String applicationId) throws ControlServiceException { return profileService.findProfileSchemasByAppId(applicationId); }
@Override public EndpointProfileSchemaDto getProfileSchemaByApplicationIdAndVersion( String applicationId, int version) throws ControlServiceException { return profileService.findProfileSchemaByAppIdAndVersion(applicationId, version); }
@Override public List<VersionDto> getProfileSchemaVersionsByApplicationId(String applicationId) throws ControlServiceException { return profileService.findProfileSchemaVersionsByAppId(applicationId); }
@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 removeProfileSchemaByIdTest() { String schemaId = generateProfSchemaDto(null, null, 1).get(0).getId(); EndpointProfileSchemaDto schemaDto = profileService.findProfileSchemaById(schemaId); Assert.assertNotNull(schemaDto); profileService.removeProfileSchemaById(schemaId); schemaDto = profileService.findProfileSchemaById(schemaId); Assert.assertNull(schemaDto); }
@Test public void removeProfileSchemasByAppIdTest() { int profSchemaCount = 2; ApplicationDto application = generateApplicationDto(null); generateProfSchemaDto(application.getTenantId(), application.getId(), profSchemaCount); List<EndpointProfileSchemaDto> schemas = profileService.findProfileSchemasByAppId(application.getId()); Assert.assertNotNull(schemas); Assert.assertFalse(schemas.isEmpty()); profileService.removeProfileSchemasByAppId(application.getId()); schemas = profileService.findProfileSchemasByAppId(application.getId()); Assert.assertNotNull(schemas); Assert.assertTrue(schemas.isEmpty()); }
@Override public EndpointProfileSchemaDto getProfileSchema(String profileSchemaId) throws ControlServiceException { return profileService.findProfileSchemaById(profileSchemaId); }
@Test(expected = IncorrectParameterException.class) public void invalidProfileFilterDeactivationTest() { String id = "-1"; profileService.deactivateProfileFilter(id, null); }
@Test public void updateExistingProfileSchemaTest() { ApplicationDto app = generateApplicationDto(null); String appId = app.getId(); List<EndpointProfileSchemaDto> schemas = generateProfSchemaDto(app.getTenantId(), appId, 1); EndpointProfileSchemaDto schema = profileService.findProfileSchemaById(schemas.get(0).getId()); Assert.assertNotNull(schema); EndpointProfileSchema endpointProfileSchema = new EndpointProfileSchema(schema); endpointProfileSchema.setName("Updated name"); endpointProfileSchema.setDescription("Updated description"); EndpointProfileSchemaDto saved = profileService.saveProfileSchema(endpointProfileSchema.toDto()); Assert.assertNotNull(saved); Assert.assertEquals(schema.getId(), saved.getId()); Assert.assertEquals(schema.getApplicationId(), saved.getApplicationId()); Assert.assertNotEquals(schema.getName(), saved.getName()); Assert.assertNotEquals(schema.getDescription(), saved.getDescription()); }
@Test(expected = IncorrectParameterException.class) public void activateProfileFilterNoProfileFilterTest() { ChangeProfileFilterNotification activated = profileService.activateProfileFilter("13232", null); }