Ejemplo n.º 1
0
  public void shouldImmediatelyReturnIfNoRobotInfoFound() throws Exception {
    // given
    when(mockCombinatorStrategy.combine(testMethod)).thenReturn(Collections.<RobotInfo>emptyList());

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

    // then
    assertTrue("Interceptor should always return true", result);
    assertNull(
        "Request attribute should not be set",
        mockRequest.getAttribute(RepInterceptor.ROBOTS_REQUEST_ATTRIBUTE));
    assertFalse("No headers should be added", mockRequest.getHeaderNames().hasMoreElements());

    verify(mockCombinatorStrategy).combine(testMethod);
  }
Ejemplo n.º 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);
  }
Ejemplo n.º 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));
  }