use of org.entando.entando.aps.system.services.dataobject.model.DataObject 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 org.entando.entando.aps.system.services.dataobject.model.DataObject 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");
}
}
}
Aggregations