Skip to content
This repository has been archived by the owner on Nov 17, 2017. It is now read-only.

Commit

Permalink
Merge functional tests for pickList + the base for ftest setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Fryc committed Mar 13, 2013
2 parents f20001c + fe7497f commit 5f58550
Show file tree
Hide file tree
Showing 16 changed files with 1,258 additions and 13 deletions.
4 changes: 4 additions & 0 deletions bootstrap/demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Running Integration Tests
-------------------------

See "How To Run Fundamental Tests":https://github.com/richfaces/build/blob/develop/fundamental-tests.md
22 changes: 16 additions & 6 deletions bootstrap/demo/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand All @@ -21,12 +21,10 @@
<dependency>
<groupId>org.richfaces.ui</groupId>
<artifactId>richfaces-components-ui</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.richfaces.core</groupId>
<artifactId>richfaces-core-impl</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.richfaces.sandbox.ui.bootstrap</groupId>
Expand All @@ -36,7 +34,6 @@
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-web-6.0</artifactId>
<version>3.0.1.Final</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
Expand All @@ -46,15 +43,28 @@
<scope>provided</scope>
</dependency>

<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<finalName>bootstrap-demo</finalName>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
Expand Down Expand Up @@ -92,13 +102,13 @@
</plugins>
</build>
</profile>

<profile>
<id>production</id>
<properties>
<javax.faces.PROJECT_STAGE>Production</javax.faces.PROJECT_STAGE>
</properties>
</profile>

</profiles>
</project>


Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* JBoss, Home of Professional Open Source
* Copyright 2012, Red Hat, Inc. 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.richfaces.bootstrap.demo.ftest;

import java.io.File;
import java.net.URL;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.importer.ZipImporter;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.runner.RunWith;

/**
* @author <a href="mailto:jstefek@redhat.com">Jiri Stefek</a>
*/
@RunWith(Arquillian.class)
public class AbstractBootsrapDemoTest {

@ArquillianResource
protected URL deploymentURL;

@Deployment(testable = false)
public static WebArchive createTestArchive() {
// TODO doesn't work
// return ShrinkWrap.create(MavenImporter.class, "bootstrap-demo.war").loadPomFromFile("pom.xml").importBuildOutput()
// .as(WebArchive.class);
return ShrinkWrap.create(ZipImporter.class, "bootstrap-demo.war").importFrom(new File("target/bootstrap-demo.war"))
.as(WebArchive.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* JBoss, Home of Professional Open Source
* Copyright 2012, Red Hat, Inc. 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.richfaces.bootstrap.demo.ftest.webdriver;

import java.net.MalformedURLException;
import java.net.URL;
import org.jboss.arquillian.drone.api.annotation.Drone;
import org.junit.Before;
import org.openqa.selenium.WebDriver;
import org.richfaces.bootstrap.demo.ftest.AbstractBootsrapDemoTest;

/**
* @author <a href="mailto:jstefek@redhat.com">Jiri Stefek</a>
*/
public abstract class AbstractWebDriverTest extends AbstractBootsrapDemoTest {

private static final String PREFIX_TEST_URL = "component/";
//
@Drone
protected WebDriver driver;

abstract protected String getComponentName();

private URL getPathURL() throws MalformedURLException {
return new URL(deploymentURL, getTestURL());
}

private String getTestURL() {
return PREFIX_TEST_URL + getComponentName();
}

@Before
public void initialize() throws MalformedURLException {
initializePageUrl();
}

public void initializePageUrl() throws MalformedURLException {
driver.get(getPathURL().toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
/**
* JBoss, Home of Professional Open Source
* Copyright 2012, Red Hat, Inc. 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.richfaces.bootstrap.demo.ftest.webdriver.pickList;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.openqa.selenium.support.FindBy;
import org.richfaces.bootstrap.demo.ftest.webdriver.AbstractWebDriverTest;
import org.richfaces.bootstrap.demo.ftest.webdriver.pickList.fragment.BootstrapPickListImpl;
import org.richfaces.bootstrap.demo.ftest.webdriver.pickList.fragment.PickListList;
import org.richfaces.bootstrap.demo.ftest.webdriver.pickList.fragment.PickListSelection.With;

/**
* @author <a href="mailto:jstefek@redhat.com">Jiri Stefek</a>
*/
public class TestPickList extends AbstractWebDriverTest {

private static final String[] CAPITALS = new String[]{ "Montgomery", "Phoenix", "Denver", "Atlanta" };
private int initListSize;
//
@FindBy(css = "div[class='pickList outer']")
BootstrapPickListImpl pickList;

private void assertListContainsCapitals(PickListList list, String... capitals) {
for (String capital : capitals) {
assertTrue("List don't contains capital " + capital, list.contains(capital));
}
}

private void assertListDontContainsCapitals(PickListList list, String... capitals) {
for (String capital : capitals) {
assertFalse("List contains capital " + capital, list.contains(capital));
}
}

private void assertLeftListSize(int size) {
assertListSize(pickList.getSourceList(), size);
}

private void assertRightListSize(int size) {
assertListSize(pickList.getTargetList(), size);
}

private void assertListSize(PickListList list, int size) {
assertEquals(size, list.size());
}

private void assertCapitalsInOrderInRightList(String... capitals) {
assertCapitalsInOrderInList(pickList.getTargetList(), capitals);
}

private void assertCapitalsInOrderInList(PickListList list, String... capitals) {
assertEquals(list.size(), capitals.length);
for (int i = 0; i < capitals.length; i++) {
String capital = list.getKeyAtIndex(i);
assertEquals(capitals[i], capital);
}
}

@Override
protected String getComponentName() {
return "pickList";
}

@Before
public void initializeInitListSize() {
this.initListSize = pickList.getSourceList().size();
assertTrue(initListSize > 0);
}

@Test
public void testAddAllRemoveAllButtons() {
pickList.addAll();
assertLeftListSize(0);
assertRightListSize(initListSize);
pickList.removeAll();
assertLeftListSize(initListSize);
assertRightListSize(0);
}

@Test
public void testAddButtonSimple() {
pickList.selectFromSourceList(CAPITALS[1]).transferByOne(With.button);
assertListContainsCapitals(pickList.getTargetList(), CAPITALS[1]);
assertListDontContainsCapitals(pickList.getSourceList(), CAPITALS[1]);
assertLeftListSize(initListSize - 1);
assertRightListSize(1);
}

@Test
public void testAddByDnD() {
pickList.selectFromSourceList(CAPITALS[1]).transferByOne(With.dnd);
assertListContainsCapitals(pickList.getTargetList(), CAPITALS[1]);
assertListDontContainsCapitals(pickList.getSourceList(), CAPITALS[1]);
assertLeftListSize(initListSize - 1);
assertRightListSize(1);
}

@Ignore("cannot select multiple elements with ctrl")
@Test
public void testAddMultipleByButton() {
pickList.selectFromSourceList(CAPITALS).transferMultiple(With.button);

assertRightListSize(CAPITALS.length);
assertLeftListSize(initListSize - CAPITALS.length);
assertListContainsCapitals(pickList.getTargetList(), CAPITALS);
assertListDontContainsCapitals(pickList.getSourceList(), CAPITALS);
}

@Ignore(value = "cannot select multiple elements with ctrl")
@Test
public void testAddMultipleByDnD() {
pickList.selectFromSourceList(CAPITALS).transferMultiple(With.dnd);

assertRightListSize(CAPITALS.length);
assertLeftListSize(initListSize - CAPITALS.length);
assertListContainsCapitals(pickList.getTargetList(), CAPITALS);
assertListDontContainsCapitals(pickList.getSourceList(), CAPITALS);
}

@Test
public void testInit() {
assertTrue("PickList is not visible", pickList.isVisible());
assertFalse("Source list of pickList should not be empty", pickList.getSourceList().isEmpty());
assertTrue("Target list of pickList should be empty", pickList.getTargetList().isEmpty());
}

@Test
public void testListOrderingSimpleByButtons() {
pickList.selectFromSourceList(CAPITALS[2], CAPITALS[1], CAPITALS[0]).transferByOne(With.button);
//reverse order, the last added will be on peak
assertCapitalsInOrderInRightList(CAPITALS[0], CAPITALS[1], CAPITALS[2]);

//test 'first' button
pickList.selectFromTargetList(CAPITALS[2]).first();
assertCapitalsInOrderInRightList(CAPITALS[2], CAPITALS[0], CAPITALS[1]);
pickList.selectFromTargetList(CAPITALS[2]).first();
assertCapitalsInOrderInRightList(CAPITALS[2], CAPITALS[0], CAPITALS[1]);

//test 'up' button
pickList.selectFromTargetList(CAPITALS[0]).up();
assertCapitalsInOrderInRightList(CAPITALS[0], CAPITALS[2], CAPITALS[1]);
pickList.selectFromTargetList(CAPITALS[0]).up();
assertCapitalsInOrderInRightList(CAPITALS[0], CAPITALS[2], CAPITALS[1]);

//test 'down' button
pickList.selectFromTargetList(CAPITALS[2]).down();
assertCapitalsInOrderInRightList(CAPITALS[0], CAPITALS[1], CAPITALS[2]);
pickList.selectFromTargetList(CAPITALS[2]).down();
assertCapitalsInOrderInRightList(CAPITALS[0], CAPITALS[1], CAPITALS[2]);

//test 'last' button
pickList.selectFromTargetList(CAPITALS[0]).last();
assertCapitalsInOrderInRightList(CAPITALS[1], CAPITALS[2], CAPITALS[0]);
pickList.selectFromTargetList(CAPITALS[0]).last();
assertCapitalsInOrderInRightList(CAPITALS[1], CAPITALS[2], CAPITALS[0]);
}

@Test
public void testRemoveButtonSimple() {
pickList.selectFromSourceList(CAPITALS[1]).transferByOne(With.button);
pickList.selectFromTargetList(CAPITALS[1]).transferByOne(With.button);
assertLeftListSize(initListSize);
assertListContainsCapitals(pickList.getSourceList(), CAPITALS[1]);
assertRightListSize(0);
}

@Test
public void testRemoveByDnD() {
pickList.selectFromSourceList(CAPITALS[1]).transferByOne(With.dnd);
pickList.selectFromTargetList(CAPITALS[1]).transferByOne(With.dnd);
assertLeftListSize(initListSize);
assertListContainsCapitals(pickList.getSourceList(), CAPITALS[1]);
assertRightListSize(0);
}
}

0 comments on commit 5f58550

Please sign in to comment.