@Override protected GenericModel<EndpointProfileSchemaDto> newInstance(Long id) { return new EndpointProfileSchema(id); } }
/** * Get id of endpoint profile schema. * @return id */ public String getEndpointProfileSchemaId() { String id = null; if (endpointProfileSchema != null) { id = endpointProfileSchema.getStringId(); } return id; }
/** * Get version of endpoint profile schema. * @return version */ public Integer getEndpointProfileSchemaVersion() { Integer version = null; if (endpointProfileSchema != null) { version = endpointProfileSchema.getVersion(); } return version; }
protected List<EndpointProfileSchema> generateProfSchema(Application app, int count) { List<EndpointProfileSchema> schemas = Collections.emptyList(); try { if (app == null) { app = generateApplication(null); } CtlSchema ctlSchema = generateCTLSchema(DEFAULT_FQN, 1, app.getTenant(), null); EndpointProfileSchema schemaDto; schemas = new ArrayList<>(count); for (int i = 0; i < count; i++) { schemaDto = new EndpointProfileSchema(); schemaDto.setApplication(app); schemaDto.setCreatedUsername("Test User"); schemaDto.setCtlSchema(ctlSchema); schemaDto.setVersion(i + 1); schemaDto.setName("Test Name"); schemaDto = profileSchemaDao.save(schemaDto); Assert.assertNotNull(schemaDto); schemas.add(schemaDto); } } catch (Exception e) { LOG.error("Can't generate profile schema {}", e); Assert.fail("Can't generate profile schema." + e.getMessage()); } return schemas; }
@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()); }
@Override public ProfileFilterDto toDto() { ProfileFilterDto filterDto = super.toDto(); filterDto.setBody(body); if (endpointProfileSchema != null) { filterDto.setEndpointProfileSchemaId(endpointProfileSchema.getStringId()); filterDto.setEndpointProfileSchemaVersion(endpointProfileSchema.getVersion()); } if (serverProfileSchema != null) { filterDto.setServerProfileSchemaId(serverProfileSchema.getStringId()); filterDto.setServerProfileSchemaVersion(serverProfileSchema.getVersion()); } return filterDto; }
int version = -1; if (endpointProfileSchema != null) { version = endpointProfileSchema.getVersion(); oldProfileSchemaDto.editFields(profileSchemaDto); profileSchemaDto = oldProfileSchemaDto; return getDto(profileSchemaDao.save(new EndpointProfileSchema(profileSchemaDto))); } else { LOG.error("Can't find profile schema with given id [{}].", id); return getDto(profileSchemaDao.save(new EndpointProfileSchema(profileSchemaDto))); } else { throw new IncorrectParameterException("Invalid profile schema object. "
@Test public void findByAppIdAndVersion() { List<EndpointProfileSchema> schemas = generateProfSchema(null, 4); Assert.assertEquals(4, schemas.size()); EndpointProfileSchema schema = schemas.get(2); Application app = schema.getApplication(); EndpointProfileSchema found = profileSchemaDao.findByAppIdAndVersion(app.getId().toString(), schema.getVersion()); Assert.assertNotNull(found); Assert.assertEquals(3, found.getVersion()); }
@Test public void findByApplicationId() { List<EndpointProfileSchema> schemas = generateProfSchema(null, 3); Assert.assertEquals(3, schemas.size()); EndpointProfileSchema schema = schemas.get(0); Application app = schema.getApplication(); List<EndpointProfileSchema> found = profileSchemaDao.findByApplicationId(app.getId().toString()); Assert.assertEquals(3, found.size()); Assert.assertEquals(schemas, found); }
@Override public int hashCode() { int result = super.hashCode(); result = 31 * result + (body != null ? body.hashCode() : 0); result = 31 * result + (endpointProfileSchema != null ? endpointProfileSchema.hashCode() : 0); result = 31 * result + (serverProfileSchema != null ? serverProfileSchema.hashCode() : 0); return result; }
@Override public void removeProfileSchemasByAppId(String applicationId) { validateSqlId(applicationId, "Can't remove profile schema. Invalid application id: " + applicationId); List<EndpointProfileSchema> schemas = profileSchemaDao.findByApplicationId(applicationId); if (schemas != null && !schemas.isEmpty()) { LOG.debug("Remove profile shemas by application id {}", applicationId); for (EndpointProfileSchema schema : schemas) { removeProfileSchemaById(schema.getId().toString()); } } }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null || getClass() != obj.getClass()) { return false; } if (!super.equals(obj)) { return false; } ProfileFilter that = (ProfileFilter) obj; if (body != null ? !body.equals(that.body) : that.body != null) { return false; } if (endpointProfileSchema != null ? !endpointProfileSchema.equals(that.endpointProfileSchema) : that.endpointProfileSchema != null) { return false; } return serverProfileSchema != null ? serverProfileSchema.equals(that.serverProfileSchema) : that.serverProfileSchema == null; }
@Test public void findLatestByAppId() { List<EndpointProfileSchema> schemas = generateProfSchema(null, 4); Assert.assertEquals(4, schemas.size()); EndpointProfileSchema schema = schemas.get(0); Application app = schema.getApplication(); EndpointProfileSchema found = profileSchemaDao.findLatestByAppId(app.getId().toString()); Assert.assertNotNull(found); Assert.assertEquals(4, found.getVersion()); }
protected List<ProfileFilter> generateFilterWithoutSchemaGeneration(EndpointProfileSchema schema, ServerProfileSchema srvSchema, EndpointGroup group, int count, UpdateStatus status) { Application app = null; if (schema != null) { app = schema.getApplication(); } else if (srvSchema != null) { app = srvSchema.getApplication(); } if (group == null) { group = generateEndpointGroup(app, null); } List<ProfileFilter> filters = new ArrayList<>(); for (int i = 0; i < count; i++) { ProfileFilter dto = new ProfileFilter(); dto.setId(null); dto.setStatus(status != null ? status : UpdateStatus.INACTIVE); dto.setEndpointGroup(group); dto.setEndpointProfileSchema(schema); dto.setServerProfileSchema(srvSchema); dto.setSequenceNumber(i); dto.setApplication(app); ProfileFilter saved = profileFilterDao.save(dto); Assert.assertNotNull(saved); filters.add(saved); } return filters; }
@Test public void findActualBySchemaIdAndGroupIdWithNullServerSchema() { EndpointProfileSchema ps = generateProfSchema(null, 1).get(0); List<ProfileFilter> filters = generateFilterWithoutSchemaGeneration(ps, null, null, 1, UpdateStatus.ACTIVE); ProfileFilter first = filters.get(0); EndpointGroup group = first.getEndpointGroup(); EndpointProfileSchema schema = first.getEndpointProfileSchema(); List<ProfileFilter> found = profileFilterDao.findActualBySchemaIdAndGroupId(schema.getStringId(), null, group.getStringId()); Assert.assertFalse(found.isEmpty()); }
@Test public void findByAppIdAndSchemaVersion() { Application app = generateApplication(null); EndpointProfileSchema schema = generateProfSchema(app, 1).get(0); ServerProfileSchemaDto srvSchema = generateServerProfileSchema(app.getStringId(), app.getTenant().getStringId(), 101); generateFilter(schema, new ServerProfileSchema(srvSchema), null, 2, UpdateStatus.ACTIVE); List<ProfileFilter> filters = generateFilterWithoutSchemaGeneration(schema, new ServerProfileSchema(srvSchema), null, 1, UpdateStatus.ACTIVE); filters.addAll(generateFilterWithoutSchemaGeneration(null, new ServerProfileSchema(srvSchema), null, 1, UpdateStatus.ACTIVE)); filters.addAll(generateFilterWithoutSchemaGeneration(schema, null, null, 1, UpdateStatus.ACTIVE)); List<ProfileFilter> found = profileFilterDao.findByAppIdAndSchemaVersionsCombination(app.getStringId(), schema.getVersion(), srvSchema.getVersion()); Assert.assertEquals(filters, found); }
/** * Create new instance of <code>ProfileFilter</code>. * @param dto data transfer object contain body, * endpoint profile schema id, server profile * schema id. Assign these values on corresponding * fields of new instance */ public ProfileFilter(ProfileFilterDto dto) { super(dto); this.body = dto.getBody(); String endpointSchemaId = dto.getEndpointProfileSchemaId(); if (isNotBlank(endpointSchemaId)) { this.endpointProfileSchema = new EndpointProfileSchema(getLongId(endpointSchemaId)); } String serverSchemaId = dto.getServerProfileSchemaId(); if (isNotBlank(serverSchemaId)) { this.serverProfileSchema = new ServerProfileSchema(getLongId(serverSchemaId)); } }
@Test public void findActualBySchemaIdAndGroupId() { List<ProfileFilter> filters = generateFilter(null, null, null, 4, UpdateStatus.DEPRECATED); ProfileFilter first = filters.get(0); EndpointGroup group = first.getEndpointGroup(); EndpointProfileSchema schema = first.getEndpointProfileSchema(); ServerProfileSchema server = first.getServerProfileSchema(); List<ProfileFilter> active = generateFilter(schema, server, group, 1, UpdateStatus.ACTIVE); generateConfiguration(null, group, 1, UpdateStatus.ACTIVE); List<ProfileFilter> inactive = generateFilter(schema, server, group, 1, UpdateStatus.INACTIVE); List<ProfileFilter> actual = new ArrayList<>(); actual.addAll(active); actual.addAll(inactive); List<ProfileFilter> found = profileFilterDao.findActualBySchemaIdAndGroupId(schema.getStringId(), server.getStringId(), group.getStringId()); Assert.assertEquals(actual.size(), found.size()); Assert.assertEquals(actual, found); }
@Test public void findInactiveFilter() { List<ProfileFilter> filters = generateFilter(null, null, null, 1, UpdateStatus.ACTIVE); Assert.assertEquals(1, filters.size()); ProfileFilter first = filters.get(0); EndpointGroup group = first.getEndpointGroup(); EndpointProfileSchema schema = first.getEndpointProfileSchema(); ServerProfileSchema server = first.getServerProfileSchema(); List<ProfileFilter> inactiveConfigs = generateFilter(schema, server, group, 1, UpdateStatus.INACTIVE); generateFilter(schema, server, group, 3, UpdateStatus.DEPRECATED); ProfileFilter found = profileFilterDao.findInactiveFilter(schema.getStringId(), server.getStringId(), group.getStringId()); Assert.assertEquals(inactiveConfigs.get(0), found); }
@Test public void findLatestFilter() { List<ProfileFilter> filters = generateFilter(null, null, null, 1, UpdateStatus.ACTIVE); Assert.assertEquals(1, filters.size()); ProfileFilter first = filters.get(0); EndpointGroup group = first.getEndpointGroup(); EndpointProfileSchema schema = first.getEndpointProfileSchema(); ServerProfileSchema server = first.getServerProfileSchema(); generateFilter(schema, server, group, 3, UpdateStatus.DEPRECATED); generateFilter(schema, server, group, 1, UpdateStatus.INACTIVE); ProfileFilter found = profileFilterDao.findLatestFilter(schema.getStringId(), server.getStringId(), group.getStringId()); Assert.assertEquals(first, found); }