Author: vrubezhny
Date: 2011-10-03 15:37:40 -0400 (Mon, 03 Oct 2011)
New Revision: 35296
Added:
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/jsp/ca/test/CAForELJavaAndJSTCompareTest.java
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.test/projects/JSF2KickStartWithoutLibs/JavaSource/demo/User.java
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/META-INF/MANIFEST.MF
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/JsfUiAllTests.java
Log:
JBIDE-9792
EL Content Assistant for java files should show sources of El elements as it does for jsp
files.
JUnit Test is added for the issue
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.test/projects/JSF2KickStartWithoutLibs/JavaSource/demo/User.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.test/projects/JSF2KickStartWithoutLibs/JavaSource/demo/User.java 2011-10-03
19:19:15 UTC (rev 35295)
+++
trunk/jsf/tests/org.jboss.tools.jsf.test/projects/JSF2KickStartWithoutLibs/JavaSource/demo/User.java 2011-10-03
19:37:40 UTC (rev 35296)
@@ -20,6 +20,7 @@
@SessionScoped
public class User {
private String name;
+ private String testString = "#{user.name}";
public User() {
}
Modified: trunk/jsf/tests/org.jboss.tools.jsf.ui.test/META-INF/MANIFEST.MF
===================================================================
--- trunk/jsf/tests/org.jboss.tools.jsf.ui.test/META-INF/MANIFEST.MF 2011-10-03 19:19:15
UTC (rev 35295)
+++ trunk/jsf/tests/org.jboss.tools.jsf.ui.test/META-INF/MANIFEST.MF 2011-10-03 19:37:40
UTC (rev 35296)
@@ -36,6 +36,8 @@
org.eclipse.wst.validation,
org.eclipse.wst.html.core;bundle-version="1.1.500",
org.eclipse.wst.html.ui;bundle-version="1.0.600",
- org.jboss.tools.jst.jsp.base.test;bundle-version="3.3.0"
+ org.jboss.tools.jst.jsp.base.test;bundle-version="3.3.0",
+ org.jboss.tools.common.el.ui;bundle-version="3.3.0",
+ org.eclipse.jdt.ui;bundle-version="3.7.0"
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Added:
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/jsp/ca/test/CAForELJavaAndJSTCompareTest.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/jsp/ca/test/CAForELJavaAndJSTCompareTest.java
(rev 0)
+++
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/jsp/ca/test/CAForELJavaAndJSTCompareTest.java 2011-10-03
19:37:40 UTC (rev 35296)
@@ -0,0 +1,191 @@
+/*******************************************************************************
+ * Copyright (c) 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.jsp.ca.test;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
+import org.eclipse.jface.text.IDocument;
+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.source.ISourceViewer;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.FileEditorInput;
+import org.jboss.tools.common.base.test.contentassist.CATestUtil;
+import org.jboss.tools.common.el.ui.ca.ELProposalProcessor;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.jst.jsp.contentassist.AutoELContentAssistantProposal;
+import org.jboss.tools.jst.jsp.test.ca.ContentAssistantTestCase;
+import org.jboss.tools.test.util.JobUtils;
+import org.jboss.tools.test.util.ProjectImportTestSetup;
+
+/**
+ * The JUnit test case for JBIDE-9792 issue
+ *
+ * @author Victor V. Rubezhny
+ *
+ */
+public class CAForELJavaAndJSTCompareTest extends ContentAssistantTestCase {
+ private static final String PROJECT_NAME = "JSF2KickStartWithoutLibs";
+ private static final String PAGE_NAME = "WebContent/pages/inputname.xhtml";
+ private static final String JAVA_FILENAME = "/demo/User.java";
+ private static final String PREFIXES[] = new String[] {"#{us" ,
"#{user.na"};
+
+ public void setUp() throws Exception {
+ project = ProjectImportTestSetup.loadProject(PROJECT_NAME);
+ project.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
+ }
+
+ public static Test suite() {
+ return new TestSuite(CAForELJavaAndJSTCompareTest.class);
+ }
+
+ public void testCAForELJavaAndJSTCompare () {
+ for (String prefix : PREFIXES) {
+ ELProposalProcessor.Proposal javaProposals[] = getJavaEditorProposals(prefix);
+ assertFalse ("No EL Proposals found in Java file: " + JAVA_FILENAME,
(javaProposals == null || javaProposals.length == 0));
+ assertTrue ("Content Assist in returned more than 1 proposal for Java file:
" + JAVA_FILENAME +
+ ". Test project and/or data should be verfied/updated.",
(javaProposals.length == 1));
+
+ AutoELContentAssistantProposal jstProposals[] = getJSTProposals(prefix);
+ assertFalse ("No EL Proposals found in Web page: " + PAGE_NAME,
(jstProposals == null || jstProposals.length == 0));
+ assertTrue ("Content Assist in returned more than 1 proposal for Web page: "
+ PAGE_NAME +
+ ". Test project and/or data should be verfied/updated.",
(jstProposals.length == 1));
+
+ compareJavaAndJSTProposals(javaProposals[0], jstProposals[0]);
+ }
+ }
+
+ private ELProposalProcessor.Proposal[] getJavaEditorProposals(String prefix) {
+ assertTrue("Test project \"" + PROJECT_NAME + "\" is not
loaded", (project != null));
+
+ IFolder srcRoot = (IFolder)EclipseResourceUtil.getJavaSourceRoot(project);
+ IFile javaFile = (srcRoot == null ? null : (IFile)srcRoot.findMember(JAVA_FILENAME));
+
+ assertTrue("The file \"" + JAVA_FILENAME + "\" is not
found", (javaFile != null));
+ assertTrue("The file \"" + JAVA_FILENAME + "\" is not
found", (javaFile.exists()));
+
+ FileEditorInput editorInput = new FileEditorInput(javaFile);
+ Throwable exception = null;
+ IEditorPart editorPart = null;
+
+ try {
+ editorPart =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(editorInput,
"org.eclipse.jdt.ui.CompilationUnitEditor");
+ } catch (PartInitException e) {
+ fail("Couldn't obtain Java Editor for " + JAVA_FILENAME + ": "
+ e.getLocalizedMessage());
+ }
+
+ // clean deffered events
+ while (Display.getCurrent().readAndDispatch());
+
+ try {
+ CompilationUnitEditor javaEditor = null;
+
+ if (editorPart instanceof CompilationUnitEditor)
+ javaEditor = (CompilationUnitEditor)editorPart;
+
+ // Delay for 3 seconds so that
+ // the Favorites view can be seen.
+ JobUtils.waitForIdle();
+
+ ISourceViewer viewer = javaEditor.getViewer();
+ IDocument document = viewer.getDocument();
+ SourceViewerConfiguration config =
CATestUtil.getSourceViewerConfiguration(javaEditor);
+ IContentAssistant contentAssistant = (config == null ? null :
config.getContentAssistant(viewer));
+
+ assertTrue("Cannot get the Content Assistant instance for the editor for file
\"" + JAVA_FILENAME + "\"", (contentAssistant != null));
+
+ String documentContent = document.get();
+ int start = (documentContent == null ? -1 : documentContent.indexOf(prefix));
+ int offsetToTest = start + prefix.length();
+
+ assertTrue("Cannot find the starting point in the test file \"" +
JAVA_FILENAME + "\"", (start != -1));
+
+ ICompletionProposal[] result= null;
+ String errorMessage = null;
+
+ IContentAssistProcessor p= CATestUtil.getProcessor(viewer, offsetToTest,
contentAssistant);
+ if (p != null) {
+ result= p.computeCompletionProposals(viewer, offsetToTest);
+ }
+
+ // if (errorMessage != null && errorMessage.trim().length() > 0) {
+ // System.out.println("#" + offsetToTest + ": ERROR MESSAGE: " +
errorMessage);
+ // }
+
+ assertTrue("Content Assistant peturned no proposals", (result != null
&& result.length > 0));
+
+ Set<ELProposalProcessor.Proposal> javaProposals = new
HashSet<ELProposalProcessor.Proposal>();
+ for (int j = 0; j < result.length; j++) {
+ if (result[j] instanceof ELProposalProcessor.Proposal) {
+ ELProposalProcessor.Proposal proposal = (ELProposalProcessor.Proposal)result[j];
+ javaProposals.add(proposal);
+ }
+ }
+ return javaProposals.toArray(new ELProposalProcessor.Proposal[0]);
+ } finally {
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+ .closeEditor(editorPart, false);
+ }
+ }
+
+ AutoELContentAssistantProposal[] getJSTProposals(String prefix) {
+ openEditor(PAGE_NAME);
+ try {
+ String documentContent = document.get();
+ int start = (documentContent == null ? -1 : documentContent.indexOf(prefix));
+ assertFalse("Required node '" + prefix + "' not found in
document", (start == -1));
+ int offsetToTest = start + prefix.length();
+
+ JobUtils.waitForIdle();
+
+ List<ICompletionProposal> res = CATestUtil.collectProposals(contentAssistant,
viewer, offsetToTest);
+
+ assertTrue("Content Assistant returned no proposals", (res != null
&& res.size() > 0));
+
+ Set<AutoELContentAssistantProposal> jstProposals = new
HashSet<AutoELContentAssistantProposal>();
+ for (ICompletionProposal p : res) {
+ if (p instanceof AutoELContentAssistantProposal) {
+ jstProposals.add((AutoELContentAssistantProposal)p);
+ }
+ }
+
+ return jstProposals.toArray(new AutoELContentAssistantProposal[0]);
+ } finally {
+ closeEditor();
+ }
+ }
+
+ private boolean compareJavaAndJSTProposals(ELProposalProcessor.Proposal javaProposal,
AutoELContentAssistantProposal jstProposal) {
+ assertNotNull ("Display String of Java EL Proposal should not be a null",
javaProposal.getDisplayString());
+ assertNotNull ("Display String of JST EL Proposal should not be a null",
jstProposal.getDisplayString());
+ assertTrue("Display Strings must be equal (Java:
["+javaProposal.getDisplayString() +"] != JST: [" +
jstProposal.getDisplayString() + "])",
javaProposal.getDisplayString().equals(jstProposal.getDisplayString()));
+
+ assertNotNull ("Additional Info String of Java EL Proposal should not be a
null", javaProposal.getAdditionalProposalInfo());
+ assertNotNull ("Additional Info String of JST EL Proposal should not be a
null", jstProposal.getAdditionalProposalInfo());
+ assertTrue("Additional Info Strings must be equal (Java:
["+javaProposal.getAdditionalProposalInfo() +"] != JST: [" +
jstProposal.getAdditionalProposalInfo() + "])",
javaProposal.getAdditionalProposalInfo().equals(jstProposal.getAdditionalProposalInfo()));
+ return true;
+ }
+}
Property changes on:
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/jsp/ca/test/CAForELJavaAndJSTCompareTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/JsfUiAllTests.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/JsfUiAllTests.java 2011-10-03
19:19:15 UTC (rev 35295)
+++
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/JsfUiAllTests.java 2011-10-03
19:37:40 UTC (rev 35296)
@@ -19,6 +19,7 @@
import org.jboss.tools.jsf.jsp.ca.test.CADefaultELStartingCharTest;
import org.jboss.tools.jsf.jsp.ca.test.CAELInsideTagBodyInJspFileTest;
import org.jboss.tools.jsf.jsp.ca.test.CAForCompositeComponentTest;
+import org.jboss.tools.jsf.jsp.ca.test.CAForELJavaAndJSTCompareTest;
import org.jboss.tools.jsf.jsp.ca.test.CAForELinStyleTest;
import org.jboss.tools.jsf.jsp.ca.test.CAForIDTest;
import
org.jboss.tools.jsf.jsp.ca.test.CAForInputTagSrcAttributeSuggestsFilePathsJBIDE1807Test;
@@ -134,11 +135,15 @@
new String[] { "JSF2KickStartWithoutLibs" })); //$NON-NLS-1$
suite.addTest(new ProjectImportTestSetup(new TestSuite(
+ CAForELJavaAndJSTCompareTest.class), "org.jboss.tools.jsf.test",
//$NON-NLS-1$
+ new String[] { "projects/JSF2KickStartWithoutLibs", }, //$NON-NLS-1$
+ new String[] { "JSF2KickStartWithoutLibs" })); //$NON-NLS-1$
+
+ suite.addTest(new ProjectImportTestSetup(new TestSuite(
CAELInsideTagBodyInJspFileTest.class), "org.jboss.tools.jsf.ui.test",
//$NON-NLS-1$
new String[] { "projects/Jbide3845Test", }, //$NON-NLS-1$
new String[] { "Jbide3845Test" })); //$NON-NLS-1$
-
// return new TestWizardsProject(suite);
return suite;
}