Search in sources :

Example 96 with MockHttpSession

use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.

the class DataElementCategoryControllerDocumentation method testGetAll.

@Test
@Override
public void testGetAll() throws Exception {
    manager.save(createDataElementCategory('A'));
    manager.save(createDataElementCategory('B'));
    manager.save(createDataElementCategory('C'));
    manager.save(createDataElementCategory('D'));
    MockHttpSession session = getSession("ALL");
    List<FieldDescriptor> fieldDescriptors = new ArrayList<>();
    fieldDescriptors.addAll(ResponseDocumentation.pager());
    fieldDescriptors.add(fieldWithPath(CategorySchemaDescriptor.PLURAL).description("Data element categories"));
    mvc.perform(get("/" + CategorySchemaDescriptor.PLURAL).session(session).accept(TestUtils.APPLICATION_JSON_UTF8)).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(TestUtils.APPLICATION_JSON_UTF8)).andExpect(jsonPath("$." + CategorySchemaDescriptor.PLURAL).isArray()).andExpect(jsonPath("$." + CategorySchemaDescriptor.PLURAL + ".length()").value(5)).andDo(documentPrettyPrint(CategorySchemaDescriptor.PLURAL + "/all", responseFields(fieldDescriptors.toArray(new FieldDescriptor[fieldDescriptors.size()]))));
}
Also used : ArrayList(java.util.ArrayList) MockHttpSession(org.springframework.mock.web.MockHttpSession) FieldDescriptor(org.springframework.restdocs.payload.FieldDescriptor) Test(org.junit.Test) AbstractWebApiTest(org.hisp.dhis.webapi.documentation.controller.AbstractWebApiTest)

Example 97 with MockHttpSession

use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.

the class DataElementCategoryControllerDocumentation method testCreate.

@Test
@Override
public void testCreate() throws Exception {
    MockHttpSession session = getSession("F_CATEGORY_PUBLIC_ADD");
    DataElementCategoryOption categoryOptionA = createCategoryOption('A');
    DataElementCategoryOption categoryOptionB = createCategoryOption('B');
    DataElementCategoryOption categoryOptionC = createCategoryOption('C');
    DataElementCategory cat = createDataElementCategory('A', categoryOptionA, categoryOptionB, categoryOptionC);
    Schema schema = schemaService.getSchema(DataElementCategory.class);
    Set<FieldDescriptor> fieldDescriptors = TestUtils.getFieldDescriptors(schema);
    mvc.perform(post("/" + ENDPOINT).session(session).contentType(TestUtils.APPLICATION_JSON_UTF8).content(TestUtils.convertObjectToJsonBytes(cat))).andExpect(status().is(createdStatus)).andDo(documentPrettyPrint("categories/create", requestFields(fieldDescriptors.toArray(new FieldDescriptor[fieldDescriptors.size()]))));
    cat = manager.getByName(DataElementCategory.class, "DataElementCategoryA");
    assertNotNull(cat);
}
Also used : DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) Schema(org.hisp.dhis.schema.Schema) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) MockHttpSession(org.springframework.mock.web.MockHttpSession) FieldDescriptor(org.springframework.restdocs.payload.FieldDescriptor) Test(org.junit.Test) AbstractWebApiTest(org.hisp.dhis.webapi.documentation.controller.AbstractWebApiTest)

Example 98 with MockHttpSession

use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.

the class DataElementControllerDocumentation method testFilterLike.

@Test
public void testFilterLike() throws Exception {
    MockHttpSession session = getSession("F_DATAELEMENT_PUBLIC_ADD");
    DataElement de = createDataElement('A');
    manager.save(de);
    List<FieldDescriptor> fieldDescriptors = new ArrayList<>();
    fieldDescriptors.addAll(ResponseDocumentation.pager());
    fieldDescriptors.add(fieldWithPath("dataElements").description("Data elements"));
    mvc.perform(get("/dataElements?filter=name:like:DataElementA").session(session).contentType(TestUtils.APPLICATION_JSON_UTF8)).andExpect(jsonPath("$.pager.total", new GreaterThan<Integer>(0))).andDo(documentPrettyPrint("data-elements/filter", responseFields(fieldDescriptors.toArray(new FieldDescriptor[fieldDescriptors.size()]))));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) ArrayList(java.util.ArrayList) MockHttpSession(org.springframework.mock.web.MockHttpSession) FieldDescriptor(org.springframework.restdocs.payload.FieldDescriptor) Test(org.junit.Test) AbstractWebApiTest(org.hisp.dhis.webapi.documentation.controller.AbstractWebApiTest)

Example 99 with MockHttpSession

use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.

the class DataElementControllerDocumentation method testFieldsFilterOk.

@Test
public void testFieldsFilterOk() throws Exception {
    MockHttpSession session = getSession("F_DATAELEMENT_PUBLIC_ADD");
    DataElement de = createDataElement('A');
    manager.save(de);
    List<FieldDescriptor> fieldDescriptors = new ArrayList<>();
    fieldDescriptors.addAll(ResponseDocumentation.pager());
    fieldDescriptors.add(fieldWithPath("dataElements").description("Data elements"));
    mvc.perform(get("/dataElements?filter=name:eq:DataElementA&fields=id,name,valueType").session(session).contentType(TestUtils.APPLICATION_JSON_UTF8)).andExpect(jsonPath("$.dataElements[*].id").exists()).andExpect(jsonPath("$.dataElements[*].name").exists()).andExpect(jsonPath("$.dataElements[*].valueType").exists()).andExpect(jsonPath("$.dataElements[*].categoryCombo").doesNotExist()).andDo(documentPrettyPrint("data-elements/fields", responseFields(fieldDescriptors.toArray(new FieldDescriptor[fieldDescriptors.size()]))));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) ArrayList(java.util.ArrayList) MockHttpSession(org.springframework.mock.web.MockHttpSession) FieldDescriptor(org.springframework.restdocs.payload.FieldDescriptor) Test(org.junit.Test) AbstractWebApiTest(org.hisp.dhis.webapi.documentation.controller.AbstractWebApiTest)

Example 100 with MockHttpSession

use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.

the class AbstractWebApiTest method testDeleteById404.

@Test
public void testDeleteById404() throws Exception {
    MockHttpSession session = getSession("ALL");
    mvc.perform(delete(schema.getRelativeApiEndpoint() + "/{id}", "deabcdefghA").session(session).accept(MediaType.APPLICATION_JSON)).andExpect(status().isNotFound());
}
Also used : MockHttpSession(org.springframework.mock.web.MockHttpSession) DhisWebSpringTest(org.hisp.dhis.webapi.DhisWebSpringTest) Test(org.junit.Test)

Aggregations

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