cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1296124 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java test/java/org/apache/cayenne/access/DataDomainTest.java
Date Fri, 02 Mar 2012 10:43:00 GMT
Author: aadamchik
Date: Fri Mar  2 10:43:00 2012
New Revision: 1296124

URL: http://svn.apache.org/viewvc?rev=1296124&view=rev
Log:
CAY-1679 A notion of default node

better logging; unit tests

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataDomainTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java?rev=1296124&r1=1296123&r2=1296124&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java
Fri Mar  2 10:43:00 2012
@@ -250,7 +250,13 @@ public class DataDomainProvider implemen
             }
         }
 
-        dataDomain.setDefaultNode(defaultNode);
+        if (defaultNode != null) {
+            logger.info("setting DataNode '"
+                    + defaultNode.getName()
+                    + "' as default, used by all unlinked DataMaps");
+
+            dataDomain.setDefaultNode(defaultNode);
+        }
 
         for (DataChannelFilter filter : filters) {
             dataDomain.addFilter(filter);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataDomainTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataDomainTest.java?rev=1296124&r1=1296123&r2=1296124&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataDomainTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataDomainTest.java
Fri Mar  2 10:43:00 2012
@@ -23,6 +23,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.configuration.server.ServerRuntime;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.event.DefaultEventManager;
@@ -37,7 +38,7 @@ public class DataDomainTest extends Serv
 
     @Inject
     private ServerRuntime runtime;
-    
+
     @Inject
     private JdbcEventLogger logger;
 
@@ -48,6 +49,54 @@ public class DataDomainTest extends Serv
         assertEquals("tst_name", domain.getName());
     }
 
+    public void testLookupDataNode() {
+
+        DataDomain domain = new DataDomain("test");
+
+        DataMap m1 = new DataMap("m1");
+        DataNode n1 = new DataNode("n1");
+        n1.addDataMap(m1);
+        domain.addNode(n1);
+
+        DataMap m2 = new DataMap("m2");
+        DataNode n2 = new DataNode("n2");
+        n2.addDataMap(m2);
+        domain.addNode(n2);
+
+        assertSame(n1, domain.lookupDataNode(m1));
+        assertSame(n2, domain.lookupDataNode(m2));
+
+        try {
+
+            domain.lookupDataNode(new DataMap("m3"));
+            fail("must have thrown on missing Map to Node maping");
+        }
+        catch (CayenneRuntimeException e) {
+            // expected
+        }
+    }
+
+    public void testLookupDataNode_Default() {
+
+        DataDomain domain = new DataDomain("test");
+
+        DataMap m1 = new DataMap("m1");
+        DataNode n1 = new DataNode("n1");
+        n1.addDataMap(m1);
+        domain.setDefaultNode(n1);
+
+        DataMap m2 = new DataMap("m2");
+        DataNode n2 = new DataNode("n2");
+        n2.addDataMap(m2);
+        domain.addNode(n2);
+
+        assertSame(n1, domain.lookupDataNode(m1));
+        assertSame(n2, domain.lookupDataNode(m2));
+
+        // must map to default
+        assertSame(n1, domain.lookupDataNode(new DataMap("m3")));
+    }
+
     public void testNodes() throws Exception {
         DataDomain domain = new DataDomain("dom1");
         assertEquals(0, domain.getDataNodes().size());
@@ -143,8 +192,9 @@ public class DataDomainTest extends Serv
 
     public void testInitDataDomainValidation() throws Exception {
         Map<Object, Object> properties = new HashMap<Object, Object>();
-        properties.put(DataDomain.VALIDATING_OBJECTS_ON_COMMIT_PROPERTY, Boolean.TRUE
-                .toString());
+        properties.put(
+                DataDomain.VALIDATING_OBJECTS_ON_COMMIT_PROPERTY,
+                Boolean.TRUE.toString());
 
         DataDomain domain = new DataDomain("d1", properties);
         assertTrue(domain.isValidatingObjectsOnCommit());
@@ -152,8 +202,9 @@ public class DataDomainTest extends Serv
 
     public void testInitDataDomainNoValidation() throws Exception {
         Map<Object, Object> properties = new HashMap<Object, Object>();
-        properties.put(DataDomain.VALIDATING_OBJECTS_ON_COMMIT_PROPERTY, Boolean.FALSE
-                .toString());
+        properties.put(
+                DataDomain.VALIDATING_OBJECTS_ON_COMMIT_PROPERTY,
+                Boolean.FALSE.toString());
 
         DataDomain domain = new DataDomain("d1", properties);
         assertFalse(domain.isValidatingObjectsOnCommit());
@@ -161,8 +212,9 @@ public class DataDomainTest extends Serv
 
     public void testDataDomainInternalTransactions() throws Exception {
         Map<Object, Object> properties = new HashMap<Object, Object>();
-        properties.put(DataDomain.USING_EXTERNAL_TRANSACTIONS_PROPERTY, Boolean.FALSE
-                .toString());
+        properties.put(
+                DataDomain.USING_EXTERNAL_TRANSACTIONS_PROPERTY,
+                Boolean.FALSE.toString());
 
         DataDomain domain = new DataDomain("d1", properties);
         assertFalse(domain.isUsingExternalTransactions());
@@ -173,8 +225,9 @@ public class DataDomainTest extends Serv
 
     public void testDataDomainExternalTransactions() throws Exception {
         Map<Object, Object> properties = new HashMap<Object, Object>();
-        properties.put(DataDomain.USING_EXTERNAL_TRANSACTIONS_PROPERTY, Boolean.TRUE
-                .toString());
+        properties.put(
+                DataDomain.USING_EXTERNAL_TRANSACTIONS_PROPERTY,
+                Boolean.TRUE.toString());
 
         DataDomain domain = new DataDomain("d1", properties);
         assertTrue(domain.isUsingExternalTransactions());



Mime
View raw message