use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.
the class ApiVersionTypeTest method testTypeAnnotationAll.
@Test
public void testTypeAnnotationAll() throws Exception {
MockHttpSession session = getSession("ALL");
String endpoint = "/type/testAll";
mvc.perform(get(endpoint).session(session)).andExpect(status().isNotFound());
mvc.perform(get("/23" + endpoint).session(session)).andExpect(status().isOk());
mvc.perform(get("/24" + endpoint).session(session)).andExpect(status().isOk());
}
use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.
the class DataElementCategoryControllerDocumentation method testAddDeleteCollectionItem.
@Test
public void testAddDeleteCollectionItem() throws Exception {
MockHttpSession session = getSession("ALL");
DataElementCategory category = createDataElementCategory('A');
manager.save(category);
Schema schema = schemaService.getSchema(DataElementCategory.class);
List<Property> properties = schema.getProperties();
for (Property property : properties) {
if (property.isCollection()) {
String collectionName = property.getCollectionName();
IdentifiableObject item = createTestObject(property.getItemKlass(), 'A', category);
if (item == null) {
continue;
} else {
manager.save(item);
}
mvc.perform(post("/" + ENDPOINT + "/" + category.getUid() + "/" + collectionName + "/" + item.getUid()).session(session).contentType(TestUtils.APPLICATION_JSON_UTF8)).andDo(documentPrettyPrint(ENDPOINT + "/add" + collectionName)).andExpect(status().isNoContent());
mvc.perform(delete("/" + ENDPOINT + "/" + category.getUid() + "/" + collectionName + "/" + item.getUid()).session(session).contentType(TestUtils.APPLICATION_JSON_UTF8)).andDo(documentPrettyPrint(ENDPOINT + "/delete" + collectionName)).andExpect(status().isNoContent());
}
}
}
use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.
the class DataElementCategoryControllerDocumentation method testDeleteByIdOk.
@Test
@Override
public void testDeleteByIdOk() throws Exception {
DataElementCategory cat = createDataElementCategory('A');
manager.save(cat);
MockHttpSession session = getSession("ALL");
mvc.perform(delete("/" + ENDPOINT + "/{id}", cat.getUid()).session(session).accept(MediaType.APPLICATION_JSON)).andExpect(status().is(deleteStatus)).andDo(documentPrettyPrint("categories/delete"));
}
use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.
the class DataElementCategoryControllerDocumentation method testGetByIdOk.
@Test
@Override
public void testGetByIdOk() throws Exception {
DataElementCategory cat = createDataElementCategory('A');
manager.save(cat);
MockHttpSession session = getSession("ALL");
Schema schema = schemaService.getSchema(DataElementCategory.class);
Set<FieldDescriptor> fieldDescriptors = TestUtils.getFieldDescriptors(schema);
mvc.perform(get("/" + CategorySchemaDescriptor.PLURAL + "/{id}", cat.getUid()).session(session).accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)).andExpect(jsonPath("$.name").value("DataElementCategoryA")).andExpect(jsonPath("$.shortName").value("DataElementCategoryA")).andDo(documentPrettyPrint(ENDPOINT + "/id", responseFields(fieldDescriptors.toArray(new FieldDescriptor[fieldDescriptors.size()]))));
}
use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.
the class DataElementControllerDocumentation method testFilteriLikeOk.
@Test
public void testFilteriLikeOk() throws Exception {
MockHttpSession session = getSession("F_DATAELEMENT_PUBLIC_ADD");
DataElement de = createDataElement('A');
manager.save(de);
mvc.perform(get("/dataElements?filter=name:ilike:DataElementA").session(session).contentType(TestUtils.APPLICATION_JSON_UTF8)).andExpect(jsonPath("$.pager.total", new GreaterThan<Integer>(0)));
}
Aggregations