use of org.springframework.test.web.servlet.MvcResult in project nikita-noark5-core by HiOA-ABI.
the class ArchiveStructureTests method testCorrectArchiveStructureFull.
// @Test
public void testCorrectArchiveStructureFull() throws Exception {
String fondsTitle = "Test fonds title";
String fondsDescription = "Test fonds description. This fonds should be automatically deleted after tests are undertaken";
Fonds fonds = new Fonds();
fonds.setTitle(fondsTitle);
fonds.setDescription(fondsDescription);
fonds.setDocumentMedium(DOCUMENT_MEDIUM_ELECTRONIC);
MvcResult result = mockMvc.perform(post("/" + FONDS).contentType(MediaType.APPLICATION_JSON_VALUE).content(objectMapper.writeValueAsString(fonds))).andExpect(status().isOk()).andReturn();
String responseObject = result.getResponse().getContentAsString();
// How do I check this is actually a fonds, a try catch?
fonds = objectMapper.readValue(responseObject, Fonds.class);
System.out.println(fonds);
}
use of org.springframework.test.web.servlet.MvcResult in project ocvn by devgateway.
the class ReleaseExportTest method testReleaseExportIsValid.
@Test
public void testReleaseExportIsValid() throws Exception {
final ClassLoader classLoader = getClass().getClassLoader();
final File file = new File(classLoader.getResource("json/award-release-test.json").getFile());
final JsonImport releaseJsonImport = new ReleaseJsonImport(releaseRepository, file, false);
final Release release = (Release) releaseJsonImport.importObject();
final MvcResult result = this.mockMvc.perform(MockMvcRequestBuilders.get("/api/ocds/release/ocid/" + release.getOcid()).accept(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).andReturn();
final String content = result.getResponse().getContentAsString();
final JsonNode jsonNodeResponse = JsonLoader.fromString(content);
final OcdsSchemaValidatorService.ProcessingReportWithNode processingReport = ocdsSchemaValidator.validate(jsonNodeResponse);
if (!processingReport.getReport().isSuccess()) {
for (ProcessingMessage processingMessage : processingReport.getReport()) {
logger.error(">>> processingMessage: \n" + processingMessage);
}
}
Assert.assertEquals("Is the release valid?", true, processingReport.getReport().isSuccess());
}
use of org.springframework.test.web.servlet.MvcResult in project metron by apache.
the class KafkaControllerIntegrationTest method test.
@Test
public void test() throws Exception {
this.kafkaService.deleteTopic("bro");
this.kafkaService.deleteTopic("someTopic");
Thread.sleep(1000);
testAndRetry(() -> this.mockMvc.perform(delete(kafkaUrl + "/topic/bro").with(httpBasic(user, password)).with(csrf())).andExpect(status().isNotFound()));
testAndRetry(() -> this.mockMvc.perform(post(kafkaUrl + "/topic").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(broTopic)).andExpect(status().isCreated()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.name").value("bro")).andExpect(jsonPath("$.numPartitions").value(1)).andExpect(jsonPath("$.replicationFactor").value(1)));
Thread.sleep(1000);
testAndRetry(() -> this.mockMvc.perform(get(kafkaUrl + "/topic/bro").with(httpBasic(user, password))).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.name").value("bro")).andExpect(jsonPath("$.numPartitions").value(1)).andExpect(jsonPath("$.replicationFactor").value(1)));
this.mockMvc.perform(get(kafkaUrl + "/topic/someTopic").with(httpBasic(user, password))).andExpect(status().isNotFound());
testAndRetry(() -> this.mockMvc.perform(get(kafkaUrl + "/topic").with(httpBasic(user, password))).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$", Matchers.hasItem("bro"))));
testAndRetry(() -> this.mockMvc.perform(post(kafkaUrl + "/topic/bro/produce").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(message1)).andExpect(status().isOk()));
testAndRetry(() -> this.mockMvc.perform(get(kafkaUrl + "/topic/bro/sample").with(httpBasic(user, password))).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("text/plain;charset=UTF-8"))).andExpect(jsonPath("$.type").value("message1")));
testAndRetry(() -> this.mockMvc.perform(post(kafkaUrl + "/topic/bro/produce").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(message2)).andExpect(status().isOk()));
testAndRetry(() -> this.mockMvc.perform(get(kafkaUrl + "/topic/bro/sample").with(httpBasic(user, password))).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("text/plain;charset=UTF-8"))).andExpect(jsonPath("$.type").value("message2")));
testAndRetry(() -> this.mockMvc.perform(post(kafkaUrl + "/topic/bro/produce").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(message3)).andExpect(status().isOk()));
testAndRetry(() -> this.mockMvc.perform(get(kafkaUrl + "/topic/bro/sample").with(httpBasic(user, password))).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("text/plain;charset=UTF-8"))).andExpect(jsonPath("$.type").value("message3")));
this.mockMvc.perform(get(kafkaUrl + "/topic/someTopic/sample").with(httpBasic(user, password))).andExpect(status().isNotFound());
boolean deleted = false;
for (int i = 0; i < KAFKA_RETRY; ++i) {
try {
MvcResult result = this.mockMvc.perform(delete(kafkaUrl + "/topic/bro").with(httpBasic(user, password)).with(csrf())).andReturn();
if (result.getResponse().getStatus() == 200) {
deleted = true;
break;
}
Thread.sleep(1000);
} catch (NestedServletException nse) {
Throwable t = nse.getRootCause();
if (t instanceof TopicAlreadyMarkedForDeletionException) {
continue;
} else {
throw nse;
}
} catch (Throwable t) {
throw t;
}
}
if (!deleted) {
throw new IllegalStateException("Unable to delete kafka topic \"bro\"");
}
}
use of org.springframework.test.web.servlet.MvcResult in project CzechIdMng by bcvsolutions.
the class IdentityContractSecurityTest method getWorkPositions.
@Test
public void getWorkPositions() {
SecurityMockMvcRequestPostProcessors.securityContext(null);
Exception ex = null;
int status = 0;
try {
status = getMockMvc().perform(get(BaseDtoController.BASE_PATH + "/identity-contracts")).andReturn().getResponse().getStatus();
} catch (Exception e) {
ex = e;
}
assertNull(ex);
assertEquals(403, status);
MvcResult mvcResult = null;
ex = null;
status = 0;
try {
mvcResult = getMockMvc().perform(get(BaseDtoController.BASE_PATH + "/identity-contracts").with(authentication(getAuthentication()))).andReturn();
} catch (Exception e) {
ex = e;
}
assertNull(ex);
assertNotNull(mvcResult);
assertEquals(200, mvcResult.getResponse().getStatus());
logout();
}
use of org.springframework.test.web.servlet.MvcResult in project CzechIdMng by bcvsolutions.
the class IdmLongRunningTaskItemControllerRestTest method getItem.
@Test
public void getItem() throws Exception {
SecurityMockMvcRequestPostProcessors.securityContext(null);
int status = getMockMvc().perform(get(BaseDtoController.BASE_PATH + PATH)).andReturn().getResponse().getStatus();
assertEquals(403, status);
MvcResult mvcResult = getMockMvc().perform(get(BaseDtoController.BASE_PATH + PATH).with(authentication(getAuthentication()))).andReturn();
assertNotNull(mvcResult);
assertEquals(200, mvcResult.getResponse().getStatus());
}
Aggregations