openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gerdo...@apache.org
Subject svn commit: r733918 - in /incubator/openwebbeans/trunk/webbeans-impl/src/test: java/org/apache/webbeans/test/unittests/xml/definition/ java/org/apache/webbeans/test/xml/definition/ resources/org/apache/webbeans/test/xml/definition/
Date Mon, 12 Jan 2009 21:53:24 GMT
Author: gerdogdu
Date: Mon Jan 12 13:53:19 2009
New Revision: 733918

URL: http://svn.apache.org/viewvc?rev=733918&view=rev
Log:
OWB-39 extends the XMLDefinitionTest, thanks  Mark Struberg

Added:
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/definition/TestBeanUnnamed.java
  (with props)
    incubator/openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/xml/definition/testBeanUnnamed.xml
  (with props)
Modified:
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/xml/definition/XMLDefinitionTest.java
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/definition/MockAsynchronousCreditCardPaymentProcessor.java
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/definition/PaymentProcessor.java
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/definition/SystemConfig.java

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/xml/definition/XMLDefinitionTest.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/xml/definition/XMLDefinitionTest.java?rev=733918&r1=733917&r2=733918&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/xml/definition/XMLDefinitionTest.java
(original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/xml/definition/XMLDefinitionTest.java
Mon Jan 12 13:53:19 2009
@@ -21,6 +21,11 @@
 import org.apache.webbeans.test.servlet.TestContext;
 import org.apache.webbeans.test.unittests.xml.XMLTest;
 import org.apache.webbeans.test.xml.definition.Definition1;
+import org.apache.webbeans.test.xml.definition.Definition2;
+import org.apache.webbeans.test.xml.definition.MockAsynchronousCreditCardPaymentProcessor;
+import org.apache.webbeans.test.xml.definition.PaymentProcessor;
+import org.apache.webbeans.test.xml.definition.SystemConfig;
+import org.apache.webbeans.test.xml.definition.TestBeanUnnamed;
 import org.apache.webbeans.xml.XMLUtil;
 import org.dom4j.Element;
 import org.junit.Before;
@@ -42,101 +47,98 @@
     @Test
     public void testDefinition1()
     {
-        Throwable e = null;
-        try
-        {
-            InputStream stream = XMLTest.class.getClassLoader().getResourceAsStream("org/apache/webbeans/test/xml/definition/definition1.xml");
-            Assert.assertNotNull(stream);
+        XMLComponentImpl<?> compDef = getWebBeanFromXml("org/apache/webbeans/test/xml/definition/definition1.xml");
 
-            clear();
+        Assert.assertEquals("definition1", compDef.getName());
 
-            Element rootElement = XMLUtil.getRootElement(stream);
-            Element beanElement = (Element) rootElement.elements().get(0);
-
-            Class<?> clazz = XMLUtil.getElementJavaType(beanElement);
-
-            defineXMLSimpleWebBeans(clazz, beanElement);
-
-            Assert.assertEquals(1, getComponents().size());
-            Object def = getComponents().get(0);
-
-            Assert.assertTrue(def instanceof XMLComponentImpl);
-
-            XMLComponentImpl<?> comp = (XMLComponentImpl<?>) def;
-
-            Assert.assertEquals("definition1", comp.getName());
-
-            Object instance = comp.create();
-
-            Assert.assertNotNull(instance);
-            Assert.assertTrue(instance instanceof Definition1);
-
-        }
-        catch (Throwable e1)
-        {
-            e1.printStackTrace();
-            e = e1;
-        }
-
-        Assert.assertNull(e);
+        Object instance = compDef.create();
 
+        Assert.assertNotNull(instance);
+        Assert.assertTrue(instance instanceof Definition1);
     }
 
+
     @Test
     public void testDefinition2()
     {
-        Throwable e = null;
-        try
-        {
-            InputStream stream = XMLTest.class.getClassLoader().getResourceAsStream("org/apache/webbeans/test/xml/definition/definition2.xml");
-            Assert.assertNotNull(stream);
-
-            clear();
+        XMLComponentImpl<?> compDef = getWebBeanFromXml("org/apache/webbeans/test/xml/definition/definition2.xml");
 
-            Element rootElement = XMLUtil.getRootElement(stream);
-            Element beanElement = (Element) rootElement.elements().get(0);
-
-            Class<?> clazz = XMLUtil.getElementJavaType(beanElement);
-
-            defineXMLSimpleWebBeans(clazz, beanElement);
-
-        }
-        catch (Throwable e1)
-        {
-            e1.printStackTrace();
-            e = e1;
-        }
-
-        Assert.assertNull(e);
+        Object instance = compDef.create();
 
+        Assert.assertNotNull(instance);
+        Assert.assertTrue(instance instanceof Definition2);
     }
 
     @Test
     public void testDefinition3()
     {
-        Throwable e = null;
-        try
-        {
-            InputStream stream = XMLTest.class.getClassLoader().getResourceAsStream("org/apache/webbeans/test/xml/definition/definition3.xml");
-            Assert.assertNotNull(stream);
+        XMLComponentImpl<?> compDef = getWebBeanFromXml("org/apache/webbeans/test/xml/definition/definition3.xml");
+        
+        // we have to additionally define the PaymentProcessor and SystemConfig
+        // which would in real world parsed by the scanner 
+        defineSimpleWebBean(PaymentProcessor.class);
+        defineSimpleWebBean(SystemConfig.class);
+        
+        Assert.assertEquals("asyncCreditCardPaymentProcessor", compDef.getName());
+        
+        Object instance = compDef.create();
+
+        Assert.assertNotNull(instance);
+        Assert.assertTrue(instance instanceof MockAsynchronousCreditCardPaymentProcessor);
+        
+        MockAsynchronousCreditCardPaymentProcessor ccProcessor = (MockAsynchronousCreditCardPaymentProcessor)
instance;
+        
+        SystemConfig config = ccProcessor.getConfig();
+        Assert.assertEquals("default", config.getValue());
+        
+        PaymentProcessor paymentProcesor = ccProcessor.getPaymentProcessor();
+        Assert.assertNotNull(paymentProcesor);
+    }
+
+    @Test
+    public void testWebBeanUnnamed()
+    {
+        XMLComponentImpl<?> compDef = getWebBeanFromXml("org/apache/webbeans/test/xml/definition/testBeanUnnamed.xml");
+        
+        // an unnamed bean must not have a name 
+        Assert.assertNull(compDef.getName());
+        
+        Object instance = compDef.create();
+        Assert.assertNotNull(instance);
+        Assert.assertTrue(instance instanceof TestBeanUnnamed);
+    }
+
+    
+    /**
+     * Private helper function which loads a WebBean definition from the given xmlResourcePath.
+     * This will first do a Class lookup and take his annotations as a base, later overlaying
+     * it with the definitions from the given XML.
+     *  
+     * @param xmlResourcePath
+     * @return XMLComponentImpl<?> with the WebBean definition 
+     */
+    private XMLComponentImpl<?> getWebBeanFromXml(String xmlResourcePath)
+    {
+        InputStream stream = XMLTest.class.getClassLoader().getResourceAsStream(xmlResourcePath);
+        Assert.assertNotNull(stream);
 
-            clear();
+        clear();
 
-            Element rootElement = XMLUtil.getRootElement(stream);
-            Element beanElement = (Element) rootElement.elements().get(0);
+        Element rootElement = XMLUtil.getRootElement(stream);
+        Element beanElement = (Element) rootElement.elements().get(0);
 
-            Class<?> clazz = XMLUtil.getElementJavaType(beanElement);
+        Class<?> clazz = XMLUtil.getElementJavaType(beanElement);
 
-            defineXMLSimpleWebBeans(clazz, beanElement);
+        defineXMLSimpleWebBeans(clazz, beanElement);
 
-        }
-        catch (Throwable e1)
-        {
-            e1.printStackTrace();
-            e = e1;
-        }
+        Assert.assertEquals(1, getComponents().size());
+        Object def = getComponents().get(0);
+        
+        Assert.assertNotNull(def);
+        
+        Assert.assertTrue(def instanceof XMLComponentImpl);
 
-        Assert.assertNull(e);
+        return (XMLComponentImpl<?>) def;
     }
 
 }

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/definition/MockAsynchronousCreditCardPaymentProcessor.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/definition/MockAsynchronousCreditCardPaymentProcessor.java?rev=733918&r1=733917&r2=733918&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/definition/MockAsynchronousCreditCardPaymentProcessor.java
(original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/definition/MockAsynchronousCreditCardPaymentProcessor.java
Mon Jan 12 13:53:19 2009
@@ -16,9 +16,21 @@
 public class MockAsynchronousCreditCardPaymentProcessor
 {
     PaymentProcessor synchronousProcessor;
+    SystemConfig config;
 
     void init(SystemConfig config)
     {
+        this.config = config;
+    }
+
+    public SystemConfig getConfig()
+    {
+        return config;
+    }
+
+    public PaymentProcessor getPaymentProcessor()
+    {
+        return synchronousProcessor;
     }
 
 }

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/definition/PaymentProcessor.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/definition/PaymentProcessor.java?rev=733918&r1=733917&r2=733918&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/definition/PaymentProcessor.java
(original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/definition/PaymentProcessor.java
Mon Jan 12 13:53:19 2009
@@ -13,6 +13,11 @@
  */
 package org.apache.webbeans.test.xml.definition;
 
+import org.apache.webbeans.test.annotation.binding.PayBy;
+import org.apache.webbeans.test.annotation.binding.Synchronous;
+
+@Synchronous
+@PayBy(value="CREDIT_CARD")
 public class PaymentProcessor
 {
 

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/definition/SystemConfig.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/definition/SystemConfig.java?rev=733918&r1=733917&r2=733918&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/definition/SystemConfig.java
(original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/definition/SystemConfig.java
Mon Jan 12 13:53:19 2009
@@ -15,5 +15,15 @@
 
 public class SystemConfig
 {
+    private String value = "default";
 
+    public String getValue()
+    {
+        return value;
+    }
+
+    public void setValue(String value)
+    {
+        this.value = value;
+    }
 }

Added: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/definition/TestBeanUnnamed.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/definition/TestBeanUnnamed.java?rev=733918&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/definition/TestBeanUnnamed.java
(added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/definition/TestBeanUnnamed.java
Mon Jan 12 13:53:19 2009
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
+ * or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.apache.webbeans.test.xml.definition;
+
+/**
+ * This test WebBean has no Named section neither via Annotation nor via XML definition.

+ */
+public class TestBeanUnnamed
+{
+    public TestBeanUnnamed()
+    {
+
+    }
+
+}

Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/xml/definition/TestBeanUnnamed.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/xml/definition/testBeanUnnamed.xml
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/xml/definition/testBeanUnnamed.xml?rev=733918&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/xml/definition/testBeanUnnamed.xml
(added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/xml/definition/testBeanUnnamed.xml
Mon Jan 12 13:53:19 2009
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<WebBeans 	xmlns="urn:java:javax.webbeans"
+		  	xmlns:myapp="urn:java:org.apache.webbeans.test.xml.definition"
+ 			xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+			xsi:schemaLocation="urn:java:javax.webbeans http://java.sun.com/jee/web-beans-1.0.xsd">
+	
+	<myapp:TestBeanUnnamed>
+		<RequestScoped/>
+		<Current/>
+		<Production/>
+	</myapp:TestBeanUnnamed>	
+	
+</WebBeans>
\ No newline at end of file

Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/xml/definition/testBeanUnnamed.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message