Skip to content

Commit

Permalink
Added new automated UI test for Arquillia Cruiser View
Browse files Browse the repository at this point in the history
  • Loading branch information
ldimaggi authored and rhopp committed Feb 15, 2016
1 parent fc91b89 commit 2b13a36
Show file tree
Hide file tree
Showing 7 changed files with 329 additions and 6 deletions.
10 changes: 7 additions & 3 deletions plugins/org.jboss.tools.arquillian.reddeer/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ Require-Bundle: org.eclipse.ui,
org.hamcrest.core,
org.jboss.ide.eclipse.as.reddeer,
org.jboss.tools.maven.reddeer;bundle-version="[4.3.1,4.4.0)",
org.jboss.reddeer.go;bundle-version="1.0.0"
org.jboss.reddeer.go,
org.jboss.reddeer.eclipse,
org.jboss.reddeer.swt,
org.jboss.reddeer.core,
org.jboss.reddeer.common
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Import-Package: org.eclipse.core.resources
Expand All @@ -22,5 +26,5 @@ Export-Package: org.jboss.tools.arquillian.ui.bot.reddeer.configurations,
org.jboss.tools.arquillian.ui.bot.reddeer.maven,
org.jboss.tools.arquillian.ui.bot.reddeer.preferences,
org.jboss.tools.arquillian.ui.bot.reddeer.profile,
org.jboss.tools.arquillian.ui.bot.reddeer.support

org.jboss.tools.arquillian.ui.bot.reddeer.support,
org.jboss.tools.arquillian.ui.bot.reddeer.view
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.jboss.tools.arquillian.ui.bot.reddeer.view;

import org.apache.log4j.Logger;
import org.jboss.reddeer.swt.api.Tree;
import org.jboss.reddeer.swt.api.TreeItem;
import org.jboss.reddeer.swt.impl.tree.DefaultTree;
import org.jboss.reddeer.swt.impl.tree.DefaultTreeItem;
import org.jboss.reddeer.workbench.impl.view.WorkbenchView;

/**
* Represents the Build List view - to support Mylyn automated tests.
*
* @author ldimaggi
*
*/
public class ArquilliaCruiserView extends WorkbenchView {

protected final static Logger log = Logger.getLogger(ArquilliaCruiserView.class);

public static final String TITLE = "Arquillia Cruiser";

public ArquilliaCruiserView() {
super(TITLE);
}

public Tree getTree(){
open();
return new DefaultTree();
}

/* Method to locate and select a build in the build list view */
public TreeItem getTreeItem (String... arquillianTreeItem ) {
new DefaultTree();
DefaultTreeItem theTreeItem = new DefaultTreeItem (arquillianTreeItem);
theTreeItem.select();
return theTreeItem;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ Require-Bundle: org.eclipse.ui,
org.jboss.ide.eclipse.as.reddeer,
org.jboss.tools.maven.reddeer;bundle-version="[4.3.1,4.4.0)",
org.jboss.tools.arquillian.reddeer;bundle-version="[4.3.1,4.4.0)",
org.jboss.reddeer.go;bundle-version="1.0.0"
org.jboss.reddeer.go;bundle-version="1.0.0",
org.jboss.tools.central.reddeer;bundle-version="4.2.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Import-Package: org.eclipse.core.resources
Eclipse-BundleShape: jar
Bundle-Vendor: JBoss by Red Hat

111 changes: 111 additions & 0 deletions tests/org.jboss.tools.arquillian.ui.bot.test/resources/functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
function searchFor(query){
$( "#search" ).val(query);
var e = jQuery.Event("keyup");
e.which=13;
e.keyCode=13;
$ ( "#search" ).trigger(e);
}

function getHTML(){
return document.documentElement.innerHTML;
}

function getExamples(){
if ($( "#results" ).hasClass("hidden")){
return null;
}
var resultsDiv = getCurrentResultsDiv();
if (resultsDiv.hasClass("hidden")){
return false;
}
return getEachInnerText(resultsDiv.find("a"));
}

function getDescriptionForExample(exampleName){
if ($( "#results" ).hasClass("hidden")){
return null;
}
var resultsDivs = getCurrentResultsDiv();
var resultDiv = getResultDivForExample(resultsDivs, exampleName);
return getEachInnerText(resultDiv.find(".list-group-item-text"));
}

function getLabelsForExample(exampleName){
if ($( "#results" ).hasClass("hidden")){
return null;
}
var resultsDivs = getCurrentResultsDiv();
var resultDiv = getResultDivForExample(resultsDivs, exampleName);
return getEachInnerText(resultDiv.find("li"));
}

function nextPage(){
if ($( "#results" ).hasClass("hidden")){
return null;
}
return $( "nav.pull-right" ).find(".next").click();
}

function hasNext(){
if ($( "#results" ).hasClass("hidden")){
return null;
}
return !$( "nav.pull-right" ).find(".next").hasClass("hidden");
}

function hasPrevious(){
if ($( "#results" ).hasClass("hidden")){
return null;
}
return !$( "nav.pull-right" ).find(".prev").hasClass("hidden");
}

function prevPage(){
if ($( "#results" ).hasClass("hidden")){
return null;
}
return $( "nav.pull-right" ).find(".prev").click();
}

function getWizards(){
if ($( "#home" ).hasClass("hidden")){
return null;
}
return getEachInnerText($( "#wizards" ).find('a'));
}

function clickWizard(name){
$( "#wizards" ).find('a').filter(":contains('"+name+"')").click();
}

function clickExample(name){
if ($( "#results" ).hasClass("hidden")){
return null;
}
var resultsDivs = getCurrentResultsDiv();
getResultDivForExample(resultsDivs, name).find("a").click();
}

function clearSearch(){
$("a").filter(":contains('clear search')").click();
}

//Internal functions from now on. Do not call them from Java tests.

function getCurrentResultsDiv(){
return $( "#resultList" ).find('div');
}

function getResultDivForExample(resultsDivs, exampleName){
return resultsDivs.filter(":contains('"+exampleName+"')");
}

function getEachInnerText(topElement){
var resultString="";
var prefix = "";
topElement.each(function(index, element){
resultString += prefix+element.textContent;
prefix=";";
});
return resultString;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jboss.tools.arquillian.ui.bot.test;

import org.jboss.reddeer.junit.runner.RedDeerSuite;
import org.jboss.tools.arquillian.ui.bot.test.cruiserView.BasicArquilliaCruiserTest;
import org.jboss.tools.arquillian.ui.bot.test.preferences.ArquillianPreferencePageTest;
import org.jboss.tools.arquillian.ui.bot.test.preferences.ArquillianValidatorPreferencePageTest;
import org.jboss.tools.arquillian.ui.bot.test.project.AddArquillianProfile;
Expand All @@ -17,7 +18,8 @@
CreateArquillianTestCase.class,
RunArquillianTestCase.class,
ArquillianPreferencePageTest.class,
ArquillianValidatorPreferencePageTest.class
ArquillianValidatorPreferencePageTest.class,
BasicArquilliaCruiserTest.class
})
public class ArquillianSuite {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package org.jboss.tools.arquillian.ui.bot.test;

import org.jboss.reddeer.junit.runner.RedDeerSuite;
import org.jboss.tools.arquillian.ui.bot.test.cruiserView.BasicArquilliaCruiserTest;
import org.jboss.tools.arquillian.ui.bot.test.preferences.ArquillianPreferencePageTest;
import org.jboss.tools.arquillian.ui.bot.test.preferences.ArquillianValidatorPreferencePageTest;
import org.jboss.tools.arquillian.ui.bot.test.project.AddArquillianProfile;
import org.jboss.tools.arquillian.ui.bot.test.project.CreateArquillianProject;
import org.jboss.tools.arquillian.ui.bot.test.testcase.CreateArquillianTestCase;
import org.jboss.tools.arquillian.ui.bot.test.testcase.RunArquillianTestCase;
import org.junit.runner.RunWith;
import org.junit.runners.Suite.SuiteClasses;

Expand All @@ -12,6 +16,10 @@
CreateArquillianProject.class,
AddArquillianProfile.class,
CreateArquillianTestCase.class,
RunArquillianTestCase.class,
ArquillianPreferencePageTest.class,
ArquillianValidatorPreferencePageTest.class,
BasicArquilliaCruiserTest.class
})
public class SmokeSuite {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
package org.jboss.tools.arquillian.ui.bot.test.cruiserView;

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

import java.util.List;

import org.jboss.reddeer.common.logging.Logger;
import org.jboss.reddeer.common.wait.WaitUntil;
import org.jboss.reddeer.eclipse.jdt.ui.ProjectExplorer;
import org.jboss.reddeer.swt.api.TreeItem;
import org.jboss.reddeer.swt.impl.browser.InternalBrowser;
import org.jboss.reddeer.swt.impl.toolbar.DefaultToolItem;
import org.jboss.reddeer.workbench.impl.editor.DefaultEditor;
import org.jboss.reddeer.workbench.impl.editor.TextEditor;
import org.jboss.reddeer.workbench.impl.shell.WorkbenchShell;
import org.jboss.tools.arquillian.ui.bot.reddeer.view.ArquilliaCruiserView;
import org.jboss.tools.central.reddeer.api.JavaScriptHelper;
import org.jboss.tools.central.reddeer.wait.CentralIsLoaded;
import org.jboss.tools.central.reddeer.wizards.NewProjectExamplesWizardDialogCentral;
import org.junit.Before;
import org.junit.Test;

/**
* Arquillia Cruiser View tests
*
* @author Len DiMaggio
*
*/

public class BasicArquilliaCruiserTest {

private static Logger log = new Logger(BasicArquilliaCruiserTest.class);
private static InternalBrowser centralBrowser;
private static JavaScriptHelper jsHelper = JavaScriptHelper.getInstance();

private static final String STRING_1 = ".addAsResource(\"META-INF/test-persistence.xml\", \"META-INF/persistence.xml\")" ;
private static final String STRING_2 = "// Kilroy was here";
private static final String QUICKSTART_SEARCH_STRING = "the `kitchensink` quickstart";
private static final String PROJECT_NAME = "jboss-kitchensink";

/* Copied from: org.jboss.tools.central.test.ui.reddeer.HTML5Test */
@Before
public void setup() {
new DefaultToolItem(new WorkbenchShell(), "JBoss Central").click();
// activate central editor
new DefaultEditor("JBoss Central");
new WaitUntil(new CentralIsLoaded());
centralBrowser = new InternalBrowser();
jsHelper.setBrowser(centralBrowser);
}

/**
* Test to verify dynamic updating of asset tree in Arquillia View
*
* Test steps:
* Import the quickstart
* Select the project in the project explorer view
* Open the Arquillia Cruiser view
* Select the project in the Arquillia Cruiser view
* Find persistence.xml in the Arquillia Cruiser view
* Open MemberRegistration.java
* Delete this line: .addAsResource("META-INF/test-persistence.xml", "META-INF/persistence.xml")
* Save file, verify persistence.xml is removed from Arquillia Cruiser view
* Restore edit, verify persistence.xml is back in Arquillia Cruiser view
*
* @throws InterruptedException
*/

@Test
public void dynamicUpdateTest () {

/* Import the quickstart */
jsHelper.searchFor(QUICKSTART_SEARCH_STRING);
String[] examples = jsHelper.getExamples();
assertTrue("One example should be found", examples.length == 1);
importExample(examples[0]);
jsHelper.clearSearch();

/* Select the project in the project explorer */
log.step("Select the project in the project explorer");
ProjectExplorer projectExplorer = new ProjectExplorer();
projectExplorer.open();
projectExplorer.getProject(PROJECT_NAME).select();

/* Locate the project in the Arquillia Cruiser View */
log.step("Locate the project in the Arquillia Cruiser View");
ArquilliaCruiserView arquilliaCruiserView = new ArquilliaCruiserView();
arquilliaCruiserView.open();

/* Verify that the persistence.xml file is present */
log.step("Verify that the persistence.xml file is present");
assertTrue ("presistence.xml file should be located in Arquillia View", findStringInTreeItemList (arquilliaCruiserView.getTree().getAllItems(), "persistence.xml"));

/* Remove the reference to persistence.xml from the MemberRegistrationTest.java file */
log.step("Remove the reference to persistence.xml from the MemberRegistrationTest.java file");
arquilliaCruiserView.getTreeItem("jboss-kitchensink", "src/test/java", "org.jboss.as.quickstarts.kitchensink.test", "MemberRegistrationTest.java").doubleClick();
editFile (STRING_1, STRING_2);

/* And confirm that persistance.xml file is dynamically removed from the Arquillia Cruiser View */
log.step("Confirm that persistance.xml file is dynamically removed from the Arquillia Cruiser View");
projectExplorer.getProject("jboss-kitchensink").select();
assertFalse ("presistence.xml file should not be located in Arquillia View", findStringInTreeItemList (arquilliaCruiserView.getTree().getAllItems(), "persistence.xml"));

/* Restore the reference to persistence.xml from the MemberRegistrationTest.java file */
log.step("Restore the reference to persistence.xml from the MemberRegistrationTest.java file");
arquilliaCruiserView.getTreeItem("jboss-kitchensink", "src/test/java", "org.jboss.as.quickstarts.kitchensink.test", "MemberRegistrationTest.java").doubleClick();
editFile (STRING_2, STRING_1);

/* And confirm that persistance.xml file is dynamically restored to the Arquillia Cruiser View */
log.step("Confirm that persistance.xml file is dynamically restored to the Arquillia Cruiser View");
projectExplorer.getProject("jboss-kitchensink").select();
assertTrue ("presistence.xml file should be located in Arquillia View", findStringInTreeItemList (arquilliaCruiserView.getTree().getAllItems(), "persistence.xml"));
}

/**
* Search for List of TreeItem objects by name/text
*
* @param treeItems
* @param searchString
* @return True or false
*/
private boolean findStringInTreeItemList (List<TreeItem> treeItems, String searchString) {
boolean retValue = false;
for(TreeItem currentItem : treeItems) {
if (currentItem.getText().equals(searchString)) {
retValue = true;
break;
}
}
return retValue;
}

/**
* Replace a string in a TextEditor
*
* @param originalText
* @param editedText
*/
private void editFile (String originalText, String editedText) {
TextEditor theEditor = new TextEditor();
theEditor.setText(theEditor.getText().replace(originalText, editedText));
theEditor.save();
}

/**
* Import an example in JBoss Central
* Copied from: org.jboss.tools.central.test.ui.reddeer.HTML5Test
*
* @param exampleName
*/
private void importExample(String exampleName) {
log.step("Importing example: " + exampleName);
jsHelper.clickExample(exampleName);
NewProjectExamplesWizardDialogCentral wizardDialog = new NewProjectExamplesWizardDialogCentral();
wizardDialog.finish(exampleName);
}

}

0 comments on commit 2b13a36

Please sign in to comment.