package demo;

import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.security.oauth2.provider.token.DefaultTokenServices;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.util.ReflectionTestUtils;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration
@IntegrationTest("server.port=0")
public class ApplicationTests {

	@Autowired
	@Qualifier("defaultAuthorizationServerTokenServices")
	private DefaultTokenServices tokenServices;

	@Test
	public void tokenStoreIsJwt() {
		assertTrue("Wrong token store type: " + tokenServices,
				ReflectionTestUtils.getField(tokenServices, "tokenStore") instanceof JwtTokenStore);
	}

}

@@ -8,16 +8,61 @@
  demo;%0A%0A
+import static org.junit.Assert.assertEquals;%0A
 import s
@@ -96,16 +96,16 @@
 rtTrue;%0A
-
 %0Aimport 
@@ -275,24 +275,83 @@
 .Qualifier;%0A
+import org.springframework.beans.factory.annotation.Value;%0A
 import org.s
@@ -453,32 +453,131 @@
 nConfiguration;%0A
+import org.springframework.boot.test.TestRestTemplate;%0Aimport org.springframework.http.HttpStatus;%0A
 import org.sprin
@@ -1104,16 +1104,68 @@
 ests %7B%0A%0A
+%09@Value(%22$%7Blocal.server.port%7D%22)%0A%09private int port;%0A%0A
 %09@Autowi
@@ -1366,16 +1366,16 @@
 rvices,%0A
-
 %09%09%09%09Refl
@@ -1459,10 +1459,483 @@
 e);%0A%09%7D%0A%0A
+%09@Test%0A%09public void tokenKeyEndpointProtected() %7B%0A%09%09assertEquals(HttpStatus.UNAUTHORIZED,%0A%09%09%09%09new TestRestTemplate().getForEntity(%22http://localhost:%22 + port + %22/oauth/token_key%22, String.class)%0A%09%09%09%09%09%09.getStatusCode());%0A%09%7D%0A%0A%09@Test%0A%09public void tokenKeyEndpointWithSecret() %7B%0A%09%09assertEquals(%0A%09%09%09%09HttpStatus.OK,%0A%09%09%09%09new TestRestTemplate(%22my-client-with-secret%22, %22secret%22).getForEntity(%0A%09%09%09%09%09%09%22http://localhost:%22 + port + %22/oauth/token_key%22, String.class).getStatusCode());%0A%09%7D%0A%0A
 %7D%0A

Add integration test for /oauth/token_key