1 17 18 package org.apache.geronimo.deployment.tools; 19 20 import java.net.URL ; 21 import java.util.Arrays ; 22 import java.util.Enumeration ; 23 import java.io.FileNotFoundException ; 24 import java.io.InputStream ; 25 import javax.enterprise.deploy.model.DDBean ; 26 import javax.enterprise.deploy.model.DDBeanRoot ; 27 import javax.enterprise.deploy.model.DeployableObject ; 28 import javax.enterprise.deploy.model.exceptions.DDBeanCreateException; 29 import javax.enterprise.deploy.shared.ModuleType ; 30 31 import junit.framework.TestCase; 32 33 38 public class DDBeanRootTest extends TestCase { 39 private DDBeanRoot root; 40 private ClassLoader classLoader; 41 42 public void testRoot() throws Exception { 43 DeployableObject deployable = new MockDeployable(); 44 URL descriptor = classLoader.getResource("descriptors/app-client1.xml"); 45 root = new DDBeanRootImpl(deployable, descriptor); 46 assertEquals("1.4", root.getDDBeanRootVersion()); 47 assertEquals(deployable, root.getDeployableObject()); 48 assertEquals(ModuleType.CAR, root.getType()); 49 assertEquals("/", root.getXpath()); 50 assertNull(root.getText("foo")); 51 assertTrue(Arrays.equals(new String [] {"Test DD for app-client1"}, root.getText("application-client/description"))); 52 assertTrue(Arrays.equals(new String [] {"http://localhost"}, root.getText("application-client/env-entry/env-entry-value"))); 53 assertTrue(Arrays.equals(new String [] {"url/test1", "url/test2"}, root.getText("application-client/env-entry/env-entry-name"))); 54 55 DDBean description = root.getChildBean("application-client/description")[0]; 56 assertEquals("Test DD for app-client1", description.getText()); 57 assertEquals("application-client/description", description.getXpath()); 58 assertEquals(description, description.getChildBean("/application-client/description")[0]); 59 } 60 61 protected void setUp() throws Exception { 62 classLoader = Thread.currentThread().getContextClassLoader(); 63 } 64 65 private class MockDeployable implements DeployableObject { 66 public Enumeration entries() { 67 fail(); 68 throw new AssertionError (); 69 } 70 71 public DDBean [] getChildBean(String xpath) { 72 fail(); 73 throw new AssertionError (); 74 } 75 76 public Class getClassFromScope(String className) { 77 fail(); 78 throw new AssertionError (); 79 } 80 81 public DDBeanRoot getDDBeanRoot() { 82 fail(); 83 throw new AssertionError (); 84 } 85 86 public DDBeanRoot getDDBeanRoot(String filename) throws FileNotFoundException , DDBeanCreateException { 87 fail(); 88 throw new AssertionError (); 89 } 90 91 public InputStream getEntry(String name) { 92 fail(); 93 throw new AssertionError (); 94 } 95 96 public String getModuleDTDVersion() { 97 fail(); 98 throw new AssertionError (); 99 } 100 101 public String [] getText(String xpath) { 102 fail(); 103 throw new AssertionError (); 104 } 105 106 public ModuleType getType() { 107 return ModuleType.CAR; 108 } 109 } 110 } 111 | Popular Tags |