/*
 * Copyright (c) 2015, Cloudera, Inc. All Rights Reserved.
 *
 * Cloudera, Inc. licenses this file to you under the Apache License,
 * Version 2.0 (the "License"). You may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * This software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for
 * the specific language governing permissions and limitations under the
 * License.
 */

package com.cloudera.oryx.lambda.serving;

import javax.servlet.RequestDispatcher;
import javax.ws.rs.core.Response;

import org.junit.Test;
import org.springframework.mock.web.MockHttpServletRequest;

import com.cloudera.oryx.common.OryxTest;

public final class ErrorResourceTest extends OryxTest {

  @Test
  public void testError() {
    MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.setAttribute(RequestDispatcher.ERROR_STATUS_CODE, 500);
    mockRequest.setAttribute(RequestDispatcher.ERROR_REQUEST_URI, "http://foo/bar");
    mockRequest.setAttribute(RequestDispatcher.ERROR_MESSAGE, "Something was wrong");
    mockRequest.setAttribute(RequestDispatcher.ERROR_EXCEPTION, new IllegalStateException());
    Response response  = new ErrorResource().errorHTML(mockRequest);
    assertEquals(500, response.getStatus());
    String responseBody = response.getEntity().toString();
    assertTrue(responseBody.contains("500"));
    assertTrue(responseBody.contains("http://foo/bar"));
    assertTrue(responseBody.contains("Something was wrong"));
    assertTrue(responseBody.contains("IllegalStateException"));
  }

}

@@ -1313,24 +1313,28 @@
 ));%0A    
+test
 Response
  respons
@@ -1329,21 +1329,147 @@
 onse
- response  = 
+(new ErrorResource().errorHTML(mockRequest), false);%0A    testResponse(new ErrorResource().errorText(mockRequest), false);%0A    testResponse(
 new 
@@ -1481,36 +1481,37 @@
 Resource().error
-HTML
+Empty
 (mockRequest);%0A 
@@ -1511,55 +1511,222 @@
 est)
-;%0A    assertEquals(500, response.getStatus());%0A
+, true);%0A  %7D%0A%0A  private static void testResponse(Response response, boolean assertEmpty) %7B%0A    assertEquals(500, response.getStatus());%0A    if (assertEmpty) %7B%0A      assertNull(response.getEntity());%0A    %7D else %7B%0A  
     
@@ -1780,24 +1780,26 @@
 ring();%0A    
+  
 assertTrue(r
@@ -1824,24 +1824,26 @@
 ns(%22500%22));%0A
+  
     assertTr
@@ -1883,32 +1883,34 @@
 foo/bar%22));%0A    
+  
 assertTrue(respo
@@ -1947,24 +1947,26 @@
 s wrong%22));%0A
+  
     assertTr
@@ -2017,15 +2017,21 @@
 ion%22));%0A
+    %7D%0A
   %7D%0A%0A%7D%0A

Improve ErrorResourceTest, per codecov