Search in sources :

Example 1 with XMLEntityMappingsWriter

use of org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappingsWriter in project eclipselink by eclipse-ee4j.

the class EntityMappingsAdvancedJUnitTestCase method testXMLEntityMappingsWriteOut.

public void testXMLEntityMappingsWriteOut() {
    try {
        XMLEntityMappings mappings = new XMLEntityMappings();
        mappings.setPersistenceUnitMetadata(new XMLPersistenceUnitMetadata());
        mappings.getPersistenceUnitMetadata().setPersistenceUnitDefaults(new XMLPersistenceUnitDefaults());
        XMLPersistenceUnitMetadata persistenceUnitMetadata = new XMLPersistenceUnitMetadata();
        persistenceUnitMetadata.setPersistenceUnitDefaults(new XMLPersistenceUnitDefaults());
        mappings.setPersistenceUnitMetadata(persistenceUnitMetadata);
        EntityAccessor entity = new EntityAccessor();
        mappings.setEntities(new ArrayList<EntityAccessor>());
        entity.setAttributes(new XMLAttributes());
        entity.getAttributes().setBasicCollections(new ArrayList<BasicCollectionAccessor>());
        entity.getAttributes().getBasicCollections().add(new BasicCollectionAccessor());
        entity.getAttributes().setOneToManys(new ArrayList<OneToManyAccessor>());
        OneToManyAccessor oneToMany = new OneToManyAccessor();
        oneToMany.setCascade(new CascadeMetadata());
        entity.getAttributes().getOneToManys().add(oneToMany);
        entity.getAttributes().setBasics(new ArrayList<BasicAccessor>());
        entity.getAttributes().getBasics().add(new BasicAccessor());
        mappings.getEntities().add(entity);
        XMLEntityMappingsWriter writer = new XMLEntityMappingsWriter();
        FileOutputStream fileOut = new FileOutputStream("XMLWriteOutTest.xml");
        XMLEntityMappingsWriter.write(mappings, fileOut);
        fileOut.close();
        FileInputStream fileIn = new FileInputStream(fileOut.getFD());
        BufferedReader in = new BufferedReader(new InputStreamReader(fileIn));
        HashSet<String> readStrings = new HashSet<String>();
        while (in.ready()) {
            readStrings.add(in.readLine());
        }
        in.close();
        // Now look for those empty types that we should not see when not explicitly set ...
        assertFalse("Found cascade on delete element", readStrings.contains("<cascade-on-delete"));
        assertFalse("Found non cacheable element", readStrings.contains("<noncacheable"));
        assertFalse("Found private owned element", readStrings.contains("<private-owned"));
        assertFalse("Found xml mapping metadata complete element", readStrings.contains("<xml-mapping-metadata-complete"));
        assertFalse("Found exclude default mappings element", readStrings.contains("<exclude-default-mappings"));
        assertFalse("Found delimeted identifiers element", readStrings.contains("<delimited-identifiers"));
        assertFalse("Found exclude default listeners element", readStrings.contains("<exclude-default-listeners"));
        assertFalse("Found exclude superclass listeners element", readStrings.contains("<exclude-superclass-listeners"));
        assertFalse("Found return update element", readStrings.contains("<return-update"));
        assertFalse("Found cascade all element", readStrings.contains("<cascade-all"));
        assertFalse("Found cascade persist element", readStrings.contains("<cascade-persist"));
        assertFalse("Found cascade merge element", readStrings.contains("<cascade-merge"));
        assertFalse("Found cascade remove element", readStrings.contains("<cascade-remove"));
        assertFalse("Found cascade refresh element", readStrings.contains("<cascade-refresh"));
        assertFalse("Found cascade detach element", readStrings.contains("<cascade-detach"));
    } catch (Exception e) {
        e.printStackTrace();
        fail("An error occurred: " + e.getMessage());
    }
}
Also used : EntityAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor) OneToManyAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.OneToManyAccessor) BasicAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.BasicAccessor) XMLEntityMappingsWriter(org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappingsWriter) InputStreamReader(java.io.InputStreamReader) XMLEntityMappings(org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappings) XMLPersistenceUnitMetadata(org.eclipse.persistence.internal.jpa.metadata.xml.XMLPersistenceUnitMetadata) CascadeMetadata(org.eclipse.persistence.internal.jpa.metadata.mappings.CascadeMetadata) XMLPersistenceUnitDefaults(org.eclipse.persistence.internal.jpa.metadata.xml.XMLPersistenceUnitDefaults) FileInputStream(java.io.FileInputStream) EntityNotFoundException(jakarta.persistence.EntityNotFoundException) BasicCollectionAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.BasicCollectionAccessor) XMLAttributes(org.eclipse.persistence.internal.jpa.metadata.accessors.classes.XMLAttributes) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) HashSet(java.util.HashSet)

Aggregations

EntityNotFoundException (jakarta.persistence.EntityNotFoundException)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 HashSet (java.util.HashSet)1 EntityAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor)1 XMLAttributes (org.eclipse.persistence.internal.jpa.metadata.accessors.classes.XMLAttributes)1 BasicAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.BasicAccessor)1 BasicCollectionAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.BasicCollectionAccessor)1 OneToManyAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.OneToManyAccessor)1 CascadeMetadata (org.eclipse.persistence.internal.jpa.metadata.mappings.CascadeMetadata)1 XMLEntityMappings (org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappings)1 XMLEntityMappingsWriter (org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappingsWriter)1 XMLPersistenceUnitDefaults (org.eclipse.persistence.internal.jpa.metadata.xml.XMLPersistenceUnitDefaults)1 XMLPersistenceUnitMetadata (org.eclipse.persistence.internal.jpa.metadata.xml.XMLPersistenceUnitMetadata)1