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 2010/11/05 15:48:59 UTC

svn commit: r1031603 - in /incubator/isis/trunk/support/prototype/quickrun: ./ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/isis/ src/test/java/org/apache/isis/support/ src/test/java/org/apache/isis/support/prototype/ src/test/...

Author: danhaywood
Date: Fri Nov  5 14:48:58 2010
New Revision: 1031603

URL: http://svn.apache.org/viewvc?rev=1031603&view=rev
Log:
added junit tests to quickrun

Added:
    incubator/isis/trunk/support/prototype/quickrun/src/test/java/org/
    incubator/isis/trunk/support/prototype/quickrun/src/test/java/org/apache/
    incubator/isis/trunk/support/prototype/quickrun/src/test/java/org/apache/isis/
    incubator/isis/trunk/support/prototype/quickrun/src/test/java/org/apache/isis/support/
    incubator/isis/trunk/support/prototype/quickrun/src/test/java/org/apache/isis/support/prototype/
    incubator/isis/trunk/support/prototype/quickrun/src/test/java/org/apache/isis/support/prototype/junit/
    incubator/isis/trunk/support/prototype/quickrun/src/test/java/org/apache/isis/support/prototype/junit/AbstractTest.java
    incubator/isis/trunk/support/prototype/quickrun/src/test/java/org/apache/isis/support/prototype/junit/ClaimSubmitTest.java
    incubator/isis/trunk/support/prototype/quickrun/src/test/java/org/apache/isis/support/prototype/junit/NewClaimTest.java
Modified:
    incubator/isis/trunk/support/prototype/quickrun/pom.xml

Modified: incubator/isis/trunk/support/prototype/quickrun/pom.xml
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/support/prototype/quickrun/pom.xml?rev=1031603&r1=1031602&r2=1031603&view=diff
==============================================================================
--- incubator/isis/trunk/support/prototype/quickrun/pom.xml (original)
+++ incubator/isis/trunk/support/prototype/quickrun/pom.xml Fri Nov  5 14:48:58 2010
@@ -65,6 +65,14 @@
 			<groupId>org.apache.isis.alternatives.objectstore</groupId>
 			<artifactId>xml</artifactId>
 		</dependency>
+
+        <!-- JUnit Viewer dependencies -->
+        <dependency>
+            <groupId>org.apache.isis.viewer</groupId>
+            <artifactId>junit</artifactId>
+            <version>0.1-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>
         
 		<!--  JETTY DEPENDENCIES FOR TESTING  -->
 		<dependency>

Added: incubator/isis/trunk/support/prototype/quickrun/src/test/java/org/apache/isis/support/prototype/junit/AbstractTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/support/prototype/quickrun/src/test/java/org/apache/isis/support/prototype/junit/AbstractTest.java?rev=1031603&view=auto
==============================================================================
--- incubator/isis/trunk/support/prototype/quickrun/src/test/java/org/apache/isis/support/prototype/junit/AbstractTest.java (added)
+++ incubator/isis/trunk/support/prototype/quickrun/src/test/java/org/apache/isis/support/prototype/junit/AbstractTest.java Fri Nov  5 14:48:58 2010
@@ -0,0 +1,113 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.support.prototype.junit;
+
+import org.apache.isis.applib.DomainObjectContainer;
+import org.apache.isis.progmodel.wrapper.applib.WrapperFactory;
+import org.apache.isis.progmodel.wrapper.applib.WrapperObject;
+import org.apache.isis.support.prototype.dom.claim.ClaimRepository;
+import org.apache.isis.support.prototype.dom.employee.Employee;
+import org.apache.isis.support.prototype.dom.employee.EmployeeRepository;
+import org.apache.isis.support.prototype.objstore.dflt.claim.ClaimRepositoryInMemory;
+import org.apache.isis.support.prototype.objstore.dflt.employee.EmployeeRepositoryInMemory;
+import org.apache.isis.viewer.junit.IsisTestRunner;
+import org.apache.isis.viewer.junit.Service;
+import org.apache.isis.viewer.junit.Services;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.runner.RunWith;
+
+@RunWith(IsisTestRunner.class)
+@Services({ @Service(ClaimRepositoryInMemory.class), @Service(EmployeeRepositoryInMemory.class) })
+public abstract class AbstractTest {
+
+    private DomainObjectContainer domainObjectContainer;
+    private WrapperFactory wrapperFactory;
+
+    /**
+     * The {@link WrapperFactory#wrap(Object) wrapped} equivalent of the {@link #setClaimRepository(ClaimRepository)
+     * injected} {@link ClaimRepository}.
+     */
+    protected ClaimRepository claimRepository;
+    /**
+     * The {@link WrapperFactory#wrap(Object) wrapped} equivalent of the
+     * {@link #setEmployeeRepository(EmployeeRepository) injected} {@link EmployeeRepository}.
+     */
+    protected EmployeeRepository employeeRepository;
+
+    protected Employee tomEmployee;
+
+    @Before
+    public void wrapInjectedServices() throws Exception {
+        claimRepository = wrapped(claimRepository);
+        employeeRepository = wrapped(employeeRepository);
+    }
+
+    @Before
+    public void setUp() {
+        tomEmployee = wrapped(employeeRepository.findEmployees("Tom").get(0));
+    }
+
+    protected <T> T wrapped(T obj) {
+        return wrapperFactory.wrap(obj);
+    }
+
+    @SuppressWarnings("unchecked")
+    protected <T> T unwrapped(T obj) {
+        if (obj instanceof WrapperObject) {
+            WrapperObject<?> wrapperObject = (WrapperObject<?>) obj;
+            return (T) wrapperObject.wrapped();
+        }
+        return obj;
+    }
+
+    @After
+    public void tearDown() {
+    }
+
+    // //////////////////////////////////////////////////////
+    // Injected.
+    // //////////////////////////////////////////////////////
+
+    protected WrapperFactory getWrapperFactory() {
+        return wrapperFactory;
+    }
+
+    public void setWrapperFactory(WrapperFactory wrapperFactory) {
+        this.wrapperFactory = wrapperFactory;
+    }
+
+    protected DomainObjectContainer getDomainObjectContainer() {
+        return domainObjectContainer;
+    }
+
+    public void setDomainObjectContainer(final DomainObjectContainer domainObjectContainer) {
+        this.domainObjectContainer = domainObjectContainer;
+    }
+
+    public void setClaimRepository(final ClaimRepository claimRepository) {
+        this.claimRepository = claimRepository;
+    }
+
+    public void setEmployeeRepository(final EmployeeRepository employeeRepository) {
+        this.employeeRepository = employeeRepository;
+    }
+
+}

Added: incubator/isis/trunk/support/prototype/quickrun/src/test/java/org/apache/isis/support/prototype/junit/ClaimSubmitTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/support/prototype/quickrun/src/test/java/org/apache/isis/support/prototype/junit/ClaimSubmitTest.java?rev=1031603&view=auto
==============================================================================
--- incubator/isis/trunk/support/prototype/quickrun/src/test/java/org/apache/isis/support/prototype/junit/ClaimSubmitTest.java (added)
+++ incubator/isis/trunk/support/prototype/quickrun/src/test/java/org/apache/isis/support/prototype/junit/ClaimSubmitTest.java Fri Nov  5 14:48:58 2010
@@ -0,0 +1,59 @@
+/*
+ *  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.support.prototype.junit;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+
+import java.util.List;
+
+import org.apache.isis.progmodel.wrapper.applib.DisabledException;
+import org.apache.isis.support.prototype.dom.claim.Approver;
+import org.apache.isis.support.prototype.dom.claim.Claim;
+import org.apache.isis.support.prototype.fixture.ClaimsFixture;
+import org.apache.isis.viewer.junit.Fixture;
+import org.apache.isis.viewer.junit.Fixtures;
+import org.junit.Test;
+
+@Fixtures({ @Fixture(ClaimsFixture.class) })
+public class ClaimSubmitTest extends AbstractTest {
+
+    @Test
+    public void cannotSubmitTwice() throws Exception {
+        Claim tomsSubmittedClaim = tomsSubmittedClaim();
+        try {
+            Approver approver = tomEmployee.getApprover();
+            tomsSubmittedClaim.submit(approver);
+            fail("Should not be able to submit again");
+        } catch (DisabledException e) {
+            assertThat(e.getMessage(), is("Claim has already been submitted"));
+        }
+    }
+
+    private Claim tomsSubmittedClaim() {
+        List<Claim> tomsClaims = claimRepository.claimsFor(tomEmployee);
+        Claim tomsClaim1 = tomsClaims.get(0);
+        tomsClaim1.submit(tomEmployee.getApprover());
+        assertThat(tomsClaim1.getStatus(), is("Submitted"));
+        return wrapped(tomsClaim1);
+    }
+
+}

Added: incubator/isis/trunk/support/prototype/quickrun/src/test/java/org/apache/isis/support/prototype/junit/NewClaimTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/support/prototype/quickrun/src/test/java/org/apache/isis/support/prototype/junit/NewClaimTest.java?rev=1031603&view=auto
==============================================================================
--- incubator/isis/trunk/support/prototype/quickrun/src/test/java/org/apache/isis/support/prototype/junit/NewClaimTest.java (added)
+++ incubator/isis/trunk/support/prototype/quickrun/src/test/java/org/apache/isis/support/prototype/junit/NewClaimTest.java Fri Nov  5 14:48:58 2010
@@ -0,0 +1,43 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.support.prototype.junit;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.apache.isis.support.prototype.dom.claim.Claim;
+import org.apache.isis.support.prototype.fixture.ClaimsFixture;
+import org.apache.isis.viewer.junit.Fixture;
+import org.apache.isis.viewer.junit.Fixtures;
+import org.junit.Test;
+
+@Fixtures({ @Fixture(ClaimsFixture.class) })
+public class NewClaimTest extends AbstractTest {
+
+    @Test
+    public void whenCreateNewClaimDefaultsOk() throws Exception {
+        Claim newClaim = claimRepository.newClaim(tomEmployee);
+        assertThat(newClaim.getDescription(), is("enter a description here"));
+        assertThat(newClaim.getStatus(), is("New"));
+        assertThat(newClaim.getApprover(), is(tomEmployee.getApprover()));
+        assertThat(newClaim.getItems().size(), is(0));
+    }
+
+}