From a132ec13d1b586cab92a7723aac932a9226f1a27 Mon Sep 17 00:00:00 2001 From: Matej Novotny Date: Mon, 17 Jul 2017 13:04:20 +0200 Subject: [PATCH] WELD-2402 Add automated test for sealed package proxy creation. --- .../tests/proxy/sealed/NotSealedBean.java | 38 ++++++++++ .../ProxyCreationInSealedPackageTest.java | 72 +++++++++++++++++++ .../sealed/library/PackagePrivateStorage.java | 31 ++++++++ .../proxy/sealed/library/SealedBean.java | 36 ++++++++++ 4 files changed, 177 insertions(+) create mode 100644 tests-arquillian/src/test/java/org/jboss/weld/tests/proxy/sealed/NotSealedBean.java create mode 100644 tests-arquillian/src/test/java/org/jboss/weld/tests/proxy/sealed/ProxyCreationInSealedPackageTest.java create mode 100644 tests-arquillian/src/test/java/org/jboss/weld/tests/proxy/sealed/library/PackagePrivateStorage.java create mode 100644 tests-arquillian/src/test/java/org/jboss/weld/tests/proxy/sealed/library/SealedBean.java diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/proxy/sealed/NotSealedBean.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/proxy/sealed/NotSealedBean.java new file mode 100644 index 00000000000..4e7261047a9 --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/proxy/sealed/NotSealedBean.java @@ -0,0 +1,38 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2017, 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.weld.tests.proxy.sealed; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; + +import org.jboss.weld.tests.proxy.sealed.library.SealedBean; + +/** + * A bean inside WAR deployment, not sealed. + * + * @author Matej Novotny + */ +@ApplicationScoped +public class NotSealedBean { + + @Inject + SealedBean bean; + + public void ping() { + bean.ping(); + } +} diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/proxy/sealed/ProxyCreationInSealedPackageTest.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/proxy/sealed/ProxyCreationInSealedPackageTest.java new file mode 100644 index 00000000000..4c61bcd2d46 --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/proxy/sealed/ProxyCreationInSealedPackageTest.java @@ -0,0 +1,72 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2017, 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.weld.tests.proxy.sealed; + +import javax.inject.Inject; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.BeanArchive; +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.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.weld.test.util.Utils; +import org.jboss.weld.tests.category.Integration; +import org.jboss.weld.tests.proxy.sealed.library.SealedBean; +import org.junit.Assert; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +/** + * + * @author Matej Novotny + */ +@RunWith(Arquillian.class) +@Category(Integration.class) +public class ProxyCreationInSealedPackageTest { + + @Deployment + public static WebArchive deploy() { + + // JAR contains SealedBean class in sealed package + JavaArchive jar = ShrinkWrap.create(BeanArchive.class, "sealed.jar").addPackage(SealedBean.class.getPackage()) + .addAsManifestResource(new StringAsset("Manifest-Version: 1.0\n" + + "\n" + + "Name: org/jboss/weld/tests/proxy/sealed/library/\n" + + "Sealed: true\n"), "MANIFEST.MF"); + + // WAR contains this test class and ordinary bean class + return ShrinkWrap.create(WebArchive.class, Utils.getDeploymentNameAsHash(ProxyCreationInSealedPackageTest.class, Utils.ARCHIVE_TYPE.WAR)) + .addPackage(ProxyCreationInSealedPackageTest.class.getPackage()) + .addAsLibraries(jar) + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + @Inject + NotSealedBean bean; + + @Test + public void testProxyCreationWithSealedJar() { + // assert that the package is sealed + Assert.assertTrue(SealedBean.class.getPackage().isSealed()); + // invoke any method to make sure we create proxy + bean.ping(); + } +} diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/proxy/sealed/library/PackagePrivateStorage.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/proxy/sealed/library/PackagePrivateStorage.java new file mode 100644 index 00000000000..e2021dee169 --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/proxy/sealed/library/PackagePrivateStorage.java @@ -0,0 +1,31 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2017, 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.weld.tests.proxy.sealed.library; + +import javax.enterprise.context.ApplicationScoped; + +/** + * + * @author Matej Novotny + */ +@ApplicationScoped +class PackagePrivateStorage { + + String getPackagePrivateInfo() { + return "Hush! Don't say this in public!"; + } +} diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/proxy/sealed/library/SealedBean.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/proxy/sealed/library/SealedBean.java new file mode 100644 index 00000000000..642ce2aa75a --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/proxy/sealed/library/SealedBean.java @@ -0,0 +1,36 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2017, 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.weld.tests.proxy.sealed.library; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; + +/** + * This class is a part of the sealed JAR and is a CDI bean + * + * @author Matej Novotny + */ +@ApplicationScoped +public class SealedBean { + + @Inject + PackagePrivateStorage packPrivate; + + public void ping() { + packPrivate.getPackagePrivateInfo(); + } +}