858687888990919293
userId = System.getProperty("appengine.userId"); pw = System.getProperty("appengine.password"); } private void initServletEnvironment(URL url) throws IOException { ServletAnswer answer = getUnAuthServletAnswer(url, "env"); prodEnv = answer.isEnvironmentProd(); devEnv = !prodEnv; }
119120121122123124125
} else { pingUrl = new URL(url.toString() + "/" + servletMethod); } URLConnection conn = pingUrl.openConnection(); String answer = Utils.readFullyAndClose(conn.getInputStream()); return new ServletAnswer(answer); }
126127128129130131132
private ServletAnswer getAuthServletAnswer(GaeAuthClient client, URL url, String method) throws IOException { HttpResponse response = client.getUrl(url + "/user-service-helper?method=" + method); String resp = EntityUtils.toString(response.getEntity()); return new ServletAnswer(resp); }
156157158159160161162163
if (!isServletProd(url)) { return; } initAuthClient(url, userId, pw); ServletAnswer answer = getAuthServletAnswer(authClient, url, "getEmail"); Assert.assertEquals("UserId should be same as authenticated user:" + answer, userId, answer.getReturnVal()); }
167168169170171172173174
public void testGetEmailDev(@ArquillianResource URL url) throws Exception { if (!isServletDev(url)) { return; } ServletAnswer answer = getUnAuthServletAnswer(url, "getEmail"); Assert.assertEquals("user is null", answer.getReturnVal()); }
182183184185186187188189
if (!isServletProd(url)) { return; } initAuthClient(url, userId, pw); ServletAnswer answer = getAuthServletAnswer(authClient, url, "isUserLoggedIn"); Assert.assertEquals("User should be Logged in since the GaeAuthClient is initialized.", "true", answer.getReturnVal()); }
196197198199200201202203
public void testIsUserLoggedInDev(@ArquillianResource URL url) throws Exception { if (!isServletDev(url)) { return; } ServletAnswer answer = getUnAuthServletAnswer(url, "isUserLoggedIn"); Assert.assertEquals("false", answer.getReturnVal()); }
208209210211212213214215216
if (!isServletProd(url)) { return; } initAuthClient(url, userId, pw); ServletAnswer answer = getAuthServletAnswer(authClient, url, "isUserAdmin"); Assert.assertEquals("User should be logged in and admin.", "true", answer.getReturnVal()); }
220221222223224225226227
public void testIsUserAdminInDev(@ArquillianResource URL url) throws Exception { if (!isServletDev(url)) { return; } ServletAnswer answer = getUnAuthServletAnswer(url, "isUserLoggedIn"); Assert.assertEquals("false", answer.getReturnVal()); }