incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From danhayw...@apache.org
Subject svn commit: r1244886 - in /incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src: main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/ test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/
Date Thu, 16 Feb 2012 08:18:36 GMT
Author: danhaywood
Date: Thu Feb 16 08:18:36 2012
New Revision: 1244886

URL: http://svn.apache.org/viewvc?rev=1244886&view=rev
Log:
ISIS-195: fixing two failing unit tests related to the NoSqlOid support for the nosql-mongo
object store

Added:
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlKeyCreatorTest_reference.java
  (with props)
Modified:
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlDestroyObjectCommand.java
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/DestroyObjectCommandImplementationTest.java
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlKeyCreatorTest.java

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlDestroyObjectCommand.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlDestroyObjectCommand.java?rev=1244886&r1=1244885&r2=1244886&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlDestroyObjectCommand.java
(original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/main/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlDestroyObjectCommand.java
Thu Feb 16 08:18:36 2012
@@ -25,35 +25,35 @@ import org.apache.isis.runtimes.dflt.run
 import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.transaction.PersistenceCommandContext;
 
 final class NoSqlDestroyObjectCommand implements DestroyObjectCommand {
-    private final ObjectAdapter object;
+    private final ObjectAdapter adapter;
     private final KeyCreator keyCreator;
     private final VersionCreator versionCreator;
 
     public NoSqlDestroyObjectCommand(final KeyCreator keyCreator, final VersionCreator versionCreator,
final ObjectAdapter object) {
         this.keyCreator = keyCreator;
         this.versionCreator = versionCreator;
-        this.object = object;
+        this.adapter = object;
     }
 
     @Override
     public void execute(final PersistenceCommandContext context) {
-        final String key = keyCreator.key(object.getOid());
-        final String version = versionCreator.versionString(object.getVersion());
-        final String specificationName = object.getSpecification().getFullIdentifier();
+        final String key = keyCreator.key(adapter.getOid());
+        final String version = versionCreator.versionString(adapter.getVersion());
+        final String specificationName = adapter.getSpecification().getFullIdentifier();
 
         ((NoSqlCommandContext) context).delete(specificationName, key, version);
     }
 
     @Override
     public ObjectAdapter onObject() {
-        return object;
+        return adapter;
     }
 
     @Override
     public String toString() {
         final ToString toString = new ToString(this);
-        toString.append("spec", object.getSpecification().getFullIdentifier());
-        toString.append("oid", object.getOid());
+        toString.append("spec", adapter.getSpecification().getFullIdentifier());
+        toString.append("oid", adapter.getOid());
         return toString.toString();
     }
 }

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/DestroyObjectCommandImplementationTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/DestroyObjectCommandImplementationTest.java?rev=1244886&r1=1244885&r2=1244886&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/DestroyObjectCommandImplementationTest.java
(original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/DestroyObjectCommandImplementationTest.java
Thu Feb 16 08:18:36 2012
@@ -19,50 +19,83 @@
 
 package org.apache.isis.runtimes.dflt.objectstores.nosql;
 
-import java.util.Date;
-
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
 import org.jmock.Expectations;
-import org.jmock.Mockery;
+import org.jmock.auto.Mock;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
 import org.apache.isis.core.metamodel.adapter.version.SerialNumberVersion;
 import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.runtimes.dflt.objectstores.dflt.testsystem.TestProxySystemII;
-import org.apache.isis.runtimes.dflt.runtime.persistence.oidgenerator.simple.SerialOid;
-import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
 
 public class DestroyObjectCommandImplementationTest {
 
+    @Rule
+    public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+    
+    @Mock
+    private NoSqlCommandContext commandContext;
+    @Mock
+    private ObjectSpecification specification;
+    @Mock
+    private ObjectAdapter adapter;
+    @Mock
+    private NoSqlOid sqlOid;
+    @Mock
+    private SerialNumberVersionCreator versionCreator;
+    @Mock
+    private NoSqlKeyCreator keyCreator;
+    @Mock
+    private SerialNumberVersion version;
+
+
+    private long id = 123;
+    private String keyStr = Long.toString(id, 16);
+    
+    private NoSqlDestroyObjectCommand command;
+
     @Before
     public void setup() {
-        Logger.getRootLogger().setLevel(Level.OFF);
-        final TestProxySystemII system = new TestProxySystemII();
-        system.init();
+        context.checking(new Expectations(){{
+
+            allowing(specification).getFullIdentifier();
+            will(returnValue("com.foo.bar.SomeClass"));
+
+            allowing(adapter).getSpecification();
+            will(returnValue(specification));
+            
+            allowing(adapter).getOid();
+            will(returnValue(sqlOid));
+
+            allowing(adapter).getVersion();
+            will(returnValue(version));
+
+        }});
     }
 
     @Test
-    public void testname() throws Exception {
-        final ObjectSpecification specification = IsisContext.getSpecificationLoader().loadSpecification(ExampleReferencePojo.class);
-        final ObjectAdapter object = IsisContext.getPersistenceSession().createInstance(specification);
-        IsisContext.getPersistenceSession().makePersistent(object);
-        object.setOptimisticLock(new SerialNumberVersion(3, "username", new Date(1000)));
-
-        final long id = ((SerialOid) object.getOid()).getSerialNo();
-        final String key = Long.toString(id, 16);
+    public void execute() throws Exception {
+        
+        final String versionStr = "3";
 
-        final Mockery context = new Mockery();
-        final NoSqlCommandContext commandContext = context.mock(NoSqlCommandContext.class);
         context.checking(new Expectations() {
             {
-                one(commandContext).delete(specification.getFullIdentifier(), key, "3");
+                one(keyCreator).key(sqlOid);
+                will(returnValue(keyStr));
+
+                one(versionCreator).versionString(version);
+                will(returnValue(versionStr));
+
+                one(commandContext).delete(specification.getFullIdentifier(), keyStr, versionStr);
             }
         });
 
-        final NoSqlDestroyObjectCommand command = new NoSqlDestroyObjectCommand(new NoSqlKeyCreator(),
new SerialNumberVersionCreator(), object);
+        command = new NoSqlDestroyObjectCommand(keyCreator, versionCreator, adapter);
         command.execute(commandContext);
     }
 }

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlKeyCreatorTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlKeyCreatorTest.java?rev=1244886&r1=1244885&r2=1244886&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlKeyCreatorTest.java
(original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlKeyCreatorTest.java
Thu Feb 16 08:18:36 2012
@@ -26,8 +26,6 @@ import org.apache.log4j.Logger;
 import org.junit.Before;
 import org.junit.Test;
 
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.oid.Oid;
 import org.apache.isis.core.metamodel.spec.ObjectSpecification;
 import org.apache.isis.runtimes.dflt.objectstores.dflt.testsystem.TestProxySystemII;
 import org.apache.isis.runtimes.dflt.runtime.persistence.oidgenerator.simple.SerialOid;
@@ -35,29 +33,22 @@ import org.apache.isis.runtimes.dflt.run
 
 public class NoSqlKeyCreatorTest {
 
+    private final int id = 3;
+    private final String reference = ExampleReferencePojo.class.getName() + "@" + id;
+    private final NoSqlOid oid3 = new NoSqlOid(ExampleReferencePojo.class.getName(), SerialOid.createPersistent(id));
+    
     private ObjectSpecification specification;
-    private ObjectAdapter object;
-    private final String reference = ExampleReferencePojo.class.getName() + "@3";
+    
     private NoSqlKeyCreator noSqlKeyCreator;
-    private final NoSqlOid oid3 = new NoSqlOid(ExampleReferencePojo.class.getName(), SerialOid.createPersistent(3));
 
     @Before
     public void setup() {
         Logger.getRootLogger().setLevel(Level.OFF);
         final TestProxySystemII system = new TestProxySystemII();
         system.init();
-
-        noSqlKeyCreator = new NoSqlKeyCreator();
-    }
-
-    @Test
-    public void reference() throws Exception {
         specification = IsisContext.getSpecificationLoader().loadSpecification(ExampleReferencePojo.class);
-        object = IsisContext.getPersistenceSession().createInstance(specification);
-        ((SerialOid) object.getOid()).setId(3);
-        object.getOid().makePersistent();
 
-        assertEquals(reference, noSqlKeyCreator.reference(object));
+        noSqlKeyCreator = new NoSqlKeyCreator();
     }
 
     @Test
@@ -69,7 +60,6 @@ public class NoSqlKeyCreatorTest {
 
     @Test
     public void specification() throws Exception {
-        specification = IsisContext.getSpecificationLoader().loadSpecification(ExampleReferencePojo.class);
         final ObjectSpecification spec = noSqlKeyCreator.specificationFromReference(reference);
         assertEquals(specification, spec);
     }

Added: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlKeyCreatorTest_reference.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlKeyCreatorTest_reference.java?rev=1244886&view=auto
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlKeyCreatorTest_reference.java
(added)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlKeyCreatorTest_reference.java
Thu Feb 16 08:18:36 2012
@@ -0,0 +1,76 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.runtimes.dflt.objectstores.nosql;
+
+import static org.junit.Assert.assertEquals;
+
+import org.jmock.Expectations;
+import org.jmock.auto.Mock;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
+import org.apache.isis.runtimes.dflt.runtime.persistence.oidgenerator.simple.SerialOid;
+
+public class NoSqlKeyCreatorTest_reference {
+
+    @Rule
+    public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_ONLY);
+
+
+    @Mock
+    private ObjectSpecification specification;
+    @Mock
+    private ObjectAdapter adapter;
+    
+    private final String className = "com.foo.bar.SomeClass";
+    private final SerialOid serialOid = SerialOid.createPersistent(123);
+    private final NoSqlOid noSqlOid = new NoSqlOid(className, serialOid);
+    
+    private NoSqlKeyCreator noSqlKeyCreator;
+
+    @Before
+    public void setup() {
+        noSqlKeyCreator = new NoSqlKeyCreator();
+        
+        context.checking(new Expectations() {
+            {
+                allowing(adapter).getSpecification();
+                will(returnValue(specification));
+
+                allowing(adapter).getOid();
+                will(returnValue(noSqlOid));
+
+                allowing(specification).getFullIdentifier();
+                will(returnValue(className));
+            }
+        });
+    }
+
+    @Test
+    public void reference() throws Exception {
+        final String expectedReference = className + "@" + Long.toString(serialOid.getSerialNo(),
16);
+        assertEquals(expectedReference, noSqlKeyCreator.reference(adapter));
+    }
+}

Propchange: incubator/isis/trunk/framework/runtimes/dflt/objectstores/nosql/src/test/java/org/apache/isis/runtimes/dflt/objectstores/nosql/NoSqlKeyCreatorTest_reference.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message