openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gerdo...@apache.org
Subject svn commit: r733157 - in /incubator/openwebbeans/trunk: distribution/ distribution/src/assembly/ webbeans-impl/src/test/java/org/apache/webbeans/test/mock/ webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/config/ webbeans-impl/src/test/re...
Date Fri, 09 Jan 2009 21:35:09 GMT
Author: gerdogdu
Date: Fri Jan  9 13:35:09 2009
New Revision: 733157

URL: http://svn.apache.org/viewvc?rev=733157&view=rev
Log:
OWB-36 WebBeansScanner Test,via Mark Struberg

Added:
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/mock/MockServletContext.java
  (with props)
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/config/
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/config/ScannerTestBean.java
  (with props)
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/config/WebBeansScannerTest.java
  (with props)
    incubator/openwebbeans/trunk/webbeans-impl/src/test/resources/META-INF/
    incubator/openwebbeans/trunk/webbeans-impl/src/test/resources/META-INF/ejb-jar.xml   (with
props)
    incubator/openwebbeans/trunk/webbeans-impl/src/test/resources/META-INF/web-beans.xml 
 (with props)
Modified:
    incubator/openwebbeans/trunk/distribution/pom.xml
    incubator/openwebbeans/trunk/distribution/src/assembly/dist.xml

Modified: incubator/openwebbeans/trunk/distribution/pom.xml
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/distribution/pom.xml?rev=733157&r1=733156&r2=733157&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/distribution/pom.xml (original)
+++ incubator/openwebbeans/trunk/distribution/pom.xml Fri Jan  9 13:35:09 2009
@@ -38,6 +38,7 @@
                 <artifactId>maven-assembly-plugin</artifactId>
                 <version>2.2-beta-2</version>
                 <configuration>
+                    <tarLongFileMode>gnu</tarLongFileMode>
                     <descriptors>
                         <descriptor>src/assembly/dist.xml</descriptor>
                     </descriptors>
@@ -68,33 +69,13 @@
         </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
-            <artifactId>guess</artifactId>
-            <version>${project.version}</version>
-            <classifier>sources</classifier>
-        </dependency>
-
-        <dependency>
-            <groupId>${project.groupId}</groupId>
-            <artifactId>webbeans-api</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>${project.groupId}</groupId>
             <artifactId>webbeans-api</artifactId>
             <version>${project.version}</version>
-            <classifier>sources</classifier>
-        </dependency>
-        
-        <dependency>
-            <groupId>${project.groupId}</groupId>
-            <artifactId>webbeans-impl</artifactId>
-            <version>${project.version}</version>
         </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
             <artifactId>webbeans-impl</artifactId>
             <version>${project.version}</version>
-            <classifier>sources</classifier>
         </dependency>
     </dependencies>
 

Modified: incubator/openwebbeans/trunk/distribution/src/assembly/dist.xml
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/distribution/src/assembly/dist.xml?rev=733157&r1=733156&r2=733157&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/distribution/src/assembly/dist.xml (original)
+++ incubator/openwebbeans/trunk/distribution/src/assembly/dist.xml Fri Jan  9 13:35:09 2009
@@ -85,15 +85,22 @@
             </includes>
         </dependencySet>
 
-        <dependencySet>
-            <outputDirectory>src</outputDirectory>
-            <includes>
-                <include>org.apache.openwebbeans:webbeans-api:jar:sources</include>
-                <include>org.apache.openwebbeans:webbeans-impl:jar:sources</include>
-                <include>org.apache.openwebbeans:guess:jar:sources</include>
-            </includes>
-        </dependencySet>
-
     </dependencySets>
 
+    <fileSets>
+        <fileSet>
+            <directory>..</directory>
+            <useDefaultExcludes>true</useDefaultExcludes>
+            <outputDirectory>src</outputDirectory>
+            <excludes>
+                <exclude>**/target/**</exclude>
+                <exclude>**/.classpath</exclude>
+                <exclude>**/.project</exclude>
+                <exclude>**/.settings/**</exclude>
+                <exclude>**/.git/**</exclude>
+                <exclude>**/.gitignore</exclude>
+            </excludes>
+        </fileSet>
+    </fileSets>
+
 </assembly>

Added: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/mock/MockServletContext.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/mock/MockServletContext.java?rev=733157&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/mock/MockServletContext.java
(added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/mock/MockServletContext.java
Fri Jan  9 13:35:09 2009
@@ -0,0 +1,183 @@
+package org.apache.webbeans.test.mock;
+
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+
+/**
+ * Implement the ServletContext interface for testing.
+ */
+public class MockServletContext implements ServletContext
+{
+
+    @SuppressWarnings("unchecked")
+    private Hashtable attributes = new Hashtable();
+
+    @Override
+    public Object getAttribute(String name)
+    {
+        return attributes.get(name);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public Enumeration getAttributeNames()
+    {
+        return attributes.keys();
+    }
+
+    @Override
+    public ServletContext getContext(String uripath)
+    {
+        return this;
+    }
+
+    @Override
+    public String getContextPath()
+    {
+        return "mockContextpath";
+    }
+
+    @Override
+    public String getInitParameter(String name)
+    {
+        return null;
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public Enumeration getInitParameterNames()
+    {
+        return new StringTokenizer(""); // 'standard' empty Enumeration
+    }
+
+    @Override
+    public int getMajorVersion()
+    {
+        return 2;
+    }
+
+    @Override
+    public String getMimeType(String file)
+    {
+        return null;
+    }
+
+    @Override
+    public int getMinorVersion()
+    {
+        return 0;
+    }
+
+    @Override
+    public RequestDispatcher getNamedDispatcher(String name)
+    {
+        return null;
+    }
+
+    @Override
+    public String getRealPath(String path)
+    {
+        return "mockRealPath";
+    }
+
+    @Override
+    public RequestDispatcher getRequestDispatcher(String path)
+    {
+        return null;
+    }
+
+    @Override
+    public URL getResource(String path) throws MalformedURLException
+    {
+        return null;
+    }
+
+    @Override
+    public InputStream getResourceAsStream(String path)
+    {
+        return null;
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public Set getResourcePaths(String path)
+    {
+        return null;
+    }
+
+    @Override
+    public String getServerInfo()
+    {
+        return "mockServer";
+    }
+
+    @Override
+    public Servlet getServlet(String name) throws ServletException
+    {
+        return null;
+    }
+
+    @Override
+    public String getServletContextName()
+    {
+        return null;
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public Enumeration getServletNames()
+    {
+        return null;
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public Enumeration getServlets()
+    {
+        return null;
+    }
+
+    @Override
+    public void log(String msg)
+    {
+        // TODO
+    }
+
+    @Override
+    public void log(Exception exception, String msg)
+    {
+        // TODO
+
+    }
+
+    @Override
+    public void log(String message, Throwable throwable)
+    {
+        // TODO
+
+    }
+
+    @Override
+    public void removeAttribute(String name)
+    {
+        attributes.remove(name);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public void setAttribute(String name, Object object)
+    {
+        attributes.put(name, object);
+    }
+
+}

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

Added: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/config/ScannerTestBean.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/config/ScannerTestBean.java?rev=733157&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/config/ScannerTestBean.java
(added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/config/ScannerTestBean.java
Fri Jan  9 13:35:09 2009
@@ -0,0 +1,25 @@
+package org.apache.webbeans.test.unittests.config;
+
+import javax.webbeans.Named;
+import javax.webbeans.RequestScoped;
+
+/**
+ * Test WebBean for the {@link WebBeansScannerTest}
+ */
+@RequestScoped
+@Named
+public class ScannerTestBean
+{
+    private int myInt = 3;
+
+    public int getMyInt()
+    {
+        return myInt;
+    }
+
+    public void setMyInt(int myInt)
+    {
+        this.myInt = myInt;
+    }
+
+}

Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/config/ScannerTestBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/config/WebBeansScannerTest.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/config/WebBeansScannerTest.java?rev=733157&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/config/WebBeansScannerTest.java
(added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/config/WebBeansScannerTest.java
Fri Jan  9 13:35:09 2009
@@ -0,0 +1,126 @@
+package org.apache.webbeans.test.unittests.config;
+
+import java.util.Map;
+import java.util.Set;
+
+import javax.servlet.ServletContext;
+import javax.webbeans.Named;
+import javax.webbeans.RequestScoped;
+
+import junit.framework.Assert;
+
+import org.apache.webbeans.config.WebBeansScanner;
+import org.apache.webbeans.test.mock.MockServletContext;
+import org.apache.webbeans.test.servlet.TestContext;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test the {@link WebBeansScanner}.
+ */
+public class WebBeansScannerTest extends TestContext
+{
+
+    public WebBeansScannerTest()
+    {
+        super(WebBeansScannerTest.class.getName());
+    }
+
+    @Before
+    public void init()
+    {
+        super.init();
+    }
+
+    @Test
+    public void testWebBeansScanner() throws Exception
+    {
+        WebBeansScanner scanner = new WebBeansScanner();
+
+        ServletContext servletContext = new MockServletContext();
+        scanner.scan(servletContext);
+        
+        // try to re-run the scan
+        scanner.scan(servletContext);
+
+        Map<String, Set<String>> classMap = scanner.getANNOTATION_DB().getClassIndex();
+        Assert.assertNotNull(classMap);
+        Assert.assertFalse(classMap.isEmpty());
+        Set<String> testBeanAnnotations = classMap.get(ScannerTestBean.class.getName());
+
+        String[] expectedAnnotations = new String[] { RequestScoped.class.getName(), Named.class.getName()
};
+
+        Assert.assertTrue(equalsIgnorePosition(testBeanAnnotations.toArray(), expectedAnnotations));
+    }
+
+    /**
+     * TODO please review this function and move to some place where all tests
+     * can use it! See also
+     * EJBInterceptComponentTest#testMultipleInterceptedComponent and other test
+     * functions
+     * 
+     * Compare two arrays regardless of the position of the elements in the
+     * arrays. 
+     * The complex handling with temporary flags is necessary due to the
+     * possibility of having multiple occurrences of the same element in the
+     * arrays. In this case both arrays have to contain the exactly same amount
+     * of those elements.
+     * 
+     * This is only suited for smaller arrays (e.g. count < 100) since the
+     * algorithm uses a product of both arrays.
+     * 
+     * If one likes to use this for larger arrays, we'd have to use hashes.
+     * 
+     * @param arr1
+     * @param arr2
+     * @return
+     */
+    public static boolean equalsIgnorePosition(Object[] arr1, Object[] arr2)
+    {
+        if (arr1 == null && arr2 == null)
+        {
+            return true;
+        }
+
+        if (arr1 == null || arr2 == null)
+        {
+            return false;
+        }
+
+        if (arr1.length != arr2.length)
+        {
+            return false;
+        }
+
+        boolean[] found1 = new boolean[arr1.length];
+        boolean[] found2 = new boolean[arr2.length];
+
+        for (int i1 = 0; i1 < arr1.length; i1++)
+        {
+            Object o1 = arr1[i1];
+
+            for (int i2 = 0; i2 < arr2.length; i2++)
+            {
+                Object o2 = arr2[i2];
+
+                // if they are equal and not found already
+                if (o1.equals(o2) && found2[i2] == false)
+                {
+                    // mark the entries in both arrays as found
+                    found1[i1] = true;
+                    found2[i2] = true;
+                    break;
+                }
+            }
+        }
+
+        for (int i = 0; i < found1.length; i++)
+        {
+            if (!found1[i] || !found2[i])
+            {
+                return false;
+            }
+        }
+        return true;
+    }
+}

Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/config/WebBeansScannerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/openwebbeans/trunk/webbeans-impl/src/test/resources/META-INF/ejb-jar.xml
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/resources/META-INF/ejb-jar.xml?rev=733157&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/resources/META-INF/ejb-jar.xml (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/resources/META-INF/ejb-jar.xml Fri
Jan  9 13:35:09 2009
@@ -0,0 +1,39 @@
+<?xml version="1.0"?>
+
+<!DOCTYPE ejb-jar PUBLIC 
+   '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN' 
+   'http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd'>
+
+<!-- 
+    This file is only needed to trigger the WebBeansScanner.
+    It does NOT contain a valid EJB configuration yet!
+    See the WebBeansScannerTest for further information.  
+-->
+
+<ejb-jar>
+   <enterprise-beans>
+
+      <!-- A minimal session EJB deployment -->
+      <session>
+         <ejb-name>testEJB</ejb-name>
+         <home>webbeans.testHome</home>
+         <remote>webbeans.test</remote>
+         <ejb-class>webbeans.TestBean</ejb-class>
+         <!-- or Stateless -->
+         <session-type>Stateful</session-type>
+         <transaction-type>Container</transaction-type>
+      </session>
+      
+      <!-- A minimal BMP entity EJB deployment -->
+      <entity>
+         <ejb-name>TestBMP</ejb-name>
+         <home>webbeans.TestBMPHome</home>
+         <remote>webbeans.TestBMP</remote>
+         <ejb-class>webbeans.TestBMPBean</ejb-class>
+         <persistence-type>Bean</persistence-type>
+         <prim-key-class>webbeans.TestBMPPK</prim-key-class>
+         <reentrant>False</reentrant>
+      </entity>
+
+   </enterprise-beans>
+</ejb-jar>

Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/test/resources/META-INF/ejb-jar.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/openwebbeans/trunk/webbeans-impl/src/test/resources/META-INF/web-beans.xml
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/resources/META-INF/web-beans.xml?rev=733157&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/resources/META-INF/web-beans.xml (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/resources/META-INF/web-beans.xml Fri
Jan  9 13:35:09 2009
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<WebBeans 	xmlns="urn:java:javax.webbeans"
+ 			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">
+<!-- 
+    This file is only needed to trigger the WebBeansScanner.
+    It does NOT contain a valid WebBeans configuration yet!
+    See the WebBeansScannerTest for further information.  
+-->
+	<Deploy>
+		<Standard/>
+		<Production/>
+	</Deploy>
+	
+</WebBeans>
\ No newline at end of file

Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/test/resources/META-INF/web-beans.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message