use of org.springframework.test.web.servlet.MvcResult in project TOSCAna by StuPro-TOSCAna.
the class TransformationControllerTest method getInputsTest2.
@Test
public void getInputsTest2() throws Exception {
preInitNonCreationTests();
// Set a SimpleProperty value
String inputKey = "secret_input";
String inputValue = "geheim";
csarService.getCsar(VALID_CSAR_NAME).get().getTransformation(VALID_PLATFORM_NAME).get().getInputs().set(inputKey, inputValue);
// Perform a request
MvcResult result = mvc.perform(get(INPUTS_VALID_URL)).andDo(print()).andExpect(status().is(200)).andExpect(content().contentType(DEFAULT_CHARSET_HAL_JSON)).andReturn();
// Check if only one value is set (the one that has been set above) and the others are not!
JSONArray obj = new JSONObject(result.getResponse().getContentAsString()).getJSONArray("inputs");
boolean valueFound = false;
boolean restNull = true;
for (int i = 0; i < obj.length(); i++) {
JSONObject content = obj.getJSONObject(i);
if (content.getString("key").equals(inputKey)) {
valueFound = content.getString("value").equals(inputValue);
} else {
restNull = restNull && (content.isNull("value") || content.getString("value").equals(INPUT_TEST_DEFAULT_VALUE));
}
}
assertTrue("Could not find valid value in property list", valueFound);
assertTrue("Not all other values in property list are null or equal to the default value", restNull);
}
use of org.springframework.test.web.servlet.MvcResult in project TOSCAna by StuPro-TOSCAna.
the class TransformationControllerTest method getInputsTest.
@Test
public void getInputsTest() throws Exception {
preInitNonCreationTests();
MvcResult result = mvc.perform(get(INPUTS_VALID_URL)).andDo(print()).andExpect(status().is(200)).andExpect(content().contentType(DEFAULT_CHARSET_HAL_JSON)).andExpect(jsonPath("$.inputs").isArray()).andExpect(jsonPath("$.inputs").isNotEmpty()).andExpect(jsonPath("$.inputs[0].key").isString()).andExpect(jsonPath("$.inputs[0].type").isString()).andExpect(jsonPath("$.inputs[0].description").isString()).andExpect(jsonPath("$.inputs[0].required").isBoolean()).andExpect(jsonPath("$.links[0].rel").value("self")).andExpect(jsonPath("$.links[0].href").value("http://localhost/api/csars/kubernetes-cluster/transformations/p-a/inputs")).andReturn();
MockHttpServletResponse response = result.getResponse();
String responseJson = new String(response.getContentAsByteArray());
String[] values = JsonPath.parse(responseJson).read("$.inputs[*].value", String[].class);
long nullCount = Arrays.asList(values).stream().filter(Objects::isNull).count();
long testCount = Arrays.asList(values).stream().filter(e -> e != null && e.equals(INPUT_TEST_DEFAULT_VALUE)).count();
assertEquals(8, nullCount);
assertEquals(1, testCount);
}
use of org.springframework.test.web.servlet.MvcResult in project TOSCAna by StuPro-TOSCAna.
the class TransformationControllerTest method transformationDetails.
// </editor-fold>
// <editor-fold desc="Transformation Details Test">
@Test
public void transformationDetails() throws Exception {
preInitNonCreationTests();
MvcResult result = mvc.perform(get(TRANSFORMATION_DETAILS_VALID_URL).accept(APPLICATION_HAL_JSON_MIME_TYPE)).andDo(print()).andExpect(status().is(200)).andExpect(content().contentType(DEFAULT_CHARSET_HAL_JSON)).andExpect(jsonPath("$.phases").isArray()).andExpect(jsonPath("$.phases").isEmpty()).andExpect(jsonPath("$.platform").value(VALID_PLATFORM_NAME)).andExpect(jsonPath("$.state").value("INPUT_REQUIRED")).andReturn();
JSONObject object = new JSONObject(result.getResponse().getContentAsString());
HALRelationUtils.validateRelations(object.getJSONArray("links"), getLinkRelationsForTransformationDetails(), VALID_CSAR_NAME, VALID_PLATFORM_NAME);
}
use of org.springframework.test.web.servlet.MvcResult in project open-kilda by telstra.
the class FlowControllerTest method pathFlow.
@Test
@WithMockUser(username = USERNAME, password = PASSWORD, roles = ROLE)
public void pathFlow() throws Exception {
MvcResult result = mockMvc.perform(get("/flows/path/{flow-id}", TestMessageMock.FLOW_ID).header(CORRELATION_ID, testCorrelationId()).contentType(APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andExpect(content().contentType(APPLICATION_JSON_UTF8_VALUE)).andReturn();
FlowPathPayload response = MAPPER.readValue(result.getResponse().getContentAsString(), FlowPathPayload.class);
assertEquals(TestMessageMock.flowPath, response);
}
use of org.springframework.test.web.servlet.MvcResult in project open-kilda by telstra.
the class FlowControllerTest method deleteFlows.
@Test
@WithMockUser(username = USERNAME, password = PASSWORD, roles = ROLE)
public void deleteFlows() throws Exception {
MvcResult result = mockMvc.perform(delete("/flows").header(CORRELATION_ID, testCorrelationId()).header(EXTRA_AUTH, System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(119)).contentType(APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andExpect(content().contentType(APPLICATION_JSON_UTF8_VALUE)).andReturn();
FlowPayload[] response = MAPPER.readValue(result.getResponse().getContentAsString(), FlowPayload[].class);
assertEquals(TestMessageMock.flow, response[0]);
}
Aggregations