Author: jlukas(a)redhat.com
Date: 2011-01-26 10:52:31 -0500 (Wed, 26 Jan 2011)
New Revision: 28616
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/uiutils/wizards/CDIWizard.java
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/uiutils/wizards/Wizard.java
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/wizard/CdiATWizardTest.java
Log:
adding tests for cdi wizards introduced in cr1
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/uiutils/wizards/CDIWizard.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/uiutils/wizards/CDIWizard.java 2011-01-26
15:34:32 UTC (rev 28615)
+++
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/uiutils/wizards/CDIWizard.java 2011-01-26
15:52:31 UTC (rev 28616)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
+ * Copyright (c) 2010-2011 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
@@ -31,7 +31,11 @@
}
public CDIWizard setName(String name) {
- setText("Name:", name);
+ if (CDIWizardType.BEANS_XML == type) {
+ setText("File name:", name);
+ } else {
+ setText("Name:", name);
+ }
return this;
}
@@ -40,6 +44,15 @@
return this;
}
+ public CDIWizard setSourceFolder(String src) {
+ if (CDIWizardType.BEANS_XML == type) {
+ setText("Enter or select the parent folder:", src);
+ } else {
+ setText("Source folder:", src);
+ }
+ return this;
+ }
+
public CDIWizard setInherited(boolean set) {
setCheckbox("Add @Inherited", set);
return this;
@@ -121,6 +134,7 @@
public CDIWizard setNamed(boolean set) {
switch (type) {
case STEREOTYPE:
+ case BEAN:
setCheckbox("Add @Named", set);
break;
default:
@@ -129,6 +143,14 @@
return this;
}
+ public CDIWizard setNamedName(String name) {
+ if (CDIWizardType.BEAN != type) {
+ throw new UnsupportedOperationException();
+ }
+ setText("Bean Name:", name);
+ return this;
+ }
+
public boolean isNamed() {
switch (type) {
case STEREOTYPE:
@@ -157,6 +179,7 @@
public CDIWizard setScope(String scope) {
switch (type) {
case STEREOTYPE:
+ case BEAN:
setCombo("Scope:", scope);
break;
default:
@@ -210,6 +233,8 @@
public CDIWizard setPublic(boolean isPublic) {
switch (type) {
case DECORATOR:
+ case BEAN:
+ case ANNOTATION_LITERAL:
if (isPublic) {
bot().radio("public").click();
} else {
@@ -247,6 +272,7 @@
public CDIWizard addInterface(String intf) {
switch (type) {
case DECORATOR:
+ case BEAN:
bot().button("Add...", 0).click();
SWTBotShell sh = bot().activeShell();
sh.bot().text().setText(intf);
@@ -260,9 +286,30 @@
return this;
}
+ public CDIWizard addQualifier(String qualifier) {
+ switch (type) {
+ case BEAN:
+ bot().button("Add", 0).click();
+ break;
+ case ANNOTATION_LITERAL:
+ bot().button("Browse", 0).click();
+ break;
+ default:
+ throw new UnsupportedOperationException();
+ }
+ SWTBotShell sh = bot().activeShell();
+ sh.bot().text().setText(qualifier);
+ sh.bot().sleep(1000);
+ sh.bot().table().getTableItem(0).select();
+ sh.bot().button("OK").click();
+ return this;
+ }
+
public CDIWizard setAbstract(boolean isAbstract) {
switch (type) {
case DECORATOR:
+ case BEAN:
+ case ANNOTATION_LITERAL:
setCheckbox("abstract", isAbstract);
break;
default:
@@ -274,6 +321,8 @@
public CDIWizard setFinal(boolean isFinal) {
switch (type) {
case DECORATOR:
+ case BEAN:
+ case ANNOTATION_LITERAL:
setCheckbox("final", isFinal);
break;
default:
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/uiutils/wizards/Wizard.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/uiutils/wizards/Wizard.java 2011-01-26
15:34:32 UTC (rev 28615)
+++
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/uiutils/wizards/Wizard.java 2011-01-26
15:52:31 UTC (rev 28616)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
+ * Copyright (c) 2010-2011 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
@@ -55,6 +55,10 @@
public void finish() {
clickButton("Finish");
}
+
+ public boolean canFinish() {
+ return canClick("Finish");
+ }
protected void clickButton(String text) {
bot().button(text).click();
@@ -66,4 +70,8 @@
t.setFocus();
t.setText(text);
}
+
+ protected boolean canClick(String button) {
+ return bot().button(button).isEnabled();
+ }
}
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/wizard/CdiATWizardTest.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/wizard/CdiATWizardTest.java 2011-01-26
15:34:32 UTC (rev 28615)
+++
trunk/cdi/tests/org.jboss.tools.cdi.bot.test/src/org/jboss/tools/cdi/bot/test/wizard/CdiATWizardTest.java 2011-01-26
15:52:31 UTC (rev 28616)
@@ -44,8 +44,7 @@
public class CdiATWizardTest extends SWTTestExt {
private static final String PROJECT_NAME = "CDIProject";
- private static final Logger L = Logger.getLogger(CdiATWizardTest.class
- .getName());
+ private static final Logger L = Logger.getLogger(CdiATWizardTest.class.getName());
@After
public void waitForJobs() {
@@ -323,6 +322,96 @@
assertTrue(code.contains("extends Date"));
}
+ @Test
+ public void testBeansXml() {
+ CDIWizard w = new NewCDIFileWizard(CDIWizardType.BEANS_XML).run();
+ w.setSourceFolder(PROJECT_NAME + "/WebContent/WEB-INF");
+ assertTrue(w.canFinish());
+ w.finish();
+ w = new NewCDIFileWizard(CDIWizardType.BEANS_XML).run();
+ assertFalse(w.canFinish());
+ w.cancel();
+ }
+
+ @Test
+ public void testBean() {
+ CDIWizard w = bean("cdi", "Bean1", true, true, false, false, null,
null, null, null);
+ w.finish();
+ util.waitForNonIgnoredJobs();
+ SWTBotEditor ed = new SWTWorkbenchBot().activeEditor();
+ assertTrue(("Bean1.java").equals(ed.getTitle()));
+ String code = ed.toTextEditor().getText();
+ L.fine(code);
+ assertTrue(code.contains("package cdi;"));
+ assertTrue(code.contains("public abstract class Bean1 {"));
+ assertFalse(code.contains("@Named"));
+ assertFalse(code.contains("final"));
+ assertFalse(code.startsWith("/**"));
+
+ w = bean("cdi", "Bean2", false, false, true, true, "",
null, "@Dependent", null);
+ w.finish();
+ util.waitForNonIgnoredJobs();
+ ed = new SWTWorkbenchBot().activeEditor();
+ assertTrue(("Bean2.java").equals(ed.getTitle()));
+ code = ed.toTextEditor().getText();
+ L.fine(code);
+ assertTrue(code.contains("package cdi;"));
+ assertTrue(code.contains("@Named"));
+ assertFalse(code.contains("@Named("));
+ assertTrue(code.contains("@Dependent"));
+ assertTrue(code.contains("final class Bean2 {"));
+ assertTrue(code.startsWith("/**"));
+
+ w = bean("cdi", "Bean3", true, false, false, true,
"TestedBean", null, "@Scope2", "Q1");
+ w.finish();
+ util.waitForNonIgnoredJobs();
+ ed = new SWTWorkbenchBot().activeEditor();
+ assertTrue(("Bean3.java").equals(ed.getTitle()));
+ code = ed.toTextEditor().getText();
+ L.fine(code);
+ assertTrue(code.contains("package cdi;"));
+ assertTrue(code.contains("@Named(\"TestedBean\")"));
+ assertTrue(code.contains("@Scope2"));
+ assertTrue(code.contains("@Q1"));
+ assertTrue(code.contains("public class Bean3 {"));
+ assertFalse(code.contains("final"));
+ assertTrue(code.startsWith("/**"));
+ }
+
+ @Test
+ public void testAnnLiteral() {
+ CDIWizard w = annLiteral("cdi", "AnnL1", true, false, true, false,
"cdi.Q1");
+ w.finish();
+ util.waitForNonIgnoredJobs();
+ SWTBotEditor ed = new SWTWorkbenchBot().activeEditor();
+ //https://issues.jboss.org/browse/JBIDE-8244
+// assertTrue(("AnnL1.java").equals(ed.getTitle()));
+ assertTrue(("Q1Literal.java").equals(ed.getTitle()));
+ String code = ed.toTextEditor().getText();
+ L.info(code);
+ assertTrue(code.contains("package cdi;"));
+ assertTrue(code.contains("public final class Q1Literal extends
AnnotationLiteral<Q1> implements Q1"));
+ assertTrue(code.contains("public static final Q1 INSTANCE = new
Q1Literal();"));
+ assertFalse(code.contains("abstract"));
+ assertFalse(code.startsWith("/**"));
+
+ w = annLiteral("cdi", "AnnL2", false, true, false, true,
"Q2");
+ //https://issues.jboss.org/browse/JBIDE-8244
+ w.setName("AnnL2");
+ w.finish();
+ util.waitForNonIgnoredJobs();
+ ed = new SWTWorkbenchBot().activeEditor();
+ assertTrue(("AnnL2.java").equals(ed.getTitle()));
+ code = ed.toTextEditor().getText();
+ L.info(code);
+ assertTrue(code.contains("package cdi;"));
+ assertTrue(code.contains("abstract class AnnL2 extends AnnotationLiteral<Q2>
implements Q2 {"));
+ assertTrue(code.contains("public static final Q2 INSTANCE = new AnnL2();"));
+ assertFalse(code.substring(code.indexOf("final") +
5).contains("final"));
+ assertTrue(code.contains("abstract"));
+ assertTrue(code.startsWith("/**"));
+ }
+
private static SWTBotMenu nodeContextMenu(final SWTBotTree tree,
SWTBotTreeItem item, final String... menu) {
assert menu.length > 0;
@@ -344,6 +433,7 @@
boolean comments) {
return create(CDIWizardType.QUALIFIER, pkg, name, inherited, comments);
}
+
private CDIWizard scope(String pkg, String name, boolean inherited,
boolean comments, boolean normalScope, boolean passivating) {
@@ -352,6 +442,7 @@
w = w.setNormalScope(normalScope);
return normalScope ? w.setPassivating(passivating) : w;
}
+
private CDIWizard binding(String pkg, String name, String target,
boolean inherited, boolean comments) {
@@ -359,6 +450,7 @@
inherited, comments);
return target != null ? w.setTarget(target) : w;
}
+
private CDIWizard stereotype(String pkg, String name, String scope,
String target, boolean inherited, boolean named,
@@ -370,6 +462,7 @@
}
return target != null ? w.setTarget(target) : w;
}
+
private CDIWizard decorator(String pkg, String name, String intf, String fieldName,
boolean isPublic, boolean isAbstract, boolean isFinal, boolean comments) {
@@ -378,6 +471,7 @@
return fieldName != null ? w.setFieldName(fieldName) : w;
}
+
private CDIWizard interceptor(String pkg, String name, String ibinding,
String superclass, String method, boolean comments) {
CDIWizard w = create(CDIWizardType.INTERCEPTOR, pkg, name, comments);
@@ -390,6 +484,37 @@
return w.addIBinding(ibinding);
}
+
+ private CDIWizard bean(String pkg, String name, boolean isPublic, boolean isAbstract,
+ boolean isFinal, boolean comments, String named,
+ String interfaces, String scope, String qualifier) {
+ CDIWizard w = create(CDIWizardType.BEAN, pkg, name, comments);
+ if (named != null) {
+ w.setNamed(true);
+ if (!"".equals(named.trim())) {
+ w.setNamedName(named);
+ }
+ }
+ w = w.setPublic(isPublic).setFinal(isFinal).setAbstract(isAbstract);
+ if (interfaces != null && !"".equals(interfaces.trim())) {
+ w.addInterface(interfaces);
+ }
+ if (scope != null && !"".equals(scope.trim())) {
+ w.setScope(scope);
+ }
+ if (qualifier != null && !"".equals(qualifier.trim())) {
+ w.addQualifier(qualifier);
+ }
+ return w;
+ }
+
+ private CDIWizard annLiteral(String pkg, String name, boolean isPublic, boolean
isAbstract,
+ boolean isFinal, boolean comments, String qualifier) {
+ assert qualifier != null && !"".equals(qualifier.trim()) :
"Qualifier has to be set";
+ CDIWizard w = create(CDIWizardType.ANNOTATION_LITERAL, pkg, name, comments);
+ return
w.setPublic(isPublic).setFinal(isFinal).setAbstract(isAbstract).addQualifier(qualifier);
+ }
+
private CDIWizard create(CDIWizardType type, String pkg, String name,
boolean inherited, boolean comments) {
return create(type, pkg, name, comments).setInherited(inherited);