Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BVTCK-48 Adding test for interceptor priority
- Loading branch information
1 parent
f78cc9e
commit 01e41fd
Showing
11 changed files
with
381 additions
and
1 deletion.
There are no files selected for viewing
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
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
28 changes: 28 additions & 0 deletions
28
...bernate/beanvalidation/tck/tests/integration/cdi/executable/priority/CalendarService.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 2013, 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.hibernate.beanvalidation.tck.tests.integration.cdi.executable.priority; | ||
|
||
/** | ||
* @author Gunnar Morling | ||
*/ | ||
@Early | ||
@Late | ||
public class CalendarService { | ||
|
||
public void createEvent(@CustomConstraint String name) { | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...ernate/beanvalidation/tck/tests/integration/cdi/executable/priority/CustomConstraint.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,41 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2013, 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.hibernate.beanvalidation.tck.tests.integration.cdi.executable.priority; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
import javax.validation.Constraint; | ||
import javax.validation.Payload; | ||
|
||
import static java.lang.annotation.ElementType.PARAMETER; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
/** | ||
* @author Gunnar Morling | ||
*/ | ||
@Documented | ||
@Constraint(validatedBy = CustomConstraintValidator.class) | ||
@Target({ PARAMETER }) | ||
@Retention(RUNTIME) | ||
public @interface CustomConstraint { | ||
String message() default "default message"; | ||
|
||
Class<?>[] groups() default { }; | ||
|
||
Class<? extends Payload>[] payload() default { }; | ||
} |
46 changes: 46 additions & 0 deletions
46
...anvalidation/tck/tests/integration/cdi/executable/priority/CustomConstraintValidator.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,46 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2013, 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.hibernate.beanvalidation.tck.tests.integration.cdi.executable.priority; | ||
|
||
import javax.inject.Inject; | ||
import javax.validation.ConstraintValidator; | ||
import javax.validation.ConstraintValidatorContext; | ||
import javax.validation.constraintvalidation.SupportedValidationTarget; | ||
import javax.validation.constraintvalidation.ValidationTarget; | ||
|
||
import static org.testng.Assert.assertFalse; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
@SupportedValidationTarget(value = ValidationTarget.PARAMETERS) | ||
public class CustomConstraintValidator implements ConstraintValidator<CustomConstraint, Object> { | ||
|
||
@Inject | ||
private InvocationTracker invocationTracker; | ||
|
||
@Override | ||
public void initialize(CustomConstraint parameters) { | ||
} | ||
|
||
@Override | ||
public boolean isValid(Object object, ConstraintValidatorContext constraintValidatorContext) { | ||
assertTrue( invocationTracker.isEarlierInterceptorInvoked() ); | ||
assertFalse( invocationTracker.isLaterInterceptorInvoked() ); | ||
|
||
invocationTracker.setValidatorInvoked( true ); | ||
return true; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...nate/beanvalidation/tck/tests/integration/cdi/executable/priority/EarlierInterceptor.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 @@ | ||
package org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.priority; | ||
|
||
import javax.annotation.Priority; | ||
import javax.inject.Inject; | ||
import javax.interceptor.AroundInvoke; | ||
import javax.interceptor.Interceptor; | ||
import javax.interceptor.InvocationContext; | ||
|
||
import static org.testng.Assert.assertFalse; | ||
|
||
@Interceptor | ||
@Early | ||
@Priority(4799) | ||
public class EarlierInterceptor { | ||
|
||
@Inject | ||
private InvocationTracker invocationTracker; | ||
|
||
@AroundInvoke | ||
public Object invoke(InvocationContext ctx) throws Exception { | ||
assertFalse( invocationTracker.isEarlierInterceptorInvoked() ); | ||
assertFalse( invocationTracker.isValidatorInvoked() ); | ||
assertFalse( invocationTracker.isLaterInterceptorInvoked() ); | ||
|
||
invocationTracker.setEarlierInterceptorInvoked( true ); | ||
return ctx.proceed(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...ava/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/priority/Early.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 2013, 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.hibernate.beanvalidation.tck.tests.integration.cdi.executable.priority; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
import javax.interceptor.InterceptorBinding; | ||
|
||
import static java.lang.annotation.ElementType.*; | ||
import static java.lang.annotation.RetentionPolicy.*; | ||
|
||
/** | ||
* @author Gunnar Morling | ||
*/ | ||
@InterceptorBinding | ||
@Target({ METHOD, TYPE }) | ||
@Retention(RUNTIME) | ||
public @interface Early { | ||
} |
54 changes: 54 additions & 0 deletions
54
...rnate/beanvalidation/tck/tests/integration/cdi/executable/priority/InvocationTracker.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,54 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2013, 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.hibernate.beanvalidation.tck.tests.integration.cdi.executable.priority; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
/** | ||
* @author Gunnar Morling | ||
*/ | ||
@ApplicationScoped | ||
public class InvocationTracker { | ||
|
||
private boolean earlierInterceptorInvoked = false; | ||
private boolean laterInterceptorInvoked = false; | ||
private boolean validatorInvoked = false; | ||
|
||
public boolean isEarlierInterceptorInvoked() { | ||
return earlierInterceptorInvoked; | ||
} | ||
|
||
public void setEarlierInterceptorInvoked(boolean earlierInterceptorInvoked) { | ||
this.earlierInterceptorInvoked = earlierInterceptorInvoked; | ||
} | ||
|
||
public boolean isLaterInterceptorInvoked() { | ||
return laterInterceptorInvoked; | ||
} | ||
|
||
public void setLaterInterceptorInvoked(boolean laterInterceptorInvoked) { | ||
this.laterInterceptorInvoked = laterInterceptorInvoked; | ||
} | ||
|
||
public boolean isValidatorInvoked() { | ||
return validatorInvoked; | ||
} | ||
|
||
public void setValidatorInvoked(boolean validatorInvoked) { | ||
this.validatorInvoked = validatorInvoked; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...java/org/hibernate/beanvalidation/tck/tests/integration/cdi/executable/priority/Late.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 2013, 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.hibernate.beanvalidation.tck.tests.integration.cdi.executable.priority; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
import javax.interceptor.InterceptorBinding; | ||
|
||
import static java.lang.annotation.ElementType.*; | ||
import static java.lang.annotation.RetentionPolicy.*; | ||
|
||
/** | ||
* @author Gunnar Morling | ||
*/ | ||
@InterceptorBinding | ||
@Target({ METHOD, TYPE }) | ||
@Retention(RUNTIME) | ||
public @interface Late { | ||
} |
29 changes: 29 additions & 0 deletions
29
...ernate/beanvalidation/tck/tests/integration/cdi/executable/priority/LaterInterceptor.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,29 @@ | ||
package org.hibernate.beanvalidation.tck.tests.integration.cdi.executable.priority; | ||
|
||
import javax.annotation.Priority; | ||
import javax.inject.Inject; | ||
import javax.interceptor.AroundInvoke; | ||
import javax.interceptor.Interceptor; | ||
import javax.interceptor.InvocationContext; | ||
|
||
import static org.testng.Assert.assertFalse; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
@Interceptor | ||
@Late | ||
@Priority(4801) | ||
public class LaterInterceptor { | ||
|
||
@Inject | ||
private InvocationTracker invocationTracker; | ||
|
||
@AroundInvoke | ||
public Object invoke(InvocationContext ctx) throws Exception { | ||
assertTrue( invocationTracker.isEarlierInterceptorInvoked() ); | ||
assertTrue( invocationTracker.isValidatorInvoked() ); | ||
assertFalse( invocationTracker.isLaterInterceptorInvoked() ); | ||
|
||
invocationTracker.setLaterInterceptorInvoked( true ); | ||
return ctx.proceed(); | ||
} | ||
} |
Oops, something went wrong.