repo
stringlengths
1
191
file
stringlengths
23
351
code
stringlengths
0
5.32M
file_length
int64
0
5.32M
avg_line_length
float64
0
2.9k
max_line_length
int64
0
288k
extension_type
stringclasses
1 value
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/interceptor/ordering/CdiInterceptor.java
/* * JBoss, Home of Professional Open Source * Copyright 2012, 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.as.test.integration.weld.ejb.interceptor.ordering; import java.io.Serializable; import java.util.List; import jakarta.interceptor.AroundInvoke; import jakarta.interceptor.Interceptor; import jakarta.interceptor.InvocationContext; @Interceptor @CdiIntercepted public class CdiInterceptor implements Serializable { private static final long serialVersionUID = -5949866804898740300L; @AroundInvoke Object aroundInvoke(InvocationContext ctx) throws Exception { Object[] parameters = ctx.getParameters(); @SuppressWarnings("unchecked") List<String> sequence = (List<String>) parameters[0]; sequence.add("CdiInterceptor"); return ctx.proceed(); } }
1,498
35.560976
75
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/interceptor/ordering/LegacyInterceptor.java
/* * JBoss, Home of Professional Open Source * Copyright 2012, 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.as.test.integration.weld.ejb.interceptor.ordering; import java.io.Serializable; import java.util.List; import jakarta.interceptor.AroundInvoke; import jakarta.interceptor.InvocationContext; public class LegacyInterceptor implements Serializable { private static final long serialVersionUID = -3142706070329564629L; @AroundInvoke Object aroundInvoke(InvocationContext ctx) throws Exception { Object[] parameters = ctx.getParameters(); @SuppressWarnings("unchecked") List<String> sequence = (List<String>) parameters[0]; sequence.add("LegacyInterceptor"); return ctx.proceed(); } }
1,435
36.789474
75
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/interceptor/ordering/InterceptedBean.java
/* * JBoss, Home of Professional Open Source * Copyright 2012, 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.as.test.integration.weld.ejb.interceptor.ordering; import java.io.Serializable; import java.util.List; import jakarta.ejb.Stateful; import jakarta.enterprise.context.ApplicationScoped; import jakarta.interceptor.AroundInvoke; import jakarta.interceptor.Interceptors; import jakarta.interceptor.InvocationContext; @Stateful @ApplicationScoped @CdiIntercepted @Interceptors(LegacyInterceptor.class) public class InterceptedBean implements Serializable { private static final long serialVersionUID = -4444919869290540443L; public void ping(List<String> list) { list.add("InterceptedBean"); } @AroundInvoke Object aroundInvoke(InvocationContext ctx) throws Exception { Object[] parameters = ctx.getParameters(); @SuppressWarnings("unchecked") List<String> sequence = (List<String>) parameters[0]; sequence.add("TargetClassInterceptor"); return ctx.proceed(); } }
1,731
34.346939
75
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/interceptor/ordering/lifecycle/SessionBeanLifecycleInterceptorOrderingTest.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.interceptor.ordering.lifecycle; import static org.junit.Assert.assertEquals; import java.util.ArrayList; import java.util.List; import jakarta.enterprise.context.spi.CreationalContext; import jakarta.enterprise.inject.spi.Bean; import jakarta.enterprise.inject.spi.BeanManager; import jakarta.inject.Inject; import jakarta.interceptor.Interceptors; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; /** * Tests that session bean lifecycle interceptors are executed in the following order: * * 1) Interceptors bound using the {@link Interceptors} annotation * 2) Interceptors bound using CDI interceptor bindings * 3) Interceptors defined on a superclass of the bean defining class * 4) Interceptors defined on the bean defining class * *@see https://issues.jboss.org/browse/AS7-6739 * * @author Jozef Hartinger * */ @RunWith(Arquillian.class) public class SessionBeanLifecycleInterceptorOrderingTest { @Inject private BeanManager manager; @Deployment public static Archive<?> getDeployment() { return ShrinkWrap .create(WebArchive.class) .addPackage(SessionBeanLifecycleInterceptorOrderingTest.class.getPackage()) .addAsWebInfResource( new StringAsset("<beans><interceptors><class>" + CdiInterceptor.class.getName() + "</class></interceptors></beans>"), "beans.xml"); } @Test public void testSessionBeanLifecycleInterceptorOrdering() { @SuppressWarnings("unchecked") Bean<InterceptedBean> bean = (Bean<InterceptedBean>) manager.resolve(manager.getBeans(InterceptedBean.class)); CreationalContext<InterceptedBean> ctx = manager.createCreationalContext(bean); List<String> expected = new ArrayList<String>(); expected.add(LegacyInterceptor.class.getSimpleName()); expected.add(CdiInterceptor.class.getSimpleName()); expected.add(Superclass.class.getSimpleName()); expected.add(InterceptedBean.class.getSimpleName()); ActionSequence.reset(); // create a new instance InterceptedBean instance = bean.create(ctx); assertEquals(expected, ActionSequence.getActions()); ActionSequence.reset(); bean.destroy(instance, ctx); assertEquals(expected, ActionSequence.getActions()); } }
3,725
38.221053
118
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/interceptor/ordering/lifecycle/ActionSequence.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.interceptor.ordering.lifecycle; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class ActionSequence { private static final List<String> actions = Collections.synchronizedList(new ArrayList<String>()); public static void addAction(String action) { actions.add(action); } public static List<String> getActions() { return Collections.unmodifiableList(actions); } public static void reset() { actions.clear(); } }
1,583
35
102
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/interceptor/ordering/lifecycle/Superclass.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.interceptor.ordering.lifecycle; import jakarta.annotation.PostConstruct; import jakarta.annotation.PreDestroy; public class Superclass { @PostConstruct void postConstructSuperclass() { ActionSequence.addAction(Superclass.class.getSimpleName()); } @PreDestroy void preDestroySuperclass() { ActionSequence.addAction(Superclass.class.getSimpleName()); } }
1,471
36.74359
78
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/interceptor/ordering/lifecycle/CdiIntercepted.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.interceptor.ordering.lifecycle; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.Target; import jakarta.interceptor.InterceptorBinding; @InterceptorBinding @Inherited @Target({ TYPE }) @Retention(RUNTIME) public @interface CdiIntercepted { }
1,491
36.3
78
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/interceptor/ordering/lifecycle/CdiInterceptor.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.interceptor.ordering.lifecycle; import java.io.Serializable; import jakarta.annotation.PostConstruct; import jakarta.annotation.PreDestroy; import jakarta.interceptor.Interceptor; import jakarta.interceptor.InvocationContext; @Interceptor @CdiIntercepted public class CdiInterceptor implements Serializable { private static final long serialVersionUID = -5949866804898740300L; @PostConstruct void postConstruct(InvocationContext ctx) { try { ActionSequence.addAction(CdiInterceptor.class.getSimpleName()); ctx.proceed(); } catch (Exception e) { throw new RuntimeException(e); } } @PreDestroy void preDestroy(InvocationContext ctx) { try { ActionSequence.addAction(CdiInterceptor.class.getSimpleName()); ctx.proceed(); } catch (Exception e) { throw new RuntimeException(e); } } }
2,007
34.22807
78
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/interceptor/ordering/lifecycle/LegacyInterceptor.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.interceptor.ordering.lifecycle; import java.io.Serializable; import jakarta.annotation.PostConstruct; import jakarta.annotation.PreDestroy; import jakarta.interceptor.InvocationContext; public class LegacyInterceptor implements Serializable { private static final long serialVersionUID = -3142706070329564629L; @PostConstruct void postConstruct(InvocationContext ctx) { try { ActionSequence.addAction(LegacyInterceptor.class.getSimpleName()); ctx.proceed(); } catch (Exception e) { throw new RuntimeException(e); } } @PreDestroy void preDestroy(InvocationContext ctx) { try { ActionSequence.addAction(LegacyInterceptor.class.getSimpleName()); ctx.proceed(); } catch (Exception e) { throw new RuntimeException(e); } } }
1,947
35.074074
78
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/interceptor/ordering/lifecycle/InterceptedBean.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.interceptor.ordering.lifecycle; import jakarta.annotation.PostConstruct; import jakarta.annotation.PreDestroy; import jakarta.ejb.Stateful; import jakarta.interceptor.Interceptors; @Stateful @Interceptors(LegacyInterceptor.class) @CdiIntercepted public class InterceptedBean extends Superclass { @PostConstruct void postConstruct() { ActionSequence.addAction(InterceptedBean.class.getSimpleName()); } @PreDestroy void preDestroy() { ActionSequence.addAction(InterceptedBean.class.getSimpleName()); } }
1,620
35.840909
78
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/interceptor/exceptions/CDIEJBInterceptorExceptionTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.interceptor.exceptions; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import jakarta.inject.Inject; /** * AS7-194 * <p/> * Tests that application exceptions are handled correctly in the presence of CDI interceptors * * @author Stuart Douglas */ @RunWith(Arquillian.class) public class CDIEJBInterceptorExceptionTestCase { @Deployment public static Archive<?> deploy() { JavaArchive jar = ShrinkWrap.create(JavaArchive.class); jar.addPackage(CDIEJBInterceptorExceptionTestCase.class.getPackage()); jar.addAsManifestResource(new StringAsset("<beans><interceptors><class>"+ExceptionInterceptor.class.getName() + "</class></interceptors></beans>"), "beans.xml"); return jar; } @Inject private ExceptionBean bean; @Test public void testUncheckedException() { try { bean.unchecked(); Assert.fail("expected exception"); } catch (UncheckedException expected) { } } @Test public void testCheckedException() { try { bean.checked(); Assert.fail("expected exception"); } catch (SimpleApplicationException expected) { } } }
2,588
32.623377
170
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/interceptor/exceptions/ExceptionBean.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.interceptor.exceptions; import jakarta.ejb.Stateless; /** * @author Stuart Douglas */ @Stateless @ExceptionBinding public class ExceptionBean { public void checked() throws SimpleApplicationException { throw new SimpleApplicationException(); } public void unchecked() { throw new UncheckedException(); } }
1,407
33.341463
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/interceptor/exceptions/UncheckedException.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.interceptor.exceptions; import jakarta.ejb.ApplicationException; /** * @author Stuart Douglas */ @ApplicationException public class UncheckedException extends RuntimeException { }
1,247
38
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/interceptor/exceptions/ExceptionBinding.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.interceptor.exceptions; import jakarta.interceptor.InterceptorBinding; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * @author Stuart Douglas */ @InterceptorBinding @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE}) public @interface ExceptionBinding { }
1,455
36.333333
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/interceptor/exceptions/ExceptionInterceptor.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.interceptor.exceptions; import jakarta.interceptor.AroundInvoke; import jakarta.interceptor.Interceptor; import jakarta.interceptor.InvocationContext; @Interceptor @ExceptionBinding public class ExceptionInterceptor { @AroundInvoke public Object invoke(InvocationContext ctx) throws Exception { return ctx.proceed(); } }
1,408
36.078947
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/interceptor/exceptions/SimpleApplicationException.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.interceptor.exceptions; import jakarta.ejb.ApplicationException; /** * @author Stuart Douglas */ @ApplicationException public class SimpleApplicationException extends Exception { }
1,248
38.03125
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/interceptor/packaging/CdiInterceptorBinding.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.interceptor.packaging; import jakarta.interceptor.InterceptorBinding; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; /** * @author Stuart Douglas */ @InterceptorBinding @Retention(RetentionPolicy.RUNTIME) public @interface CdiInterceptorBinding { }
1,353
37.685714
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/interceptor/packaging/NonCdiEjb.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.interceptor.packaging; import jakarta.ejb.Stateless; /** * This is not deployed in an archive with a beans.xml file * * @author Stuart Douglas */ @Stateless @CdiInterceptorBinding public class NonCdiEjb { public String sayHello() { return "Hello"; } }
1,339
32.5
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/interceptor/packaging/CdiInterceptorEarPackagingTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.interceptor.packaging; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.test.integration.ejb.packaging.war.namingcontext.EjbInterface; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import javax.naming.InitialContext; import javax.naming.NamingException; /** * AS7-1032 * * Tests the {@link org.jboss.as.weld.ejb.Jsr299BindingsInterceptor} is only applied to appropriate EJB's * * @author Stuart Douglas */ @RunWith(Arquillian.class) public class CdiInterceptorEarPackagingTestCase { @Deployment public static Archive<?> deploy() { EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "CdiInterceptorPackaging.ear"); JavaArchive lib = ShrinkWrap.create(JavaArchive.class, "lib.jar"); lib.addClass(EjbInterface.class); ear.addAsLibrary(lib); JavaArchive jar1 = ShrinkWrap.create(JavaArchive.class, "cdiJar.jar"); jar1.addClasses(CdiInterceptorEarPackagingTestCase.class, CdiInterceptorBinding.class, CdiInterceptor.class, CdiEjb.class); jar1.add(new StringAsset("<beans><interceptors><class>"+ CdiInterceptor.class.getName() + "</class></interceptors></beans>"), "META-INF/beans.xml"); ear.addAsModule(jar1); JavaArchive jar2 = ShrinkWrap.create(JavaArchive.class, "nonCdiJar.jar"); jar2.addClasses(NonCdiEjb.class); ear.addAsModule(jar2); return ear; } @Test public void testCdiInterceptorApplied() throws NamingException { CdiEjb cdiEjb = (CdiEjb) new InitialContext().lookup("java:app/cdiJar/CdiEjb"); Assert.assertEquals("Hello World", cdiEjb.sayHello()); } @Test public void testCdiInterceptorNotApplied() throws NamingException { NonCdiEjb cdiEjb = (NonCdiEjb) new InitialContext().lookup("java:app/nonCdiJar/NonCdiEjb"); Assert.assertEquals("Hello", cdiEjb.sayHello()); } }
3,289
40.125
156
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/interceptor/packaging/CdiInterceptor.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.interceptor.packaging; import jakarta.interceptor.AroundInvoke; import jakarta.interceptor.Interceptor; import jakarta.interceptor.InvocationContext; /** * @author Stuart Douglas */ @CdiInterceptorBinding @Interceptor public class CdiInterceptor { @AroundInvoke public Object invoke(final InvocationContext context ) throws Exception { return context.proceed().toString() + " World"; } }
1,478
35.073171
77
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/interceptor/packaging/CdiEjb.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.interceptor.packaging; import jakarta.ejb.Stateless; /** * @author Stuart Douglas */ @Stateless @CdiInterceptorBinding public class CdiEjb { public String sayHello() { return "Hello"; } }
1,273
32.526316
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/multipleviews/MusicPlayer.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.multipleviews; /** * @author Stuart Douglas */ public interface MusicPlayer { void setSongCount(int songCount); }
1,186
36.09375
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/multipleviews/NormalScopedEjbWithMultipleViewsTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.multipleviews; import jakarta.inject.Inject; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * * Tests that Session beans can be instantiated using the bean constructor, rather than * the default constructor * * @author Stuart Douglas */ @RunWith(Arquillian.class) public class NormalScopedEjbWithMultipleViewsTestCase { @Deployment public static Archive<?> deploy() { JavaArchive jar = ShrinkWrap.create(JavaArchive.class); jar.addPackage(NormalScopedEjbWithMultipleViewsTestCase.class.getPackage()); jar.addAsManifestResource(new StringAsset(""), "beans.xml"); return jar; } @Inject private MusicPlayer musicPlayer; @Inject private EntertainmentDevice entertainmentDevice; @Test public void testBothViewsReferToSameBeanInstance() { musicPlayer.setSongCount(10); Assert.assertEquals(10, entertainmentDevice.getSongCount()); } }
2,321
34.181818
87
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/multipleviews/EntertainmentDevice.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.multipleviews; /** * @author Stuart Douglas */ public interface EntertainmentDevice { int getSongCount(); }
1,179
37.064516
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/multipleviews/Mp3Player.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.multipleviews; import jakarta.ejb.Local; import jakarta.ejb.Stateful; import jakarta.enterprise.context.ApplicationScoped; /** * @author Stuart Douglas */ @Stateful @ApplicationScoped @Local({MusicPlayer.class, EntertainmentDevice.class}) public class Mp3Player implements MusicPlayer, EntertainmentDevice { private int songCount; public int getSongCount() { return songCount; } public void setSongCount(final int songCount) { this.songCount = songCount; } }
1,565
33.043478
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/constructor/NoDefaultCtorView.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.constructor; import jakarta.ejb.Local; /** * @author Stuart Douglas */ @Local public interface NoDefaultCtorView { Dog getDog(); }
1,221
32.944444
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/constructor/NoDefaultCtorBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.constructor; import jakarta.ejb.Stateless; import jakarta.inject.Inject; /** * @author Stuart Douglas */ @Stateless public class NoDefaultCtorBean implements NoDefaultCtorView { private final Dog dog; @Inject private NoDefaultCtorBean(Dog dog) { this.dog = dog; } @Override public Dog getDog() { return dog; } }
1,443
30.391304
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/constructor/Dog.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.constructor; import java.io.Serializable; /** * @author Stuart Douglas */ public class Dog implements Serializable { }
1,186
37.290323
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/constructor/Kennel.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.constructor; import jakarta.ejb.Stateful; import jakarta.inject.Inject; /** * @author Stuart Douglas */ @Stateful public class Kennel { private final Dog dog; public Kennel() { dog = null; } @Inject public Kennel(Dog dog) { this.dog = dog; } public Dog getDog() { return dog; } }
1,407
28.333333
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/constructor/EjbConstructorInjectionTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.constructor; import jakarta.inject.Inject; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * * Tests that Session beans can be instantiated using the bean constructor, rather than * the default constructor * * @author Stuart Douglas */ @RunWith(Arquillian.class) public class EjbConstructorInjectionTestCase { @Deployment public static Archive<?> deploy() { JavaArchive jar = ShrinkWrap.create(JavaArchive.class); jar.addPackage(EjbConstructorInjectionTestCase.class.getPackage()); jar.addAsManifestResource(new StringAsset("<beans bean-discovery-mode=\"all\"></beans>"), "beans.xml"); return jar; } @Inject private Kennel bean; @Inject private NoDefaultCtorView noDefaultCtorView; @Test public void testSessionBeanConstructorInjection() { Assert.assertNotNull(bean.getDog()); } @Test public void testSessionBeanConstructorInjectionWithDoDefaultCtor() { Assert.assertNotNull(noDefaultCtorView.getDog()); } }
2,413
33.485714
111
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/requestscope/RemoteEjb.java
package org.jboss.as.test.integration.weld.ejb.requestscope; import jakarta.ejb.Stateless; import jakarta.inject.Inject; /** * @author Stuart Douglas */ @Stateless public class RemoteEjb implements RemoteInterface { @Inject private RequestScopedBean bean; @Override public String getMessage() { return bean.getMessage(); } }
359
17
60
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/requestscope/RequestServlet.java
package org.jboss.as.test.integration.weld.ejb.requestscope; import java.io.IOException; import jakarta.ejb.EJB; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; /** * @author Stuart Douglas */ @WebServlet(urlPatterns = "/*") public class RequestServlet extends HttpServlet{ @EJB(lookup = "ejb:/ejb/RemoteEjb!org.jboss.as.test.integration.weld.ejb.requestscope.RemoteInterface") private RemoteInterface remoteInterface; @Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { resp.getWriter().write(remoteInterface.getMessage()); resp.getWriter().close(); } }
855
30.703704
125
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/requestscope/RemoteInterface.java
package org.jboss.as.test.integration.weld.ejb.requestscope; import jakarta.ejb.Remote; /** * @author Stuart Douglas */ @Remote public interface RemoteInterface { String getMessage(); }
196
13.071429
60
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/requestscope/RequestScopedBean.java
package org.jboss.as.test.integration.weld.ejb.requestscope; import jakarta.enterprise.context.RequestScoped; /** * @author Stuart Douglas */ @RequestScoped public class RequestScopedBean { public static final String MESSAGE = "Request Scoped"; public String getMessage() { return MESSAGE; } }
320
17.882353
60
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/requestscope/RequestScopeActivationTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.requestscope; import java.io.IOException; import java.net.URL; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.OperateOnDeployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.test.integration.common.HttpRequest; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; import static org.junit.Assert.assertEquals; /** * AS7-4119 * <p/> * Tests that request scope is active in in-vm remote interface requests * * @author Stuart Douglas */ @RunWith(Arquillian.class) @RunAsClient public class RequestScopeActivationTestCase { @ArquillianResource @OperateOnDeployment("web") private URL web; @ArquillianResource @OperateOnDeployment("web2") private URL web2; @Deployment(name = "ejb") public static Archive<?> ejb() { JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "ejb.jar"); jar.addClasses(RemoteEjb.class, RemoteInterface.class, RequestScopedBean.class); jar.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); return jar; } @Deployment(name = "web") public static Archive<?> web() { WebArchive war = ShrinkWrap.create(WebArchive.class, "web.war"); war.addClasses(RequestServlet.class, RemoteInterface.class); return war; } @Deployment(name = "web2") public static Archive<?> web2() { WebArchive war = ShrinkWrap.create(WebArchive.class, "web2.war"); war.addClasses(RequestServlet.class, RemoteInterface.class); war.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); return war; } @Test public void testRequestContextActiveNoCDI() throws IOException, ExecutionException, TimeoutException { String response = HttpRequest.get(web.toExternalForm(), 10, TimeUnit.SECONDS); assertEquals(RequestScopedBean.MESSAGE, response); } @Test public void testRequestContextActiveCDI() throws IOException, ExecutionException, TimeoutException { String response = HttpRequest.get(web2.toExternalForm(), 10, TimeUnit.SECONDS); assertEquals(RequestScopedBean.MESSAGE, response); } }
3,727
36.656566
106
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/injection/BusStation.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.injection; import jakarta.ejb.EJB; /** * @author Stuart Douglas */ public class BusStation { @EJB private Bus bus; @EJB(lookup = "java:module/Bus") private Bus lookupBus; @EJB(lookup = "java:comp/Bus") private Bus lookupBus2; public Bus getBus() { return bus; } public Bus getLookupBus() { return lookupBus; } public Bus getLookupBus2() { return lookupBus2; } }
1,508
27.471698
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/injection/EjbInjectionIntoCdiBeanTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.injection; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import jakarta.annotation.Resource; import jakarta.inject.Inject; import jakarta.transaction.UserTransaction; /** * AS7-1269 * * Tests the @EJB injection into CDI beans works correctly * * @author Stuart Douglas */ @RunWith(Arquillian.class) public class EjbInjectionIntoCdiBeanTestCase { @Deployment public static Archive<?> deploy() { WebArchive war = ShrinkWrap.create(WebArchive.class); war.addPackage(EjbInjectionIntoCdiBeanTestCase.class.getPackage()); war.addAsWebInfResource(new StringAsset("<beans bean-discovery-mode=\"all\"></beans>"), "beans.xml"); return war; } @Inject private BusStation bean; @Resource(lookup="java:jboss/UserTransaction") private UserTransaction userTransaction; @Test public void testEjbInjection() { Assert.assertNotNull(bean.getBus()); Assert.assertNotNull(bean.getLookupBus()); Assert.assertNotNull(bean.getLookupBus2()); } @Test public void testUserTransactionInjection() { Assert.assertNotNull(userTransaction); } }
2,530
33.202703
109
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/injection/Bus.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.injection; import jakarta.ejb.Stateless; import java.io.Serializable; /** * @author Stuart Douglas */ @Stateless public class Bus implements Serializable { }
1,225
36.151515
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/removemethod/House.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.removemethod; import jakarta.ejb.Remove; import jakarta.ejb.Stateful; import jakarta.enterprise.context.ApplicationScoped; /** * @author Stuart Douglas */ @Stateful @ApplicationScoped public class House { @Remove public void remove() { } }
1,322
31.268293
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/removemethod/Garage.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.removemethod; import jakarta.ejb.Remove; import jakarta.ejb.Stateful; /** * @author Stuart Douglas */ @Stateful public class Garage { public void park() { } @Remove public void remove() { } }
1,284
28.883721
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/removemethod/RemoveMethodExceptionTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.removemethod; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import jakarta.ejb.NoSuchEJBException; import jakarta.inject.Inject; /** * AS7-1463 * <p/> * Tests that @Remove method for CDI managed beans throw exceptions. * * @author Stuart Douglas */ @RunWith(Arquillian.class) public class RemoveMethodExceptionTestCase { @Deployment public static Archive<?> deploy() { JavaArchive jar = ShrinkWrap.create(JavaArchive.class); jar.addPackage(RemoveMethodExceptionTestCase.class.getPackage()); jar.addAsManifestResource(new StringAsset(""), "beans.xml"); return jar; } @Inject private House house; @Inject private Garage garage; @Test public void testRemoveMethodOnNormalScopedBean() { try { house.remove(); throw new RuntimeException("Expected exception"); } catch (UnsupportedOperationException e) { } } @Test public void testRemoveMethodOnDependentScopedCdiBean() { try { garage.remove(); garage.park(); } catch (Exception e) { if (!(e instanceof NoSuchEJBException)){ Assert.fail("Expected NoSuchEJBException but got: " + e); } return; } Assert.fail("NoSuchEJBException should occur but didn't!"); } }
2,747
31.329412
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/packaging/warlib/WarLibEjb.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.packaging.warlib; import jakarta.ejb.Stateless; import jakarta.inject.Inject; /** * @author Stuart Douglas */ @Stateless public class WarLibEjb implements WarLibInterface { private final OtherEjb ejb; public WarLibEjb() { ejb = null; } @Inject public WarLibEjb(final OtherEjb ejb) { this.ejb = ejb; } public OtherEjb getEjb() { return ejb; } }
1,471
29.666667
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/packaging/warlib/EjbInWarLibPackagingTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.packaging.warlib; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import javax.naming.InitialContext; import javax.naming.NamingException; /** * AS7-1089 * * Tests the EJB's in WAR/lib are looked up using the correct bean manager * * @author Stuart Douglas */ @RunWith(Arquillian.class) public class EjbInWarLibPackagingTestCase { @Deployment public static Archive<?> deploy() { WebArchive war = ShrinkWrap.create(WebArchive.class, "CdiInterceptorPackaging.war"); JavaArchive lib = ShrinkWrap.create(JavaArchive.class, "lib.jar"); lib.addClasses(WarLibEjb.class, WarLibInterface.class); lib.add(EmptyAsset.INSTANCE, "META-INF/beans.xml"); war.addAsLibrary(lib); war.addClasses(EjbInWarLibPackagingTestCase.class, OtherEjb.class); war.add(EmptyAsset.INSTANCE, "WEB-INF/beans.xml"); return war; } @Test public void testEjbInWarLibResolvedCorrectly() throws NamingException { WarLibInterface cdiEjb = (WarLibInterface) new InitialContext().lookup("java:module/WarLibEjb"); Assert.assertEquals("Hello", cdiEjb.getEjb().sayHello()); } }
2,587
35.971429
104
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/packaging/warlib/WarLibInterface.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.packaging.warlib; import jakarta.ejb.Local; /** * @author Stuart Douglas */ @Local public interface WarLibInterface { OtherEjb getEjb(); }
1,213
33.685714
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/packaging/warlib/OtherEjb.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.ejb.packaging.warlib; import jakarta.ejb.Stateless; /** * @author Stuart Douglas */ @Stateless public class OtherEjb { public String sayHello() { return "Hello"; } }
1,246
33.638889
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/context/application/event/ApplicationContextInitializedEventTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2015, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.context.application.event; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.Testable; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; //import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * Testcase for WFLY-3334 * @author Jozef Hartinger * */ @RunWith(Arquillian.class) public class ApplicationContextInitializedEventTestCase { @Deployment public static Archive<?> getDeployment() { JavaArchive lib = ShrinkWrap.create(JavaArchive.class) .addAsManifestResource(new StringAsset("<beans bean-discovery-mode=\"all\"></beans>"), "beans.xml") .addClasses(Library.class, ApplicationContextInitializedEventTestCase.class); JavaArchive ejb = Testable.archiveToTest(ShrinkWrap.create(JavaArchive.class).addAsManifestResource(new StringAsset("<beans bean-discovery-mode=\"all\"></beans>"), "beans.xml").addClass(SessionBean.class)); return ShrinkWrap.create(EnterpriseArchive.class).addAsModule(ejb).addAsLibrary(lib); } @Test public void testEjbJar() { Assert.assertNotNull(SessionBean.EVENT); } @Test public void testLibrary() { Assert.assertNotNull(Library.EVENT); } }
2,619
39.9375
214
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/context/application/event/SessionBean.java
/* * JBoss, Home of Professional Open Source * Copyright 2015, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.context.application.event; import jakarta.ejb.Stateless; import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.Initialized; import jakarta.enterprise.event.Observes; @Stateless public class SessionBean { public static volatile Object EVENT; public static void init(@Observes @Initialized(ApplicationScoped.class) Object event) { if (EVENT != null) { throw new IllegalStateException("Event already received: " + EVENT); } EVENT = event; } public void ping() { } }
1,616
35.75
91
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/context/application/event/Library.java
/* * JBoss, Home of Professional Open Source * Copyright 2015, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.context.application.event; import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.Initialized; import jakarta.enterprise.event.Observes; public class Library { public static volatile Object EVENT; public static void init(@Observes @Initialized(ApplicationScoped.class) Object event) { if (EVENT != null) { throw new IllegalStateException("Event already received: " + EVENT); } EVENT = event; } }
1,539
38.487179
91
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/context/application/lifecycle/Servlet.java
/* * JBoss, Home of Professional Open Source. * Copyright (c) 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.context.application.lifecycle; import org.jboss.logging.Logger; import jakarta.annotation.Resource; import jakarta.ejb.EJB; import jakarta.enterprise.concurrent.ManagedExecutorService; import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.BeforeDestroyed; import jakarta.enterprise.context.Destroyed; import jakarta.enterprise.context.Initialized; import jakarta.enterprise.context.control.RequestContextController; import jakarta.enterprise.event.Observes; import jakarta.inject.Inject; import jakarta.jms.JMSContext; import jakarta.jms.Queue; import javax.naming.NamingException; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; /** * @author emmartins */ @WebServlet(name="Servlet", urlPatterns={"/FiveHundred"}) public class Servlet extends HttpServlet { private static final Logger LOGGER = Logger.getLogger(Servlet.class.getName()); @Resource private ManagedExecutorService executorService; @Inject private JMSContext jmsContext; @Resource(lookup = Mdb.JNDI_NAME) private Queue jmsQueue; @Inject private RequestContextController requestContextController; @EJB(lookup = "java:global/TEST_RESULTS/TestResultsBean!org.jboss.as.test.integration.weld.context.application.lifecycle.TestResults") private TestResults testResults; public void onInitialized(@Observes @Initialized(ApplicationScoped.class) Object event) { LOGGER.info("onInitialized!"); try { Utils.sendMessage(jmsContext, jmsQueue, requestContextController); Utils.lookupCommonResources(LOGGER, false); executorService.submit(() -> { try { Utils.sendMessage(jmsContext, jmsQueue, requestContextController); Utils.lookupCommonResources(LOGGER, false); testResults.setServletInitialized(true); } catch (NamingException e) { LOGGER.error("Failed to set initialized test result", e); testResults.setServletInitialized(false); } }).get(); } catch (Throwable e) { LOGGER.error("Failed to set initialized test result", e); testResults.setServletInitialized(false); } } public void onBeforeDestroyed(@Observes @BeforeDestroyed(ApplicationScoped.class) Object object) { LOGGER.info("onBeforeDestroyed!"); try { Utils.sendMessage(jmsContext, jmsQueue, requestContextController); Utils.lookupCommonResources(LOGGER, false); executorService.submit(() -> { try { Utils.sendMessage(jmsContext, jmsQueue, requestContextController); Utils.lookupCommonResources(LOGGER, false); testResults.setServletBeforeDestroyed(true); } catch (NamingException e) { LOGGER.error("Failed to set before destroyed test result", e); testResults.setServletBeforeDestroyed(false); } }).get(); } catch (Throwable e) { LOGGER.error("Failed to set before destroyed test result", e); testResults.setServletBeforeDestroyed(false); } } public void onDestroyed(@Observes @Destroyed(ApplicationScoped.class) Object object) { LOGGER.info("onDestroyed!"); try { executorService.submit(() -> testResults.setServletDestroyed(true)).get(); } catch (Throwable e) { LOGGER.error("Failed to set destroyed test result", e); testResults.setServletDestroyed(false); } } @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.sendError(500); } }
5,106
39.531746
138
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/context/application/lifecycle/Utils.java
/* * JBoss, Home of Professional Open Source * Copyright 2019, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.context.application.lifecycle; import org.jboss.logging.Logger; import jakarta.enterprise.context.control.RequestContextController; import jakarta.jms.JMSContext; import jakarta.jms.JMSProducer; import jakarta.jms.Queue; import javax.naming.InitialContext; import javax.naming.NamingException; /** * @author emmartins */ public interface Utils { static void sendMessage(JMSContext jmsContext, Queue jmsQueue, RequestContextController requestContextController) { requestContextController.activate(); final JMSProducer producer = jmsContext.createProducer(); producer.send(jmsQueue, "a message"); requestContextController.deactivate(); } static void lookupCommonResources(Logger logger, boolean statelessEjb) throws NamingException { final InitialContext initialContext = new InitialContext(); // lookup app name logger.info("java:app/AppName: "+initialContext.lookup("java:app/AppName")); // lookup module name logger.info("java:module/ModuleName: "+initialContext.lookup("java:module/ModuleName")); // lookup default EE concurrency resources logger.info("java:comp/DefaultContextService: "+initialContext.lookup("java:comp/DefaultContextService")); logger.info("java:comp/DefaultManagedExecutorService: "+initialContext.lookup("java:comp/DefaultManagedExecutorService")); logger.info("java:comp/DefaultManagedScheduledExecutorService: "+initialContext.lookup("java:comp/DefaultManagedScheduledExecutorService")); logger.info("java:comp/DefaultManagedThreadFactory: "+initialContext.lookup("java:comp/DefaultManagedThreadFactory")); // lookup default datasource logger.info("java:comp/DefaultDataSource: "+initialContext.lookup("java:comp/DefaultDataSource")); // lookup default Jakarta Messaging connection factory logger.info("java:comp/DefaultJMSConnectionFactory: "+initialContext.lookup("java:comp/DefaultJMSConnectionFactory")); // lookup tx resources logger.info("java:comp/TransactionSynchronizationRegistry: "+initialContext.lookup("java:comp/TransactionSynchronizationRegistry")); if (!statelessEjb) { logger.info("java:comp/UserTransaction: "+initialContext.lookup("java:comp/UserTransaction")); } else { logger.info("java:comp/EJBContext: "+initialContext.lookup("java:comp/EJBContext")); } } }
3,497
48.971429
148
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/context/application/lifecycle/TestResults.java
/* * JBoss, Home of Professional Open Source * Copyright 2019, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.context.application.lifecycle; import jakarta.ejb.Remote; import java.util.concurrent.TimeUnit; /** * @author emmartins */ @Remote public interface TestResults { boolean isCdiBeanInitialized(); void setCdiBeanInitialized(boolean cdiBeanInitialized); boolean isEjbBeanInitialized(); void setEjbBeanInitialized(boolean ejbBeanInitialized); boolean isServletInitialized(); void setServletInitialized(boolean servletInitialized); boolean isCdiBeanBeforeDestroyed(); void setCdiBeanBeforeDestroyed(boolean cdiBeanBeforeDestroyed); boolean isEjbBeanBeforeDestroyed(); void setEjbBeanBeforeDestroyed(boolean ejbBeanBeforeDestroyed); boolean isServletBeforeDestroyed(); void setServletBeforeDestroyed(boolean servletBeforeDestroyed); boolean isCdiBeanDestroyed(); void setCdiBeanDestroyed(boolean cdiBeanDestroyed); boolean isEjbBeanDestroyed(); void setEjbBeanDestroyed(boolean ejbBeanDestroyed); boolean isServletDestroyed(); void setServletDestroyed(boolean servletDestroyed); void setup(int latchCount); void await(long timeout, TimeUnit timeUnit) throws InterruptedException; }
2,241
28.5
76
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/context/application/lifecycle/Ejb.java
/* * JBoss, Home of Professional Open Source * Copyright 2019, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.context.application.lifecycle; import org.jboss.logging.Logger; import jakarta.annotation.Resource; import jakarta.ejb.EJB; import jakarta.ejb.Stateless; import jakarta.enterprise.concurrent.ManagedExecutorService; import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.BeforeDestroyed; import jakarta.enterprise.context.Destroyed; import jakarta.enterprise.context.Initialized; import jakarta.enterprise.context.control.RequestContextController; import jakarta.enterprise.event.Observes; import jakarta.inject.Inject; import jakarta.jms.JMSContext; import jakarta.jms.Queue; import javax.naming.NamingException; /** * @author emmartins */ @Stateless public class Ejb { private static final Logger LOGGER = Logger.getLogger(Ejb.class.getName()); @Resource private ManagedExecutorService executorService; @Inject private JMSContext jmsContext; @Resource(lookup = Mdb.JNDI_NAME) private Queue jmsQueue; @Inject private RequestContextController requestContextController; @EJB(lookup = "java:global/TEST_RESULTS/TestResultsBean!org.jboss.as.test.integration.weld.context.application.lifecycle.TestResults") private TestResults testResults; public void onInitialized(@Observes @Initialized(ApplicationScoped.class) Object event) { LOGGER.info("onInitialized!"); try { Utils.sendMessage(jmsContext, jmsQueue, requestContextController); Utils.lookupCommonResources(LOGGER, true); executorService.submit(() -> { try { Utils.sendMessage(jmsContext, jmsQueue, requestContextController); Utils.lookupCommonResources(LOGGER, true); testResults.setEjbBeanInitialized(true); } catch (NamingException e) { LOGGER.error("Failed to set initialized test result", e); testResults.setEjbBeanInitialized(false); } }).get(); } catch (Throwable e) { LOGGER.error("Failed to set initialized test result", e); testResults.setEjbBeanInitialized(false); } } public void onBeforeDestroyed(@Observes @BeforeDestroyed(ApplicationScoped.class) Object object) { LOGGER.info("onBeforeDestroyed!"); try { Utils.sendMessage(jmsContext, jmsQueue, requestContextController); Utils.lookupCommonResources(LOGGER, false); executorService.submit(() -> { try { Utils.sendMessage(jmsContext, jmsQueue, requestContextController); Utils.lookupCommonResources(LOGGER, false); testResults.setEjbBeanBeforeDestroyed(true); } catch (NamingException e) { LOGGER.error("Failed to set before destroyed test result", e); testResults.setEjbBeanBeforeDestroyed(false); } }).get(); } catch (Throwable e) { LOGGER.error("Failed to set before destroyed test result", e); testResults.setEjbBeanBeforeDestroyed(false); } } public void onDestroyed(@Observes @Destroyed(ApplicationScoped.class) Object object) { LOGGER.info("onDestroyed!"); try { Utils.sendMessage(jmsContext, jmsQueue, requestContextController); Utils.lookupCommonResources(LOGGER, false); executorService.submit(() -> { try { Utils.sendMessage(jmsContext, jmsQueue, requestContextController); Utils.lookupCommonResources(LOGGER, false); testResults.setEjbBeanDestroyed(true); } catch (NamingException e) { LOGGER.error("Failed to set destroyed test result", e); testResults.setEjbBeanDestroyed(false); } }).get(); } catch (Throwable e) { LOGGER.error("Failed to set destroyed test result", e); testResults.setEjbBeanDestroyed(false); } } }
5,177
39.453125
138
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/context/application/lifecycle/Bean.java
/* * JBoss, Home of Professional Open Source * Copyright 2019, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.context.application.lifecycle; import org.jboss.logging.Logger; import jakarta.annotation.Resource; import jakarta.ejb.EJB; import jakarta.enterprise.concurrent.ManagedExecutorService; import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.context.BeforeDestroyed; import jakarta.enterprise.context.Destroyed; import jakarta.enterprise.context.Initialized; import jakarta.enterprise.context.control.RequestContextController; import jakarta.enterprise.event.Observes; import jakarta.inject.Inject; import jakarta.jms.JMSContext; import jakarta.jms.Queue; import javax.naming.NamingException; /** * @author emmartins */ @ApplicationScoped public class Bean { private static final Logger LOGGER = Logger.getLogger(Bean.class.getName()); @Resource private ManagedExecutorService executorService; @Inject private JMSContext jmsContext; @Resource(lookup = Mdb.JNDI_NAME) private Queue jmsQueue; @Inject private RequestContextController requestContextController; @EJB(lookup = "java:global/TEST_RESULTS/TestResultsBean!org.jboss.as.test.integration.weld.context.application.lifecycle.TestResults") private TestResults testResults; public void onInitialized(@Observes @Initialized(ApplicationScoped.class) Object object) { LOGGER.info("onInitialized!"); try { Utils.sendMessage(jmsContext, jmsQueue, requestContextController); Utils.lookupCommonResources(LOGGER, false); executorService.submit(() -> { try { Utils.sendMessage(jmsContext, jmsQueue, requestContextController); Utils.lookupCommonResources(LOGGER, false); testResults.setCdiBeanInitialized(true); } catch (NamingException e) { LOGGER.error("Failed to set initialized test result", e); testResults.setCdiBeanInitialized(false); } }).get(); } catch (Throwable e) { LOGGER.error("Failed to set initialized test result", e); testResults.setCdiBeanInitialized(false); } } public void onBeforeDestroyed(@Observes @BeforeDestroyed(ApplicationScoped.class) Object object) { LOGGER.info("onBeforeDestroyed!"); try { Utils.sendMessage(jmsContext, jmsQueue, requestContextController); Utils.lookupCommonResources(LOGGER, false); executorService.submit(() -> { try { Utils.sendMessage(jmsContext, jmsQueue, requestContextController); Utils.lookupCommonResources(LOGGER, false); testResults.setCdiBeanBeforeDestroyed(true); } catch (NamingException e) { LOGGER.error("Failed to set initialized test result", e); testResults.setCdiBeanBeforeDestroyed(false); } }).get(); } catch (Throwable e) { LOGGER.error("Failed to set initialized test result", e); testResults.setCdiBeanBeforeDestroyed(false); } } public void onDestroyed(@Observes @Destroyed(ApplicationScoped.class) Object object) { LOGGER.info("onDestroyed!"); try { Utils.sendMessage(jmsContext, jmsQueue, requestContextController); Utils.lookupCommonResources(LOGGER, false); executorService.submit(() -> { try { Utils.sendMessage(jmsContext, jmsQueue, requestContextController); Utils.lookupCommonResources(LOGGER, false); testResults.setCdiBeanDestroyed(true); } catch (NamingException e) { LOGGER.error("Failed to set initialized test result", e); testResults.setCdiBeanDestroyed(false); } }).get(); } catch (Throwable e) { LOGGER.error("Failed to set initialized test result", e); testResults.setCdiBeanDestroyed(false); } } }
5,154
39.590551
138
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/context/application/lifecycle/TestResultsBean.java
/* * JBoss, Home of Professional Open Source * Copyright 2019, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.context.application.lifecycle; import org.jboss.as.test.shared.TimeoutUtil; import jakarta.ejb.Singleton; import jakarta.ejb.Startup; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; /** * @author emmartins */ @Startup @Singleton public class TestResultsBean implements TestResults { private CountDownLatch latch; private boolean cdiBeanInitialized; private boolean cdiBeanBeforeDestroyed; private boolean cdiBeanDestroyed; private boolean ejbBeanInitialized; private boolean ejbBeanBeforeDestroyed; private boolean ejbBeanDestroyed; private boolean servletInitialized; private boolean servletBeforeDestroyed; private boolean servletDestroyed; public boolean isCdiBeanInitialized() { return cdiBeanInitialized; } public void setCdiBeanInitialized(boolean cdiBeanInitialized) { this.cdiBeanInitialized = cdiBeanInitialized; latch.countDown(); } public boolean isEjbBeanInitialized() { return ejbBeanInitialized; } public void setEjbBeanInitialized(boolean ejbBeanInitialized) { this.ejbBeanInitialized = ejbBeanInitialized; latch.countDown(); } public boolean isServletInitialized() { return servletInitialized; } public void setServletInitialized(boolean servletInitialized) { this.servletInitialized = servletInitialized; latch.countDown(); } // --- public boolean isCdiBeanBeforeDestroyed() { return cdiBeanBeforeDestroyed; } public void setCdiBeanBeforeDestroyed(boolean cdiBeanBeforeDestroyed) { this.cdiBeanBeforeDestroyed = cdiBeanBeforeDestroyed; latch.countDown(); } public boolean isEjbBeanBeforeDestroyed() { return ejbBeanBeforeDestroyed; } public void setEjbBeanBeforeDestroyed(boolean ejbBeanBeforeDestroyed) { this.ejbBeanBeforeDestroyed = ejbBeanBeforeDestroyed; latch.countDown(); } public boolean isServletBeforeDestroyed() { return servletBeforeDestroyed; } public void setServletBeforeDestroyed(boolean servletBeforeDestroyed) { this.servletBeforeDestroyed = servletBeforeDestroyed; latch.countDown(); } // --- public boolean isCdiBeanDestroyed() { return cdiBeanDestroyed; } public void setCdiBeanDestroyed(boolean cdiBeanDestroyed) { this.cdiBeanDestroyed = cdiBeanDestroyed; latch.countDown(); } public boolean isEjbBeanDestroyed() { return ejbBeanDestroyed; } public void setEjbBeanDestroyed(boolean ejbBeanDestroyed) { this.ejbBeanDestroyed = ejbBeanDestroyed; latch.countDown(); } public boolean isServletDestroyed() { return servletDestroyed; } public void setServletDestroyed(boolean servletDestroyed) { this.servletDestroyed = servletDestroyed; latch.countDown(); } // -- public void setup(int latchCount) { if (latch != null) { throw new IllegalStateException(); } latch = new CountDownLatch(latchCount); } public void await(long timeout, TimeUnit timeUnit) throws InterruptedException { if (latch == null) { throw new IllegalStateException(); } try { latch.await(TimeoutUtil.adjust(Long.valueOf(timeout).intValue()), timeUnit); } finally { latch = null; } } }
4,555
27.835443
88
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/context/application/lifecycle/ApplicationContextLifecycleTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2019, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.context.application.lifecycle; import org.jboss.arquillian.container.test.api.Deployer; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.as.test.shared.TimeoutUtil; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import javax.naming.InitialContext; import javax.naming.NamingException; import java.util.PropertyPermission; import java.util.concurrent.TimeUnit; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; /** * Tests possible deployment scenarios for CDI ApplicationScoped events, and usage of other EE technologies in such event handlers. * @author emmartins */ @RunWith(Arquillian.class) public class ApplicationContextLifecycleTestCase { private static final String TEST_BEANS_LIB_JAR = "TEST_BEANS_LIB_JAR"; private static final String TEST_BEANS_EJB_JAR = "TEST_BEANS_EJB_JAR"; private static final String TEST_BEANS_EAR = "TEST_BEANS_EAR"; private static final String TEST_BEANS_WAR = "TEST_BEANS_WAR"; private static final String TEST_RESULTS = "TEST_RESULTS"; @ArquillianResource public Deployer deployer; @Deployment(name = TEST_BEANS_EJB_JAR, managed = false) public static Archive<JavaArchive> deployJar() { final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, TEST_BEANS_EJB_JAR +".jar") .addClasses(Ejb.class, Bean.class, Mdb.class, TestResults.class, Utils.class, TimeoutUtil.class) .addAsManifestResource(createPermissionsXmlAsset( new PropertyPermission(TimeoutUtil.FACTOR_SYS_PROP, "read")), "permissions.xml"); return ejbJar; } @Deployment(name = TEST_BEANS_EAR, managed = false) public static Archive<EnterpriseArchive> deployEar() { final JavaArchive libJar = ShrinkWrap.create(JavaArchive.class, TEST_BEANS_LIB_JAR +".jar") .addClasses(TestResults.class, Utils.class); final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, TEST_BEANS_EJB_JAR +".jar") .addClasses(Ejb.class, Bean.class, Mdb.class); final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, TEST_BEANS_EAR +".ear") .addAsLibrary(libJar) .addAsModule(ejbJar); return ear; } @Deployment(name = TEST_BEANS_WAR, managed = false) public static Archive<WebArchive> deployWar() { final JavaArchive libJar = ShrinkWrap.create(JavaArchive.class, TEST_BEANS_LIB_JAR +".jar") .addClasses(TestResults.class, Utils.class); final WebArchive war = ShrinkWrap.create(WebArchive.class, TEST_BEANS_WAR +".war") .addAsLibrary(libJar) .addClasses(Servlet.class, Bean.class, Mdb.class); return war; } @Deployment public static Archive<?> deployTestResults() { final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, TEST_RESULTS +".jar"); jar.addClasses(TestResultsBean.class, TestResults.class, TimeoutUtil.class); jar.addAsManifestResource(createPermissionsXmlAsset( new PropertyPermission(TimeoutUtil.FACTOR_SYS_PROP, "read")), "permissions.xml"); return jar; } @ArquillianResource private InitialContext initialContext; @Test public void testJar() throws NamingException, InterruptedException { final TestResults testResults = (TestResults) initialContext.lookup("java:global/"+ TEST_RESULTS +"/"+ TestResultsBean.class.getSimpleName()+"!"+ TestResults.class.getName()); // setup initialized test testResults.setup(2); // deploy app deployer.deploy(TEST_BEANS_EJB_JAR); // await and assert initialized results testResults.await(TimeoutUtil.adjust(5), TimeUnit.SECONDS); Assert.assertTrue(testResults.isCdiBeanInitialized()); Assert.assertTrue(testResults.isEjbBeanInitialized()); // NOTE: before destroyed and destroyed atm only guaranteed for web deployments, uncomment all once that's solved // setup before destroyed and destroyed test //testResults.setup(4); // undeploy app deployer.undeploy(TEST_BEANS_EJB_JAR); // await and assert before destroyed and destroyed results //testResults.await(TimeoutUtil.adjust(5), TimeUnit.SECONDS); //Assert.assertTrue(testResults.isCdiBeanBeforeDestroyed()); //Assert.assertTrue(testResults.isCdiBeanDestroyed()); //Assert.assertTrue(testResults.isEjbBeanBeforeDestroyed()); //Assert.assertTrue(testResults.isEjbBeanDestroyed()); } @Test public void testEar() throws NamingException, InterruptedException { final TestResults testResults = (TestResults) initialContext.lookup("java:global/"+ TEST_RESULTS +"/"+ TestResultsBean.class.getSimpleName()+"!"+ TestResults.class.getName()); // setup initialized test testResults.setup(2); // deploy app deployer.deploy(TEST_BEANS_EAR); // await and assert initialized results testResults.await(TimeoutUtil.adjust(5), TimeUnit.SECONDS); Assert.assertTrue(testResults.isCdiBeanInitialized()); Assert.assertTrue(testResults.isEjbBeanInitialized()); // NOTE: before destroyed and destroyed atm only guaranteed for web deployments, uncomment all once that's solved // setup before destroyed and destroyed test //testResults.setup(4); // undeploy app deployer.undeploy(TEST_BEANS_EAR); // await and assert before destroyed and destroyed results //testResults.await(TimeoutUtil.adjust(5), TimeUnit.SECONDS); //Assert.assertTrue(testResults.isCdiBeanBeforeDestroyed()); //Assert.assertTrue(testResults.isCdiBeanDestroyed()); //Assert.assertTrue(testResults.isEjbBeanBeforeDestroyed()); //Assert.assertTrue(testResults.isEjbBeanDestroyed()); } @Test public void testWar() throws NamingException, InterruptedException { final TestResults testResults = (TestResults) initialContext.lookup("java:global/"+ TEST_RESULTS +"/"+ TestResultsBean.class.getSimpleName()+"!"+ TestResults.class.getName()); // setup initialized test testResults.setup(2); // deploy app deployer.deploy(TEST_BEANS_WAR); // await and assert initialized results testResults.await(TimeoutUtil.adjust(5), TimeUnit.SECONDS); Assert.assertTrue(testResults.isCdiBeanInitialized()); Assert.assertTrue(testResults.isServletInitialized()); // setup before destroyed and destroyed test testResults.setup(4); // undeploy app deployer.undeploy(TEST_BEANS_WAR); // await and assert before destroyed and destroyed results testResults.await(TimeoutUtil.adjust(5), TimeUnit.SECONDS); Assert.assertTrue(testResults.isCdiBeanBeforeDestroyed()); Assert.assertTrue(testResults.isCdiBeanDestroyed()); Assert.assertTrue(testResults.isServletBeforeDestroyed()); Assert.assertTrue(testResults.isServletDestroyed()); } }
8,568
47.6875
183
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/context/application/lifecycle/Mdb.java
/* * JBoss, Home of Professional Open Source * Copyright 2019, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.context.application.lifecycle; import org.jboss.logging.Logger; import jakarta.ejb.ActivationConfigProperty; import jakarta.ejb.MessageDriven; import jakarta.jms.JMSDestinationDefinition; import jakarta.jms.Message; import jakarta.jms.MessageListener; import jakarta.jms.TextMessage; /** * @author emmartins */ @JMSDestinationDefinition( name = Mdb.JNDI_NAME, interfaceName = "jakarta.jms.Queue", destinationName = "jmsQueue" ) @MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = Mdb.JNDI_NAME), @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "jakarta.jms.Queue"), @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "auto-acknowledge") }) public class Mdb implements MessageListener { private static final Logger LOGGER = Logger.getLogger(Mdb.class); public static final String JNDI_NAME = "java:app/mdb"; public void onMessage(Message message) { try { String text = ((TextMessage) message).getText(); LOGGER.info("Received " + text); } catch (Throwable e) { LOGGER.error("Failed to receive or send message", e); } } }
2,328
35.968254
105
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/beanvalidation/MinimumValueProvider.java
/* * JBoss, Home of Professional Open Source * Copyright 2013, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.beanvalidation; /** * Provides a minimum value for the number of people for a Reservation instance. * * @author Farah Juma */ public class MinimumValueProvider { public int getMin() { return 5; } }
1,279
35.571429
80
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/beanvalidation/CustomMin.java
/* * JBoss, Home of Professional Open Source * Copyright 2013, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.beanvalidation; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.PARAMETER; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.lang.annotation.Target; import jakarta.validation.Constraint; import jakarta.validation.Payload; /** * A custom constraint that uses CDI in its validator class. * * @author Farah Juma */ @Constraint(validatedBy = CustomMinValidator.class) @Documented @Target({ METHOD, FIELD, TYPE, PARAMETER }) @Retention(RUNTIME) public @interface CustomMin { String message() default "Not enough people for a reservation"; Class<?>[] groups() default {}; Class<? extends Payload>[] payload() default {}; }
1,960
36
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/beanvalidation/Reservation.java
/* * JBoss, Home of Professional Open Source * Copyright 2013, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.beanvalidation; import jakarta.validation.constraints.NotNull; /** * A Reservation. * * @author Farah Juma */ public class Reservation { @CustomMin private int numberOfPeople; @NotNull(message = "may not be null") private String lastName; public Reservation(int numberOfPeople, String lastName) { this.numberOfPeople = numberOfPeople; this.lastName = lastName; } }
1,473
32.5
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/beanvalidation/BeanValidationIntegrationTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2013, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.beanvalidation; import static org.jboss.as.test.shared.PermissionUtils.createPermissionsXmlAsset; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Set; import javax.naming.InitialContext; import jakarta.inject.Inject; import javax.naming.NamingException; import jakarta.validation.ConstraintViolation; import jakarta.validation.ValidatorFactory; import org.hibernate.validator.HibernateValidatorPermission; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; /** * Tests for the integration of CDI and Jakarta Bean Validation. * * @author Farah Juma */ @RunWith(Arquillian.class) public class BeanValidationIntegrationTestCase { @Deployment public static Archive<?> deploy() { WebArchive war = ShrinkWrap.create(WebArchive.class, "BeanValidationIntegrationTestCase.war"); war.addPackage(BeanValidationIntegrationTestCase.class.getPackage()); war.addAsWebInfResource(new StringAsset("<beans bean-discovery-mode=\"all\"></beans>"), "beans.xml"); war.addAsManifestResource(createPermissionsXmlAsset( HibernateValidatorPermission.ACCESS_PRIVATE_MEMBERS ), "permissions.xml"); return war; } @Inject ValidatorFactory defaultValidatorFactory; @Test public void testInjectedValidatorFactoryIsCdiEnabled() { assertNotNull(defaultValidatorFactory); Set<ConstraintViolation<Reservation>> violations = defaultValidatorFactory.getValidator().validate(new Reservation(1, "Smith")); assertEquals(1, violations.size()); assertEquals("Not enough people for a reservation", violations.iterator().next().getMessage()); } @Test public void testJndiBoundValidatorFactoryIsCdiEnabled() throws NamingException { ValidatorFactory validatorFactory = (ValidatorFactory) new InitialContext().lookup("java:comp/ValidatorFactory"); assertNotNull(validatorFactory); Set<ConstraintViolation<Reservation>> violations = validatorFactory.getValidator().validate(new Reservation(4, null)); List<String> actualViolations = new ArrayList<String>(); for (ConstraintViolation<?> violation : violations) { actualViolations.add(violation.getMessage()); } List<String> expectedViolations = new ArrayList<String>(); expectedViolations.add("may not be null"); expectedViolations.add("Not enough people for a reservation"); Collections.sort(actualViolations); Collections.sort(expectedViolations); assertEquals(expectedViolations, actualViolations); } }
4,066
40.080808
136
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/beanvalidation/CustomMinValidator.java
/* * JBoss, Home of Professional Open Source * Copyright 2013, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.beanvalidation; import jakarta.inject.Inject; import jakarta.validation.ConstraintValidator; import jakarta.validation.ConstraintValidatorContext; /** * A validator that uses constructor injection. * * @author Farah Juma */ public class CustomMinValidator implements ConstraintValidator<CustomMin, Integer> { private final MinimumValueProvider minimumValueProvider; @Inject public CustomMinValidator(MinimumValueProvider minimumValueProvider) { this.minimumValueProvider = minimumValueProvider; } @Override public void initialize(CustomMin constraintAnnotation) { } @Override public boolean isValid(Integer value, ConstraintValidatorContext context) { return value >= minimumValueProvider.getMin(); } }
1,828
34.862745
84
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/extensions/ExtensionsInEarDiscoveredTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.extensions; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; import jakarta.enterprise.inject.spi.Extension; import javax.naming.InitialContext; import javax.naming.NamingException; /** * AS7-623 * * Make sure extensions in WEB-INF/lib of a war in an ear are discovered. * * A jar with a portable extension that adds MyBean as a bean is added to a war that is deployed as an ear * * Normally MyBean would not be a bean as it is not in a jar with a beans.xml * * The test checks that it is possible to inject MyBean * * @author Stuart Douglas */ @RunWith(Arquillian.class) public class ExtensionsInEarDiscoveredTestCase { @Deployment public static Archive<?> deploy() { EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "testExtensions.ear"); WebArchive war = ShrinkWrap.create(WebArchive.class, "testWar.war"); JavaArchive warLib = ShrinkWrap.create(JavaArchive.class, "testLib.jar"); warLib.addClasses(MyBean.class, AddBeanExtension.class); warLib.add(new StringAsset(AddBeanExtension.class.getName()), "META-INF/services/" + Extension.class.getName()); war.addAsLibrary(warLib); war.addClass(WarSLSB.class); war.add(EmptyAsset.INSTANCE, "WEB-INF/beans.xml"); JavaArchive lib = ShrinkWrap.create(JavaArchive.class, "lib.jar"); lib.addClasses(ExtensionsInEarDiscoveredTestCase.class, SomeInterface.class); ear.addAsLibrary(lib); ear.addAsModule(war); return ear; } @Test public void testExtensionIsLoaded() throws NamingException { SomeInterface bean = (SomeInterface) new InitialContext().lookup("java:global/testExtensions/testWar/WarSLSB"); bean.testInjectionWorked(); } }
3,276
35.820225
120
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/extensions/WarSLSB.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.extensions; import org.junit.Assert; import jakarta.ejb.Local; import jakarta.ejb.Stateless; import jakarta.inject.Inject; /** * @author Stuart Douglas */ @Stateless @Local(SomeInterface.class) public class WarSLSB implements SomeInterface { @Inject private MyBean myBean; @Override public void testInjectionWorked() { Assert.assertNotNull(myBean); } }
1,450
30.543478
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/extensions/AddBeanExtension.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.extensions; import jakarta.enterprise.event.Observes; import jakarta.enterprise.inject.spi.BeanManager; import jakarta.enterprise.inject.spi.BeforeBeanDiscovery; import jakarta.enterprise.inject.spi.Extension; /** * @author Stuart Douglas */ public class AddBeanExtension implements Extension { public void beforeBeanDiscovery(@Observes BeforeBeanDiscovery beforeBeanDiscovery, final BeanManager beanManager) { beforeBeanDiscovery.addAnnotatedType(beanManager.createAnnotatedType(MyBean.class), MyBean.class.getName()); } }
1,605
40.179487
119
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/extensions/MyBean.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.extensions; /** * @author Stuart Douglas */ public class MyBean { }
1,130
38
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/extensions/SomeInterface.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.extensions; /** * @author Stuart Douglas */ public interface SomeInterface { void testInjectionWorked(); }
1,174
36.903226
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/extensions/cdiportableextensions/ExtensionTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.extensions.cdiportableextensions; import static org.junit.Assert.assertEquals; import java.net.MalformedURLException; import java.net.URL; import jakarta.enterprise.inject.spi.Extension; import jakarta.inject.Inject; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.AfterClass; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(Arquillian.class) public class ExtensionTestCase extends AbstractModuleTest { protected static String modulePath = "cidExtensionModule"; @AfterClass public static void tearDown() throws Exception { doCleanup(modulePath); } protected static void doSetup() throws Exception { URL url = ExtensionTestCase.class.getResource("module.xml"); if (url == null) { throw new IllegalStateException("Could not find module.xml"); } JavaArchive moduleJar = ShrinkWrap.create(JavaArchive.class, "weldTest.jar"); moduleJar.addClasses(FunExtension.class, Funny.class); moduleJar.addAsServiceProvider(Extension.class, FunExtension.class); doSetup(modulePath, url.openStream(), moduleJar); } @Deployment public static Archive<?> deploy() throws Exception { doSetup(); JavaArchive jar = ShrinkWrap .create(JavaArchive.class, "test.jar") .addClasses(Clown.class, ExtensionTestCase.class, AbstractModuleTest.class) .addAsManifestResource(new StringAsset("<beans bean-discovery-mode=\"all\"></beans>"), "beans.xml") .addAsManifestResource(new StringAsset("Dependencies: cidExtensionModule services\n"), "MANIFEST.MF"); return jar; } @Inject FunExtension funExtension; @Test public void testFoo() throws MalformedURLException { assertEquals("There should be one funny bean.", 1, funExtension.getFunnyBeans().size()); assertEquals("Clown should be the funny bean.", Clown.class, funExtension.getFunnyBeans().iterator().next() .getBeanClass()); } }
3,383
36.186813
115
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/extensions/cdiportableextensions/AbstractModuleTest.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.extensions.cdiportableextensions; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import org.jboss.shrinkwrap.api.exporter.ZipExporter; import org.jboss.shrinkwrap.api.spec.JavaArchive; /** * Tests that beans defined in a static can be used by a deployment * * @author Stuart Douglas * @author Marek Schmidt */ public abstract class AbstractModuleTest { public static void doSetup(String modulePath, InputStream moduleXml, JavaArchive moduleArchive) throws Exception { File testModuleRoot = new File(getModulePath(), modulePath); deleteRecursively(testModuleRoot); createTestModule(testModuleRoot, moduleXml, moduleArchive); } public static void doCleanup(String modulePath) { File testModuleRoot = new File(getModulePath(), modulePath); deleteRecursively(testModuleRoot); } private static void deleteRecursively(File file) { if (file.exists()) { if (file.isDirectory()) { for (String name : file.list()) { deleteRecursively(new File(file, name)); } } file.delete(); //this will always fail on windows, as module is still loaded and in use. } } private static void createTestModule(File testModuleRoot, InputStream moduleXml, JavaArchive moduleArchive) throws IOException { if (testModuleRoot.exists()) { throw new IllegalArgumentException(testModuleRoot + " already exists"); } File file = new File(testModuleRoot, "main"); if (!file.mkdirs()) { throw new IllegalArgumentException("Could not create " + file); } copyFile(new File(file, "module.xml"), moduleXml); try (FileOutputStream jarFile = new FileOutputStream(new File(file, moduleArchive.getName()))){ moduleArchive.as(ZipExporter.class).exportTo(jarFile); } } private static void copyFile(File target, InputStream src) throws IOException { Files.copy(src, target.toPath()); } private static File getModulePath() { String modulePath = System.getProperty("module.path", null); if (modulePath == null) { String jbossHome = System.getProperty("jboss.home", null); if (jbossHome == null) { throw new IllegalStateException("Neither -Dmodule.path nor -Djboss.home were set"); } modulePath = jbossHome + File.separatorChar + "modules"; } else { modulePath = modulePath.split(File.pathSeparator)[0]; } File moduleDir = new File(modulePath); if (!moduleDir.exists()) { throw new IllegalStateException("Determined module path does not exist"); } if (!moduleDir.isDirectory()) { throw new IllegalStateException("Determined module path is not a dir"); } return moduleDir; } }
4,076
37.462264
132
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/extensions/cdiportableextensions/Clown.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.extensions.cdiportableextensions; @Funny public class Clown { }
1,133
38.103448
76
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/extensions/cdiportableextensions/Funny.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.extensions.cdiportableextensions; import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.lang.annotation.Target; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.PARAMETER; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; @Target({ TYPE, METHOD, PARAMETER, FIELD }) @Retention(RUNTIME) @Documented public @interface Funny { }
1,605
37.238095
76
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/extensions/cdiportableextensions/FunExtension.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.extensions.cdiportableextensions; import java.util.HashSet; import java.util.Set; import jakarta.enterprise.event.Observes; import jakarta.enterprise.inject.spi.Bean; import jakarta.enterprise.inject.spi.Extension; import jakarta.enterprise.inject.spi.ProcessAnnotatedType; import jakarta.enterprise.inject.spi.ProcessBean; public class FunExtension implements Extension { Set<Class<?>> funnyClasses = new HashSet<Class<?>>(); Set<Bean<?>> funnyBeans = new HashSet<Bean<?>>(); public Set<Bean<?>> getFunnyBeans() { return funnyBeans; } public void processAnnotatedType(@Observes ProcessAnnotatedType<?> pat) { //System.out.println("FunExtension processAnnotatedType " + pat.getAnnotatedType().toString()); if (pat.getAnnotatedType().getAnnotation(Funny.class) != null) { //System.out.println("FunExtension adding funny class " + pat.getAnnotatedType().getJavaClass()); funnyClasses.add(pat.getAnnotatedType().getJavaClass()); } } public void processBean(@Observes ProcessBean<?> pb) { //System.out.println("FunExtension processBean " + pb.getBean().getBeanClass()); if (funnyClasses.contains(pb.getBean().getBeanClass())) { funnyBeans.add(pb.getBean()); } } }
2,360
38.35
109
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/jpa/Employee.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.jpa; import jakarta.persistence.Entity; import jakarta.persistence.Id; /** * Employee entity class * * @author Scott Marlow */ @Entity public class Employee { @Id private int id; private String name; private String address; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public int getId() { return id; } public void setId(int id) { this.id = id; } }
1,708
24.507463
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/jpa/CdiJpaInjectingBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.jpa; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; import jakarta.persistence.Query; public class CdiJpaInjectingBean { @PersistenceContext(unitName = "cdiPu") EntityManager em; public Employee queryEmployeeName(int id) { Query q = em.createQuery("SELECT e FROM Employee e where e.id=:employeeId"); q.setParameter("employeeId", id); return (Employee) q.getSingleResult(); } }
1,531
36.365854
84
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/jpa/WeldJpaInjectionTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.jpa; import jakarta.inject.Inject; import jakarta.persistence.NoResultException; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; /** * Weld JPA injection tests. Simply tests that a persistence context can be injected into a CDI bean. * * @author Stuart Douglas */ @RunWith(Arquillian.class) public class WeldJpaInjectionTestCase { private static final String ARCHIVE_NAME = "jpa_OrmTestCase"; private static final String persistence_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> " + "<persistence xmlns=\"http://java.sun.com/xml/ns/persistence\" version=\"1.0\">" + " <persistence-unit name=\"cdiPu\">" + " <description>OrmTestCase Persistence Unit." + " </description>" + " <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>" + "<properties> <property name=\"hibernate.hbm2ddl.auto\" value=\"create-drop\"/>" + "</properties>" + " </persistence-unit>" + "</persistence>"; @Deployment public static Archive<?> deploy() { JavaArchive jar = ShrinkWrap.create(JavaArchive.class, ARCHIVE_NAME + ".jar"); jar.addClasses(WeldJpaInjectionTestCase.class, Employee.class, CdiJpaInjectingBean.class ); jar.addAsResource(new StringAsset(persistence_xml), "META-INF/persistence.xml"); jar.addAsManifestResource(new StringAsset("<beans bean-discovery-mode=\"all\"></beans>"), "beans.xml"); return jar; } @Rule public ExpectedException expected = ExpectedException.none(); @Inject private CdiJpaInjectingBean bean; @Test public void testOrmXmlDefinedEmployeeEntity() { expected.expect(NoResultException.class); bean.queryEmployeeName(1); } }
3,257
36.022727
111
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/jpa/scoping/Employee.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.jpa.scoping; import jakarta.persistence.Entity; import jakarta.persistence.Id; /** * Employee entity class * * @author Scott Marlow */ @Entity public class Employee { @Id private int id; private String name; private String address; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public int getId() { return id; } public void setId(int id) { this.id = id; } }
1,716
24.626866
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/jpa/scoping/WeldJpaInjectionScopeTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.jpa.scoping; import jakarta.inject.Inject; import jakarta.persistence.NoResultException; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * AS7-1761 * <p/> * Weld JPA injection tests. Simply tests that a persistence context can be injected into a CDI bean in another deployment unit * * @author Stuart Douglas */ @RunWith(Arquillian.class) public class WeldJpaInjectionScopeTestCase { private static final String persistence_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> " + "<persistence xmlns=\"http://java.sun.com/xml/ns/persistence\" version=\"1.0\">" + " <persistence-unit name=\"cdiPu\">" + " <description>OrmTestCase Persistence Unit." + " </description>" + " <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>" + "<properties> <property name=\"hibernate.hbm2ddl.auto\" value=\"create-drop\"/>" + "</properties>" + " </persistence-unit>" + "</persistence>"; @Deployment public static Archive<?> deploy() { EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "cdiPuScope.ear"); WebArchive war = ShrinkWrap.create(WebArchive.class, "simple.war"); war.addClasses(WeldJpaInjectionScopeTestCase.class, CdiJpaInjectingBean.class); war.addAsWebInfResource(new StringAsset("<beans bean-discovery-mode=\"all\"></beans>"), "beans.xml"); ear.addAsModule(war); JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "util.jar"); jar.addAsResource(new StringAsset(persistence_xml), "META-INF/persistence.xml"); jar.addClass(Employee.class); ear.addAsLibrary(jar); return ear; } @Inject private CdiJpaInjectingBean bean; @Test public void testOrmXmlDefinedEmployeeEntity() throws Exception { try { Employee emp = bean.queryEmployeeName(1); } catch (Exception e) { if (!(e instanceof NoResultException)) { Assert.fail("Expected NoResultException but got " + e); } return; } Assert.fail("NoResultException should occur but didn't!"); } }
3,793
38.936842
127
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/jpa/scoping/CdiJpaInjectingBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.jpa.scoping; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; import jakarta.persistence.Query; public class CdiJpaInjectingBean { @PersistenceContext(unitName = "cdiPu") EntityManager em; public Employee queryEmployeeName(int id) { Query q = em.createQuery("SELECT e FROM Employee e where e.id=:employeeId"); q.setParameter("employeeId", id); return (Employee) q.getSingleResult(); } }
1,539
36.560976
84
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/jpa/subdeployment/WeldSubdeploymentScopeTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.jpa.subdeployment; import jakarta.inject.Inject; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * WFLY-6485 * <p/> * Test that JPA dependencies are set for sub-deployments * * @author Scott Marlow */ @RunWith(Arquillian.class) public class WeldSubdeploymentScopeTestCase { @Deployment public static Archive<?> deploy() { EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "cdiPuScope.ear"); WebArchive war = ShrinkWrap.create(WebArchive.class, "simple.war"); war.addClasses(WeldSubdeploymentScopeTestCase.class, CdiJpaInjectingBean.class); war.addAsWebInfResource(new StringAsset("<beans bean-discovery-mode=\"all\"></beans>"), "beans.xml"); JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "util.jar"); jar.addAsManifestResource(WeldSubdeploymentScopeTestCase.class.getPackage(), "persistence.xml", "persistence.xml"); war.addAsLibrary(jar); ear.addAsModule(war); return ear; } @Inject private CdiJpaInjectingBean bean; @Test public void testInjectedPersistenceContext() throws Exception { Assert.assertNotNull("WFLY-6485 regression, injected EntityManagerFactory should not be null but is", bean.entityManagerFactory()); } }
2,791
37.777778
123
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/jpa/subdeployment/QualifyEntityManagerFactory.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.jpa.subdeployment; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.PARAMETER; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; import jakarta.inject.Qualifier; /** * QualifyEntityManagerFactory * * @author Scott Marlow */ @Qualifier @Retention(RUNTIME) @Target({TYPE, METHOD, FIELD, PARAMETER}) public @interface QualifyEntityManagerFactory { }
1,668
34.510638
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/jpa/subdeployment/CdiJpaInjectingBean.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.jpa.subdeployment; import jakarta.enterprise.inject.Produces; import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.PersistenceUnit; public class CdiJpaInjectingBean { @Produces @QualifyEntityManagerFactory @PersistenceUnit(unitName = "cdiPu") EntityManagerFactory emf; public EntityManagerFactory entityManagerFactory() { return emf; } }
1,466
33.928571
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/alternative/WeldAlternativeTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.alternative; import jakarta.inject.Inject; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * * A test of the Jakarta Contexts and Dependency Injection alternatives. This tests that the alternative * information in the beans.xml file is being parsed correctly. * * @author Stuart Douglas */ @RunWith(Arquillian.class) public class WeldAlternativeTestCase { @Deployment public static Archive<?> deploy() { JavaArchive jar = ShrinkWrap.create(JavaArchive.class); jar.addPackage(WeldAlternativeTestCase.class.getPackage()); jar.addAsManifestResource(new StringAsset("<beans bean-discovery-mode=\"all\"><alternatives><class>" + AlternativeBean.class.getName() + "</class></alternatives></beans>"), "beans.xml"); return jar; } @Inject private SimpleBean bean; @Test public void testAlternatives() { Assert.assertEquals("Hello World", bean.sayHello()); } }
2,323
35.3125
194
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/alternative/SimpleBean.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.alternative; /** * @author Stuart Douglas */ public class SimpleBean { public String sayHello() { return "Hello"; } }
1,197
35.30303
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/alternative/AlternativeBean.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.alternative; import jakarta.enterprise.inject.Alternative; /** * @author Stuart Douglas */ @Alternative public class AlternativeBean extends SimpleBean { @Override public String sayHello() { return "Hello World"; } }
1,301
34.189189
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/packaging/ABean.java
package org.jboss.as.test.integration.weld.packaging; import jakarta.enterprise.context.Dependent; /** * @author Stuart Douglas */ @Dependent public class ABean { }
169
14.454545
53
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/packaging/WeldMultipleBeansXmlTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.packaging; import jakarta.inject.Inject; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * * Tests that war deployments work correctly even with multiple beans.xml files * * AS7-6737 * * @author Stuart Douglas */ @RunWith(Arquillian.class) public class WeldMultipleBeansXmlTestCase { @Deployment public static Archive<?> deploy() { WebArchive jar = ShrinkWrap.create(WebArchive.class); jar.addPackage(WeldMultipleBeansXmlTestCase.class.getPackage()); jar.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); jar.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); jar.addAsResource(EmptyAsset.INSTANCE, "META-INF/beans.xml"); return jar; } @Inject private ABean bean; @Test public void testAlternatives() { Assert.assertNotNull(bean); } }
2,234
32.358209
79
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/jndi/WeldJndiLookupTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.jndi; import jakarta.enterprise.inject.spi.BeanManager; import jakarta.inject.Inject; import javax.naming.InitialContext; import javax.naming.NamingException; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; /** * @author Stuart Douglas */ @RunWith(Arquillian.class) public class WeldJndiLookupTestCase { @Deployment public static Archive<?> deploy() { JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "WeldJndiLookupTestCase.jar"); jar.addPackage(WeldJndiLookupTestCase.class.getPackage()); jar.add(new StringAsset("<beans bean-discovery-mode=\"all\"></beans>"), "META-INF/beans.xml"); jar.addAsManifestResource(WeldJndiLookupTestCase.class.getPackage(), "ejb-jar.xml", "ejb-jar.xml"); return jar; } @Inject private StartupSingletonEjb ejb; @Inject private AppNameInjector appNameInjector; @Test public void testBeanManagerCanBeLookedUp() throws NamingException { BeanManager bm = (BeanManager) new InitialContext().lookup("java:comp/BeanManager"); Assert.assertNotNull(bm); } @Test public void testOtherJNDIbindingsAreAvailableAtStartup() { Assert.assertEquals("WeldJndiLookupTestCase", ejb.getName()); } @Test public void testBeanManagerResourceLookup() { Assert.assertTrue( ejb.getBeanManager() instanceof BeanManager); } @Test public void testCdiBeanWithResourceName() { Assert.assertEquals("foo-value", appNameInjector.getFoo()); } }
2,896
34.765432
107
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/jndi/AppNameInjector.java
package org.jboss.as.test.integration.weld.jndi; import jakarta.annotation.Resource; import jakarta.enterprise.context.ApplicationScoped; /** * @author Stuart Douglas */ @ApplicationScoped public class AppNameInjector { @Resource(name = "java:global/foo") private String name; public String getFoo() { return name; } }
350
16.55
52
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/jndi/StartupSingletonEjb.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.jndi; import jakarta.annotation.Resource; import jakarta.ejb.Singleton; import jakarta.ejb.Startup; import jakarta.enterprise.inject.spi.BeanManager; import jakarta.inject.Inject; /** * @author Stuart Douglas */ @Singleton @Startup public class StartupSingletonEjb { @Inject private String appName; @Resource(lookup="java:comp/BeanManager") private BeanManager beanManager; public String getName() { return appName; } public BeanManager getBeanManager() { return beanManager; } }
1,598
28.611111
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/jndi/AppNameProducer.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.jndi; import jakarta.annotation.Resource; import jakarta.enterprise.inject.Produces; /** * @author Stuart Douglas */ public class AppNameProducer { @Produces @Resource(mappedName="java:app/AppName") public String name; }
1,305
34.297297
70
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/servlet/NonCdiCompliantAsyncListener.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.servlet; import java.io.IOException; import jakarta.servlet.AsyncEvent; import jakarta.servlet.AsyncListener; public class NonCdiCompliantAsyncListener implements AsyncListener { public NonCdiCompliantAsyncListener(int foo) { } @Override public void onComplete(AsyncEvent event) throws IOException { } @Override public void onTimeout(AsyncEvent event) throws IOException { } @Override public void onError(AsyncEvent event) throws IOException { } @Override public void onStartAsync(AsyncEvent event) throws IOException { } }
1,648
31.333333
73
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/servlet/NonCdiCompliantAsyncListenerTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.weld.servlet; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; /** * A CDI-incompatible {@link javax.servletAsyncListener} may be bundled with a deployment. * This is OK as long as the application does it pass the listener class to * {@link javax.servletAsyncContext#createListener(Class)}. This test verifies that the deployment * of an application with the listener does not fail. * * @author Jozef Hartinger * * @see https://issues.jboss.org/browse/WFLY-2165 * */ @RunWith(Arquillian.class) public class NonCdiCompliantAsyncListenerTestCase { @Deployment public static Archive<?> getDeployment() { return ShrinkWrap.create(WebArchive.class) .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") .addClass(NonCdiCompliantAsyncListener.class); } @Test public void test() { // noop, just test that the app deploys } }
2,255
37.237288
98
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/optionalcomponent/cleanup/StandardServletAsyncWebRequest.java
/* * JBoss, Home of Professional Open Source * Copyright 2018, 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.as.test.integration.weld.optionalcomponent.cleanup; import java.io.IOException; import jakarta.servlet.AsyncEvent; import jakarta.servlet.AsyncListener; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; /** * * @author <a href="mailto:[email protected]">Matej Novotny</a> */ public class StandardServletAsyncWebRequest implements AsyncListener { /** * just to make non-default constructor - this is against spec and will blow up */ public StandardServletAsyncWebRequest(HttpServletRequest request, HttpServletResponse response) { } @Override public void onStartAsync(AsyncEvent event) throws IOException { } @Override public void onError(AsyncEvent event) throws IOException { } @Override public void onTimeout(AsyncEvent event) throws IOException { } @Override public void onComplete(AsyncEvent event) throws IOException { } }
1,753
30.890909
101
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/optionalcomponent/cleanup/EjbService.java
/* * JBoss, Home of Professional Open Source * Copyright 2018, 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.as.test.integration.weld.optionalcomponent.cleanup; import jakarta.ejb.Singleton; import jakarta.ejb.Startup; /** * * @author <a href="mailto:[email protected]">Matej Novotny</a> */ @Singleton @Startup public class EjbService { }
1,031
33.4
75
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/optionalcomponent/cleanup/WeldCleanupWithOptionalWebComponentTest.java
/* * JBoss, Home of Professional Open Source * Copyright 2018, 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.as.test.integration.weld.optionalcomponent.cleanup; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; /** * Tests that Weld cleanup is not causing deployment errors for composite deployment with optional web component. * * @see WFLY-10784 * @author <a href="mailto:[email protected]">Matej Novotny</a> */ @RunWith(Arquillian.class) public class WeldCleanupWithOptionalWebComponentTest { @Deployment(name = "ear", testable = false) public static Archive<?> ear() { // create faulty WAR WebArchive war = ShrinkWrap.create(WebArchive.class, "WebComponentsIntegrationTestCase.war"); war.addAsLibraries( ShrinkWrap.create(JavaArchive.class, "module.jar").addClass(StandardServletAsyncWebRequest.class)); // create EJB JAR JavaArchive ejb = ShrinkWrap.create(JavaArchive.class, "ejb.jar").addClass(EjbService.class); // add all to EAR EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "WebComponentsIntegrationTestCase.ear"); ear.addAsModule(war); ear.addAsModule(ejb); return ear; } @Test @RunAsClient public void testEar() { // no-op the ability to deploy without error is the test here } }
2,451
37.920635
115
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/bc/BouncyCastleModuleTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.bc; import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset; import java.nio.charset.StandardCharsets; import java.security.Key; import java.security.Security; import java.security.SecurityPermission; import java.util.Arrays; import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.logging.Logger; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Test; import org.junit.runner.RunWith; /** * Verify that BouncyCastle securtiy provider can be loaded and used through JCE api. * Basically, this can fail when security provider class isn't in properly signed jar with signature accepted by used JDK. * See https://docs.oracle.com/javase/8/docs/technotes/guides/security/crypto/HowToImplAProvider.html#Step1a for details. */ @RunWith(Arquillian.class) public class BouncyCastleModuleTestCase { private static final String BC_DEPLOYMENT = "bc-test"; private static final Logger logger = Logger.getLogger(BouncyCastleModuleTestCase.class); @Deployment(name = BC_DEPLOYMENT, testable = true) public static WebArchive createDeployment() { WebArchive archive = ShrinkWrap.create(WebArchive.class, BC_DEPLOYMENT + ".war"); archive.addPackage(BouncyCastleModuleTestCase.class.getPackage()); archive.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); //needed to load CDI for arquillian archive.addAsManifestResource(createPermissionsXmlAsset( new SecurityPermission("insertProvider"), new SecurityPermission("removeProviderProperty.BC"), new SecurityPermission("putProviderProperty.BC") ), "permissions.xml"); archive.setManifest(new StringAsset("" + "Manifest-Version: 1.0\n" + "Dependencies: org.bouncycastle.bcprov, org.bouncycastle.bcpkix, org.bouncycastle.bcmail\n")); return archive; } @Test public void testBouncyCastleProviderIsUsableThroughJceApi() throws Exception { BouncyCastleProvider bcProvider = null; try { bcProvider = new BouncyCastleProvider(); useBouncyCastleProviderThroughJceApi(bcProvider); } catch (Exception e) { if (e instanceof SecurityException && e.getMessage().contains("JCE cannot authenticate the provider")) { String bcLocation = (bcProvider == null) ? "" : "(" + bcProvider.getClass().getResource("/") + ")"; throw new Exception("Packaging with BouncyCastleProvider" + bcLocation + " is probably not properly signed for JCE usage, see server log for details.", e); } else { throw e; } } } private static void useBouncyCastleProviderThroughJceApi(BouncyCastleProvider bcProvider) throws Exception { Security.addProvider(bcProvider); KeyGenerator keygenerator = KeyGenerator.getInstance("DES"); Key myDesKey = keygenerator.generateKey(); Cipher desCipher; // Create the cipher with explicit BC provider desCipher = Cipher.getInstance("DES/ECB/PKCS5Padding", bcProvider.getName()); // Initialize the cipher for encryption desCipher.init(Cipher.ENCRYPT_MODE, myDesKey); // Sensitive information byte[] text = "Nobody can see me".getBytes(StandardCharsets.UTF_8); logger.debug("Text [Byte Format]: " + Arrays.toString(text)); logger.debug("Text: " + new String(text)); // Encrypt the text byte[] textEncrypted = desCipher.doFinal(text); logger.debug("Text Encryted [Byte Format]: " + Arrays.toString(textEncrypted)); // Initialize the same cipher for decryption desCipher.init(Cipher.DECRYPT_MODE, myDesKey); // Decrypt the text byte[] textDecrypted = desCipher.doFinal(textEncrypted); logger.debug("Text Decryted: " + new String(textDecrypted,StandardCharsets.UTF_8)); } }
5,431
43.162602
122
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/datasourcedefinition/RepeatedAnnotationDataSourceBean.java
/* * Copyright 2018 Red Hat, Inc. * * 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.as.test.integration.ee.datasourcedefinition; import java.sql.SQLException; import jakarta.annotation.Resource; import jakarta.annotation.sql.DataSourceDefinition; import jakarta.ejb.Stateless; import javax.sql.DataSource; /** * @author Stuart Douglas */ @DataSourceDefinition( name = "java:comp/ds", user = "sa", password = "sa", className = "org.h2.jdbcx.JdbcDataSource", url = "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE" ) @DataSourceDefinition( name = "java:comp/dse", className = "org.jboss.as.test.integration.ee.datasourcedefinition.EmbeddedDataSource", url = "jdbc:embedded:/some/url" ) @Stateless public class RepeatedAnnotationDataSourceBean { @Resource(lookup = "java:comp/ds", name = "java:app/DataSource") private DataSource dataSource; /** * This should be injected with the same datasource as above, as they both have the same name */ @Resource(lookup = "java:comp/ds") private DataSource dataSource2; @Resource(lookup = "java:app/DataSource") private DataSource dataSource3; @Resource(lookup = "org.jboss.as.test.integration.ee.datasourcedefinition.RepeatedAnnotationDataSourceBean/dataSource3") private DataSource dataSource4; @Resource(lookup = "java:comp/dse") private DataSource dataSource5; public void createTable() throws SQLException { dataSource.getConnection().createStatement().execute("create table if not exists coffee(id int not null);"); } public void insert1RolledBack() throws SQLException { dataSource.getConnection().createStatement().execute("insert into coffee values (1)"); throw new RuntimeException("roll back"); } public void insert2() throws SQLException { dataSource.getConnection().createStatement().execute("insert into coffee values (2)"); } public DataSource getDataSource() { return dataSource; } public DataSource getDataSource2() { return dataSource2; } public DataSource getDataSource3() { return dataSource3; } public DataSource getDataSource4() { return dataSource4; } public DataSource getDataSource5() { return dataSource5; } }
2,882
30
124
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/datasourcedefinition/DataSourceBean.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ee.datasourcedefinition; import java.sql.SQLException; import jakarta.annotation.Resource; import jakarta.annotation.sql.DataSourceDefinition; import jakarta.annotation.sql.DataSourceDefinitions; import jakarta.ejb.Stateless; import javax.sql.DataSource; /** * @author Stuart Douglas */ @DataSourceDefinitions({ @DataSourceDefinition( name = "java:comp/ds", user = "sa", password = "sa", className = "org.h2.jdbcx.JdbcDataSource", url = "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE" ), @DataSourceDefinition( name = "java:comp/dse", className = "org.jboss.as.test.integration.ee.datasourcedefinition.EmbeddedDataSource", url = "jdbc:embedded:/some/url" ) } ) @Stateless public class DataSourceBean { @Resource(lookup = "java:comp/ds", name="java:app/DataSource") private DataSource dataSource; /** * This should be injected with the same datasource as above, as they both have the same name */ @Resource(lookup="java:comp/ds") private DataSource dataSource2; @Resource(lookup = "java:app/DataSource") private DataSource dataSource3; @Resource(lookup="org.jboss.as.test.integration.ee.datasourcedefinition.DataSourceBean/dataSource3") private DataSource dataSource4; @Resource(lookup="java:comp/dse") private DataSource dataSource5; public void createTable() throws SQLException { dataSource.getConnection().createStatement().execute("create table if not exists coffee(id int not null);"); } public void insert1RolledBack() throws SQLException { dataSource.getConnection().createStatement().execute("insert into coffee values (1)"); throw new RuntimeException("roll back"); } public void insert2() throws SQLException { dataSource.getConnection().createStatement().execute("insert into coffee values (2)"); } public DataSource getDataSource() { return dataSource; } public DataSource getDataSource2() { return dataSource2; } public DataSource getDataSource3() { return dataSource3; } public DataSource getDataSource4() { return dataSource4; } public DataSource getDataSource5() { return dataSource5; } }
3,438
32.38835
116
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/datasourcedefinition/DataSourceDefinitionTestCase.java
/* * JBoss, Home of Professional Open Source * Copyright 2010, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ee.datasourcedefinition; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.sql.DataSource; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; /** * Tests that @DataSourceDefinition works, and that the datasource is automatically enlisted in the transaction * * @author Stuart Douglas */ @RunWith(Arquillian.class) public class DataSourceDefinitionTestCase { @Rule public ExpectedException expectedException = ExpectedException.none(); @Deployment public static Archive<?> deploy() { final WebArchive war = ShrinkWrap.create(WebArchive.class,"testds.war"); war.addClasses(DataSourceBean.class, EmbeddedDataSource.class); war.addAsManifestResource(new StringAsset("Dependencies: com.h2database.h2\n"),"MANIFEST.MF"); return war; } @ArquillianResource private InitialContext ctx; @Before public void createTables() throws NamingException, SQLException { DataSourceBean bean = (DataSourceBean)ctx.lookup("java:module/" + DataSourceBean.class.getSimpleName()); bean.createTable(); } @Test public void testDataSourceDefinition() throws NamingException, SQLException { DataSourceBean bean = (DataSourceBean)ctx.lookup("java:module/" + DataSourceBean.class.getSimpleName()); DataSource ds = bean.getDataSource(); Connection c = ds.getConnection(); ResultSet result = c.createStatement().executeQuery("select 1"); Assert.assertTrue(result.next()); c.close(); } @Test public void testTransactionEnlistment() throws NamingException, SQLException { DataSourceBean bean = (DataSourceBean)ctx.lookup("java:module/" + DataSourceBean.class.getSimpleName()); try { bean.insert1RolledBack(); Assert.fail("expect exception"); } catch (RuntimeException expected) { } DataSource ds = bean.getDataSource(); Connection c = ds.getConnection(); ResultSet result = c.createStatement().executeQuery("select id from coffee where id=1;"); Assert.assertFalse(result.next()); c.close(); } @Test public void testTransactionEnlistment2() throws NamingException, SQLException { DataSourceBean bean = (DataSourceBean)ctx.lookup("java:module/" + DataSourceBean.class.getSimpleName()); bean.insert2(); DataSource ds = bean.getDataSource(); Connection c = ds.getConnection(); ResultSet result = c.createStatement().executeQuery("select id from coffee where id=2;"); Assert.assertTrue(result.next()); c.close(); } @Test public void testResourceInjectionWithSameName() throws NamingException { DataSourceBean bean = (DataSourceBean)ctx.lookup("java:module/" + DataSourceBean.class.getSimpleName()); Assert.assertNotNull(bean.getDataSource2()); Assert.assertNotNull(bean.getDataSource3()); Assert.assertNotNull(bean.getDataSource4()); } /** * Tests an embedded datasource resource def. * @throws NamingException * @throws SQLException */ @Test public void testEmbeddedDatasource() throws NamingException, SQLException { DataSourceBean bean = (DataSourceBean)ctx.lookup("java:module/" + DataSourceBean.class.getSimpleName()); Assert.assertEquals(bean.getDataSource5().getConnection().nativeSQL("dse"),"dse"); } /** * Test if NullPointerException ir raised when connection is closed and then method connection.isWrapperFor(...) is called * See https://issues.jboss.org/browse/JBJCA-1389 */ @Test public void testCloseConnectionWrapperFor() throws NamingException, SQLException { expectedException.expect(SQLException.class); expectedException.expectMessage("IJ031041"); DataSourceBean bean = (DataSourceBean)ctx.lookup("java:module/" + DataSourceBean.class.getSimpleName()); DataSource ds = bean.getDataSource(); Connection c = ds.getConnection(); c.close(); try { c.isWrapperFor(ResultSet.class); } catch (NullPointerException e) { Assert.fail("Wrong exception is raised. The exception should be Connection is not associated with a managed connection: ... See JBJCA-1389."); } } }
5,947
38.919463
154
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/datasourcedefinition/RepeatableDataSourceDefinitionTestCase.java
/* * Copyright 2018 Red Hat, Inc. * * 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.as.test.integration.ee.datasourcedefinition; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.sql.DataSource; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; /** * Tests that @DataSourceDefinition works, and that the datasource is automatically enlisted in the transaction * * @author Stuart Douglas */ @RunWith(Arquillian.class) public class RepeatableDataSourceDefinitionTestCase { @Deployment public static Archive<?> deploy() { final WebArchive war = ShrinkWrap.create(WebArchive.class,"testds.war"); war.addClasses(RepeatedAnnotationDataSourceBean.class, EmbeddedDataSource.class); war.addAsManifestResource(new StringAsset("Dependencies: com.h2database.h2\n"),"MANIFEST.MF"); return war; } @ArquillianResource private InitialContext ctx; @Before public void createTables() throws NamingException, SQLException { RepeatedAnnotationDataSourceBean bean = lookup(); bean.createTable(); } @Test public void testDataSourceDefinition() throws NamingException, SQLException { RepeatedAnnotationDataSourceBean bean = lookup(); DataSource ds = bean.getDataSource(); Connection c = ds.getConnection(); ResultSet result = c.createStatement().executeQuery("select 1"); Assert.assertTrue(result.next()); c.close(); } @Test public void testTransactionEnlistment() throws NamingException, SQLException { RepeatedAnnotationDataSourceBean bean = lookup(); try { bean.insert1RolledBack(); Assert.fail("expect exception"); } catch (RuntimeException expected) { } DataSource ds = bean.getDataSource(); Connection c = ds.getConnection(); ResultSet result = c.createStatement().executeQuery("select id from coffee where id=1;"); Assert.assertFalse(result.next()); c.close(); } @Test public void testTransactionEnlistment2() throws NamingException, SQLException { RepeatedAnnotationDataSourceBean bean = lookup(); bean.insert2(); DataSource ds = bean.getDataSource(); Connection c = ds.getConnection(); ResultSet result = c.createStatement().executeQuery("select id from coffee where id=2;"); Assert.assertTrue(result.next()); c.close(); } @Test public void testResourceInjectionWithSameName() throws NamingException { RepeatedAnnotationDataSourceBean bean = lookup(); Assert.assertNotNull(bean.getDataSource2()); Assert.assertNotNull(bean.getDataSource3()); Assert.assertNotNull(bean.getDataSource4()); } /** * Tests an embedded datasource resource def. * @throws NamingException * @throws SQLException */ @Test public void testEmbeddedDatasource() throws NamingException, SQLException { RepeatedAnnotationDataSourceBean bean = lookup(); Assert.assertEquals(bean.getDataSource5().getConnection().nativeSQL("dse"),"dse"); } private RepeatedAnnotationDataSourceBean lookup() throws NamingException { return (RepeatedAnnotationDataSourceBean) ctx.lookup("java:module/" + RepeatedAnnotationDataSourceBean.class.getSimpleName()); } }
4,397
35.04918
134
java
null
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/datasourcedefinition/EmbeddedDataSource.java
/* * JBoss, Home of Professional Open Source * Copyright 2015, Red Hat Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.test.integration.ee.datasourcedefinition; import java.io.PrintWriter; import java.sql.Array; import java.sql.Blob; import java.sql.CallableStatement; import java.sql.Clob; import java.sql.DatabaseMetaData; import java.sql.NClob; import java.sql.PreparedStatement; import java.sql.SQLClientInfoException; import java.sql.SQLException; import java.sql.SQLFeatureNotSupportedException; import java.sql.SQLWarning; import java.sql.SQLXML; import java.sql.Savepoint; import java.sql.Statement; import java.sql.Struct; import java.util.Map; import java.util.Properties; import java.util.concurrent.Executor; import java.util.logging.Logger; import javax.sql.DataSource; /** * A dummy {@link DataSource} impl, which connection's nativeSql(String) method echoes its string arg value. * * @author emmartins */ public class EmbeddedDataSource implements DataSource { @Override public Connection getConnection() throws SQLException { return new Connection(); } @Override public Connection getConnection(String username, String password) throws SQLException { return new Connection(); } @Override public PrintWriter getLogWriter() throws SQLException { return null; } @Override public void setLogWriter(PrintWriter out) throws SQLException { } @Override public void setLoginTimeout(int seconds) throws SQLException { } @Override public int getLoginTimeout() throws SQLException { return 0; } @Override public Logger getParentLogger() throws SQLFeatureNotSupportedException { return null; } @Override public <T> T unwrap(Class<T> iface) throws SQLException { return null; } public void setUrl(String v) { } @Override public boolean isWrapperFor(Class<?> iface) throws SQLException { return false; } private class Connection implements java.sql.Connection { @Override public Statement createStatement() throws SQLException { return null; } @Override public PreparedStatement prepareStatement(String sql) throws SQLException { return null; } @Override public CallableStatement prepareCall(String sql) throws SQLException { return null; } @Override public String nativeSQL(String sql) throws SQLException { return sql; } @Override public void setAutoCommit(boolean autoCommit) throws SQLException { } @Override public boolean getAutoCommit() throws SQLException { return false; } @Override public void commit() throws SQLException { } @Override public void rollback() throws SQLException { } @Override public void close() throws SQLException { } @Override public boolean isClosed() throws SQLException { return false; } @Override public DatabaseMetaData getMetaData() throws SQLException { return null; } @Override public void setReadOnly(boolean readOnly) throws SQLException { } @Override public boolean isReadOnly() throws SQLException { return false; } @Override public void setCatalog(String catalog) throws SQLException { } @Override public String getCatalog() throws SQLException { return null; } @Override public void setTransactionIsolation(int level) throws SQLException { } @Override public int getTransactionIsolation() throws SQLException { return 0; } @Override public SQLWarning getWarnings() throws SQLException { return null; } @Override public void clearWarnings() throws SQLException { } @Override public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException { return null; } @Override public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { return null; } @Override public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { return null; } @Override public Map<String, Class<?>> getTypeMap() throws SQLException { return null; } @Override public void setTypeMap(Map<String, Class<?>> map) throws SQLException { } @Override public void setHoldability(int holdability) throws SQLException { } @Override public int getHoldability() throws SQLException { return 0; } @Override public Savepoint setSavepoint() throws SQLException { return null; } @Override public Savepoint setSavepoint(String name) throws SQLException { return null; } @Override public void rollback(Savepoint savepoint) throws SQLException { } @Override public void releaseSavepoint(Savepoint savepoint) throws SQLException { } @Override public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { return null; } @Override public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { return null; } @Override public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { return null; } @Override public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException { return null; } @Override public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException { return null; } @Override public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException { return null; } @Override public Clob createClob() throws SQLException { return null; } @Override public Blob createBlob() throws SQLException { return null; } @Override public NClob createNClob() throws SQLException { return null; } @Override public SQLXML createSQLXML() throws SQLException { return null; } @Override public boolean isValid(int timeout) throws SQLException { return false; } @Override public void setClientInfo(String name, String value) throws SQLClientInfoException { } @Override public void setClientInfo(Properties properties) throws SQLClientInfoException { } @Override public String getClientInfo(String name) throws SQLException { return null; } @Override public Properties getClientInfo() throws SQLException { return null; } @Override public Array createArrayOf(String typeName, Object[] elements) throws SQLException { return null; } @Override public Struct createStruct(String typeName, Object[] attributes) throws SQLException { return null; } @Override public void setSchema(String schema) throws SQLException { } @Override public String getSchema() throws SQLException { return null; } @Override public void abort(Executor executor) throws SQLException { } @Override public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException { } @Override public int getNetworkTimeout() throws SQLException { return 0; } @Override public <T> T unwrap(Class<T> iface) throws SQLException { return null; } @Override public boolean isWrapperFor(Class<?> iface) throws SQLException { return false; } } }
9,689
24.978552
154
java