/*
* implicit grant2
*/
public void testDoGet4() throws Exception {
ServletTester tester=new ServletTester();
tester.setContextPath("/test");
tester.addServlet(AuthorizationServlet2.class, "/authorize");
tester.setResourceBase("./web");
tester.addServlet(JspServlet.class, "*.jsp");
tester.start();
String queryParameter = "response_type=token&client_id=myKey&state=xyz&redirect_uri=http%3A%2F%2Flocalhost%2FCookieJar%2FCallback";
HttpTester request = new HttpTester();
HttpTester response = new HttpTester();
request.setMethod("GET");
request.setHeader("Host","server.example.com");
request.setURI("/test/authorize"+"?"+queryParameter);
request.setVersion("HTTP/1.1");
response.parse(tester.getResponses(request.generate()));
assertEquals(200,response.getStatus());
assertTrue(response.getContent().contains("<h3>\"CookieJar\" is trying to access your information.</h3>"));
assertTrue(response.getContent().contains("<form name=\"authZForm\" action=\"auth\" method=\"POST\">\n" +
" <input type=\"text\" name=\"userId\" value=\"\" size=\"20\" /><br>\n" +
" <input type=\"hidden\" name=\"redirect_uri\" value=\"http://localhost/CookieJar/Callback\"/>\n" +
" <input type=\"hidden\" name=\"client_id\" value=\"myKey\"/> \n" +
" <input type=\"submit\" name=\"Authorize\" value=\"Authorize\"/>\n" +
" </form>"));
request = new HttpTester();
response = new HttpTester();
String postParameter = "userId=yutaka&response_type=token&client_id=myKey&state=xyz"+
"&redirect_uri=http%3A%2F%2Flocalhost%2FCookieJar%2FCallback";
request.setMethod("POST");
request.setHeader("Host","server.example.com");
request.setURI("/test/authorize");
request.setVersion("HTTP/1.1");
request.setHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
request.setContent(postParameter);
response.parse(tester.getResponses(request.generate()));
assertEquals(302,response.getStatus());
Pattern pattern = Pattern.compile("http://localhost/CookieJar/Callback#access_token=.+&token_type=bearer&expires_in=3600&state=xyz");
Matcher matcher = pattern.matcher(response.getHeader("Location"));
assertTrue(matcher.matches());