Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
356 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/Aircraft.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2010, Red Hat, Inc., 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.weld.tests.extensions.injectionTarget; | ||
|
||
interface Aircraft | ||
{ | ||
boolean isFlying(); | ||
} |
34 changes: 34 additions & 0 deletions
34
tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/AircraftDecorator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2010, Red Hat, Inc., 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.weld.tests.extensions.injectionTarget; | ||
|
||
import javax.decorator.Decorator; | ||
import javax.decorator.Delegate; | ||
import javax.inject.Inject; | ||
|
||
@Decorator | ||
class AircraftDecorator implements Aircraft | ||
{ | ||
@Inject @Delegate | ||
private Aircraft delegate; | ||
|
||
public boolean isFlying() | ||
{ | ||
return ! delegate.isFlying(); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...c/test/java/org/jboss/weld/tests/extensions/injectionTarget/InjectionTargetExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2010, Red Hat, Inc., 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.weld.tests.extensions.injectionTarget; | ||
|
||
import javax.enterprise.event.Observes; | ||
import javax.enterprise.inject.spi.Extension; | ||
import javax.enterprise.inject.spi.InjectionTarget; | ||
import javax.enterprise.inject.spi.ProcessInjectionTarget; | ||
|
||
public class InjectionTargetExtension implements Extension | ||
{ | ||
public void foo(@Observes ProcessInjectionTarget<Spitfire> event) | ||
{ | ||
InjectionTarget<Spitfire> it = event.getInjectionTarget(); | ||
event.setInjectionTarget(decorate(it)); | ||
} | ||
|
||
private <T> InjectionTarget<T> decorate(InjectionTarget<T> delegate) | ||
{ | ||
return new InjectionTargetWrapper<T>(delegate); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/InjectionTargetTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2010, Red Hat, Inc., 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.weld.tests.extensions.injectionTarget; | ||
|
||
import javax.enterprise.context.spi.CreationalContext; | ||
import javax.enterprise.inject.spi.Bean; | ||
|
||
import org.jboss.testharness.impl.packaging.Artifact; | ||
import org.jboss.testharness.impl.packaging.IntegrationTest; | ||
import org.jboss.testharness.impl.packaging.Packaging; | ||
import org.jboss.testharness.impl.packaging.PackagingType; | ||
import org.jboss.testharness.impl.packaging.jsr299.BeansXml; | ||
import org.jboss.testharness.impl.packaging.jsr299.Extension; | ||
import org.jboss.weld.test.AbstractWeldTest; | ||
import org.testng.annotations.Test; | ||
|
||
@Artifact | ||
@IntegrationTest | ||
@BeansXml("beans.xml") | ||
@Packaging(PackagingType.EAR) | ||
@Extension("javax.enterprise.inject.spi.Extension") | ||
public class InjectionTargetTest extends AbstractWeldTest | ||
{ | ||
@Test(description="WELD-557") | ||
public void testActualInstanceAndNotProxyPassedToInject() | ||
{ | ||
InjectionTargetWrapper.clear(); | ||
Spitfire aircraft = getReference(Spitfire.class); | ||
aircraft.isFlying(); | ||
assert aircraft.isTheSameInstance(InjectionTargetWrapper.injectInstance); | ||
} | ||
|
||
@Test(description="WELD-557") | ||
public void testActualInstanceAndNotProxyPassedToPostConstruct() | ||
{ | ||
InjectionTargetWrapper.clear(); | ||
Spitfire aircraft = getReference(Spitfire.class); | ||
aircraft.isFlying(); | ||
assert aircraft.isTheSameInstance(InjectionTargetWrapper.postConstructInstance); | ||
} | ||
|
||
@Test(description="WELD-557") | ||
public void testActualInstanceAndNotProxyPassedToPreDestroy() | ||
{ | ||
// prepare instance | ||
InjectionTargetWrapper.clear(); | ||
Bean<Spitfire> bean = getBean(Spitfire.class); | ||
CreationalContext<Spitfire> ctx = getCurrentManager().createCreationalContext(bean); | ||
Spitfire aircraft = (Spitfire) getCurrentManager().getReference(bean, Spitfire.class, ctx); | ||
// invoke business method | ||
aircraft.isFlying(); | ||
// destroy instance | ||
bean.destroy(aircraft, ctx); | ||
|
||
assert aircraft.isTheSameInstance(InjectionTargetWrapper.preDestroyInstance); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...src/test/java/org/jboss/weld/tests/extensions/injectionTarget/InjectionTargetWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2010, Red Hat, Inc., 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.weld.tests.extensions.injectionTarget; | ||
|
||
import java.util.Set; | ||
|
||
import javax.enterprise.context.spi.CreationalContext; | ||
import javax.enterprise.inject.spi.InjectionPoint; | ||
import javax.enterprise.inject.spi.InjectionTarget; | ||
|
||
class InjectionTargetWrapper<T> implements InjectionTarget<T> | ||
{ | ||
private InjectionTarget<T> delegate; | ||
public static Object injectInstance; | ||
public static Object postConstructInstance; | ||
public static Object preDestroyInstance; | ||
|
||
public static void clear() | ||
{ | ||
injectInstance = null; | ||
postConstructInstance = null; | ||
preDestroyInstance = null; | ||
} | ||
|
||
public InjectionTargetWrapper(InjectionTarget<T> delegate) | ||
{ | ||
this.delegate = delegate; | ||
} | ||
|
||
public void inject(T instance, CreationalContext<T> ctx) | ||
{ | ||
injectInstance = instance; | ||
delegate.inject(instance, ctx); | ||
} | ||
|
||
public void postConstruct(T instance) | ||
{ | ||
postConstructInstance = instance; | ||
delegate.postConstruct(instance); | ||
} | ||
|
||
public void preDestroy(T instance) | ||
{ | ||
preDestroyInstance = instance; | ||
delegate.preDestroy(instance); | ||
} | ||
|
||
public void dispose(T instance) | ||
{ | ||
delegate.dispose(instance); | ||
} | ||
|
||
public Set<InjectionPoint> getInjectionPoints() | ||
{ | ||
return delegate.getInjectionPoints(); | ||
} | ||
|
||
public T produce(CreationalContext<T> ctx) | ||
{ | ||
return delegate.produce(ctx); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/Secured.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2010, Red Hat, Inc., 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.weld.tests.extensions.injectionTarget; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Documented; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import javax.interceptor.InterceptorBinding; | ||
|
||
@InterceptorBinding | ||
@Retention(RUNTIME) | ||
@Target({ElementType.TYPE, ElementType.METHOD}) | ||
@Documented | ||
@interface Secured | ||
{ | ||
} |
32 changes: 32 additions & 0 deletions
32
tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/SecurityInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2010, Red Hat, Inc., 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.weld.tests.extensions.injectionTarget; | ||
|
||
import javax.interceptor.AroundInvoke; | ||
import javax.interceptor.Interceptor; | ||
import javax.interceptor.InvocationContext; | ||
|
||
@Interceptor | ||
@Secured | ||
class SecurityInterceptor | ||
{ | ||
@AroundInvoke | ||
public Object intercept(InvocationContext ctx) throws Exception | ||
{ | ||
return ! (Boolean) ctx.proceed(); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
tests/src/test/java/org/jboss/weld/tests/extensions/injectionTarget/Spitfire.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2010, Red Hat, Inc., 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.weld.tests.extensions.injectionTarget; | ||
|
||
import javax.enterprise.context.RequestScoped; | ||
|
||
@RequestScoped | ||
class Spitfire implements Aircraft | ||
{ | ||
@Secured | ||
public boolean interceptedMethod() | ||
{ | ||
return false; | ||
} | ||
|
||
public boolean isFlying() | ||
{ | ||
return false; | ||
} | ||
|
||
/* | ||
* Cannot use equals() since behavior of all Object class methods | ||
* except for toString() is not defined on the client proxy | ||
*/ | ||
public boolean isTheSameInstance(Object object) | ||
{ | ||
return this == object; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
tests/src/test/resources/org/jboss/weld/tests/extensions/injectionTarget/beans.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<beans> | ||
<interceptors> | ||
<class>org.jboss.weld.tests.extensions.injectionTarget.SecurityInterceptor</class> | ||
</interceptors> | ||
<decorators> | ||
<class>org.jboss.weld.tests.extensions.injectionTarget.AircraftDecorator</class> | ||
</decorators> | ||
</beans> |
1 change: 1 addition & 0 deletions
1
...ces/org/jboss/weld/tests/extensions/injectionTarget/javax.enterprise.inject.spi.Extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.jboss.weld.tests.extensions.injectionTarget.InjectionTargetExtension |