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 2012/12/06 11:10:35 UTC
[29/51] [partial] ISIS-188: moving modules into core
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/IsisSystemForTest.java
----------------------------------------------------------------------
diff --git a/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/IsisSystemForTest.java b/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/IsisSystemForTest.java
new file mode 100644
index 0000000..4e90833
--- /dev/null
+++ b/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/IsisSystemForTest.java
@@ -0,0 +1,622 @@
+/*
+ * 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.testsupport;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+import com.google.common.collect.Lists;
+
+import org.apache.isis.applib.DomainObjectContainer;
+import org.apache.isis.applib.fixtures.InstallableFixture;
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
+import org.apache.isis.core.metamodel.progmodel.ProgrammingModel;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.specloader.validator.MetaModelValidator;
+import org.apache.isis.core.runtime.authentication.AuthenticationManager;
+import org.apache.isis.core.runtime.authentication.AuthenticationRequest;
+import org.apache.isis.runtimes.dflt.objectstores.dflt.InMemoryPersistenceMechanismInstaller;
+import org.apache.isis.runtimes.dflt.runtime.fixtures.FixturesInstallerDelegate;
+import org.apache.isis.runtimes.dflt.runtime.installerregistry.installerapi.PersistenceMechanismInstaller;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.ObjectStoreSpi;
+import org.apache.isis.runtimes.dflt.runtime.system.DeploymentType;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.Persistor;
+import org.apache.isis.runtimes.dflt.runtime.system.transaction.IsisTransaction;
+import org.apache.isis.runtimes.dflt.runtime.system.transaction.IsisTransaction.State;
+import org.apache.isis.runtimes.dflt.runtime.system.transaction.IsisTransactionManager;
+import org.apache.isis.security.dflt.authentication.AuthenticationRequestDefault;
+
+/**
+ * Wraps a plain {@link IsisSystemDefault}, and provides a number of features to assist with testing.
+ */
+public class IsisSystemForTest implements org.junit.rules.TestRule {
+
+ public interface Listener {
+
+ void init(IsisConfiguration configuration) throws Exception;
+
+ void preSetupSystem(boolean firstTime) throws Exception;
+ void postSetupSystem(boolean firstTime) throws Exception;
+
+ void preBounceSystem() throws Exception;
+ void postBounceSystem() throws Exception;
+
+ void preTeardownSystem() throws Exception;
+ void postTeardownSystem() throws Exception;
+
+ }
+
+ public static abstract class ListenerAdapter implements Listener {
+
+ private IsisConfiguration configuration;
+
+ public void init(IsisConfiguration configuration) throws Exception {
+ this.configuration = configuration;
+ }
+
+ protected IsisConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ @Override
+ public void preSetupSystem(boolean firstTime) throws Exception {
+ }
+
+ @Override
+ public void postSetupSystem(boolean firstTime) throws Exception {
+ }
+
+ @Override
+ public void preBounceSystem() throws Exception {
+ }
+
+ @Override
+ public void postBounceSystem() throws Exception {
+ }
+
+ @Override
+ public void preTeardownSystem() throws Exception {
+ }
+
+ @Override
+ public void postTeardownSystem() throws Exception {
+ }
+
+ }
+
+
+
+
+ private IsisSystemDefault isisSystem;
+ private AuthenticationSession authenticationSession;
+
+ // public visibility just to reduce noise in tests
+ public DomainObjectContainer container;
+
+ private final IsisConfiguration configuration;
+ private final PersistenceMechanismInstaller persistenceMechanismInstaller;
+ private final AuthenticationRequest authenticationRequest;
+ private final List<Object> services;
+ private final List<InstallableFixture> fixtures;
+ private List <Listener> listeners;
+
+ private final MetaModelValidator metaModelValidator;
+ private final ProgrammingModel programmingModel;
+
+
+ ////////////////////////////////////////////////////////////
+ // constructor
+ ////////////////////////////////////////////////////////////
+
+ public static class Builder {
+
+ private AuthenticationRequest authenticationRequest = new AuthenticationRequestDefault("tester");
+
+ private IsisConfiguration configuration;
+ private PersistenceMechanismInstaller persistenceMechanismInstaller = new InMemoryPersistenceMechanismInstaller();
+ private MetaModelValidator metaModelValidator;
+ private ProgrammingModel programmingModel;
+
+ private Object[] services;
+ private InstallableFixture[] fixtures;
+
+ private final List <Listener> listeners = Lists.newArrayList();
+
+ public Builder with(IsisConfiguration configuration) {
+ this.configuration = configuration;
+ return this;
+ }
+
+ public Builder with(PersistenceMechanismInstaller persistenceMechanismInstaller) {
+ this.persistenceMechanismInstaller = persistenceMechanismInstaller;
+ return this;
+ }
+
+ public Builder with(AuthenticationRequest authenticationRequest) {
+ this.authenticationRequest = authenticationRequest;
+ return this;
+ }
+
+ public Builder withServices(Object... services) {
+ this.services = services;
+ return this;
+ }
+
+ public Builder withFixtures(InstallableFixture... fixtures) {
+ this.fixtures = fixtures;
+ return this;
+ }
+
+
+ public IsisSystemForTest build() {
+ final List<Object> servicesIfAny = asList(services);
+ final List<InstallableFixture> fixturesIfAny = asList(fixtures);
+ return new IsisSystemForTest(configuration, programmingModel, metaModelValidator, persistenceMechanismInstaller, authenticationRequest, servicesIfAny, fixturesIfAny, listeners);
+ }
+
+ private static <T> List<T> asList(T[] objects) {
+ return objects != null? Arrays.asList(objects): Collections.<T>emptyList();
+ }
+
+ public Builder with(Listener listener) {
+ if(listener != null) {
+ listeners.add(listener);
+ }
+ return this;
+ }
+
+ public Builder with(MetaModelValidator metaModelValidator) {
+ this.metaModelValidator = metaModelValidator;
+ return this;
+ }
+
+ public Builder with(ProgrammingModel programmingModel) {
+ this.programmingModel = programmingModel;
+ return this;
+ }
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ private IsisSystemForTest(IsisConfiguration configuration, ProgrammingModel programmingModel, MetaModelValidator metaModelValidator, PersistenceMechanismInstaller persistenceMechanismInstaller, AuthenticationRequest authenticationRequest, List<Object> services, List<InstallableFixture> fixtures, List<Listener> listeners) {
+ this.configuration = configuration;
+ this.programmingModel = programmingModel;
+ this.metaModelValidator = metaModelValidator;
+ this.persistenceMechanismInstaller = persistenceMechanismInstaller;
+ this.authenticationRequest = authenticationRequest;
+ this.services = services;
+ this.fixtures = fixtures;
+ this.listeners = listeners;
+ }
+
+
+ ////////////////////////////////////////////////////////////
+ // setup, teardown
+ ////////////////////////////////////////////////////////////
+
+
+ /**
+ * Intended to be called from a test's {@link Before} method.
+ */
+ public void setUpSystem() throws Exception {
+ setUpSystem(FireListeners.FIRE);
+ }
+
+ private void setUpSystem(FireListeners fireListeners) throws Exception {
+ Logger.getRootLogger().setLevel(Level.OFF);
+
+ boolean firstTime = isisSystem == null;
+ if(fireListeners.shouldFire()) {
+ fireInitAndPreSetupSystem(firstTime);
+ }
+
+ if(firstTime) {
+ isisSystem = createIsisSystem(services);
+ isisSystem.init();
+ IsisContext.closeSession();
+ }
+
+ final AuthenticationManager authenticationManager = isisSystem.getSessionFactory().getAuthenticationManager();
+ authenticationSession = authenticationManager.authenticate(authenticationRequest);
+
+ IsisContext.openSession(authenticationSession);
+ container = getContainer();
+
+ wireAndInstallFixtures();
+ if(fireListeners.shouldFire()) {
+ firePostSetupSystem(firstTime);
+ }
+ }
+
+ private void wireAndInstallFixtures() {
+ FixturesInstallerDelegate fid = new FixturesInstallerDelegate(getPersistenceSession());
+ fid.addFixture(fixtures);
+ fid.installFixtures();
+ }
+
+ private enum FireListeners {
+ FIRE,
+ DONT_FIRE;
+ public boolean shouldFire() {
+ return this == FIRE;
+ }
+ }
+
+ private DomainObjectContainer getContainer() {
+ return getPersistenceSession().getServicesInjector().getContainer();
+ }
+
+ /**
+ * Intended to be called from a test's {@link After} method.
+ */
+ public void tearDownSystem() throws Exception {
+ tearDownSystem(FireListeners.FIRE);
+ }
+
+ private void tearDownSystem(final FireListeners fireListeners) throws Exception {
+ if(fireListeners.shouldFire()) {
+ firePreTeardownSystem();
+ }
+ IsisContext.closeSession();
+ if(fireListeners.shouldFire()) {
+ firePostTeardownSystem();
+ }
+ }
+
+ public void bounceSystem() throws Exception {
+ firePreBounceSystem();
+ tearDownSystem(FireListeners.DONT_FIRE);
+ setUpSystem(FireListeners.DONT_FIRE);
+ firePostBounceSystem();
+ }
+
+
+ private IsisSystemDefault createIsisSystem(List<Object> services) {
+ final IsisSystemDefault system = new IsisSystemDefault(DeploymentType.UNIT_TESTING, services) {
+ @Override
+ public IsisConfiguration getConfiguration() {
+ if(IsisSystemForTest.this.configuration != null) {
+ return IsisSystemForTest.this.configuration;
+ } else {
+ return super.getConfiguration();
+ }
+ }
+ @Override
+ protected ProgrammingModel obtainReflectorProgrammingModel() {
+ if(IsisSystemForTest.this.programmingModel != null) {
+ return IsisSystemForTest.this.programmingModel;
+ } else {
+ return super.obtainReflectorProgrammingModel();
+ }
+ }
+ @Override
+ protected MetaModelValidator obtainReflectorMetaModelValidator() {
+ if(IsisSystemForTest.this.metaModelValidator != null) {
+ return IsisSystemForTest.this.metaModelValidator;
+ } else {
+ return super.obtainReflectorMetaModelValidator();
+ }
+ }
+ @Override
+ protected PersistenceMechanismInstaller obtainPersistenceMechanismInstaller(IsisConfiguration configuration) {
+ final PersistenceMechanismInstaller installer = IsisSystemForTest.this.persistenceMechanismInstaller;
+ configuration.injectInto(installer);
+ return installer;
+ }
+ };
+ return system;
+ }
+
+
+
+ ////////////////////////////////////////////////////////////
+ // listeners
+ ////////////////////////////////////////////////////////////
+
+ private void fireInitAndPreSetupSystem(boolean firstTime) throws Exception {
+ if(firstTime) {
+ for(Listener listener: listeners) {
+ listener.init(configuration);
+ }
+ }
+ for(Listener listener: listeners) {
+ listener.preSetupSystem(firstTime);
+ }
+ }
+
+ private void firePostSetupSystem(boolean firstTime) throws Exception {
+ for(Listener listener: listeners) {
+ listener.postSetupSystem(firstTime);
+ }
+ }
+
+ private void firePreTeardownSystem() throws Exception {
+ for(Listener listener: listeners) {
+ listener.preTeardownSystem();
+ }
+ }
+
+ private void firePostTeardownSystem() throws Exception {
+ for(Listener listener: listeners) {
+ listener.postTeardownSystem();
+ }
+ }
+
+ private void firePreBounceSystem() throws Exception {
+ for(Listener listener: listeners) {
+ listener.preBounceSystem();
+ }
+ }
+
+ private void firePostBounceSystem() throws Exception {
+ for(Listener listener: listeners) {
+ listener.postBounceSystem();
+ }
+ }
+
+
+ ////////////////////////////////////////////////////////////
+ // properties
+ ////////////////////////////////////////////////////////////
+
+ /**
+ * The {@link IsisSystemDefault} created during {@link #setUpSystem()}.
+ *
+ * <p>
+ * Can fine-tune the actual implementation using the hook {@link #createIsisSystem()}.
+ */
+ public IsisSystemDefault getIsisSystem() {
+ return isisSystem;
+ }
+
+ /**
+ * The {@link AuthenticationSession} created during {@link #setUpSystem()}.
+ *
+ * <p>
+ * Can fine-tune before hand using {@link #createAuthenticationRequest()}.
+ */
+ public AuthenticationSession getAuthenticationSession() {
+ return authenticationSession;
+ }
+
+
+
+ ////////////////////////////////////////////////////////////
+ // Convenience for tests
+ ////////////////////////////////////////////////////////////
+
+ public ObjectSpecification loadSpecification(Class<?> cls) {
+ return getIsisSystem().getSessionFactory().getSpecificationLoader().loadSpecification(cls);
+ }
+
+ public ObjectAdapter persist(Object domainObject) {
+ ensureSessionInProgress();
+ ensureObjectIsNotPersistent(domainObject);
+ container.persist(domainObject);
+ return adapterFor(domainObject);
+ }
+
+ public ObjectAdapter destroy(Object domainObject ) {
+ ensureSessionInProgress();
+ ensureObjectIsPersistent(domainObject);
+ container.remove(domainObject);
+ return adapterFor(domainObject);
+ }
+
+ public ObjectAdapter adapterFor(Object domainObject) {
+ ensureSessionInProgress();
+ return getAdapterManager().adapterFor(domainObject);
+ }
+
+ public ObjectAdapter reload(RootOid oid) {
+ ensureSessionInProgress();
+ final Persistor persistenceSession = getPersistenceSession();
+ return persistenceSession.loadObject(oid);
+ }
+
+ public ObjectAdapter recreateAdapter(RootOid oid) {
+ ensureSessionInProgress();
+ return getAdapterManager().adapterFor(oid);
+ }
+
+ public ObjectAdapter remapAsPersistent(Object pojo, RootOid persistentOid) {
+ ensureSessionInProgress();
+ ensureObjectIsNotPersistent(pojo);
+ final ObjectAdapter adapter = adapterFor(pojo);
+ getPersistenceSession().remapAsPersistent(adapter, persistentOid);
+ return adapter;
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T extends ObjectStoreSpi> T getObjectStore(Class<T> cls) {
+ final PersistenceSession persistenceSession = getPersistenceSession();
+ return (T) persistenceSession.getObjectStore();
+ }
+
+ private static void ensureSessionInProgress() {
+ if(!IsisContext.inSession()) {
+ throw new IllegalStateException("Session must be in progress");
+ }
+ }
+
+ private void ensureObjectIsNotPersistent(Object domainObject) {
+ if(container.isPersistent(domainObject)) {
+ throw new IllegalArgumentException("domain object is already persistent");
+ }
+ }
+
+ private void ensureObjectIsPersistent(Object domainObject) {
+ if(!container.isPersistent(domainObject)) {
+ throw new IllegalArgumentException("domain object is not persistent");
+ }
+ }
+
+ ////////////////////////////////////////////////////////////
+ // JUnit @Rule integration
+ ////////////////////////////////////////////////////////////
+
+ @Override
+ public Statement apply(final Statement base, Description description) {
+ return new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ setUpSystem();
+ try {
+ base.evaluate();
+ tearDownSystem();
+ } catch(Throwable ex) {
+ try {
+ tearDownSystem();
+ } catch(Exception ex2) {
+ // ignore, since already one pending
+ }
+ throw ex;
+ }
+ }
+ };
+ }
+
+
+
+ public void beginTran() {
+ final IsisTransactionManager transactionManager = getTransactionManager();
+ final IsisTransaction transaction = transactionManager.getTransaction();
+
+ if(transaction == null) {
+ transactionManager.startTransaction();
+ return;
+ }
+
+ final State state = transaction.getState();
+ switch(state) {
+ case COMMITTED:
+ case ABORTED:
+ transactionManager.startTransaction();
+ break;
+ case IN_PROGRESS:
+ // nothing to do
+ break;
+ case MUST_ABORT:
+ Assert.fail("Transaction is in state of '" + state + "'");
+ break;
+ default:
+ Assert.fail("Unknown transaction state '" + state + "'");
+ }
+
+ }
+
+ public void commitTran() {
+ final IsisTransactionManager transactionManager = getTransactionManager();
+ final IsisTransaction transaction = transactionManager.getTransaction();
+ if(transaction == null) {
+ Assert.fail("No transaction exists");
+ return;
+ }
+ final State state = transaction.getState();
+ switch(state) {
+ case COMMITTED:
+ case ABORTED:
+ case MUST_ABORT:
+ Assert.fail("Transaction is in state of '" + state + "'");
+ break;
+ case IN_PROGRESS:
+ transactionManager.endTransaction();
+ break;
+ default:
+ Assert.fail("Unknown transaction state '" + state + "'");
+ }
+ }
+
+ public void abortTran() {
+ final IsisTransactionManager transactionManager = getTransactionManager();
+ final IsisTransaction transaction = transactionManager.getTransaction();
+ if(transaction == null) {
+ Assert.fail("No transaction exists");
+ return;
+ }
+ final State state = transaction.getState();
+ switch(state) {
+ case ABORTED:
+ break;
+ case COMMITTED:
+ Assert.fail("Transaction is in state of '" + state + "'");
+ break;
+ case MUST_ABORT:
+ case IN_PROGRESS:
+ transactionManager.abortTransaction();
+ break;
+ default:
+ Assert.fail("Unknown transaction state '" + state + "'");
+ }
+ }
+
+
+
+
+ @SuppressWarnings("unchecked")
+ public <T> T getService(Class<T> serviceClass) {
+ List<ObjectAdapter> servicesAdapters = getPersistenceSession().getServices();
+ for(ObjectAdapter serviceAdapter: servicesAdapters) {
+ Object servicePojo = serviceAdapter.getObject();
+ if(serviceClass.isAssignableFrom(servicePojo.getClass())) {
+ return (T) servicePojo;
+ }
+ }
+ throw new RuntimeException("Could not find a service of type: " + serviceClass.getName());
+ }
+
+
+
+ protected IsisTransactionManager getTransactionManager() {
+ return getPersistenceSession().getTransactionManager();
+ }
+
+ public Persistor getPersistor() {
+ return getPersistenceSession();
+ }
+
+ public AdapterManager getAdapterManager() {
+ return getPersistor().getAdapterManager();
+ }
+
+ protected PersistenceSession getPersistenceSession() {
+ return IsisContext.getPersistenceSession();
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/IsisSystemWithFixtures.java
----------------------------------------------------------------------
diff --git a/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/IsisSystemWithFixtures.java b/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/IsisSystemWithFixtures.java
new file mode 100644
index 0000000..53d1a1b
--- /dev/null
+++ b/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/IsisSystemWithFixtures.java
@@ -0,0 +1,669 @@
+/*
+ * 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.testsupport;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.isis.applib.DomainObjectContainer;
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
+import org.apache.isis.core.metamodel.progmodel.ProgrammingModel;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.specloader.validator.MetaModelValidator;
+import org.apache.isis.core.runtime.authentication.AuthenticationManager;
+import org.apache.isis.core.runtime.authentication.AuthenticationRequest;
+import org.apache.isis.runtimes.dflt.objectstores.dflt.InMemoryPersistenceMechanismInstaller;
+import org.apache.isis.runtimes.dflt.runtime.installerregistry.installerapi.PersistenceMechanismInstaller;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.ObjectStoreSpi;
+import org.apache.isis.runtimes.dflt.runtime.system.DeploymentType;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.Persistor;
+import org.apache.isis.runtimes.dflt.runtime.system.transaction.IsisTransaction;
+import org.apache.isis.runtimes.dflt.runtime.system.transaction.IsisTransaction.State;
+import org.apache.isis.runtimes.dflt.runtime.system.transaction.IsisTransactionManager;
+import org.apache.isis.runtimes.dflt.testsupport.IsisSystemWithFixtures.Fixtures.Initialization;
+import org.apache.isis.security.dflt.authentication.AuthenticationRequestDefault;
+import org.apache.isis.tck.dom.refs.AggregatedEntity;
+import org.apache.isis.tck.dom.refs.ParentEntity;
+import org.apache.isis.tck.dom.refs.ParentEntityRepository;
+import org.apache.isis.tck.dom.refs.ReferencingEntity;
+import org.apache.isis.tck.dom.refs.SimpleEntity;
+import org.apache.isis.tck.dom.scalars.ApplibValuedEntity;
+import org.apache.isis.tck.dom.scalars.JdkValuedEntity;
+import org.apache.isis.tck.dom.scalars.PrimitiveValuedEntity;
+import org.apache.isis.tck.dom.scalars.WrapperValuedEntity;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+import com.google.common.collect.Lists;
+
+/**
+ * Wraps a plain {@link IsisSystemDefault}, and provides a number of features to assist with testing.
+ *
+ * <p>
+ * TODO: need to make inherit from the {@link IsisSystemForTest}.
+ */
+public class IsisSystemWithFixtures implements org.junit.rules.TestRule {
+
+ public interface Listener {
+
+ void init(IsisConfiguration configuration) throws Exception;
+
+ void preSetupSystem(boolean firstTime) throws Exception;
+ void postSetupSystem(boolean firstTime) throws Exception;
+
+ void preBounceSystem() throws Exception;
+ void postBounceSystem() throws Exception;
+
+ void preTeardownSystem() throws Exception;
+ void postTeardownSystem() throws Exception;
+
+ }
+
+ public static abstract class ListenerAdapter implements Listener {
+
+ private IsisConfiguration configuration;
+
+ public void init(IsisConfiguration configuration) throws Exception {
+ this.configuration = configuration;
+ }
+
+ protected IsisConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ @Override
+ public void preSetupSystem(boolean firstTime) throws Exception {
+ }
+
+ @Override
+ public void postSetupSystem(boolean firstTime) throws Exception {
+ }
+
+ @Override
+ public void preBounceSystem() throws Exception {
+ }
+
+ @Override
+ public void postBounceSystem() throws Exception {
+ }
+
+ @Override
+ public void preTeardownSystem() throws Exception {
+ }
+
+ @Override
+ public void postTeardownSystem() throws Exception {
+ }
+
+ }
+
+
+
+ /**
+ * A precanned set of fixtures for use by tests if desired.
+ */
+ public static class Fixtures {
+
+ public enum Initialization {
+ INIT,
+ NO_INIT
+ }
+
+ public ParentEntityRepository associatedEntitiesRepository = new ParentEntityRepository();
+
+ public ApplibValuedEntity ave1, ave2;
+ public JdkValuedEntity jve1, jve2;
+ public PrimitiveValuedEntity pve1, pve2;
+ public WrapperValuedEntity wve1, wve2;
+
+ public SimpleEntity smpl1, smpl2, smpl3, smpl4, smpl5, smpl6;
+ public ReferencingEntity rfcg1, rfcg2, rfcg3, rfcg4, rfcg5, rfcg6;
+ public ParentEntity prnt1, prnt2, prnt3, prnt4, prnt5, prnt6;
+ public AggregatedEntity rfcg1_a1, rfcg1_a2, rfcg1_a3, prnt1_a1, prnt1_a2, prnt1_a3;
+
+ private void init(DomainObjectContainer container) {
+ ave1 = container.newTransientInstance(ApplibValuedEntity.class);
+ ave2 = container.newTransientInstance(ApplibValuedEntity.class);
+
+ jve1 = container.newTransientInstance(JdkValuedEntity.class);
+ jve2 = container.newTransientInstance(JdkValuedEntity.class);
+
+ pve1 = container.newTransientInstance(PrimitiveValuedEntity.class);
+ pve2 = container.newTransientInstance(PrimitiveValuedEntity.class);
+
+ wve1 = container.newTransientInstance(WrapperValuedEntity.class);
+ wve2 = container.newTransientInstance(WrapperValuedEntity.class);
+
+ smpl1 = container.newTransientInstance(SimpleEntity.class);
+ smpl2 = container.newTransientInstance(SimpleEntity.class);
+ smpl3 = container.newTransientInstance(SimpleEntity.class);
+ smpl4 = container.newTransientInstance(SimpleEntity.class);
+ smpl5 = container.newTransientInstance(SimpleEntity.class);
+ smpl6 = container.newTransientInstance(SimpleEntity.class);
+ rfcg1 = container.newTransientInstance(ReferencingEntity.class);
+ rfcg2 = container.newTransientInstance(ReferencingEntity.class);
+ rfcg3 = container.newTransientInstance(ReferencingEntity.class);
+ rfcg4 = container.newTransientInstance(ReferencingEntity.class);
+ rfcg5 = container.newTransientInstance(ReferencingEntity.class);
+ rfcg6 = container.newTransientInstance(ReferencingEntity.class);
+ prnt1 = container.newTransientInstance(ParentEntity.class);
+ prnt2 = container.newTransientInstance(ParentEntity.class);
+ prnt3 = container.newTransientInstance(ParentEntity.class);
+ prnt4 = container.newTransientInstance(ParentEntity.class);
+ prnt5 = container.newTransientInstance(ParentEntity.class);
+ prnt6 = container.newTransientInstance(ParentEntity.class);
+ rfcg1_a1 = container.newAggregatedInstance(rfcg1, AggregatedEntity.class);
+ rfcg1_a2 = container.newAggregatedInstance(rfcg1, AggregatedEntity.class);
+ rfcg1_a3 = container.newAggregatedInstance(rfcg1, AggregatedEntity.class);
+ prnt1_a1 = container.newAggregatedInstance(prnt1, AggregatedEntity.class);
+ prnt1_a2 = container.newAggregatedInstance(prnt1, AggregatedEntity.class);
+ prnt1_a3 = container.newAggregatedInstance(prnt1, AggregatedEntity.class);
+ }
+ }
+
+ private IsisSystemDefault isisSystem;
+ private AuthenticationSession authenticationSession;
+
+ // public visibility just to reduce noise in tests
+ public DomainObjectContainer container;
+ // public visibility just to reduce noise in tests
+ public final Fixtures fixtures;
+
+ private Initialization fixturesInitialization;
+ private final IsisConfiguration configuration;
+ private final PersistenceMechanismInstaller persistenceMechanismInstaller;
+ private final AuthenticationRequest authenticationRequest;
+ private final List<Object> services;
+ private List <Listener> listeners;
+ private final MetaModelValidator metaModelValidator;
+ private final ProgrammingModel programmingModel;
+
+
+ ////////////////////////////////////////////////////////////
+ // constructor
+ ////////////////////////////////////////////////////////////
+
+ public static class Builder {
+
+ private AuthenticationRequest authenticationRequest = new AuthenticationRequestDefault("tester");
+
+ private Initialization fixturesInitialization = Initialization.INIT;
+ private IsisConfiguration configuration;
+ private PersistenceMechanismInstaller persistenceMechanismInstaller = new InMemoryPersistenceMechanismInstaller();
+ private MetaModelValidator metaModelValidator;
+ private ProgrammingModel programmingModel;
+
+ private final List <Listener> listeners = Lists.newArrayList();
+ private Object[] services;
+
+
+ public Builder with(IsisConfiguration configuration) {
+ this.configuration = configuration;
+ return this;
+ }
+
+ public Builder with(Initialization initialization) {
+ this.fixturesInitialization = initialization;
+ return this;
+ }
+
+ public Builder with(PersistenceMechanismInstaller persistenceMechanismInstaller) {
+ this.persistenceMechanismInstaller = persistenceMechanismInstaller;
+ return this;
+ }
+
+ public Builder with(AuthenticationRequest authenticationRequest) {
+ this.authenticationRequest = authenticationRequest;
+ return this;
+ }
+
+ public Builder withServices(Object... services) {
+ this.services = services;
+ return this;
+ }
+
+ public IsisSystemWithFixtures build() {
+ final List<Object> servicesIfAny = services != null? Arrays.asList(services): null;
+ return new IsisSystemWithFixtures(fixturesInitialization, configuration, programmingModel, metaModelValidator, persistenceMechanismInstaller, authenticationRequest, servicesIfAny, listeners);
+ }
+
+ public Builder with(Listener listener) {
+ if(listener != null) {
+ listeners.add(listener);
+ }
+ return this;
+ }
+
+ public Builder with(MetaModelValidator metaModelValidator) {
+ this.metaModelValidator = metaModelValidator;
+ return this;
+ }
+
+ public Builder with(ProgrammingModel programmingModel) {
+ this.programmingModel = programmingModel;
+ return this;
+ }
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ private IsisSystemWithFixtures(Initialization fixturesInitialization, IsisConfiguration configuration, ProgrammingModel programmingModel, MetaModelValidator metaModelValidator, PersistenceMechanismInstaller persistenceMechanismInstaller, AuthenticationRequest authenticationRequest, List<Object> services, List<Listener> listeners) {
+ this.fixturesInitialization = fixturesInitialization;
+ this.configuration = configuration;
+ this.programmingModel = programmingModel;
+ this.metaModelValidator = metaModelValidator;
+ this.persistenceMechanismInstaller = persistenceMechanismInstaller;
+ this.authenticationRequest = authenticationRequest;
+ this.fixtures = new Fixtures();
+ if(services == null) {
+ services = Arrays.asList((Object)fixtures.associatedEntitiesRepository);
+ }
+ this.services = services;
+ this.listeners = listeners;
+ }
+
+
+ ////////////////////////////////////////////////////////////
+ // setup, teardown
+ ////////////////////////////////////////////////////////////
+
+
+ /**
+ * Intended to be called from a test's {@link Before} method.
+ */
+ public void setUpSystem() throws Exception {
+ setUpSystem(FireListeners.FIRE);
+ }
+
+ private void setUpSystem(FireListeners fireListeners) throws Exception {
+ Logger.getRootLogger().setLevel(Level.OFF);
+
+ boolean firstTime = isisSystem == null;
+ if(fireListeners.shouldFire()) {
+ fireInitAndPreSetupSystem(firstTime);
+ }
+
+ if(firstTime) {
+ isisSystem = createIsisSystem(services);
+ isisSystem.init();
+ IsisContext.closeSession();
+ }
+
+ final AuthenticationManager authenticationManager = isisSystem.getSessionFactory().getAuthenticationManager();
+ authenticationSession = authenticationManager.authenticate(authenticationRequest);
+
+ IsisContext.openSession(authenticationSession);
+ container = getContainer();
+ if(firstTime && fixturesInitialization == Fixtures.Initialization.INIT) {
+ fixtures.init(container);
+ }
+ if(fireListeners.shouldFire()) {
+ firePostSetupSystem(firstTime);
+ }
+ }
+
+ private enum FireListeners {
+ FIRE,
+ DONT_FIRE;
+ public boolean shouldFire() {
+ return this == FIRE;
+ }
+ }
+
+ private DomainObjectContainer getContainer() {
+ return getPersistenceSession().getServicesInjector().getContainer();
+ }
+
+ /**
+ * Intended to be called from a test's {@link After} method.
+ */
+ public void tearDownSystem() throws Exception {
+ tearDownSystem(FireListeners.FIRE);
+ }
+
+ private void tearDownSystem(final FireListeners fireListeners) throws Exception {
+ if(fireListeners.shouldFire()) {
+ firePreTeardownSystem();
+ }
+ IsisContext.closeSession();
+ if(fireListeners.shouldFire()) {
+ firePostTeardownSystem();
+ }
+ }
+
+ public void bounceSystem() throws Exception {
+ firePreBounceSystem();
+ tearDownSystem(FireListeners.DONT_FIRE);
+ setUpSystem(FireListeners.DONT_FIRE);
+ firePostBounceSystem();
+ }
+
+
+ private IsisSystemDefault createIsisSystem(List<Object> services) {
+ final IsisSystemDefault system = new IsisSystemDefault(DeploymentType.UNIT_TESTING, services) {
+ @Override
+ public IsisConfiguration getConfiguration() {
+ if(IsisSystemWithFixtures.this.configuration != null) {
+ return IsisSystemWithFixtures.this.configuration;
+ } else {
+ return super.getConfiguration();
+ }
+ }
+ @Override
+ protected ProgrammingModel obtainReflectorProgrammingModel() {
+ if(IsisSystemWithFixtures.this.programmingModel != null) {
+ return IsisSystemWithFixtures.this.programmingModel;
+ } else {
+ return super.obtainReflectorProgrammingModel();
+ }
+ }
+ @Override
+ protected MetaModelValidator obtainReflectorMetaModelValidator() {
+ if(IsisSystemWithFixtures.this.metaModelValidator != null) {
+ return IsisSystemWithFixtures.this.metaModelValidator;
+ } else {
+ return super.obtainReflectorMetaModelValidator();
+ }
+ }
+ @Override
+ protected PersistenceMechanismInstaller obtainPersistenceMechanismInstaller(IsisConfiguration configuration) {
+ final PersistenceMechanismInstaller installer = IsisSystemWithFixtures.this.persistenceMechanismInstaller;
+ configuration.injectInto(installer);
+ return installer;
+ }
+ };
+ return system;
+ }
+
+
+
+ ////////////////////////////////////////////////////////////
+ // listeners
+ ////////////////////////////////////////////////////////////
+
+ private void fireInitAndPreSetupSystem(boolean firstTime) throws Exception {
+ if(firstTime) {
+ for(Listener listener: listeners) {
+ listener.init(configuration);
+ }
+ }
+ for(Listener listener: listeners) {
+ listener.preSetupSystem(firstTime);
+ }
+ }
+
+ private void firePostSetupSystem(boolean firstTime) throws Exception {
+ for(Listener listener: listeners) {
+ listener.postSetupSystem(firstTime);
+ }
+ }
+
+ private void firePreTeardownSystem() throws Exception {
+ for(Listener listener: listeners) {
+ listener.preTeardownSystem();
+ }
+ }
+
+ private void firePostTeardownSystem() throws Exception {
+ for(Listener listener: listeners) {
+ listener.postTeardownSystem();
+ }
+ }
+
+ private void firePreBounceSystem() throws Exception {
+ for(Listener listener: listeners) {
+ listener.preBounceSystem();
+ }
+ }
+
+ private void firePostBounceSystem() throws Exception {
+ for(Listener listener: listeners) {
+ listener.postBounceSystem();
+ }
+ }
+
+
+ ////////////////////////////////////////////////////////////
+ // properties
+ ////////////////////////////////////////////////////////////
+
+ /**
+ * The {@link IsisSystemDefault} created during {@link #setUpSystem()}.
+ *
+ * <p>
+ * Can fine-tune the actual implementation using the hook {@link #createIsisSystem()}.
+ */
+ public IsisSystemDefault getIsisSystem() {
+ return isisSystem;
+ }
+
+ /**
+ * The {@link AuthenticationSession} created during {@link #setUpSystem()}.
+ *
+ * <p>
+ * Can fine-tune before hand using {@link #createAuthenticationRequest()}.
+ */
+ public AuthenticationSession getAuthenticationSession() {
+ return authenticationSession;
+ }
+
+
+
+ ////////////////////////////////////////////////////////////
+ // Convenience for tests
+ ////////////////////////////////////////////////////////////
+
+ public ObjectSpecification loadSpecification(Class<?> cls) {
+ return getIsisSystem().getSessionFactory().getSpecificationLoader().loadSpecification(cls);
+ }
+
+ public ObjectAdapter persist(Object domainObject) {
+ ensureSessionInProgress();
+ ensureObjectIsNotPersistent(domainObject);
+ container.persist(domainObject);
+ return adapterFor(domainObject);
+ }
+
+ public ObjectAdapter destroy(Object domainObject ) {
+ ensureSessionInProgress();
+ ensureObjectIsPersistent(domainObject);
+ container.remove(domainObject);
+ return adapterFor(domainObject);
+ }
+
+ public ObjectAdapter adapterFor(Object domainObject) {
+ ensureSessionInProgress();
+ return getAdapterManager().adapterFor(domainObject);
+ }
+
+ public ObjectAdapter reload(RootOid oid) {
+ ensureSessionInProgress();
+ final Persistor persistenceSession = getPersistenceSession();
+ return persistenceSession.loadObject(oid);
+ }
+
+ public ObjectAdapter recreateAdapter(RootOid oid) {
+ ensureSessionInProgress();
+ return getAdapterManager().adapterFor(oid);
+ }
+
+ public ObjectAdapter remapAsPersistent(Object pojo, RootOid persistentOid) {
+ ensureSessionInProgress();
+ ensureObjectIsNotPersistent(pojo);
+ final ObjectAdapter adapter = adapterFor(pojo);
+ getPersistenceSession().remapAsPersistent(adapter, persistentOid);
+ return adapter;
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T extends ObjectStoreSpi> T getObjectStore(Class<T> cls) {
+ final PersistenceSession persistenceSession = getPersistenceSession();
+ return (T) persistenceSession.getObjectStore();
+ }
+
+ private static void ensureSessionInProgress() {
+ if(!IsisContext.inSession()) {
+ throw new IllegalStateException("Session must be in progress");
+ }
+ }
+
+ private void ensureObjectIsNotPersistent(Object domainObject) {
+ if(container.isPersistent(domainObject)) {
+ throw new IllegalArgumentException("domain object is already persistent");
+ }
+ }
+
+ private void ensureObjectIsPersistent(Object domainObject) {
+ if(!container.isPersistent(domainObject)) {
+ throw new IllegalArgumentException("domain object is not persistent");
+ }
+ }
+
+ ////////////////////////////////////////////////////////////
+ // JUnit @Rule integration
+ ////////////////////////////////////////////////////////////
+
+ @Override
+ public Statement apply(final Statement base, Description description) {
+ return new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ setUpSystem();
+ try {
+ base.evaluate();
+ tearDownSystem();
+ } catch(Throwable ex) {
+ try {
+ tearDownSystem();
+ } catch(Exception ex2) {
+ // ignore, since already one pending
+ }
+ throw ex;
+ }
+ }
+ };
+ }
+
+
+
+ public void beginTran() {
+ final IsisTransactionManager transactionManager = getTransactionManager();
+ final IsisTransaction transaction = transactionManager.getTransaction();
+
+ if(transaction == null) {
+ transactionManager.startTransaction();
+ return;
+ }
+
+ final State state = transaction.getState();
+ switch(state) {
+ case COMMITTED:
+ case ABORTED:
+ transactionManager.startTransaction();
+ break;
+ case IN_PROGRESS:
+ // nothing to do
+ break;
+ case MUST_ABORT:
+ Assert.fail("Transaction is in state of '" + state + "'");
+ break;
+ default:
+ Assert.fail("Unknown transaction state '" + state + "'");
+ }
+
+ }
+
+ public void commitTran() {
+ final IsisTransactionManager transactionManager = getTransactionManager();
+ final IsisTransaction transaction = transactionManager.getTransaction();
+ if(transaction == null) {
+ Assert.fail("No transaction exists");
+ return;
+ }
+ final State state = transaction.getState();
+ switch(state) {
+ case COMMITTED:
+ case ABORTED:
+ case MUST_ABORT:
+ Assert.fail("Transaction is in state of '" + state + "'");
+ break;
+ case IN_PROGRESS:
+ transactionManager.endTransaction();
+ break;
+ default:
+ Assert.fail("Unknown transaction state '" + state + "'");
+ }
+ }
+
+ public void abortTran() {
+ final IsisTransactionManager transactionManager = getTransactionManager();
+ final IsisTransaction transaction = transactionManager.getTransaction();
+ if(transaction == null) {
+ Assert.fail("No transaction exists");
+ return;
+ }
+ final State state = transaction.getState();
+ switch(state) {
+ case ABORTED:
+ break;
+ case COMMITTED:
+ Assert.fail("Transaction is in state of '" + state + "'");
+ break;
+ case MUST_ABORT:
+ case IN_PROGRESS:
+ transactionManager.abortTransaction();
+ break;
+ default:
+ Assert.fail("Unknown transaction state '" + state + "'");
+ }
+ }
+
+ protected IsisTransactionManager getTransactionManager() {
+ return getPersistenceSession().getTransactionManager();
+ }
+
+ public Persistor getPersistor() {
+ return getPersistenceSession();
+ }
+
+ public AdapterManager getAdapterManager() {
+ return getPersistor().getAdapterManager();
+ }
+
+ protected PersistenceSession getPersistenceSession() {
+ return IsisContext.getPersistenceSession();
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/noop/AuthenticationManagerNoop.java
----------------------------------------------------------------------
diff --git a/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/noop/AuthenticationManagerNoop.java b/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/noop/AuthenticationManagerNoop.java
new file mode 100644
index 0000000..0946015
--- /dev/null
+++ b/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/noop/AuthenticationManagerNoop.java
@@ -0,0 +1,65 @@
+/*
+ * 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.testsupport.noop;
+
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.commons.components.Noop;
+import org.apache.isis.core.runtime.authentication.AuthenticationManager;
+import org.apache.isis.core.runtime.authentication.AuthenticationRequest;
+import org.apache.isis.core.runtime.authentication.RegistrationDetails;
+
+public class AuthenticationManagerNoop implements AuthenticationManager, Noop {
+
+ @Override
+ public void init() {
+ }
+
+ @Override
+ public void shutdown() {
+ }
+
+ @Override
+ public AuthenticationSession authenticate(final AuthenticationRequest request) {
+ return null;
+ }
+
+ @Override
+ public void closeSession(final AuthenticationSession session) {
+ }
+
+ @Override
+ public boolean isSessionValid(final AuthenticationSession session) {
+ return false;
+ }
+
+ public void testSetSession(final AuthenticationSession authenticationSession) {
+ }
+
+ @Override
+ public boolean register(final RegistrationDetails registrationDetails) {
+ return false;
+ }
+
+ @Override
+ public boolean supportsRegistration(final Class<? extends RegistrationDetails> registrationDetailsClass) {
+ return false;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/noop/AuthorizationManagerNoop.java
----------------------------------------------------------------------
diff --git a/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/noop/AuthorizationManagerNoop.java b/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/noop/AuthorizationManagerNoop.java
new file mode 100644
index 0000000..7858de5
--- /dev/null
+++ b/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/noop/AuthorizationManagerNoop.java
@@ -0,0 +1,47 @@
+/*
+ * 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.testsupport.noop;
+
+import org.apache.isis.applib.Identifier;
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.runtime.authorization.AuthorizationManager;
+
+public class AuthorizationManagerNoop implements AuthorizationManager {
+
+ @Override
+ public void init() {
+ }
+
+ @Override
+ public void shutdown() {
+ }
+
+ @Override
+ public boolean isUsable(final AuthenticationSession session, final ObjectAdapter target, final Identifier identifier) {
+ return true;
+ }
+
+ @Override
+ public boolean isVisible(final AuthenticationSession session, final ObjectAdapter target, final Identifier identifier) {
+ return true;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/noop/TemplateImageLoaderNoop.java
----------------------------------------------------------------------
diff --git a/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/noop/TemplateImageLoaderNoop.java b/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/noop/TemplateImageLoaderNoop.java
new file mode 100644
index 0000000..54a68e9
--- /dev/null
+++ b/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/noop/TemplateImageLoaderNoop.java
@@ -0,0 +1,44 @@
+/*
+ * 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.testsupport.noop;
+
+import org.apache.isis.core.commons.components.Noop;
+import org.apache.isis.core.runtime.imageloader.TemplateImage;
+import org.apache.isis.core.runtime.imageloader.TemplateImageLoader;
+
+/**
+ * No-op implementation, for tests.
+ */
+public class TemplateImageLoaderNoop implements TemplateImageLoader, Noop {
+
+ @Override
+ public TemplateImage getTemplateImage(final String name) {
+ return null;
+ }
+
+ @Override
+ public void init() {
+ }
+
+ @Override
+ public void shutdown() {
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/noop/TemplateImageLoaderNoopInstaller.java
----------------------------------------------------------------------
diff --git a/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/noop/TemplateImageLoaderNoopInstaller.java b/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/noop/TemplateImageLoaderNoopInstaller.java
new file mode 100644
index 0000000..31bca71
--- /dev/null
+++ b/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/noop/TemplateImageLoaderNoopInstaller.java
@@ -0,0 +1,44 @@
+/*
+ * 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.testsupport.noop;
+
+import java.util.List;
+
+import org.apache.isis.core.commons.config.InstallerAbstract;
+import org.apache.isis.core.runtime.imageloader.TemplateImageLoader;
+import org.apache.isis.core.runtime.imageloader.TemplateImageLoaderInstaller;
+
+public class TemplateImageLoaderNoopInstaller extends InstallerAbstract implements TemplateImageLoaderInstaller {
+
+ public TemplateImageLoaderNoopInstaller() {
+ super(TemplateImageLoaderInstaller.TYPE, "noop");
+ }
+
+ @Override
+ public TemplateImageLoader createLoader() {
+ return new TemplateImageLoaderNoop();
+ }
+
+ @Override
+ public List<Class<?>> getTypes() {
+ return listOf(TemplateImageLoader.class);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/noop/UserProfileStoreNoop.java
----------------------------------------------------------------------
diff --git a/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/noop/UserProfileStoreNoop.java b/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/noop/UserProfileStoreNoop.java
new file mode 100644
index 0000000..5a56bd5
--- /dev/null
+++ b/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/noop/UserProfileStoreNoop.java
@@ -0,0 +1,61 @@
+/*
+ * 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.testsupport.noop;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.isis.core.commons.debug.DebugBuilder;
+import org.apache.isis.core.commons.debug.DebuggableWithTitle;
+import org.apache.isis.core.runtime.userprofile.UserProfile;
+import org.apache.isis.core.runtime.userprofile.UserProfileStore;
+
+public class UserProfileStoreNoop implements UserProfileStore, DebuggableWithTitle {
+
+ private static final Map<String, UserProfile> profiles = new HashMap<String, UserProfile>();
+
+ @Override
+ public boolean isFixturesInstalled() {
+ return false;
+ }
+
+ @Override
+ public UserProfile getUserProfile(final String name) {
+ return profiles.get(name);
+ }
+
+ @Override
+ public void save(final String name, final UserProfile userProfile) {
+ profiles.put(name, userProfile);
+ }
+
+ @Override
+ public void debugData(final DebugBuilder debug) {
+ for (final String name : profiles.keySet()) {
+ debug.appendln(name, profiles.get(name));
+ }
+ }
+
+ @Override
+ public String debugTitle() {
+ return "InMemoryUserProfileStore";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/tck/ObjectStoreContractTest_persist.java
----------------------------------------------------------------------
diff --git a/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/tck/ObjectStoreContractTest_persist.java b/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/tck/ObjectStoreContractTest_persist.java
new file mode 100644
index 0000000..b70d221
--- /dev/null
+++ b/framework/core/integtestsupport/src/main/java/org/apache/isis/runtimes/dflt/testsupport/tck/ObjectStoreContractTest_persist.java
@@ -0,0 +1,171 @@
+/*
+ * 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.testsupport.tck;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotSame;
+
+import java.util.Date;
+import java.util.List;
+
+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.oid.RootOid;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.runtimes.dflt.runtime.installerregistry.installerapi.PersistenceMechanismInstaller;
+import org.apache.isis.runtimes.dflt.runtime.persistence.objectstore.ObjectStoreSpi;
+import org.apache.isis.runtimes.dflt.runtime.persistence.query.PersistenceQueryFindByTitle;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession;
+import org.apache.isis.runtimes.dflt.testsupport.IsisSystemWithFixtures;
+import org.apache.isis.tck.dom.refs.SimpleEntity;
+
+public abstract class ObjectStoreContractTest_persist {
+
+ @Rule
+ public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder()
+ .with(createPersistenceMechanismInstaller())
+ .with(iswfListener()).build();
+
+
+ /**
+ * Mandatory hook.
+ */
+ protected abstract PersistenceMechanismInstaller createPersistenceMechanismInstaller();
+
+ protected IsisSystemWithFixtures.Listener iswfListener() {
+ return null;
+ }
+
+ /**
+ * hook method
+ */
+ protected void resetPersistenceStore() {
+ }
+
+ protected ObjectAdapter epv2Adapter;
+ protected ObjectSpecification epvSpecification;
+
+ protected ObjectStoreSpi getStore() {
+ PersistenceSession psos = IsisContext.getPersistenceSession();
+ return (ObjectStoreSpi) psos.getObjectStore();
+ }
+
+
+ @Before
+ public void setUpFixtures() throws Exception {
+ epv2Adapter = iswf.adapterFor(iswf.fixtures.smpl2);
+ epvSpecification = iswf.loadSpecification(SimpleEntity.class);
+ }
+
+
+ @Test
+ public void getInstances_usingFindByTitle() throws Exception {
+
+ // given nothing in DB
+ resetPersistenceStore();
+
+ // when search for any object
+ boolean hasInstances = getStore().hasInstances(epvSpecification);
+
+ // then find none
+ assertFalse(hasInstances);
+
+ // given now persisted
+ final SimpleEntity epv2 = iswf.fixtures.smpl2;
+ epv2.setName("foo");
+ epv2.setDate(new Date());
+ epv2.setNullable(1234567890L);
+ epv2.setSize(123);
+
+ iswf.persist(epv2);
+
+ iswf.bounceSystem();
+
+ // when search for object
+ List<ObjectAdapter> retrievedInstance = getStore().loadInstancesAndAdapt(new PersistenceQueryFindByTitle(epvSpecification, epv2Adapter.titleString()));
+
+ // then find
+ assertEquals(1, retrievedInstance.size());
+ final ObjectAdapter retrievedAdapter = retrievedInstance.get(0);
+
+ assertNotSame(epv2Adapter, retrievedAdapter);
+ assertEquals(((SimpleEntity)epv2Adapter.getObject()).getName(), ((SimpleEntity)retrievedAdapter.getObject()).getName());
+ assertEquals(epv2Adapter.getOid(), retrievedAdapter.getOid());
+
+ // and when search for some other title
+ retrievedInstance = getStore().loadInstancesAndAdapt(new PersistenceQueryFindByTitle(epvSpecification, "some other title"));
+
+ // then don't find
+ assertEquals(0, retrievedInstance.size());
+ }
+
+
+ @Test
+ public void updateInstance() throws Exception {
+
+ // given persisted
+ resetPersistenceStore();
+ ObjectAdapter adapter = iswf.persist(iswf.fixtures.smpl2);
+ final RootOid oid = (RootOid) adapter.getOid();
+ iswf.bounceSystem();
+
+ // when change
+ adapter = iswf.reload(oid);
+
+ SimpleEntity epv = (SimpleEntity) adapter.getObject();
+ epv.setName("changed");
+
+ iswf.bounceSystem();
+
+ // then found
+ List<ObjectAdapter> retrievedInstance = getStore().loadInstancesAndAdapt(new PersistenceQueryFindByTitle(epvSpecification, adapter.titleString()));
+ assertEquals(1, retrievedInstance.size());
+
+ final ObjectAdapter retrievedAdapter = retrievedInstance.get(0);
+ assertNotSame(adapter, retrievedAdapter);
+ assertEquals(((SimpleEntity)adapter.getObject()).getName(), ((SimpleEntity)retrievedAdapter.getObject()).getName());
+ assertEquals(adapter.getOid(), retrievedAdapter.getOid());
+ }
+
+ @Test
+ public void removeInstance() throws Exception {
+
+ // given persisted
+ resetPersistenceStore();
+ ObjectAdapter adapter = iswf.persist(iswf.fixtures.smpl2);
+ final RootOid oid = (RootOid) adapter.getOid();
+ iswf.bounceSystem();
+
+ // when destroy
+ adapter = iswf.reload(oid);
+
+ SimpleEntity epv = (SimpleEntity) adapter.getObject();
+ iswf.destroy(epv);
+ iswf.bounceSystem();
+
+ // then not found
+ assertEquals(false, getStore().hasInstances(epvSpecification));
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/integtestsupport/src/site/apt/index.apt
----------------------------------------------------------------------
diff --git a/framework/core/integtestsupport/src/site/apt/index.apt b/framework/core/integtestsupport/src/site/apt/index.apt
new file mode 100644
index 0000000..f77a373
--- /dev/null
+++ b/framework/core/integtestsupport/src/site/apt/index.apt
@@ -0,0 +1,30 @@
+~~ 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.
+
+
+
+Test Support
+
+ The <testsupport> module is ...
+
+ []
+
+Documentation
+
+ See the {{{../index.html}default runtime}} documentation
+ ({{{../docbkx/html/guide/isis-default-runtime.html}HTML}} or
+ {{{../docbkx/pdf/isis-default-runtime.pdf}PDF}}).
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/integtestsupport/src/site/apt/jottings.apt
----------------------------------------------------------------------
diff --git a/framework/core/integtestsupport/src/site/apt/jottings.apt b/framework/core/integtestsupport/src/site/apt/jottings.apt
new file mode 100644
index 0000000..7920f56
--- /dev/null
+++ b/framework/core/integtestsupport/src/site/apt/jottings.apt
@@ -0,0 +1,43 @@
+~~ 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.
+
+
+
+Jottings
+
+ This page is to capture any random jottings relating to this module prior
+ to being moved into formal documentation.
+
+Support for viewer config files
+
+ The "Installer" architecture will automatically load configFiles, following
+ the convention "xxx_yyy.properties". When run from org.apache.isis.Isis or
+ org.apache.isis.WebServer, a "viewer installer" is also specified, meaning
+ that a config file for this viewer is also loaded (eg viewer_html.properties).
+ However, while IsisWebAppBootstrapper uses the installer architecture for
+ "back-end" components (security, persistor etc), it is not used for the viewers.
+
+ Therefore, the IsisWebAppBootstrapper will load additional config files for
+ viewers if required, by searching for the "isis.viewers" context-param.
+
+ For example:
+
+ <context-param>
+ <param-name>isis.viewers</param-name>
+ <param-value>restful</param-value>
+ </context-param>
+
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/integtestsupport/src/site/site.xml
----------------------------------------------------------------------
diff --git a/framework/core/integtestsupport/src/site/site.xml b/framework/core/integtestsupport/src/site/site.xml
new file mode 100644
index 0000000..ec82d2b
--- /dev/null
+++ b/framework/core/integtestsupport/src/site/site.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project>
+
+ <body>
+ <breadcrumbs>
+ <item name="Monitoring" href="index.html"/>
+ </breadcrumbs>
+
+ <menu name="Monitoring">
+ <item name="About" href="index.html" />
+ <item name="Jottings" href="jottings.html" />
+ </menu>
+
+ <menu name="Default Runtime">
+ <item name="Implementation" href="../runtime/index.html" />
+ <item name="Objectstores" href="../objectstores/index.html" />
+ <item name="Profilestores" href="../profilestores/index.html" />
+ <item name="Bytecode" href="../bytecode/index.html" />
+ <item name="Monitoring" href="../monitoring/index.html" />
+ <item name="Webapp Support" href="../webapp/index.html" />
+ <item name="Webserver" href="../webserver/index.html" />
+ <item name="Remoting" href="../remoting/index.html" />
+ </menu>
+
+ <menu name="Maven Reports" ref="reports" />
+ </body>
+</project>
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/integtestsupport/src/test/java/org/apache/isis/runtimes/dflt/objectstores/dflt/InMemoryObjectStoreTest_debug.java
----------------------------------------------------------------------
diff --git a/framework/core/integtestsupport/src/test/java/org/apache/isis/runtimes/dflt/objectstores/dflt/InMemoryObjectStoreTest_debug.java b/framework/core/integtestsupport/src/test/java/org/apache/isis/runtimes/dflt/objectstores/dflt/InMemoryObjectStoreTest_debug.java
new file mode 100644
index 0000000..5cfbe38
--- /dev/null
+++ b/framework/core/integtestsupport/src/test/java/org/apache/isis/runtimes/dflt/objectstores/dflt/InMemoryObjectStoreTest_debug.java
@@ -0,0 +1,78 @@
+/*
+ * 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.dflt;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.apache.isis.core.commons.debug.DebugString;
+import org.apache.isis.core.commons.matchers.IsisMatchers;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+import org.apache.isis.runtimes.dflt.testsupport.IsisSystemWithFixtures;
+import org.junit.Rule;
+import org.junit.Test;
+
+public class InMemoryObjectStoreTest_debug {
+
+ @Rule
+ public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder().build();
+
+ private static InMemoryObjectStore getStore() {
+ return (InMemoryObjectStore) IsisContext.getPersistenceSession().getObjectStore();
+ }
+
+ @Test
+ public void debugTitle() throws Exception {
+
+ // when
+ final String debugTitle = getStore().debugTitle();
+
+ // then
+ assertThat(debugTitle, is("In-Memory Object Store"));
+ }
+
+
+ @Test
+ public void debugXxx_whenHasObject() throws Exception {
+
+ // given
+ iswf.persist(iswf.fixtures.smpl1);
+
+ // when
+ final DebugString debug = new DebugString();
+ getStore().debugData(debug);
+
+
+ // then
+ assertThat(debug.toString(), IsisMatchers.containsStripNewLines("SMPL:2"));
+ }
+
+
+ @Test
+ public void testEmpty() throws Exception {
+
+ // when
+ final DebugString debug = new DebugString();
+ getStore().debugData(debug);
+
+ // then
+ assertThat(debug.toString(), is("\nDomain Objects\n--------------\n\n"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/integtestsupport/src/test/java/org/apache/isis/runtimes/dflt/objectstores/dflt/InMemoryObjectStoreTest_init.java
----------------------------------------------------------------------
diff --git a/framework/core/integtestsupport/src/test/java/org/apache/isis/runtimes/dflt/objectstores/dflt/InMemoryObjectStoreTest_init.java b/framework/core/integtestsupport/src/test/java/org/apache/isis/runtimes/dflt/objectstores/dflt/InMemoryObjectStoreTest_init.java
new file mode 100644
index 0000000..3ac1914
--- /dev/null
+++ b/framework/core/integtestsupport/src/test/java/org/apache/isis/runtimes/dflt/objectstores/dflt/InMemoryObjectStoreTest_init.java
@@ -0,0 +1,44 @@
+/*
+ * 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.dflt;
+
+import static org.junit.Assert.assertFalse;
+
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+import org.apache.isis.runtimes.dflt.testsupport.IsisSystemWithFixtures;
+
+public class InMemoryObjectStoreTest_init {
+
+ @Rule
+ public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder().build();
+
+ private static InMemoryObjectStore getStore() {
+ return (InMemoryObjectStore) IsisContext.getPersistenceSession().getObjectStore();
+ }
+
+ @Test
+ public void testStartsUpInUnitializedSate() throws Exception {
+ assertFalse(getStore().isFixturesInstalled());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/integtestsupport/src/test/java/org/apache/isis/runtimes/dflt/objectstores/dflt/InMemoryObjectStoreTest_name.java
----------------------------------------------------------------------
diff --git a/framework/core/integtestsupport/src/test/java/org/apache/isis/runtimes/dflt/objectstores/dflt/InMemoryObjectStoreTest_name.java b/framework/core/integtestsupport/src/test/java/org/apache/isis/runtimes/dflt/objectstores/dflt/InMemoryObjectStoreTest_name.java
new file mode 100644
index 0000000..79dc871
--- /dev/null
+++ b/framework/core/integtestsupport/src/test/java/org/apache/isis/runtimes/dflt/objectstores/dflt/InMemoryObjectStoreTest_name.java
@@ -0,0 +1,41 @@
+/*
+ * 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.dflt;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class InMemoryObjectStoreTest_name {
+
+ private InMemoryObjectStore store;
+
+ @Before
+ public void setUp() throws Exception {
+ store = new InMemoryObjectStore();
+ }
+
+ @Test
+ public void testName() throws Exception {
+ assertEquals("In-Memory Object Store", store.name());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/core/integtestsupport/src/test/java/org/apache/isis/runtimes/dflt/objectstores/dflt/InMemoryObjectStoreTest_openAndClose.java
----------------------------------------------------------------------
diff --git a/framework/core/integtestsupport/src/test/java/org/apache/isis/runtimes/dflt/objectstores/dflt/InMemoryObjectStoreTest_openAndClose.java b/framework/core/integtestsupport/src/test/java/org/apache/isis/runtimes/dflt/objectstores/dflt/InMemoryObjectStoreTest_openAndClose.java
new file mode 100644
index 0000000..de0bc15
--- /dev/null
+++ b/framework/core/integtestsupport/src/test/java/org/apache/isis/runtimes/dflt/objectstores/dflt/InMemoryObjectStoreTest_openAndClose.java
@@ -0,0 +1,120 @@
+/*
+ * 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.dflt;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+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.testsupport.jmock.JUnitRuleMockery2;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
+import org.apache.isis.runtimes.dflt.objectstores.dflt.internal.ObjectStorePersistedObjects;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSession;
+
+/**
+ * Tested in style of <i>Working Effectively with Legacy Code</i> (Feathers) and
+ * <i>Growing Object-Oriented Software</i> (Freeman & Pryce).
+ */
+public class InMemoryObjectStoreTest_openAndClose {
+
+ @Rule
+ public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+
+ @Mock
+ private InMemoryPersistenceSessionFactory mockInMemoryPersistenceSessionFactory;
+ @Mock
+ private PersistenceSession mockPersistenceSession;
+ @Mock
+ private ObjectStorePersistedObjects mockObjectStorePersistedObjects;
+
+ private boolean recreatedAdapters = false;
+
+ private InMemoryObjectStore objectStore;
+
+ @Before
+ public void setUp() throws Exception {
+ objectStore = new InMemoryObjectStore() {
+ @Override
+ protected InMemoryPersistenceSessionFactory getInMemoryPersistenceSessionFactory() {
+ return mockInMemoryPersistenceSessionFactory;
+ }
+
+ @Override
+ protected PersistenceSession getPersistenceSession() {
+ return mockPersistenceSession;
+ }
+
+ @Override
+ protected void recreateAdapters() {
+ recreatedAdapters = true;
+ }
+ };
+ }
+
+ @Test
+ public void whenOpenForFirstTimeThenCreatesPersistedObjects() throws Exception {
+ context.never(mockPersistenceSession);
+ context.checking(new Expectations() {
+ {
+ one(mockInMemoryPersistenceSessionFactory).getPersistedObjects();
+ will(returnValue(null));
+
+ one(mockInMemoryPersistenceSessionFactory).createPersistedObjects();
+ will(returnValue(mockObjectStorePersistedObjects));
+ }
+ });
+ objectStore.open();
+ }
+
+ @Test
+ public void whenOpenSubsequentlyThenObtainsPersistedObjectsFromObjectStoreFactoryAndRecreatesAdapters() throws Exception {
+ context.never(mockPersistenceSession);
+ context.checking(new Expectations() {
+ {
+ one(mockInMemoryPersistenceSessionFactory).getPersistedObjects();
+ will(returnValue(mockObjectStorePersistedObjects));
+ }
+ });
+
+ assertThat(recreatedAdapters, is(false));
+ objectStore.open();
+ assertThat(recreatedAdapters, is(true));
+ }
+
+ @Test
+ public void whenCloseThenGivesObjectsBackToObjectStoreFactory() throws Exception {
+ context.never(mockPersistenceSession);
+ whenOpenSubsequentlyThenObtainsPersistedObjectsFromObjectStoreFactoryAndRecreatesAdapters();
+
+ context.checking(new Expectations() {
+ {
+ one(mockInMemoryPersistenceSessionFactory).attach(with(mockPersistenceSession), with(mockObjectStorePersistedObjects));
+ never(mockPersistenceSession);
+ }
+ });
+ objectStore.close();
+ }
+
+}