Author: vpakan(a)redhat.com
Date: 2011-06-15 07:54:53 -0400 (Wed, 15 Jun 2011)
New Revision: 32119
Added:
trunk/jsf/tests/org.jboss.tools.jsf.ui.bot.test/src/org/jboss/tools/jsf/ui/bot/test/smoke/FacesConfigCodeCompletionTest.java
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.ui.bot.test/src/org/jboss/tools/jsf/ui/bot/test/JSFAllBotTests.java
trunk/jsf/tests/org.jboss.tools.jsf.ui.bot.test/src/org/jboss/tools/jsf/ui/bot/test/smoke/CodeCompletionTest.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/ReflectionsHelper.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/ContentAssistBot.java
Log:
Added faces-config.xml file Code Completion Test.
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.ui.bot.test/src/org/jboss/tools/jsf/ui/bot/test/JSFAllBotTests.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.ui.bot.test/src/org/jboss/tools/jsf/ui/bot/test/JSFAllBotTests.java 2011-06-15
09:41:53 UTC (rev 32118)
+++
trunk/jsf/tests/org.jboss.tools.jsf.ui.bot.test/src/org/jboss/tools/jsf/ui/bot/test/JSFAllBotTests.java 2011-06-15
11:54:53 UTC (rev 32119)
@@ -15,6 +15,7 @@
import org.jboss.tools.jsf.ui.bot.test.smoke.AddRemoveJSFCapabilitiesTest;
import org.jboss.tools.jsf.ui.bot.test.smoke.CodeCompletionTest;
import org.jboss.tools.jsf.ui.bot.test.smoke.CreateNewJSFProjectTest;
+import org.jboss.tools.jsf.ui.bot.test.smoke.FacesConfigCodeCompletionTest;
import org.jboss.tools.jsf.ui.bot.test.smoke.OpenOnTest;
import org.jboss.tools.jsf.ui.bot.test.templates.SetTemplateForUnknownTagTest;
import org.jboss.tools.jsf.ui.bot.test.templates.UnknownTemplateTest;
@@ -42,6 +43,7 @@
suite.addTestSuite(JSF2AttributeRenameTest.class);
suite.addTestSuite(OpenOnTest.class);
suite.addTestSuite(CodeCompletionTest.class);
+ suite.addTestSuite(FacesConfigCodeCompletionTest.class);
return suite;
}
}
\ No newline at end of file
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.ui.bot.test/src/org/jboss/tools/jsf/ui/bot/test/smoke/CodeCompletionTest.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.ui.bot.test/src/org/jboss/tools/jsf/ui/bot/test/smoke/CodeCompletionTest.java 2011-06-15
09:41:53 UTC (rev 32118)
+++
trunk/jsf/tests/org.jboss.tools.jsf.ui.bot.test/src/org/jboss/tools/jsf/ui/bot/test/smoke/CodeCompletionTest.java 2011-06-15
11:54:53 UTC (rev 32119)
@@ -144,7 +144,7 @@
"Editor Text is\n" + editor.getText(),
editor.getText().contains(expectedInsertedText));
editor.save();
- // check Content Assist insertion of jsfc attribute attribute
+ // check Content Assist content of jsfc attribute attribute
ContentAssistHelper.checkContentAssistContent(SWTTestExt.bot,
FACELETS_TEST_PAGE,
expectedInsertedText,
Added:
trunk/jsf/tests/org.jboss.tools.jsf.ui.bot.test/src/org/jboss/tools/jsf/ui/bot/test/smoke/FacesConfigCodeCompletionTest.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.ui.bot.test/src/org/jboss/tools/jsf/ui/bot/test/smoke/FacesConfigCodeCompletionTest.java
(rev 0)
+++
trunk/jsf/tests/org.jboss.tools.jsf.ui.bot.test/src/org/jboss/tools/jsf/ui/bot/test/smoke/FacesConfigCodeCompletionTest.java 2011-06-15
11:54:53 UTC (rev 32119)
@@ -0,0 +1,204 @@
+/*******************************************************************************
+ * Copyright (c) 2007-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,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jsf.ui.bot.test.smoke;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
+import org.jboss.tools.jsf.ui.bot.test.JSFAutoTestCase;
+import org.jboss.tools.ui.bot.ext.SWTTestExt;
+import org.jboss.tools.ui.bot.ext.helper.ContentAssistHelper;
+import org.jboss.tools.ui.bot.ext.parts.SWTBotEditorExt;
+import org.jboss.tools.ui.bot.ext.types.IDELabel;
+import org.jboss.tools.vpe.ui.bot.test.VPEAutoTestCase;
+/** * Test Code Completion functionality of faces-config.xml file
+ * @author Vladimir Pakan
+ *
+ */
+public class FacesConfigCodeCompletionTest extends JSFAutoTestCase{
+
+ private static final String FACES_CONFIG_FILE_NAME = "faces-config.xml";
+ private SWTBotEditor facesConfigEditor;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ facesConfigEditor = eclipse.openFile(VPEAutoTestCase.JBT_TEST_PROJECT_NAME,
+ "WebContent",
+ "WEB-INF",
+ FacesConfigCodeCompletionTest.FACES_CONFIG_FILE_NAME);
+ new SWTBotEditorExt(facesConfigEditor.toTextEditor().getReference(),bot)
+ .selectPage(IDELabel.FacesConfigEditor.SOURCE_TAB_LABEL);
+ }
+ @Override
+ protected void tearDown() throws Exception {
+ if (facesConfigEditor != null){
+ facesConfigEditor.saveAndClose();
+ }
+ super.tearDown();
+ }
+ /**
+ * Test Code Completion functionality of faces-config.xml file
+ */
+ public void testCodeCompletionOfFacesConfig(){
+ String textToSelect = "<managed-bean>";
+ // check Content Assist inside <faces-config> node
+ ContentAssistHelper.checkContentAssistContent(SWTTestExt.bot,
+ FacesConfigCodeCompletionTest.FACES_CONFIG_FILE_NAME,
+ textToSelect,
+ 0,
+ 0,
+ 0,
+ getInsideFacesConfigTagProposalList());
+ textToSelect = "<description>User Name Bean</description>";
+ // check Content Assist inside <managed-bean> node
+ ContentAssistHelper.checkContentAssistContent(SWTTestExt.bot,
+ FacesConfigCodeCompletionTest.FACES_CONFIG_FILE_NAME,
+ textToSelect,
+ 0,
+ 0,
+ 0,
+ getInsideManagedBeanTagProposalList());
+ textToSelect = "<property-name>name</property-name>";
+ // check Content Assist inside <managed-property> node
+ ContentAssistHelper.checkContentAssistContent(SWTTestExt.bot,
+ FacesConfigCodeCompletionTest.FACES_CONFIG_FILE_NAME,
+ textToSelect,
+ 0,
+ 0,
+ 0,
+ getInsideManagedPropertyTagProposalList());
+ textToSelect = "<from-view-id>";
+ // check Content Assist inside <navigation-rule> node
+ ContentAssistHelper.checkContentAssistContent(SWTTestExt.bot,
+ FacesConfigCodeCompletionTest.FACES_CONFIG_FILE_NAME,
+ textToSelect,
+ 0,
+ 0,
+ 0,
+ getInsideNavigationRuleTagProposalList());
+ textToSelect = "<from-outcome>";
+ // check Content Assist inside <navigation-case> node
+ ContentAssistHelper.checkContentAssistContent(SWTTestExt.bot,
+ FacesConfigCodeCompletionTest.FACES_CONFIG_FILE_NAME,
+ textToSelect,
+ 0,
+ 0,
+ 0,
+ getInsideNavigationCaseTagProposalList());
+ }
+ /**
+ * Returns list of expected proposals inside <faces-config> tag
+ * @return
+ */
+ private static List<String> getInsideFacesConfigTagProposalList(){
+ LinkedList<String> result = new LinkedList<String>();
+
+ result.add("application");
+ result.add("component");
+ result.add("converter");
+ result.add("faces-config-extension");
+ result.add("factory");
+ result.add("lifecycle");
+ result.add("managed-bean");
+ result.add("navigation-rule");
+ result.add("referenced-bean");
+ result.add("render-kit");
+ result.add("validator");
+ result.add("XSL processing instruction - XSL processing instruction");
+ result.add("comment - xml comment");
+ result.add("user : User");
+
+ return result;
+ }
+ /**
+ * Returns list of expected proposals inside <managed-bean> tag
+ * @return
+ */
+ private static List<String> getInsideManagedBeanTagProposalList(){
+ LinkedList<String> result = new LinkedList<String>();
+
+ result.add("description");
+ result.add("display-name");
+ result.add("icon");
+ result.add("list-entries");
+ result.add("managed-bean-class");
+ result.add("managed-bean-extension");
+ result.add("managed-bean-name");
+ result.add("managed-bean-scope");
+ result.add("managed-property");
+ result.add("map-entries");
+ result.add("XSL processing instruction - XSL processing instruction");
+ result.add("comment - xml comment");
+ result.add("user : User");
+ return result;
+ }
+ /**
+ * Returns list of expected proposals inside <managed-property> tag
+ * @return
+ */
+ private static List<String> getInsideManagedPropertyTagProposalList(){
+ LinkedList<String> result = new LinkedList<String>();
+
+ result.add("description");
+ result.add("display-name");
+ result.add("icon");
+ result.add("list-entries");
+ result.add("map-entries");
+ result.add("null-value");
+ result.add("property-class");
+ result.add("property-name");
+ result.add("value");
+ result.add("XSL processing instruction - XSL processing instruction");
+ result.add("comment - xml comment");
+ result.add("user : User");
+ return result;
+ }
+ /**
+ * Returns list of expected proposals inside <navigation-rule> tag
+ * @return
+ */
+ private static List<String> getInsideNavigationRuleTagProposalList(){
+ LinkedList<String> result = new LinkedList<String>();
+
+ result.add("description");
+ result.add("display-name");
+ result.add("icon");
+ result.add("from-view-id");
+ result.add("navigation-case");
+ result.add("navigation-rule-extension");
+ result.add("XSL processing instruction - XSL processing instruction");
+ result.add("comment - xml comment");
+ result.add("user : User");
+ return result;
+ }
+ /**
+ * Returns list of expected proposals inside <navigation-case> tag
+ * @return
+ */
+ private static List<String> getInsideNavigationCaseTagProposalList(){
+ LinkedList<String> result = new LinkedList<String>();
+
+ result.add("description");
+ result.add("display-name");
+ result.add("from-action");
+ result.add("icon");
+ result.add("from-outcome");
+ result.add("redirect");
+ result.add("to-view-id");
+ result.add("XSL processing instruction - XSL processing instruction");
+ result.add("comment - xml comment");
+ result.add("user : User");
+ return result;
+ }
+
+}
\ No newline at end of file
Property changes on:
trunk/jsf/tests/org.jboss.tools.jsf.ui.bot.test/src/org/jboss/tools/jsf/ui/bot/test/smoke/FacesConfigCodeCompletionTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/ReflectionsHelper.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/ReflectionsHelper.java 2011-06-15
09:41:53 UTC (rev 32118)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/ReflectionsHelper.java 2011-06-15
11:54:53 UTC (rev 32119)
@@ -12,6 +12,8 @@
package org.jboss.tools.ui.bot.ext.helper;
import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import org.apache.log4j.Logger;
/**
@@ -35,5 +37,73 @@
return null;
}
}
+ /**
+ * Invoke method methodName of class clazz on instance and return return value
+ * @param <T>
+ * @param clazz
+ * @param methodName
+ * @param instance
+ * @param resultClazz
+ * @return
+ * @throws SecurityException
+ * @throws NoSuchMethodException
+ * @throws IllegalArgumentException
+ * @throws IllegalAccessException
+ * @throws InvocationTargetException
+ */
+ @SuppressWarnings("unchecked")
+ public static <T> T retrieveMethodReturnValue(Class<?> clazz,
+ String methodName, Object instance, Class<T> resultClazz)
+ throws SecurityException, NoSuchMethodException,
+ IllegalArgumentException, IllegalAccessException,
+ InvocationTargetException {
+
+ Method[] methods = clazz.getDeclaredMethods();
+ boolean notFound = true;
+ int index = 0;
+ while (notFound && methods.length > index) {
+ if (methods[index].getName().equals(methodName)) {
+ notFound = false;
+ } else {
+ index++;
+ }
+ }
+
+ if (!notFound) {
+ methods[index].setAccessible(true);
+ Object value = methods[index].invoke(instance);
+ if (value != null) {
+ return (T) value;
+ } else {
+ return null;
+ }
+
+ } else {
+ throw new NoSuchMethodException(methodName);
+ }
+ }
+ /**
+ * Returns true if class clazz implements method methodName
+ * @param clazz
+ * @param methodName
+ * @return
+ */
+ public static boolean isClassImplementingMethod(Class<?> clazz,
+ String methodName) {
+
+ Method[] methods = clazz.getDeclaredMethods();
+ boolean notFound = true;
+ int index = 0;
+ while (notFound && methods.length > index) {
+ if (methods[index].getName().equals(methodName)) {
+ notFound = false;
+ } else {
+ index++;
+ }
+ }
+
+ return !notFound;
+
+ }
}
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/ContentAssistBot.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/ContentAssistBot.java 2011-06-15
09:41:53 UTC (rev 32118)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/parts/ContentAssistBot.java 2011-06-15
11:54:53 UTC (rev 32119)
@@ -5,6 +5,7 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
@@ -18,10 +19,13 @@
import org.eclipse.swtbot.swt.finder.results.VoidResult;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
+import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.forms.editor.FormEditor;
+import org.eclipse.ui.part.MultiPageEditorPart;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.swtbot.swt.finder.results.Result;
+import org.jboss.tools.ui.bot.ext.helper.ReflectionsHelper;
/**
* This provides working Content assist functionality.
@@ -130,6 +134,55 @@
});
}
+ /* More accurate check here will be
+ (oEditor instanceof org.jboss.tools.common.model.ui.editor.EditorPartWrapper)
+ but using Reflections dependency on org.jboss.tools.common.model.ui.editor is
omitted
+ */
+ else if (ReflectionsHelper.isClassImplementingMethod(oEditor.getClass(),
"getEditor")){
+ final IEditorPart innerEditor;
+ try {
+ innerEditor = (IEditorPart)ReflectionsHelper.retrieveMethodReturnValue(
+ oEditor.getClass(),
+ "getEditor",
+ oEditor,
+ IEditorPart.class);
+ if (innerEditor instanceof MultiPageEditorPart){
+ textEditor = syncExec(new Result<ITextEditor>() {
+ public ITextEditor run() {
+ ITextEditor result = null;
+ try {
+ result =
(ITextEditor)ReflectionsHelper.retrieveMethodReturnValue(MultiPageEditorPart.class,
+ "getActiveEditor",
+ innerEditor,
+ IEditorPart.class);
+ } catch (SecurityException e) {
+ e.printStackTrace();
+ } catch (IllegalArgumentException e) {
+ e.printStackTrace();
+ } catch (NoSuchMethodException e) {
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
+ }
+ return result;
+ }
+ });
+ }
+
+ } catch (SecurityException e1) {
+ e1.printStackTrace();
+ } catch (IllegalArgumentException e1) {
+ e1.printStackTrace();
+ } catch (NoSuchMethodException e1) {
+ e1.printStackTrace();
+ } catch (IllegalAccessException e1) {
+ e1.printStackTrace();
+ } catch (InvocationTargetException e1) {
+ e1.printStackTrace();
+ }
+ }
else{
textEditor = (ITextEditor)oEditor;
}