View Javadoc

1   /*
2    * Copyright 2013-2014 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5    * the License. You may obtain a copy of the License at
6    *
7    * http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10   * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11   * specific language governing permissions and limitations under the License.
12   */
13  
14  package sparklr.common;
15  
16  import static org.junit.Assert.assertEquals;
17  import static org.junit.Assert.assertTrue;
18  
19  import org.junit.Test;
20  import org.springframework.http.HttpStatus;
21  import org.springframework.http.ResponseEntity;
22  
23  /**
24   * @author Dave Syer
25   *
26   */
27  public abstract class AbstractProtectedResourceTests extends AbstractIntegrationTests {
28  
29  	@Test
30  	public void testHomePageIsProtected() throws Exception {
31  		ResponseEntity<String> response = http.getForString("/");
32  		assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
33  		assertTrue("Wrong header: " + response.getHeaders(), response.getHeaders().getFirst("WWW-Authenticate")
34  				.startsWith("Bearer realm="));
35  	}
36  
37  	@Test
38  	public void testBeansResourceIsProtected() throws Exception {
39  		ResponseEntity<String> response = http.getForString("/admin/beans");
40  		assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
41  		assertTrue("Wrong header: " + response.getHeaders(), response.getHeaders().getFirst("WWW-Authenticate")
42  				.startsWith("Bearer realm="));
43  	}
44  
45  	@Test
46  	public void testHealthResourceIsOpen() throws Exception {
47  		assertEquals(HttpStatus.OK, http.getStatusCode("/admin/health"));
48  	}
49  
50  
51  }