Search in sources :

Example 41 with MockHttpSession

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);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) MockHttpSession(org.springframework.mock.web.MockHttpSession) Test(org.junit.Test) AbstractWebApiTest(org.hisp.dhis.webapi.documentation.controller.AbstractWebApiTest)

Example 42 with MockHttpSession

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());
}
Also used : MockHttpSession(org.springframework.mock.web.MockHttpSession) Test(org.junit.Test) AbstractWebApiTest(org.hisp.dhis.webapi.documentation.controller.AbstractWebApiTest)

Example 43 with MockHttpSession

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());
        }
    }
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) Schema(org.hisp.dhis.schema.Schema) MockHttpSession(org.springframework.mock.web.MockHttpSession) Property(org.hisp.dhis.schema.Property) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.Test) AbstractWebApiTest(org.hisp.dhis.webapi.documentation.controller.AbstractWebApiTest)

Example 44 with MockHttpSession

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));
}
Also used : InputStream(java.io.InputStream) MockHttpSession(org.springframework.mock.web.MockHttpSession) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 45 with MockHttpSession

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()]))));
}
Also used : InputStream(java.io.InputStream) MockHttpSession(org.springframework.mock.web.MockHttpSession) ClassPathResource(org.springframework.core.io.ClassPathResource) FieldDescriptor(org.springframework.restdocs.payload.FieldDescriptor)

Aggregations

MockHttpSession (org.springframework.mock.web.MockHttpSession)106 Test (org.junit.Test)84 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)44 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)34 DhisWebSpringTest (org.hisp.dhis.webapi.DhisWebSpringTest)23 HashMap (java.util.HashMap)13 AbstractWebApiTest (org.hisp.dhis.webapi.documentation.controller.AbstractWebApiTest)13 MockFilterChain (org.springframework.mock.web.MockFilterChain)12 FieldDescriptor (org.springframework.restdocs.payload.FieldDescriptor)11 ModelAndView (org.springframework.web.servlet.ModelAndView)11 OAuthRegisteredService (org.apereo.cas.support.oauth.services.OAuthRegisteredService)9 FilterChain (javax.servlet.FilterChain)8 MockServletContext (org.springframework.mock.web.MockServletContext)8 SessionRegistry (org.springframework.security.core.session.SessionRegistry)8 ConcurrentSessionFilter (org.springframework.security.web.session.ConcurrentSessionFilter)8 Principal (org.apereo.cas.authentication.principal.Principal)7 DataElement (org.hisp.dhis.dataelement.DataElement)7 CasProfile (org.pac4j.cas.profile.CasProfile)7 InputStream (java.io.InputStream)6 Before (org.junit.Before)6