use of org.apache.cayenne.configuration.xml.XMLDataMapLoader in project cayenne by apache.
the class DataMapTest method testQuoteSqlIdentifiersEncodeAsXML.
@Test
public void testQuoteSqlIdentifiersEncodeAsXML() {
DataMap map = new DataMap("aaa");
map.setQuotingSQLIdentifiers(true);
StringWriter w = new StringWriter();
XMLEncoder encoder = new XMLEncoder(new PrintWriter(w));
map.encodeAsXML(encoder, new EmptyConfigurationNodeVisitor());
assertTrue(map.quotingSQLIdentifiers);
XMLDataMapLoader loader = new XMLDataMapLoader();
try {
URL url = mock(URL.class);
InputStream is = new ByteArrayInputStream(w.getBuffer().toString().getBytes("UTF-8"));
when(url.openStream()).thenReturn(is);
DataMap newMap = loader.load(new URLResource(url));
assertTrue(newMap.quotingSQLIdentifiers);
} catch (Exception e) {
e.printStackTrace();
}
map.setQuotingSQLIdentifiers(false);
StringWriter w2 = new StringWriter();
XMLEncoder encoder2 = new XMLEncoder(new PrintWriter(w2));
map.encodeAsXML(encoder2, new EmptyConfigurationNodeVisitor());
assertFalse(map.quotingSQLIdentifiers);
try {
URL url = mock(URL.class);
InputStream is = new ByteArrayInputStream(w.getBuffer().toString().getBytes("UTF-8"));
when(url.openStream()).thenReturn(is);
DataMap newMap = loader.load(new URLResource(url));
assertFalse(newMap.quotingSQLIdentifiers);
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations