Commit ceb0887ed442006d52440d9f6fc9d7d183847178

Authored by Cleverson Sacramento
1 parent 788c9cf1
Exists in master

IN PROGRESS - issue FWK-119: Testes da extensão Servlet

https://demoiselle.atlassian.net/browse/FWK-119
impl/extension/servlet/src/test/java/security/SecurityTest.java
@@ -3,15 +3,15 @@ package security; @@ -3,15 +3,15 @@ package security;
3 import static org.junit.Assert.assertEquals; 3 import static org.junit.Assert.assertEquals;
4 4
5 import java.io.IOException; 5 import java.io.IOException;
  6 +import java.net.URISyntaxException;
6 import java.net.URL; 7 import java.net.URL;
7 8
8 import org.apache.http.HttpResponse; 9 import org.apache.http.HttpResponse;
9 import org.apache.http.HttpStatus; 10 import org.apache.http.HttpStatus;
10 import org.apache.http.client.ClientProtocolException; 11 import org.apache.http.client.ClientProtocolException;
11 import org.apache.http.client.methods.HttpGet; 12 import org.apache.http.client.methods.HttpGet;
  13 +import org.apache.http.client.utils.URIBuilder;
12 import org.apache.http.impl.client.DefaultHttpClient; 14 import org.apache.http.impl.client.DefaultHttpClient;
13 -import org.apache.http.params.HttpParams;  
14 -import org.apache.http.params.HttpParamsNames;  
15 import org.jboss.arquillian.container.test.api.Deployment; 15 import org.jboss.arquillian.container.test.api.Deployment;
16 import org.jboss.arquillian.junit.Arquillian; 16 import org.jboss.arquillian.junit.Arquillian;
17 import org.jboss.arquillian.test.api.ArquillianResource; 17 import org.jboss.arquillian.test.api.ArquillianResource;
@@ -38,24 +38,24 @@ public class SecurityTest { @@ -38,24 +38,24 @@ public class SecurityTest {
38 } 38 }
39 39
40 @Test 40 @Test
41 - public void loginSucessfull() throws ClientProtocolException, IOException {  
42 - DefaultHttpClient client = new DefaultHttpClient();  
43 -// HttpGet get = new HttpGet(deploymentUrl + "/login");  
44 -// get.getParams().setParameter("username", "demoiselle");  
45 -// get.getParams().setParameter("password", "changeit");  
46 - HttpGet get = new HttpGet(deploymentUrl + "/login?username=demoiselle&password=changeit");  
47 - HttpResponse response = client.execute(get); 41 + public void loginSucessfull() throws ClientProtocolException, IOException, URISyntaxException {
  42 + URIBuilder uriBuilder = new URIBuilder(deploymentUrl + "/login");
  43 + uriBuilder.setParameter("username", "demoiselle");
  44 + uriBuilder.setParameter("password", "changeit");
  45 +
  46 + HttpGet httpGet = new HttpGet(uriBuilder.build());
  47 + HttpResponse response = new DefaultHttpClient().execute(httpGet);
48 48
49 int status = response.getStatusLine().getStatusCode(); 49 int status = response.getStatusLine().getStatusCode();
50 assertEquals(HttpStatus.SC_OK, status); 50 assertEquals(HttpStatus.SC_OK, status);
51 } 51 }
52 - 52 +
53 @Test 53 @Test
54 public void loginFailed() throws ClientProtocolException, IOException { 54 public void loginFailed() throws ClientProtocolException, IOException {
55 DefaultHttpClient client = new DefaultHttpClient(); 55 DefaultHttpClient client = new DefaultHttpClient();
56 HttpGet get = new HttpGet(deploymentUrl + "/login?username=demoiselle&password=wrongpass"); 56 HttpGet get = new HttpGet(deploymentUrl + "/login?username=demoiselle&password=wrongpass");
57 HttpResponse response = client.execute(get); 57 HttpResponse response = client.execute(get);
58 - 58 +
59 int status = response.getStatusLine().getStatusCode(); 59 int status = response.getStatusLine().getStatusCode();
60 assertEquals(HttpStatus.SC_UNAUTHORIZED, status); 60 assertEquals(HttpStatus.SC_UNAUTHORIZED, status);
61 } 61 }