1 25 26 package org.objectweb.easybeans.tests.deploymentdesc; 27 28 import static org.objectweb.easybeans.util.url.URLUtils.fileToURL2; 29 import static org.testng.Assert.assertEquals; 30 import static org.testng.Assert.assertNotNull; 31 import static org.testng.Assert.assertTrue; 32 33 import java.io.File ; 34 import java.net.URL ; 35 import java.util.List ; 36 37 import org.objectweb.easybeans.deployment.xml.parsing.EJB3DeploymentDescLoader; 38 import org.objectweb.easybeans.deployment.xml.parsing.ParsingException; 39 import org.objectweb.easybeans.deployment.xml.struct.EJB3; 40 import org.objectweb.easybeans.deployment.xml.struct.EnterpriseBeans; 41 import org.objectweb.easybeans.deployment.xml.struct.Session; 42 import org.objectweb.easybeans.deployment.xml.struct.common.EnvEntry; 43 import org.objectweb.easybeans.util.url.URLUtilsException; 44 import org.objectweb.easybeans.util.xml.DocumentParserException; 45 import org.testng.annotations.Test; 46 import org.xml.sax.SAXException ; 47 48 52 public class TestLoading { 53 54 57 private static final String PREFIX = TestLoading.class.getPackage().getName().replace(".", "/") + "/xmls/"; 58 59 62 private static final String TEST_DIR_PREFIX = "tests/src/java/"; 63 64 70 private static URL getURL(final String fileName) throws ParsingException { 71 URL url = TestLoading.class.getResource(PREFIX + fileName); 72 if (url == null) { 73 File file = new File (TEST_DIR_PREFIX + PREFIX + fileName); 75 if (file.exists()) { 76 try { 77 return fileToURL2(file); 78 } catch (URLUtilsException e) { 79 throw new ParsingException("Cannot transform file into url", e); 80 } 81 } 82 } 83 if (url == null) { 84 throw new ParsingException("URl for '" + fileName + "' was not found."); 85 } 86 return url; 87 } 88 89 95 private EJB3 getEjb3(final String fileName) throws ParsingException { 96 URL urlEjb01 = getURL(fileName); 97 98 return EJB3DeploymentDescLoader.loadDeploymentDescriptor(urlEjb01); 99 100 } 101 102 106 @Test 107 public void analyzeParsedXml() throws ParsingException { 108 EJB3 ejb3 = getEjb3("ejb-jar01.xml"); 109 110 EnterpriseBeans enterpriseBeans = ejb3.getEnterpriseBeans(); 112 assertNotNull(enterpriseBeans); 113 114 List <Session> sessionList = enterpriseBeans.getSessionList(); 116 assertNotNull(sessionList); 117 assertTrue(sessionList.size() > 0); 118 119 Session testBean = sessionList.get(0); 121 assertNotNull(testBean); 122 assertEquals("TestBean", testBean.getEjbName()); 123 124 List <EnvEntry> envEntries = testBean.getEnvEntryList(); 126 assertNotNull(envEntries); 128 assertTrue(envEntries.size() > 0); 129 130 EnvEntry envEntry = envEntries.get(0); 131 assertEquals("testBoolean", envEntry.getEnvEntryName()); 132 assertEquals("java.lang.Boolean", envEntry.getEnvEntryType()); 133 assertEquals("false", envEntry.getEnvEntryValue()); 134 135 } 136 137 140 @Test 141 public void error01() { 142 try { 144 getEjb3("ejb-jar-error01.xml"); 145 assert false; 146 } catch (ParsingException e) { 147 Throwable t = e.getCause(); 148 assertTrue(t instanceof DocumentParserException); 149 DocumentParserException dpe = (DocumentParserException) t; 150 Throwable tt = dpe.getCause(); 151 assertTrue(tt instanceof SAXException ); 152 SAXException se = (SAXException ) tt; 153 assertTrue(se.getMessage().contains("The content of element 'session' is not complete")); 155 } 156 157 } 158 159 } 160 | Popular Tags |