PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms 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. package org.jboss.as.test.integration.deployment.classloading.transformer;
  23. import org.jboss.arquillian.container.test.api.Deployment;
  24. import org.jboss.arquillian.junit.Arquillian;
  25. import org.jboss.as.test.integration.deployment.classloading.ear.TestAA;
  26. import org.jboss.shrinkwrap.api.Archive;
  27. import org.jboss.shrinkwrap.api.ShrinkWrap;
  28. import org.jboss.shrinkwrap.api.asset.StringAsset;
  29. import org.jboss.shrinkwrap.api.spec.WebArchive;
  30. import org.junit.Assert;
  31. import org.junit.Test;
  32. import org.junit.runner.RunWith;
  33. /**
  34. * @author Marius Bogoevici
  35. */
  36. @RunWith(Arquillian.class)
  37. public class WarJbossStructureClassFileTransformerTestCase {
  38. public static final String CLASS_NAME = "org.jboss.as.test.integration.deployment.classloading.ear.TestAA";
  39. public static final String TRANSFORMER1_CLASS_NAME_CANONICAL = "org/jboss/as/testsuite/integration/deployment/classloading/ear/DummyClassFileTransformer1";
  40. public static final String TRANSFORMER2_CLASS_NAME_CANONICAL = "org/jboss/as/testsuite/integration/deployment/classloading/ear/DummyClassFileTransformer2";
  41. @Deployment
  42. public static Archive<?> deploy() {
  43. WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war");
  44. war.addClasses(TestAA.class, DummyClassFileTransformer1.class, DummyClassFileTransformer2.class, WarJbossStructureClassFileTransformerTestCase.class);
  45. war.addAsManifestResource(new StringAsset(
  46. "<jboss-deployment-structure xmlns=\"urn:jboss:deployment-structure:1.0\">\n" +
  47. " <deployment>\n" +
  48. " <transformers>\n" +
  49. " <transformer class=\"" + DummyClassFileTransformer1.class.getName() + "\"/>\n" +
  50. " <transformer class=\"" + DummyClassFileTransformer2.class.getName() + "\"/>\n" +
  51. " </transformers>\n" +
  52. " </deployment>\n" +
  53. "</jboss-deployment-structure>"), "jboss-deployment-structure.xml");
  54. return war;
  55. }
  56. @Test
  57. public void testTransformerApplied() throws ClassNotFoundException {
  58. loadClass(CLASS_NAME, getClass().getClassLoader());
  59. Assert.assertTrue(DummyClassFileTransformer1.wasActive);
  60. Assert.assertTrue(DummyClassFileTransformer2.wasActive);
  61. String canonicalClassName = CLASS_NAME.replace(".", "/");
  62. Assert.assertTrue(DummyClassFileTransformer1.transformedClassNames.contains(canonicalClassName));
  63. Assert.assertTrue(DummyClassFileTransformer2.transformedClassNames.contains(canonicalClassName));
  64. Assert.assertFalse(DummyClassFileTransformer1.transformedClassNames.contains(TRANSFORMER2_CLASS_NAME_CANONICAL));
  65. Assert.assertFalse(DummyClassFileTransformer2.transformedClassNames.contains(TRANSFORMER1_CLASS_NAME_CANONICAL));
  66. }
  67. private static Class<?> loadClass(String name, ClassLoader cl) throws ClassNotFoundException {
  68. if (cl != null) {
  69. return Class.forName(name, false, cl);
  70. } else
  71. return Class.forName(name);
  72. }
  73. }