Author: michiel
Date: 2009-11-26 21:10:16 +0100 (Thu, 26 Nov 2009)
New Revision: 39992

Modified:
   mmbase/trunk/core/src/main/java/org/mmbase/bridge/mock/MockCloud.java
   mmbase/trunk/core/src/main/java/org/mmbase/bridge/mock/MockNode.java
   mmbase/trunk/core/src/main/java/org/mmbase/bridge/mock/MockNodeManager.java
   mmbase/trunk/core/src/main/java/org/mmbase/bridge/mock/MockTransaction.java
   mmbase/trunk/core/src/test/java/org/mmbase/bridge/util/QueriesTest.java
Log:
implemted Node#isNew on MockNodes. Added test-case for Queries#createNodeQuery 
for new nodes

Modified: mmbase/trunk/core/src/main/java/org/mmbase/bridge/mock/MockCloud.java
===================================================================
--- mmbase/trunk/core/src/main/java/org/mmbase/bridge/mock/MockCloud.java       
2009-11-26 19:43:38 UTC (rev 39991)
+++ mmbase/trunk/core/src/main/java/org/mmbase/bridge/mock/MockCloud.java       
2009-11-26 20:10:16 UTC (rev 39992)
@@ -35,21 +35,21 @@
     }
 
 
-    Node getNode(final Map<String, Object> m, final NodeManager nm) {
-        return new MockNode(m, cloudContext, nm);
+    Node getNode(final Map<String, Object> m, final NodeManager nm, boolean n) 
{
+        return new MockNode(m, cloudContext, nm, n);
     }
 
     @Override
     public Node getNode(int number) throws NotFoundException {
         MockCloudContext.NodeDescription nd = cloudContext.nodes.get(number);
         if (nd == null) {
-            throw new NotFoundException();
+            throw new NotFoundException("No node with number " + number + " 
found in " + this);
         }
         if (nd.type.equals("typedef")) {
             return  
getNodeManager(org.mmbase.util.Casting.toString(nd.values.get("name")));
         } else {
             NodeManager nm = getNodeManager(nd.type);
-            return getNode(nd.values, nm);
+            return getNode(nd.values, nm, false);
         }
     }
 
@@ -125,7 +125,7 @@
                         if (nm.getName().equals("typedef")) {
                             return 
MockCloud.this.getNodeManager(Casting.toString(m.get("name")));
                         } else {
-                            return MockCloud.this.getNode(m, nm);
+                            return MockCloud.this.getNode(m, nm, false);
                         }
                     }
                 }

Modified: mmbase/trunk/core/src/main/java/org/mmbase/bridge/mock/MockNode.java
===================================================================
--- mmbase/trunk/core/src/main/java/org/mmbase/bridge/mock/MockNode.java        
2009-11-26 19:43:38 UTC (rev 39991)
+++ mmbase/trunk/core/src/main/java/org/mmbase/bridge/mock/MockNode.java        
2009-11-26 20:10:16 UTC (rev 39992)
@@ -30,11 +30,13 @@
     private final Map<String, Object> originalMap;
     private final MockCloudContext cloudContext;
     private String context = "default";
+    private boolean isNew;
 
-    MockNode(Map<String, Object> map, MockCloudContext cc, NodeManager nm) {
+    MockNode(Map<String, Object> map, MockCloudContext cc, NodeManager nm, 
boolean isNew) {
         super(new HashMap<String, Object>(map), nm);
         originalMap = map;
         cloudContext = cc;
+        this.isNew = isNew;
     }
 
     @Override
@@ -50,6 +52,7 @@
         }
         originalMap.putAll(values);
         cloudContext.setNodeType(getNumber(), getNodeManager().getName());
+        isNew = false;
     }
     @Override
     public Object getValueWithoutProcess(String fieldName) {
@@ -79,8 +82,15 @@
         return sl;
     }
 
+    @Override
+    public boolean isNew() {
+        return isNew;
+    }
 
 
+
+
+
     @Override
     public String toString() {
         return getNodeManager().toString() + values;

Modified: 
mmbase/trunk/core/src/main/java/org/mmbase/bridge/mock/MockNodeManager.java
===================================================================
--- mmbase/trunk/core/src/main/java/org/mmbase/bridge/mock/MockNodeManager.java 
2009-11-26 19:43:38 UTC (rev 39991)
+++ mmbase/trunk/core/src/main/java/org/mmbase/bridge/mock/MockNodeManager.java 
2009-11-26 20:10:16 UTC (rev 39992)
@@ -92,7 +92,7 @@
     public Node createNode() {
         Map<String, Object> map = new HashMap<String, Object>();
         map.put("otype", oType);
-        return vcloud.getNode(map, this);
+        return vcloud.getNode(map, this, true);
     }
 
 

Modified: 
mmbase/trunk/core/src/main/java/org/mmbase/bridge/mock/MockTransaction.java
===================================================================
--- mmbase/trunk/core/src/main/java/org/mmbase/bridge/mock/MockTransaction.java 
2009-11-26 19:43:38 UTC (rev 39991)
+++ mmbase/trunk/core/src/main/java/org/mmbase/bridge/mock/MockTransaction.java 
2009-11-26 20:10:16 UTC (rev 39992)
@@ -58,10 +58,10 @@
 
 
     @Override
-    Node getNode(final Map<String, Object> m, final NodeManager nm) {
-        Node n = super.getNode(m, nm);
-        nodes.add(n);
-        return n;
+    Node getNode(final Map<String, Object> m, final NodeManager nm, boolean n) 
{
+        Node node = super.getNode(m, nm, n);
+        nodes.add(node);
+        return node;
     }
 
     @Override

Modified: 
mmbase/trunk/core/src/test/java/org/mmbase/bridge/util/QueriesTest.java
===================================================================
--- mmbase/trunk/core/src/test/java/org/mmbase/bridge/util/QueriesTest.java     
2009-11-26 19:43:38 UTC (rev 39991)
+++ mmbase/trunk/core/src/test/java/org/mmbase/bridge/util/QueriesTest.java     
2009-11-26 20:10:16 UTC (rev 39992)
@@ -125,13 +125,23 @@
         Cloud cloud = getCloudContext().getCloud("mmbase");
         Node node = cloud.getNodeManager("news").createNode();
         node.setStringValue("title", "foo");
+        {
+            NodeQuery q = Queries.createNodeQuery(node);
+            assertEquals(1, q.getSteps().size());
+            assertEquals("news", q.getSteps().get(0).getTableName());
+
+            // createNodeQuery on a new node will leave the query unconstraint
+            assertNull(q.getSteps().get(0).getNodes());
+        }
         node.commit();
+        {
+            NodeQuery q = Queries.createNodeQuery(node);
+            assertEquals(1, q.getSteps().size());
+            assertEquals("news", q.getSteps().get(0).getTableName());
+            assertEquals(1, q.getSteps().get(0).getNodes().size());
+            
assertTrue(q.getSteps().get(0).getNodes().contains(node.getNumber()));
+        }
 
-        NodeQuery q = Queries.createNodeQuery(node);
-        assertEquals(1, q.getSteps().size());
-        assertEquals("news", q.getSteps().get(0).getTableName());
-        assertEquals(1, q.getSteps().get(0).getNodes().size());
-        assertTrue(q.getSteps().get(0).getNodes().contains(node.getNumber()));
     }
 
     @Test

_______________________________________________
Cvs mailing list
Cvs@lists.mmbase.org
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to