当前位置: 首页>>代码示例>>Java>>正文


Java ResultMatcher类代码示例

本文整理汇总了Java中org.springframework.test.web.servlet.ResultMatcher的典型用法代码示例。如果您正苦于以下问题:Java ResultMatcher类的具体用法?Java ResultMatcher怎么用?Java ResultMatcher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ResultMatcher类属于org.springframework.test.web.servlet包,在下文中一共展示了ResultMatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: attributeHasFieldErrorCode

import org.springframework.test.web.servlet.ResultMatcher; //导入依赖的package包/类
/**
 * Assert a field error code for a model attribute using a {@link org.hamcrest.Matcher}.
 * @since 4.1
 */
public <T> ResultMatcher attributeHasFieldErrorCode(final String name, final String fieldName,
		final Matcher<? super String> matcher) {

	return new ResultMatcher() {
		@Override
		public void match(MvcResult mvcResult) throws Exception {
			ModelAndView mav = getModelAndView(mvcResult);
			BindingResult result = getBindingResult(mav, name);
			assertTrue("No errors for attribute: [" + name + "]", result.hasErrors());

			boolean hasFieldErrors = result.hasFieldErrors(fieldName);
			assertTrue("No errors for field: [" + fieldName + "] of attribute [" + name + "]", hasFieldErrors);

			String code = result.getFieldError(fieldName).getCode();
			assertThat("Field name '" + fieldName + "' of attribute '" + name + "'", code, matcher);
		}
	};
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:ModelResultMatchers.java

示例2: assertIncorrectResponseHeaderValue

import org.springframework.test.web.servlet.ResultMatcher; //导入依赖的package包/类
private void assertIncorrectResponseHeaderValue(ResultMatcher resultMatcher, String unexpected) throws Exception {
	try {
		this.mockMvc.perform(get("/persons/1").header(IF_MODIFIED_SINCE, oneMinuteAgo))//
		.andExpect(resultMatcher);

		fail(EXPECTED_ASSERTION_ERROR_MSG);
	}
	catch (AssertionError e) {
		if (EXPECTED_ASSERTION_ERROR_MSG.equals(e.getMessage())) {
			throw e;
		}
		// [SPR-10659] Ensure that the header name is included in the message
		//
		// We don't use assertEquals() since we cannot control the formatting
		// produced by JUnit or Hamcrest.
		assertMessageContains(e, "Response header " + LAST_MODIFIED);
		assertMessageContains(e, unexpected);
		assertMessageContains(e, now);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:HeaderAssertionTests.java

示例3: attributehasGlobalErrors

import org.springframework.test.web.servlet.ResultMatcher; //导入依赖的package包/类
/**
 * Assert the given model attribute has error/s
 * @param attributeName
 * @return
 */
public ResultMatcher attributehasGlobalErrors(final String attributeName) {
	return result -> {
		ModelAndView mav = getModelAndView(result);
		BindingResult bindingResult = getBindingResult(mav, attributeName);
		assertTrue("No global binding errors for attribute: " + attributeName, bindingResult.hasGlobalErrors());
	};
}
 
开发者ID:Azanx,项目名称:Smart-Shopping,代码行数:13,代码来源:GlobalErrorModelResultMatchers.java

示例4: hasGlobalErrorCode

import org.springframework.test.web.servlet.ResultMatcher; //导入依赖的package包/类
public ResultMatcher hasGlobalErrorCode(final String attributeName, final String error) {
	return result -> {
		ModelAndView mav = getModelAndView(result);
		BindingResult bindingResult = getBindingResult(mav, attributeName);
		assertTrue("No global binding errors for attribute: " + attributeName, bindingResult.hasGlobalErrors());
		Optional<String> presentError = bindingResult.getGlobalErrors()//
			.stream()//
				.map(globalError -> globalError.getCode())//
					.filter(errorCode -> errorCode.equals(error))//
						.findAny();//
		assertTrue("No global error with code " + error + " found for attribute: " + attributeName, presentError.isPresent());
	};
}
 
开发者ID:Azanx,项目名称:Smart-Shopping,代码行数:14,代码来源:GlobalErrorModelResultMatchers.java

示例5: feedbackCreated

import org.springframework.test.web.servlet.ResultMatcher; //导入依赖的package包/类
private ResultMatcher feedbackCreated(FeedbackForm form) {
    return result -> {
        List<Feedback> feedbacks = feedbackRepository.findAllOfStudent(student);
        assertThat(feedbacks, hasSize(1));

        Feedback feedback = feedbacks.get(0);
        assertThat(feedback.getSuggestions(), equalTo(form.getSuggestions()));
        assertThat(feedback.getType(), equalTo(form.isLike() ? LIKE : DISLIKE));
    };
}
 
开发者ID:university-information-system,项目名称:uis,代码行数:11,代码来源:StudentFeedbackTests.java

示例6: resultHasUsersPage

import org.springframework.test.web.servlet.ResultMatcher; //导入依赖的package包/类
private ResultMatcher resultHasUsersPage(Page<UisUser> page) {
    return result -> {
        Page actualPage = (Page) result.getModelAndView().getModel().get("page");

        assertNotNull(actualPage);
        assertThat(actualPage.getNumber(), equalTo(page.getNumber()));
        assertThat(actualPage.getTotalElements(), equalTo(page.getTotalElements()));
        assertThat(actualPage.getSize(), equalTo(page.getSize()));
        assertThat(actualPage.getContent(), equalTo(page.getContent()));
    };
}
 
开发者ID:university-information-system,项目名称:uis,代码行数:12,代码来源:AdminUsersTests.java

示例7: orderFieldsAtPath

import org.springframework.test.web.servlet.ResultMatcher; //导入依赖的package包/类
private static ResultMatcher orderFieldsAtPath(final Order order, final String jsonPath) throws Exception {
    return allOf(
            jsonPath(jsonPath + ".id").value(order.getId()),
            jsonPath(jsonPath + ".deliveryAddress.firstName").value(order.getDeliveryAddress().getFirstName()),
            jsonPath(jsonPath + ".deliveryAddress.lastName").value(order.getDeliveryAddress().getLastName()),
            jsonPath(jsonPath + ".deliveryAddress.street").value(order.getDeliveryAddress().getStreet()),
            jsonPath(jsonPath + ".deliveryAddress.zip").value(order.getDeliveryAddress().getZip()),
            jsonPath(jsonPath + ".deliveryAddress.city").value(order.getDeliveryAddress().getCity()),
            jsonPath(jsonPath + ".deliveryPrice").value(order.calculateDeliveryPrice().getAmount()),
            orderItemsAtIndex(order.getItems(), jsonPath)
    );
}
 
开发者ID:britter,项目名称:bootify-testpyramid,代码行数:13,代码来源:OrderResponseMatchers.java

示例8: orderItemsAtIndex

import org.springframework.test.web.servlet.ResultMatcher; //导入依赖的package包/类
static ResultMatcher orderItemsAtIndex(List<OrderItem> items, String jsonPath) throws Exception {
    final List<ResultMatcher> matchers = new ArrayList<>();
    for (int i = 0; i < items.size(); i++) {
        matchers.add(orderItemAt(items.get(i), jsonPath + ".items[" + i + "]"));
    }
    return allOf(matchers);
}
 
开发者ID:britter,项目名称:bootify-testpyramid,代码行数:8,代码来源:OrderResponseMatchers.java

示例9: orderItemAt

import org.springframework.test.web.servlet.ResultMatcher; //导入依赖的package包/类
private static ResultMatcher orderItemAt(final OrderItem orderItem, final String jsonPath) throws Exception {
    return allOf(
            jsonPath(jsonPath + ".name").value(orderItem.getName()),
            jsonPath(jsonPath + ".description").value(orderItem.getDescription()),
            jsonPath(jsonPath + ".weight").value(orderItem.getWeight().getValue()),
            jsonPath(jsonPath + ".price").value(orderItem.getPrice().getAmount()),
            jsonPath(jsonPath + ".quantity").value(orderItem.getQuantity())
    );
}
 
开发者ID:britter,项目名称:bootify-testpyramid,代码行数:10,代码来源:OrderResponseMatchers.java

示例10: allOf

import org.springframework.test.web.servlet.ResultMatcher; //导入依赖的package包/类
private static ResultMatcher allOf(final ResultMatcher... matchers) throws Exception {
    return (result) -> {
        for (ResultMatcher m : matchers) {
            m.match(result);
        }
    };
}
 
开发者ID:britter,项目名称:bootify-testpyramid,代码行数:8,代码来源:OrderResponseMatchers.java

示例11: containsPagedResources

import org.springframework.test.web.servlet.ResultMatcher; //导入依赖的package包/类
/**
 * Tests if the response contains the JSON representation of a paging result with items of the
 * given type.
 *
 * @param clazz the class of the expected paged objects.
 * @param <T> the type of the expected paged objects.
 * @return ResultMatcher that performs the test described above.
 */
public static <T> ResultMatcher containsPagedResources(Class<T> clazz) {
  return result -> {
    String json = result.getResponse().getContentAsString();
    try {
      PagedResources<T> pagedResources = JsonHelper.fromPagedResourceJson(json, clazz);
      assertThat(pagedResources).isNotNull();
    } catch (Exception e) {
      throw new RuntimeException(
          String.format("expected JSON representation of class %s but found '%s'", clazz, json),
          e);
    }
  };
}
 
开发者ID:reflectoring,项目名称:infiniboard,代码行数:22,代码来源:ResultMatchers.java

示例12: value

import org.springframework.test.web.servlet.ResultMatcher; //导入依赖的package包/类
/**
 * Evaluate the JSON path expression against the response content and
 * assert that the result is equal to the supplied value.
 */
public ResultMatcher value(final Object expectedValue) {
	return new ResultMatcher() {
		@Override
		public void match(MvcResult result) throws Exception {
			jsonPathHelper.assertValue(result.getResponse().getContentAsString(), expectedValue);
		}
	};
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:JsonPathResultMatchers.java

示例13: doesNotExist

import org.springframework.test.web.servlet.ResultMatcher; //导入依赖的package包/类
/**
 * Evaluate the JSON path expression against the response content and
 * assert that a value does not exist at the given path.
 * <p>If the JSON path expression is not {@linkplain JsonPath#isDefinite
 * definite}, this method asserts that the value at the given path is
 * <em>empty</em>.
 */
public ResultMatcher doesNotExist() {
	return new ResultMatcher() {
		@Override
		public void match(MvcResult result) throws Exception {
			String content = result.getResponse().getContentAsString();
			jsonPathHelper.doesNotExist(content);
		}
	};
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:JsonPathResultMatchers.java

示例14: isMap

import org.springframework.test.web.servlet.ResultMatcher; //导入依赖的package包/类
/**
 * Evaluate the JSON path expression against the response content and
 * assert that the result is a {@link java.util.Map}.
 * @since 4.2.1
 */
public ResultMatcher isMap() {
	return new ResultMatcher() {
		@Override
		public void match(MvcResult result) throws Exception {
			String content = result.getResponse().getContentAsString();
			jsonPathHelper.assertValueIsMap(content);
		}
	};
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:15,代码来源:JsonPathResultMatchers.java

示例15: doesNotExist

import org.springframework.test.web.servlet.ResultMatcher; //导入依赖的package包/类
/**
 * Assert that the named response header does not exist.
 * @since 4.0
 */
public ResultMatcher doesNotExist(final String name) {
	return new ResultMatcher() {
		@Override
		public void match(MvcResult result) {
			assertTrue("Response should not contain header " + name, !result.getResponse().containsHeader(name));
		}
	};
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:HeaderResultMatchers.java


注:本文中的org.springframework.test.web.servlet.ResultMatcher类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。