Repository: syncope Updated Branches: refs/heads/master 607e239c8 -> 04941418a
[SYNCOPE-809] Added Tests for Eclipse Plugin - This closes #34 Project: http://git-wip-us.apache.org/repos/asf/syncope/repo Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/04941418 Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/04941418 Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/04941418 Branch: refs/heads/master Commit: 04941418ad182489e0f45eb450fad8141897faed Parents: 607e239 Author: Tushar <[email protected]> Authored: Wed Aug 17 09:41:53 2016 +0530 Committer: Francesco Chicchiriccò <[email protected]> Committed: Fri Aug 19 13:32:47 2016 +0200 ---------------------------------------------------------------------- .gitignore | 2 + .../META-INF/MANIFEST.MF | 21 ++ .../build.properties | 22 ++ .../pom.xml | 154 +++++++++ .../ide/eclipse/tests/SyncopeViewTest.java | 343 +++++++++++++++++++ ide/eclipse/pom.xml | 7 + pom.xml | 7 +- 7 files changed, 555 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/syncope/blob/04941418/.gitignore ---------------------------------------------------------------------- diff --git a/.gitignore b/.gitignore index 0059895..deb11f0 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ maven-eclipse.xml archetype/src/main/resources/archetype-resources/pom.xml ide/eclipse/bundles/org.apache.syncope.ide.eclipse.plugin/bin/ ide/eclipse/bundles/org.apache.syncope.ide.eclipse.plugin/lib/ +ide/eclipse/bundles/org.apache.syncope.ide.eclipse.tests/bin/ +ide/eclipse/bundles/org.apache.syncope.ide.eclipse.tests/screenshots/ http://git-wip-us.apache.org/repos/asf/syncope/blob/04941418/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.tests/META-INF/MANIFEST.MF ---------------------------------------------------------------------- diff --git a/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.tests/META-INF/MANIFEST.MF b/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.tests/META-INF/MANIFEST.MF new file mode 100644 index 0000000..44ab47f --- /dev/null +++ b/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.tests/META-INF/MANIFEST.MF @@ -0,0 +1,21 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: org.apache.syncope.ide.eclipse.tests +Bundle-SymbolicName: org.apache.syncope.ide.eclipse.tests;singleton:=true +Bundle-Version: 2.0.0.qualifier +Bundle-ActivationPolicy: lazy +Bundle-Vendor: +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Require-Bundle: org.eclipse.swtbot.go, + org.eclipse.jface.text, + org.eclipse.core.resources, + org.eclipse.ui, + org.eclipse.ui.editors, + org.eclipse.ui.ide, + org.eclipse.core.runtime, + org.eclipse.swtbot.swt.finder, + org.eclipse.swtbot.eclipse.finder, + org.apache.log4j, + org.eclipse.swtbot.junit4_x, + org.apache.syncope.ide.eclipse.plugin, + org.eclipse.swtbot.eclipse.ui http://git-wip-us.apache.org/repos/asf/syncope/blob/04941418/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.tests/build.properties ---------------------------------------------------------------------- diff --git a/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.tests/build.properties b/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.tests/build.properties new file mode 100644 index 0000000..f397c4d --- /dev/null +++ b/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.tests/build.properties @@ -0,0 +1,22 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . http://git-wip-us.apache.org/repos/asf/syncope/blob/04941418/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.tests/pom.xml ---------------------------------------------------------------------- diff --git a/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.tests/pom.xml b/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.tests/pom.xml new file mode 100644 index 0000000..61d5861 --- /dev/null +++ b/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.tests/pom.xml @@ -0,0 +1,154 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you 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/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.syncope.ide</groupId> + <artifactId>syncope-ide-eclipse</artifactId> + <version>2.0.0-SNAPSHOT</version> + <relativePath>../../</relativePath> + </parent> + + <name>Apache Syncope IDE Eclipse Tests</name> + <description>Apache Syncope IDE Eclipse Tests</description> + <groupId>org.apache.syncope.ide.eclipse</groupId> + <artifactId>org.apache.syncope.ide.eclipse.tests</artifactId> + <packaging>eclipse-test-plugin</packaging> + + <properties> + <rootpom.basedir>${basedir}/../../../..</rootpom.basedir> + </properties> + + <dependencies> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.syncope.fit</groupId> + <artifactId>syncope-fit-core-reference</artifactId> + <version>${project.version}</version> + <type>war</type> + <scope>test</scope> + </dependency> + </dependencies> + + <profiles> + <profile> + <id>eclipse-it</id> + <build> + <plugins> + <plugin> + <groupId>org.eclipse.tycho</groupId> + <artifactId>target-platform-configuration</artifactId> + <configuration> + <dependency-resolution> + <extraRequirements> + <requirement> + <type>eclipse-feature</type> + <id>org.eclipse.e4.rcp</id> + <versionRange>0.0.0</versionRange> + </requirement> + <requirement> + <type>eclipse-feature</type> + <id>org.eclipse.pde</id> + <versionRange>0.0.0</versionRange> + </requirement> + <requirement> + <type>eclipse-feature</type> + <id>org.eclipse.cvs</id> + <versionRange>0.0.0</versionRange> + </requirement> + </extraRequirements> + </dependency-resolution> + </configuration> + </plugin> + + <plugin> + <groupId>org.eclipse.tycho</groupId> + <artifactId>tycho-surefire-plugin</artifactId> + <configuration> + <useUIHarness>true</useUIHarness> + <useUIThread>false</useUIThread> + <product>org.eclipse.sdk.ide</product> + <application>org.eclipse.ui.ide.workbench</application> + </configuration> + </plugin> + + <plugin> + <groupId>org.codehaus.cargo</groupId> + <artifactId>cargo-maven2-plugin</artifactId> + <inherited>true</inherited> + <configuration> + <container> + <dependencies> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + </dependency> + </dependencies> + </container> + <configuration> + <type>standalone</type> + <properties> + <cargo.servlet.port>${cargo.servlet.port}</cargo.servlet.port> + <cargo.tomcat.ajp.port>${cargo.tomcat.ajp.port}</cargo.tomcat.ajp.port> + <cargo.rmi.port>${cargo.rmi.port}</cargo.rmi.port> + + <cargo.jvmargs>-XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC -XX:MaxPermSize=512m -Xmx1024m -Xms512m</cargo.jvmargs> + </properties> + </configuration> + <deployables> + <deployable> + <location>${basedir}/../../../../fit/core-reference/target/syncope-fit-core-reference-${project.version}.war</location> + <pingURL>http://localhost:${cargo.servlet.port}/syncope/cacheStats.jsp</pingURL> + <pingTimeout>60000</pingTimeout> + <properties> + <context>syncope</context> + </properties> + <type>war</type> + </deployable> + </deployables> + </configuration> + <executions> + <execution> + <id>start-container</id> + <phase>pre-integration-test</phase> + <goals> + <goal>start</goal> + </goals> + </execution> + <execution> + <id>stop-container</id> + <phase>post-integration-test</phase> + <goals> + <goal>stop</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> http://git-wip-us.apache.org/repos/asf/syncope/blob/04941418/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.tests/src/main/java/org/apache/syncope/ide/eclipse/tests/SyncopeViewTest.java ---------------------------------------------------------------------- diff --git a/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.tests/src/main/java/org/apache/syncope/ide/eclipse/tests/SyncopeViewTest.java b/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.tests/src/main/java/org/apache/syncope/ide/eclipse/tests/SyncopeViewTest.java new file mode 100644 index 0000000..9228481 --- /dev/null +++ b/ide/eclipse/bundles/org.apache.syncope.ide.eclipse.tests/src/main/java/org/apache/syncope/ide/eclipse/tests/SyncopeViewTest.java @@ -0,0 +1,343 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +package org.apache.syncope.ide.eclipse.tests; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; +import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; +import org.eclipse.swtbot.swt.finder.SWTBot; +import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; +import org.eclipse.swtbot.swt.finder.waits.ICondition; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(SWTBotJunit4ClassRunner.class) +public class SyncopeViewTest { + + private static SWTWorkbenchBot BOT; + + private SWTBotView syncopeView; + + private SWTBotTreeItem mTemplateItem; + + private SWTBotTreeItem rTemplateItem; + + private SWTBotTreeItem[] mtemplateList; + + private SWTBotTreeItem[] rtemplateList; + + protected static final String ADMIN_UNAME = "admin"; + + protected static final String ADMIN_PWD = "password"; + + protected static final String ADDRESS = "http://localhost:9080/syncope/rest"; + + @BeforeClass + public static void beforeClass() throws Exception { + BOT = new SWTWorkbenchBot(); + } + + @Test + public void canOpenView() throws Exception { + BOT.menu("Window").menu("Show View").menu("Other...").click(); + SWTBotShell shell = BOT.shell("Show View"); + shell.activate(); + BOT.tree().expandNode("Apache Syncope").select("Apache Syncope Templates").click(); + BOT.button("OK").click(); + } + + @Test + public void canOpenLoginDialog() throws Exception { + SWTBotView view = BOT.viewByTitle("Apache Syncope Templates"); + view.getToolbarButtons().get(0).click(); + } + + @Test + public void canLoginAdmin() throws Exception { + SWTBotShell loginShell = BOT.activeShell(); + loginShell.activate(); + BOT.textWithLabel("Deployment Url").setText(ADDRESS); + BOT.textWithLabel("Username").setText(ADMIN_UNAME); + BOT.textWithLabel("Password").setText(ADMIN_PWD); + BOT.button("Login").click(); + BOT.waitWhile(new ICondition() { + + @Override + public boolean test() throws Exception { + String title = BOT.activeShell().getText(); + return title.equals("Loading Templates"); + } + + @Override + public void init(final SWTBot bot) { + } + + @Override + public String getFailureMessage() { + return "Unable to Login"; + } + }); + } + + @Test + public void hasCorrectTemplates() throws Exception { + syncopeView = BOT.viewByTitle("Apache Syncope Templates"); + mTemplateItem = syncopeView.bot().tree().expandNode("Mail Templates"); + rTemplateItem = syncopeView.bot().tree().expandNode("Report Templates"); + + mtemplateList = mTemplateItem.getItems(); + rtemplateList = rTemplateItem.getItems(); + + assertNotNull(mtemplateList); + assertNotNull(rtemplateList); + + assertTrue(checkMailTemplateKeys()); + assertTrue(checkReportTemplateKeys()); + assertTrue(canAddMailTemplate()); + assertTrue(canDeleteMailTemplate()); + assertTrue(canAddReportTemplate()); + assertTrue(canDeleteReportTemplate()); + + assertTrue(canOpenMailTemplateEditor()); + assertTrue(canOpenReportTemplateEditor()); + } + + public boolean checkMailTemplateKeys() { + return (mtemplateList[0].getText().equals("confirmPasswordReset") + && mtemplateList[1].getText().equals("optin") + && mtemplateList[2].getText().equals("requestPasswordReset") + && mtemplateList[3].getText().equals("test")); + } + + public boolean checkReportTemplateKeys() { + return (rtemplateList[0].getText().equals("empty") && rtemplateList[1].getText().equals("sample")); + } + + private boolean canAddMailTemplate() { + SWTBotTreeItem mTemplateHead = syncopeView.bot().tree().getTreeItem("Mail Templates"); + mTemplateHead.setFocus(); + mTemplateHead.select().contextMenu("Add Template").click(); + BOT.sleep(1000); + + // Filling Dialog details + SWTBotShell addTemplateShell = BOT.activeShell(); + addTemplateShell.activate(); + BOT.textWithLabel("Key").setText("newMailTemplate"); + BOT.button("Add").click(); + + // wait for template keys reload + BOT.waitWhile(new ICondition() { + + @Override + public boolean test() throws Exception { + String title = BOT.activeShell().getText(); + return title.equals("Loading Templates"); + } + + @Override + public void init(final SWTBot bot) { + } + + @Override + public String getFailureMessage() { + return "Unable to Login"; + } + }); + + // recheck available templates + syncopeView = BOT.viewByTitle("Apache Syncope Templates"); + mTemplateItem = syncopeView.bot().tree().expandNode("Mail Templates"); + mtemplateList = mTemplateItem.getItems(); + + return (mtemplateList.length == 5 && mtemplateList[1].getText().equals("newMailTemplate")); + } + + private boolean canAddReportTemplate() { + SWTBotTreeItem rTemplateHead = syncopeView.bot().tree().getTreeItem("Report Templates"); + rTemplateHead.setFocus(); + rTemplateHead.select().contextMenu("Add Template").click(); + BOT.sleep(1000); + + // Filling Dialog details + SWTBotShell addTemplateShell = BOT.activeShell(); + addTemplateShell.activate(); + BOT.textWithLabel("Key").setText("newReportTemplate"); + BOT.button("Add").click(); + + // wait for template keys reload + BOT.waitWhile(new ICondition() { + + @Override + public boolean test() throws Exception { + String title = BOT.activeShell().getText(); + return title.equals("Loading Templates"); + } + + @Override + public void init(final SWTBot bot) { + } + + @Override + public String getFailureMessage() { + return "Unable to Login"; + } + }); + + // recheck available templates + syncopeView = BOT.viewByTitle("Apache Syncope Templates"); + rTemplateItem = syncopeView.bot().tree().expandNode("Report Templates"); + rtemplateList = rTemplateItem.getItems(); + + return (rtemplateList.length == 3 && rtemplateList[1].getText().equals("newReportTemplate")); + } + + private boolean canDeleteMailTemplate() { + SWTBotTreeItem mTemplateHead = syncopeView.bot().tree().getTreeItem("Mail Templates"); + + if (!mTemplateHead.isExpanded()) { + mTemplateHead.expand(); + } + + SWTBotTreeItem mNewTemplate = mTemplateHead.getNode("newMailTemplate"); + + mNewTemplate.setFocus(); + mNewTemplate.select().contextMenu("Remove template").click(); + BOT.sleep(1000); + // wait for template keys reload + BOT.waitWhile(new ICondition() { + + @Override + public boolean test() throws Exception { + String title = BOT.activeShell().getText(); + return title.equals("Loading Templates"); + } + + @Override + public void init(final SWTBot bot) { + } + + @Override + public String getFailureMessage() { + return "Unable to Login"; + } + }); + + // recheck available templates + mTemplateItem = syncopeView.bot().tree().expandNode("Mail Templates"); + mtemplateList = mTemplateItem.getItems(); + + return (mtemplateList.length == 4); + } + + private boolean canDeleteReportTemplate() { + SWTBotTreeItem rTemplateHead = syncopeView.bot().tree().getTreeItem("Report Templates"); + + if (!rTemplateHead.isExpanded()) { + rTemplateHead.expand(); + } + + SWTBotTreeItem rNewTemplate = rTemplateHead.getNode("newReportTemplate"); + + rNewTemplate.setFocus(); + rNewTemplate.select().contextMenu("Remove template").click(); + BOT.sleep(1000); + // wait for template keys reload + BOT.waitWhile(new ICondition() { + + @Override + public boolean test() throws Exception { + String title = BOT.activeShell().getText(); + return title.equals("Loading Templates"); + } + + @Override + public void init(final SWTBot bot) { + } + + @Override + public String getFailureMessage() { + return "Unable to Login"; + } + }); + + // recheck available templates + rTemplateItem = syncopeView.bot().tree().expandNode("Report Templates"); + rtemplateList = rTemplateItem.getItems(); + + return (rtemplateList.length == 2); + } + + public boolean canOpenMailTemplateEditor() { + final int initBotEditors = BOT.editors().size(); + SWTBotTreeItem optin = syncopeView.bot().tree().expandNode("Mail Templates").getNode("optin"); + optin.setFocus(); + optin.select().contextMenu("View Template").click(); + + // wait for template keys reload + BOT.waitWhile(new ICondition() { + + @Override + public boolean test() throws Exception { + return BOT.editors().size() == initBotEditors; + } + + @Override + public void init(final SWTBot bot) { + } + + @Override + public String getFailureMessage() { + return "Unable to Login"; + } + }); + return !BOT.editors().isEmpty(); + } + + public boolean canOpenReportTemplateEditor() { + final int initBotEditors = BOT.editors().size(); + SWTBotTreeItem sample = syncopeView.bot().tree().expandNode("Report Templates").getNode("sample"); + sample.setFocus(); + sample.select().contextMenu("View Template").click(); + + // wait for template keys reload + BOT.waitWhile(new ICondition() { + + @Override + public boolean test() throws Exception { + return BOT.editors().size() == initBotEditors; + } + + @Override + public void init(final SWTBot bot) { + } + + @Override + public String getFailureMessage() { + return "Unable to Login"; + } + }); + return !BOT.editors().isEmpty(); + } + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/04941418/ide/eclipse/pom.xml ---------------------------------------------------------------------- diff --git a/ide/eclipse/pom.xml b/ide/eclipse/pom.xml index 3d3b2be..eaafddf 100644 --- a/ide/eclipse/pom.xml +++ b/ide/eclipse/pom.xml @@ -93,6 +93,13 @@ under the License. <profiles> <profile> + <id>eclipse-it</id> + <modules> + <module>bundles/org.apache.syncope.ide.eclipse.tests</module> + </modules> + </profile> + + <profile> <id>apache-release</id> <build> http://git-wip-us.apache.org/repos/asf/syncope/blob/04941418/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index ee6ded9..69a3d1a 100644 --- a/pom.xml +++ b/pom.xml @@ -1575,7 +1575,12 @@ under the License. <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-p2-repository-plugin</artifactId> <version>${tycho-version}</version> - </plugin> + </plugin> + <plugin> + <groupId>org.eclipse.tycho</groupId> + <artifactId>tycho-surefire-plugin</artifactId> + <version>${tycho-version}</version> + </plugin> </plugins> </pluginManagement>
