Author: vrubezhny
Date: 2011-07-25 11:47:48 -0400 (Mon, 25 Jul 2011)
New Revision: 33179
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.core/META-INF/MANIFEST.MF
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/SeamResourceBundlesTest.java
Log:
JBIDE-9087
Support of Bundles bean in CDI projects with Seam International module.
JUnit Test Case for Seam3 International module EL resolver is added
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.seam.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.seam.core/META-INF/MANIFEST.MF 2011-07-25
14:03:02 UTC (rev 33178)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.seam.core/META-INF/MANIFEST.MF 2011-07-25
15:47:48 UTC (rev 33179)
@@ -17,4 +17,5 @@
org.jboss.tools.cdi.core;bundle-version="1.2.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
-Export-Package: org.jboss.tools.cdi.seam.core
+Export-Package: org.jboss.tools.cdi.seam.core,
+ org.jboss.tools.cdi.seam.core.international.el
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-07-25
14:03:02 UTC (rev 33178)
+++ trunk/cdi/tests/org.jboss.tools.cdi.seam.core.test/META-INF/MANIFEST.MF 2011-07-25
15:47:48 UTC (rev 33179)
@@ -18,5 +18,7 @@
org.jboss.tools.common;bundle-version="3.3.0",
org.eclipse.ui;bundle-version="3.7.0",
org.jboss.tools.common.base.test;bundle-version="3.3.0",
- org.eclipse.jface.text;bundle-version="3.7.0"
+ org.eclipse.jface.text;bundle-version="3.7.0",
+ org.jboss.tools.common.el.core;bundle-version="3.3.0",
+ org.jboss.tools.common.text.ext;bundle-version="3.3.0"
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.seam.core.test/src/org/jboss/tools/cdi/seam/core/test/SeamResourceBundlesTest.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.seam.core.test/src/org/jboss/tools/cdi/seam/core/test/SeamResourceBundlesTest.java 2011-07-25
14:03:02 UTC (rev 33178)
+++
trunk/cdi/tests/org.jboss.tools.cdi.seam.core.test/src/org/jboss/tools/cdi/seam/core/test/SeamResourceBundlesTest.java 2011-07-25
15:47:48 UTC (rev 33179)
@@ -11,8 +11,9 @@
package org.jboss.tools.cdi.seam.core.test;
import java.io.File;
+import java.util.List;
-import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.FileLocator;
@@ -21,9 +22,15 @@
import org.jboss.tools.cdi.core.CDICorePlugin;
import org.jboss.tools.cdi.core.test.tck.TCKTest;
import org.jboss.tools.cdi.seam.core.CDISeamCorePlugin;
+import
org.jboss.tools.cdi.seam.core.international.el.CDIInternationalMessagesELResolver;
+import org.jboss.tools.common.el.core.resolver.ELContext;
+import org.jboss.tools.common.el.core.resolver.ELResolver;
+import org.jboss.tools.common.text.TextProposal;
+import org.jboss.tools.common.text.ext.util.Utils;
import org.jboss.tools.common.util.FileUtil;
import org.jboss.tools.jst.jsp.test.TestUtil;
import org.jboss.tools.jst.jsp.test.ca.ContentAssistantTestCase;
+import org.jboss.tools.jst.web.kb.PageContextFactory;
import org.jboss.tools.jst.web.kb.internal.validation.ValidatorManager;
import org.jboss.tools.test.util.JobUtils;
import org.osgi.framework.Bundle;
@@ -46,22 +53,102 @@
private String[] resourceBundleNames = new String[] {"bundles.messages"};
private String[] defaultResourceBundleNameProperties = new String[]
{"bundles.messages.home_header", "bundles.messages.home_body",
"bundles.messages.home_note"};
private String[] germanResourceBundleNameProperties = new String[]
{"bundles.messages.de_home_header", "bundles.messages.de_home_body",
"bundles.messages.de_home_note"};
+ private String[] textDefaultResourceBundleNameProperties = new String[]
{"home_header", "home_body", "home_note"};
+ private String[] textGermanResourceBundleNameProperties = new String[]
{"de_home_header", "de_home_body", "de_home_note"};
- public void testResourceBundles() {
+ boolean bReadyForTesting = false;
+ String errMessage = null;
+
+ public SeamResourceBundlesTest () {
+ super();
+
+ boolean setupOK = true;
// Set up seam-international.jar library into the project's WEB-INF/lib folder
try {
- assertTrue("Cannot set up SEAM International module and resource bundles into a
test project",
- setUpSeamInternationalLibraryAndResourceBundle());
+ setupOK = setUpSeamInternationalLibraryAndResourceBundle();
+ if (!setupOK)
+ errMessage = "Cannot set up SEAM International module and resource bundles into
a test project";
} catch (Exception e) {
- fail("Cannot set up SEAM International module and resource bundles into a test
project: "
- + e.getLocalizedMessage());
+ setupOK = false;
+ errMessage = "Cannot set up SEAM International module and resource bundles into a
test project: "
+ + e.getLocalizedMessage();
}
+ if (!setupOK)
+ return;
+
// Test that seam-international module is successfully installed on the CDI project
- assertTrue("SEAM International module is not installed or incorrectly
installed",
- CDICorePlugin.getCDI(tckProject, true).getExtensionManager()
- .isCDIExtensionAvailable(CDISeamCorePlugin.CDI_INTERNATIONAL_RUNTIME_EXTENTION));
+ setupOK = CDICorePlugin.getCDI(tckProject, true).getExtensionManager()
+ .isCDIExtensionAvailable(CDISeamCorePlugin.CDI_INTERNATIONAL_RUNTIME_EXTENTION);
+ if (!setupOK)
+ errMessage = "SEAM International module is not installed or incorrectly
installed";
+
+ bReadyForTesting = setupOK;
+ }
+
+ /**
+ * The method checks if CDIInternationalMessagesELResolver present among the EL
Resolvers,
+ * then if the required resolver found uses it to retrieve and test proposals for bundle
and their properties
+ */
+ public void testCDIInternationalMessages () {
+ assertTrue(errMessage, bReadyForTesting);
+
+ IFile page = tckProject.getFile(PAGE_NAME);
+ assertTrue("Test page not found: " + PAGE_NAME, (page != null &&
page.exists()));
+ ELContext elContext = PageContextFactory.createPageContext(page);
+
+ ELResolver[] elResolvers = elContext.getElResolvers();
+ ELResolver cdiInternationalModuleResolver = null;
+ if (elResolvers != null) {
+ for (ELResolver r : elResolvers) {
+ if (r instanceof CDIInternationalMessagesELResolver) {
+ cdiInternationalModuleResolver = r;
+ break;
+ }
+ }
+ }
+ assertNotNull("Seam International module resolver is not set up on the
project", cdiInternationalModuleResolver);
+
+ List<TextProposal> bundleProposals =
cdiInternationalModuleResolver.getProposals(elContext, "value=\"#{", 1);
+ assertTrue("Seam International module resolver didn't return proposals for
bundles",
+ (bundleProposals != null && bundleProposals.size() > 0));
+ proposalsExist(bundleProposals, resourceBundleNames);
+
+ List<TextProposal> bundlePropertyProposals =
cdiInternationalModuleResolver.getProposals(elContext,
"value=\"#{bundles.messages.", 1);
+ assertTrue("Seam International module resolver didn't return proposals for
bundles",
+ (bundlePropertyProposals != null && bundlePropertyProposals.size() > 0));
+ proposalsExist(bundlePropertyProposals, textDefaultResourceBundleNameProperties);
+ proposalsExist(bundlePropertyProposals, textGermanResourceBundleNameProperties);
+ }
+
+ public void proposalsExist(List<TextProposal> res, String[] proposals) {
+ TextProposal[] result = res.toArray(new TextProposal[res.size()]);
+ for (int i = 0; i < proposals.length; i++) {
+ boolean found = compareTextProposal(proposals[i], result);
+ assertTrue("Proposal " + proposals[i] + " not found!",
found ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ public boolean compareTextProposal(String proposal, TextProposal[] proposals){
+ for (int i = 0; i < proposals.length; i++) {
+ String replacementString = proposals[i].getReplacementString().toLowerCase();
+ if (replacementString.equalsIgnoreCase(proposal)) return true;
+ // For an attribute value proposal there will be the quote characters
+
+ replacementString = Utils.trimQuotes(replacementString);
+ if (replacementString.equalsIgnoreCase(proposal)) return true;
+
+ }
+ return false;
+ }
+
+ /**
+ * The method tests CA on CDI Seam International Module Resource Bundles
+ */
+ public void testResourceBundles() {
+ assertTrue(errMessage, bReadyForTesting);
+
// Perform CA test
caTest.checkProposals(PAGE_NAME, "value=\"#{", 9, resourceBundleNames,
false);
caTest.checkProposals(PAGE_NAME, "value=\"#{bundles.messages.", 26,
defaultResourceBundleNameProperties, false);