コード例 #1
0
  public void shouldNotExecuteInHeaderMode() throws Exception {
    // given
    ModelAndView modelAndView = new ModelAndView("test-view");
    interceptor.setMode(RepInterceptor.RepMode.HEADER);

    // when
    interceptor.postHandle(mockRequest, mockResponse, mockHandlerMethod, modelAndView);

    // then
    assertTrue("Model should be empty", modelAndView.getModel().isEmpty());
    verifyZeroInteractions(mockMetaFormatter, mockCombinatorStrategy);
  }
コード例 #2
0
  public void shouldWriteAttributeNotHeadersInMetaMode() throws Exception {
    // given
    interceptor.setMode(RepInterceptor.RepMode.META);
    when(mockCombinatorStrategy.combine(testMethod))
        .thenReturn(Lists.newArrayList(new RobotInfo("ua")));

    // when
    final boolean result = interceptor.preHandle(mockRequest, mockResponse, mockHandlerMethod);

    // then
    assertTrue("Interceptor should always return true", result);

    final Object attribute = mockRequest.getAttribute(RepInterceptor.ROBOTS_REQUEST_ATTRIBUTE);
    assertNotNull("Request attribute should be set", attribute);

    final List<String> headers = mockResponse.getHeaders(RepInterceptor.ROBOTS_HEADER_NAME);
    assertTrue("No headers should be written", headers.isEmpty());

    verify(mockCombinatorStrategy).combine(testMethod);
    verifyZeroInteractions(mockHeaderFormatter);
  }
コード例 #3
0
  public void shouldWriteAttributeAndHeadersInHeaderMode() throws Exception {
    // given
    interceptor.setMode(RepInterceptor.RepMode.HEADER);
    when(mockCombinatorStrategy.combine(testMethod))
        .thenReturn(Lists.newArrayList(new RobotInfo("ua")));

    // when
    final boolean result = interceptor.preHandle(mockRequest, mockResponse, mockHandlerMethod);

    // then
    assertTrue("Interceptor should always return true", result);

    final Object attribute = mockRequest.getAttribute(RepInterceptor.ROBOTS_REQUEST_ATTRIBUTE);
    assertNotNull("Request attribute should be set", attribute);

    final List<String> headers = mockResponse.getHeaders(RepInterceptor.ROBOTS_HEADER_NAME);
    assertEquals(1, headers.size());
    assertEquals("header-value", headers.get(0));

    verify(mockCombinatorStrategy).combine(testMethod);
    verify(mockHeaderFormatter).format(any(RobotInfo.class));
  }