Search in sources :

Example 71 with DataObject

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");
        }
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) InputStream(java.io.InputStream) ResultActions(org.springframework.test.web.servlet.ResultActions) IEntityTypesConfigurer(com.agiletec.aps.system.common.entity.IEntityTypesConfigurer) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 72 with DataObject

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");
        }
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) InputStream(java.io.InputStream) ResultActions(org.springframework.test.web.servlet.ResultActions) IEntityTypesConfigurer(com.agiletec.aps.system.common.entity.IEntityTypesConfigurer) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Aggregations

DataObject (org.entando.entando.aps.system.services.dataobject.model.DataObject)72 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)10 UserDetails (com.agiletec.aps.system.services.user.UserDetails)9 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)7 JAXBDataObject (org.entando.entando.aps.system.services.dataobject.api.model.JAXBDataObject)7 Test (org.junit.Test)7 TextAttribute (com.agiletec.aps.system.common.entity.model.attribute.TextAttribute)6 ArrayList (java.util.ArrayList)5 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)4 ITextAttribute (com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute)4 MonoTextAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoTextAttribute)4 Category (com.agiletec.aps.system.services.category.Category)4 Date (java.util.Date)4 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)3 FieldError (com.agiletec.aps.system.common.entity.model.FieldError)3 DateAttribute (com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)3 MonoListAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute)3 Group (com.agiletec.aps.system.services.group.Group)3 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)3 IDataObjectManager (org.entando.entando.aps.system.services.dataobject.IDataObjectManager)3