Author: psrna
Date: 2010-10-22 03:20:27 -0400 (Fri, 22 Oct 2010)
New Revision: 25988
Added:
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/.classpath
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/.project
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/META-INF/
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/META-INF/MANIFEST.MF
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/bin/
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/build.properties
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/screenshots/
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/src/
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/src/org/
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/src/org/jboss/
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/src/org/jboss/tools/
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/src/org/jboss/tools/modeshape/
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/src/org/jboss/tools/modeshape/rest/
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/src/org/jboss/tools/modeshape/rest/ui/
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/src/org/jboss/tools/modeshape/rest/ui/bot/
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/src/org/jboss/tools/modeshape/rest/ui/bot/tests/
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/src/org/jboss/tools/modeshape/rest/ui/bot/tests/ModeshapeAllTests.java
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/src/org/jboss/tools/modeshape/rest/ui/bot/tests/Properties.java
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/src/org/jboss/tools/modeshape/rest/ui/bot/tests/Publishing.java
Log:
* SWTBot tests for Modeshape Eclipse Plug-in
Added: trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/.classpath
===================================================================
--- trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/.classpath
(rev 0)
+++ trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/.classpath 2010-10-22
07:20:27 UTC (rev 25988)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con"
path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Property changes on:
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/.classpath
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/.project
===================================================================
--- trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/.project
(rev 0)
+++ trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/.project 2010-10-22
07:20:27 UTC (rev 25988)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.jboss.tools.modeshape.rest.ui.bot.test</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Property changes on:
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/.project
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/META-INF/MANIFEST.MF
===================================================================
--- trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/META-INF/MANIFEST.MF
(rev 0)
+++
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/META-INF/MANIFEST.MF 2010-10-22
07:20:27 UTC (rev 25988)
@@ -0,0 +1,11 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Modeshape SWTBot Tests
+Bundle-SymbolicName: org.jboss.tools.modeshape.rest.ui.bot.test;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-ActivationPolicy: lazy
+Bundle-Vendor:
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Require-Bundle: org.eclipse.swtbot.go,
+ org.jboss.tools.ui.bot.ext;bundle-version="3.2.0",
+ org.eclipse.jdt.junit4.runtime;bundle-version="1.1.100"
Property changes on:
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/META-INF/MANIFEST.MF
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/build.properties
===================================================================
--- trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/build.properties
(rev 0)
+++
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/build.properties 2010-10-22
07:20:27 UTC (rev 25988)
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
Property changes on:
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/build.properties
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/src/org/jboss/tools/modeshape/rest/ui/bot/tests/ModeshapeAllTests.java
===================================================================
---
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/src/org/jboss/tools/modeshape/rest/ui/bot/tests/ModeshapeAllTests.java
(rev 0)
+++
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/src/org/jboss/tools/modeshape/rest/ui/bot/tests/ModeshapeAllTests.java 2010-10-22
07:20:27 UTC (rev 25988)
@@ -0,0 +1,19 @@
+package org.jboss.tools.modeshape.rest.ui.bot.tests;
+
+
+import org.jboss.tools.ui.bot.ext.RequirementAwareSuite;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite.SuiteClasses;
+
+/**
+ *
+ * @author psrna
+ *
+ */
+@SuiteClasses({
+ Publishing.class
+ })
+(a)RunWith(RequirementAwareSuite.class)
+public class ModeshapeAllTests {
+
+}
Property changes on:
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/src/org/jboss/tools/modeshape/rest/ui/bot/tests/ModeshapeAllTests.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/src/org/jboss/tools/modeshape/rest/ui/bot/tests/Properties.java
===================================================================
---
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/src/org/jboss/tools/modeshape/rest/ui/bot/tests/Properties.java
(rev 0)
+++
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/src/org/jboss/tools/modeshape/rest/ui/bot/tests/Properties.java 2010-10-22
07:20:27 UTC (rev 25988)
@@ -0,0 +1,22 @@
+package org.jboss.tools.modeshape.rest.ui.bot.tests;
+
+/**
+ *
+ * @author psrna
+ *
+ */
+public class Properties {
+
+ public static final String PROJECT_NAME = "testproject";
+ public static final String FILE_NAME = "testfile";
+ public static final String FILE_CONTENT = "testcontent";
+
+ public static final String URL = "http://localhost:8080/modeshape-rest";
+ public static final String WEBDAV_URL =
"http://localhost:8080/modeshape-webdav";
+
+ public static final String REPOSITORY = "repository";
+ public static final String WORKSPACE = "default";
+
+ public static final String USER = "admin";
+ public static final String PASSWORD = "admin";
+}
Property changes on:
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/src/org/jboss/tools/modeshape/rest/ui/bot/tests/Properties.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/src/org/jboss/tools/modeshape/rest/ui/bot/tests/Publishing.java
===================================================================
---
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/src/org/jboss/tools/modeshape/rest/ui/bot/tests/Publishing.java
(rev 0)
+++
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/src/org/jboss/tools/modeshape/rest/ui/bot/tests/Publishing.java 2010-10-22
07:20:27 UTC (rev 25988)
@@ -0,0 +1,251 @@
+package org.jboss.tools.modeshape.rest.ui.bot.tests;
+
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import org.eclipse.core.internal.preferences.Base64;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
+import org.eclipse.swtbot.swt.finder.SWTBot;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.jboss.tools.ui.bot.ext.SWTTestExt;
+import org.jboss.tools.ui.bot.ext.SWTUtilExt;
+import org.jboss.tools.ui.bot.ext.config.Annotations.SWTBotTestRequires;
+import org.jboss.tools.ui.bot.ext.config.Annotations.Server;
+import org.jboss.tools.ui.bot.ext.config.Annotations.ServerType;
+import org.jboss.tools.ui.bot.ext.gen.ActionItem;
+import org.jboss.tools.ui.bot.ext.gen.ActionItem.NewObject.GeneralProject;
+import org.jboss.tools.ui.bot.ext.types.IDELabel;
+import org.jboss.tools.ui.bot.ext.helper.ContextMenuHelper;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ *
+ * @author psrna
+ *
+ */
+@SWTBotTestRequires(server=(a)Server(type=ServerType.EAP,version="5.0"),perspective="Java
EE")
+public class Publishing extends SWTTestExt{
+
+ private static final String CONNERR_MSG = "Unable to connect using the specified
server properties." +
+ "The server properties could be invalid or the server may be
offline.";
+
+
+ public static void createResource(){
+
+ SWTBot wiz = open.newObject(ActionItem.NewObject.GeneralProject.LABEL);
+ wiz.textWithLabel(GeneralProject.TEXT_PROJECT_NAME).setText(Properties.PROJECT_NAME);
+ open.finish(wiz);
+ assertTrue(projectExplorer.existsResource(Properties.PROJECT_NAME));
+
+ wiz = open.newObject(ActionItem.NewObject.GeneralFile.LABEL);
+ wiz.tree().select(Properties.PROJECT_NAME);
+ wiz.textWithLabel(ActionItem.NewObject.GeneralFile.TEXT_FILE_NAME).typeText(Properties.FILE_NAME);
+ open.finish(wiz);
+ assertTrue(projectExplorer.isFilePresent(Properties.PROJECT_NAME,
Properties.FILE_NAME));
+
+ String projectLocation = SWTUtilExt.getPathToProject(Properties.PROJECT_NAME);
+ try {
+ FileWriter fstream = new FileWriter(projectLocation + "/" +
Properties.FILE_NAME);
+ BufferedWriter out = new BufferedWriter(fstream);
+ out.write(Properties.FILE_CONTENT);
+ out.close();
+ } catch (IOException e) {
+ fail("Unable to write to file.");
+ log.error(e.getMessage());
+ }
+
+ }
+
+ @BeforeClass
+ public static void beforeClass(){
+ createResource();
+ }
+
+
+ @Test
+ public void createModeShapeServer(){
+
+ openModeshapeView();
+ SWTBotView view = bot.viewByTitle("ModeShape");
+ assertTrue("ModeShape View must be active", view.isActive());
+
+ view.toolbarButton("Create a new server").click();
+ SWTBotShell shell = bot.shell("New Server");
+ shell.activate();
+
+ shell.bot().textWithLabel("URL:").typeText(Properties.URL);
+ shell.bot().textWithLabel("User:").typeText(Properties.USER);
+ shell.bot().textWithLabel("Password:").typeText(Properties.PASSWORD);
+
+ shell.bot().button("Test").click();
+ shell = bot.shell("Test Server Connection");
+ shell.activate();
+
+ String msg = shell.bot().label(1).getText();
+ assertTrue(CONNERR_MSG, msg.equals("Successfully connected using the specified
server properties."));
+
+ open.finish(bot.activeShell().bot(), IDELabel.Button.OK);
+ shell = bot.shell("New Server");
+ shell.activate();
+
+ open.finish(shell.bot());
+
+ assertTrue("Created server not visible in ModeShape view.",
view.bot().tree().getTreeItem(Properties.URL).isVisible());
+ }
+
+ private void openModeshapeView(){
+
+ bot.menu(IDELabel.Menu.WINDOW)
+ .menu(IDELabel.Menu.SHOW_VIEW)
+ .menu(IDELabel.Menu.OTHER).click();
+
+ SWTBotShell shell = bot.shell("Show View");
+ shell.activate();
+ shell.bot().tree().expandNode("ModeShape",
false).select("ModeShape");
+
+ open.finish(bot.activeShell().bot(), IDELabel.Button.OK);
+ }
+
+
+ @Test
+ public void publishFile(){
+
+ SWTBotView view = bot.viewByTitle("Project Explorer");
+ SWTBot viewBot = view.bot();
+ SWTBotTreeItem node = eclipse.selectTreeLocation(viewBot, Properties.PROJECT_NAME,
Properties.FILE_NAME);
+
+ ContextMenuHelper.prepareTreeItemForContextMenu(projectExplorer.tree(),node);
+ ContextMenuHelper.clickContextMenu(projectExplorer.tree(), "ModeShape",
"Publish");
+
+ SWTBotShell shell = bot.shell("Publish");
+ shell.activate();
+
+ SWTBotCombo serverCombo = shell.bot().comboBoxWithLabel("Server:");
+ SWTBotCombo repoCombo = shell.bot().comboBoxWithLabel("Repository:");
+ SWTBotCombo workspaceCombo = shell.bot().comboBoxWithLabel("Workspace:");
+
+ assertTrue("URL mismatch.", serverCombo.getText().equals(Properties.URL));
+ assertTrue("Repository mismatch.",
repoCombo.getText().equals(Properties.REPOSITORY));
+ assertTrue("Workspace mismatch.",
workspaceCombo.getText().equals(Properties.WORKSPACE));
+
+ open.finish(shell.bot());
+
+ assertTrue("HTTP Response code must be 200 after publishing.",
HttpURLConnection.HTTP_OK == testPublishedFile());
+ }
+
+
+ @Test
+ public void publishedLocations(){
+
+ SWTBotView view = bot.viewByTitle("Project Explorer");
+ SWTBot viewBot = view.bot();
+ SWTBotTreeItem node = eclipse.selectTreeLocation(viewBot, Properties.PROJECT_NAME,
Properties.FILE_NAME);
+
+ ContextMenuHelper.prepareTreeItemForContextMenu(projectExplorer.tree(),node);
+ ContextMenuHelper.clickContextMenu(projectExplorer.tree(), "ModeShape",
"Show Published Locations");
+
+ SWTBotShell shell = bot.shell("Published Locations");
+ shell.activate();
+
+ SWTBotTable table = shell.bot().table();
+ assertTrue("Url mismatch.", table.cell(0, 0).equals(Properties.URL));
+ assertTrue("User mismatch.", table.cell(0, 1).equals(Properties.USER));
+ assertTrue("Repository mismatch.", table.cell(0,
2).equals(Properties.REPOSITORY));
+ assertTrue("Workspace mismatch.", table.cell(0,
3).equals(Properties.WORKSPACE));
+
+ String expectedPublishedUrl = Properties.URL + "/" +
+ Properties.REPOSITORY + "/" +
+ Properties.WORKSPACE + "/items/" +
+ Properties.PROJECT_NAME + "/" +
+ Properties.FILE_NAME;
+
+ assertTrue("Published Url mismatch.", table.cell(0,
4).equals(expectedPublishedUrl));
+
+ open.finish(shell.bot(), IDELabel.Button.OK);
+
+ }
+
+
+
+ @Test
+ public void unpublishFile(){
+
+ SWTBotView view = bot.viewByTitle("Project Explorer");
+ SWTBot viewBot = view.bot();
+ SWTBotTreeItem node = eclipse.selectTreeLocation(viewBot, Properties.PROJECT_NAME,
Properties.FILE_NAME);
+
+ ContextMenuHelper.prepareTreeItemForContextMenu(projectExplorer.tree(),node);
+ ContextMenuHelper.clickContextMenu(projectExplorer.tree(), "ModeShape",
"Unpublish");
+
+ SWTBotShell shell = bot.shell("Unpublish");
+ shell.activate();
+
+ SWTBotCombo serverCombo = shell.bot().comboBoxWithLabel("Server:");
+ SWTBotCombo repoCombo = shell.bot().comboBoxWithLabel("Repository:");
+ SWTBotCombo workspaceCombo = shell.bot().comboBoxWithLabel("Workspace:");
+
+ assertTrue("URL mismatch.", serverCombo.getText().equals(Properties.URL));
+ assertTrue("Repository mismatch.",
repoCombo.getText().equals(Properties.REPOSITORY));
+ assertTrue("Workspace mismatch.",
workspaceCombo.getText().equals(Properties.WORKSPACE));
+
+ open.finish(shell.bot());
+
+ assertTrue("HTTP Response code must be 404 after unpublishing.",
HttpURLConnection.HTTP_NOT_FOUND == testPublishedFile());
+
+ }
+
+
+ /**
+ *
+ * @return response code
+ */
+ private int testPublishedFile(){
+
+ try {
+
+ URL url = new URL(Properties.WEBDAV_URL + "/" + Properties.PROJECT_NAME +
"/" + Properties.FILE_NAME);
+ HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+
+ conn.setRequestMethod("GET");
+ conn.setAllowUserInteraction(false);
+ conn.setUseCaches(false);
+ conn.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
+
+ String authorization = Properties.USER + ":" + Properties.PASSWORD;
+ String encodedAuthorization= new String(Base64.encode(authorization.getBytes()));
+ conn.setRequestProperty("Authorization", "Basic " +
encodedAuthorization);
+
+ conn.connect();
+
+ if(conn.getResponseCode() == HttpURLConnection.HTTP_OK){
+ //if HTTP_OK, test content
+ BufferedReader rd = new BufferedReader(new
InputStreamReader(conn.getInputStream()));
+ StringBuilder sb = new StringBuilder();
+ String line = null;
+
+ while ((line = rd.readLine()) != null){
+ sb.append(line);
+ }
+ assertTrue("File content mismatch.",
sb.toString().equals(Properties.FILE_CONTENT));
+ }
+
+ //return response code
+ return conn.getResponseCode();
+
+ } catch (IOException e) {
+ fail("Unable to test the published file.");
+ log.error(e.getMessage());
+ }
+ return -1;
+ }
+
+}
Property changes on:
trunk/modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test/src/org/jboss/tools/modeshape/rest/ui/bot/tests/Publishing.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain