use of org.jpox.samples.i18n.ISO8859_2 in project tests by datanucleus.
the class BasicTest method testMetaDataManagerI18N.
/**
* Test for the MetaDataManager.
*/
public void testMetaDataManagerI18N() {
JDOMetaDataHelper mdProc = new JDOMetaDataHelper();
String filename = "/org/jpox/samples/i18n/UTF8.jdo";
MetaDataManager mmgr1 = new JDOMetaDataManager(new PersistenceNucleusContextImpl("JDO", null));
MetaDataParser parser1 = new MetaDataParser(mmgr1, mmgr1.getNucleusContext().getPluginManager(), true, true);
mmgr1.setValidate(false);
FileMetaData fmd = (FileMetaData) parser1.parseMetaDataStream(MetaDataParser.class.getResourceAsStream(filename), filename, "jdo");
fmd.getPackage("org.jpox.samples.i18n").getClass("UTF8");
org.datanucleus.metadata.AbstractClassMetaData cmd1 = fmd.getPackage("org.jpox.samples.i18n").getClass("UTF8");
cmd1.populate(new ClassLoaderResolverImpl(), null, mmgr1);
cmd1.initialise(new ClassLoaderResolverImpl());
MetaDataManager mmgr2 = new JDOMetaDataManager(new PersistenceNucleusContextImpl("JDO", null));
mmgr2.setValidate(false);
org.datanucleus.metadata.AbstractClassMetaData cmd = mmgr2.getMetaDataForClass(UTF8.class, new ClassLoaderResolverImpl());
if (!mdProc.getXMLForMetaData(cmd, "", "").equals(mdProc.getXMLForMetaData(cmd1, "", ""))) {
fail("i18n UTF-8 issues in parser");
}
filename = "/org/jpox/samples/i18n/ISO8859_2.jdo";
MetaDataManager mmgr3 = new JDOMetaDataManager(new PersistenceNucleusContextImpl("JDO", null));
MetaDataParser parser3 = new MetaDataParser(mmgr3, mmgr3.getNucleusContext().getPluginManager(), true, true);
mmgr3.setValidate(false);
fmd = (FileMetaData) parser3.parseMetaDataStream(MetaDataParser.class.getResourceAsStream(filename), filename, "jdo");
fmd.getPackage("org.jpox.samples.i18n").getClass("ISO8859_2");
MetaDataManager mmgr4 = new JDOMetaDataManager(new PersistenceNucleusContextImpl("JDO", null));
mmgr4.setValidate(false);
cmd1 = fmd.getPackage("org.jpox.samples.i18n").getClass("ISO8859_2");
cmd1.populate(new ClassLoaderResolverImpl(), null, mmgr4);
cmd1.initialise(null);
cmd = mmgr4.getMetaDataForClass(ISO8859_2.class, new ClassLoaderResolverImpl());
if (!mdProc.getXMLForMetaData(cmd, "", "").equals(mdProc.getXMLForMetaData(cmd1, "", ""))) {
fail("i18n ISO8859_2 issues in parser");
}
}
use of org.jpox.samples.i18n.ISO8859_2 in project tests by datanucleus.
the class I18NTest method testISO8859_2.
/**
* Simple test to load up the ISO8859-2 class.
*/
public void testISO8859_2() throws Exception {
if (vendorID != null && vendorID.equals("postgresql")) {
// Dont run on Postgresql
return;
}
String datastoreProtocol = TestHelper.getDatastorePluginProtocol(1);
if (datastoreProtocol != null && datastoreProtocol.equals("cassandra")) {
// Don't run on Cassandra
return;
}
try {
try {
addClassesToSchema(new Class[] { ISO8859_2.class });
} catch (Exception e) {
fail("Failed to load class with ISO8859-2 field names : " + e.getMessage());
} finally {
}
// Test persistence of an object
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
ISO8859_2 obj = new ISO8859_2("����", "����");
pm.makePersistent(obj);
tx.commit();
} catch (Exception e) {
fail("Failed to persist an object of class with ISO8859-2 field names : " + e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
}
// Test retrieval of object
tx = pm.currentTransaction();
try {
tx.begin();
Extent<ISO8859_2> e = pm.getExtent(org.jpox.samples.i18n.ISO8859_2.class, false);
Query<ISO8859_2> q = pm.newQuery(e);
Collection<ISO8859_2> c = q.executeList();
assertTrue("Number of ISO8859_2 objects is incorrect (" + c.size() + ") : should have been 1", c.size() == 1);
Iterator<ISO8859_2> iter = c.iterator();
while (iter.hasNext()) {
ISO8859_2 obj = iter.next();
LOG.info(obj);
}
tx.commit();
} catch (Exception e) {
fail("Failed to retrieve an object of class with ISO8859-2 field names : " + e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
}
pm.close();
} finally {
clean(ISO8859_2.class);
}
}
Aggregations