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 2016/06/16 09:44:50 UTC

[09/13] isis git commit: ISIS-1441: fixes unit tests

ISIS-1441: fixes unit tests


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

Branch: refs/heads/ISIS-1427
Commit: ed318639be47e243cf2e7628065f967dd386e0c1
Parents: 364e5b9
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Thu Jun 16 10:24:28 2016 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Thu Jun 16 10:25:45 2016 +0100

----------------------------------------------------------------------
 .../ExplorationAuthenticatorTest.java           | 100 ++++++++++++++
 .../fixture/LogonFixtureAuthenticatorTest.java  |  99 ++++++++++++++
 .../ExplorationAuthenticatorTest.java           | 129 ------------------
 .../fixture/LogonFixtureAuthenticatorTest.java  | 131 -------------------
 4 files changed, 199 insertions(+), 260 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/ed318639/core/metamodel/src/test/java/org/apache/isis/core/runtime/authentication/exploration/ExplorationAuthenticatorTest.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/runtime/authentication/exploration/ExplorationAuthenticatorTest.java b/core/metamodel/src/test/java/org/apache/isis/core/runtime/authentication/exploration/ExplorationAuthenticatorTest.java
new file mode 100644
index 0000000..6a17244
--- /dev/null
+++ b/core/metamodel/src/test/java/org/apache/isis/core/runtime/authentication/exploration/ExplorationAuthenticatorTest.java
@@ -0,0 +1,100 @@
+/*
+ *  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.authentication.exploration;
+
+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.metamodel.deployment.DeploymentCategory;
+import org.apache.isis.core.runtime.authentication.AuthenticationRequestAbstract;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+@RunWith(JMock.class)
+public class ExplorationAuthenticatorTest {
+
+    private final Mockery mockery = new JUnit4Mockery();
+
+    private IsisConfiguration mockConfiguration;
+    private ExplorationAuthenticator authenticator;
+
+    private AuthenticationRequestExploration explorationRequest;
+
+    private SomeOtherAuthenticationRequest someOtherRequest;
+
+    private static class SomeOtherAuthenticationRequest extends AuthenticationRequestAbstract {
+        public SomeOtherAuthenticationRequest() {
+            super("other");
+        }
+    }
+
+    @Before
+    public void setUp() {
+        mockConfiguration = mockery.mock(IsisConfiguration.class);
+
+        mockery.checking(new Expectations() {
+            {
+                allowing(mockConfiguration).getString(ExplorationAuthenticatorConstants.USERS);
+                will(returnValue("unit-testing"));
+            }
+        });
+
+        explorationRequest = new AuthenticationRequestExploration();
+        someOtherRequest = new SomeOtherAuthenticationRequest();
+
+        authenticator = new ExplorationAuthenticator(mockConfiguration);
+    }
+
+    @Test
+    public void canAuthenticateExplorationRequest() throws Exception {
+        assertThat(authenticator.canAuthenticate(explorationRequest.getClass()), is(true));
+    }
+
+    @Test
+    public void canAuthenticateSomeOtherTypeOfRequest() throws Exception {
+        assertThat(authenticator.canAuthenticate(someOtherRequest.getClass()), is(false));
+    }
+
+    @Test
+    public void isValidExplorationRequestWhenRunningInExplorationMode() throws Exception {
+        authenticator.init(DeploymentCategory.EXPLORING);
+        assertThat(authenticator.isValid(explorationRequest), is(true));
+    }
+
+    @Test
+    public void isNotValidExplorationRequestWhenRunningInSomethingOtherThanExplorationMode() throws Exception {
+        authenticator.init(DeploymentCategory.PROTOTYPING);
+        assertThat(authenticator.isValid(explorationRequest), is(false));
+    }
+
+    @Test
+    public void isValidSomeOtherTypeOfRequest() throws Exception {
+        authenticator.init(DeploymentCategory.PROTOTYPING);
+        assertThat(authenticator.canAuthenticate(someOtherRequest.getClass()), is(false));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/ed318639/core/metamodel/src/test/java/org/apache/isis/core/runtime/authentication/fixture/LogonFixtureAuthenticatorTest.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/runtime/authentication/fixture/LogonFixtureAuthenticatorTest.java b/core/metamodel/src/test/java/org/apache/isis/core/runtime/authentication/fixture/LogonFixtureAuthenticatorTest.java
new file mode 100644
index 0000000..93d0e59
--- /dev/null
+++ b/core/metamodel/src/test/java/org/apache/isis/core/runtime/authentication/fixture/LogonFixtureAuthenticatorTest.java
@@ -0,0 +1,99 @@
+/*
+ *  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.authentication.fixture;
+
+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.applib.fixtures.LogonFixture;
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.metamodel.deployment.DeploymentCategory;
+import org.apache.isis.core.runtime.authentication.AuthenticationRequestAbstract;
+import org.apache.isis.core.runtime.fixtures.authentication.AuthenticationRequestLogonFixture;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+@RunWith(JMock.class)
+public class LogonFixtureAuthenticatorTest {
+
+    private final Mockery mockery = new JUnit4Mockery();
+
+    private IsisConfiguration mockConfiguration;
+    private LogonFixtureAuthenticator authenticator;
+
+    private AuthenticationRequestLogonFixture logonFixtureRequest;
+
+    private SomeOtherAuthenticationRequest someOtherRequest;
+
+    private static class SomeOtherAuthenticationRequest extends AuthenticationRequestAbstract {
+        public SomeOtherAuthenticationRequest() {
+            super("other");
+        }
+    }
+
+    @Before
+    public void setUp() {
+        mockConfiguration = mockery.mock(IsisConfiguration.class);
+
+        logonFixtureRequest = new AuthenticationRequestLogonFixture(new LogonFixture("joebloggs"));
+        someOtherRequest = new SomeOtherAuthenticationRequest();
+        authenticator = new LogonFixtureAuthenticator(mockConfiguration);
+    }
+
+    @Test
+    public void canAuthenticateExplorationRequest() throws Exception {
+        assertThat(authenticator.canAuthenticate(logonFixtureRequest.getClass()), is(true));
+    }
+
+    @Test
+    public void canAuthenticateSomeOtherTypeOfRequest() throws Exception {
+        assertThat(authenticator.canAuthenticate(someOtherRequest.getClass()), is(false));
+    }
+
+    @Test
+    public void isValidLogonFixtureRequestWhenRunningInExplorationMode() throws Exception {
+        authenticator.init(DeploymentCategory.EXPLORING);
+        assertThat(authenticator.isValid(logonFixtureRequest), is(true));
+    }
+
+    @Test
+    public void isValidLogonFixtureRequestWhenRunningInPrototypeMode() throws Exception {
+        authenticator.init(DeploymentCategory.PROTOTYPING);
+        assertThat(authenticator.isValid(logonFixtureRequest), is(true));
+    }
+
+    @Test
+    public void isNotValidExplorationRequestWhenRunningInSomethingOtherThanExplorationOrPrototypeMode() throws Exception {
+        authenticator.init(DeploymentCategory.PRODUCTION);
+        assertThat(authenticator.isValid(logonFixtureRequest), is(false));
+    }
+
+    @Test
+    public void isValidSomeOtherTypeOfRequest() throws Exception {
+        authenticator.init(DeploymentCategory.EXPLORING);
+        assertThat(authenticator.canAuthenticate(SomeOtherAuthenticationRequest.class), is(false));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/ed318639/core/runtime/src/test/java/org/apache/isis/core/runtime/authentication/exploration/ExplorationAuthenticatorTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/authentication/exploration/ExplorationAuthenticatorTest.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/authentication/exploration/ExplorationAuthenticatorTest.java
deleted file mode 100644
index f8cad24..0000000
--- a/core/runtime/src/test/java/org/apache/isis/core/runtime/authentication/exploration/ExplorationAuthenticatorTest.java
+++ /dev/null
@@ -1,129 +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.core.runtime.authentication.exploration;
-
-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.AuthenticationRequestAbstract;
-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.system.DeploymentType;
-import org.apache.isis.core.runtime.system.SystemConstants;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-@RunWith(JMock.class)
-public class ExplorationAuthenticatorTest {
-
-    private final Mockery mockery = new JUnit4Mockery();
-
-    private IsisConfiguration mockConfiguration;
-    private ExplorationAuthenticator authenticator;
-
-    private AuthenticationRequestExploration explorationRequest;
-
-    private SomeOtherAuthenticationRequest someOtherRequest;
-
-    private static class SomeOtherAuthenticationRequest extends AuthenticationRequestAbstract {
-        public SomeOtherAuthenticationRequest() {
-            super("other");
-        }
-    }
-
-    @Before
-    public void setUp() {
-        mockConfiguration = mockery.mock(IsisConfiguration.class);
-
-        mockery.checking(new Expectations() {
-            {
-                allowing(mockConfiguration).getString(ExplorationAuthenticatorConstants.USERS);
-                will(returnValue(DeploymentType.UNIT_TESTING.name()));
-            }
-        });
-
-        explorationRequest = new AuthenticationRequestExploration();
-        someOtherRequest = new SomeOtherAuthenticationRequest();
-
-        authenticator = new ExplorationAuthenticator(mockConfiguration);
-    }
-
-    @Test
-    public void canAuthenticateExplorationRequest() throws Exception {
-        assertThat(authenticator.canAuthenticate(explorationRequest.getClass()), is(true));
-    }
-
-    @Test
-    public void canAuthenticateSomeOtherTypeOfRequest() throws Exception {
-        assertThat(authenticator.canAuthenticate(someOtherRequest.getClass()), is(false));
-    }
-
-    @Test
-    public void isValidExplorationRequestWhenRunningInExplorationMode() throws Exception {
-        mockery.checking(new Expectations() {
-            {
-                allowing(mockConfiguration).getString(SystemConstants.DEPLOYMENT_TYPE_KEY);
-                will(returnValue(DeploymentType.SERVER_EXPLORATION.name()));
-            }
-        });
-        assertThat(authenticator.isValid(explorationRequest), is(true));
-    }
-
-    @Test
-    public void isNotValidExplorationRequestWhenRunningInSomethingOtherThanExplorationMode() throws Exception {
-        mockery.checking(new Expectations() {
-            {
-                allowing(mockConfiguration).getString(SystemConstants.DEPLOYMENT_TYPE_KEY);
-                will(returnValue(DeploymentType.SERVER_PROTOTYPE.name()));
-            }
-        });
-        assertThat(authenticator.isValid(explorationRequest), is(false));
-    }
-
-    @Test(expected = IllegalStateException.class)
-    public void expectsThereToBeADeploymentTypeInIsisConfiguration() throws Exception {
-        mockery.checking(new Expectations() {
-            {
-                allowing(mockConfiguration).getString(SystemConstants.DEPLOYMENT_TYPE_KEY);
-                will(returnValue(null));
-            }
-        });
-        authenticator.isValid(explorationRequest);
-    }
-
-    @Test
-    public void isValidSomeOtherTypeOfRequest() throws Exception {
-        mockery.checking(new Expectations() {
-            {
-                allowing(mockConfiguration).getString(SystemConstants.DEPLOYMENT_TYPE_KEY);
-                will(returnValue(DeploymentType.SERVER_PROTOTYPE.name()));
-            }
-        });
-        assertThat(authenticator.canAuthenticate(someOtherRequest.getClass()), is(false));
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/isis/blob/ed318639/core/runtime/src/test/java/org/apache/isis/core/runtime/authentication/fixture/LogonFixtureAuthenticatorTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/authentication/fixture/LogonFixtureAuthenticatorTest.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/authentication/fixture/LogonFixtureAuthenticatorTest.java
deleted file mode 100644
index bcbeb32..0000000
--- a/core/runtime/src/test/java/org/apache/isis/core/runtime/authentication/fixture/LogonFixtureAuthenticatorTest.java
+++ /dev/null
@@ -1,131 +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.core.runtime.authentication.fixture;
-
-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.applib.fixtures.LogonFixture;
-import org.apache.isis.core.commons.config.IsisConfiguration;
-import org.apache.isis.core.runtime.authentication.AuthenticationRequestAbstract;
-import org.apache.isis.core.runtime.authentication.fixture.LogonFixtureAuthenticator;
-import org.apache.isis.core.runtime.fixtures.authentication.AuthenticationRequestLogonFixture;
-import org.apache.isis.core.runtime.system.DeploymentType;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-@RunWith(JMock.class)
-public class LogonFixtureAuthenticatorTest {
-
-    private final Mockery mockery = new JUnit4Mockery();
-
-    private IsisConfiguration mockConfiguration;
-    private LogonFixtureAuthenticator authenticator;
-
-    private AuthenticationRequestLogonFixture logonFixtureRequest;
-
-    private SomeOtherAuthenticationRequest someOtherRequest;
-
-    private static class SomeOtherAuthenticationRequest extends AuthenticationRequestAbstract {
-        public SomeOtherAuthenticationRequest() {
-            super("other");
-        }
-    }
-
-    @Before
-    public void setUp() {
-        mockConfiguration = mockery.mock(IsisConfiguration.class);
-
-        logonFixtureRequest = new AuthenticationRequestLogonFixture(new LogonFixture("joebloggs"));
-        someOtherRequest = new SomeOtherAuthenticationRequest();
-        authenticator = new LogonFixtureAuthenticator(mockConfiguration);
-    }
-
-    @Test
-    public void canAuthenticateExplorationRequest() throws Exception {
-        assertThat(authenticator.canAuthenticate(logonFixtureRequest.getClass()), is(true));
-    }
-
-    @Test
-    public void canAuthenticateSomeOtherTypeOfRequest() throws Exception {
-        assertThat(authenticator.canAuthenticate(someOtherRequest.getClass()), is(false));
-    }
-
-    @Test
-    public void isValidLogonFixtureRequestWhenRunningInExplorationMode() throws Exception {
-        mockery.checking(new Expectations() {
-            {
-                allowing(mockConfiguration).getString("isis.deploymentType");
-                will(returnValue(DeploymentType.SERVER_EXPLORATION.name()));
-            }
-        });
-        assertThat(authenticator.isValid(logonFixtureRequest), is(true));
-    }
-
-    @Test
-    public void isValidLogonFixtureRequestWhenRunningInPrototypeMode() throws Exception {
-        mockery.checking(new Expectations() {
-            {
-                allowing(mockConfiguration).getString("isis.deploymentType");
-                will(returnValue(DeploymentType.SERVER_PROTOTYPE.name()));
-            }
-        });
-        assertThat(authenticator.isValid(logonFixtureRequest), is(true));
-    }
-
-    @Test
-    public void isNotValidExplorationRequestWhenRunningInSomethingOtherThanExplorationOrPrototypeMode() throws Exception {
-        mockery.checking(new Expectations() {
-            {
-                allowing(mockConfiguration).getString("isis.deploymentType");
-                will(returnValue(DeploymentType.SERVER.name()));
-            }
-        });
-        assertThat(authenticator.isValid(logonFixtureRequest), is(false));
-    }
-
-    @Test(expected = IllegalStateException.class)
-    public void expectsThereToBeADeploymentTypeInIsisConfiguration() throws Exception {
-        mockery.checking(new Expectations() {
-            {
-                allowing(mockConfiguration).getString("isis.deploymentType");
-                will(returnValue(null));
-            }
-        });
-        authenticator.isValid(logonFixtureRequest);
-    }
-
-    @Test
-    public void isValidSomeOtherTypeOfRequest() throws Exception {
-        mockery.checking(new Expectations() {
-            {
-                allowing(mockConfiguration).getString("isis.deploymentType");
-                will(returnValue(DeploymentType.SERVER_EXPLORATION.name()));
-            }
-        });
-        assertThat(authenticator.canAuthenticate(SomeOtherAuthenticationRequest.class), is(false));
-    }
-
-}