Author: manaRH
Date: 2012-07-24 11:24:10 -0400 (Tue, 24 Jul 2012)
New Revision: 15001
Added:
branches/enterprise/JBPAPP_5_0/src/test/integration/src/org/jboss/seam/test/integration/Component1.java
branches/enterprise/JBPAPP_5_0/src/test/integration/src/org/jboss/seam/test/integration/Component2.java
branches/enterprise/JBPAPP_5_0/src/test/integration/src/org/jboss/seam/test/integration/PrecedenceComponentTest.java
Modified:
branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/init/Initialization.java
branches/enterprise/JBPAPP_5_0/src/test/integration/resources/WEB-INF/components.xml
branches/enterprise/JBPAPP_5_0/src/test/integration/src/org/jboss/seam/test/integration/testng.xml
Log:
JBPAPP-8159 fixed Component precedence init
Modified: branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/init/Initialization.java
===================================================================
---
branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/init/Initialization.java 2012-07-24
15:11:55 UTC (rev 15000)
+++
branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/init/Initialization.java 2012-07-24
15:24:10 UTC (rev 15001)
@@ -511,7 +511,19 @@
propName = prop.getQName().getName();
}
String qualifiedPropName = name + '.' + toCamelCase(propName, false);
- properties.put( qualifiedPropName, getPropertyValue(prop, qualifiedPropName,
replacements) );
+ log.info("qualifiedPropName " + qualifiedPropName);
+ //properties.put( qualifiedPropName, getPropertyValue(prop, qualifiedPropName,
replacements) );
+ if (properties.containsKey(qualifiedPropName))
+ {
+ if (isSetProperties(name, precedence))
+ {
+ properties.put(qualifiedPropName, getPropertyValue(prop,
qualifiedPropName, replacements));
+ }
+ }
+ else
+ {
+ properties.put(qualifiedPropName, getPropertyValue(prop, qualifiedPropName,
replacements));
+ }
}
for ( Attribute prop: (List<Attribute>) component.attributes() )
@@ -524,7 +536,11 @@
try
{
propValue = getPropertyValue(prop, replacements);
- properties.put( qualifiedPropName, propValue );
+// properties.put( qualifiedPropName, propValue );
+ if (isSetProperties(name, precedence))
+ {
+ properties.put(qualifiedPropName, propValue);
+ }
}
catch (Exception ex)
{
@@ -537,6 +553,25 @@
}
}
+ private boolean isSetProperties(String name, int precedence)
+ {
+ TreeSet<ComponentDescriptor> currentSet =
(TreeSet<ComponentDescriptor>) componentDescriptors.get(name);
+ if (currentSet != null)
+ {
+ ComponentDescriptor highestPriorityDescriptor = currentSet.first();
+ if (highestPriorityDescriptor == null)
+ {
+ return true;
+ }
+ return precedence >= highestPriorityDescriptor.getPrecedence();
+ }
+ else
+ {
+ log.info("Component is not in componentDescriptory " + name + "
precedence " + precedence);
+ return true;
+ }
+ }
+
/**
* component properties are non-namespaced and not in the reserved attribute list
*/
Modified:
branches/enterprise/JBPAPP_5_0/src/test/integration/resources/WEB-INF/components.xml
===================================================================
---
branches/enterprise/JBPAPP_5_0/src/test/integration/resources/WEB-INF/components.xml 2012-07-24
15:11:55 UTC (rev 15000)
+++
branches/enterprise/JBPAPP_5_0/src/test/integration/resources/WEB-INF/components.xml 2012-07-24
15:24:10 UTC (rev 15001)
@@ -53,6 +53,11 @@
<jms:managed-queue-sender name="testSender"
auto-create="true"
queue-jndi-name="/queue/testQueue" />
-
-
+
+ <component name="component1"
class="org.jboss.seam.test.integration.Component2"
precedence="30">
+ <property name="name">Component1High</property>
+ </component>
+ <component name="component1"
class="org.jboss.seam.test.integration.Component1"
precedence="10">
+ <property name="name">Component1Low</property>
+ </component>
</components>
Added:
branches/enterprise/JBPAPP_5_0/src/test/integration/src/org/jboss/seam/test/integration/Component1.java
===================================================================
---
branches/enterprise/JBPAPP_5_0/src/test/integration/src/org/jboss/seam/test/integration/Component1.java
(rev 0)
+++
branches/enterprise/JBPAPP_5_0/src/test/integration/src/org/jboss/seam/test/integration/Component1.java 2012-07-24
15:24:10 UTC (rev 15001)
@@ -0,0 +1,18 @@
+package org.jboss.seam.test.integration;
+
+public class Component1
+{
+
+ private String name;
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+}
Added:
branches/enterprise/JBPAPP_5_0/src/test/integration/src/org/jboss/seam/test/integration/Component2.java
===================================================================
---
branches/enterprise/JBPAPP_5_0/src/test/integration/src/org/jboss/seam/test/integration/Component2.java
(rev 0)
+++
branches/enterprise/JBPAPP_5_0/src/test/integration/src/org/jboss/seam/test/integration/Component2.java 2012-07-24
15:24:10 UTC (rev 15001)
@@ -0,0 +1,18 @@
+package org.jboss.seam.test.integration;
+
+public class Component2
+{
+
+ private String name;
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+}
Added:
branches/enterprise/JBPAPP_5_0/src/test/integration/src/org/jboss/seam/test/integration/PrecedenceComponentTest.java
===================================================================
---
branches/enterprise/JBPAPP_5_0/src/test/integration/src/org/jboss/seam/test/integration/PrecedenceComponentTest.java
(rev 0)
+++
branches/enterprise/JBPAPP_5_0/src/test/integration/src/org/jboss/seam/test/integration/PrecedenceComponentTest.java 2012-07-24
15:24:10 UTC (rev 15001)
@@ -0,0 +1,41 @@
+package org.jboss.seam.test.integration;
+
+import org.jboss.seam.Component;
+import org.jboss.seam.mock.SeamTest;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class PrecedenceComponentTest extends SeamTest
+{
+
+ /**
+ * Test if precedence of component is working correctly
+ * components.xml specifies component1 with 2 possible
+ * configuration - first has got higher precedence than
+ * second and the first should set component1.name property
+ * to Componen1High. Result should be that even last component1
+ * is set the higher precedence configuration has to be set and
+ * remain as the only one available.
+ * JBPAPP-8159 and JBSEAM-3138
+ * @throws Exception
+ */
+ @Test
+ public void testPrecedenceComponents() throws Exception
+ {
+
+ new FacesRequest()
+ {
+ @Override
+ protected void invokeApplication() throws Exception {
+ Object component = Component.getInstance("component1");
+ if (!(component instanceof Component2))
+ {
+ Assert.fail("component is not expected Component2.class");
+ }
+ Component2 myPrecedenceComponent = (Component2) component;
+ Assert.assertEquals(myPrecedenceComponent.getName(),
"Component1High");
+ }
+ }.run();
+ }
+
+}
\ No newline at end of file
Modified:
branches/enterprise/JBPAPP_5_0/src/test/integration/src/org/jboss/seam/test/integration/testng.xml
===================================================================
---
branches/enterprise/JBPAPP_5_0/src/test/integration/src/org/jboss/seam/test/integration/testng.xml 2012-07-24
15:11:55 UTC (rev 15000)
+++
branches/enterprise/JBPAPP_5_0/src/test/integration/src/org/jboss/seam/test/integration/testng.xml 2012-07-24
15:24:10 UTC (rev 15001)
@@ -11,6 +11,7 @@
<class name="org.jboss.seam.test.integration.NamespaceResolverTest"
/>
<class name="org.jboss.seam.test.integration.ConcurrentFactoryTest"
/>
<class name="org.jboss.seam.test.integration.FactoryLockTest" />
+ <class
name="org.jboss.seam.test.integration.PrecedenceComponentTest" />
</classes>
</test>
<test name="Seam Integration Tests - Persistence">
Show replies by date