@Override public EndpointProfileSchemaDto editProfileSchema(EndpointProfileSchemaDto profileSchema) throws ControlServiceException { return profileService.saveProfileSchema(profileSchema); }
private EndpointProfileSchemaDto createDefaultProfileSchema(String appId, String createdUsername) { EndpointProfileSchemaDto profileSchemaDto = new EndpointProfileSchemaDto(); profileSchemaDto.setApplicationId(appId); CTLSchemaDto ctlSchema = ctlService.getOrCreateEmptySystemSchema(createdUsername); profileSchemaDto.setCtlSchemaId(ctlSchema.getId()); profileSchemaDto.setName(DEFAULT_SCHEMA_NAME); profileSchemaDto.setCreatedUsername(createdUsername); profileSchemaDto = profileService.saveProfileSchema(profileSchemaDto); if (profileSchemaDto == null) { throw new RuntimeException("Can't save default profile schema "); //NOSONAR } return profileSchemaDto; }
protected List<EndpointProfileSchemaDto> generateProfSchemaDto(String tenantId, String appId, int count) { List<EndpointProfileSchemaDto> schemas = Collections.emptyList(); try { if (isBlank(tenantId)) { tenantId = generateTenantDto().getId(); } if (isBlank(appId)) { appId = generateApplicationDto(tenantId).getId(); } EndpointProfileSchemaDto schemaDto; CTLSchemaDto ctlSchemaDto = ctlService.saveCtlSchema(generateCTLSchemaDto(tenantId)); schemas = new ArrayList<>(count); for (int i = 0; i < count; i++) { schemaDto = new EndpointProfileSchemaDto(); schemaDto.setApplicationId(appId); schemaDto.setCtlSchemaId(ctlSchemaDto.getId()); schemaDto.setCreatedUsername("Test User"); schemaDto.setName("Test Name"); schemaDto = profileService.saveProfileSchema(schemaDto); Assert.assertNotNull(schemaDto); schemas.add(schemaDto); } } catch (Exception e) { LOG.error("Can't generate configs {}", e); Assert.fail("Can't generate configurations."); } return schemas; }
protected List<EndpointProfileSchemaDto> generateProfSchema(String tenantId, String applicationId, int count) { List<EndpointProfileSchemaDto> schemas = Collections.emptyList(); try { if (isBlank(tenantId)) { tenantId = generateTenant().getId(); } if (isBlank(applicationId)) { applicationId = generateApplication(tenantId).getId(); } CTLSchemaDto ctlSchemaDto = ctlService.saveCtlSchema(generateCTLSchemaDto(DEFAULT_FQN, tenantId, 1)); EndpointProfileSchemaDto schemaDto; schemas = new ArrayList<>(count); for (int i = 0; i < count; i++) { schemaDto = new EndpointProfileSchemaDto(); schemaDto.setApplicationId(applicationId); schemaDto.setCtlSchemaId(ctlSchemaDto.getId()); schemaDto.setCreatedUsername("Test User"); schemaDto.setName("Test Name"); schemaDto = profileService.saveProfileSchema(schemaDto); Assert.assertNotNull(schemaDto); schemas.add(schemaDto); } } catch (Exception e) { LOG.error("Can't generate profile schemas {}", e); Assert.fail("Can't generate profile schemas."); } return schemas; }
@Test(expected = IncorrectParameterException.class) public void updateExistingProfileSchemaWithIncorrectIdTest() { String appId = generateApplicationDto(null).getId(); EndpointProfileSchemaDto profileSchema = new EndpointProfileSchemaDto(); profileSchema.setId("-1"); profileSchema.setApplicationId(appId); profileSchema.setName("Updated name"); profileSchema.setDescription("Updated description"); profileService.saveProfileSchema(profileSchema); }
@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 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()); }