use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.
the class PrePostSecurityAnnotationsTest method authorityNoAuthorityCantAccessApps.
@Test
public void authorityNoAuthorityCantAccessApps() throws Exception {
MockHttpSession session = getSession("NO_AUTHORITY");
mvc.perform(put("/apps").session(session)).andExpect(status().isForbidden());
}
use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.
the class TranslationWebApiTest method testOK.
@Test
public void testOK() throws Exception {
Locale locale = Locale.FRENCH;
MockHttpSession session = getSession("ALL");
DataElement dataElementA = createDataElement('A');
identifiableObjectManager.save(dataElementA);
String valueToCheck = "frenchTranslated";
dataElementA.getTranslations().add(new ObjectTranslation(locale.getLanguage(), TranslationProperty.NAME, valueToCheck));
mvc.perform(put("/dataElements/" + dataElementA.getUid() + "/translations").session(session).contentType(TestUtils.APPLICATION_JSON_UTF8).content(TestUtils.convertObjectToJsonBytes(dataElementA))).andExpect(status().is(HttpStatus.SC_NO_CONTENT));
MvcResult result = mvc.perform(get("/dataElements/" + dataElementA.getUid() + "?locale=" + locale.getLanguage()).session(session).contentType(TestUtils.APPLICATION_JSON_UTF8)).andReturn();
ObjectMapper mapper = new ObjectMapper();
JsonNode node = mapper.readTree(result.getResponse().getContentAsString());
assertEquals(valueToCheck, node.get("displayName").asText());
}
use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.
the class AttributeControllerDocumentation method testUpdate.
@Override
public void testUpdate() throws Exception {
InputStream input = new ClassPathResource("attribute/SQLViewAttribute.json").getInputStream();
MockHttpSession session = getSession("ALL");
MvcResult postResult = mvc.perform(post(schema.getRelativeApiEndpoint()).session(session).contentType(TestUtils.APPLICATION_JSON_UTF8).content(ByteStreams.toByteArray(input))).andExpect(status().is(createdStatus)).andReturn();
String uid = TestUtils.getCreatedUid(postResult.getResponse().getContentAsString());
InputStream inputUpdate = new ClassPathResource("attribute/SQLViewAttribute.json").getInputStream();
mvc.perform(put(schema.getRelativeApiEndpoint() + "/" + uid).session(session).contentType(TestUtils.APPLICATION_JSON_UTF8).content(ByteStreams.toByteArray(inputUpdate))).andExpect(status().is(updateStatus)).andDo(documentPrettyPrint(schema.getPlural() + "/update"));
}
use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.
the class AttributeControllerDocumentation method testGetAll.
@Override
public void testGetAll() throws Exception {
InputStream input = new ClassPathResource("attribute/SQLViewAttribute.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)).andReturn();
List<FieldDescriptor> fieldDescriptors = new ArrayList<>();
fieldDescriptors.addAll(ResponseDocumentation.pager());
fieldDescriptors.add(fieldWithPath(schema.getPlural()).description(schema.getPlural()));
mvc.perform(get(schema.getRelativeApiEndpoint()).session(session).accept(TestUtils.APPLICATION_JSON_UTF8)).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(TestUtils.APPLICATION_JSON_UTF8)).andExpect(jsonPath("$." + schema.getPlural()).isArray()).andExpect(jsonPath("$." + schema.getPlural() + ".length()").value(1)).andDo(documentPrettyPrint(schema.getPlural() + "/all", responseFields(fieldDescriptors.toArray(new FieldDescriptor[fieldDescriptors.size()]))));
}
use of org.springframework.mock.web.MockHttpSession in project dhis2-core by dhis2.
the class AttributeControllerDocumentation method testGetByIdOk.
@Override
public void testGetByIdOk() throws Exception {
InputStream input = new ClassPathResource("attribute/SQLViewAttribute.json").getInputStream();
MockHttpSession session = getSession("ALL");
MvcResult postResult = mvc.perform(post(schema.getRelativeApiEndpoint()).session(session).contentType(TestUtils.APPLICATION_JSON_UTF8).content(ByteStreams.toByteArray(input))).andExpect(status().is(createdStatus)).andReturn();
Set<FieldDescriptor> fieldDescriptors = TestUtils.getFieldDescriptors(schema);
String uid = TestUtils.getCreatedUid(postResult.getResponse().getContentAsString());
mvc.perform(get(schema.getRelativeApiEndpoint() + "/{id}", uid).session(session).accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)).andExpect(jsonPath("$.name").value("sqlViewAttribute")).andDo(documentPrettyPrint(schema.getPlural() + "/id", responseFields(fieldDescriptors.toArray(new FieldDescriptor[fieldDescriptors.size()]))));
}
Aggregations