Java源码示例:org.hamcrest.beans.HasPropertyWithValue
示例1
@Test
public void shouldRemoveStateSameSiteCookieAndFallbackCookie() {
Cookie cookie1 = new Cookie("com.auth0.state", "123456");
Cookie cookie2 = new Cookie("_com.auth0.state", "123456");
request.setCookies(cookie1, cookie2);
String state = TransientCookieStore.getState(request, response, true);
assertThat(state, is("123456"));
Cookie[] cookies = response.getCookies();
assertThat(cookies, is(notNullValue()));
List<Cookie> cookieList = Arrays.asList(cookies);
assertThat(cookieList.size(), is(2));
assertThat(Arrays.asList(cookies), everyItem(HasPropertyWithValue.hasProperty("value", is(""))));
assertThat(Arrays.asList(cookies), everyItem(HasPropertyWithValue.hasProperty("maxAge", is(0))));
}
示例2
@Test
public void shouldRemoveStateSameSiteCookie() {
Cookie cookie1 = new Cookie("com.auth0.state", "123456");
request.setCookies(cookie1);
String state = TransientCookieStore.getState(request, response, false);
assertThat(state, is("123456"));
Cookie[] cookies = response.getCookies();
assertThat(cookies, is(notNullValue()));
List<Cookie> cookieList = Arrays.asList(cookies);
assertThat(cookieList.size(), is(1));
assertThat(Arrays.asList(cookies), everyItem(HasPropertyWithValue.hasProperty("value", is(""))));
assertThat(Arrays.asList(cookies), everyItem(HasPropertyWithValue.hasProperty("maxAge", is(0))));
}
示例3
@Test
public void shouldRemoveStateFallbackCookie() {
Cookie cookie1 = new Cookie("_com.auth0.state", "123456");
request.setCookies(cookie1);
String state = TransientCookieStore.getState(request, response, true);
assertThat(state, is("123456"));
Cookie[] cookies = response.getCookies();
assertThat(cookies, is(notNullValue()));
List<Cookie> cookieList = Arrays.asList(cookies);
assertThat(cookieList.size(), is(1));
assertThat(Arrays.asList(cookies), everyItem(HasPropertyWithValue.hasProperty("value", is(""))));
assertThat(Arrays.asList(cookies), everyItem(HasPropertyWithValue.hasProperty("maxAge", is(0))));
}
示例4
@Test
public void shouldRemoveNonceSameSiteCookieAndFallbackCookie() {
Cookie cookie1 = new Cookie("com.auth0.nonce", "123456");
Cookie cookie2 = new Cookie("_com.auth0.nonce", "123456");
request.setCookies(cookie1, cookie2);
String state = TransientCookieStore.getNonce(request, response, true);
assertThat(state, is("123456"));
Cookie[] cookies = response.getCookies();
assertThat(cookies, is(notNullValue()));
List<Cookie> cookieList = Arrays.asList(cookies);
assertThat(cookieList.size(), is(2));
assertThat(Arrays.asList(cookies), everyItem(HasPropertyWithValue.hasProperty("value", is(""))));
assertThat(Arrays.asList(cookies), everyItem(HasPropertyWithValue.hasProperty("maxAge", is(0))));
}
示例5
@Test
public void shouldRemoveNonceSameSiteCookie() {
Cookie cookie1 = new Cookie("com.auth0.nonce", "123456");
request.setCookies(cookie1);
String state = TransientCookieStore.getNonce(request, response, true);
assertThat(state, is("123456"));
Cookie[] cookies = response.getCookies();
assertThat(cookies, is(notNullValue()));
List<Cookie> cookieList = Arrays.asList(cookies);
assertThat(cookieList.size(), is(1));
assertThat(Arrays.asList(cookies), everyItem(HasPropertyWithValue.hasProperty("value", is(""))));
assertThat(Arrays.asList(cookies), everyItem(HasPropertyWithValue.hasProperty("maxAge", is(0))));
}
示例6
@Test
public void shouldRemoveNonceFallbackCookie() {
Cookie cookie1 = new Cookie("_com.auth0.nonce", "123456");
request.setCookies(cookie1);
String state = TransientCookieStore.getNonce(request, response, true);
assertThat(state, is("123456"));
Cookie[] cookies = response.getCookies();
assertThat(cookies, is(notNullValue()));
List<Cookie> cookieList = Arrays.asList(cookies);
assertThat(cookieList.size(), is(1));
assertThat(Arrays.asList(cookies), everyItem(HasPropertyWithValue.hasProperty("value", is(""))));
assertThat(Arrays.asList(cookies), everyItem(HasPropertyWithValue.hasProperty("maxAge", is(0))));
}
示例7
@Test
public void serverErrorPageWithUUID() {
request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, mock(Exception.class));
assertNotNull(errorController.serverErrorPage(request, response));
verify(controllerUtils).buildErrorModelAndView(argThat(new HasPropertyWithValue<>("mainMessageCode", is(CustomErrorController.MESSAGE_CODE_INTERNAL_SERVER_ERROR_MAIN))));
verify(controllerUtils).buildErrorModelAndView(argThat(new HasPropertyWithValue<>("subMessageCode", is(CustomErrorController.MESSAGE_CODE_INTERNAL_SERVER_ERROR_SUB))));
}
示例8
@Test
public void testWriteUnlockNotifiesListeners() throws MessageCodecException {
ActiveInvokeContext<LockTransition> locker = newContext();
ActiveInvokeContext<LockTransition> waiter = newContext();
ClientDescriptor waiterDescriptor = () -> null;
when(waiter.getClientDescriptor()).thenReturn(waiterDescriptor);
entity.invokeActive(locker, LockMessaging.lock(WRITE));
entity.invokeActive(waiter, LockMessaging.lock(WRITE));
entity.invokeActive(locker, LockMessaging.unlock(WRITE));
verify(communicator).sendNoResponse(same(waiterDescriptor), argThat(
HasPropertyWithValue.<EntityResponse>hasProperty("released", is(true))));
}
示例9
@Test
public void testReadUnlockNotifiesListeners() throws MessageCodecException {
ActiveInvokeContext<LockTransition> locker = newContext();
ActiveInvokeContext<LockTransition> waiter = newContext();
ClientDescriptor waiterDescriptor = () -> null;
when(waiter.getClientDescriptor()).thenReturn(waiterDescriptor);
entity.invokeActive(locker, LockMessaging.lock(READ));
entity.invokeActive(waiter, LockMessaging.lock(WRITE));
entity.invokeActive(locker, LockMessaging.unlock(READ));
verify(communicator).sendNoResponse(same(waiterDescriptor), argThat(
HasPropertyWithValue.<EntityResponse>hasProperty("released", is(true))));
}
示例10
@Test
public void clientAuthenticationErrorPage() {
assertNotNull(errorController.clientAuthenticationErrorPage(request));
verify(controllerUtils).buildErrorModelAndView(argThat(new HasPropertyWithValue<>("mainMessageCode", is(HodErrorController.MESSAGE_CODE_CLIENT_AUTHENTICATION_ERROR_MAIN))));
}
示例11
@Test
public void authenticationErrorPage() {
assertNotNull(errorController.authenticationErrorPage(request, response));
verify(controllerUtils).buildErrorModelAndView(argThat(new HasPropertyWithValue<>("mainMessageCode", is(CustomErrorController.MESSAGE_CODE_AUTHENTICATION_ERROR_MAIN))));
}
示例12
@Test
public void serverErrorPageWithoutUUID() {
assertNotNull(errorController.serverErrorPage(request, response));
verify(controllerUtils).buildErrorModelAndView(argThat(new HasPropertyWithValue<>("mainMessageCode", is(CustomErrorController.MESSAGE_CODE_INTERNAL_SERVER_ERROR_MAIN))));
verify(controllerUtils).buildErrorModelAndView(argThat(new HasPropertyWithValue<>("subMessageCode", is(CustomErrorController.MESSAGE_CODE_INTERNAL_SERVER_ERROR_SUB))));
}
示例13
@Test
public void notFoundError() {
assertNotNull(errorController.notFoundError(request, response));
verify(controllerUtils).buildErrorModelAndView(argThat(new HasPropertyWithValue<>("mainMessageCode", is(CustomErrorController.MESSAGE_CODE_NOT_FOUND_MAIN))));
}