incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From timothyjw...@apache.org
Subject svn commit: r896592 - /incubator/aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/parsing/PersistenceXMLParsingTest.java
Date Wed, 06 Jan 2010 18:16:49 GMT
Author: timothyjward
Date: Wed Jan  6 18:16:47 2010
New Revision: 896592

URL: http://svn.apache.org/viewvc?rev=896592&view=rev
Log:
ARIES-80: Add parsing logic for persistence units

Modified:
    incubator/aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/parsing/PersistenceXMLParsingTest.java

Modified: incubator/aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/parsing/PersistenceXMLParsingTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/parsing/PersistenceXMLParsingTest.java?rev=896592&r1=896591&r2=896592&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/parsing/PersistenceXMLParsingTest.java
(original)
+++ incubator/aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/parsing/PersistenceXMLParsingTest.java
Wed Jan  6 18:16:47 2010
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package com.ibm.osgi.jpa.unit.manager.test;
+package org.apache.aries.jpa.container.parsing;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -26,250 +26,170 @@
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import java.io.File;
+import java.io.FileInputStream;
 import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
-import java.util.Hashtable;
 import java.util.List;
 import java.util.Properties;
 
-import javax.persistence.spi.PersistenceUnitTransactionType;
-import javax.xml.XMLConstants;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
-
-import mocks.BundleContextMock;
-import mocks.BundleMock;
-
-import org.junit.After;
-import org.junit.Before;
+import org.apache.aries.jpa.container.impl.PersistenceDescriptor;
+import org.apache.aries.unittest.mocks.Skeleton;
 import org.junit.Test;
 import org.osgi.framework.Bundle;
-import org.osgi.service.jpa.PersistenceUnitInfoService;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-
-import com.ibm.aries.unittest.mocks.Skeleton;
-import com.ibm.osgi.jpa.unit.parsing.JPAHandler;
-import com.ibm.osgi.jpa.util.PersistenceLocationData;
-
 
 public class PersistenceXMLParsingTest
 {
 
-  private Bundle persistenceBundle;
-  private SAXParser parser;
-  
-  @Before
-  public void init() throws MalformedURLException, SAXException, ParserConfigurationException
-  {
-    
-    persistenceBundle = Skeleton.newMock(new BundleMock("scooby.doo", new Hashtable<String,
Object>()), Bundle.class);
-    
-    Skeleton skel = Skeleton.getSkeleton(persistenceBundle);
-    
-    SAXParserFactory parserFactory = SAXParserFactory.newInstance();
-
-    SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
-
-    Schema s = schemaFactory.newSchema(new URL("http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"));
-
-    parserFactory.setSchema(s);
-    parserFactory.setNamespaceAware(true);
-
-    parser = parserFactory.newSAXParser();
-
-  }
-  
-  @After
-  public void destroy()
-  {
-    BundleContextMock.clear();
-  }
-  
+  /**
+   * Test parsing a persistence descriptor with several entries
+   * @throws Exception
+   */
   @Test
   public void testFile1() throws Exception
   {
     InputStream is = null;
-    
     try {
+      String location = "src/test/resources/file1/META-INF/persistence.xml";
+      is = new FileInputStream(location);
+      PersistenceDescriptor descriptor = new PersistenceDescriptor(location, is);
       
-      URL xml = new File("unittest/resources/file1/META-INF/persistence.xml").toURI().toURL();
-      is = xml.openStream();
+      Collection<PersistenceDescriptor> descriptors = new ArrayList<PersistenceDescriptor>();
+      descriptors.add(descriptor);
       
-      URL root = new File("unittest/resources/file1").toURI().toURL();
-    
-      JPAHandler handler = new JPAHandler(new PersistenceLocationData(xml, root, persistenceBundle),
"1.0");
-      parser.parse(is, handler);
+      Bundle b = Skeleton.newMock(Bundle.class);
       
-      Collection<? extends PersistenceUnitInfoService> puinfos = handler.getPersistenceUnits();
-      assertEquals("An incorrect number of persistence units has been returned.", 4, puinfos.size());
+      Collection<ParsedPersistenceUnit> parsedUnits = PersistenceDescriptorParser.parse(b,
descriptors);
+      assertEquals("An incorrect number of persistence units has been returned.", 4, parsedUnits.size());
       
-      List<PersistenceUnitInfoService> units = getList(puinfos);
+      List<ParsedPersistenceUnit> units = getList(parsedUnits);
       
-      PersistenceUnitInfoService unit = units.get(0);
+      ParsedPersistenceUnit unit = units.get(0);
       
       assertEquals("The schema version was incorrect", "1.0",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.SCHEMA_VERSION));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.SCHEMA_VERSION));
       assertEquals("The unit name was incorrect", "alpha",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.UNIT_NAME));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.UNIT_NAME));
       assertNull("The transaction type was incorrect",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.TRANSACTION_TYPE));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.TRANSACTION_TYPE));
       assertNull("The provider class name was incorrect",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.PROVIDER_CLASSNAME));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.PROVIDER_CLASSNAME));
       assertNull("The jta datasource jndi name was wrong",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.JTA_DATASOURCE));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.JTA_DATASOURCE));
       assertNull("The non jta datasource jndi name was wrong",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.NON_JTA_DATASOURCE));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.NON_JTA_DATASOURCE));
       assertNull("One or more mapping files were specified",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.MAPPING_FILES));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.MAPPING_FILES));
       assertNull("One or more jar files were specified",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.JAR_FILES));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.JAR_FILES));
       assertNull("One or more managed classes were specified",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.MANAGED_CLASSES));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.MANAGED_CLASSES));
       assertNull("We should not exclude any classes",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.EXCLUDE_UNLISTED_CLASSES));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.EXCLUDE_UNLISTED_CLASSES));
       assertNull("The properties should never be null",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.PROPERTIES));
-      assertNotNull("The persistence.xml location was not specified", unit.getPersistenceXmlLocation());
-      assertEquals("The persistence.xml location points at the wrong file",
-          new File("unittest/resources/file1/META-INF/persistence.xml").toURI().toURL().toExternalForm(),
-          unit.getPersistenceXmlLocation().toExternalForm());
-      assertNotNull("The persistence root location was not specified", unit.getPersistenceUnitRoot());
-      assertEquals("The persistence root points at the wrong place",
-          new File("unittest/resources/file1").toURI().toURL().toExternalForm(),
-          unit.getPersistenceUnitRoot().toExternalForm());
-      assertSame("The persistence unit was associated with the wrong bundle", persistenceBundle,
unit.getDefiningBundle());
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.PROPERTIES));
+      assertSame("The persistence unit was associated with the wrong bundle", b, unit.getDefiningBundle());
       
 
       unit = units.get(1);
       
       assertEquals("The schema version was incorrect", "1.0",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.SCHEMA_VERSION));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.SCHEMA_VERSION));
       assertEquals("The unit name was incorrect", "bravo",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.UNIT_NAME));
-      assertEquals("The transaction type was incorrect", PersistenceUnitTransactionType.JTA,
-          PersistenceUnitTransactionType.valueOf((String)unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.TRANSACTION_TYPE)));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.UNIT_NAME));
+      assertEquals("The transaction type was incorrect", "JTA",
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.TRANSACTION_TYPE));
       assertEquals("The provider class name was incorrect", "bravo.persistence.provider",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.PROVIDER_CLASSNAME));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.PROVIDER_CLASSNAME));
       assertEquals("The jta datasource jndi name was wrong", "bravo/jtaDS",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.JTA_DATASOURCE));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.JTA_DATASOURCE));
       assertEquals("The non jta datasource jndi name was wrong", "bravo/nonJtaDS",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.NON_JTA_DATASOURCE));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.NON_JTA_DATASOURCE));
       assertEquals("An incorrect number of mapping files were specified", 2,
-          ((Collection)unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.MAPPING_FILES)).size());
+          ((Collection)unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.MAPPING_FILES)).size());
       assertTrue("Incorrect mapping files were listed",
-          ((Collection)unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.MAPPING_FILES)).contains("bravoMappingFile1.xml")
-          && ((Collection)unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.MAPPING_FILES)).contains("bravoMappingFile2.xml"));
+          ((Collection)unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.MAPPING_FILES)).contains("bravoMappingFile1.xml")
+          && ((Collection)unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.MAPPING_FILES)).contains("bravoMappingFile2.xml"));
       assertEquals("An incorrect number of jar files were specified", 2,
-          ((Collection)unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.JAR_FILES)).size());
-      assertTrue("Incorrect jar URLs were listed", checkJARURLs((Collection<String>)unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.JAR_FILES)));
+          ((Collection)unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.JAR_FILES)).size());
+      assertTrue("Incorrect jar URLs were listed", checkJARURLs((Collection<String>)unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.JAR_FILES)));
           
       assertEquals("An incorrect number of managed classes were specified", 2,
-          ((Collection)unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.MANAGED_CLASSES)).size());
+          ((Collection)unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.MANAGED_CLASSES)).size());
       assertTrue("Incorrect managed classes were listed",
-          ((Collection)unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.MANAGED_CLASSES)).contains("bravoClass1")
-          && ((Collection)unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.MANAGED_CLASSES)).contains("bravoClass2"));
+          ((Collection)unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.MANAGED_CLASSES)).contains("bravoClass1")
+          && ((Collection)unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.MANAGED_CLASSES)).contains("bravoClass2"));
       
       //In the schema this defaults to false. There is a separate test (testFile1b)
       //for the spec behaviour, which defaults to true
       assertFalse("We should exclude any classes not listed",
-          (Boolean)unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.EXCLUDE_UNLISTED_CLASSES));
+          (Boolean)unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.EXCLUDE_UNLISTED_CLASSES));
       assertNotNull("The properties should never be null",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.PROPERTIES));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.PROPERTIES));
       assertEquals("The wrong number of properties were specified", 2,
-          ((Properties)unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.PROPERTIES)).size());
+          ((Properties)unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.PROPERTIES)).size());
       assertEquals("The property had the wrong value", "prop.value",
-          ((Properties)unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.PROPERTIES)).getProperty("some.prop"));
+          ((Properties)unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.PROPERTIES)).getProperty("some.prop"));
       assertEquals("The property had the wrong value", "another.prop.value",
-          ((Properties)unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.PROPERTIES)).getProperty("some.other.prop"));
-      assertNotNull("The persistence.xml location was not specified", unit.getPersistenceXmlLocation());
-      assertEquals("The persistence.xml location points at the wrong file",
-          new File("unittest/resources/file1/META-INF/persistence.xml").toURI().toURL().toExternalForm(),
-          unit.getPersistenceXmlLocation().toExternalForm());
-      assertNotNull("The persistence root location was not specified", unit.getPersistenceUnitRoot());
-      assertEquals("The persistence root points at the wrong place",
-          new File("unittest/resources/file1").toURI().toURL().toExternalForm(),
-          unit.getPersistenceUnitRoot().toExternalForm());
-      assertSame("The persistence unit was associated with the wrong bundle", persistenceBundle,
unit.getDefiningBundle());
+          ((Properties)unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.PROPERTIES)).getProperty("some.other.prop"));
+      assertSame("The persistence unit was associated with the wrong bundle", b, unit.getDefiningBundle());
       
       
       unit = units.get(2);
       
       assertEquals("The schema version was incorrect", "1.0",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.SCHEMA_VERSION));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.SCHEMA_VERSION));
       assertEquals("The unit name was incorrect", "charlie",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.UNIT_NAME));
-      assertEquals("The transaction type was incorrect", PersistenceUnitTransactionType.RESOURCE_LOCAL,
-          PersistenceUnitTransactionType.valueOf((String)unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.TRANSACTION_TYPE)));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.UNIT_NAME));
+      assertEquals("The transaction type was incorrect", "RESOURCE_LOCAL",
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.TRANSACTION_TYPE));
       assertEquals("The provider class name was incorrect", "charlie.persistence.provider",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.PROVIDER_CLASSNAME));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.PROVIDER_CLASSNAME));
       assertNull("The jta datasource jndi name was wrong",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.JTA_DATASOURCE));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.JTA_DATASOURCE));
       assertNull("The non jta datasource jndi name was wrong",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.NON_JTA_DATASOURCE));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.NON_JTA_DATASOURCE));
       assertNull("One or more mapping files were specified",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.MAPPING_FILES));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.MAPPING_FILES));
       assertNull("One or more jar files were specified",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.JAR_FILES));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.JAR_FILES));
       assertNull("One or more managed classes were specified",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.MANAGED_CLASSES));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.MANAGED_CLASSES));
       assertTrue("We should not exclude any classes",
-          (Boolean)unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.EXCLUDE_UNLISTED_CLASSES));
-     assertNull("The properties should never be null",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.PROPERTIES));
-      assertNotNull("The persistence.xml location was not specified", unit.getPersistenceXmlLocation());
-      assertEquals("The persistence.xml location points at the wrong file",
-          new File("unittest/resources/file1/META-INF/persistence.xml").toURI().toURL().toExternalForm(),
-          unit.getPersistenceXmlLocation().toExternalForm());
-      assertNotNull("The persistence root location was not specified", unit.getPersistenceUnitRoot());
-      assertEquals("The persistence root points at the wrong place",
-          new File("unittest/resources/file1").toURI().toURL().toExternalForm(),
-          unit.getPersistenceUnitRoot().toExternalForm());
-      assertSame("The persistence unit was associated with the wrong bundle", persistenceBundle,
unit.getDefiningBundle());
+          (Boolean)unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.EXCLUDE_UNLISTED_CLASSES));
+      assertNull("The properties should never be null",
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.PROPERTIES));
+
+      assertSame("The persistence unit was associated with the wrong bundle", b, unit.getDefiningBundle());
       
       
       unit = units.get(3);
       
       assertEquals("The schema version was incorrect", "1.0",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.SCHEMA_VERSION));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.SCHEMA_VERSION));
       assertEquals("The unit name was incorrect", "delta",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.UNIT_NAME));
-      assertEquals("The transaction type was incorrect", PersistenceUnitTransactionType.RESOURCE_LOCAL,
-          PersistenceUnitTransactionType.valueOf((String)unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.TRANSACTION_TYPE)));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.UNIT_NAME));
+      assertEquals("The transaction type was incorrect", "RESOURCE_LOCAL",
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.TRANSACTION_TYPE));
       assertEquals("The provider class name was incorrect", "delta.persistence.provider",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.PROVIDER_CLASSNAME));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.PROVIDER_CLASSNAME));
       assertNull("The jta datasource jndi name was wrong",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.JTA_DATASOURCE));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.JTA_DATASOURCE));
       assertNull("The non jta datasource jndi name was wrong",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.NON_JTA_DATASOURCE));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.NON_JTA_DATASOURCE));
       assertNull("One or more mapping files were specified",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.MAPPING_FILES));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.MAPPING_FILES));
       assertNull("One or more jar files were specified",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.JAR_FILES));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.JAR_FILES));
       assertNull("One or more managed classes were specified",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.MANAGED_CLASSES));
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.MANAGED_CLASSES));
       assertFalse("We should not exclude any classes",
-          (Boolean)unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.EXCLUDE_UNLISTED_CLASSES));
+          (Boolean)unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.EXCLUDE_UNLISTED_CLASSES));
       assertNull("The properties should never be null",
-          unit.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.PROPERTIES));
-      assertNotNull("The persistence.xml location was not specified", unit.getPersistenceXmlLocation());
-      assertEquals("The persistence.xml location points at the wrong file",
-          new File("unittest/resources/file1/META-INF/persistence.xml").toURI().toURL().toExternalForm(),
-          unit.getPersistenceXmlLocation().toExternalForm());
-      assertNotNull("The persistence root location was not specified", unit.getPersistenceUnitRoot());
-      assertEquals("The persistence root points at the wrong place",
-          new File("unittest/resources/file1").toURI().toURL().toExternalForm(),
-          unit.getPersistenceUnitRoot().toExternalForm());
-      assertSame("The persistence unit was associated with the wrong bundle", persistenceBundle,
unit.getDefiningBundle());
+          unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.PROPERTIES));
+      assertSame("The persistence unit was associated with the wrong bundle", b, unit.getDefiningBundle());
 
     } finally {
       
@@ -285,35 +205,39 @@
     InputStream is = null;
 
     try {
-      URL xml = new File("unittest/resources/file2/META-INF/persistence.xml").toURI().toURL();
-      is = xml.openStream();
+      String location = "src/test/resources/file2/META-INF/persistence.xml";
+      is = new FileInputStream(location);
+      PersistenceDescriptor descriptor = new PersistenceDescriptor(location, is);
       
-      URL root = new File("unittest/resources/file2").toURI().toURL();
-    
-      JPAHandler handler = new JPAHandler(new PersistenceLocationData(xml, root, persistenceBundle),
"1.0");
-      parser.parse(is, handler);
+      Collection<PersistenceDescriptor> descriptors = new ArrayList<PersistenceDescriptor>();
+      descriptors.add(descriptor);
+      
+      Bundle b = Skeleton.newMock(Bundle.class);
       
-      Collection<? extends PersistenceUnitInfoService> puinfos = handler.getPersistenceUnits();
-      assertEquals("An incorrect number of persistence units has been returned.", 0, puinfos.size());
+      Collection<ParsedPersistenceUnit> parsedUnits = PersistenceDescriptorParser.parse(b,
descriptors);
+      assertEquals("An incorrect number of persistence units has been returned.", 0, parsedUnits.size());
     } finally {
       if(is != null)
         is.close();
     }
   }
   
-  @Test(expected=SAXParseException.class)
+  @Test(expected=PersistenceDescriptorParserException.class)
   public void testFile3() throws Exception
   {
     InputStream is = null;
 
     try {
-      URL xml = new File("unittest/resources/file3/META-INF/persistence.xml").toURI().toURL();
-      is = xml.openStream();
+      String location = "src/test/resources/file3/META-INF/persistence.xml";
+      is = new FileInputStream(location);
+      PersistenceDescriptor descriptor = new PersistenceDescriptor(location, is);
       
-      URL root = new File("unittest/resources/file3").toURI().toURL();
-    
-      JPAHandler handler = new JPAHandler(new PersistenceLocationData(xml, root, persistenceBundle),
"1.0");
-      parser.parse(is, handler);
+      Collection<PersistenceDescriptor> descriptors = new ArrayList<PersistenceDescriptor>();
+      descriptors.add(descriptor);
+      
+      Bundle b = Skeleton.newMock(Bundle.class);
+      
+      Collection<ParsedPersistenceUnit> parsedUnits = PersistenceDescriptorParser.parse(b,
descriptors);
 
       fail("Parsing should not succeed");
     } finally {
@@ -322,18 +246,23 @@
     }
   }
 
-  private static List<PersistenceUnitInfoService> getList(Collection<? extends PersistenceUnitInfoService>
puinfos)
+  /**
+   * Sort a Collection of ParsedPersistenceUnit into alphabetical order (by unit name)
+   * @param puinfos
+   * @return
+   */
+  private static List<ParsedPersistenceUnit> getList(Collection<? extends ParsedPersistenceUnit>
puinfos)
   {
-    List<PersistenceUnitInfoService> list = new ArrayList<PersistenceUnitInfoService>();
+    List<ParsedPersistenceUnit> list = new ArrayList<ParsedPersistenceUnit>();
     
     list.addAll(puinfos);
     
-    Collections.sort(list, new Comparator<PersistenceUnitInfoService>() {
+    Collections.sort(list, new Comparator<ParsedPersistenceUnit>() {
 
-      public int compare(PersistenceUnitInfoService o1, PersistenceUnitInfoService o2)
+      public int compare(ParsedPersistenceUnit o1, ParsedPersistenceUnit o2)
       {
-        return ((String)o1.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.UNIT_NAME))
-        .compareTo((String)o2.getPersistenceXmlMetadata().get(PersistenceUnitInfoService.UNIT_NAME));
+        return ((String)o1.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.UNIT_NAME))
+        .compareTo((String)o2.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.UNIT_NAME));
       }
       
     });
@@ -341,6 +270,11 @@
     return list;
   }
   
+  /**
+   * Check we have all the jar file names we expect
+   * @param collection
+   * @return
+   */
   private boolean checkJARURLs(Collection<String> collection)
   {
     List<String> jars = new ArrayList<String>();



Mime
View raw message