You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by gp...@apache.org on 2012/01/02 19:02:14 UTC

git commit: DELTASPIKE-20 unit tests

Updated Branches:
  refs/heads/master 620d1f758 -> 94ba73cfc


DELTASPIKE-20 unit tests


Project: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/commit/94ba73cf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/tree/94ba73cf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/diff/94ba73cf

Branch: refs/heads/master
Commit: 94ba73cfcdbf7a13b6717051454dcf1b7cd2e67c
Parents: 620d1f7
Author: gpetracek <gp...@apache.org>
Authored: Mon Jan 2 19:00:51 2012 +0100
Committer: gpetracek <gp...@apache.org>
Committed: Mon Jan 2 19:00:51 2012 +0100

----------------------------------------------------------------------
 .../core/test/api/provider/BeanProviderTest.java   |  111 +++++++++++++++
 .../deltaspike/core/test/api/provider/MBean01.java |   29 ++++
 .../deltaspike/core/test/api/provider/MBean02.java |   29 ++++
 .../core/test/api/provider/MultiBean.java          |   26 ++++
 .../deltaspike/core/test/api/provider/NoBean.java  |   26 ++++
 5 files changed, 221 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/94ba73cf/deltaspike/core/impl/src/test/java/org/apache/deltaspike/core/test/api/provider/BeanProviderTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/core/test/api/provider/BeanProviderTest.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/core/test/api/provider/BeanProviderTest.java
new file mode 100644
index 0000000..f6c3f02
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/core/test/api/provider/BeanProviderTest.java
@@ -0,0 +1,111 @@
+/*
+* 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.deltaspike.core.test.api.provider;
+
+
+import org.apache.deltaspike.core.api.provider.BeanProvider;
+import org.apache.deltaspike.core.test.api.temptestutil.ShrinkWrapArchiveUtil;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.List;
+
+@RunWith(Arquillian.class)
+public class BeanProviderTest
+{
+    /**
+     *X TODO creating a WebArchive is only a workaround because JavaArchive cannot contain other archives.
+     */
+    @Deployment
+    public static WebArchive deploy()
+    {
+        return ShrinkWrap.create(WebArchive.class)
+                .addAsLibraries(ShrinkWrapArchiveUtil.getArchives(null,
+                                                  "META-INF/beans.xml",
+                                                  new String[]{"org.apache.deltaspike.core"},
+                                                  null))
+                .addClass(TestBean.class)
+                .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
+    }
+
+    /**
+     * lookup by type
+     */
+    @Test
+    public void simpleBeanLookupByType()
+    {
+        TestBean testBean = BeanProvider.getContextualReference(TestBean.class, false);
+
+        Assert.assertNotNull(testBean);
+    }
+
+    /**
+     * lookup by name
+     */
+    @Test
+    public void simpleBeanLookupByName()
+    {
+        TestBean testBean = BeanProvider.getContextualReference(TestBean.class, false, "extraNameBean");
+
+        Assert.assertNotNull(testBean);
+    }
+
+    /*
+     * lookup without result
+     */
+    @Test
+    public void optionalBeanLookup()
+    {
+        NoBean result = BeanProvider.getContextualReference(NoBean.class, true);
+
+        Assert.assertNull(result);
+    }
+
+    /*
+     * lookup of all beans of a given type
+     */
+    @Test
+    public void multiBeanLookupWithDependentBean() throws Exception
+    {
+        List<MultiBean> result = BeanProvider.getContextualReferences(MultiBean.class, false);
+
+        Assert.assertNotNull(result);
+
+        Assert.assertEquals(2, result.size());
+    }
+
+    /*
+     * lookup of all beans of a given type which aren't dependent scoped
+     */
+    @Test
+    public void multiBeanLookupWithoutDependentBean() throws Exception
+    {
+        List<MultiBean> result = BeanProvider.getContextualReferences(MultiBean.class, false, false);
+
+        Assert.assertNotNull(result);
+
+        Assert.assertEquals(1, result.size());
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/94ba73cf/deltaspike/core/impl/src/test/java/org/apache/deltaspike/core/test/api/provider/MBean01.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/core/test/api/provider/MBean01.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/core/test/api/provider/MBean01.java
new file mode 100644
index 0000000..cf97a44
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/core/test/api/provider/MBean01.java
@@ -0,0 +1,29 @@
+/*
+* 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.deltaspike.core.test.api.provider;
+
+import javax.enterprise.context.ApplicationScoped;
+
+/**
+ * Impl #1
+ */
+@ApplicationScoped
+public class MBean01 implements MultiBean
+{
+}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/94ba73cf/deltaspike/core/impl/src/test/java/org/apache/deltaspike/core/test/api/provider/MBean02.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/core/test/api/provider/MBean02.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/core/test/api/provider/MBean02.java
new file mode 100644
index 0000000..58f311f
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/core/test/api/provider/MBean02.java
@@ -0,0 +1,29 @@
+/*
+* 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.deltaspike.core.test.api.provider;
+
+import javax.enterprise.context.Dependent;
+
+/**
+ * Impl #2
+ */
+@Dependent
+public class MBean02 implements MultiBean
+{
+}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/94ba73cf/deltaspike/core/impl/src/test/java/org/apache/deltaspike/core/test/api/provider/MultiBean.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/core/test/api/provider/MultiBean.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/core/test/api/provider/MultiBean.java
new file mode 100644
index 0000000..edc193c
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/core/test/api/provider/MultiBean.java
@@ -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.deltaspike.core.test.api.provider;
+
+/**
+ * Interface for multiple beans
+ */
+public interface MultiBean
+{
+}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/94ba73cf/deltaspike/core/impl/src/test/java/org/apache/deltaspike/core/test/api/provider/NoBean.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/core/test/api/provider/NoBean.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/core/test/api/provider/NoBean.java
new file mode 100644
index 0000000..52b21d1
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/core/test/api/provider/NoBean.java
@@ -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.deltaspike.core.test.api.provider;
+
+/**
+ * Interface without implementation
+ */
+public interface NoBean
+{
+}