use of com.agiletec.aps.system.common.entity.IEntityTypesConfigurer in project entando-core by entando.
the class DataTypeControllerIntegrationTest method testAddUpdateDataType_1.
@Test
public void testAddUpdateDataType_1() throws Exception {
try {
Assert.assertNull(this.dataObjectManager.getEntityPrototype("AAA"));
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
InputStream isJsonPost = this.getClass().getResourceAsStream("1_POST_valid.json");
String jsonPost = FileTextReader.getText(isJsonPost);
ResultActions result1 = mockMvc.perform(post("/dataTypes").content(jsonPost).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result1.andExpect(status().isOk());
DataObject addedType = (DataObject) this.dataObjectManager.getEntityPrototype("AAA");
Assert.assertNotNull(addedType);
Assert.assertEquals("Type AAA", addedType.getTypeDescription());
Assert.assertEquals(1, addedType.getAttributeList().size());
InputStream isJsonPutInvalid = this.getClass().getResourceAsStream("1_PUT_invalid.json");
String jsonPutInvalid = FileTextReader.getText(isJsonPutInvalid);
ResultActions result2 = mockMvc.perform(put("/dataTypes/{dataTypeCode}", new Object[] { "AAA" }).content(jsonPutInvalid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result2.andExpect(status().isBadRequest());
InputStream isJsonPutValid = this.getClass().getResourceAsStream("1_PUT_valid.json");
String jsonPutValid = FileTextReader.getText(isJsonPutValid);
ResultActions result3 = mockMvc.perform(put("/dataTypes/{dataTypeCode}", new Object[] { "AAA" }).content(jsonPutValid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result3.andExpect(status().isOk());
addedType = (DataObject) this.dataObjectManager.getEntityPrototype("AAA");
Assert.assertEquals("Type AAA Modified", addedType.getTypeDescription());
Assert.assertEquals(2, addedType.getAttributeList().size());
ResultActions result4 = mockMvc.perform(delete("/dataTypes/{dataTypeCode}", new Object[] { "AAA" }).header("Authorization", "Bearer " + accessToken));
result4.andExpect(status().isOk());
Assert.assertNull(this.dataObjectManager.getEntityPrototype("AAA"));
} finally {
if (null != this.dataObjectManager.getEntityPrototype("AAA")) {
((IEntityTypesConfigurer) this.dataObjectManager).removeEntityPrototype("AAA");
}
}
}
use of com.agiletec.aps.system.common.entity.IEntityTypesConfigurer in project entando-core by entando.
the class DataTypeControllerIntegrationTest method testAddUpdateDataType_2.
@Test
public void testAddUpdateDataType_2() throws Exception {
try {
Assert.assertNull(this.dataObjectManager.getEntityPrototype("TST"));
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
InputStream isJsonPostInvalid = this.getClass().getResourceAsStream("2_POST_invalid.json");
String jsonPostInvalid = FileTextReader.getText(isJsonPostInvalid);
ResultActions result1 = mockMvc.perform(post("/dataTypes").content(jsonPostInvalid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result1.andExpect(status().isBadRequest());
Assert.assertNull(this.dataObjectManager.getEntityPrototype("TST"));
InputStream isJsonPostValid = this.getClass().getResourceAsStream("2_POST_valid.json");
String jsonPostValid = FileTextReader.getText(isJsonPostValid);
ResultActions result2 = mockMvc.perform(post("/dataTypes").content(jsonPostValid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result2.andExpect(status().isOk());
DataObject addedDataObject = (DataObject) this.dataObjectManager.getEntityPrototype("TST");
Assert.assertNotNull(addedDataObject);
Assert.assertEquals(3, addedDataObject.getAttributeList().size());
ResultActions result2_bis = mockMvc.perform(post("/dataTypes").content(jsonPostValid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result2_bis.andExpect(status().isConflict());
InputStream isJsonPutValid = this.getClass().getResourceAsStream("2_PUT_valid.json");
String jsonPutValid = FileTextReader.getText(isJsonPutValid);
ResultActions result3 = mockMvc.perform(put("/dataTypes/{dataTypeCode}", new Object[] { "AAA" }).content(jsonPutValid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result3.andExpect(status().isBadRequest());
ResultActions result3_bis = mockMvc.perform(put("/dataTypes/{dataTypeCode}", new Object[] { "TST" }).content(jsonPutValid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result3_bis.andExpect(status().isOk());
DataObject modifiedDataObject = (DataObject) this.dataObjectManager.getEntityPrototype("TST");
Assert.assertNotNull(modifiedDataObject);
Assert.assertEquals(5, modifiedDataObject.getAttributeList().size());
ResultActions result4 = mockMvc.perform(delete("/dataTypes/{dataTypeCode}", new Object[] { "TST" }).header("Authorization", "Bearer " + accessToken));
result4.andExpect(status().isOk());
Assert.assertNull(this.dataObjectManager.getEntityPrototype("TST"));
} finally {
if (null != this.dataObjectManager.getEntityPrototype("TST")) {
((IEntityTypesConfigurer) this.dataObjectManager).removeEntityPrototype("TST");
}
}
}
use of com.agiletec.aps.system.common.entity.IEntityTypesConfigurer in project entando-core by entando.
the class ProfileTypeControllerIntegrationTest method testAddUpdateUserProfileType_2.
@Test
public void testAddUpdateUserProfileType_2() throws Exception {
try {
Assert.assertNull(this.userProfileManager.getEntityPrototype("TST"));
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
InputStream isJsonPostInvalid = this.getClass().getResourceAsStream("2_POST_invalid.json");
String jsonPostInvalid = FileTextReader.getText(isJsonPostInvalid);
ResultActions result1 = mockMvc.perform(post("/profileTypes").content(jsonPostInvalid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result1.andExpect(status().isBadRequest());
Assert.assertNull(this.userProfileManager.getEntityPrototype("TST"));
InputStream isJsonPostValid = this.getClass().getResourceAsStream("2_POST_valid.json");
String jsonPostValid = FileTextReader.getText(isJsonPostValid);
ResultActions result2 = mockMvc.perform(post("/profileTypes").content(jsonPostValid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result2.andExpect(status().isOk());
UserProfile addedDataObject = (UserProfile) this.userProfileManager.getEntityPrototype("TST");
Assert.assertNotNull(addedDataObject);
Assert.assertEquals(3, addedDataObject.getAttributeList().size());
ResultActions result2_bis = mockMvc.perform(post("/profileTypes").content(jsonPostValid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result2_bis.andExpect(status().isConflict());
InputStream isJsonPutValid = this.getClass().getResourceAsStream("2_PUT_valid.json");
String jsonPutValid = FileTextReader.getText(isJsonPutValid);
ResultActions result3 = mockMvc.perform(put("/profileTypes/{profileTypeCode}", new Object[] { "AAA" }).content(jsonPutValid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result3.andExpect(status().isBadRequest());
ResultActions result3_bis = mockMvc.perform(put("/profileTypes/{profileTypeCode}", new Object[] { "TST" }).content(jsonPutValid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result3_bis.andExpect(status().isOk());
UserProfile modifiedDataObject = (UserProfile) this.userProfileManager.getEntityPrototype("TST");
Assert.assertNotNull(modifiedDataObject);
Assert.assertEquals(5, modifiedDataObject.getAttributeList().size());
ResultActions result4 = mockMvc.perform(delete("/profileTypes/{profileTypeCode}", new Object[] { "TST" }).header("Authorization", "Bearer " + accessToken));
result4.andExpect(status().isOk());
Assert.assertNull(this.userProfileManager.getEntityPrototype("TST"));
} finally {
if (null != this.userProfileManager.getEntityPrototype("TST")) {
((IEntityTypesConfigurer) this.userProfileManager).removeEntityPrototype("TST");
}
}
}
use of com.agiletec.aps.system.common.entity.IEntityTypesConfigurer in project entando-core by entando.
the class ApiEntityTypeInterface method deleteEntityType.
public void deleteEntityType(Properties properties) throws Throwable {
try {
String typeCode = properties.getProperty(this.getTypeCodeParamName());
IApsEntity masterEntityType = this.getEntityManager().getEntityPrototype(typeCode);
if (null == masterEntityType) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, this.getTypeLabel() + " with code '" + typeCode + "' doesn't exist");
}
EntitySearchFilter filter = new EntitySearchFilter(IEntityManager.ENTITY_TYPE_CODE_FILTER_KEY, false, typeCode, false);
List<String> entityIds = this.getEntityManager().searchId(new EntitySearchFilter[] { filter });
if (null != entityIds && !entityIds.isEmpty()) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, this.getTypeLabel() + " '" + typeCode + "' are used into " + entityIds.size() + " entities");
}
this.checkEntityTypeToDelete(masterEntityType);
((IEntityTypesConfigurer) this.getEntityManager()).removeEntityPrototype(typeCode);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("Error deleting Entity type", t);
// ApsSystemUtils.logThrowable(t, this, "deleteEntityType");
throw new ApsSystemException("Error deleting Entity type", t);
}
}
Aggregations