Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WELD-580 Added test cases for AroundInvoke interceptor contract
- Loading branch information
1 parent
82399bb
commit 7e9d8f7
Showing
10 changed files
with
346 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
tests/src/test/java/org/jboss/weld/tests/interceptors/invalidContract/Intercept.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,37 @@ | ||
/* | ||
* 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.interceptors.invalidContract; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import javax.interceptor.InterceptorBinding; | ||
|
||
/** | ||
* Intercept | ||
* | ||
* @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a> | ||
* @version $Revision: $ | ||
*/ | ||
@InterceptorBinding | ||
@Target({ElementType.TYPE, ElementType.METHOD}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface Intercept { | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
tests/src/test/java/org/jboss/weld/tests/interceptors/invalidContract/NoArgInterceptor.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.interceptors.invalidContract; | ||
|
||
import javax.interceptor.AroundInvoke; | ||
import javax.interceptor.Interceptor; | ||
|
||
/** | ||
* By Contract this method should take InvocationContext as a argument, no arguments should result in DefinitionException | ||
* | ||
* @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a> | ||
* @version $Revision: $ | ||
*/ | ||
@Intercept @Interceptor | ||
public class NoArgInterceptor | ||
{ | ||
@AroundInvoke | ||
public Object intercept() throws Exception | ||
{ | ||
return null; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...rg/jboss/weld/tests/interceptors/invalidContract/NoArgInterceptorInvalidContractTest.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,45 @@ | ||
/* | ||
* 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.interceptors.invalidContract; | ||
|
||
import org.jboss.testharness.impl.packaging.Artifact; | ||
import org.jboss.testharness.impl.packaging.Classes; | ||
import org.jboss.testharness.impl.packaging.ExpectedDeploymentException; | ||
import org.jboss.weld.exceptions.DefinitionException; | ||
import org.jboss.weld.test.AbstractWeldTest; | ||
import org.testng.annotations.Test; | ||
|
||
/** | ||
* Test to verify that a DefinitionException is thrown when the defined Interceptor | ||
* does not follow the defined contract. | ||
* | ||
* "Around-invoke methods have the following signature: | ||
* Object <METHOD>(InvocationContext) throws Exception" | ||
* | ||
* @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a> | ||
* @version $Revision: $ | ||
*/ | ||
@ExpectedDeploymentException(DefinitionException.class) | ||
@Artifact | ||
@Classes({Intercept.class, Service.class, ServiceImpl.class, NoArgInterceptor.class}) | ||
public class NoArgInterceptorInvalidContractTest extends AbstractWeldTest | ||
{ | ||
@Test(groups = "broken", description = "WELD-580") | ||
public void shouldHaveThrownDefinitionException() throws Exception | ||
{ | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...va/org/jboss/weld/tests/interceptors/invalidContract/NotThrowingExceptionInterceptor.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,37 @@ | ||
/* | ||
* 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.interceptors.invalidContract; | ||
|
||
import javax.interceptor.AroundInvoke; | ||
import javax.interceptor.Interceptor; | ||
import javax.interceptor.InvocationContext; | ||
|
||
/** | ||
* By Contract this method should throw Exception, not throwing should result in DefinitionException | ||
* | ||
* @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a> | ||
* @version $Revision: $ | ||
*/ | ||
@Intercept @Interceptor | ||
public class NotThrowingExceptionInterceptor | ||
{ | ||
@AroundInvoke | ||
public Object intercept(final InvocationContext context) | ||
{ | ||
return null; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...ests/interceptors/invalidContract/NotThrowingExceptionInterceptorInvalidContractTest.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,45 @@ | ||
/* | ||
* 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.interceptors.invalidContract; | ||
|
||
import org.jboss.testharness.impl.packaging.Artifact; | ||
import org.jboss.testharness.impl.packaging.Classes; | ||
import org.jboss.testharness.impl.packaging.ExpectedDeploymentException; | ||
import org.jboss.weld.exceptions.DefinitionException; | ||
import org.jboss.weld.test.AbstractWeldTest; | ||
import org.testng.annotations.Test; | ||
|
||
/** | ||
* Test to verify that a DefinitionException is thrown when the defined Interceptor | ||
* does not follow the defined contract. | ||
* | ||
* "Around-invoke methods have the following signature: | ||
* Object <METHOD>(InvocationContext) throws Exception" | ||
* | ||
* @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a> | ||
* @version $Revision: $ | ||
*/ | ||
@ExpectedDeploymentException(DefinitionException.class) | ||
@Artifact | ||
@Classes({Intercept.class, Service.class, ServiceImpl.class, NotThrowingExceptionInterceptor.class}) | ||
public class NotThrowingExceptionInterceptorInvalidContractTest extends AbstractWeldTest | ||
{ | ||
@Test(groups = "broken", description = "WELD-580") | ||
public void shouldHaveThrownDefinitionException() throws Exception | ||
{ | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
tests/src/test/java/org/jboss/weld/tests/interceptors/invalidContract/Service.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,28 @@ | ||
/* | ||
* 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.interceptors.invalidContract; | ||
|
||
/** | ||
* Service | ||
* | ||
* @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a> | ||
* @version $Revision: $ | ||
*/ | ||
public interface Service | ||
{ | ||
void on(); | ||
} |
31 changes: 31 additions & 0 deletions
31
tests/src/test/java/org/jboss/weld/tests/interceptors/invalidContract/ServiceImpl.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,31 @@ | ||
/* | ||
* 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.interceptors.invalidContract; | ||
|
||
/** | ||
* ServiceImpl | ||
* | ||
* @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a> | ||
* @version $Revision: $ | ||
*/ | ||
@Intercept | ||
public class ServiceImpl implements Service | ||
{ | ||
public void on() | ||
{ | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
tests/src/test/java/org/jboss/weld/tests/interceptors/invalidContract/VoidInterceptor.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,37 @@ | ||
/* | ||
* 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.interceptors.invalidContract; | ||
|
||
import javax.interceptor.AroundInvoke; | ||
import javax.interceptor.Interceptor; | ||
import javax.interceptor.InvocationContext; | ||
|
||
/** | ||
* By Contract this method should return Object, void methods should result in DefinitionException | ||
* | ||
* @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a> | ||
* @version $Revision: $ | ||
*/ | ||
@Intercept @Interceptor | ||
public class VoidInterceptor | ||
{ | ||
@AroundInvoke | ||
public void intercept(final InvocationContext context) throws Exception | ||
{ | ||
context.proceed(); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...org/jboss/weld/tests/interceptors/invalidContract/VoidInterceptorInvalidContractTest.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,45 @@ | ||
/* | ||
* 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.interceptors.invalidContract; | ||
|
||
import org.jboss.testharness.impl.packaging.Artifact; | ||
import org.jboss.testharness.impl.packaging.Classes; | ||
import org.jboss.testharness.impl.packaging.ExpectedDeploymentException; | ||
import org.jboss.weld.exceptions.DefinitionException; | ||
import org.jboss.weld.test.AbstractWeldTest; | ||
import org.testng.annotations.Test; | ||
|
||
/** | ||
* Test to verify that a DefinitionException is thrown when the defined Interceptor | ||
* does not follow the defined contract. | ||
* | ||
* "Around-invoke methods have the following signature: | ||
* Object <METHOD>(InvocationContext) throws Exception" | ||
* | ||
* @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a> | ||
* @version $Revision: $ | ||
*/ | ||
@ExpectedDeploymentException(DefinitionException.class) | ||
@Artifact | ||
@Classes({Intercept.class, Service.class, ServiceImpl.class, VoidInterceptor.class}) | ||
public class VoidInterceptorInvalidContractTest extends AbstractWeldTest | ||
{ | ||
@Test(groups = "broken", description = "WELD-580") | ||
public void shouldHaveThrownDefinitionException() throws Exception | ||
{ | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
tests/src/test/resources/org/jboss/weld/tests/interceptors/invalidContract/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,5 @@ | ||
<beans> | ||
<interceptors> | ||
<class>org.jboss.weld.tests.interceptors.invalidContract.ServiceInterceptor</class> | ||
</interceptors> | ||
</beans> |