You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2013/03/01 13:17:37 UTC

git commit: ISIS-351: fixing some broken tests

Updated Branches:
  refs/heads/master e8b5d02e3 -> b1d7000ae


ISIS-351: fixing some broken tests

... sorry about that, should've done this before I pushed.

The breakage was because of errors in the tests, that were being masked before.  Previously,
a test could call flush() on a committed transaction.  This didn't matter because
flush() would be a no-op if there were no queued commands.

Now, however, the flush continues, because - for the JDO object store - not every update
is wrapped as a command.  This caused a guard to trigger, failing the tests.

The fix was to make sure that a transaction was correctly in progress, using
@Before and @After (or equivalent).

There was also a one-liner guard in the ServicesInjector to allow for a null container
when caching services by type.  This wouldn't happen in production but does happen
in one of the tests for this class (ServicesInjectorDefault).


Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/b1d7000a
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/b1d7000a
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/b1d7000a

Branch: refs/heads/master
Commit: b1d7000aebfe2a01a1debb841c4e07cd612a0718
Parents: e8b5d02
Author: Dan Haywood <da...@apache.org>
Authored: Fri Mar 1 12:17:19 2013 +0000
Committer: Dan Haywood <da...@apache.org>
Committed: Fri Mar 1 12:17:19 2013 +0000

----------------------------------------------------------------------
 .../sql/common/SqlIntegrationTestCommonBase.java   |   11 +++++
 .../sql/common/SqlIntegrationTestData.java         |   28 +++++++++++-
 .../isis/objectstore/sql/PolymorphismTest.java     |   19 ++++++++-
 .../entity/properties/EntityPropertiesForm.java    |   33 ---------------
 .../integtestsupport/IsisSystemWithFixtures.java   |    1 +
 .../IsisSystemWithFixturesTest_basicTest.java      |    2 +
 .../services/ServicesInjectorDefault.java          |    8 +++-
 .../system/transaction/IsisTransaction.java        |   12 +----
 8 files changed, 67 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/b1d7000a/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestCommonBase.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestCommonBase.java b/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestCommonBase.java
index f6c5e92..2f6a0fe 100755
--- a/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestCommonBase.java
+++ b/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestCommonBase.java
@@ -18,6 +18,9 @@
  */
 package org.apache.isis.objectstore.sql.common;
 
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.assertThat;
+
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
@@ -32,6 +35,7 @@ import org.junit.FixMethodOrder;
 import org.junit.Rule;
 import org.junit.runners.MethodSorters;
 
+import org.apache.isis.core.runtime.system.context.IsisContext;
 import org.apache.isis.core.tck.dom.poly.ReferencingPolyTypesEntity;
 import org.apache.isis.core.tck.dom.sqlos.SqlDomainObjectRepository;
 import org.apache.isis.core.tck.dom.sqlos.data.SqlDataClass;
@@ -150,13 +154,19 @@ public abstract class SqlIntegrationTestCommonBase {
         sqlDataClass = getSqlIntegrationTestFixtures().getSqlDataClass();
         referencingPolyTypesEntity = getSqlIntegrationTestFixtures().getPolyTestClass();
     }
+    
+
 
     // //////////////////////////////////////////////////////////////////////////////
     // after
     // //////////////////////////////////////////////////////////////////////////////
 
+
     @After
     public void tearDown() throws Exception {
+        
+        
+        
         if (!getSqlIntegrationTestFixtures().getState().isInitialize()) {
             return;
         }
@@ -171,6 +181,7 @@ public abstract class SqlIntegrationTestCommonBase {
         getSqlIntegrationTestFixtures().shutDown();
     }
 
+
     /**
      * optional hook
      */

http://git-wip-us.apache.org/repos/asf/isis/blob/b1d7000a/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestData.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestData.java b/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestData.java
index 0b19c9e..687afb4 100644
--- a/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestData.java
+++ b/component/objectstore/sql/sql-tests-common/src/main/java/org/apache/isis/objectstore/sql/common/SqlIntegrationTestData.java
@@ -19,8 +19,10 @@
 
 package org.apache.isis.objectstore.sql.common;
 
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -29,6 +31,8 @@ import java.util.List;
 
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.FixMethodOrder;
 import org.junit.Test;
 import org.junit.runners.MethodSorters;
@@ -42,6 +46,9 @@ import org.apache.isis.applib.value.Password;
 import org.apache.isis.applib.value.Percentage;
 import org.apache.isis.applib.value.Time;
 import org.apache.isis.applib.value.TimeStamp;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.core.runtime.system.transaction.IsisTransaction;
+import org.apache.isis.core.runtime.system.transaction.IsisTransactionManager;
 import org.apache.isis.core.tck.dom.scalars.PrimitiveValuedEntity;
 import org.apache.isis.core.tck.dom.sqlos.SqlDomainObjectRepository;
 import org.apache.isis.core.tck.dom.sqlos.data.SimpleClass;
@@ -76,7 +83,20 @@ public abstract class SqlIntegrationTestData extends SqlIntegrationTestCommonBas
     private static PrimitiveValuedEntity pve1;
     private static PrimitiveValuedEntity pve2;
 
-    @Test
+    
+    @Before
+    public void setUpXactn() throws Exception {
+        IsisContext.getTransactionManager().startTransaction();
+    }
+
+    @After
+    public void tearDownXactn() throws Exception {
+        IsisContext.getTransactionManager().endTransaction();
+        assertThat(IsisContext.getTransactionManager().getTransaction().getState().isComplete(), is(true));
+        
+    }
+
+    
     /**
      * Uses factory methods within the Isis framework to create the test data,
      * thus exercising the "create data" portion of the object store.
@@ -85,6 +105,7 @@ public abstract class SqlIntegrationTestData extends SqlIntegrationTestCommonBas
      * object store is "in-memory" (this is required since "in-memory" has to be
      * left alone for created data to still be present in the next test).
      */
+    @Test
     public void testSetupStore() throws Exception {
         testSetup();
         setUpFactory();
@@ -178,7 +199,6 @@ public abstract class SqlIntegrationTestData extends SqlIntegrationTestCommonBas
         setFixtureInitializationState(State.DONT_INITIALIZE, "in-memory");
     }
 
-    @Test
     /**
      * The actual "tests". Unless the test is using the "in-memory" object store 
      * the Isis framework is re-created, thus ensuring that no domain objects are
@@ -191,7 +211,9 @@ public abstract class SqlIntegrationTestData extends SqlIntegrationTestCommonBas
      * Especially, it confirms that dates, times, etc, do not suffer from differences in
      * time zones between the database and the Isis framework.
      */
+    @Test
     public void testTestAll() throws Exception {
+        
         testLoad();
 
         setUpFactory();
@@ -241,6 +263,8 @@ public abstract class SqlIntegrationTestData extends SqlIntegrationTestCommonBas
 
     private void testLoad() throws Exception {
         final List<SqlDataClass> dataClasses = factory.allDataClasses();
+        IsisContext.getTransactionManager().flushTransaction();
+        
         assertEquals(1, dataClasses.size());
         final SqlDataClass sqlDataClass = dataClasses.get(0);
         getSqlIntegrationTestFixtures().setSqlDataClass(sqlDataClass);

http://git-wip-us.apache.org/repos/asf/isis/blob/b1d7000a/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/PolymorphismTest.java
----------------------------------------------------------------------
diff --git a/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/PolymorphismTest.java b/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/PolymorphismTest.java
index 7f79e44..49039e5 100755
--- a/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/PolymorphismTest.java
+++ b/component/objectstore/sql/sql-tests-common/src/test/java/org/apache/isis/objectstore/sql/PolymorphismTest.java
@@ -18,17 +18,22 @@
  */
 package org.apache.isis.objectstore.sql;
 
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 import java.util.List;
 
+import org.junit.After;
+import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.FixMethodOrder;
 import org.junit.Test;
 import org.junit.runners.MethodSorters;
 
+import org.apache.isis.core.runtime.system.context.IsisContext;
 import org.apache.isis.core.tck.dom.poly.Empty;
 import org.apache.isis.core.tck.dom.poly.EmptyEntityWithOwnProperty;
 import org.apache.isis.core.tck.dom.poly.ReferencingPolyTypesEntity;
@@ -100,6 +105,18 @@ public class PolymorphismTest extends SqlIntegrationTestCommonBase {
         testSetup();
     }
 
+    @Before
+    public void setUpXactn() throws Exception {
+        IsisContext.getTransactionManager().startTransaction();
+    }
+
+    @After
+    public void tearDownXactn() throws Exception {
+        IsisContext.getTransactionManager().endTransaction();
+        assertThat(IsisContext.getTransactionManager().getTransaction().getState().isComplete(), is(true));
+        
+    }
+
     @Test
     /**
      * Uses the database connection to drop database tables related to these tests.
@@ -188,7 +205,6 @@ public class PolymorphismTest extends SqlIntegrationTestCommonBase {
         setFixtureInitializationState(State.DONT_INITIALIZE, "in-memory");
     }
 
-    @Test
     /**
      * The actual "tests". Unless the test is using the "in-memory" object store 
      * the Isis framework is re-created, thus ensuring that no domain objects are
@@ -200,6 +216,7 @@ public class PolymorphismTest extends SqlIntegrationTestCommonBase {
      * Confirms that polymorphic classes are loaded as expected (via interface, 
      * via super-class, etc.)
      */
+    @Test
     public void test3All() throws Exception {
         load();
 

http://git-wip-us.apache.org/repos/asf/isis/blob/b1d7000a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/properties/EntityPropertiesForm.java
----------------------------------------------------------------------
diff --git a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/properties/EntityPropertiesForm.java b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/properties/EntityPropertiesForm.java
index cd2a027..02d6c4f 100644
--- a/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/properties/EntityPropertiesForm.java
+++ b/component/viewer/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/entity/properties/EntityPropertiesForm.java
@@ -110,8 +110,6 @@ class EntityPropertiesForm extends FormAbstract<ObjectAdapter> {
         addPropertiesAndOrCollections();
         addButtons();
         addFeedbackGui();
-
-        addValidator();
     }
 
     private void addPropertiesAndOrCollections() {
@@ -297,18 +295,6 @@ class EntityPropertiesForm extends FormAbstract<ObjectAdapter> {
 
         };
         add(okButton);
-        
-        okButton.add(new IValidator<String>(){
-
-            private static final long serialVersionUID = 1L;
-
-            @Override
-            public void validate(IValidatable<String> validatable) {
-
-
-                //validatable.error(new ValidationError("testing 1,2,3"));
-            }
-        });
 
         cancelButton = new AjaxButton(ID_CANCEL_BUTTON, Model.of("Cancel")) {
             private static final long serialVersionUID = 1L;
@@ -409,25 +395,6 @@ class EntityPropertiesForm extends FormAbstract<ObjectAdapter> {
         }
     }
 
-    private void addValidator() {
-
-        // no longer used, instead using the PreValidate stuff.
-        
-//        add(new AbstractFormValidator() {
-//
-//            private static final long serialVersionUID = 1L;
-//
-//            @Override
-//            public FormComponent<?>[] getDependentFormComponents() {
-//                return new FormComponent<?>[0];
-//            }
-//
-//            @Override
-//            public void validate(final Form<?> form) {
-//            }
-//        });
-    }
-
     private EntityModel getEntityModel() {
         return (EntityModel) getModel();
     }

http://git-wip-us.apache.org/repos/asf/isis/blob/b1d7000a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystemWithFixtures.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystemWithFixtures.java b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystemWithFixtures.java
index 15701b8..3b2d9fb 100644
--- a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystemWithFixtures.java
+++ b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystemWithFixtures.java
@@ -323,6 +323,7 @@ public class IsisSystemWithFixtures implements org.junit.rules.TestRule {
         authenticationSession = authenticationManager.authenticate(authenticationRequest);
 
         IsisContext.openSession(authenticationSession);
+        
         container = getContainer();
         if(firstTime && fixturesInitialization == Fixtures.Initialization.INIT) {
             fixtures.init(container);

http://git-wip-us.apache.org/repos/asf/isis/blob/b1d7000a/core/integtestsupport/src/test/java/org/apache/isis/core/integtestsupport/IsisSystemWithFixturesTest_basicTest.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/test/java/org/apache/isis/core/integtestsupport/IsisSystemWithFixturesTest_basicTest.java b/core/integtestsupport/src/test/java/org/apache/isis/core/integtestsupport/IsisSystemWithFixturesTest_basicTest.java
index dd069b0..cdbfb74 100644
--- a/core/integtestsupport/src/test/java/org/apache/isis/core/integtestsupport/IsisSystemWithFixturesTest_basicTest.java
+++ b/core/integtestsupport/src/test/java/org/apache/isis/core/integtestsupport/IsisSystemWithFixturesTest_basicTest.java
@@ -36,11 +36,13 @@ public class IsisSystemWithFixturesTest_basicTest {
     @Test
     public void savePojo() throws Exception {
 
+        iswf.beginTran();
         assertThat(iswf.container.allInstances(JdkValuedEntity.class).size(), is(0));
         
         iswf.container.persist(iswf.fixtures.jve1);
         
         assertThat(iswf.container.allInstances(JdkValuedEntity.class).size(), is(1));
+        iswf.commitTran();
     }
 
 }

http://git-wip-us.apache.org/repos/asf/isis/blob/b1d7000a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/ServicesInjectorDefault.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/ServicesInjectorDefault.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/ServicesInjectorDefault.java
index 0b656a8..eb28818 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/ServicesInjectorDefault.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/ServicesInjectorDefault.java
@@ -240,12 +240,16 @@ public class ServicesInjectorDefault implements ServicesInjectorSpi {
 
         List<Object> matchingServices = Lists.newArrayList();
         addMatchingTo(serviceClass, services, matchingServices);
-        addMatchingTo(serviceClass, Collections.<Object>singletonList(container), matchingServices);
+        addMatchingTo(serviceClass, singletonListFor(container), matchingServices);
         
         servicesByType.put(serviceClass, matchingServices);
     }
 
-    private void addMatchingTo(Class<?> type, List<Object> candidates, List<Object> filteredServicesAndContainer) {
+    private static List<Object> singletonListFor(Object obj) {
+        return obj!=null? Collections.singletonList(obj): Collections.emptyList();
+    }
+
+    private static void addMatchingTo(Class<?> type, List<Object> candidates, List<Object> filteredServicesAndContainer) {
         Iterable<Object> filteredServices = Iterables.filter(candidates, ofType(type));
         filteredServicesAndContainer.addAll(Lists.newArrayList(filteredServices));
     }

http://git-wip-us.apache.org/repos/asf/isis/blob/b1d7000a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransaction.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransaction.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransaction.java
index 5f89c1c..3442a18 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransaction.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransaction.java
@@ -190,14 +190,14 @@ public class IsisTransaction implements TransactionScopedComponent {
 
     private final UUID guid;
 
-    public IsisTransaction(final IsisTransactionManager transactionManager, final org.apache.isis.core.commons.authentication.MessageBroker messageBroker2, final UpdateNotifier updateNotifier, final TransactionalResource objectStore, final AuditingService auditingService, PublishingServiceWithDefaultPayloadFactories publishingService) {
+    public IsisTransaction(final IsisTransactionManager transactionManager, final org.apache.isis.core.commons.authentication.MessageBroker messageBroker, final UpdateNotifier updateNotifier, final TransactionalResource objectStore, final AuditingService auditingService, PublishingServiceWithDefaultPayloadFactories publishingService) {
         
         ensureThatArg(transactionManager, is(not(nullValue())), "transaction manager is required");
-        ensureThatArg(messageBroker2, is(not(nullValue())), "message broker is required");
+        ensureThatArg(messageBroker, is(not(nullValue())), "message broker is required");
         ensureThatArg(updateNotifier, is(not(nullValue())), "update notifier is required");
 
         this.transactionManager = transactionManager;
-        this.messageBroker = messageBroker2;
+        this.messageBroker = messageBroker;
         this.updateNotifier = updateNotifier;
         this.auditingService = auditingService;
         this.publishingService = publishingService;
@@ -309,12 +309,6 @@ public class IsisTransaction implements TransactionScopedComponent {
         // for example, the JDO object store just lets DataNucleus do the change tracking
         // itself
         
-//        if(commands.isEmpty()) {
-//            // nothing to do
-//            return;
-//        }
-        
-        
         ensureThatState(getState().canFlush(), is(true), "state is: " + getState());
         if (LOG.isDebugEnabled()) {
             LOG.debug("flush transaction " + this);