Search in sources :

Example 6 with EmptyConfigurationNodeVisitor

use of org.apache.cayenne.configuration.EmptyConfigurationNodeVisitor 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

PrintWriter (java.io.PrintWriter)6 EmptyConfigurationNodeVisitor (org.apache.cayenne.configuration.EmptyConfigurationNodeVisitor)6 XMLEncoder (org.apache.cayenne.util.XMLEncoder)6 StringWriter (java.io.StringWriter)5 Test (org.junit.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 List (java.util.List)1 ConfigurationNodeVisitor (org.apache.cayenne.configuration.ConfigurationNodeVisitor)1 XMLDataMapLoader (org.apache.cayenne.configuration.xml.XMLDataMapLoader)1 DbAttribute (org.apache.cayenne.map.DbAttribute)1 DbEntity (org.apache.cayenne.map.DbEntity)1 DbRelationship (org.apache.cayenne.map.DbRelationship)1 EJBQLQueryDescriptor (org.apache.cayenne.map.EJBQLQueryDescriptor)1 ObjAttribute (org.apache.cayenne.map.ObjAttribute)1 ObjEntity (org.apache.cayenne.map.ObjEntity)1 ObjRelationship (org.apache.cayenne.map.ObjRelationship)1 URLResource (org.apache.cayenne.resource.URLResource)1 XMLSerializable (org.apache.cayenne.util.XMLSerializable)1