Skip to content

Commit

Permalink
BVTCK-48 Adding test for interceptor priority
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnarmorling committed Mar 17, 2013
1 parent f78cc9e commit 01e41fd
Show file tree
Hide file tree
Showing 11 changed files with 381 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pom.xml
Expand Up @@ -77,7 +77,7 @@
<java.source.version>1.6</java.source.version>
<java.target.version>1.6</java.target.version>
<jboss.test.audit.version>1.1.0.Final</jboss.test.audit.version>
<validation.api.version>1.1.0.CR2</validation.api.version>
<validation.api.version>1.1.0.CR2</validation.api.version>
<arquillian.version>1.0.0.Final</arquillian.version>
<shrinkwrap.version>1.0.0</shrinkwrap.version>
<shrinkwrap.descriptors.version>2.0.0-alpha-2</shrinkwrap.descriptors.version>
Expand Down Expand Up @@ -125,11 +125,21 @@
<artifactId>cdi-api</artifactId>
<version>1.1-PFD</version>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.interceptor</groupId>
<artifactId>jboss-interceptors-api_1.2_spec</artifactId>
<version>1.0.0.Alpha1</version>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.ejb</groupId>
<artifactId>jboss-ejb-api_3.2_spec</artifactId>
<version>1.0.0.Alpha2</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.2-b02</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
10 changes: 10 additions & 0 deletions tests/pom.xml
Expand Up @@ -45,11 +45,21 @@
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.interceptor</groupId>
<artifactId>jboss-interceptors-api_1.2_spec</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.ejb</groupId>
<artifactId>jboss-ejb-api_3.2_spec</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<scope>provided</scope>
</dependency>

</dependencies>

<build>
Expand Down
@@ -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) {
}
}
@@ -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 { };
}
@@ -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;
}
}
@@ -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();
}
}
@@ -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 {
}
@@ -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;
}
}
@@ -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 {
}
@@ -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();
}
}

0 comments on commit 01e41fd

Please sign in to comment.