[webbeans-commits] Webbeans SVN: r3846 - in ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit: interceptor and 1 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Mon Oct 5 03:59:15 EDT 2009
Author: marius.bogoevici
Date: 2009-10-05 03:59:14 -0400 (Mon, 05 Oct 2009)
New Revision: 3846
Added:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/PrimaryInterceptionBinding.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/SecondaryInterceptionBinding.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/SimpleBean.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/SimpleBeanImpl.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/SimpleDecorator.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/SimpleInterceptor.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/SimpleInterceptorTest.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/TwoBindingsInterceptor.java
Log:
A couple of interceptor tests.
Added: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/PrimaryInterceptionBinding.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/PrimaryInterceptionBinding.java (rev 0)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/PrimaryInterceptionBinding.java 2009-10-05 07:59:14 UTC (rev 3846)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed 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.jboss.webbeans.test.unit.interceptor.simple;
+
+import javax.interceptor.InterceptorBinding;
+import java.lang.annotation.*;
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.RetentionPolicy.*;
+
+/**
+ * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
+ */
+ at InterceptorBinding
+ at Documented
+ at Retention(RUNTIME)
+ at Target({METHOD, TYPE})
+public @interface PrimaryInterceptionBinding
+{
+}
Added: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/SecondaryInterceptionBinding.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/SecondaryInterceptionBinding.java (rev 0)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/SecondaryInterceptionBinding.java 2009-10-05 07:59:14 UTC (rev 3846)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed 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.jboss.webbeans.test.unit.interceptor.simple;
+
+import javax.interceptor.InterceptorBinding;
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
+ */
+ at InterceptorBinding
+ at Documented
+ at Retention(RUNTIME)
+ at Target({METHOD, TYPE})
+ at PrimaryInterceptionBinding
+public @interface SecondaryInterceptionBinding
+{
+}
Added: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/SimpleBean.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/SimpleBean.java (rev 0)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/SimpleBean.java 2009-10-05 07:59:14 UTC (rev 3846)
@@ -0,0 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed 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.jboss.webbeans.test.unit.interceptor.simple;
+
+/**
+ * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
+ */
+public interface SimpleBean
+{
+ String doSomething();
+}
Added: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/SimpleBeanImpl.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/SimpleBeanImpl.java (rev 0)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/SimpleBeanImpl.java 2009-10-05 07:59:14 UTC (rev 3846)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed 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.jboss.webbeans.test.unit.interceptor.simple;
+
+import javax.annotation.PostConstruct;
+
+/**
+ * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
+ */
+//@PrimaryInterceptionBinding
+public class SimpleBeanImpl implements SimpleBean
+{
+
+ public static boolean businessMethodInvoked = false;
+
+ public static boolean postConstructCalled = false;
+
+ @SecondaryInterceptionBinding
+ public String doSomething()
+ {
+ businessMethodInvoked = true;
+ return "Hello!";
+ }
+
+ @PostConstruct
+ public void doPostConstruct()
+ {
+ postConstructCalled = true;
+ }
+
+}
Copied: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/SimpleDecorator.java (from rev 3834, ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/decorator/simple/SimpleDecorator1.java)
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/SimpleDecorator.java (rev 0)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/SimpleDecorator.java 2009-10-05 07:59:14 UTC (rev 3846)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed 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.jboss.webbeans.test.unit.interceptor.simple;
+
+import org.jboss.webbeans.test.unit.interceptor.simple.SimpleBean;
+
+import javax.decorator.Decorates;
+import javax.decorator.Decorator;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+ at Decorator
+public class SimpleDecorator
+{
+ @Decorates
+ SimpleBean delegate;
+
+ public String doSomething()
+ {
+ return "decorated-" + delegate.doSomething() + "-decorated";
+ }
+}
\ No newline at end of file
Added: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/SimpleInterceptor.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/SimpleInterceptor.java (rev 0)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/SimpleInterceptor.java 2009-10-05 07:59:14 UTC (rev 3846)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed 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.jboss.webbeans.test.unit.interceptor.simple;
+
+import javax.interceptor.Interceptor;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
+ */
+ at Interceptor @PrimaryInterceptionBinding
+public class SimpleInterceptor
+{
+ public static boolean postConstructCalled = false;
+ public static boolean aroundInvokeCalled = false;
+ public static boolean preDestroyCalled = false;
+
+ @PostConstruct
+ public void doPostConstruct(InvocationContext context) throws Exception
+ {
+ postConstructCalled = true;
+ context.proceed();
+ }
+
+ @AroundInvoke
+ public Object doAround(InvocationContext context) throws Exception
+ {
+ aroundInvokeCalled = true;
+ return context.proceed();
+ }
+
+ @PreDestroy
+ public void doPreDestroy(InvocationContext context) throws Exception
+ {
+ preDestroyCalled = true;
+ context.proceed();
+ }
+}
Added: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/SimpleInterceptorTest.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/SimpleInterceptorTest.java (rev 0)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/SimpleInterceptorTest.java 2009-10-05 07:59:14 UTC (rev 3846)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed 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.jboss.webbeans.test.unit.interceptor.simple;
+
+import org.jboss.webbeans.test.AbstractWebBeansTest;
+import org.jboss.webbeans.metadata.cache.InterceptorBindingModel;
+import org.jboss.webbeans.metadata.TypeStore;
+import org.jboss.webbeans.resources.ClassTransformer;
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.jsr299.BeansXml;
+import org.testng.annotations.Test;
+
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.context.spi.CreationalContext;
+import java.util.Set;
+import java.lang.annotation.Annotation;
+
+/**
+ * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
+ */
+ at Artifact
+ at BeansXml("beans.xml")
+public class SimpleInterceptorTest extends AbstractWebBeansTest
+{
+
+ @Test
+ public void testInterceptorModel()
+ {
+ InterceptorBindingModel<SecondaryInterceptionBinding> interceptorBindingModel
+ = new InterceptorBindingModel<SecondaryInterceptionBinding>(SecondaryInterceptionBinding.class, new ClassTransformer(new TypeStore()));
+ Set<Annotation> annotations = interceptorBindingModel.getInheritedInterceptionBindingTypes();
+ assert annotations.size() != 0;
+ }
+
+ @Test
+ public void testSimpleInterceptor()
+ {
+ Bean bean = getCurrentManager().getBeans(SimpleBeanImpl.class).iterator().next();
+ CreationalContext creationalContext = getCurrentManager().createCreationalContext(bean);
+ SimpleBeanImpl simpleBean = (SimpleBeanImpl)bean.create(creationalContext);
+ String result = simpleBean.doSomething();
+ assert "decorated-Hello!-decorated".equals(result);
+ bean.destroy(simpleBean, creationalContext);
+ assert SimpleInterceptor.aroundInvokeCalled;
+ assert !SimpleInterceptor.postConstructCalled;
+ assert !SimpleInterceptor.preDestroyCalled;
+ assert TwoBindingsInterceptor.aroundInvokeCalled;
+ assert SimpleBeanImpl.postConstructCalled;
+
+ }
+}
Added: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/TwoBindingsInterceptor.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/TwoBindingsInterceptor.java (rev 0)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/interceptor/simple/TwoBindingsInterceptor.java 2009-10-05 07:59:14 UTC (rev 3846)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed 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.jboss.webbeans.test.unit.interceptor.simple;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+import javax.interceptor.Interceptor;
+
+/**
+ * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
+ */
+ at SecondaryInterceptionBinding
+ at Interceptor
+public class TwoBindingsInterceptor
+{
+ public static boolean aroundInvokeCalled = false;
+
+ @AroundInvoke
+ public Object doAround(InvocationContext context) throws Exception
+ {
+ aroundInvokeCalled = true;
+ return context.proceed();
+ }
+}
More information about the weld-commits
mailing list