Commit 788c9cf1b624432f0a94da5b9ba2b922bc618999
1 parent
51073806
Exists in
master
IN PROGRESS - issue FWK-119: Testes da extensão Servlet
https://demoiselle.atlassian.net/browse/FWK-119
Showing
2 changed files
with
18 additions
and
14 deletions
Show diff stats
impl/extension/servlet/src/test/java/security/SecurityServlet.java
| ... | ... | @@ -10,6 +10,7 @@ import javax.servlet.http.HttpServletResponse; |
| 10 | 10 | |
| 11 | 11 | import org.apache.http.HttpStatus; |
| 12 | 12 | |
| 13 | +import br.gov.frameworkdemoiselle.security.AuthenticationException; | |
| 13 | 14 | import br.gov.frameworkdemoiselle.security.Credentials; |
| 14 | 15 | import br.gov.frameworkdemoiselle.security.SecurityContext; |
| 15 | 16 | import br.gov.frameworkdemoiselle.util.Beans; |
| ... | ... | @@ -28,8 +29,14 @@ public class SecurityServlet extends HttpServlet { |
| 28 | 29 | credentials.setUsername(request.getParameter("username")); |
| 29 | 30 | credentials.setPassword(request.getParameter("password")); |
| 30 | 31 | |
| 31 | - Beans.getReference(SecurityContext.class).login(); | |
| 32 | + try { | |
| 33 | + Beans.getReference(SecurityContext.class).login(); | |
| 34 | + response.setStatus(HttpStatus.SC_OK); | |
| 35 | + } catch (AuthenticationException e) { | |
| 36 | + response.setStatus(HttpStatus.SC_UNAUTHORIZED); | |
| 37 | + } | |
| 32 | 38 | |
| 33 | - response.setStatus(HttpStatus.SC_OK); | |
| 39 | + | |
| 40 | + | |
| 34 | 41 | } |
| 35 | 42 | } | ... | ... |
impl/extension/servlet/src/test/java/security/SecurityTest.java
| ... | ... | @@ -50,16 +50,13 @@ public class SecurityTest { |
| 50 | 50 | assertEquals(HttpStatus.SC_OK, status); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | -// @Test | |
| 54 | -// public void loginFailed() throws ClientProtocolException, IOException { | |
| 55 | -// DefaultHttpClient client = new DefaultHttpClient(); | |
| 56 | -//// HttpGet get = new HttpGet(deploymentUrl + "/login"); | |
| 57 | -//// get.getParams().setParameter("username", "demoiselle"); | |
| 58 | -//// get.getParams().setParameter("password", "changeit"); | |
| 59 | -// HttpGet get = new HttpGet(deploymentUrl + "/login?username=demoiselle&password=wrongpass"); | |
| 60 | -// HttpResponse response = client.execute(get); | |
| 61 | -// | |
| 62 | -// int status = response.getStatusLine().getStatusCode(); | |
| 63 | -// assertEquals(HttpStatus.S, status); | |
| 64 | -// } | |
| 53 | + @Test | |
| 54 | + public void loginFailed() throws ClientProtocolException, IOException { | |
| 55 | + DefaultHttpClient client = new DefaultHttpClient(); | |
| 56 | + HttpGet get = new HttpGet(deploymentUrl + "/login?username=demoiselle&password=wrongpass"); | |
| 57 | + HttpResponse response = client.execute(get); | |
| 58 | + | |
| 59 | + int status = response.getStatusLine().getStatusCode(); | |
| 60 | + assertEquals(HttpStatus.SC_UNAUTHORIZED, status); | |
| 61 | + } | |
| 65 | 62 | } | ... | ... |