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:03 UTC
[4/58] ISIS-188: renaming packages, now builds ok (not yet tested)
http://git-wip-us.apache.org/repos/asf/isis/blob/978f79af/core/runtime/src/test/java/org/apache/isis/core/runtime/system/JavaObjectWithBasicProgramConventions.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/system/JavaObjectWithBasicProgramConventions.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/JavaObjectWithBasicProgramConventions.java
new file mode 100644
index 0000000..0057d61
--- /dev/null
+++ b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/JavaObjectWithBasicProgramConventions.java
@@ -0,0 +1,272 @@
+/*
+ * 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.runtime.system;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.apache.isis.applib.security.UserMemento;
+
+public class JavaObjectWithBasicProgramConventions implements Interface1, Interface2 {
+ public static String classActionValid;
+ public String objectActionValid;
+ private final List<Object> collection = new ArrayList<Object>();
+
+ public static String pluralName() {
+ return "Plural";
+ }
+
+ public static String singularName() {
+ return "Singular";
+ }
+
+ public static String getFour() {
+ return "";
+ }
+
+ public static void setFour(final String value) {
+ }
+
+ public String getOne() {
+ return "";
+ }
+
+ public String defaultOne() {
+ return "default value";
+ }
+
+ public String[] choicesOne() {
+ return new String[] { "four", "five", "six" };
+ }
+
+ public void setOne(final String value) {
+ }
+
+ public static boolean optionalOne() {
+ return true;
+
+ }
+
+ public static String disableOne(final UserMemento user) {
+ return "no edits";
+ }
+
+ public boolean hideFieldTwo() {
+ return true;
+ }
+
+ private JavaReferencedObject object;
+
+ public JavaReferencedObject getFieldTwo() {
+ return object;
+ }
+
+ public void setFieldTwo(final JavaReferencedObject object) {
+ this.object = object;
+ }
+
+ // field two should be hidden for the user
+ public static boolean hideFieldTwo(final UserMemento user) {
+ Assert.assertEquals("unit tester", user.getName());
+ return true;
+ }
+
+ // this field should not be persisted as it has no setter
+ public JavaReferencedObject getThree() {
+ return null;
+ }
+
+ public static boolean alwaysHideSix() {
+ return true;
+ }
+
+ public String[] choicesSix() {
+ return new String[] { "one", "two" };
+ }
+
+ public String getSix() {
+ return "";
+ }
+
+ public void setSix(final String value) {
+ }
+
+ public String disableSeven() {
+ return "no changes";
+ }
+
+ public String getSeven() {
+ return "";
+ }
+
+ public void setSeven(final String value) {
+ }
+
+ public static boolean protectEight() {
+ return true;
+ }
+
+ public String getEight() {
+ return "";
+ }
+
+ public void setEight(final String value) {
+ }
+
+ public void setValue(final String value) {
+ }
+
+ public static String nameStop() {
+ return "object action name";
+ }
+
+ public static String descriptionStop() {
+ return "object action description";
+ }
+
+ public String validateStart(final String param) {
+ return objectActionValid;
+ }
+
+ public void stop() {
+ }
+
+ public static boolean[] optionalStart() {
+ return new boolean[] { true };
+ }
+
+ public String[] defaultStart() {
+ return new String[] { "default param" };
+ }
+
+ public String[][] choicesStart() {
+ return new String[][] { { "one", "two", "three" } };
+ }
+
+ public void start2(final String name) {
+ }
+
+ public Object[] choicesStart2() {
+ return new Object[] { new String[] { "three", "two", "one" } };
+ }
+
+ public static String validateTop() {
+ return classActionValid;
+ }
+
+ public static String[] namesStart() {
+ return new String[] { "parameter name" };
+ }
+
+ public int start(final String param) {
+ return 1;
+ }
+
+ public static String nameTop() {
+ return "class action name";
+ }
+
+ public static String descriptionTop() {
+ return "class action description";
+ }
+
+ public static void top() {
+ }
+
+ public static void bottom(final String param) {
+ }
+
+ public static String actionOrder() {
+ // make sure there is an action which doesn't exist
+ return "missing, start, stop";
+ }
+
+ public static String classActionOrder() {
+ return "top, bottom";
+ }
+
+ public static String fieldOrder() {
+ return "one, field two ,three, five";
+ }
+
+ // tests the hide method with same set of paramaters
+ public static boolean alwaysHideHiddenAction(final String param) {
+ return true;
+ }
+
+ public void hiddenAction(final String param) {
+ }
+
+ // tests the hide method with no paramaters
+ public static boolean alwaysHideHiddenAction2() {
+ return true;
+ }
+
+ public void hiddenAction2(final String param1, final String param2) {
+ }
+
+ public static boolean hideHiddenToUser(final UserMemento user) {
+ Assert.assertEquals("unit tester", user.getName());
+ return true;
+ }
+
+ public void hiddenToUser() {
+ }
+
+ public List<Object> getFive() {
+ return collection;
+ }
+
+ public void addToFive(final JavaReferencedObject person) {
+ }
+
+ public void removeFromFive(final JavaReferencedObject person) {
+ }
+
+ public static String nameFive() {
+ return "five";
+ }
+
+ public List getNine() {
+ return collection;
+ }
+
+ // method that would be run on client
+ public void localRunOnClient() {
+ }
+
+ // method that would be run on the server
+ public void remoteRunOnServer() {
+ }
+
+ // method for debug access
+ public String debugTwo(final String parameter) {
+ return "action two";
+ }
+
+ // exploration method
+ public void explorationSetUp() {
+ }
+}
+
+interface Interface2 {
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/978f79af/core/runtime/src/test/java/org/apache/isis/core/runtime/system/JavaObjectWithOneToOneAssociations.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/system/JavaObjectWithOneToOneAssociations.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/JavaObjectWithOneToOneAssociations.java
new file mode 100644
index 0000000..c47e15d
--- /dev/null
+++ b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/JavaObjectWithOneToOneAssociations.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.runtime.system;
+
+public class JavaObjectWithOneToOneAssociations {
+ boolean available = false;
+ private JavaReferencedObject object;
+ boolean valid = false;
+ boolean visible = false;
+
+ public String availableReferencedObject(final JavaReferencedObject object) {
+ return available ? null : "not available";
+ }
+
+ public JavaReferencedObject getReferencedObject() {
+ return object;
+ }
+
+ public void setReferencedObject(final JavaReferencedObject object) {
+ this.object = object;
+ }
+
+ public String validReferencedObject(final JavaReferencedObject object) {
+ return valid ? null : "not valid";
+ }
+
+ public boolean hideReferencedObject(final JavaReferencedObject object) {
+ return !visible;
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/978f79af/core/runtime/src/test/java/org/apache/isis/core/runtime/system/JavaReferencedObject.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/system/JavaReferencedObject.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/JavaReferencedObject.java
new file mode 100644
index 0000000..696458f
--- /dev/null
+++ b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/JavaReferencedObject.java
@@ -0,0 +1,35 @@
+/*
+ * 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.runtime.system;
+
+public class JavaReferencedObject {
+ private static int next;
+ private final int id = next++;
+
+ public JavaReferencedObject() {
+ super();
+ }
+
+ @Override
+ public String toString() {
+ return "JavaReferencedObject#" + id;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/978f79af/core/runtime/src/test/java/org/apache/isis/core/runtime/system/MethodFinderUtilsTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/system/MethodFinderUtilsTest.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/MethodFinderUtilsTest.java
new file mode 100644
index 0000000..cbdcaa8
--- /dev/null
+++ b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/MethodFinderUtilsTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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.runtime.system;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import org.apache.isis.core.commons.lang.MethodUtils;
+import org.apache.isis.core.metamodel.methodutils.MethodFinderUtils;
+import org.apache.isis.core.metamodel.methodutils.MethodScope;
+
+@RunWith(Parameterized.class)
+public class MethodFinderUtilsTest {
+
+ private static Method staticMethod;
+ private static Method instanceMethod;
+
+ static {
+ staticMethod = MethodUtils.findMethodElseNull(MethodFinderUtilsTest.class, "someStaticMethod");
+ instanceMethod = MethodUtils.findMethodElseNull(MethodFinderUtilsTest.class, "someInstanceMethod");
+ }
+
+ private final MethodScope methodScope;
+ private final Method method;
+ private final boolean result;
+
+ @Before
+ public void setUp() {
+ assertThat(staticMethod, is(not(nullValue())));
+ assertThat(instanceMethod, is(not(nullValue())));
+ }
+
+ @Parameters
+ public static Collection parameters() {
+ return Arrays.asList(new Object[][] { { MethodScope.OBJECT, staticMethod, false }, { MethodScope.CLASS, staticMethod, true }, { MethodScope.OBJECT, instanceMethod, true }, { MethodScope.CLASS, instanceMethod, false }, });
+ }
+
+ public static void someStaticMethod() {
+ }
+
+ public void someInstanceMethod() {
+ }
+
+ public MethodFinderUtilsTest(final MethodScope methodScope, final Method method, final boolean result) {
+ this.methodScope = methodScope;
+ this.method = method;
+ this.result = result;
+ }
+
+ @Test
+ public void all() {
+ assertThat(MethodFinderUtils.inScope(methodScope, method), is(result));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/978f79af/core/runtime/src/test/java/org/apache/isis/core/runtime/system/ObjectActionImplTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/system/ObjectActionImplTest.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/ObjectActionImplTest.java
new file mode 100644
index 0000000..e24382e
--- /dev/null
+++ b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/ObjectActionImplTest.java
@@ -0,0 +1,160 @@
+/*
+ * 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.runtime.system;
+
+import static org.junit.Assert.assertEquals;
+
+import org.jmock.Expectations;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.applib.Identifier;
+import org.apache.isis.core.commons.authentication.AuthenticationSessionProvider;
+import org.apache.isis.core.metamodel.adapter.QuerySubmitter;
+import org.apache.isis.core.metamodel.adapter.ServicesProvider;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.deployment.DeploymentCategory;
+import org.apache.isis.core.metamodel.facets.FacetedMethod;
+import org.apache.isis.core.metamodel.facets.named.NamedFacet;
+import org.apache.isis.core.metamodel.facets.named.NamedFacetAbstract;
+import org.apache.isis.core.metamodel.spec.SpecificationLoader;
+import org.apache.isis.core.metamodel.spec.feature.ObjectMemberContext;
+import org.apache.isis.core.metamodel.specloader.collectiontyperegistry.CollectionTypeRegistry;
+import org.apache.isis.core.metamodel.specloader.specimpl.ObjectActionImpl;
+import org.apache.isis.core.unittestsupport.jmock.auto.Mock;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode;
+
+public class ObjectActionImplTest {
+
+ @Rule
+ public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+
+
+ private ObjectActionImpl action;
+
+ @Mock
+ private FacetedMethod mockFacetedMethod;
+
+ @Mock
+ private AuthenticationSessionProvider mockAuthenticationSessionProvider;
+ @Mock
+ private SpecificationLoader mockSpecificationLookup;
+ @Mock
+ private AdapterManager mockAdapterManager;
+ @Mock
+ private ServicesProvider mockServicesProvider;
+ @Mock
+ private QuerySubmitter mockQuerySubmitter;
+ @Mock
+ private CollectionTypeRegistry mockCollectionTypeRegistry;
+
+// protected TestProxySystem system;
+//
+// private TestProxyConfiguration mockConfiguration;
+// private TestProxyReflector mockReflector;
+// private AuthenticationSession mockAuthSession;
+// private TestProxyPersistenceSessionFactory mockPersistenceSessionFactory;
+// private TestProxyPersistenceSession mockPersistenceSession;
+// private TestUserProfileStore mockUserProfileStore;
+
+ @Before
+ public void setUp() throws Exception {
+// Logger.getRootLogger().setLevel(Level.OFF);
+//
+// system = new TestProxySystem();
+//
+// mockConfiguration = new TestProxyConfiguration();
+// mockReflector = new TestProxyReflector();
+// mockAuthSession = new TestProxySession();
+// mockPersistenceSessionFactory = new TestProxyPersistenceSessionFactory();
+// mockPersistenceSession = new TestProxyPersistenceSession(mockPersistenceSessionFactory);
+// mockPersistenceSessionFactory.setPersistenceSessionToCreate(mockPersistenceSession);
+// mockUserProfileStore = new TestUserProfileStore();
+//
+// system.openSession(mockConfiguration, mockReflector, mockAuthSession, null, null, null, mockUserProfileStore, null, mockPersistenceSessionFactory, null);
+
+ context.checking(new Expectations() {
+ {
+ one(mockFacetedMethod).getIdentifier();
+ will(returnValue(Identifier.actionIdentifier("Customer", "reduceheadcount")));
+ }
+ });
+
+ action = new ObjectActionImpl(mockFacetedMethod, new ObjectMemberContext(DeploymentCategory.PRODUCTION, mockAuthenticationSessionProvider, mockSpecificationLookup, mockAdapterManager, mockQuerySubmitter, mockCollectionTypeRegistry), mockServicesProvider);
+ }
+
+ @Ignore // DKH
+ @Test
+ public void testExecutePassedOnToPeer() {
+// final TestProxyAdapter target = new TestProxyAdapter();
+// target.setupSpecification(new TestSpecification());
+// final ObjectAdapter[] parameters = new ObjectAdapter[2];
+//
+// final TestProxyAdapter result = new TestProxyAdapter();
+// final ActionInvocationFacet facet = new ActionInvocationFacetAbstract(mockFacetedMethod) {
+// @Override
+// public ObjectAdapter invoke(final ObjectAdapter target, final ObjectAdapter[] parameters) {
+// return result;
+// }
+//
+// @Override
+// public ObjectSpecification getReturnType() {
+// return null;
+// }
+//
+// @Override
+// public ObjectSpecification getOnType() {
+// return new TestSpecification();
+// }
+// };
+//
+// context.checking(new Expectations() {
+// {
+// exactly(2).of(mockFacetedMethod).getFacet(ActionInvocationFacet.class);
+// will(returnValue(facet));
+// }
+// });
+//
+// final ObjectAdapter returnObject = action.execute(target, parameters);
+// assertEquals(returnObject, result);
+ }
+
+ @Test
+ public void testNameDefaultsToActionsMethodName() {
+ final NamedFacet facet = new NamedFacetAbstract("Reduceheadcount", mockFacetedMethod) {
+ };
+ context.checking(new Expectations() {
+ {
+ one(mockFacetedMethod).getFacet(NamedFacet.class);
+ will(returnValue(facet));
+ }
+ });
+ assertEquals("Reduceheadcount", action.getName());
+ }
+
+ @Test
+ public void testId() {
+ assertEquals("reduceheadcount", action.getId());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/978f79af/core/runtime/src/test/java/org/apache/isis/core/runtime/system/ObjectMemberAbstractTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/system/ObjectMemberAbstractTest.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/ObjectMemberAbstractTest.java
new file mode 100644
index 0000000..7a7a3e0
--- /dev/null
+++ b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/ObjectMemberAbstractTest.java
@@ -0,0 +1,246 @@
+/*
+ * 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.runtime.system;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.applib.annotation.When;
+import org.apache.isis.applib.annotation.Where;
+import org.apache.isis.core.commons.authentication.AuthenticationSession;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.consent.Consent;
+import org.apache.isis.core.metamodel.consent.InteractionInvocationMethod;
+import org.apache.isis.core.metamodel.deployment.DeploymentCategory;
+import org.apache.isis.core.metamodel.facetapi.FeatureType;
+import org.apache.isis.core.metamodel.facets.FacetedMethod;
+import org.apache.isis.core.metamodel.facets.describedas.DescribedAsFacetAbstract;
+import org.apache.isis.core.metamodel.facets.named.NamedFacetAbstract;
+import org.apache.isis.core.metamodel.interactions.PropertyUsabilityContext;
+import org.apache.isis.core.metamodel.interactions.PropertyVisibilityContext;
+import org.apache.isis.core.metamodel.interactions.UsabilityContext;
+import org.apache.isis.core.metamodel.interactions.VisibilityContext;
+import org.apache.isis.core.metamodel.spec.Instance;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.ObjectMemberContext;
+import org.apache.isis.core.metamodel.specloader.specimpl.ObjectMemberAbstract;
+import org.apache.isis.core.progmodel.facets.members.disabled.DisableForSessionFacetAbstract;
+import org.apache.isis.core.progmodel.facets.members.hidden.HiddenFacetAbstract;
+import org.apache.isis.core.progmodel.facets.members.hidden.HiddenFacetImpl;
+import org.apache.isis.core.progmodel.facets.members.hidden.HiddenFacetNever;
+import org.apache.isis.core.progmodel.facets.members.hidden.HideForContextFacetNone;
+import org.apache.isis.core.progmodel.facets.members.hidden.HideForSessionFacetAbstract;
+import org.apache.isis.core.progmodel.facets.members.hidden.staticmethod.HiddenFacetAlwaysEverywhere;
+import org.apache.isis.core.runtime.persistence.objectstore.transaction.PojoAdapterBuilder;
+import org.apache.isis.core.runtime.persistence.objectstore.transaction.PojoAdapterBuilder.Persistence;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode;
+
+public class ObjectMemberAbstractTest {
+
+ @Rule
+ public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+
+ private ObjectMemberAbstractImpl testMember;
+
+ private ObjectAdapter persistentAdapter;
+ private ObjectAdapter transientAdapter;
+
+ @Before
+ public void setUp() throws Exception {
+ Logger.getRootLogger().setLevel(Level.OFF);
+
+ persistentAdapter = PojoAdapterBuilder.create().build();
+ transientAdapter = PojoAdapterBuilder.create().with(Persistence.TRANSIENT).build();
+
+ testMember = new ObjectMemberAbstractImpl("id");
+ }
+
+
+ @Test
+ public void testToString() throws Exception {
+ testMember.addFacet(new NamedFacetAbstract("", testMember) {});
+ assertTrue(testMember.toString().length() > 0);
+ }
+
+ @Test
+ public void testAvailableForUser() throws Exception {
+ testMember.addFacet(new DisableForSessionFacetAbstract(testMember) {
+ @Override
+ public String disabledReason(final AuthenticationSession session) {
+ return null;
+ }
+ });
+ final Consent usable = testMember.isUsable(null, persistentAdapter, Where.ANYWHERE);
+ final boolean allowed = usable.isAllowed();
+ assertTrue(allowed);
+ }
+
+ @Test
+ public void testVisibleWhenHiddenFacetSetToAlways() {
+ testMember.addFacet(new HideForContextFacetNone(testMember));
+ testMember.addFacet(new HiddenFacetAbstract(When.ALWAYS, Where.ANYWHERE, testMember) {
+ @Override
+ public String hiddenReason(final ObjectAdapter target, final Where whereContext) {
+ return null;
+ }
+ });
+ final Consent visible = testMember.isVisible(null, persistentAdapter, Where.ANYWHERE);
+ assertTrue(visible.isAllowed());
+ }
+
+ @Test
+ public void testVisibleWhenTargetPersistentAndHiddenFacetSetToOncePersisted() {
+ testMember.addFacet(new HideForContextFacetNone(testMember));
+ testMember.addFacet(new HiddenFacetImpl(When.ONCE_PERSISTED, Where.ANYWHERE, testMember));
+ assertFalse(testMember.isVisible(null, persistentAdapter, Where.ANYWHERE).isAllowed());
+ }
+
+ @Test
+ public void testVisibleWhenTargetPersistentAndHiddenFacetSetToUntilPersisted() {
+ testMember.addFacet(new HideForContextFacetNone(testMember));
+ testMember.addFacet(new HiddenFacetImpl(When.UNTIL_PERSISTED, Where.ANYWHERE, testMember));
+ final Consent visible = testMember.isVisible(null, persistentAdapter, Where.ANYWHERE);
+ assertTrue(visible.isAllowed());
+ }
+
+ @Test
+ public void testVisibleWhenTargetTransientAndHiddenFacetSetToUntilPersisted() {
+ testMember.addFacet(new HideForContextFacetNone(testMember));
+ testMember.addFacet(new HiddenFacetImpl(When.UNTIL_PERSISTED, Where.ANYWHERE, testMember));
+
+ final Consent visible = testMember.isVisible(null, transientAdapter, Where.ANYWHERE);
+ assertFalse(visible.isAllowed());
+ }
+
+ @Test
+ public void testVisibleDeclarativelyByDefault() {
+ testMember.addFacet(new HiddenFacetNever(testMember) {
+ });
+ assertTrue(testMember.isVisible(null, persistentAdapter, Where.ANYWHERE).isAllowed());
+ }
+
+ @Test
+ public void testVisibleDeclaratively() {
+ testMember.addFacet(new HiddenFacetAlwaysEverywhere(testMember) {
+ });
+ assertFalse(testMember.isVisible(null, persistentAdapter, Where.ANYWHERE).isAllowed());
+ }
+
+ @Test
+ public void testVisibleForSessionByDefault() {
+ final Consent visible = testMember.isVisible(null, persistentAdapter, Where.ANYWHERE);
+ assertTrue(visible.isAllowed());
+ }
+
+ @Test
+ public void testVisibleForSession() {
+ testMember.addFacet(new HideForSessionFacetAbstract(testMember) {
+ @Override
+ public String hiddenReason(final AuthenticationSession session) {
+ return "Hidden";
+ }
+ });
+ assertFalse(testMember.isVisible(null, persistentAdapter, Where.ANYWHERE).isAllowed());
+ }
+
+ @Test
+ public void testVisibleForSessionFails() {
+ testMember.addFacet(new HideForSessionFacetAbstract(testMember) {
+ @Override
+ public String hiddenReason(final AuthenticationSession session) {
+ return "hidden";
+ }
+ });
+ assertFalse(testMember.isVisible(null, persistentAdapter, Where.ANYWHERE).isAllowed());
+ }
+
+ @Test
+ public void testName() throws Exception {
+ final String name = "action name";
+ testMember.addFacet(new NamedFacetAbstract(name, testMember) {
+ });
+ assertEquals(name, testMember.getName());
+ }
+
+ @Test
+ public void testDescription() throws Exception {
+ final String name = "description text";
+ testMember.addFacet(new DescribedAsFacetAbstract(name, testMember) {
+ });
+ assertEquals(name, testMember.getDescription());
+ }
+}
+
+class ObjectMemberAbstractImpl extends ObjectMemberAbstract {
+
+ public static class Customer {
+ private String firstName;
+
+ public String getFirstName() {
+ return firstName;
+ }
+ }
+
+ protected ObjectMemberAbstractImpl(final String id) {
+ super(FacetedMethod.createForProperty(Customer.class, "firstName"), FeatureType.PROPERTY, new ObjectMemberContext(DeploymentCategory.PRODUCTION, null, null, null, null, null));
+ }
+
+ @Override
+ public String debugData() {
+ return null;
+ }
+
+ public Consent isUsable(final ObjectAdapter target) {
+ return null;
+ }
+
+ @Override
+ public ObjectSpecification getSpecification() {
+ return null;
+ }
+
+ @Override
+ public UsabilityContext<?> createUsableInteractionContext(final AuthenticationSession session, final InteractionInvocationMethod invocationMethod, final ObjectAdapter target, Where where) {
+ return new PropertyUsabilityContext(DeploymentCategory.PRODUCTION, session, invocationMethod, target, getIdentifier(), where);
+ }
+
+ @Override
+ public VisibilityContext<?> createVisibleInteractionContext(final AuthenticationSession session, final InteractionInvocationMethod invocationMethod, final ObjectAdapter targetObjectAdapter, Where where) {
+ return new PropertyVisibilityContext(DeploymentCategory.PRODUCTION, session, invocationMethod, targetObjectAdapter, getIdentifier(), where);
+ }
+
+ // /////////////////////////////////////////////////////////////
+ // getInstance
+ // /////////////////////////////////////////////////////////////
+
+ @Override
+ public Instance getInstance(final ObjectAdapter adapter) {
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/978f79af/core/runtime/src/test/java/org/apache/isis/core/runtime/system/OneToManyAssociationImplTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/system/OneToManyAssociationImplTest.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/OneToManyAssociationImplTest.java
new file mode 100644
index 0000000..4fe69c2
--- /dev/null
+++ b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/OneToManyAssociationImplTest.java
@@ -0,0 +1,183 @@
+/*
+ * 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.runtime.system;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.jmock.Expectations;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.applib.Identifier;
+import org.apache.isis.core.commons.authentication.AuthenticationSessionProvider;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.adapter.QuerySubmitter;
+import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.deployment.DeploymentCategory;
+import org.apache.isis.core.metamodel.facets.FacetedMethod;
+import org.apache.isis.core.metamodel.facets.collections.modify.CollectionAddToFacet;
+import org.apache.isis.core.metamodel.facets.named.NamedFacet;
+import org.apache.isis.core.metamodel.facets.notpersisted.NotPersistedFacet;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.SpecificationLoader;
+import org.apache.isis.core.metamodel.spec.feature.ObjectMemberContext;
+import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation;
+import org.apache.isis.core.metamodel.specloader.collectiontyperegistry.CollectionTypeRegistry;
+import org.apache.isis.core.metamodel.specloader.specimpl.OneToManyAssociationImpl;
+import org.apache.isis.core.unittestsupport.jmock.auto.Mock;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode;
+
+public class OneToManyAssociationImplTest {
+
+ private static final String COLLECTION_ID = "orders";
+
+ public static class Customer {
+ }
+
+ public static class Order {
+ }
+
+ private static final Class<?> COLLECTION_TYPE = Order.class;
+
+ @Rule
+ public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+
+ @Mock
+ private ObjectAdapter mockOwnerAdapter;
+ @Mock
+ private ObjectAdapter mockAssociatedAdapter;
+ @Mock
+ private AuthenticationSessionProvider mockAuthenticationSessionProvider;
+ @Mock
+ private SpecificationLoader mockSpecificationLookup;
+ @Mock
+ private AdapterManager mockAdapterManager;
+ @Mock
+ private QuerySubmitter mockQuerySubmitter;
+ @Mock
+ private FacetedMethod mockPeer;
+ @Mock
+ private NamedFacet mockNamedFacet;
+ @Mock
+ private CollectionAddToFacet mockCollectionAddToFacet;
+ @Mock
+ private CollectionTypeRegistry mockCollectionTypeRegistry;
+
+ private OneToManyAssociation association;
+
+ @Before
+ public void setUp() {
+ allowingPeerToReturnCollectionType();
+ allowingPeerToReturnIdentifier();
+ allowingSpecLoaderToReturnSpecs();
+ association = new OneToManyAssociationImpl(mockPeer, new ObjectMemberContext(DeploymentCategory.PRODUCTION, mockAuthenticationSessionProvider, mockSpecificationLookup, mockAdapterManager, mockQuerySubmitter, mockCollectionTypeRegistry));
+ }
+
+ private void allowingSpecLoaderToReturnSpecs() {
+ context.checking(new Expectations() {
+ {
+ allowing(mockSpecificationLookup).loadSpecification(Order.class);
+ }
+ });
+ }
+
+ @Test
+ public void id() {
+ assertThat(association.getId(), is(equalTo(COLLECTION_ID)));
+ }
+
+ @Test
+ public void name() {
+ expectPeerToReturnNamedFacet();
+ assertThat(association.getName(), is(equalTo("My name")));
+ }
+
+ @Test
+ public void delegatesToUnderlying() {
+ final ObjectSpecification spec = association.getSpecification();
+ }
+
+ @Test
+ public void canAddPersistable() {
+ context.checking(new Expectations() {
+ {
+ one(mockPeer).containsFacet(NotPersistedFacet.class);
+ will(returnValue(false));
+
+ one(mockOwnerAdapter).representsPersistent();
+ will(returnValue(true));
+
+ one(mockAssociatedAdapter).isTransient();
+ will(returnValue(false));
+
+ one(mockPeer).getFacet(CollectionAddToFacet.class);
+ will(returnValue(mockCollectionAddToFacet));
+
+ one(mockCollectionAddToFacet).add(mockOwnerAdapter, mockAssociatedAdapter);
+ }
+ });
+ association.addElement(mockOwnerAdapter, mockAssociatedAdapter);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void cannotRemoveNull() {
+ association.removeElement(mockOwnerAdapter, null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void cannotAddNull() {
+ association.addElement(mockOwnerAdapter, null);
+ }
+
+ private void allowingPeerToReturnCollectionType() {
+ context.checking(new Expectations() {
+ {
+ allowing(mockPeer).getType();
+ will(returnValue(COLLECTION_TYPE));
+ }
+ });
+ }
+
+ private void allowingPeerToReturnIdentifier() {
+ context.checking(new Expectations() {
+ {
+ one(mockPeer).getIdentifier();
+ will(returnValue(Identifier.propertyOrCollectionIdentifier(Customer.class, COLLECTION_ID)));
+ }
+ });
+ }
+
+ private void expectPeerToReturnNamedFacet() {
+ context.checking(new Expectations() {
+ {
+ one(mockPeer).getFacet(NamedFacet.class);
+ will(returnValue(mockNamedFacet));
+
+ one(mockNamedFacet).value();
+ will(returnValue("My name"));
+ }
+ });
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/978f79af/core/runtime/src/test/java/org/apache/isis/core/runtime/system/RuntimeTestPojo.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/system/RuntimeTestPojo.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/RuntimeTestPojo.java
new file mode 100644
index 0000000..e542b1d
--- /dev/null
+++ b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/RuntimeTestPojo.java
@@ -0,0 +1,51 @@
+/*
+ * 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.runtime.system;
+
+public class RuntimeTestPojo {
+ private static int nextId;
+ private final int id = nextId++;
+ private final String state = "pojo" + id;
+
+ @Override
+ public String toString() {
+ return "Pojo#" + id;
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ if (other == null) {
+ return false;
+ }
+ if (other == this) {
+ return true;
+ }
+ if (other.getClass() == getClass()) {
+ final RuntimeTestPojo otherTestPojo = (RuntimeTestPojo) other;
+ return otherTestPojo.state.equals(state);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return state.hashCode();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/978f79af/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TestDomainObject.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TestDomainObject.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TestDomainObject.java
new file mode 100644
index 0000000..6ac2004
--- /dev/null
+++ b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TestDomainObject.java
@@ -0,0 +1,24 @@
+/*
+ * 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.runtime.system;
+
+public class TestDomainObject {
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/978f79af/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TestObject.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TestObject.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TestObject.java
new file mode 100644
index 0000000..9d20f20
--- /dev/null
+++ b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TestObject.java
@@ -0,0 +1,23 @@
+/*
+ * 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.runtime.system;
+
+public class TestObject {
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/978f79af/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TestObjectAsAggregated.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TestObjectAsAggregated.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TestObjectAsAggregated.java
new file mode 100644
index 0000000..05896f7
--- /dev/null
+++ b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TestObjectAsAggregated.java
@@ -0,0 +1,29 @@
+/*
+ * 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.runtime.system;
+
+// import org.apache.isis.applib.Aggregated;
+
+public class TestObjectAsAggregated { // implements Aggregated {
+
+ public Object getAggregate() {
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/978f79af/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TestObjectAsService.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TestObjectAsService.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TestObjectAsService.java
new file mode 100644
index 0000000..05d0667
--- /dev/null
+++ b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TestObjectAsService.java
@@ -0,0 +1,37 @@
+/*
+ * 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.runtime.system;
+
+public class TestObjectAsService {
+
+ public String getId() {
+ return null;
+ }
+
+ public void init() {
+ }
+
+ public void action() {
+ }
+
+ public String title() {
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/978f79af/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TestObjectWithCollection.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TestObjectWithCollection.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TestObjectWithCollection.java
new file mode 100644
index 0000000..a6b55d3
--- /dev/null
+++ b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TestObjectWithCollection.java
@@ -0,0 +1,108 @@
+/*
+ * 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.runtime.system;
+
+import java.util.Vector;
+
+public class TestObjectWithCollection extends RuntimeTestPojo {
+
+ private final Vector arrayList;
+ private final boolean throwException;
+
+ public TestObjectWithCollection(final Vector arrayList, final boolean throwException) {
+ this.arrayList = arrayList;
+ this.throwException = throwException;
+ }
+
+ public Object getList() {
+ throwException();
+ return arrayList;
+ }
+
+ public void addToList(final Object object) {
+ throwException();
+ arrayList.add(object);
+ }
+
+ private void throwException() {
+ if (throwException) {
+ throw new Error("cause invocation failure");
+ }
+ }
+
+ public void removeFromList(final Object object) {
+ throwException();
+ arrayList.remove(object);
+ }
+
+ public void clearList() {
+ throwException();
+ arrayList.clear();
+ }
+
+ public String validateAddToList(final Object object) {
+ throwException();
+ if (object instanceof TestObjectWithCollection) {
+ return "can't add this type of object";
+ } else {
+ return null;
+ }
+ }
+
+ public String validateRemoveFromList(final Object object) {
+ throwException();
+ if (object instanceof TestObjectWithCollection) {
+ return "can't remove this type of object";
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + ((arrayList == null) ? 0 : arrayList.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!super.equals(obj)) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final TestObjectWithCollection other = (TestObjectWithCollection) obj;
+ if (arrayList == null) {
+ if (other.arrayList != null) {
+ return false;
+ }
+ } else if (!arrayList.equals(other.arrayList)) {
+ return false;
+ }
+ return true;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/978f79af/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TypeExtractorMethodReturnTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TypeExtractorMethodReturnTest.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TypeExtractorMethodReturnTest.java
new file mode 100644
index 0000000..385795b
--- /dev/null
+++ b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TypeExtractorMethodReturnTest.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.core.runtime.system;
+
+import static org.apache.isis.core.commons.matchers.IsisMatchers.containsElementThat;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+import org.junit.Test;
+
+import org.apache.isis.core.metamodel.specloader.traverser.TypeExtractorMethodReturn;
+
+public class TypeExtractorMethodReturnTest {
+
+ @Test
+ public void shouldFindGenericTypes() throws Exception {
+
+ class Customer {
+ }
+ class CustomerRepository {
+ @SuppressWarnings("unused")
+ public List<Customer> findCustomers() {
+ return null;
+ }
+ }
+
+ final Class<?> clazz = CustomerRepository.class;
+ final Method method = clazz.getMethod("findCustomers");
+
+ final TypeExtractorMethodReturn extractor = new TypeExtractorMethodReturn(method);
+
+ final List<Class<?>> classes = extractor.getClasses();
+ assertThat(classes.size(), is(2));
+ assertThat(classes, containsElementThat(equalTo((Class<?>)java.util.List.class)));
+ assertThat(classes, containsElementThat(equalTo((Class<?>)Customer.class)));
+ }
+
+ @Test
+ public void ignoresVoidType() throws Exception {
+
+ class CustomerRepository {
+ @SuppressWarnings("unused")
+ public void findCustomers() {
+ }
+ }
+
+ final Class<?> clazz = CustomerRepository.class;
+ final Method method = clazz.getMethod("findCustomers");
+
+ final TypeExtractorMethodReturn extractor = new TypeExtractorMethodReturn(method);
+
+ assertThat(extractor.getClasses().size(), is(0));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/978f79af/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TypeExtractorMethodsParametersTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TypeExtractorMethodsParametersTest.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TypeExtractorMethodsParametersTest.java
new file mode 100644
index 0000000..1c92687
--- /dev/null
+++ b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TypeExtractorMethodsParametersTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.runtime.system;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+import org.junit.Test;
+
+import org.apache.isis.core.commons.matchers.IsisMatchers;
+import org.apache.isis.core.metamodel.specloader.traverser.TypeExtractorMethodParameters;
+
+public class TypeExtractorMethodsParametersTest {
+
+ @Test
+ public void shouldFindGenericTypes() throws Exception {
+
+ class Customer {
+ }
+ class CustomerRepository {
+ @SuppressWarnings("unused")
+ public void filterCustomers(final List<Customer> customerList) {
+ ;
+ }
+ }
+
+ final Class<?> clazz = CustomerRepository.class;
+ final Method method = clazz.getMethod("filterCustomers", List.class);
+
+ final TypeExtractorMethodParameters extractor = new TypeExtractorMethodParameters(method);
+
+ assertThat(extractor.getClasses().size(), is(2));
+ assertThat(extractor.getClasses(), IsisMatchers.containsElementThat(equalTo(java.util.List.class)));
+ assertThat(extractor.getClasses(), IsisMatchers.containsElementThat(equalTo(Customer.class)));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/978f79af/core/runtime/src/test/java/org/apache/isis/core/runtime/userprofile/OptionsTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/userprofile/OptionsTest.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/userprofile/OptionsTest.java
new file mode 100644
index 0000000..ed9a0fe
--- /dev/null
+++ b/core/runtime/src/test/java/org/apache/isis/core/runtime/userprofile/OptionsTest.java
@@ -0,0 +1,116 @@
+/*
+ * 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.runtime.userprofile;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Iterator;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.core.commons.debug.DebugString;
+import org.apache.isis.core.runtime.userprofile.Options;
+
+public class OptionsTest {
+
+ private Options options;
+ private Options suboptions;
+
+ @Before
+ public void setup() throws Exception {
+ suboptions = new Options();
+ suboptions.addOption("name-3", "value-2");
+
+ options = new Options();
+ options.addOption("test", "value");
+ options.addOption("anInt", "23");
+ options.addOptions("suboptions", suboptions);
+ }
+
+ @Test
+ public void savedValueIsRetrieved() throws Exception {
+ assertEquals("value", options.getString("test"));
+ }
+
+ @Test
+ public void unknownNameIsNull() throws Exception {
+ assertNull(options.getString("unknown"));
+ }
+
+ @Test
+ public void intValue() throws Exception {
+ assertEquals(23, options.getInteger("anInt", 0));
+ }
+
+ @Test
+ public void intDefault() throws Exception {
+ assertEquals(10, options.getInteger("unknown", 10));
+ }
+
+ @Test
+ public void stringDefault() throws Exception {
+ assertEquals("def", options.getString("unknown", "def"));
+ }
+
+ @Test
+ public void debug() throws Exception {
+ final DebugString debug = new DebugString();
+ options.debugData(debug);
+ assertNotNull(debug.toString());
+ }
+
+ @Test
+ public void names() throws Exception {
+ final Iterator<String> names = options.names();
+ assertTrue(names.hasNext());
+ }
+
+ @Test
+ public void copy() throws Exception {
+ final Options copy = new Options();
+ copy.copy(options);
+ assertEquals("value", copy.getString("test"));
+ }
+
+ @Test
+ public void addOptions() throws Exception {
+ final Options suboptions = options.getOptions("suboptions");
+ assertEquals("value-2", suboptions.getString("name-3"));
+ }
+
+ @Test
+ public void emptyWhenOptionsWhenNotFound() throws Exception {
+ final Options suboptions = options.getOptions("unkown");
+ assertFalse(suboptions.names().hasNext());
+ }
+
+ @Test
+ public void newEmptyOptionsAdded() throws Exception {
+ final Options suboptions = options.getOptions("unknown");
+ suboptions.addOption("test", "value");
+ assertSame(suboptions, options.getOptions("unknown"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/978f79af/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/AuthenticatorAbstractForDfltRuntimeTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/AuthenticatorAbstractForDfltRuntimeTest.java b/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/AuthenticatorAbstractForDfltRuntimeTest.java
deleted file mode 100644
index 297ccba..0000000
--- a/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/AuthenticatorAbstractForDfltRuntimeTest.java
+++ /dev/null
@@ -1,127 +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.runtime.authentication.standard;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-import org.jmock.Expectations;
-import org.jmock.Mockery;
-import org.jmock.integration.junit4.JMock;
-import org.jmock.integration.junit4.JUnit4Mockery;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import org.apache.isis.core.commons.config.IsisConfiguration;
-import org.apache.isis.core.runtime.authentication.AuthenticationRequest;
-import org.apache.isis.core.runtime.authentication.AuthenticatorAbstractForDfltRuntime;
-import org.apache.isis.core.runtime.system.DeploymentType;
-
-@RunWith(JMock.class)
-public class AuthenticatorAbstractForDfltRuntimeTest {
-
- private final Mockery mockery = new JUnit4Mockery();
-
- private IsisConfiguration mockConfiguration;
- private AuthenticatorAbstractForDfltRuntime authenticator;
-
- @Before
- public void setUp() {
- mockConfiguration = mockery.mock(IsisConfiguration.class);
-
- authenticator = new AuthenticatorAbstractForDfltRuntime(mockConfiguration) {
-
- @Override
- public boolean isValid(final AuthenticationRequest request) {
- return false;
- }
-
- @Override
- public boolean canAuthenticate(final Class<? extends AuthenticationRequest> authenticationRequestClass) {
- return false;
- }
- };
- }
-
- @Test
- public void getConfiguration() throws Exception {
- assertThat(authenticator.getConfiguration(), is(mockConfiguration));
- }
-
- @Test
- public void getDeploymentTypeForExploration() throws Exception {
- final DeploymentType deploymentType = DeploymentType.EXPLORATION;
- mockery.checking(new Expectations() {
- {
- allowing(mockConfiguration).getString("isis.deploymentType");
- will(returnValue(deploymentType.name()));
- }
- });
- assertThat(authenticator.getDeploymentType(), is(deploymentType));
- }
-
- @Test
- public void getDeploymentTypeForPrototype() throws Exception {
- final DeploymentType deploymentType = DeploymentType.PROTOTYPE;
- mockery.checking(new Expectations() {
- {
- allowing(mockConfiguration).getString("isis.deploymentType");
- will(returnValue(deploymentType.name()));
- }
- });
- assertThat(authenticator.getDeploymentType(), is(deploymentType));
- }
-
- @Test
- public void getDeploymentTypeForServer() throws Exception {
- final DeploymentType deploymentType = DeploymentType.SERVER;
- mockery.checking(new Expectations() {
- {
- allowing(mockConfiguration).getString("isis.deploymentType");
- will(returnValue(deploymentType.name()));
- }
- });
- assertThat(authenticator.getDeploymentType(), is(deploymentType));
- }
-
- @Test(expected = IllegalStateException.class)
- public void expectsThereToBeADeploymentTypeInIsisConfiguration() throws Exception {
- mockery.checking(new Expectations() {
- {
- allowing(mockConfiguration).getString("isis.deploymentType");
- will(returnValue(null));
- }
- });
- authenticator.getDeploymentType();
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void expectsThereToBeAValidDeploymentTypeInIsisConfiguration() throws Exception {
- mockery.checking(new Expectations() {
- {
- allowing(mockConfiguration).getString("isis.deploymentType");
- will(returnValue("GARBAGE"));
- }
- });
- authenticator.getDeploymentType();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/978f79af/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/MultiUserExplorationSessionTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/MultiUserExplorationSessionTest.java b/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/MultiUserExplorationSessionTest.java
deleted file mode 100644
index 7a250e8..0000000
--- a/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/MultiUserExplorationSessionTest.java
+++ /dev/null
@@ -1,210 +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.runtime.authentication.standard;
-
-import static org.hamcrest.CoreMatchers.*;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-import java.util.List;
-import java.util.Set;
-
-import junit.framework.Assert;
-
-import org.jmock.Expectations;
-import org.jmock.Mockery;
-import org.jmock.integration.junit4.JMock;
-import org.jmock.integration.junit4.JUnit4Mockery;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import org.apache.isis.core.commons.authentication.AuthenticationSession;
-import org.apache.isis.core.commons.config.IsisConfiguration;
-import org.apache.isis.core.runtime.authentication.exploration.AuthenticationRequestExploration;
-import org.apache.isis.core.runtime.authentication.exploration.ExplorationAuthenticator;
-import org.apache.isis.core.runtime.authentication.exploration.ExplorationAuthenticatorConstants;
-import org.apache.isis.core.runtime.authentication.exploration.ExplorationSession;
-import org.apache.isis.core.runtime.authentication.exploration.MultiUserExplorationSession;
-import org.apache.isis.core.runtime.authentication.standard.SimpleSession;
-import org.apache.isis.core.runtime.system.DeploymentType;
-import org.apache.isis.core.runtime.system.SystemConstants;
-
-@RunWith(JMock.class)
-public class MultiUserExplorationSessionTest {
-
- private final Mockery mockery = new JUnit4Mockery();
-
- private MultiUserExplorationSession session;
- private IsisConfiguration mockConfiguration;
- private ExplorationAuthenticator authenticator;
-
- @Before
- public void setUp() {
- mockConfiguration = mockery.mock(IsisConfiguration.class);
- mockery.checking(new Expectations() {
- {
- allowing(mockConfiguration).getString(SystemConstants.DEPLOYMENT_TYPE_KEY);
- will(returnValue(DeploymentType.EXPLORATION.name()));
- }
- });
- }
-
- @Test
- public void testNameDefaultsToFirstUser() throws Exception {
- mockery.checking(new Expectations() {
- {
- allowing(mockConfiguration).getString(ExplorationAuthenticatorConstants.USERS);
- will(returnValue("fred, sven:admin|sales|marketing, bob:sales, dick"));
- }
- });
- authenticator = new ExplorationAuthenticator(mockConfiguration);
- final AuthenticationSession session = authenticator.authenticate(new AuthenticationRequestExploration(), "");
-
- Assert.assertEquals("fred", session.getUserName());
- }
-
- @Test
- public void testValidateCode() throws Exception {
- mockery.checking(new Expectations() {
- {
- allowing(mockConfiguration).getString(ExplorationAuthenticatorConstants.USERS);
- will(returnValue("fred, sven:admin|sales|marketing, bob:sales, dick"));
- }
- });
- authenticator = new ExplorationAuthenticator(mockConfiguration);
- final AuthenticationSession session = authenticator.authenticate(new AuthenticationRequestExploration(), "xxx");
-
- Assert.assertEquals("xxx", session.getValidationCode());
- }
-
- @Test
- public void testNoRolesSpecifiedForFirstUser() throws Exception {
- mockery.checking(new Expectations() {
- {
- allowing(mockConfiguration).getString(ExplorationAuthenticatorConstants.USERS);
- will(returnValue("fred, sven:admin|sales|marketing, bob:sales, dick"));
- }
- });
- authenticator = new ExplorationAuthenticator(mockConfiguration);
- final AuthenticationSession session = authenticator.authenticate(new AuthenticationRequestExploration(), "");
-
- Assert.assertEquals(0, session.getRoles().size());
- }
-
- @Test
- public void testForMultipleUser() throws Exception {
- mockery.checking(new Expectations() {
- {
- allowing(mockConfiguration).getString(ExplorationAuthenticatorConstants.USERS);
- will(returnValue("fred, sven:admin|sales|marketing, bob:sales, dick"));
- }
- });
- authenticator = new ExplorationAuthenticator(mockConfiguration);
- final AuthenticationSession authSession = authenticator.authenticate(new AuthenticationRequestExploration(), "");
-
- assertThat(authSession, is(instanceOf(MultiUserExplorationSession.class)));
-
- assertThat(authSession.getUserName(), is(equalTo("fred")));
- }
-
- @Test
- public void testForSingleUser() throws Exception {
- mockery.checking(new Expectations() {
- {
- allowing(mockConfiguration).getString(ExplorationAuthenticatorConstants.USERS);
- will(returnValue("sven"));
- }
- });
- authenticator = new ExplorationAuthenticator(mockConfiguration);
- final AuthenticationSession authSession = authenticator.authenticate(new AuthenticationRequestExploration(), "");
- assertThat(authSession, is(instanceOf(SimpleSession.class)));
-
- assertThat(authSession.getUserName(), is(equalTo("sven")));
- }
-
- @Test
- public void testNoUsersSpecified() throws Exception {
- mockery.checking(new Expectations() {
- {
- allowing(mockConfiguration).getString(ExplorationAuthenticatorConstants.USERS);
- will(returnValue(null));
- }
- });
- authenticator = new ExplorationAuthenticator(mockConfiguration);
-
- final AuthenticationSession authSession = authenticator.authenticate(new AuthenticationRequestExploration(), "");
- assertThat(authSession, is(instanceOf(ExplorationSession.class)));
- }
-
- @Test
- public void testOtherUsers() throws Exception {
- mockery.checking(new Expectations() {
- {
- allowing(mockConfiguration).getString(ExplorationAuthenticatorConstants.USERS);
- will(returnValue("fred, sven:admin|sales|marketing, bob:sales, dick"));
- }
- });
- authenticator = new ExplorationAuthenticator(mockConfiguration);
- this.session = (MultiUserExplorationSession) authenticator.authenticate(new AuthenticationRequestExploration(), "");
-
- final Set<String> availableSessions = session.getUserNames();
- Assert.assertEquals(4, availableSessions.size());
- Assert.assertTrue(availableSessions.contains("fred"));
- Assert.assertTrue(availableSessions.contains("sven"));
- Assert.assertTrue(availableSessions.contains("bob"));
- Assert.assertTrue(availableSessions.contains("dick"));
- }
-
- @Test
- public void testChangeUser() throws Exception {
- mockery.checking(new Expectations() {
- {
- allowing(mockConfiguration).getString(ExplorationAuthenticatorConstants.USERS);
- will(returnValue("fred, sven:admin|sales|marketing, bob:sales, dick"));
- }
- });
- authenticator = new ExplorationAuthenticator(mockConfiguration);
- this.session = (MultiUserExplorationSession) authenticator.authenticate(new AuthenticationRequestExploration(), "");
-
- session.setCurrentSession("bob");
- Assert.assertEquals("bob", session.getUserName());
- }
-
- @Test
- public void testRolesExist() throws Exception {
- mockery.checking(new Expectations() {
- {
- allowing(mockConfiguration).getString(ExplorationAuthenticatorConstants.USERS);
- will(returnValue("fred, sven:admin|sales|marketing, bob:sales, dick"));
- }
- });
- authenticator = new ExplorationAuthenticator(mockConfiguration);
- this.session = (MultiUserExplorationSession) authenticator.authenticate(new AuthenticationRequestExploration(), "");
-
- session.setCurrentSession("sven");
- final List<String> roles = session.getRoles();
- Assert.assertEquals(3, roles.size());
- Assert.assertEquals("admin", roles.get(0));
- Assert.assertEquals("sales", roles.get(1));
- Assert.assertEquals("marketing", roles.get(2));
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/978f79af/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/SimpleSessionEncodabilityNoRolesTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/SimpleSessionEncodabilityNoRolesTest.java b/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/SimpleSessionEncodabilityNoRolesTest.java
deleted file mode 100644
index 08a0431..0000000
--- a/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/SimpleSessionEncodabilityNoRolesTest.java
+++ /dev/null
@@ -1,36 +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.runtime.authentication.standard;
-
-import org.jmock.integration.junit4.JMock;
-import org.junit.runner.RunWith;
-
-import org.apache.isis.core.commons.encoding.Encodable;
-import org.apache.isis.core.runtime.authentication.standard.SimpleSession;
-
-@RunWith(JMock.class)
-public class SimpleSessionEncodabilityNoRolesTest extends SimpleSessionEncodabilityTestAbstract {
-
- @Override
- protected Encodable createEncodable() {
- return new SimpleSession("joe", new String[] {});
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/978f79af/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/SimpleSessionEncodabilityTestAbstract.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/SimpleSessionEncodabilityTestAbstract.java b/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/SimpleSessionEncodabilityTestAbstract.java
deleted file mode 100644
index fe4c618..0000000
--- a/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/SimpleSessionEncodabilityTestAbstract.java
+++ /dev/null
@@ -1,40 +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.runtime.authentication.standard;
-
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-import org.apache.isis.core.commons.encoding.EncodabilityContractTest;
-import org.apache.isis.core.runtime.authentication.standard.SimpleSession;
-
-public abstract class SimpleSessionEncodabilityTestAbstract extends EncodabilityContractTest {
-
- @Override
- protected void assertRoundtripped(final Object decodedEncodable, final Object originalEncodable) {
- final SimpleSession decoded = (SimpleSession) decodedEncodable;
- final SimpleSession original = (SimpleSession) originalEncodable;
-
- assertThat(decoded.getUserName(), is(equalTo(original.getUserName())));
- assertThat(decoded.getRoles(), is(equalTo(original.getRoles())));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/978f79af/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/SimpleSessionEncodabilityWithRolesTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/SimpleSessionEncodabilityWithRolesTest.java b/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/SimpleSessionEncodabilityWithRolesTest.java
deleted file mode 100644
index 7c6b688..0000000
--- a/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/SimpleSessionEncodabilityWithRolesTest.java
+++ /dev/null
@@ -1,36 +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.runtime.authentication.standard;
-
-import org.jmock.integration.junit4.JMock;
-import org.junit.runner.RunWith;
-
-import org.apache.isis.core.commons.encoding.Encodable;
-import org.apache.isis.core.runtime.authentication.standard.SimpleSession;
-
-@RunWith(JMock.class)
-public class SimpleSessionEncodabilityWithRolesTest extends SimpleSessionEncodabilityTestAbstract {
-
- @Override
- protected Encodable createEncodable() {
- return new SimpleSession("joe", new String[] { "role1", "role2" });
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/978f79af/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/StandardAuthenticationManager_AuthenticationTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/StandardAuthenticationManager_AuthenticationTest.java b/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/StandardAuthenticationManager_AuthenticationTest.java
deleted file mode 100644
index d47a6f9..0000000
--- a/core/runtime/src/test/java/org/apache/isis/runtimes/dflt/runtime/authentication/standard/StandardAuthenticationManager_AuthenticationTest.java
+++ /dev/null
@@ -1,96 +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.runtime.authentication.standard;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-import org.jmock.Expectations;
-import org.jmock.Mockery;
-import org.jmock.integration.junit4.JMock;
-import org.jmock.integration.junit4.JUnit4Mockery;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import org.apache.isis.core.commons.authentication.AuthenticationSession;
-import org.apache.isis.core.commons.config.IsisConfiguration;
-import org.apache.isis.core.commons.matchers.IsisMatchers;
-import org.apache.isis.core.runtime.authentication.AuthenticationRequest;
-import org.apache.isis.core.runtime.authentication.AuthenticationRequestPassword;
-import org.apache.isis.core.runtime.authentication.standard.AuthenticationManagerStandard;
-import org.apache.isis.core.runtime.authentication.standard.Authenticator;
-import org.apache.isis.core.runtime.authentication.standard.RandomCodeGenerator;
-
-@RunWith(JMock.class)
-public class StandardAuthenticationManager_AuthenticationTest {
-
- private final Mockery mockery = new JUnit4Mockery();
-
- private AuthenticationManagerStandard authenticationManager;
-
- private IsisConfiguration mockConfiguration;
- private RandomCodeGenerator mockRandomCodeGenerator;
- private Authenticator mockAuthenticator;
- private AuthenticationSession mockAuthSession;
-
- @Before
- public void setUp() throws Exception {
- mockConfiguration = mockery.mock(IsisConfiguration.class);
- mockRandomCodeGenerator = mockery.mock(RandomCodeGenerator.class);
- mockAuthenticator = mockery.mock(Authenticator.class);
- mockAuthSession = mockery.mock(AuthenticationSession.class);
-
- authenticationManager = new AuthenticationManagerStandard(mockConfiguration);
- authenticationManager.addAuthenticator(mockAuthenticator);
- authenticationManager.setRandomCodeGenerator(mockRandomCodeGenerator);
-
- mockery.checking(new Expectations() {
- {
- allowing(mockAuthenticator).canAuthenticate(with(IsisMatchers.anySubclassOf(AuthenticationRequest.class)));
- will(returnValue(true));
-
- allowing(mockAuthenticator).authenticate(with(any(AuthenticationRequest.class)), with(any(String.class)));
- will(returnValue(mockAuthSession));
-
- allowing(mockRandomCodeGenerator).generateRandomCode();
- will(returnValue("123456"));
-
- allowing(mockAuthSession).getValidationCode();
- will(returnValue("123456"));
-
- allowing(mockAuthSession).hasUserNameOf("foo");
- will(returnValue(true));
-
- allowing(mockAuthSession).getUserName();
- will(returnValue("foo"));
- }
- });
- }
-
- @Test
- public void newlyCreatedAuthenticationSessionShouldBeValid() throws Exception {
- final AuthenticationRequestPassword request = new AuthenticationRequestPassword("foo", "bar");
- final AuthenticationSession session = authenticationManager.authenticate(request);
-
- assertThat(authenticationManager.isSessionValid(session), is(true));
- }
-
-}