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());
}
}
Aggregations