Search in sources :

Example 1 with XMLDataMapLoader

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();
    }
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) XMLEncoder(org.apache.cayenne.util.XMLEncoder) EmptyConfigurationNodeVisitor(org.apache.cayenne.configuration.EmptyConfigurationNodeVisitor) StringWriter(java.io.StringWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) XMLDataMapLoader(org.apache.cayenne.configuration.xml.XMLDataMapLoader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) URL(java.net.URL) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 URL (java.net.URL)1 EmptyConfigurationNodeVisitor (org.apache.cayenne.configuration.EmptyConfigurationNodeVisitor)1 XMLDataMapLoader (org.apache.cayenne.configuration.xml.XMLDataMapLoader)1 URLResource (org.apache.cayenne.resource.URLResource)1 XMLEncoder (org.apache.cayenne.util.XMLEncoder)1 Test (org.junit.Test)1