use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class ProfileTypeControllerIntegrationTest method executeProfileTypePost.
private ResultActions executeProfileTypePost(String fileName, String accessToken, ResultMatcher expected) throws Exception {
InputStream isJsonPostValid = this.getClass().getResourceAsStream(fileName);
String jsonPostValid = FileTextReader.getText(isJsonPostValid);
ResultActions result = mockMvc.perform(post("/profileTypes").content(jsonPostValid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result.andExpect(expected);
return result;
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class ProfileTypeControllerIntegrationTest method testAddUpdateUserProfileType_1.
@Test
public void testAddUpdateUserProfileType_1() throws Exception {
try {
Assert.assertNull(this.userProfileManager.getEntityPrototype("AAA"));
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
this.executeProfileTypePost("1_POST_valid.json", accessToken, status().isOk());
UserProfile addedType = (UserProfile) this.userProfileManager.getEntityPrototype("AAA");
Assert.assertNotNull(addedType);
Assert.assertEquals("Profile Type AAA", addedType.getTypeDescription());
Assert.assertEquals(1, addedType.getAttributeList().size());
this.executeProfileTypePut("1_PUT_invalid.json", "AAA", accessToken, status().isBadRequest());
this.executeProfileTypePut("1_PUT_valid.json", "AAA", accessToken, status().isOk());
addedType = (UserProfile) this.userProfileManager.getEntityPrototype("AAA");
Assert.assertEquals("Profile Type AAA Modified", addedType.getTypeDescription());
Assert.assertEquals(2, addedType.getAttributeList().size());
ResultActions result4 = mockMvc.perform(delete("/profileTypes/{profileTypeCode}", new Object[] { "AAA" }).header("Authorization", "Bearer " + accessToken));
result4.andExpect(status().isOk());
Assert.assertNull(this.userProfileManager.getEntityPrototype("AAA"));
} finally {
if (null != this.userProfileManager.getEntityPrototype("AAA")) {
((IEntityTypesConfigurer) this.userProfileManager).removeEntityPrototype("AAA");
}
}
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class ProfileTypeControllerIntegrationTest method testGetUserProfileAttribute.
// ------------------------------------
@Test
public void testGetUserProfileAttribute() throws Exception {
try {
Assert.assertNull(this.userProfileManager.getEntityPrototype("TST"));
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
this.executeProfileTypePost("2_POST_valid.json", accessToken, status().isOk());
ResultActions result1 = mockMvc.perform(get("/profileTypes/{profileTypeCode}/attribute/{attributeCode}", new Object[] { "XXX", "TextAttribute" }).header("Authorization", "Bearer " + accessToken));
result1.andExpect(status().isNotFound());
result1.andExpect(jsonPath("$.payload", Matchers.hasSize(0)));
result1.andExpect(jsonPath("$.errors", Matchers.hasSize(1)));
result1.andExpect(jsonPath("$.metaData.size()", is(0)));
ResultActions result2 = mockMvc.perform(get("/profileTypes/{profileTypeCode}/attribute/{attributeCode}", new Object[] { "TST", "WrongCpde" }).header("Authorization", "Bearer " + accessToken));
result2.andExpect(status().isNotFound());
result2.andExpect(jsonPath("$.payload", Matchers.hasSize(0)));
result2.andExpect(jsonPath("$.errors", Matchers.hasSize(1)));
result2.andExpect(jsonPath("$.metaData.size()", is(0)));
ResultActions result3 = mockMvc.perform(get("/profileTypes/{profileTypeCode}/attribute/{attributeCode}", new Object[] { "TST", "TextAttribute" }).header("Authorization", "Bearer " + accessToken));
result3.andExpect(status().isOk());
result3.andExpect(jsonPath("$.payload.code", is("TextAttribute")));
result3.andExpect(jsonPath("$.payload.type", is("Text")));
result3.andExpect(jsonPath("$.errors", Matchers.hasSize(0)));
result3.andExpect(jsonPath("$.metaData.size()", is(1)));
result3.andExpect(jsonPath("$.metaData.profileTypeCode", is("TST")));
} finally {
if (null != this.userProfileManager.getEntityPrototype("TST")) {
((IEntityTypesConfigurer) this.userProfileManager).removeEntityPrototype("TST");
}
}
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class UserProfileControllerIntegrationTest method testGetInvalidUserProfileType.
@Test
public void testGetInvalidUserProfileType() throws Exception {
String accessToken = this.createAccessToken();
ResultActions result = mockMvc.perform(get("/userProfiles/{username}", new Object[] { "xxxxx" }).header("Authorization", "Bearer " + accessToken));
System.out.println(result.andReturn().getResponse().getContentAsString());
result.andExpect(status().isNotFound());
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class UserProfileControllerIntegrationTest method executeProfileGet.
private ResultActions executeProfileGet(String username, String accessToken, ResultMatcher expected) throws Exception {
ResultActions result = mockMvc.perform(get("/userProfiles/{username}", new Object[] { username }).header("Authorization", "Bearer " + accessToken));
result.andExpect(expected);
return result;
}
Aggregations