use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.
the class DataElementControllerDocumentation method testCreateValidation.
@Test
public void testCreateValidation() throws Exception {
MockHttpSession session = getSession("F_DATAELEMENT_PUBLIC_ADD");
DataElement de = createDataElement('A');
de.setName(null);
mvc.perform(post("/dataElements").session(session).contentType(TestUtils.APPLICATION_JSON_UTF8).content(TestUtils.convertObjectToJsonBytes(de)));
de = manager.getByName(DataElement.class, "DataElementA");
assertNull(de);
}
use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.
the class DataElementControllerDocumentation method testGetById404.
@Test
public void testGetById404() throws Exception {
MockHttpSession session = getSession("ALL");
mvc.perform(get("/dataElements/{id}", "deabcdefghA").session(session).accept(MediaType.APPLICATION_JSON)).andExpect(status().isNotFound());
}
use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.
the class DataElementControllerDocumentation method testAddDeleteCollectionItem.
@Test
public void testAddDeleteCollectionItem() throws Exception {
MockHttpSession session = getSession("ALL");
DataElement de = createDataElement('A');
manager.save(de);
Schema schema = schemaService.getSchema(DataElement.class);
List<Property> properties = schema.getProperties();
for (Property property : properties) {
if (property.isCollection()) {
String collectionName = property.getCollectionName();
IdentifiableObject item = createTestObject(property.getItemKlass(), 'A');
if (item == null) {
continue;
} else {
manager.save(item);
}
mvc.perform(post("/dataElements/" + de.getUid() + "/" + collectionName + "/" + item.getUid()).session(session).contentType(TestUtils.APPLICATION_JSON_UTF8)).andDo(documentPrettyPrint("data-elements/add" + collectionName)).andExpect(status().isNoContent());
mvc.perform(delete("/dataElements/" + de.getUid() + "/" + collectionName + "/" + item.getUid()).session(session).contentType(TestUtils.APPLICATION_JSON_UTF8)).andDo(documentPrettyPrint("data-elements/delete" + collectionName)).andExpect(status().isNoContent());
}
}
}
use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.
the class AttributeControllerDocumentation method testCreateSectionAttribute.
@Test
public void testCreateSectionAttribute() throws Exception {
InputStream input = new ClassPathResource("attribute/SectionAttribute.json").getInputStream();
MockHttpSession session = getSession("ALL");
mvc.perform(post(schema.getRelativeApiEndpoint()).session(session).contentType(TestUtils.APPLICATION_JSON_UTF8).content(ByteStreams.toByteArray(input))).andExpect(status().is(createdStatus));
}
use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.
the class AttributeControllerDocumentation method testCreate.
@Override
public void testCreate() throws Exception {
InputStream input = new ClassPathResource("attribute/SQLViewAttribute.json").getInputStream();
MockHttpSession session = getSession("ALL");
Set<FieldDescriptor> fieldDescriptors = TestUtils.getFieldDescriptors(schema);
mvc.perform(post(schema.getRelativeApiEndpoint()).session(session).contentType(TestUtils.APPLICATION_JSON_UTF8).content(ByteStreams.toByteArray(input))).andExpect(status().is(createdStatus)).andDo(documentPrettyPrint(schema.getPlural() + "/create", requestFields(fieldDescriptors.toArray(new FieldDescriptor[fieldDescriptors.size()]))));
}
Aggregations