Author: scabanovich
Date: 2011-05-20 20:05:23 -0400 (Fri, 20 May 2011)
New Revision: 31407
Added:
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/.classpath
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/.project
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/META-INF/
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/META-INF/MANIFEST.MF
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/build.properties
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/plugin.properties
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/pom.xml
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/ui/
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/ui/test/
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/ui/test/CdiSeamConfigUIAllTests.java
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/ui/test/ContentAssistantTestCase.java
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/ui/test/SeamConfigContentAssistTest.java
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/ui/test/TestUtil.java
Log:
JBIDE-8842
https://issues.jboss.org/browse/JBIDE-8842
tests
Added: trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/.classpath
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/.classpath
(rev 0)
+++ trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/.classpath 2011-05-21 00:05:23
UTC (rev 31407)
@@ -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/JavaSE-1.6"/>
+ <classpathentry kind="con"
path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Property changes on: trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/.classpath
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/.project
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/.project
(rev 0)
+++ trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/.project 2011-05-21 00:05:23
UTC (rev 31407)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.jboss.tools.cdi.seam.config.ui.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>
+ <buildCommand>
+ <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature>
+ </natures>
+</projectDescription>
Property changes on: trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/.project
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/META-INF/MANIFEST.MF
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/META-INF/MANIFEST.MF
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/META-INF/MANIFEST.MF 2011-05-21
00:05:23 UTC (rev 31407)
@@ -0,0 +1,25 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %Bundle-Name.0
+Bundle-SymbolicName: org.jboss.tools.cdi.seam.config.ui.test
+Bundle-Version: 1.0.0.qualifier
+Require-Bundle: org.junit,
+ org.eclipse.ui,
+ org.eclipse.core.resources,
+ org.eclipse.jface.text,
+ org.jboss.tools.common,
+ org.jboss.tools.common.el.core,
+ org.jboss.tools.common.model.ui,
+ org.jboss.tools.cdi.core,
+ org.jboss.tools.cdi.core.test,
+ org.jboss.tools.cdi.seam.config.core,
+ org.jboss.tools.cdi.seam.config.core.test,
+ org.jboss.tools.tests,
+ org.eclipse.core.runtime,
+ org.eclipse.jdt.core
+Bundle-ActivationPolicy: lazy
+Bundle-Vendor: %Bundle-Vendor.0
+Export-Package: org.jboss.tools.cdi.seam.config.ui.test
+Bundle-Localization: plugin
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/META-INF/MANIFEST.MF
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/build.properties
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/build.properties
(rev 0)
+++ trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/build.properties 2011-05-21
00:05:23 UTC (rev 31407)
@@ -0,0 +1,9 @@
+output.. = bin/
+bin.includes = META-INF/,\
+ plugin.properties,\
+ .
+src.includes = src/,\
+ META-INF/,\
+ build.properties
+jars.compile.order = .
+source.. = src/
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/build.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/plugin.properties
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/plugin.properties
(rev 0)
+++ trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/plugin.properties 2011-05-21
00:05:23 UTC (rev 31407)
@@ -0,0 +1,3 @@
+#Properties file for org.jboss.tools.cdi.seam.config.ui.test
+Bundle-Vendor.0 = JBoss by Red Hat
+Bundle-Name.0 = CDI Seam Config UI Tests Plug-in
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/plugin.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/pom.xml
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/pom.xml
(rev 0)
+++ trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/pom.xml 2011-05-21 00:05:23
UTC (rev 31407)
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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.jboss.tools</groupId>
+ <artifactId>org.jboss.tools.parent.pom</artifactId>
+ <version>0.0.2-SNAPSHOT</version>
+ </parent>
+ <groupId>org.jboss.tools.cdi.tests</groupId>
+ <artifactId>org.jboss.tools.cdi.seam.config.ui.test</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <packaging>eclipse-test-plugin</packaging>
+
+ <properties>
+ <emma.filter>org.jboss.tools.cdi*</emma.filter>
+ <emma.instrument.bundles>org.jboss.tools.cdi.core,org.jboss.tools.cdi.seam.config.ui</emma.instrument.bundles>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.sonatype.tycho</groupId>
+ <artifactId>maven-osgi-test-plugin</artifactId>
+ <configuration>
+ <explodedBundles>
+ <bundle>org.jboss.tools.cdi.core.test</bundle>
+ </explodedBundles>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Property changes on: trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/pom.xml
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/ui/test/CdiSeamConfigUIAllTests.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/ui/test/CdiSeamConfigUIAllTests.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/ui/test/CdiSeamConfigUIAllTests.java 2011-05-21
00:05:23 UTC (rev 31407)
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.cdi.seam.config.ui.test;
+
+import org.eclipse.jdt.internal.core.JavaModelManager;
+import org.jboss.tools.cdi.core.test.CDICoreTestSetup;
+import org.jboss.tools.cdi.seam.config.core.test.SeamConfigTestSetup;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class CdiSeamConfigUIAllTests {
+
+ public static Test suite() {
+ // it could be done here because it is not needed to be enabled back
+ JavaModelManager.getIndexManager().disable();
+
+ TestSuite suiteAll = new TestSuite("CDI Config UI Tests");
+
+ TestSuite suiteConfig = new TestSuite("CDI Seam Config UI Tests");
+ suiteConfig.addTestSuite(SeamConfigContentAssistTest.class);
+
+ suiteAll.addTest(new SeamConfigTestSetup(suiteConfig));
+
+ return suiteAll;
+ }
+}
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/ui/test/CdiSeamConfigUIAllTests.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/ui/test/ContentAssistantTestCase.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/ui/test/ContentAssistantTestCase.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/ui/test/ContentAssistantTestCase.java 2011-05-21
00:05:23 UTC (rev 31407)
@@ -0,0 +1,248 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2010 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.cdi.seam.config.ui.test;
+
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContentAssistant;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
+import org.eclipse.wst.sse.ui.StructuredTextEditor;
+import org.eclipse.wst.sse.ui.internal.StructuredTextViewer;
+import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal;
+import org.jboss.tools.common.editor.ObjectMultiPageEditor;
+import org.jboss.tools.common.model.ui.editor.EditorPartWrapper;
+import org.jboss.tools.common.text.ext.util.Utils;
+import org.jboss.tools.test.util.WorkbenchUtils;
+
+//copied from ContentAssistantTestCase - they should have common super class
+public class ContentAssistantTestCase extends TestCase {
+ protected IProject project = null;
+ protected IEditorPart editor = null;
+ protected StructuredTextEditor jspTextEditor = null;
+ protected StructuredTextViewer viewer = null;
+ protected IContentAssistant contentAssistant = null;
+ protected IDocument document = null;
+
+ public void openEditor(String fileName) {
+ IEditorPart editorPart = WorkbenchUtils.openEditor(project.getName()+"/"+
fileName); //$NON-NLS-1$
+ editor = editorPart;
+
+//getting editor start
+ if(editorPart instanceof EditorPartWrapper) {
+ editorPart = ((EditorPartWrapper)editorPart).getEditor();
+ }
+ if (editorPart instanceof ObjectMultiPageEditor) {
+ jspTextEditor = ((ObjectMultiPageEditor) editorPart).getSourceEditor();
+ } else if (editorPart instanceof StructuredTextEditor) {
+ jspTextEditor = (StructuredTextEditor)editorPart;
+ }
+
+ // clean deffered events
+ while (Display.getCurrent().readAndDispatch());
+
+//getting editor end.
+
+ viewer = jspTextEditor.getTextViewer();
+ document = viewer.getDocument();
+ SourceViewerConfiguration config = TestUtil
+ .getSourceViewerConfiguration(jspTextEditor);
+ contentAssistant = (config == null ? null : config
+ .getContentAssistant(viewer));
+
+ assertTrue(
+ "Cannot get the Content Assistant instance for the editor for page \""
//$NON-NLS-1$
+ + fileName + "\"", (contentAssistant != null)); //$NON-NLS-1$
+
+ assertTrue("The IDocument is not instance of IStructuredDocument for page
\"" //$NON-NLS-1$
+ + fileName + "\"", //$NON-NLS-1$
+ (document instanceof IStructuredDocument));
+
+ }
+
+ public ICompletionProposal[] checkProposals(String fileName, int offset, String[]
proposals, boolean exactly) {
+ return checkProposals(fileName, null, offset, proposals, exactly, true);
+ }
+
+ public ICompletionProposal[] checkProposals(String fileName, String substring, int
offset, String[] proposals, boolean exactly) {
+ return checkProposals(fileName, substring, offset, proposals, exactly, false);
+ }
+ public ICompletionProposal[] checkProposals(String fileName, String substring, int
offset, String[] proposals, boolean exactly, boolean excludeELProposalsFromExactTest){
+ openEditor(fileName);
+
+ int position = 0;
+ if (substring != null) {
+ String documentContent = document.get();
+ position = documentContent.indexOf(substring);
+ }
+
+ List<ICompletionProposal> res = TestUtil.collectProposals(contentAssistant,
viewer, position+offset);
+
+ assertTrue("Content Assistant returned no proposals", (res != null
&& res.size() > 0)); //$NON-NLS-1$
+
+ // for (int i = 0; i < result.length; i++) {
+ // System.out.println("proposal - "+result[i].getDisplayString());
+ // }
+
+ ICompletionProposal[] result = res.toArray(new ICompletionProposal[res.size()]);
+ int foundCounter = 0;
+ for (int i = 0; i < proposals.length; i++) {
+ boolean found = compareProposal(proposals[i], result);
+ if (found)
+ foundCounter++;
+ assertTrue("Proposal " + proposals[i] + " not found!",
found ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ if (exactly) {
+ if (excludeELProposalsFromExactTest) {
+ assertTrue("Some other proposals were found!", foundCounter ==
proposals.length); //$NON-NLS-1$
+ } else {
+ assertTrue("Some other proposals were found!", result.length ==
proposals.length); //$NON-NLS-1$
+ }
+ }
+
+// System.out.println("checkProposals <<< Exiting");
+ return result;
+ }
+
+ //CustomCompletionProposal instead of AutoContentAssistantProposal
+ public boolean compareProposal(String proposalName, ICompletionProposal[] proposals){
+ for (int i = 0; i < proposals.length; i++) {
+ if (proposals[i] instanceof CustomCompletionProposal) {
+ CustomCompletionProposal ap = (CustomCompletionProposal)proposals[i];
+
+ if(proposals[i].getClass() == CustomCompletionProposal.class) {
+ //It is wtp's proposal - ignore it.
+ continue;
+ }
+
+ String replacementString = ap.getReplacementString().toLowerCase();
+ if (replacementString.equalsIgnoreCase(proposalName)) return true;
+
+
+ // For a tag proposal there will be not only the the tag name but all others
characters like default attributes, tag ending characters and so on
+ if (replacementString.indexOf("/>") != -1) {
+ replacementString = replacementString.substring(0,
replacementString.indexOf("/>"));
+ }
+ if (replacementString.indexOf('>') != -1) {
+ replacementString = replacementString.substring(0,
replacementString.indexOf('>'));
+ }
+ if (replacementString.equalsIgnoreCase(proposalName)) return true;
+
+ String[] replacementStringParts = replacementString.split(" ");
//$NON-NLS-1$
+ if (replacementStringParts != null && replacementStringParts.length > 0)
{
+ if (replacementStringParts[0].equalsIgnoreCase(proposalName)) return true;
+ }
+
+ // for an attribute proposal there will be a pare of attribute-value (i.e.
attrName="attrValue")
+ replacementStringParts = replacementString.split("="); //$NON-NLS-1$
+ if (replacementStringParts != null && replacementStringParts.length > 0)
{
+ if (replacementStringParts[0].equalsIgnoreCase(proposalName)) return true;
+ }
+
+ // for an Unclosed EL the closing character is appended to the proposal string (i.e.
person} )
+ // perform case sensitive compare operation
+ replacementStringParts = replacementString.split("}"); //$NON-NLS-1$
+ if (replacementStringParts != null && replacementStringParts.length > 0)
{
+ if (replacementStringParts[0].equals(proposalName)) return true;
+ }
+
+ // For an attribute value proposal there will be the quote characters
+ replacementString = Utils.trimQuotes(replacementString);
+ if (replacementString.equalsIgnoreCase(proposalName)) return true;
+
+ } else {
+ if(proposals[i].getDisplayString().toLowerCase().equals(proposalName.toLowerCase()))
return true;
+ }
+ }
+ return false;
+ }
+
+ public void closeEditor() {
+ if (editor != null) {
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+ .getActivePage().closeEditor(editor, false);
+ editor = null;
+ }
+ }
+
+ /**
+ * @return the project
+ */
+ public IProject getProject() {
+ return project;
+ }
+
+ /**
+ * @param project the project to set
+ */
+ public void setProject(IProject project) {
+ this.project = project;
+ }
+
+ /**
+ * @return the jspTextEditor
+ */
+ public StructuredTextEditor getTextEditor() {
+ return jspTextEditor;
+ }
+
+ /**
+ * @return the viewer
+ */
+ public StructuredTextViewer getViewer() {
+ return viewer;
+ }
+
+ /**
+ * @param viewer the viewer to set
+ */
+ public void setViewer(StructuredTextViewer viewer) {
+ this.viewer = viewer;
+ }
+
+ /**
+ * @return the contentAssistant
+ */
+ public IContentAssistant getContentAssistant() {
+ return contentAssistant;
+ }
+
+ /**
+ * @param contentAssistant the contentAssistant to set
+ */
+ public void setContentAssistant(IContentAssistant contentAssistant) {
+ this.contentAssistant = contentAssistant;
+ }
+
+ /**
+ * @return the document
+ */
+ public IDocument getDocument() {
+ return document;
+ }
+
+ /**
+ * @param document the document to set
+ */
+ public void setDocument(IDocument document) {
+ this.document = document;
+ }
+}
\ No newline at end of file
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/ui/test/ContentAssistantTestCase.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/ui/test/SeamConfigContentAssistTest.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/ui/test/SeamConfigContentAssistTest.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/ui/test/SeamConfigContentAssistTest.java 2011-05-21
00:05:23 UTC (rev 31407)
@@ -0,0 +1,69 @@
+package org.jboss.tools.cdi.seam.config.ui.test;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.jboss.tools.cdi.core.CDICorePlugin;
+import org.jboss.tools.cdi.core.ICDIProject;
+import org.jboss.tools.test.util.ResourcesUtils;
+
+public class SeamConfigContentAssistTest extends ContentAssistantTestCase {
+ protected static String PLUGIN_ID =
"org.jboss.tools.cdi.seam.config.core.test";
+ protected static String PROJECT_NAME = "CDIConfigTest";
+ protected static String PROJECT_PATH = "/projects/CDIConfigTest";
+
+ protected static String FILE_PATH = "src/META-INF/seam-beans.xml";
+
+ protected ICDIProject cdiProject;
+
+ public SeamConfigContentAssistTest() {
+ project = getTestProject();
+ cdiProject = CDICorePlugin.getCDIProject(project, false);
+ }
+
+ public IProject getTestProject() {
+ if(project==null) {
+ try {
+ project = findTestProject();
+ if(project==null || !project.exists()) {
+ project = ResourcesUtils.importProject(PLUGIN_ID, PROJECT_PATH);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Can't import CDI test project: " + e.getMessage());
+ }
+ }
+ return project;
+ }
+
+ public static IProject findTestProject() {
+ return ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME);
+ }
+
+ public void testCustomClasses() {
+ String[] proposals = {"test01:MyBean1", "test01:MyBean2",
"test01:MyBean3", "test01:MyBean4"};
+ checkProposals(FILE_PATH, "<test01:", 8, proposals, true);
+ }
+
+ public void testEEClassesAndKeyWords() {
+ String[] proposals = {"s:modifies"};
+ checkProposals(FILE_PATH, "<s:mo", 5, proposals, true);
+ proposals = new String[]{"s:modifies", "s:replaces",
"s:parameters",
+ "s:Inject", "s:Alternative", "s:Delegate",
"s:Dependent", "s:Disposes",
+ "s:Named", "s:New", "s:NormalScope"};
+ checkProposals(FILE_PATH, "<s:mo", 3, proposals, false);
+ }
+
+ public void testPackageInNamespace() {
+ String[] proposals = {
+ "urn:java:org.jboss.beans.test01",
+ "urn:java:org.jboss.beans.test02",
+ "urn:java:org.jboss.beans.test03",
+ "urn:java:org.jboss.beans.test04",
+ "urn:java:org.jboss.beans.test05",
+ "urn:java:org.jboss.beans.test06"};
+ String text = "urn:java:org.jboss.beans.";
+ checkProposals(FILE_PATH, text, text.length(), proposals, false);
+ }
+
+
+}
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/ui/test/SeamConfigContentAssistTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/ui/test/TestUtil.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/ui/test/TestUtil.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/ui/test/TestUtil.java 2011-05-21
00:05:23 UTC (rev 31407)
@@ -0,0 +1,144 @@
+package org.jboss.tools.cdi.seam.config.ui.test;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.TextUtilities;
+import org.eclipse.jface.text.contentassist.ContentAssistant;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.text.contentassist.IContentAssistant;
+import org.eclipse.jface.text.contentassist.IContentAssistantExtension;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.texteditor.AbstractTextEditor;
+import org.eclipse.wst.sse.ui.internal.contentassist.StructuredContentAssistant;
+import org.jboss.tools.common.text.xml.contentassist.ProposalSorter;
+
+//copied from org.jboss.tools.jst.jsp.test.TestUtil
+//TODO remove this class and move original to common
+public class TestUtil {
+
+ /** The Constant MAX_IDLE. */
+ public static final long MAX_IDLE = 5*60*1000L;
+
+ /**
+ * Returns the CA Processor from content assistant for the given offset in the
document.
+ *
+ *
+ * @param viewer
+ * @param offset
+ * @param ca
+ */
+
+ public static IContentAssistProcessor getProcessor(ITextViewer viewer, int offset,
IContentAssistant ca) {
+ try {
+ IDocument document= viewer.getDocument();
+ String type= TextUtilities.getContentType(document,
((IContentAssistantExtension)ca).getDocumentPartitioning(), offset, true);
+ return ca.getContentAssistProcessor(type);
+ } catch (BadLocationException x) {
+ }
+
+ return null;
+ }
+
+ /**
+ * Process UI input but do not return for the specified time interval.
+ *
+ * @param waitTimeMillis
+ * the number of milliseconds
+ */
+ public static void delay(long waitTimeMillis) {
+ Display display = Display.getCurrent();
+
+ // If this is the UI thread,
+ // then process input.
+ if (display != null) {
+ long endTimeMillis = System.currentTimeMillis() + waitTimeMillis;
+ while (System.currentTimeMillis() < endTimeMillis) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ display.update();
+ }
+ // Otherwise, perform a simple sleep.
+ else {
+ try {
+ Thread.sleep(waitTimeMillis);
+ } catch (InterruptedException e) {
+ // Ignored.
+ }
+ }
+ }
+
+ /**
+ * Wait for idle.
+ */
+ public static void waitForIdle(long maxIdle) {
+ long start = System.currentTimeMillis();
+ while (!Job.getJobManager().isIdle()) {
+ delay(500);
+ if ( (System.currentTimeMillis()-start) > maxIdle )
+ throw new RuntimeException("A long running task detected"); //$NON-NLS-1$
+ }
+ }
+
+ public static SourceViewerConfiguration getSourceViewerConfiguration(AbstractTextEditor
editor) {
+ Class editorClass = editor.getClass();
+ while (editorClass != null) {
+ try {
+ Method m = editorClass.getDeclaredMethod("getSourceViewerConfiguration",
new Class[] {});
+
+ if(m != null) {
+ m.setAccessible(true);
+ Object result = m.invoke(editor, new Object[]{});
+ return (result instanceof SourceViewerConfiguration ?
(SourceViewerConfiguration)result : null);
+ }
+ } catch (NoSuchMethodException ne) {
+ } catch (Exception e) {
+ }
+ editorClass = editorClass.getSuperclass();
+ }
+ return null;
+
+ }
+
+ public static void prepareCAInvokation(IContentAssistant ca, ITextViewer viewer, int
offset) {
+ if (ca == null || viewer == null)
+ return;
+
+ // sets cursor position
+ viewer.getTextWidget().setCaretOffset(offset);
+
+ TestUtil.waitForIdle(TestUtil.MAX_IDLE);
+ TestUtil.delay(1000);
+
+ ca.showPossibleCompletions();
+ }
+
+ public static int MAX_CATEGORIES_COUNT = 10;
+ public static List<ICompletionProposal> collectProposals(IContentAssistant ca,
ITextViewer viewer, int offset) {
+ prepareCAInvokation(ca, viewer, offset);
+
+ final IContentAssistProcessor p= TestUtil.getProcessor(viewer, offset, ca);
+ List<ICompletionProposal> res= new ArrayList<ICompletionProposal>();
+ // Try to acquire all the proposal categories assuming that there are less than 10 or
equal
+ for (int i = 0; i < MAX_CATEGORIES_COUNT && p != null; i++) {
+ ICompletionProposal[] result= p.computeCompletionProposals(viewer, offset);
+ for (int j = 0; result != null && j < result.length; j++) {
+ res.add(result[j]);
+ }
+ }
+ return ProposalSorter.filterAndSortProposals(res, null, null);
+ }
+
+}
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.seam.config.ui.test/src/org/jboss/tools/cdi/seam/config/ui/test/TestUtil.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain