Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functional tests for uncovered DeltaSpike quickstarts #5

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions deltaspike-authorization/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,29 @@ Undeploy the Archive

mvn jboss-as:undeploy

Run the Arquillian Functional Tests
-----------------------------------

This quickstart provides Arquillian functional tests. They are located under the directory "functional-tests". Functional tests verify that your application behaves correctly from the user's point of view - simulating clicking around the page as a normal user would do.

To run these tests, you must build the main project as described above.

1. Open a command line and navigate to the root directory of this quickstart.
2. Build the quickstart WAR using the following command:

mvn clean package

3. Navigate to the functional-tests/ directory in this quickstart.
4. If you have a running instance of the JBoss Server, as described above, run the remote tests by typing the following command:

mvn clean verify -Parq-jbossas-remote

5. If you prefer to run the functional tests using managed instance of the JBoss server, meaning the tests will start the server for you, type the following command:

_NOTE: For this to work, Arquillian needs to know the location of the JBoss server. This can be declared through the `JBOSS_HOME` environment variable or the `jbossHome` property in `arquillian.xml`. See [Run the Arquillian Tests](../README.md#run-the-arquillian-tests) for complete instructions and additional options._

mvn clean verify -Parq-jbossas-managed


Run the Quickstart in JBoss Developer Studio or Eclipse
-------------------------------------
Expand Down
128 changes: 128 additions & 0 deletions deltaspike-authorization/functional-tests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
JBoss, Home of Professional Open Source
Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
contributors by the @authors tag. See the copyright.txt in the
distribution for a full listing of individual contributors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.jboss.as.quickstarts.wfk</groupId>
<artifactId>deltaspike-authorization-test-webdriver</artifactId>
<version>2.4.0-build-SNAPSHOT</version>
<name>JBoss WFK Quickstart: deltaspike-authorization test via WebDriver with Arquillian</name>

<url>http://jboss.org/jbossas</url>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<distribution>repo</distribution>
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
</license>
</licenses>

<properties>
<!-- Explicitly declaring the source encoding eliminates the following
message: -->
<!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
resources, i.e. build is platform dependent! -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<!-- JBoss dependency versions -->
<version.jboss.maven.plugin>7.4.Final</version.jboss.maven.plugin>

<!-- Define the version of the JBoss BOMs we want to import. The JBoss BOMs specify tested stacks. -->
<version.jboss.bom.wfk>2.4.0-build-5</version.jboss.bom.wfk>

<!-- other plugin versions -->
<version.surefire.plugin>2.10</version.surefire.plugin>

<!-- maven-compiler-plugin -->
<maven.compiler.target>1.6</maven.compiler.target>
<maven.compiler.source>1.6</maven.compiler.source>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${version.surefire.plugin}</version>
</plugin>
</plugins>
</build>

<dependencyManagement>
<dependencies>
<!-- Arquillian dependency -->
<dependency>
<groupId>org.jboss.bom.wfk</groupId>
<artifactId>jboss-javaee-6.0-with-tools</artifactId>
<version>${version.jboss.bom.wfk}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>


<dependencies>
<dependency>
<groupId>org.jboss.arquillian.graphene</groupId>
<artifactId>graphene-webdriver</artifactId>
<scope>test</scope>
<type>pom</type>
</dependency>

<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
<profile>
<!-- Profile that executes tests in managed JBoss AS instance. -->
<id>arq-jbossas-managed</id>
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-container-managed</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</profile>

<profile>
<!-- Profile that executes tests in remote JBoss AS instance. -->
<id>arq-jbossas-remote</id>
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-container-remote</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.wfk.test.deltaspike.authorization;

import java.io.File;
import java.net.URL;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.drone.api.annotation.Drone;
import static org.jboss.arquillian.graphene.Graphene.guardHttp;
import org.jboss.arquillian.graphene.findby.FindByJQuery;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.After;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

/**
* Tests DeltaSpike authorization
*
* @author Ron Smeral
*/
@RunAsClient
@RunWith(Arquillian.class)
public class AuthorizationTest {

private static final String USERNAME = "quickstartUser";
private static final String PASSWORD = "quickstartPwd1!";
private static final String LOGIN_PATH = "index.html";
private static final String WELCOME_PATH = "welcome.jsf";
private static final String WELCOME_HEADER = "Welcome to the restricted page!";
private static final String EMPLOYEE_TEXT = "You executed a @EmployeeAllowed method";
private static final String ADMIN_TEXT = "AccessDeniedException";

@FindByJQuery("input[name='j_username']")
WebElement LOGIN_USERNAME;

@FindByJQuery("input[name='j_password']")
WebElement LOGIN_PASSWORD;

@FindByJQuery("input[value='Login']")
WebElement LOGIN_BUTTON;

@FindByJQuery("input[value='Logout']")
WebElement LOGOUT_BUTTON;

@FindByJQuery("input[value='Employees only Method']")
WebElement EMPLOYEES_BUTTON;

@FindByJQuery("input[value='Admins only Method']")
WebElement ADMIN_BUTTON;

private static final String TEST_DEPLOYMENT = "../target/jboss-deltaspike-authorization.war";

@Deployment(testable = false)
public static WebArchive deployment() {
return ShrinkWrap.createFromZipFile(WebArchive.class, new File(TEST_DEPLOYMENT));
}

@Drone
WebDriver driver;

@ArquillianResource
URL contextPath;

@Before
public void beforeTest() {
login();
}

@After
public void afterTest() {
logout();
}

@Test
public void loginTest() {
assertTrue(driver.getPageSource().contains(WELCOME_HEADER));
}

@Test
public void employeeTest() {
guardHttp(EMPLOYEES_BUTTON).click();
assertTrue(driver.getPageSource().contains(EMPLOYEE_TEXT));
}

@Test
public void adminTest() {
guardHttp(ADMIN_BUTTON).click();
assertTrue(driver.getPageSource().contains(ADMIN_TEXT));
}

private void login() {
driver.navigate().to(contextPath + LOGIN_PATH);
LOGIN_USERNAME.clear();
LOGIN_USERNAME.sendKeys(USERNAME);

LOGIN_PASSWORD.clear();
LOGIN_PASSWORD.sendKeys(PASSWORD);

guardHttp(LOGIN_BUTTON).click();
}

private void logout() {
driver.navigate().to(contextPath + WELCOME_PATH);
guardHttp(LOGOUT_BUTTON).click();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0"?>
<!--
JBoss, Home of Professional Open Source
Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
contributors by the @authors tag. See the copyright.txt in the
distribution for a full listing of individual contributors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://jboss.org/schema/arquillian"
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">

<!-- Example configuration for a remote JBoss Enterprise Application Platform 6 or AS 7 instance -->
<container qualifier="jboss" default="true">
<!-- By default, Arquillian will use the JBOSS_HOME environment variable.
Alternatively, the configuration below can be uncommented. -->
<!--
<configuration>
<property name="jbossHome">/path/to/jboss/as</property>
</configuration>
-->
</container>

<!-- WebDriver extension -->
<extension qualifier="webdriver">
<!-- By default, the browser you are going to use for your tests is set to Firefox. -->
<property name="browser">firefox</property>
<!-- Uncomment this line in order to specify where your Firefox binary is located, WebDriver
will use the default one in your system otherwise. These tests are verified to be functioning
with Firefox 23. -->
<!--
<property name="firefox_binary">/path/to/firefox/binary</property>
-->
</extension>

</arquillian>
23 changes: 23 additions & 0 deletions deltaspike-beanmanagerprovider/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,29 @@ Undeploy the Archive

mvn jboss-as:undeploy

Run the Arquillian Functional Tests
-----------------------------------

This quickstart provides Arquillian functional tests. They are located under the directory "functional-tests". Functional tests verify that your application behaves correctly from the user's point of view - simulating clicking around the page as a normal user would do.

To run these tests, you must build the main project as described above.

1. Open a command line and navigate to the root directory of this quickstart.
2. Build the quickstart WAR using the following command:

mvn clean package

3. Navigate to the functional-tests/ directory in this quickstart.
4. If you have a running instance of the JBoss Server, as described above, run the remote tests by typing the following command:

mvn clean verify -Parq-jbossas-remote

5. If you prefer to run the functional tests using managed instance of the JBoss server, meaning the tests will start the server for you, type the following command:

_NOTE: For this to work, Arquillian needs to know the location of the JBoss server. This can be declared through the `JBOSS_HOME` environment variable or the `jbossHome` property in `arquillian.xml`. See [Run the Arquillian Tests](../README.md#run-the-arquillian-tests) for complete instructions and additional options._

mvn clean verify -Parq-jbossas-managed

Run the Quickstart in JBoss Developer Studio or Eclipse
-------------------------------------

Expand Down
Loading