|
| 1 | +/* |
| 2 | + * Copyright 2024, Red Hat, Inc., and individual contributors |
| 3 | + * by the @authors tag. See the copyright.txt in the distribution for a |
| 4 | + * full listing of individual contributors. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.jboss.cdi.tck.tests.invokers; |
| 17 | + |
| 18 | +import jakarta.enterprise.context.ApplicationScoped; |
| 19 | +import jakarta.enterprise.inject.build.compatible.spi.BeanInfo; |
| 20 | +import jakarta.enterprise.inject.build.compatible.spi.BuildCompatibleExtension; |
| 21 | +import jakarta.enterprise.inject.build.compatible.spi.InvokerFactory; |
| 22 | +import jakarta.enterprise.inject.build.compatible.spi.Registration; |
| 23 | +import jakarta.enterprise.inject.build.compatible.spi.Synthesis; |
| 24 | +import jakarta.enterprise.inject.build.compatible.spi.SyntheticComponents; |
| 25 | +import jakarta.enterprise.invoke.Invoker; |
| 26 | +import org.jboss.arquillian.container.test.api.Deployment; |
| 27 | +import org.jboss.cdi.tck.AbstractTest; |
| 28 | +import org.jboss.cdi.tck.cdi.Sections; |
| 29 | +import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder; |
| 30 | +import org.jboss.shrinkwrap.api.spec.WebArchive; |
| 31 | +import org.jboss.test.audit.annotations.SpecAssertion; |
| 32 | +import org.jboss.test.audit.annotations.SpecVersion; |
| 33 | +import org.testng.annotations.Test; |
| 34 | + |
| 35 | +import java.util.List; |
| 36 | +import java.util.Set; |
| 37 | + |
| 38 | +import static org.testng.Assert.assertEquals; |
| 39 | + |
| 40 | +@SpecVersion(spec = "cdi", version = "4.1") |
| 41 | +public class SimpleInvokerTest extends AbstractTest { |
| 42 | + @Deployment |
| 43 | + public static WebArchive createTestArchive() { |
| 44 | + return new WebArchiveBuilder() |
| 45 | + .withTestClass(SimpleInvokerTest.class) |
| 46 | + .withClasses(MyService.class) |
| 47 | + .withBuildCompatibleExtension(TestExtension.class) |
| 48 | + .withClasses(InvokerHolder.class, InvokerHolderCreator.class, InvokerHolderExtensionBase.class) |
| 49 | + .build(); |
| 50 | + } |
| 51 | + |
| 52 | + public static class TestExtension extends InvokerHolderExtensionBase implements BuildCompatibleExtension { |
| 53 | + @Registration(types = MyService.class) |
| 54 | + public void myServiceRegistration(BeanInfo bean, InvokerFactory invokers) { |
| 55 | + registerInvokers(bean, invokers, Set.of("hello")); |
| 56 | + } |
| 57 | + |
| 58 | + @Synthesis |
| 59 | + public void synthesis(SyntheticComponents syn) { |
| 60 | + synthesizeInvokerHolder(syn); |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + @Test(dataProvider = ARQUILLIAN_DATA_PROVIDER) |
| 65 | + @SpecAssertion(section = Sections.METHOD_INVOKERS, id = "a") |
| 66 | + @SpecAssertion(section = Sections.BUILDING_INVOKER, id = "a") |
| 67 | + @SpecAssertion(section = Sections.BUILDING_INVOKER, id = "e") |
| 68 | + @SpecAssertion(section = Sections.USING_INVOKER_BUILDER, id = "a") |
| 69 | + public void test(MyService service, InvokerHolder invokers) throws Exception { |
| 70 | + Invoker<MyService, String> hello = invokers.get("hello"); |
| 71 | + assertEquals(hello.invoke(service, new Object[]{1, List.of()}), "foobar1[]"); |
| 72 | + } |
| 73 | + |
| 74 | + @ApplicationScoped |
| 75 | + public static class MyService { |
| 76 | + public String hello(int param1, List<String> param2) { |
| 77 | + return "foobar" + param1 + param2; |
| 78 | + } |
| 79 | + } |
| 80 | +} |
0 commit comments