Skip to content

Commit

Permalink
Issue #438 Fix the interceptor ordering test for both CDI Lite and Full
Browse files Browse the repository at this point in the history
  • Loading branch information
Ladicek authored and manovotn committed Mar 2, 2023
1 parent 5e3a5e1 commit fe2dcf7
Show file tree
Hide file tree
Showing 13 changed files with 227 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jboss.cdi.tck.tests.interceptors.definition.interceptorOrder;
package org.jboss.cdi.tck.tests.full.interceptors.definition.interceptorOrder;

import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.cdi.tck.tests.interceptors.definition.interceptorOrder;
package org.jboss.cdi.tck.tests.full.interceptors.definition.interceptorOrder;

import jakarta.enterprise.context.Dependent;
import jakarta.interceptor.AroundInvoke;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.cdi.tck.tests.interceptors.definition.interceptorOrder;
package org.jboss.cdi.tck.tests.full.interceptors.definition.interceptorOrder;

import jakarta.annotation.Priority;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.Interceptor;
import jakarta.interceptor.InvocationContext;

import org.jboss.cdi.tck.util.ActionSequence;

@Interceptor
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.cdi.tck.tests.full.interceptors.definition.interceptorOrder;

import jakarta.annotation.Priority;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.Interceptor;
import jakarta.interceptor.InvocationContext;
import org.jboss.cdi.tck.util.ActionSequence;

@Interceptor
@Secure
@Priority(Interceptor.Priority.APPLICATION+1)
public class FirstInterceptor {

@AroundInvoke
public Object alwaysReturnThis(InvocationContext ctx) throws Exception {
ActionSequence.addAction(FirstInterceptor.class.getName());
return ctx.proceed();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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.cdi.tck.tests.full.interceptors.definition.interceptorOrder;

import jakarta.enterprise.context.Dependent;

@Secure
@Dependent
public class Foo {
public void bar() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* 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.cdi.tck.tests.full.interceptors.definition.interceptorOrder;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.cdi.tck.AbstractTest;
import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder;
import org.jboss.cdi.tck.util.ActionSequence;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.impl.BeansXml;
import org.jboss.test.audit.annotations.SpecAssertion;
import org.jboss.test.audit.annotations.SpecAssertions;
import org.jboss.test.audit.annotations.SpecVersion;
import org.testng.annotations.Test;

import java.util.List;

import static org.jboss.cdi.tck.TestGroups.CDI_FULL;
import static org.jboss.cdi.tck.cdi.Sections.ENABLED_INTERCEPTORS;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;

@SpecVersion(spec = "cdi", version = "2.0")
@Test(groups = CDI_FULL)
public class InterceptorOrderTest extends AbstractTest {

@Deployment
public static WebArchive createTestArchive() {
return new WebArchiveBuilder()
.withTestClassPackage(InterceptorOrderTest.class)
.withBeansXml(new BeansXml().interceptors(SecondInterceptor.class, FirstInterceptor.class, TransactionalInterceptor.class))
.build();
}

@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER)
@SpecAssertions({ @SpecAssertion(section = ENABLED_INTERCEPTORS, id = "b"), @SpecAssertion(section = ENABLED_INTERCEPTORS, id = "c") })
public void testInterceptorsCalledInOrderDefinedByBeansXml(Foo foo) {

assertNotNull(foo);
ActionSequence.reset();

foo.bar();

List<String> sequence = ActionSequence.getSequenceData();
assertEquals(sequence.size(), 2);
assertEquals(sequence.get(0), SecondInterceptor.class.getName());
assertEquals(sequence.get(1), FirstInterceptor.class.getName());
}

@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER)
@SpecAssertion(section = ENABLED_INTERCEPTORS, id = "g")
public void testInterceptorsInvocationOrder(AccountTransaction transaction) {

assertNotNull(transaction);
ActionSequence.reset();

transaction.execute();

List<String> sequence = ActionSequence.getSequenceData();
assertEquals(sequence.size(), 4, sequence.toString());
assertEquals(sequence.get(0), AnotherInterceptor.class.getName());
assertEquals(sequence.get(1), TransactionalInterceptor.class.getName());
assertEquals(sequence.get(2), Transaction.class.getName());
assertEquals(sequence.get(3), AccountTransaction.class.getName());
}
}
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.cdi.tck.tests.full.interceptors.definition.interceptorOrder;

import jakarta.annotation.Priority;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.Interceptor;
import jakarta.interceptor.InvocationContext;
import org.jboss.cdi.tck.util.ActionSequence;

@Interceptor
@Secure
@Priority(Interceptor.Priority.APPLICATION)
public class SecondInterceptor {
public static boolean calledFirst = false;

@AroundInvoke
public Object alwaysReturnThis(InvocationContext ctx) throws Exception {
ActionSequence.addAction(SecondInterceptor.class.getName());
return ctx.proceed();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.cdi.tck.tests.full.interceptors.definition.interceptorOrder;

import jakarta.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;

@Target({ TYPE, METHOD })
@Retention(RUNTIME)
@Documented
@InterceptorBinding
public @interface Secure {

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
* limitations under the License.
*/

package org.jboss.cdi.tck.tests.interceptors.definition.interceptorOrder;
package org.jboss.cdi.tck.tests.full.interceptors.definition.interceptorOrder;

import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.InvocationContext;

import org.jboss.cdi.tck.util.ActionSequence;

public class Transaction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.cdi.tck.tests.interceptors.definition.interceptorOrder;
package org.jboss.cdi.tck.tests.full.interceptors.definition.interceptorOrder;

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.cdi.tck.tests.interceptors.definition.interceptorOrder;
package org.jboss.cdi.tck.tests.full.interceptors.definition.interceptorOrder;

import jakarta.annotation.Priority;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.Interceptor;
import jakarta.interceptor.InvocationContext;

import org.jboss.cdi.tck.util.ActionSequence;

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ public static WebArchive createTestArchive() {
}

@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER)
@SpecAssertions({ @SpecAssertion(section = ENABLED_INTERCEPTORS, id = "b"), @SpecAssertion(section = ENABLED_INTERCEPTORS, id = "c") })
public void testInterceptorsCalledInOrderDefinedByBeansXml(Foo foo) {

@SpecAssertion(section = ENABLED_INTERCEPTORS, id = "l")
public void testInterceptorsInvocationOrder(Foo foo) {
assertNotNull(foo);
ActionSequence.reset();

Expand All @@ -58,20 +57,4 @@ public void testInterceptorsCalledInOrderDefinedByBeansXml(Foo foo) {
assertEquals(sequence.get(1), FirstInterceptor.class.getName());
}

@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER)
@SpecAssertion(section = ENABLED_INTERCEPTORS, id = "g")
public void testInterceptorsInvocationOrder(AccountTransaction transaction) {

assertNotNull(transaction);
ActionSequence.reset();

transaction.execute();

List<String> sequence = ActionSequence.getSequenceData();
assertEquals(sequence.size(), 4, sequence.toString());
assertEquals(sequence.get(0), AnotherInterceptor.class.getName());
assertEquals(sequence.get(1), TransactionalInterceptor.class.getName());
assertEquals(sequence.get(2), Transaction.class.getName());
assertEquals(sequence.get(3), AccountTransaction.class.getName());
}
}
7 changes: 7 additions & 0 deletions impl/src/main/resources/tck-audit-cdi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5157,6 +5157,13 @@
</text>
</assertion>

<assertion id="l">
<text>The Priority annotation can be used to enable and order interceptors associated with components that use interceptor bindings.
The required value element of the Priority annotation determines the ordering.
Interceptors with smaller priority values are called first.</text>
<note>This is defined in the Interceptors 2.0 spec, 5.2.1. Use of the Priority Annotation in Ordering Interceptors.</note>
</assertion>

</section>

<section id="interceptor_resolution" title="Interceptor resolution" level="2">
Expand Down

0 comments on commit fe2dcf7

Please sign in to comment.