PageRenderTime 34ms CodeModel.GetById 18ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/jboss-as-7.1.1.Final/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/classloading/transformer/WarJbossStructureClassFileTransformerTestCase.java

#
Java | 84 lines | 49 code | 11 blank | 24 comment | 2 complexity | 4ce86c5c59dfa902f9b95e7f95899a45 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
 1/*
 2 * JBoss, Home of Professional Open Source
 3 * Copyright 2011, Red Hat Inc., and individual contributors as indicated
 4 * by the @authors tag. See the copyright.txt in the distribution for a
 5 * full listing of individual contributors.
 6 *
 7 * This is free software; you can redistribute it and/or modify it
 8 * under the terms of the GNU Lesser General Public License as
 9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */
22
23package org.jboss.as.test.integration.deployment.classloading.transformer;
24
25import org.jboss.arquillian.container.test.api.Deployment;
26import org.jboss.arquillian.junit.Arquillian;
27import org.jboss.as.test.integration.deployment.classloading.ear.TestAA;
28import org.jboss.shrinkwrap.api.Archive;
29import org.jboss.shrinkwrap.api.ShrinkWrap;
30import org.jboss.shrinkwrap.api.asset.StringAsset;
31
32import org.jboss.shrinkwrap.api.spec.WebArchive;
33import org.junit.Assert;
34import org.junit.Test;
35import org.junit.runner.RunWith;
36
37/**
38 * @author Marius Bogoevici
39 */
40@RunWith(Arquillian.class)
41public class WarJbossStructureClassFileTransformerTestCase {
42
43    public static final String CLASS_NAME = "org.jboss.as.test.integration.deployment.classloading.ear.TestAA";
44
45    public static final String TRANSFORMER1_CLASS_NAME_CANONICAL = "org/jboss/as/testsuite/integration/deployment/classloading/ear/DummyClassFileTransformer1";
46
47    public static final String TRANSFORMER2_CLASS_NAME_CANONICAL = "org/jboss/as/testsuite/integration/deployment/classloading/ear/DummyClassFileTransformer2";
48
49    @Deployment
50    public static Archive<?> deploy() {
51        WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war");
52        war.addClasses(TestAA.class, DummyClassFileTransformer1.class, DummyClassFileTransformer2.class, WarJbossStructureClassFileTransformerTestCase.class);
53
54        war.addAsManifestResource(new StringAsset(
55                "<jboss-deployment-structure xmlns=\"urn:jboss:deployment-structure:1.0\">\n" +
56                        "  <deployment>\n" +
57                        "     <transformers>\n" +
58                        "         <transformer class=\"" + DummyClassFileTransformer1.class.getName() + "\"/>\n" +
59                        "         <transformer class=\"" + DummyClassFileTransformer2.class.getName() + "\"/>\n" +
60                        "     </transformers>\n" +
61                        "  </deployment>\n" +
62                        "</jboss-deployment-structure>"), "jboss-deployment-structure.xml");
63        return war;
64    }
65
66    @Test
67    public void testTransformerApplied() throws ClassNotFoundException {
68        loadClass(CLASS_NAME, getClass().getClassLoader());
69        Assert.assertTrue(DummyClassFileTransformer1.wasActive);
70        Assert.assertTrue(DummyClassFileTransformer2.wasActive);
71        String canonicalClassName = CLASS_NAME.replace(".", "/");
72        Assert.assertTrue(DummyClassFileTransformer1.transformedClassNames.contains(canonicalClassName));
73        Assert.assertTrue(DummyClassFileTransformer2.transformedClassNames.contains(canonicalClassName));
74        Assert.assertFalse(DummyClassFileTransformer1.transformedClassNames.contains(TRANSFORMER2_CLASS_NAME_CANONICAL));
75        Assert.assertFalse(DummyClassFileTransformer2.transformedClassNames.contains(TRANSFORMER1_CLASS_NAME_CANONICAL));
76    }
77
78    private static Class<?> loadClass(String name, ClassLoader cl) throws ClassNotFoundException {
79        if (cl != null) {
80            return Class.forName(name, false, cl);
81        } else
82            return Class.forName(name);
83    }
84}