當前位置: 首頁>>代碼示例>>Java>>正文


Java ResultActions類代碼示例

本文整理匯總了Java中org.springframework.test.web.servlet.ResultActions的典型用法代碼示例。如果您正苦於以下問題:Java ResultActions類的具體用法?Java ResultActions怎麽用?Java ResultActions使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ResultActions類屬於org.springframework.test.web.servlet包,在下文中一共展示了ResultActions類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testFindPrivilegeByName

import org.springframework.test.web.servlet.ResultActions; //導入依賴的package包/類
@Test
public void testFindPrivilegeByName() throws Exception {
	PrivilegeEntity dbResult = new PrivilegeEntity()
			.setId("123")
			.setName("12345")
			.setDescription("Description 12345");
	when(privilegeService.findPrivilegeByIdOrName("123")).thenReturn(dbResult);
	ResultActions resultActions = mockMvc.perform(get("/api/privileges/123").contentType(MediaType.APPLICATION_JSON))
			.andExpect(status().isOk())
			.andDo(document("privilege-read"));
	MockHttpServletResponse response = resultActions
			.andReturn()
			.getResponse();
	verify(privilegeService).findPrivilegeByIdOrName("123");
	assertThat(response.getContentAsByteArray())
			.isEqualTo(objectMapper.writeValueAsBytes(PrivilegeRestData.builder().fromPrivilegeEntity(dbResult).build()));
}
 
開發者ID:codenergic,項目名稱:theskeleton,代碼行數:18,代碼來源:PrivilegeRestControllerTest.java

示例2: http_get_hello_endpoint

import org.springframework.test.web.servlet.ResultActions; //導入依賴的package包/類
@Test
public void http_get_hello_endpoint() throws Exception {
	logger.info(Boot_Container_Test.TC_HEAD + "simple mvc test" );
	// mock does much validation.....
	ResultActions resultActions = mockMvc.perform(
			get( "/hello" )
					.accept( MediaType.TEXT_PLAIN ) );

	//
	String result = resultActions
			.andExpect( status().isOk() )
			.andExpect( content().contentType( "text/plain;charset=UTF-8" ) )
			.andReturn().getResponse().getContentAsString();
	logger.info( "result:\n" + result );

	assertThat( result )
			.startsWith( "Hello") ;
}
 
開發者ID:csap-platform,項目名稱:csap-core,代碼行數:19,代碼來源:Landing_Page.java

示例3: subjectZoneDoesNotExistException

import org.springframework.test.web.servlet.ResultActions; //導入依賴的package包/類
@Test
public void subjectZoneDoesNotExistException() throws Exception {
    // NOTE: To throw a ZoneDoesNotExistException, we must ensure that the AcsRequestContext in the
    //       SpringSecurityZoneResolver class returns a null ZoneEntity
    MockSecurityContext.mockSecurityContext(null);
    MockAcsRequestContext.mockAcsRequestContext();

    BaseSubject subject = JSON_UTILS.deserializeFromFile("controller-test/a-subject.json", BaseSubject.class);
    MockMvcContext putContext = TEST_UTILS.createWACWithCustomPUTRequestBuilder(this.wac,
            "zoneDoesNotExist", SUBJECT_BASE_URL + '/' + subject.getSubjectIdentifier());
    ResultActions resultActions = putContext.getMockMvc().perform(putContext.getBuilder()
            .contentType(MediaType.APPLICATION_JSON).content(OBJECT_MAPPER.writeValueAsString(subject)));
    resultActions.andExpect(status().isBadRequest());
    resultActions.andReturn().getResponse().getContentAsString().contentEquals("Zone not found");
    MockSecurityContext.mockSecurityContext(this.testZone);
    MockAcsRequestContext.mockAcsRequestContext();
}
 
開發者ID:eclipse,項目名稱:keti,代碼行數:18,代碼來源:SubjectPrivilegeManagementControllerIT.java

示例4: testFindRoles

import org.springframework.test.web.servlet.ResultActions; //導入依賴的package包/類
@Test
public void testFindRoles() throws Exception {
	RoleEntity dbResult = new RoleEntity()
			.setId("123")
			.setCode("12345")
			.setDescription("Description 12345");
	Page<RoleEntity> pageResponseBody = new PageImpl<>(Arrays.asList(dbResult));
	Page<RoleRestData> expectedResponseBody = new PageImpl<>(Arrays.asList(RoleRestData.builder()
			.fromRoleEntity(dbResult).build()));
	when(roleService.findRoles(anyString(), any())).thenReturn(pageResponseBody);
	ResultActions resultActions = mockMvc.perform(get("/api/roles")
				.contentType(MediaType.APPLICATION_JSON))
			.andExpect(status().isOk())
			.andDo(document("role-read-all"));
	MockHttpServletResponse response = resultActions
			.andReturn()
			.getResponse();
	verify(roleService).findRoles(anyString(), any());
	assertThat(response.getContentAsByteArray()).isEqualTo(objectMapper.writeValueAsBytes(expectedResponseBody));
}
 
開發者ID:codenergic,項目名稱:theskeleton,代碼行數:21,代碼來源:RoleRestControllerTest.java

示例5: testLoadHistogram

import org.springframework.test.web.servlet.ResultActions; //導入依賴的package包/類
private void testLoadHistogram(long fileId) throws Exception {
    TrackQuery histogramQuery = initTrackQuery(fileId);
    ResultActions actions = mvc().perform(post(URL_LOAD_GENES_HISTOGRAM).content(getObjectMapper()
                                                                       .writeValueAsString(histogramQuery))
                                .contentType(EXPECTED_CONTENT_TYPE))
        .andExpect(status().isOk())
        .andExpect(content().contentType(EXPECTED_CONTENT_TYPE))
        .andExpect(jsonPath(JPATH_PAYLOAD).exists())
        .andExpect(jsonPath(JPATH_STATUS).value(ResultStatus.OK.name()));
    actions.andDo(MockMvcResultHandlers.print());

    ResponseResult<Track<Wig>> histogram = getObjectMapper()
        .readValue(actions.andReturn().getResponse().getContentAsByteArray(),
                   getTypeFactory().constructParametrizedType(ResponseResult.class, ResponseResult.class,
                                                          getTypeFactory().constructParametrizedType(Track.class,
                                                                                                     Track.class,
                                                                                                     Wig.class)));

    Assert.assertFalse(histogram.getPayload().getBlocks().isEmpty());
    Assert.assertTrue(histogram.getPayload().getBlocks()
                      .stream()
                      .allMatch(b -> b.getStartIndex() != null && b.getEndIndex() != null && b.getValue() != null));
}
 
開發者ID:react-dev26,項目名稱:NGB-master,代碼行數:24,代碼來源:GeneControllerTest.java

示例6: policyZoneDoesNotExistException

import org.springframework.test.web.servlet.ResultActions; //導入依賴的package包/類
public void policyZoneDoesNotExistException() throws Exception {
    // NOTE: To throw a ZoneDoesNotExistException, we must ensure that the AcsRequestContext in the
    //       SpringSecurityZoneResolver class returns a null ZoneEntity
    MockSecurityContext.mockSecurityContext(null);
    MockAcsRequestContext.mockAcsRequestContext();
    String thisUri = VERSION + "/policy-set/" + this.policySet.getName();
    // create policy-set in first zone
    MockMvcContext putContext = this.testUtils.createWACWithCustomPUTRequestBuilder(this.wac,
            this.testZone.getSubdomain(), thisUri);
    ResultActions resultActions = putContext.getMockMvc().perform(
            putContext.getBuilder().contentType(MediaType.APPLICATION_JSON)
                    .content(this.objectWriter.writeValueAsString(this.policySet)));
    resultActions.andExpect(status().isUnprocessableEntity());
    resultActions.andReturn().getResponse().getContentAsString().contains("zone 'null' does not exist");

    MockSecurityContext.mockSecurityContext(this.testZone);
    MockAcsRequestContext.mockAcsRequestContext();
}
 
開發者ID:eclipse,項目名稱:keti,代碼行數:19,代碼來源:PolicyManagementControllerIT.java

示例7: testCreateSpeaker_conflict

import org.springframework.test.web.servlet.ResultActions; //導入依賴的package包/類
@Test
public void testCreateSpeaker_conflict() throws Exception {
    //Given
    Speaker josh = given.speaker("Josh Long").company("Pivotal").save();
    String requestBody = given.asJsonString(given.speakerDto("Josh Long").company("Pivotal").build());

    //When
    ResultActions action = mockMvc.perform(post("/speakers").content(requestBody));
    action.andDo(print());

    //Then
    assertEquals(1, speakerRepository.count());
    action.andExpect(status().isConflict());
    action.andExpect(jsonPath("content", is("Entity  Speaker with name 'Josh Long' already present in DB.")));
    action.andDo(document("{class-name}/{method-name}",
            responseFields(
                    fieldWithPath("content").description("Errors that were found during validation."))));
}
 
開發者ID:tsypuk,項目名稱:springrestdoc,代碼行數:19,代碼來源:SpeakerControllerTest.java

示例8: loadMy

import org.springframework.test.web.servlet.ResultActions; //導入依賴的package包/類
private List<ProjectVO> loadMy() throws Exception {
    ResultActions actions = mvc()
        .perform(get(URL_LOAD_MY_PROJECTS)
                     .contentType(EXPECTED_CONTENT_TYPE))
        .andExpect(MockMvcResultMatchers.status().isOk())
        .andExpect(MockMvcResultMatchers.content().contentType(EXPECTED_CONTENT_TYPE))
        .andExpect(MockMvcResultMatchers.jsonPath(JPATH_PAYLOAD).exists())
        .andExpect(MockMvcResultMatchers.jsonPath(JPATH_STATUS).value(ResultStatus.OK.name()));
    actions.andDo(MockMvcResultHandlers.print());

    ResponseResult<List<ProjectVO>> myProjects = getObjectMapper()
        .readValue(actions.andReturn().getResponse().getContentAsByteArray(),
                   getTypeFactory().constructParametrizedType(ResponseResult.class, ResponseResult.class,
                                                              getTypeFactory().constructParametrizedType(List.class,
                                                                                     List.class, ProjectVO.class)));

    Assert.assertNotNull(myProjects.getPayload());
    Assert.assertFalse(myProjects.getPayload().isEmpty());

    return myProjects.getPayload();
}
 
開發者ID:react-dev26,項目名稱:NGB-master,代碼行數:22,代碼來源:ProjectControllerTest.java

示例9: testFindUsersByUsernameStartingWith

import org.springframework.test.web.servlet.ResultActions; //導入依賴的package包/類
@Test
public void testFindUsersByUsernameStartingWith() throws Exception {
	final UserEntity user = new UserEntity()
			.setId("user123")
			.setEmail("[email protected]");
	final Page<UserEntity> users = new PageImpl<>(Arrays.asList(user));
	when(userAdminService.findUsersByUsernameStartingWith(eq("user123"), any())).thenReturn(users);
	ResultActions resultActions = mockMvc.perform(get("/api/users?username=user123")
				.contentType(MediaType.APPLICATION_JSON))
			.andExpect(status().isOk())
			.andDo(document("user-read-username-startingwith"));
	MockHttpServletResponse response = resultActions
			.andReturn()
			.getResponse();
	assertThat(response.getContentAsByteArray())
			.isEqualTo(objectMapper.writeValueAsBytes(
				users.map(u -> UserRestData.builder().fromUserEntity(u).build())));
	verify(userAdminService).findUsersByUsernameStartingWith(eq("user123"), any());
}
 
開發者ID:codenergic,項目名稱:theskeleton,代碼行數:20,代碼來源:UserRestControllerTest.java

示例10: testUpdateRole

import org.springframework.test.web.servlet.ResultActions; //導入依賴的package包/類
@Test
public void testUpdateRole() throws Exception {
	RoleEntity input = new RoleEntity()
			.setId("123")
			.setCode("12345")
			.setDescription("Description 12345");
	RoleEntity dbResult = new RoleEntity()
			.setId(UUID.randomUUID().toString())
			.setCode("12345")
			.setDescription("Description 12345");
	byte[] jsonInput = objectMapper.writeValueAsBytes(RoleRestData.builder().fromRoleEntity(input).build());
	when(roleService.updateRole(eq("123"), any())).thenReturn(dbResult);
	ResultActions resultActions = mockMvc.perform(put("/api/roles/123")
				.contentType(MediaType.APPLICATION_JSON)
				.content(jsonInput))
			.andExpect(status().isOk())
			.andDo(document("role-update"));
	MockHttpServletResponse response = resultActions
			.andReturn()
			.getResponse();
	verify(roleService).updateRole(eq("123"), any());
	assertThat(response.getContentAsByteArray())
			.isEqualTo(objectMapper.writeValueAsBytes(RoleRestData.builder().fromRoleEntity(dbResult).build()));
}
 
開發者ID:codenergic,項目名稱:theskeleton,代碼行數:25,代碼來源:RoleRestControllerTest.java

示例11: testEnableOrDisableUser

import org.springframework.test.web.servlet.ResultActions; //導入依賴的package包/類
@Test
public void testEnableOrDisableUser() throws Exception {
	final UserEntity user = new UserEntity()
			.setEnabled(true);
	when(userAdminService.enableOrDisableUser("user123", true)).thenReturn(user);
	ResultActions resultActions = mockMvc.perform(put("/api/users/user123/enable")
				.content("{\"enabled\": true}")
				.contentType(MediaType.APPLICATION_JSON))
			.andExpect(status().isOk())
			.andDo(document("user-enable"));
	MockHttpServletResponse response = resultActions
			.andReturn()
			.getResponse();
	assertThat(response.getContentAsByteArray())
			.isEqualTo(objectMapper.writeValueAsBytes(UserRestData.builder().fromUserEntity(user).build()));
	verify(userAdminService).enableOrDisableUser("user123", true);
}
 
開發者ID:codenergic,項目名稱:theskeleton,代碼行數:18,代碼來源:UserRestControllerTest.java

示例12: shouldPartialUpdateTodo

import org.springframework.test.web.servlet.ResultActions; //導入依賴的package包/類
@Test
public void shouldPartialUpdateTodo() throws Exception {
    // Given
    Todo todo = new Todo(1L, "title", "desc");
    given(todoService.getTodoById(1L)).willReturn(todo);
    HashMap<String, Object> updates = new HashMap<>();
    updates.put("title", "new title");
    updates.put("description", "new description");
    // When
    ResultActions result = this.mvc.perform(patch("/todos/1")
            .contentType(MediaType.APPLICATION_JSON_UTF8)
            .content(objectMapper.writeValueAsString(updates)));
    // Then
    result.andExpect(status().isNoContent())
            .andExpect(status().reason("Todo partial updated!"));
}
 
開發者ID:kchrusciel,項目名稱:Spring-Boot-Examples,代碼行數:17,代碼來源:TodoControllerTest.java

示例13: testFindUserByEmail

import org.springframework.test.web.servlet.ResultActions; //導入依賴的package包/類
@Test
public void testFindUserByEmail() throws Exception {
	final UserEntity user = new UserEntity()
			.setId("user123")
			.setEmail("[email protected]");
	when(userService.findUserByEmail("[email protected]")).thenReturn(user);
	ResultActions resultActions = mockMvc.perform(get("/api/users/[email protected]?email=true")
				.contentType(MediaType.APPLICATION_JSON))
			.andExpect(status().isOk())
			.andDo(document("user-read-email"));
	MockHttpServletResponse response = resultActions
			.andReturn()
			.getResponse();
	assertThat(response.getContentAsByteArray())
			.isEqualTo(objectMapper.writeValueAsBytes(UserRestData.builder().fromUserEntity(user).build()));
	verify(userService).findUserByEmail("[email protected]");
}
 
開發者ID:codenergic,項目名稱:theskeleton,代碼行數:18,代碼來源:UserRestControllerTest.java

示例14: testUpdateUserPassword

import org.springframework.test.web.servlet.ResultActions; //導入依賴的package包/類
@Test
public void testUpdateUserPassword() throws Exception {
	final UserEntity user = new UserEntity()
			.setId("user123");
	when(userAdminService.updateUserPassword(eq("user123"), any())).thenReturn(user);
	ResultActions resultActions = mockMvc.perform(put("/api/users/user123/password")
				.content("{\"username\": \"user123\"}")
				.contentType(MediaType.APPLICATION_JSON))
			.andExpect(status().isOk())
			.andDo(document("user-update-password"));
	MockHttpServletResponse response = resultActions
			.andReturn()
			.getResponse();
	assertThat(response.getContentAsByteArray())
			.isEqualTo(objectMapper.writeValueAsBytes(UserRestData.builder().fromUserEntity(user).build()));
	verify(userAdminService).updateUserPassword(eq("user123"), any());
}
 
開發者ID:codenergic,項目名稱:theskeleton,代碼行數:18,代碼來源:UserRestControllerTest.java

示例15: testRemovePrivilegeFromRole

import org.springframework.test.web.servlet.ResultActions; //導入依賴的package包/類
@Test
public void testRemovePrivilegeFromRole() throws Exception {
	final RoleEntity role = new RoleEntity()
			.setId("role123")
			.setCode("role123");
	when(roleService.removePrivilegeFromRole("role123", "privilege123")).thenReturn(role);
	ResultActions resultActions = mockMvc.perform(delete("/api/roles/role123/privileges")
				.content("{\"privilege\": \"privilege123\"}")
				.contentType(MediaType.APPLICATION_JSON))
			.andExpect(status().isOk())
			.andDo(document("role-privilege-delete"));
	MockHttpServletResponse response = resultActions
			.andReturn()
			.getResponse();
	verify(roleService).removePrivilegeFromRole("role123", "privilege123");
	assertThat(response.getContentAsByteArray())
			.isEqualTo(objectMapper.writeValueAsBytes(RoleRestData.builder().fromRoleEntity(role).build()));
}
 
開發者ID:codenergic,項目名稱:theskeleton,代碼行數:19,代碼來源:RoleRestControllerTest.java


注:本文中的org.springframework.test.web.servlet.ResultActions類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。