Commit 51073806235dc0740966cd776f1444cfd756ddc4
1 parent
d8a665f5
Exists in
master
IN PROGRESS - issue FWK-119: Testes da extensão Servlet
https://demoiselle.atlassian.net/browse/FWK-119
Showing
4 changed files
with
37 additions
and
31 deletions
Show diff stats
impl/extension/servlet/src/test/java/security/SecurityServlet.java
| @@ -25,8 +25,8 @@ public class SecurityServlet extends HttpServlet { | @@ -25,8 +25,8 @@ public class SecurityServlet extends HttpServlet { | ||
| 25 | result = (result == null ? request.getHeader("authorization") : result); | 25 | result = (result == null ? request.getHeader("authorization") : result); |
| 26 | 26 | ||
| 27 | Credentials credentials = Beans.getReference(Credentials.class); | 27 | Credentials credentials = Beans.getReference(Credentials.class); |
| 28 | - credentials.setUsername("asdrubal"); | ||
| 29 | - credentials.setPassword("asdrubal"); | 28 | + credentials.setUsername(request.getParameter("username")); |
| 29 | + credentials.setPassword(request.getParameter("password")); | ||
| 30 | 30 | ||
| 31 | Beans.getReference(SecurityContext.class).login(); | 31 | Beans.getReference(SecurityContext.class).login(); |
| 32 | 32 |
impl/extension/servlet/src/test/java/security/SecurityTest.java
| @@ -10,6 +10,8 @@ import org.apache.http.HttpStatus; | @@ -10,6 +10,8 @@ import org.apache.http.HttpStatus; | ||
| 10 | import org.apache.http.client.ClientProtocolException; | 10 | import org.apache.http.client.ClientProtocolException; |
| 11 | import org.apache.http.client.methods.HttpGet; | 11 | import org.apache.http.client.methods.HttpGet; |
| 12 | import org.apache.http.impl.client.DefaultHttpClient; | 12 | import org.apache.http.impl.client.DefaultHttpClient; |
| 13 | +import org.apache.http.params.HttpParams; | ||
| 14 | +import org.apache.http.params.HttpParamsNames; | ||
| 13 | import org.jboss.arquillian.container.test.api.Deployment; | 15 | import org.jboss.arquillian.container.test.api.Deployment; |
| 14 | import org.jboss.arquillian.junit.Arquillian; | 16 | import org.jboss.arquillian.junit.Arquillian; |
| 15 | import org.jboss.arquillian.test.api.ArquillianResource; | 17 | import org.jboss.arquillian.test.api.ArquillianResource; |
| @@ -36,12 +38,28 @@ public class SecurityTest { | @@ -36,12 +38,28 @@ public class SecurityTest { | ||
| 36 | } | 38 | } |
| 37 | 39 | ||
| 38 | @Test | 40 | @Test |
| 39 | - public void login() throws ClientProtocolException, IOException { | 41 | + public void loginSucessfull() throws ClientProtocolException, IOException { |
| 40 | DefaultHttpClient client = new DefaultHttpClient(); | 42 | DefaultHttpClient client = new DefaultHttpClient(); |
| 41 | - HttpGet get = new HttpGet(deploymentUrl + "/login"); | 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"); | ||
| 42 | HttpResponse response = client.execute(get); | 47 | HttpResponse response = client.execute(get); |
| 43 | 48 | ||
| 44 | int status = response.getStatusLine().getStatusCode(); | 49 | int status = response.getStatusLine().getStatusCode(); |
| 45 | assertEquals(HttpStatus.SC_OK, status); | 50 | assertEquals(HttpStatus.SC_OK, status); |
| 46 | } | 51 | } |
| 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 | +// } | ||
| 47 | } | 65 | } |
impl/extension/servlet/src/test/resources/domain.xml
| @@ -7,40 +7,28 @@ | @@ -7,40 +7,28 @@ | ||
| 7 | </module> | 7 | </module> |
| 8 | </application> | 8 | </application> |
| 9 | </system-applications> | 9 | </system-applications> |
| 10 | - <applications> | ||
| 11 | - <application context-root="/AuthenticationPrj01" location="${com.sun.aas.instanceRootURI}/eclipseApps/AuthenticationPrj01/" name="AuthenticationPrj01" directory-deployed="true" object-type="user"> | ||
| 12 | - <property name="appLocation" value="${com.sun.aas.instanceRootURI}/eclipseApps/AuthenticationPrj01/"></property> | ||
| 13 | - <property name="defaultAppName" value="AuthenticationPrj01"></property> | ||
| 14 | - <module name="AuthenticationPrj01"> | ||
| 15 | - <engine sniffer="security"></engine> | ||
| 16 | - <engine sniffer="web"></engine> | ||
| 17 | - </module> | ||
| 18 | - </application> | ||
| 19 | - </applications> | 10 | + <applications></applications> |
| 20 | <resources> | 11 | <resources> |
| 21 | - <jdbc-connection-pool datasource-classname="org.apache.derby.jdbc.ClientXADataSource" res-type="javax.sql.XADataSource" name="luciano" transaction-isolation-level="serializable"> | ||
| 22 | - <property name="User" value="APP"></property> | ||
| 23 | - <property name="Password" value="APP"></property> | ||
| 24 | - <property name="ServerName" value="localhost"></property> | ||
| 25 | - <property name="PortNumber" value="1527"></property> | ||
| 26 | - <property name="DatabaseName" value="luciano"></property> | 12 | + <jdbc-resource pool-name="__TimerPool" jndi-name="jdbc/__TimerPool" object-type="system-admin"></jdbc-resource> |
| 13 | + <jdbc-resource pool-name="DerbyPool" jndi-name="jdbc/__default"></jdbc-resource> | ||
| 14 | + <jdbc-connection-pool datasource-classname="org.apache.derby.jdbc.EmbeddedXADataSource" res-type="javax.sql.XADataSource" name="__TimerPool"> | ||
| 15 | + <property name="databaseName" value="${com.sun.aas.instanceRoot}/lib/databases/ejbtimer"></property> | ||
| 16 | + <property name="connectionAttributes" value=";create=true"></property> | ||
| 27 | </jdbc-connection-pool> | 17 | </jdbc-connection-pool> |
| 28 | - <jdbc-resource pool-name="luciano" jndi-name="jdbc/luciano"></jdbc-resource> | ||
| 29 | - <jdbc-connection-pool driver-classname="" datasource-classname="org.postgresql.xa.PGXADataSource" res-type="javax.sql.XADataSource" description="" name="postgresql"> | ||
| 30 | - <property name="portNumber" value="5432"></property> | ||
| 31 | - <property name="databaseName" value="bd1"></property> | 18 | + <jdbc-connection-pool is-isolation-level-guaranteed="false" datasource-classname="org.apache.derby.jdbc.ClientDataSource" res-type="javax.sql.DataSource" name="DerbyPool"> |
| 19 | + <property name="PortNumber" value="1527"></property> | ||
| 20 | + <property name="Password" value="APP"></property> | ||
| 21 | + <property name="User" value="APP"></property> | ||
| 32 | <property name="serverName" value="localhost"></property> | 22 | <property name="serverName" value="localhost"></property> |
| 33 | - <property name="user" value="postgres"></property> | ||
| 34 | - <property name="password" value="postgres"></property> | 23 | + <property name="DatabaseName" value="sun-appserv-samples"></property> |
| 24 | + <property name="connectionAttributes" value=";create=true"></property> | ||
| 35 | </jdbc-connection-pool> | 25 | </jdbc-connection-pool> |
| 36 | - <jdbc-resource pool-name="postgresql" description="" jndi-name="jdbc/postgresql"></jdbc-resource> | ||
| 37 | </resources> | 26 | </resources> |
| 38 | <servers> | 27 | <servers> |
| 39 | <server name="server" config-ref="server-config"> | 28 | <server name="server" config-ref="server-config"> |
| 40 | - <resource-ref ref="jdbc/luciano"></resource-ref> | ||
| 41 | - <resource-ref ref="jdbc/postgresql"></resource-ref> | ||
| 42 | <application-ref ref="__admingui" virtual-servers="__asadmin"></application-ref> | 29 | <application-ref ref="__admingui" virtual-servers="__asadmin"></application-ref> |
| 43 | - <application-ref ref="AuthenticationPrj01" virtual-servers="server"></application-ref> | 30 | + <resource-ref ref="jdbc/__TimerPool"></resource-ref> |
| 31 | + <resource-ref ref="jdbc/__default"></resource-ref> | ||
| 44 | </server> | 32 | </server> |
| 45 | </servers> | 33 | </servers> |
| 46 | <nodes> | 34 | <nodes> |
impl/extension/servlet/src/test/resources/keyfile