You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by st...@apache.org on 2013/03/12 15:30:34 UTC

svn commit: r1455547 - in /openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/disabledspecialization: ./ DisabledSpecializationTest.java LoginService.java MockLoginService.java VetoMe.java VetoMeExtension.java

Author: struberg
Date: Tue Mar 12 14:30:33 2013
New Revision: 1455547

URL: http://svn.apache.org/r1455547
Log:
OWB-788 provide a unit test for further debugging

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/disabledspecialization/
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/disabledspecialization/DisabledSpecializationTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/disabledspecialization/LoginService.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/disabledspecialization/MockLoginService.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/disabledspecialization/VetoMe.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/disabledspecialization/VetoMeExtension.java

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/disabledspecialization/DisabledSpecializationTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/disabledspecialization/DisabledSpecializationTest.java?rev=1455547&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/disabledspecialization/DisabledSpecializationTest.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/disabledspecialization/DisabledSpecializationTest.java Tue Mar 12 14:30:33 2013
@@ -0,0 +1,44 @@
+/*
+ * 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.newtests.specalization.disabledspecialization;
+
+import org.apache.webbeans.newtests.AbstractUnitTest;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Test that @Specializes on disabled beans is no problem.
+ */
+public class DisabledSpecializationTest extends AbstractUnitTest
+{
+
+    @Test
+    public void testSpecialization() throws Exception{
+        addExtension(new VetoMeExtension());
+        startContainer(LoginService.class, MockLoginService.class);
+
+        LoginService loginService = getInstance(LoginService.class);
+        Assert.assertNotNull(loginService);
+
+        Assert.assertFalse(loginService.login("dummy"));
+    }
+
+
+}

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/disabledspecialization/LoginService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/disabledspecialization/LoginService.java?rev=1455547&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/disabledspecialization/LoginService.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/disabledspecialization/LoginService.java Tue Mar 12 14:30:33 2013
@@ -0,0 +1,33 @@
+/*
+ * 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.newtests.specalization.disabledspecialization;
+
+import javax.enterprise.context.Dependent;
+
+/**
+ * This dummy login service always denies the login attempt.
+ */
+@Dependent
+public class LoginService
+{
+    public boolean login(String userId)
+    {
+        return false;
+    }
+}

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/disabledspecialization/MockLoginService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/disabledspecialization/MockLoginService.java?rev=1455547&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/disabledspecialization/MockLoginService.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/disabledspecialization/MockLoginService.java Tue Mar 12 14:30:33 2013
@@ -0,0 +1,40 @@
+/*
+ * 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.newtests.specalization.disabledspecialization;
+
+import javax.enterprise.context.Dependent;
+import javax.enterprise.inject.Specializes;
+
+/**
+ * And this version always logs in.
+ *
+ * The important point is that this version is always
+ * disabled via a veto Extension through ProcessAnnotatedType.
+ */
+@Dependent
+@Specializes
+@VetoMe
+public class MockLoginService extends LoginService
+{
+    @Override
+    public boolean login(String userId)
+    {
+        return true;
+    }
+}

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/disabledspecialization/VetoMe.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/disabledspecialization/VetoMe.java?rev=1455547&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/disabledspecialization/VetoMe.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/disabledspecialization/VetoMe.java Tue Mar 12 14:30:33 2013
@@ -0,0 +1,19 @@
+package org.apache.webbeans.newtests.specalization.disabledspecialization;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Veto all beans annotated with this marker.
+ */
+@Target( { ElementType.METHOD, ElementType.TYPE, ElementType.FIELD })
+@Retention(RetentionPolicy.RUNTIME)
+@Inherited
+@Documented
+public @interface VetoMe
+{
+}

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/disabledspecialization/VetoMeExtension.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/disabledspecialization/VetoMeExtension.java?rev=1455547&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/disabledspecialization/VetoMeExtension.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/disabledspecialization/VetoMeExtension.java Tue Mar 12 14:30:33 2013
@@ -0,0 +1,37 @@
+/*
+ * 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.newtests.specalization.disabledspecialization;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessAnnotatedType;
+
+/**
+ * A CDI Extension which handles the {@link VetoMe} annotations.
+ */
+public class VetoMeExtension implements Extension
+{
+    public void vetoTheBeans(@Observes ProcessAnnotatedType pat)
+    {
+        if (pat.getAnnotatedType().isAnnotationPresent(VetoMe.class))
+        {
+            pat.veto();
+        }
+    }
+}