Author: scabanovich
Date: 2007-07-25 12:07:11 -0400 (Wed, 25 Jul 2007)
New Revision: 2654
Modified:
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/TestScanner/WebContent/WEB-INF/components.xml
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/ScannerTest.java
Log:
EXIN-336 ScannerTest updated to current seam model implementation.
Method testSeamProjectObject() added which will include cases of
various ways to define components and their properties.
Modified:
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/TestScanner/WebContent/WEB-INF/components.xml
===================================================================
---
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/TestScanner/WebContent/WEB-INF/components.xml 2007-07-25
15:18:25 UTC (rev 2653)
+++
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/TestScanner/WebContent/WEB-INF/components.xml 2007-07-25
16:07:11 UTC (rev 2654)
@@ -1,10 +1,12 @@
<?xml version="1.0"?>
<components
xmlns="http://jboss.com/products/seam/components"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.com/products/seam/components
http://jboss.com/products/seam/components-1.2.xsd">
+
xmlns:core="http://jboss.com/products/seam/core"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.com/products/seam/components
http://jboss.com/products/seam/components-1.2.xsd http://jboss.com/products/seam/core
http://jboss.com/products/seam/core-1.2.xsd">
<component class="java.lang.Boolean" name="myComponent"
scope="page">
<property name="property1">value1</property>
<property name="myList">
<value>value1</value>
</property>
</component>
+ <core:managed-persistence-context name="myPersistenceContext1"/>
</components>
Modified:
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/ScannerTest.java
===================================================================
---
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/ScannerTest.java 2007-07-25
15:18:25 UTC (rev 2653)
+++
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/ScannerTest.java 2007-07-25
16:07:11 UTC (rev 2654)
@@ -27,9 +27,13 @@
import org.jboss.tools.seam.core.ISeamFactory;
import org.jboss.tools.seam.core.ISeamProject;
import org.jboss.tools.seam.core.ISeamProperty;
+import org.jboss.tools.seam.core.ScopeType;
import org.jboss.tools.seam.core.SeamCoreBuilder;
+import org.jboss.tools.seam.core.event.ISeamValueList;
import org.jboss.tools.seam.internal.core.SeamProject;
import org.jboss.tools.seam.internal.core.scanner.IFileScanner;
+import org.jboss.tools.seam.internal.core.scanner.lib.ClassPath;
+import org.jboss.tools.seam.internal.core.scanner.lib.LibraryScanner;
public class ScannerTest extends TestCase {
TestProjectProvider provider = null;
@@ -46,10 +50,14 @@
} catch (Exception e) {
e.printStackTrace();
}
- XJob.waitForJob();
+ try {
+ XJob.waitForJob();
+ } catch (InterruptedException e) {
+ //ignore
+ }
}
-
- public void testXMLScanner() {
+
+ private ISeamProject getSeamProject() {
try {
XJob.waitForJob();
} catch (Exception e) {
@@ -68,8 +76,20 @@
fail("Cannot get seam nature.");
}
assertNotNull("Seam project is null", seamProject);
-
-
+ return seamProject;
+ }
+
+ /**
+ * This empty test is meaningful as it gives Eclipse opportunity
+ * to pass for the first time setUp() and show the license dialog
+ * that may cause InterruptedException for XJob.waitForJob()
+ */
+ public void testCreatingProject() {
+ }
+
+ public void testXMLScanner() {
+ ISeamProject seamProject = getSeamProject();
+
IFile f = project.getFile("WebContent/WEB-INF/components.xml");
assertTrue("Cannot find components.xml in test project", f != null &&
f.exists());
@@ -98,26 +118,14 @@
assertTrue("Property myList is not found in components.xml", prs.size() ==
1);
ISeamProperty property = prs.get(0);
Object o = property.getValue();
- assertTrue("Property myList in myComponent must be instanceof
java.util.List.", o instanceof List);
- List<?> oList = (List<?>)o;
- assertTrue("Property myList misses value 'value1.",
"value1".equals(oList.get(0)));
+ assertTrue("Property myList in myComponent must be instanceof
ISeamValueList", o instanceof ISeamValueList);
+ ISeamValueList oList = (ISeamValueList)o;
+ assertTrue("Property myList misses value 'value1.",
"value1".equals(oList.getValues().get(0).getValue().getValue()));
}
public void testJavaScanner() {
- try {
- XJob.waitForJob();
- } catch (Exception e) {
- fail("Interrupted");
- }
- ISeamProject seamProject = null;
- try {
- seamProject = (ISeamProject)project.getNature(SeamProject.NATURE_ID);
- } catch (Exception e) {
- fail("Cannot get seam nature.");
- }
- assertNotNull("Seam project is null", seamProject);
+ ISeamProject seamProject = getSeamProject();
-
IFile f = project.getFile("JavaSource/demo/User.java");
assertTrue("Cannot find User.java in test project", f != null &&
f.exists());
@@ -144,40 +152,32 @@
}
public void testLibraryScanner() {
+ ISeamProject seamProject = getSeamProject();
- try {
- XJob.waitForJob();
- } catch (Exception e) {
- fail("Interrupted");
- }
- ISeamProject seamProject = null;
- try {
- seamProject = (ISeamProject)project.getNature(SeamProject.NATURE_ID);
- } catch (Exception e) {
- fail("Cannot get seam nature.");
- }
- assertNotNull("Seam project is null", seamProject);
-
-
IFile f = project.getFile("WebContent/WEB-INF/lib/jboss-seam.jar");
assertTrue("Cannot find User.java in test project", f != null &&
f.exists());
- IFileScanner scanner = SeamCoreBuilder.getLibraryScanner();
+ LibraryScanner scanner =(LibraryScanner)SeamCoreBuilder.getLibraryScanner();
+ ClassPath cp = ((SeamProject)seamProject).getClassPath();
+ scanner.setClassPath(cp);
+ cp.update();
+
assertTrue("Scanner cannot recognise jboss-seam.jar",
scanner.isRelevant(f));
assertTrue("Scanner cannot recognise jboss-seam.jar content",
scanner.isLikelyComponentSource(f));
-
+
ISeamFactory[] cs = null;
try {
cs = scanner.parse(f).getFactories().toArray(new ISeamFactory[0]);
} catch (Exception e) {
+ e.printStackTrace();
fail("Error in library scanner:" + e.getMessage());
}
assertTrue("Factories are not found in jboss-seam.jar", cs != null &&
cs.length > 0);
boolean hasActor = false;
for (int i = 0; i < cs.length && !hasActor; i++) {
- if("actor".equals(cs[0].getName())) hasActor = true;
+ if("actor".equals(cs[i].getName())) hasActor = true;
}
assertTrue("Factory " + "actor" + " is not found in
jboss-seam.jar", hasActor);
@@ -197,4 +197,23 @@
assertTrue("Seam builder must put actor to project.",
components.size()==1);
}
-}
\ No newline at end of file
+
+ /**
+ * This method is to cover most cases of configuring components
+ */
+ public void testSeamProjectObjects() {
+ ISeamProject seamProject = getSeamProject();
+
+ //1. components.xml has entry
+ // <core:managed-persistence-context name="myPersistenceContext1"/>
+ // check that myPersistenceContext1 exists and has scope CONVERSATION
+
+ ISeamComponent c = seamProject.getComponent("myPersistenceContext1");
+ assertNotNull("Component myPersistenceContext1 not found.", c);
+ ScopeType scope = c.getScope();
+ assertTrue("Component myPersistenceContext1 has scope=" + (scope == null ?
null : scope.getLabel()) + ", but has to have " +
ScopeType.CONVERSATION.getLabel(), ScopeType.CONVERSATION == scope);
+
+
+ }
+
+}