Author: vrubezhny
Date: 2011-11-16 12:48:01 -0500 (Wed, 16 Nov 2011)
New Revision: 36375
Added:
trunk/cdi/tests/org.jboss.tools.cdi.seam.core.test/src/org/jboss/tools/cdi/seam/core/test/international/CACdiAddInfoELMessagesTest.java
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.core/src/org/jboss/tools/cdi/seam/core/international/el/CDIInternationalMessagesELResolver.java
trunk/cdi/tests/org.jboss.tools.cdi.seam.core.test/META-INF/MANIFEST.MF
trunk/cdi/tests/org.jboss.tools.cdi.seam.core.test/src/org/jboss/tools/cdi/seam/core/test/CDISeamCoreAllTests.java
Log:
JBIDE-9910 Proposal info for message bundles in code completion for EL
JUnit test for CDI International EL Resource Bundle Messages resolver is added
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.core/src/org/jboss/tools/cdi/seam/core/international/el/CDIInternationalMessagesELResolver.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.core/src/org/jboss/tools/cdi/seam/core/international/el/CDIInternationalMessagesELResolver.java 2011-11-16
16:30:06 UTC (rev 36374)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.core/src/org/jboss/tools/cdi/seam/core/international/el/CDIInternationalMessagesELResolver.java 2011-11-16
17:48:01 UTC (rev 36375)
@@ -317,10 +317,24 @@
for (Variable var : resolvedVariables) {
String varName = var.getName();
if(operand.getLength()<=varName.length()) {
- TextProposal proposal = new TextProposal();
+ MessagesELTextProposal proposal = new MessagesELTextProposal();
proposal.setReplacementString(varName.substring(operand.getLength()));
proposal.setLabel(varName);
+ proposal.setPropertyName(null); // Since it's not a property
proposal.setImage(getELProposalImageForMember(null));
+
+ List<XModelObject> objects = new ArrayList<XModelObject>();
+ IBundleModel bundleModel = BundleModelFactory.getBundleModel(var.f.getProject());
+ if(bundleModel != null && bundleModel.getBundle(var.basename) != null) {
+ IBundle bundle = bundleModel.getBundle(var.basename);
+ if(bundle == null)
+ continue;
+ Map<String, XModelObject> os = ((BundleImpl)bundle).getObjects();
+ for (XModelObject o: os.values()) {
+ if (o != null) objects.add(o);
+ }
+ }
+ proposal.setObjects(objects);
proposals.add(proposal);
} else if(returnEqualedVariablesOnly) {
TextProposal proposal = new TextProposal();
Modified: trunk/cdi/tests/org.jboss.tools.cdi.seam.core.test/META-INF/MANIFEST.MF
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.seam.core.test/META-INF/MANIFEST.MF 2011-11-16
16:30:06 UTC (rev 36374)
+++ trunk/cdi/tests/org.jboss.tools.cdi.seam.core.test/META-INF/MANIFEST.MF 2011-11-16
17:48:01 UTC (rev 36375)
@@ -24,6 +24,7 @@
org.jboss.tools.jst.text.ext,
org.jboss.tools.jst.text.ext.test,
org.jboss.tools.cdi.seam.solder.core.test,
- org.eclipse.wst.validation;bundle-version="1.2.300"
+ org.eclipse.wst.validation;bundle-version="1.2.300",
+ org.jboss.tools.jst.jsp
Export-Package: org.jboss.tools.cdi.seam.core.test
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.seam.core.test/src/org/jboss/tools/cdi/seam/core/test/CDISeamCoreAllTests.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.seam.core.test/src/org/jboss/tools/cdi/seam/core/test/CDISeamCoreAllTests.java 2011-11-16
16:30:06 UTC (rev 36374)
+++
trunk/cdi/tests/org.jboss.tools.cdi.seam.core.test/src/org/jboss/tools/cdi/seam/core/test/CDISeamCoreAllTests.java 2011-11-16
17:48:01 UTC (rev 36375)
@@ -16,6 +16,7 @@
import org.eclipse.jdt.internal.core.JavaModelManager;
import org.eclipse.wst.validation.ValidationFramework;
import org.jboss.tools.cdi.seam.core.test.international.BundleModelTest;
+import org.jboss.tools.cdi.seam.core.test.international.CACdiAddInfoELMessagesTest;
import
org.jboss.tools.cdi.seam.core.test.international.SeamResourceBundleCdiElResolverTest;
import org.jboss.tools.cdi.seam.core.test.international.SeamResourceBundleELTooltipTest;
import org.jboss.tools.cdi.seam.core.test.international.SeamResourceBundlesTest;
@@ -48,6 +49,7 @@
suite.addTestSuite(SeamResourceBundleCdiElResolverTest.class);
suite.addTestSuite(SeamResourceBundleELTooltipTest.class);
suite.addTestSuite(SeamRestValidationTest.class);
+ suite.addTestSuite(CACdiAddInfoELMessagesTest.class);
suite.addTestSuite(BundleModelTest.class); // should be the last in this suite because
it removes/adds seam-international.jar
suiteAll.addTest(new SeamCoreTestSetup(suite));
Added:
trunk/cdi/tests/org.jboss.tools.cdi.seam.core.test/src/org/jboss/tools/cdi/seam/core/test/international/CACdiAddInfoELMessagesTest.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.seam.core.test/src/org/jboss/tools/cdi/seam/core/test/international/CACdiAddInfoELMessagesTest.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.seam.core.test/src/org/jboss/tools/cdi/seam/core/test/international/CACdiAddInfoELMessagesTest.java 2011-11-16
17:48:01 UTC (rev 36375)
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * 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.cdi.seam.core.test.international;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.jboss.tools.cdi.seam.core.test.SeamCoreTest;
+import org.jboss.tools.common.base.test.contentassist.CATestUtil;
+import org.jboss.tools.jst.jsp.contentassist.AutoELContentAssistantProposal;
+import org.jboss.tools.jst.jsp.test.ca.ContentAssistantTestCase;
+
+/**
+ * The JUnit test case for JBIDE-9910 issue
+ *
+ * @author Victor V. Rubezhny
+ *
+ */
+public class CACdiAddInfoELMessagesTest extends SeamCoreTest {
+
+ private ContentAssistantTestCase caTest = new ContentAssistantTestCase();
+ private static final String PAGE_NAME =
"WebContent/seam-international.xhtml";
+
+ private static final String PREFIXES[] = new String[] {"#{bundles.messa",
"#{bundles.messages.home_hea"};
+ private static final String NAMES[] = new String[] {"bundles.messages",
"home_header"};
+ private static final String ADD_INFOS[] = new String[] {
+ "<html><body text=\"#000000\"
bgcolor=\"#ffffe1\"><br><b>Resource Bundle:</b>
/SeamCoreTest/src/messages.properties<br><br><b>Resource
Bundle:</b>
/SeamCoreTest/src/messages_de.properties</body></html>",
+ "<html><body text=\'#ffffff\"
bgcolor=\"#000000\"><b>Property:</b>
home_header<br><b>Base Name:</b>
messages<br><br><b>Resource Bundle:</b>
/SeamCoreTest/src/messages.properties<br><b>Value:</b> About this
example application</body></html>"
+ };
+
+ /**
+ * The method tests CA on CDI Seam International Module Resource Bundles
+ * @throws Exception
+ */
+ public void testCACdiAddInfoELMessagesTest() throws Exception {
+ // Perform CA test
+ caTest.setProject(getTestProject());
+
+ for (int i = 0; i < PREFIXES.length; i++) {
+ AutoELContentAssistantProposal jstProposals[] = getJSTProposals(PREFIXES[i]);
+ assertFalse ("No EL Proposals found in Web page: " + PAGE_NAME,
(jstProposals == null || jstProposals.length == 0));
+
+ boolean proposalFound = false;
+ for (AutoELContentAssistantProposal proposal : jstProposals) {
+ if (NAMES[i].equals(proposal.getDisplayString())) {
+ String addInfo = proposal.getAdditionalProposalInfo();
+
+ String addInfoValue = html2Text(addInfo);
+ String compareValue = html2Text(ADD_INFOS[i]);
+ assertTrue("Additional Info exists but its value is not expected:\nAdd. Info:
[" + addInfoValue + "]\nExpected Value: [" + compareValue + "]",
compareValue.equalsIgnoreCase(addInfoValue));
+ proposalFound = true;
+ break;
+ }
+ }
+ assertTrue("No '" + NAMES[i] + "' EL Proposals found in Web
page: " + PAGE_NAME, proposalFound);
+ }
+ }
+
+ String html2Text(String html) {
+ StringBuilder sb = new StringBuilder();
+ int state = 0;
+ for (char ch : html.toCharArray()) {
+ switch (state) {
+ case (int)'<':
+ // Read to null until '>'-char is read
+ if (ch != '>')
+ continue;
+ state = 0;
+ break;
+ default:
+ if (ch == '<') {
+ state = '<';
+ continue;
+ }
+ sb.append(ch);
+ break;
+ }
+ }
+ return sb.toString();
+ }
+
+ AutoELContentAssistantProposal[] getJSTProposals(String prefix) {
+ caTest.openEditor(PAGE_NAME);
+ try {
+ String documentContent = caTest.getDocument().get();
+
+ int start = (documentContent == null ? -1 : documentContent.indexOf(prefix));
+ assertFalse("Required node '" + prefix + "' not found in
document", (start == -1));
+ int offsetToTest = start + prefix.length();
+
+
+ List<ICompletionProposal> res =
CATestUtil.collectProposals(caTest.getContentAssistant(), caTest.getViewer(),
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 {
+ caTest.closeEditor();
+ }
+ }
+}
\ No newline at end of file
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.seam.core.test/src/org/jboss/tools/cdi/seam/core/test/international/CACdiAddInfoELMessagesTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain