Author: vrubezhny
Date: 2010-09-22 17:02:05 -0400 (Wed, 22 Sep 2010)
New Revision: 25107
Removed:
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/ca/test/JsfJspJbide1704Test.java
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/ca/test/JsfJspJbide1717Test.java
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/ca/test/JsfJspJbide6259Test.java
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/test/JsfCATests.java
Log:
JBIDE-7123
Create JUnit test for JBIDE-6259: Add an option to Preferences to disable/enable code
completion for getteres and setters in EL.
JUnit test is moved to UI plugin
Deleted:
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/ca/test/JsfJspJbide1704Test.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/ca/test/JsfJspJbide1704Test.java 2010-09-22
20:59:40 UTC (rev 25106)
+++
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/ca/test/JsfJspJbide1704Test.java 2010-09-22
21:02:05 UTC (rev 25107)
@@ -1,115 +0,0 @@
-package org.jboss.tools.jsf.ca.test;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.FindReplaceDocumentAdapter;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.contentassist.ContentAssistant;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
-import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal;
-import org.jboss.tools.jst.jsp.contentassist.AutoContentAssistantProposal;
-import org.jboss.tools.jst.jsp.test.TestUtil;
-import org.jboss.tools.jst.jsp.test.ca.ContentAssistantTestCase;
-import org.jboss.tools.test.util.TestProjectProvider;
-
-public class JsfJspJbide1704Test extends ContentAssistantTestCase {
- TestProjectProvider provider = null;
-
- boolean makeCopy = false;
- private static final String PROJECT_NAME = "JsfJbide1704Test";
- private static final String PAGE_NAME = "/WebContent/pages/greeting";
-
- public static Test suite() {
- return new TestSuite(JsfJspJbide1704Test.class);
- }
-
- public void setUp() throws Exception {
- provider = new TestProjectProvider("org.jboss.tools.jsf.test", null,
PROJECT_NAME, makeCopy);
- project = provider.getProject();
- }
-
- protected void tearDown() throws Exception {
- if(provider != null) {
- provider.dispose();
- }
- }
-
- public void testJspJbide1704 () {
- assertTrue("Test project \"" + PROJECT_NAME + "\" is not
loaded", (project != null));
- doTestJsfJspJbide1704(PAGE_NAME + ".jsp");
- }
-
- public void testXhtmlJbide1704 () {
- assertTrue("Test project \"" + PROJECT_NAME + "\" is not
loaded", (project != null));
- doTestJsfJspJbide1704(PAGE_NAME + ".xhtml");
- }
-
- private static final String TEST_RESOURCES_VALUE = "\"resources\"";
-
- private void doTestJsfJspJbide1704(String pageName) {
-
- openEditor(pageName);
-
- try {
-
- final IRegion reg = new FindReplaceDocumentAdapter(document).find(0,
- " var=\"msg\"", true, true, false, false);
- String text = document.get();
- String errorMessage = null;
-
- List<ICompletionProposal> res = TestUtil.collectProposals(contentAssistant,
viewer, reg.getOffset());
-
- assertTrue("Content Assist returned no proposals: ", (res != null &&
res.size() > 0));
-
- for (ICompletionProposal proposal : res) {
- // There should not be a proposal of type AutoContentAssistantProposal in the result
- // (the only exclusion is EL-proposals)
-
- if (proposal instanceof AutoContentAssistantProposal) {
- if(((AutoContentAssistantProposal)proposal).getReplacementString().startsWith("#{"))
{
- // The only EL template proposal is allowed to be shown here
- continue;
- }
- }
-
-
- if (proposal instanceof CustomCompletionProposal) {
- // There are two cases are allowed to be shown
- // AutoContentAssistantProposal which returns the "resources" string as
replacement
- // CustomCompletionProposal which returns the current value string as replacement
-
- if (!(proposal instanceof AutoContentAssistantProposal)) {
- int equalSignIndex = text.lastIndexOf('=', reg.getOffset());
- if (equalSignIndex != -1) {
- String prevAttrValue = text.substring(equalSignIndex+1,
reg.getOffset()).trim();
- if
(((CustomCompletionProposal)proposal).getReplacementString().equals(prevAttrValue)){
- // The old value for the attribute is allowed to be shown here
- continue;
- }
- }
- } else {
- if
(((CustomCompletionProposal)proposal).getReplacementString().equals(TEST_RESOURCES_VALUE)){
- // The old value for the attribute is allowed to be shown here
- continue;
- }
-
- }
- }
-
- assertFalse("Content Assistant peturned proposals of type (" +
proposal.getClass().getName() + ").", (proposal instanceof
AutoContentAssistantProposal));
- }
-
- } catch (BadLocationException e) {
- fail(e.getMessage());
- }
-
- closeEditor();
- }
-
-}
Deleted:
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/ca/test/JsfJspJbide1717Test.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/ca/test/JsfJspJbide1717Test.java 2010-09-22
20:59:40 UTC (rev 25106)
+++
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/ca/test/JsfJspJbide1717Test.java 2010-09-22
21:02:05 UTC (rev 25107)
@@ -1,117 +0,0 @@
-package org.jboss.tools.jsf.ca.test;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
-import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal;
-import org.jboss.tools.jst.jsp.test.TestUtil;
-import org.jboss.tools.jst.jsp.test.ca.ContentAssistantTestCase;
-import org.jboss.tools.test.util.JobUtils;
-import org.jboss.tools.test.util.TestProjectProvider;
-
-
-public class JsfJspJbide1717Test extends ContentAssistantTestCase {
- TestProjectProvider provider = null;
- boolean makeCopy = false;
- private static final String PROJECT_NAME = "JsfJbide1704Test";
- private static final String PAGE_NAME = "/WebContent/pages/greeting.jsp";
- private static final String INSERT_BEFORE_STRING = "<h:outputText";
- private static final String INSERTION_BEGIN_STRING = "<h:outputText
value=\"";
- private static final String INSERTION_END_STRING = "\" />";
- private static final String JSF_EXPR_STRING = "#{msg.greeting}";
-
- public static Test suite() {
- return new TestSuite(JsfJspJbide1717Test.class);
- }
-
- public void setUp() throws Exception {
- provider = new TestProjectProvider("org.jboss.tools.jsf.test", null,
PROJECT_NAME, makeCopy);
- project = provider.getProject();
- }
-
- protected void tearDown() throws Exception {
- if(provider != null) {
- provider.dispose();
- }
- }
-
- public void testJstJspJbide1717() {
- openEditor(PAGE_NAME);
-
- // Find start of <h:outputText> tag
- String documentContent = document.get();
- int start = (documentContent == null ? -1 :
documentContent.indexOf(INSERT_BEFORE_STRING));
-
- assertTrue("Cannot find the starting point in the test file \"" +
PAGE_NAME + "\"", (start != -1));
-
- // First of all perform the test on a region placed in one space behind empty-valued
attribute -
- // this is to return normal list of attribute names proposal list
-
- String documentContentModified = documentContent.substring(0, start) +
- INSERTION_BEGIN_STRING + INSERTION_END_STRING + documentContent.substring(start);
-
- int offsetToTest = start + INSERTION_BEGIN_STRING.length() + 2;
-
- jspTextEditor.setText(documentContentModified);
-
- String errorMessage = null;
-
- List<ICompletionProposal> res = TestUtil.collectProposals(contentAssistant,
viewer, offsetToTest);
-
- List<String> customCompletionProposals = new ArrayList<String>();
-
- if (res != null) {
- for (ICompletionProposal proposal : res) {
- // There should be at least one proposal of type CustomCompletionProposal in the
result
- if (proposal instanceof CustomCompletionProposal) {
- customCompletionProposals.add(((CustomCompletionProposal)proposal).getReplacementString());
- }
- }
- }
- assertFalse("Content Assistant returned no proposals of type
CustomCompletionProposal.",customCompletionProposals.isEmpty());
-
- try {
- JobUtils.waitForIdle();
- } catch (Exception e) {
- e.printStackTrace();
- assertTrue("Waiting for the jobs to complete has failed.", false);
- }
-
- // Next perform the test on a region placed in one space behind an attribute those
value is a container
- // (contains JSF expression) - this has to return the same normal list of attribute
names proposal list as
- // we got at the first step (because the tag is the same, but only the attribute value
is changed)
-
- documentContentModified = documentContent.substring(0, start) +
- INSERTION_BEGIN_STRING + JSF_EXPR_STRING + INSERTION_END_STRING +
documentContent.substring(start);
-
- offsetToTest = start + INSERTION_BEGIN_STRING.length() + JSF_EXPR_STRING.length() + 2;
-
- String visualizeCursorPosition = documentContentModified.substring(0, offsetToTest) +
- "|" + documentContentModified.substring(offsetToTest);
-
- jspTextEditor.setText(documentContentModified);
-
- res = TestUtil.collectProposals(contentAssistant, viewer, offsetToTest);
-
- if (res != null) {
- for (ICompletionProposal proposal : res) {
- // There should be the same proposals as in the saved result
- if (proposal instanceof CustomCompletionProposal) {
- assertTrue("Content Assistant returned additional proposal (proposal returned
doesn't exist in the saved list).",
- customCompletionProposals.contains(((CustomCompletionProposal)proposal).getReplacementString()));
- customCompletionProposals.remove(((CustomCompletionProposal)proposal).getReplacementString());
- }
- }
- }
- assertTrue("Content Assistant didn't returned some
proposals.",customCompletionProposals.isEmpty());
-
- closeEditor();
- }
-
-
-}
Deleted:
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/ca/test/JsfJspJbide6259Test.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/ca/test/JsfJspJbide6259Test.java 2010-09-22
20:59:40 UTC (rev 25106)
+++
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/ca/test/JsfJspJbide6259Test.java 2010-09-22
21:02:05 UTC (rev 25107)
@@ -1,184 +0,0 @@
-package org.jboss.tools.jsf.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.jface.text.BadLocationException;
-import org.eclipse.jface.text.FindReplaceDocumentAdapter;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal;
-import org.jboss.tools.common.el.core.ELCorePlugin;
-import org.jboss.tools.common.el.core.ca.preferences.ELContentAssistPreferences;
-import org.jboss.tools.jst.jsp.contentassist.AutoContentAssistantProposal;
-import org.jboss.tools.jst.jsp.contentassist.AutoELContentAssistantProposal;
-import org.jboss.tools.jst.jsp.test.TestUtil;
-import org.jboss.tools.jst.jsp.test.ca.ContentAssistantTestCase;
-import org.jboss.tools.test.util.TestProjectProvider;
-
-public class JsfJspJbide6259Test extends ContentAssistantTestCase {
- TestProjectProvider provider = null;
-
- boolean makeCopy = false;
- private static final String PROJECT_NAME = "JsfJbide1704Test";
- private static final String PAGE_NAME = "/WebContent/pages/greeting.jsp";
-
- public static Test suite() {
- return new TestSuite(JsfJspJbide1704Test.class);
- }
-
- public void setUp() throws Exception {
- provider = new TestProjectProvider("org.jboss.tools.jsf.test", null,
PROJECT_NAME, makeCopy);
- project = provider.getProject();
- }
-
- protected void tearDown() throws Exception {
- if(provider != null) {
- provider.dispose();
- }
- }
-
- private static final String EXPRESSION_STRING = "#{person.";
- private static final String[] TEST_PROPOSAL_EMPTY_SET_EMPTY = new String[0];
- private static final String[] TEST_PROPOSAL_SET_GETTERS_AND_SETTERS_TRUE = {
- "name",
- "getName",
- "getName()"
- };
- private static final String[] TEST_PROPOSAL_SET_GETTERS_AND_SETTERS_FALSE = {
- "name"
- };
- private static final String[] TEST_PROPOSAL_SET_GETTERS_AND_SETTERS_FALSE_WRONG_CASES =
{
- "getName",
- "getName()"
- };
- private static final String[] TEST_PROPOSAL_METHODS_WITH_PARENTHESES_ONLY_TRUE = {
- "getName()"
- };
- private static final String[]
TEST_PROPOSAL_METHODS_WITH_PARENTHESES_ONLY_TRUE_WRONG_CASES = {
- "getName"
- };
- private static final String[] TEST_PROPOSAL_METHODS_WITH_PARENTHESES_ONLY_FALSE = {
- "getName",
- "getName()"
- };
-
- private void testProposals (List<ICompletionProposal> proposals, String[]
testCases, String[] wrongCases) {
- // testCases is the array of proposals which are strict to be present
- // wrongCases is the array of proposals which are strict to be absent
-
- Set<String> existingCases = new HashSet<String>();
- for (ICompletionProposal p : proposals) {
- if (!(p instanceof AutoELContentAssistantProposal))
- continue;
-
- AutoELContentAssistantProposal proposal = (AutoELContentAssistantProposal)p;
- String replacement = proposal.getReplacementString();
- if (replacement == null)
- continue;
-
- if (replacement.indexOf('.') > -1) {
- replacement = replacement.substring(replacement.lastIndexOf('.') + 1);
- }
-
- for (int i = 0; i < testCases.length; i++) {
- if (replacement.equals(testCases[i])) {
- existingCases.add(testCases[i]); // add the proposal to existing set
- continue;
- }
- }
-
- for (int i = 0; i < wrongCases.length; i++) {
- assertFalse("The proposal \'" + replacement + "\' is not
allowed to be shown!", replacement.equals(wrongCases[i]));
- }
- }
- assertTrue("Not all the required proposals are present!",
(existingCases.size() == testCases.length));
- }
-
- private void setupELContentAssistPreferences(boolean methodsWithParenthesesOnly, boolean
showGettersAndSetters) {
- ELCorePlugin.getDefault().getPreferenceStore().setValue(ELContentAssistPreferences.SHOW_METHODS_WITH_PARENTHESES_ONLY,
methodsWithParenthesesOnly);
- ELCorePlugin.getDefault().getPreferenceStore().setValue(ELContentAssistPreferences.SHOW_GETTERS_AND_SETTERS,
showGettersAndSetters);
- }
-
- public void testJspJbide6259 () {
- assertTrue("Test project \"" + PROJECT_NAME + "\" is not
loaded", (project != null));
-
- openEditor(PAGE_NAME);
-
- try {
-
- final IRegion reg = new FindReplaceDocumentAdapter(document).find(0,
- EXPRESSION_STRING, true, true, false, false);
- String errorMessage = null;
-
- int offsetToTest = reg.getOffset() + EXPRESSION_STRING.length();
-
- // Test method presentations: with and without parentheses
-
- // Set up EL Content Assist preferences to:
- // methods are to be shown with and without parentheses
- // getters and setters are to be shown
- setupELContentAssistPreferences(false, true);
-
- List<ICompletionProposal> res = TestUtil.collectProposals(contentAssistant,
viewer, offsetToTest);
-
- assertTrue("Content Assist returned no proposals: ", (res != null &&
res.size() > 0));
-
- testProposals(res, TEST_PROPOSAL_METHODS_WITH_PARENTHESES_ONLY_FALSE,
TEST_PROPOSAL_EMPTY_SET_EMPTY);
-
- // Test method presentations: with parentheses only
-
- // Set up EL Content Assist preferences to:
- // methods are to be shown with parentheses only
- // getters and setters are to be shown
-
- setupELContentAssistPreferences(true, true);
- TestUtil.prepareCAInvokation(contentAssistant, viewer, 0); // drop the CA Window
- res = TestUtil.collectProposals(contentAssistant, viewer, offsetToTest);
-
- assertTrue("Content Assist returned no proposals: ", (res != null &&
res.size() > 0));
-
- testProposals(res, TEST_PROPOSAL_METHODS_WITH_PARENTHESES_ONLY_TRUE,
TEST_PROPOSAL_METHODS_WITH_PARENTHESES_ONLY_TRUE_WRONG_CASES);
-
- // Test property presentations: property name, getters and setters are to be shown
-
- // Set up EL Content Assist preferences to:
- // methods are to be shown with and without parentheses
- // getters and setters are to be shown
-
- setupELContentAssistPreferences(false, true);
-
- TestUtil.prepareCAInvokation(contentAssistant, viewer, 0); // drop the CA Window
- res = TestUtil.collectProposals(contentAssistant, viewer, offsetToTest);
-
- assertTrue("Content Assist returned no proposals: ", (res != null &&
res.size() > 0));
-
- testProposals(res, TEST_PROPOSAL_SET_GETTERS_AND_SETTERS_TRUE,
TEST_PROPOSAL_EMPTY_SET_EMPTY);
-
- // Test property presentations: the only property name is to be shown
-
- // Set up EL Content Assist preferences to:
- // methods are to be shown with and without parentheses
- // getters and setters are to be shown
-
- setupELContentAssistPreferences(false, false);
-
- TestUtil.prepareCAInvokation(contentAssistant, viewer, 0); // drop the CA Window
- res = TestUtil.collectProposals(contentAssistant, viewer, offsetToTest);
-
- assertTrue("Content Assist returned no proposals: ", (res != null &&
res.size() > 0));
-
- testProposals(res, TEST_PROPOSAL_SET_GETTERS_AND_SETTERS_FALSE,
TEST_PROPOSAL_SET_GETTERS_AND_SETTERS_FALSE_WRONG_CASES);
-
- } catch (BadLocationException e) {
- fail(e.getMessage());
- }
-
- closeEditor();
- }
-
-}
Deleted:
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/test/JsfCATests.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/test/JsfCATests.java 2010-09-22
20:59:40 UTC (rev 25106)
+++
trunk/jsf/tests/org.jboss.tools.jsf.test/src/org/jboss/tools/jsf/test/JsfCATests.java 2010-09-22
21:02:05 UTC (rev 25107)
@@ -1,30 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Exadel, Inc. and 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:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.jsf.test;
-
-import org.jboss.tools.jsf.ca.test.JsfJspJbide1704Test;
-import org.jboss.tools.jsf.ca.test.JsfJspJbide1717Test;
-import org.jboss.tools.jsf.ca.test.JsfJspJbide6259Test;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-public class JsfCATests {
- public static Test suite() {
- TestSuite suite = new TestSuite("Test for org.jboss.tools.jsf.test");
-
- suite.addTestSuite(JsfJspJbide6259Test.class);
- suite.addTestSuite(JsfJspJbide1704Test.class);
- suite.addTestSuite(JsfJspJbide1717Test.class);
-
- return suite;
- }
-}