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/13 08:30:04 UTC
[50/58] [partial] ISIS-188: renaming packages in line with
groupId:artifactId
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/core/bytecode-javassist/src/main/java/org/apache/isis/core/bytecode/javassist/ObjectResolveAndObjectChangedEnhancer.java
----------------------------------------------------------------------
diff --git a/core/bytecode-javassist/src/main/java/org/apache/isis/core/bytecode/javassist/ObjectResolveAndObjectChangedEnhancer.java b/core/bytecode-javassist/src/main/java/org/apache/isis/core/bytecode/javassist/ObjectResolveAndObjectChangedEnhancer.java
new file mode 100644
index 0000000..0c1d6fb
--- /dev/null
+++ b/core/bytecode-javassist/src/main/java/org/apache/isis/core/bytecode/javassist/ObjectResolveAndObjectChangedEnhancer.java
@@ -0,0 +1,113 @@
+/*
+ * 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.core.bytecode.javassist;
+
+import java.lang.reflect.Method;
+
+import javassist.util.proxy.MethodFilter;
+import javassist.util.proxy.MethodHandler;
+import javassist.util.proxy.ProxyFactory;
+import javassist.util.proxy.ProxyObject;
+
+import org.apache.isis.core.commons.exceptions.IsisException;
+import org.apache.isis.core.commons.lang.ArrayUtils;
+import org.apache.isis.core.metamodel.facets.ImperativeFacetUtils;
+import org.apache.isis.core.metamodel.facets.ImperativeFacetUtils.ImperativeFacetFlags;
+import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
+import org.apache.isis.core.metamodel.spec.feature.ObjectMember;
+import org.apache.isis.core.metamodel.specloader.specimpl.dflt.ObjectSpecificationDefault;
+import org.apache.isis.core.runtime.bytecode.ObjectResolveAndObjectChangedEnhancerAbstract;
+import org.apache.isis.core.runtime.persistence.objectfactory.ObjectChanger;
+import org.apache.isis.core.runtime.persistence.objectfactory.ObjectResolver;
+
+public class ObjectResolveAndObjectChangedEnhancer extends ObjectResolveAndObjectChangedEnhancerAbstract {
+
+ private MethodHandler methodHandler;
+
+ public ObjectResolveAndObjectChangedEnhancer(final ObjectResolver objectResolver, final ObjectChanger objectChanger, final SpecificationLoaderSpi specificationLoader) {
+ super(objectResolver, objectChanger, specificationLoader);
+
+ createCallback();
+ }
+
+ @Override
+ protected void createCallback() {
+ this.methodHandler = new MethodHandler() {
+ @Override
+ public Object invoke(final Object proxied, final Method proxyMethod, final Method proxiedMethod, final Object[] args) throws Throwable {
+
+ final boolean ignore = proxyMethod.getDeclaringClass().equals(Object.class);
+ ImperativeFacetFlags flags = null;
+
+ if (!ignore) {
+ final ObjectSpecificationDefault targetObjSpec = getJavaSpecificationOfOwningClass(proxiedMethod);
+
+ final ObjectMember member = targetObjSpec.getMember(proxiedMethod);
+ flags = ImperativeFacetUtils.getImperativeFacetFlags(member, proxiedMethod);
+
+ if (flags.impliesResolve()) {
+ objectResolver.resolve(proxied, member.getName());
+ }
+ }
+
+ final Object proxiedReturn = proxiedMethod.invoke(proxied, args); // execute
+ // the
+ // original
+ // method.
+
+ if (!ignore && flags.impliesObjectChanged()) {
+ objectChanger.objectChanged(proxied);
+ }
+
+ return proxiedReturn;
+ }
+ };
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> T newInstance(final Class<T> cls) {
+
+ final ProxyFactory proxyFactory = new ProxyFactory();
+ proxyFactory.setSuperclass(cls);
+ proxyFactory.setInterfaces(ArrayUtils.combine(cls.getInterfaces(), new Class<?>[] { JavassistEnhanced.class }));
+
+ proxyFactory.setFilter(new MethodFilter() {
+ @Override
+ public boolean isHandled(final Method m) {
+ // ignore finalize()
+ return !m.getName().equals("finalize");
+ }
+ });
+
+ final Class<T> proxySubclass = proxyFactory.createClass();
+ try {
+ final T newInstance = proxySubclass.newInstance();
+ final ProxyObject proxyObject = (ProxyObject) newInstance;
+ proxyObject.setHandler(methodHandler);
+
+ return newInstance;
+ } catch (final InstantiationException e) {
+ throw new IsisException(e);
+ } catch (final IllegalAccessException e) {
+ throw new IsisException(e);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/core/bytecode-javassist/src/main/java/org/apache/isis/runtimes/dflt/bytecode/javassist/classsubstitutor/JavassistClassSubstitutor.java
----------------------------------------------------------------------
diff --git a/core/bytecode-javassist/src/main/java/org/apache/isis/runtimes/dflt/bytecode/javassist/classsubstitutor/JavassistClassSubstitutor.java b/core/bytecode-javassist/src/main/java/org/apache/isis/runtimes/dflt/bytecode/javassist/classsubstitutor/JavassistClassSubstitutor.java
deleted file mode 100644
index 583ef6d..0000000
--- a/core/bytecode-javassist/src/main/java/org/apache/isis/runtimes/dflt/bytecode/javassist/classsubstitutor/JavassistClassSubstitutor.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.bytecode.javassist.classsubstitutor;
-
-import org.apache.isis.core.commons.lang.JavaClassUtils;
-import org.apache.isis.core.metamodel.specloader.classsubstitutor.ClassSubstitutorAbstract;
-import org.apache.isis.runtimes.dflt.bytecode.javassist.objectfactory.internal.JavassistEnhanced;
-
-public class JavassistClassSubstitutor extends ClassSubstitutorAbstract {
-
- public JavassistClassSubstitutor() {
- ignore(javassist.util.proxy.ProxyObject.class);
- ignore(javassist.util.proxy.MethodHandler.class);
- }
-
- /**
- * If {@link JavassistEnhanced} then return superclass, else as per
- * {@link ClassSubstitutorAbstract#getClass(Class) superclass'}
- * implementation.
- */
- @Override
- public Class<?> getClass(final Class<?> cls) {
- if (JavaClassUtils.directlyImplements(cls, JavassistEnhanced.class)) {
- return getClass(cls.getSuperclass());
- }
- return super.getClass(cls);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/core/bytecode-javassist/src/main/java/org/apache/isis/runtimes/dflt/bytecode/javassist/objectfactory/JavassistObjectFactory.java
----------------------------------------------------------------------
diff --git a/core/bytecode-javassist/src/main/java/org/apache/isis/runtimes/dflt/bytecode/javassist/objectfactory/JavassistObjectFactory.java b/core/bytecode-javassist/src/main/java/org/apache/isis/runtimes/dflt/bytecode/javassist/objectfactory/JavassistObjectFactory.java
deleted file mode 100644
index 6333282..0000000
--- a/core/bytecode-javassist/src/main/java/org/apache/isis/runtimes/dflt/bytecode/javassist/objectfactory/JavassistObjectFactory.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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.bytecode.javassist.objectfactory;
-
-import org.apache.isis.core.metamodel.spec.ObjectInstantiationException;
-import org.apache.isis.runtimes.dflt.bytecode.javassist.objectfactory.internal.ObjectResolveAndObjectChangedEnhancer;
-import org.apache.isis.runtimes.dflt.runtime.persistence.container.DomainObjectContainerObjectChanged;
-import org.apache.isis.runtimes.dflt.runtime.persistence.container.DomainObjectContainerResolve;
-import org.apache.isis.runtimes.dflt.runtime.persistence.objectfactory.ObjectChanger;
-import org.apache.isis.runtimes.dflt.runtime.persistence.objectfactory.ObjectFactoryAbstract;
-import org.apache.isis.runtimes.dflt.runtime.persistence.objectfactory.ObjectResolver;
-
-public class JavassistObjectFactory extends ObjectFactoryAbstract {
-
- private ObjectResolveAndObjectChangedEnhancer classEnhancer;
- private DomainObjectContainerResolve resolver;
- private DomainObjectContainerObjectChanged changer;
-
- public JavassistObjectFactory() {
- }
-
- @Override
- public void open() {
- super.open();
- changer = new DomainObjectContainerObjectChanged();
- resolver = new DomainObjectContainerResolve();
-
- final ObjectResolver objectResolver = new ObjectResolver() {
- @Override
- public void resolve(final Object domainObject, final String propertyName) {
- // TODO: could do better than this by maintaining a map of
- // resolved
- // properties on the ObjectAdapter adapter.
- resolver.resolve(domainObject);
- }
- };
- final ObjectChanger objectChanger = new ObjectChanger() {
- @Override
- public void objectChanged(final Object domainObject) {
- changer.objectChanged(domainObject);
- }
- };
-
- classEnhancer = new ObjectResolveAndObjectChangedEnhancer(objectResolver, objectChanger, getSpecificationLoader());
- }
-
- @Override
- public <T> T doInstantiate(final Class<T> cls) throws ObjectInstantiationException {
- return classEnhancer.newInstance(cls);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/core/bytecode-javassist/src/main/java/org/apache/isis/runtimes/dflt/bytecode/javassist/objectfactory/internal/JavassistEnhanced.java
----------------------------------------------------------------------
diff --git a/core/bytecode-javassist/src/main/java/org/apache/isis/runtimes/dflt/bytecode/javassist/objectfactory/internal/JavassistEnhanced.java b/core/bytecode-javassist/src/main/java/org/apache/isis/runtimes/dflt/bytecode/javassist/objectfactory/internal/JavassistEnhanced.java
deleted file mode 100644
index 96a56ad..0000000
--- a/core/bytecode-javassist/src/main/java/org/apache/isis/runtimes/dflt/bytecode/javassist/objectfactory/internal/JavassistEnhanced.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.bytecode.javassist.objectfactory.internal;
-
-import org.apache.isis.runtimes.dflt.bytecode.javassist.classsubstitutor.JavassistClassSubstitutor;
-
-/**
- * Marker interface that we make entities implement so easy to spot in the
- * {@link JavassistClassSubstitutor}.
- */
-public interface JavassistEnhanced {
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/core/bytecode-javassist/src/main/java/org/apache/isis/runtimes/dflt/bytecode/javassist/objectfactory/internal/ObjectResolveAndObjectChangedEnhancer.java
----------------------------------------------------------------------
diff --git a/core/bytecode-javassist/src/main/java/org/apache/isis/runtimes/dflt/bytecode/javassist/objectfactory/internal/ObjectResolveAndObjectChangedEnhancer.java b/core/bytecode-javassist/src/main/java/org/apache/isis/runtimes/dflt/bytecode/javassist/objectfactory/internal/ObjectResolveAndObjectChangedEnhancer.java
deleted file mode 100644
index 4994463..0000000
--- a/core/bytecode-javassist/src/main/java/org/apache/isis/runtimes/dflt/bytecode/javassist/objectfactory/internal/ObjectResolveAndObjectChangedEnhancer.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * 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.bytecode.javassist.objectfactory.internal;
-
-import java.lang.reflect.Method;
-
-import javassist.util.proxy.MethodFilter;
-import javassist.util.proxy.MethodHandler;
-import javassist.util.proxy.ProxyFactory;
-import javassist.util.proxy.ProxyObject;
-
-import org.apache.isis.core.commons.exceptions.IsisException;
-import org.apache.isis.core.commons.lang.ArrayUtils;
-import org.apache.isis.core.metamodel.facets.ImperativeFacetUtils;
-import org.apache.isis.core.metamodel.facets.ImperativeFacetUtils.ImperativeFacetFlags;
-import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
-import org.apache.isis.core.metamodel.spec.feature.ObjectMember;
-import org.apache.isis.core.metamodel.specloader.specimpl.dflt.ObjectSpecificationDefault;
-import org.apache.isis.runtimes.dflt.runtime.bytecode.ObjectResolveAndObjectChangedEnhancerAbstract;
-import org.apache.isis.runtimes.dflt.runtime.persistence.objectfactory.ObjectChanger;
-import org.apache.isis.runtimes.dflt.runtime.persistence.objectfactory.ObjectResolver;
-
-public class ObjectResolveAndObjectChangedEnhancer extends ObjectResolveAndObjectChangedEnhancerAbstract {
-
- private MethodHandler methodHandler;
-
- public ObjectResolveAndObjectChangedEnhancer(final ObjectResolver objectResolver, final ObjectChanger objectChanger, final SpecificationLoaderSpi specificationLoader) {
- super(objectResolver, objectChanger, specificationLoader);
-
- createCallback();
- }
-
- @Override
- protected void createCallback() {
- this.methodHandler = new MethodHandler() {
- @Override
- public Object invoke(final Object proxied, final Method proxyMethod, final Method proxiedMethod, final Object[] args) throws Throwable {
-
- final boolean ignore = proxyMethod.getDeclaringClass().equals(Object.class);
- ImperativeFacetFlags flags = null;
-
- if (!ignore) {
- final ObjectSpecificationDefault targetObjSpec = getJavaSpecificationOfOwningClass(proxiedMethod);
-
- final ObjectMember member = targetObjSpec.getMember(proxiedMethod);
- flags = ImperativeFacetUtils.getImperativeFacetFlags(member, proxiedMethod);
-
- if (flags.impliesResolve()) {
- objectResolver.resolve(proxied, member.getName());
- }
- }
-
- final Object proxiedReturn = proxiedMethod.invoke(proxied, args); // execute
- // the
- // original
- // method.
-
- if (!ignore && flags.impliesObjectChanged()) {
- objectChanger.objectChanged(proxied);
- }
-
- return proxiedReturn;
- }
- };
- }
-
- @SuppressWarnings("unchecked")
- public <T> T newInstance(final Class<T> cls) {
-
- final ProxyFactory proxyFactory = new ProxyFactory();
- proxyFactory.setSuperclass(cls);
- proxyFactory.setInterfaces(ArrayUtils.combine(cls.getInterfaces(), new Class<?>[] { JavassistEnhanced.class }));
-
- proxyFactory.setFilter(new MethodFilter() {
- @Override
- public boolean isHandled(final Method m) {
- // ignore finalize()
- return !m.getName().equals("finalize");
- }
- });
-
- final Class<T> proxySubclass = proxyFactory.createClass();
- try {
- final T newInstance = proxySubclass.newInstance();
- final ProxyObject proxyObject = (ProxyObject) newInstance;
- proxyObject.setHandler(methodHandler);
-
- return newInstance;
- } catch (final InstantiationException e) {
- throw new IsisException(e);
- } catch (final IllegalAccessException e) {
- throw new IsisException(e);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystemDefault.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystemDefault.java b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystemDefault.java
new file mode 100644
index 0000000..940e211
--- /dev/null
+++ b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystemDefault.java
@@ -0,0 +1,227 @@
+/*
+ * 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.core.integtestsupport;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.commons.config.IsisConfigurationDefault;
+import org.apache.isis.core.commons.resource.ResourceStreamSourceContextLoaderClassPath;
+import org.apache.isis.core.metamodel.facetapi.ClassSubstitutorFactory;
+import org.apache.isis.core.metamodel.facetapi.MetaModelRefiner;
+import org.apache.isis.core.metamodel.facetdecorator.FacetDecorator;
+import org.apache.isis.core.metamodel.progmodel.ProgrammingModel;
+import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
+import org.apache.isis.core.metamodel.specloader.collectiontyperegistry.CollectionTypeRegistry;
+import org.apache.isis.core.metamodel.specloader.collectiontyperegistry.CollectionTypeRegistryDefault;
+import org.apache.isis.core.metamodel.specloader.validator.MetaModelValidator;
+import org.apache.isis.core.objectstore.InMemoryPersistenceMechanismInstaller;
+import org.apache.isis.core.profilestore.InMemoryUserProfileStore;
+import org.apache.isis.core.progmodel.metamodelvalidator.dflt.MetaModelValidatorDefault;
+import org.apache.isis.core.runtime.authentication.AuthenticationManager;
+import org.apache.isis.core.runtime.authentication.standard.AuthenticationManagerStandard;
+import org.apache.isis.core.runtime.authentication.standard.Authenticator;
+import org.apache.isis.core.runtime.authorization.AuthorizationManager;
+import org.apache.isis.core.runtime.authorization.standard.AuthorizationManagerStandard;
+import org.apache.isis.core.runtime.fixtures.FixturesInstaller;
+import org.apache.isis.core.runtime.fixtures.FixturesInstallerFromConfiguration;
+import org.apache.isis.core.runtime.installerregistry.installerapi.PersistenceMechanismInstaller;
+import org.apache.isis.core.runtime.services.ServicesInstallerFromConfiguration;
+import org.apache.isis.core.runtime.system.DeploymentType;
+import org.apache.isis.core.runtime.system.IsisSystemException;
+import org.apache.isis.core.runtime.system.persistence.PersistenceSessionFactory;
+import org.apache.isis.core.runtime.systemusinginstallers.IsisSystemAbstract;
+import org.apache.isis.core.runtime.transaction.facetdecorator.standard.StandardTransactionFacetDecorator;
+import org.apache.isis.core.runtime.userprofile.UserProfileStore;
+import org.apache.isis.core.security.authentication.AuthenticatorBypass;
+import org.apache.isis.progmodels.dflt.JavaReflectorHelper;
+import org.apache.isis.progmodels.dflt.ProgrammingModelFacetsJava5;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+
+public class IsisSystemDefault extends IsisSystemAbstract {
+
+ private final IsisConfigurationDefault configuration;
+ private final List<Object> servicesIfAny;
+
+ public IsisSystemDefault(Object... servicesIfAny) {
+ this(DeploymentType.SERVER, servicesIfAny);
+ }
+
+ public IsisSystemDefault(List<Object> services) {
+ this(DeploymentType.SERVER, services);
+ }
+
+ public IsisSystemDefault(DeploymentType deploymentType, Object... servicesIfAny) {
+ this(deploymentType, asList(servicesIfAny));
+ }
+
+ public IsisSystemDefault(DeploymentType deploymentType, List<Object> services) {
+ super(deploymentType);
+ this.configuration = new IsisConfigurationDefault(ResourceStreamSourceContextLoaderClassPath.create("config"));
+ this.servicesIfAny = services;
+ }
+
+ private static List<Object> asList(Object... objects) {
+ return objects != null? Collections.unmodifiableList(Lists.newArrayList(objects)): null;
+ }
+
+ /**
+ * Reads <tt>isis.properties</tt> (and other optional property files) from the "config" package on the current classpath.
+ */
+ @Override
+ public IsisConfiguration getConfiguration() {
+ return configuration;
+ }
+
+
+ /**
+ * Either the services explicitly provided by a constructor, otherwise reads from the configuration.
+ */
+ @Override
+ protected List<Object> obtainServices() {
+ if(servicesIfAny != null) {
+ return servicesIfAny;
+ }
+ // else
+ final ServicesInstallerFromConfiguration servicesInstaller = new ServicesInstallerFromConfiguration();
+ return servicesInstaller.getServices(getDeploymentType());
+ }
+
+ /**
+ * Install fixtures from configuration.
+ */
+ @Override
+ protected FixturesInstaller obtainFixturesInstaller() throws IsisSystemException {
+ final FixturesInstallerFromConfiguration fixturesInstallerFromConfiguration = new FixturesInstallerFromConfiguration();
+ fixturesInstallerFromConfiguration.setConfiguration(getConfiguration());
+ return fixturesInstallerFromConfiguration;
+ }
+
+
+ /**
+ * Optional hook method, to create the reflector with defaults (Java5, with cglib, and only the transaction facet decorators)
+ *
+ * <p>
+ * Each of the subcomponents can be overridden if required.
+ *
+ * @see #obtainReflectorFacetDecoratorSet()
+ * @see #obtainReflectorMetaModelValidator()
+ * @see #obtainReflectorProgrammingModel()
+ */
+ @Override
+ protected SpecificationLoaderSpi obtainSpecificationLoaderSpi(DeploymentType deploymentType, ClassSubstitutorFactory classSubstitutorFactory, Collection<MetaModelRefiner> metaModelRefiners) throws IsisSystemException {
+
+ final ProgrammingModel programmingModel = obtainReflectorProgrammingModel();
+ final Set<FacetDecorator> facetDecorators = obtainReflectorFacetDecoratorSet();
+ final MetaModelValidator mmv = obtainReflectorMetaModelValidator();
+
+ return JavaReflectorHelper.createObjectReflector(programmingModel, classSubstitutorFactory, metaModelRefiners, facetDecorators, mmv, getConfiguration());
+ }
+
+
+ /**
+ * Optional hook method, called from {@link #obtainSpecificationLoaderSpi(DeploymentType, ClassSubstitutorFactory, MetaModelRefiner)}.
+ * @return
+ */
+ protected CollectionTypeRegistry obtainReflectorCollectionTypeRegistry() {
+ return new CollectionTypeRegistryDefault();
+ }
+
+
+ /**
+ * Optional hook method, called from {@link #obtainSpecificationLoaderSpi(DeploymentType, ClassSubstitutorFactory, MetaModelRefiner)}.
+ * @return
+ */
+ protected ProgrammingModel obtainReflectorProgrammingModel() {
+ return new ProgrammingModelFacetsJava5();
+ }
+
+ /**
+ * Optional hook method, called from {@link #obtainSpecificationLoaderSpi(DeploymentType, ClassSubstitutorFactory, MetaModelRefiner)}.
+ * @return
+ */
+ protected Set<FacetDecorator> obtainReflectorFacetDecoratorSet() {
+ return Sets.newHashSet((FacetDecorator)new StandardTransactionFacetDecorator(getConfiguration()));
+ }
+
+ /**
+ * Optional hook method, called from {@link #obtainSpecificationLoaderSpi(DeploymentType, ClassSubstitutorFactory, MetaModelRefiner)}.
+ * @return
+ */
+ protected MetaModelValidator obtainReflectorMetaModelValidator() {
+ return new MetaModelValidatorDefault();
+ }
+
+ /**
+ * The standard authentication manager, configured with the default authenticator (allows all requests through).
+ */
+ @Override
+ protected AuthenticationManager obtainAuthenticationManager(DeploymentType deploymentType) throws IsisSystemException {
+ final AuthenticationManagerStandard authenticationManager = new AuthenticationManagerStandard(getConfiguration());
+ Authenticator authenticator = new AuthenticatorBypass(configuration);
+ authenticationManager.addAuthenticator(authenticator);
+ return authenticationManager;
+ }
+
+ /**
+ * The standard authorization manager, allowing all access.
+ */
+ @Override
+ protected AuthorizationManager obtainAuthorizationManager(DeploymentType deploymentType) {
+ return new AuthorizationManagerStandard(getConfiguration());
+ }
+
+ /**
+ * The in-memory user profile store.
+ */
+ @Override
+ protected UserProfileStore obtainUserProfileStore() {
+ return new InMemoryUserProfileStore();
+ }
+
+ /**
+ * The in-memory object store (unless overridden by {@link #obtainPersistenceMechanismInstaller(IsisConfiguration)}).
+ */
+ @Override
+ protected PersistenceSessionFactory obtainPersistenceSessionFactory(DeploymentType deploymentType) throws IsisSystemException {
+ PersistenceMechanismInstaller installer = obtainPersistenceMechanismInstaller(getConfiguration());
+ if(installer == null) {
+ final InMemoryPersistenceMechanismInstaller inMemoryPersistenceMechanismInstaller = new InMemoryPersistenceMechanismInstaller();
+ inMemoryPersistenceMechanismInstaller.setConfiguration(getConfiguration());
+ installer = inMemoryPersistenceMechanismInstaller;
+ }
+ return installer.createPersistenceSessionFactory(deploymentType);
+ }
+
+
+ /**
+ * Optional hook; if returns <tt>null</tt> then the {@link #obtainPersistenceSessionFactory(DeploymentType)} is used.
+ */
+ protected PersistenceMechanismInstaller obtainPersistenceMechanismInstaller(IsisConfiguration configuration) throws IsisSystemException {
+ InMemoryPersistenceMechanismInstaller installer = new InMemoryPersistenceMechanismInstaller();
+ installer.setConfiguration(getConfiguration());
+ return installer;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/951a0fe4/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystemForTest.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystemForTest.java b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystemForTest.java
new file mode 100644
index 0000000..0ea130d
--- /dev/null
+++ b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystemForTest.java
@@ -0,0 +1,646 @@
+/*
+ * 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.core.integtestsupport;
+
+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.objectstore.InMemoryPersistenceMechanismInstaller;
+import org.apache.isis.core.runtime.authentication.AuthenticationManager;
+import org.apache.isis.core.runtime.authentication.AuthenticationRequest;
+import org.apache.isis.core.runtime.fixtures.FixturesInstallerDelegate;
+import org.apache.isis.core.runtime.installerregistry.installerapi.PersistenceMechanismInstaller;
+import org.apache.isis.core.runtime.persistence.objectstore.ObjectStoreSpi;
+import org.apache.isis.core.runtime.system.DeploymentType;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
+import org.apache.isis.core.runtime.system.persistence.Persistor;
+import org.apache.isis.core.runtime.system.transaction.IsisTransaction;
+import org.apache.isis.core.runtime.system.transaction.IsisTransactionManager;
+import org.apache.isis.core.runtime.system.transaction.IsisTransaction.State;
+import org.apache.isis.core.security.authentication.AuthenticationRequestNameOnly;
+
+/**
+ * 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 Level level = Level.INFO;
+
+ private final MetaModelValidator metaModelValidator;
+ private final ProgrammingModel programmingModel;
+
+
+ ////////////////////////////////////////////////////////////
+ // constructor
+ ////////////////////////////////////////////////////////////
+
+ public static class Builder {
+
+ private AuthenticationRequest authenticationRequest = new AuthenticationRequestNameOnly("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();
+
+ private Level level = null;
+
+ 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 Builder withLoggingAt(Level level) {
+ this.level = level;
+ 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;
+ }
+
+ ////////////////////////////////////////////////////////////
+ // logging
+ ////////////////////////////////////////////////////////////
+
+ public Level getLevel() {
+ return level;
+ }
+
+ public void setLevel(Level level) {
+ this.level = level;
+ }
+
+ ////////////////////////////////////////////////////////////
+ // setup, teardown
+ ////////////////////////////////////////////////////////////
+
+
+ /**
+ * Intended to be called from a test's {@link Before} method.
+ */
+ public IsisSystemForTest setUpSystem() throws RuntimeException {
+ try {
+ setUpSystem(FireListeners.FIRE);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ return this;
+ }
+
+ private void setUpSystem(FireListeners fireListeners) throws Exception {
+ Logger.getRootLogger().setLevel(getLevel());
+
+ 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/951a0fe4/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
new file mode 100644
index 0000000..535bedd
--- /dev/null
+++ b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/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.core.integtestsupport;
+
+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.integtestsupport.IsisSystemWithFixtures.Fixtures.Initialization;
+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.objectstore.InMemoryPersistenceMechanismInstaller;
+import org.apache.isis.core.runtime.authentication.AuthenticationManager;
+import org.apache.isis.core.runtime.authentication.AuthenticationRequest;
+import org.apache.isis.core.runtime.installerregistry.installerapi.PersistenceMechanismInstaller;
+import org.apache.isis.core.runtime.persistence.objectstore.ObjectStoreSpi;
+import org.apache.isis.core.runtime.system.DeploymentType;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
+import org.apache.isis.core.runtime.system.persistence.Persistor;
+import org.apache.isis.core.runtime.system.transaction.IsisTransaction;
+import org.apache.isis.core.runtime.system.transaction.IsisTransactionManager;
+import org.apache.isis.core.runtime.system.transaction.IsisTransaction.State;
+import org.apache.isis.core.security.authentication.AuthenticationRequestNameOnly;
+import org.apache.isis.core.tck.dom.refs.AggregatedEntity;
+import org.apache.isis.core.tck.dom.refs.ParentEntity;
+import org.apache.isis.core.tck.dom.refs.ParentEntityRepository;
+import org.apache.isis.core.tck.dom.refs.ReferencingEntity;
+import org.apache.isis.core.tck.dom.refs.SimpleEntity;
+import org.apache.isis.core.tck.dom.scalars.ApplibValuedEntity;
+import org.apache.isis.core.tck.dom.scalars.JdkValuedEntity;
+import org.apache.isis.core.tck.dom.scalars.PrimitiveValuedEntity;
+import org.apache.isis.core.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 AuthenticationRequestNameOnly("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/951a0fe4/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/components/AuthenticationManagerNull.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/components/AuthenticationManagerNull.java b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/components/AuthenticationManagerNull.java
new file mode 100644
index 0000000..3850500
--- /dev/null
+++ b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/components/AuthenticationManagerNull.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.core.integtestsupport.components;
+
+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 AuthenticationManagerNull 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/951a0fe4/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/components/AuthorizationManagerAllowAll.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/components/AuthorizationManagerAllowAll.java b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/components/AuthorizationManagerAllowAll.java
new file mode 100644
index 0000000..03c9e70
--- /dev/null
+++ b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/components/AuthorizationManagerAllowAll.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.core.integtestsupport.components;
+
+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 AuthorizationManagerAllowAll 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/951a0fe4/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/components/TemplateImageLoaderNoopInstaller.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/components/TemplateImageLoaderNoopInstaller.java b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/components/TemplateImageLoaderNoopInstaller.java
new file mode 100644
index 0000000..0e78f50
--- /dev/null
+++ b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/components/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.core.integtestsupport.components;
+
+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 TemplateImageLoaderNull();
+ }
+
+ @Override
+ public List<Class<?>> getTypes() {
+ return listOf(TemplateImageLoader.class);
+ }
+
+}