#91 Added skeleton for naked-objects example using Apache Isis SimpleApp archetype

This commit is contained in:
Ilkka Seppala
2015-07-13 15:19:16 +03:00
parent aa491b2458
commit 5337ecdc35
62 changed files with 5304 additions and 6 deletions

1
naked-objects/integtests/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/translations.pot

View File

@ -0,0 +1,111 @@
# 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.
#
# Isis uses log4j is used to provide system logging
#
log4j.rootCategory=INFO, Console
# The console appender
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.target=System.out
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d{ABSOLUTE} [%-20c{1} %-10t %-5p] %m%n
log4j.appender.File=org.apache.log4j.RollingFileAppender
log4j.appender.File.file=isis.log
log4j.appender.File.append=false
log4j.appender.File.layout=org.apache.log4j.PatternLayout
log4j.appender.File.layout.ConversionPattern=%d [%-20c{1} %-10t %-5p] %m%n
log4j.appender.translations-po=org.apache.log4j.FileAppender
log4j.appender.translations-po.File=./translations.pot
log4j.appender.translations-po.Append=false
log4j.appender.translations-po.layout=org.apache.log4j.PatternLayout
log4j.appender.translations-po.layout.ConversionPattern=%m%n
! turn on the internal log4j debugging flag so we can see what it is doing
#log4j.debug=true
# DataNucleus
# the first two log the DML and DDL (if set to DEBUG)
log4j.logger.DataNucleus.Datastore.Native=WARN, Console
log4j.logger.DataNucleus.Datastore.Schema=DEBUG, Console
# the remainder can probably be left to WARN
log4j.logger.DataNucleus.Persistence=WARN, Console
log4j.logger.DataNucleus.Transaction=WARN, Console
log4j.logger.DataNucleus.Connection=WARN, Console
log4j.logger.DataNucleus.Query=WARN, Console
log4j.logger.DataNucleus.Cache=WARN, Console
log4j.logger.DataNucleus.MetaData=WARN, Console
log4j.logger.DataNucleus.Datastore=WARN, Console
log4j.logger.DataNucleus.Datastore.Persist=WARN, Console
log4j.logger.DataNucleus.Datastore.Retrieve=WARN, Console
log4j.logger.DataNucleus.General=WARN, Console
log4j.logger.DataNucleus.Lifecycle=WARN, Console
log4j.logger.DataNucleus.ValueGeneration=WARN, Console
log4j.logger.DataNucleus.Enhancer=WARN, Console
log4j.logger.DataNucleus.SchemaTool=ERROR, Console
log4j.logger.DataNucleus.JDO=WARN, Console
log4j.logger.DataNucleus.JPA=ERROR, Console
log4j.logger.DataNucleus.JCA=WARN, Console
log4j.logger.DataNucleus.IDE=ERROR, Console
log4j.additivity.DataNucleus.Datastore.Native=false
log4j.additivity.DataNucleus.Datastore.Schema=false
log4j.additivity.DataNucleus.Datastore.Persistence=false
log4j.additivity.DataNucleus.Datastore.Transaction=false
log4j.additivity.DataNucleus.Datastore.Connection=false
log4j.additivity.DataNucleus.Datastore.Query=false
log4j.additivity.DataNucleus.Datastore.Cache=false
log4j.additivity.DataNucleus.Datastore.MetaData=false
log4j.additivity.DataNucleus.Datastore.Datastore=false
log4j.additivity.DataNucleus.Datastore.Datastore.Persist=false
log4j.additivity.DataNucleus.Datastore.Datastore.Retrieve=false
log4j.additivity.DataNucleus.Datastore.General=false
log4j.additivity.DataNucleus.Datastore.Lifecycle=false
log4j.additivity.DataNucleus.Datastore.ValueGeneration=false
log4j.additivity.DataNucleus.Datastore.Enhancer=false
log4j.additivity.DataNucleus.Datastore.SchemaTool=false
log4j.additivity.DataNucleus.Datastore.JDO=false
log4j.additivity.DataNucleus.Datastore.JPA=false
log4j.additivity.DataNucleus.Datastore.JCA=false
log4j.additivity.DataNucleus.Datastore.IDE=false
# if using log4jdbc-remix as JDBC driver
#log4j.logger.jdbc.sqlonly=DEBUG, sql, Console
#log4j.additivity.jdbc.sqlonly=false
#log4j.logger.jdbc.resultsettable=DEBUG, jdbc, Console
#log4j.additivity.jdbc.resultsettable=false
#log4j.logger.jdbc.audit=WARN,jdbc, Console
#log4j.additivity.jdbc.audit=false
#log4j.logger.jdbc.resultset=WARN,jdbc
#log4j.additivity.jdbc.resultset=false
#log4j.logger.jdbc.sqltiming=WARN,sqltiming
#log4j.additivity.jdbc.sqltiming=false
#log4j.logger.jdbc.connection=FATAL,connection
#log4j.additivity.jdbc.connection=false
log4j.logger.org.apache.isis.core.runtime.services.i18n.po.PoWriter=INFO,translations-po
log4j.additivity.org.apache.isis.core.runtime.services.i18n.po.PotWriter=false

View File

@ -0,0 +1,128 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
--><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>naked-objects</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>naked-objects-integtests</artifactId>
<name>Simple App Integration Tests</name>
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
<testResource>
<directory>src/test/java</directory>
<includes>
<include>**</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
</build>
<dependencies>
<!-- other modules in this project -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>naked-objects-fixture</artifactId>
</dependency>
<dependency>
<groupId>org.apache.isis.core</groupId>
<artifactId>isis-core-unittestsupport</artifactId>
</dependency>
<dependency>
<groupId>org.apache.isis.core</groupId>
<artifactId>isis-core-integtestsupport</artifactId>
</dependency>
<dependency>
<groupId>org.apache.isis.core</groupId>
<artifactId>isis-core-specsupport</artifactId>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
</dependency>
<dependency>
<groupId>org.apache.isis.core</groupId>
<artifactId>isis-core-wrapper</artifactId>
</dependency>
<dependency>
<groupId>org.apache.isis.core</groupId>
<artifactId>isis-core-runtime</artifactId>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
</dependency>
<!--
uncomment to enable enhanced cucumber-jvm reporting
http://www.masterthought.net/section/cucumber-reporting
<dependency>
<groupId>com.googlecode.totallylazy</groupId>
<artifactId>totallylazy</artifactId>
<version>991</version>
</dependency>
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>0.0.21</version>
</dependency>
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>0.0.4</version>
</dependency>
-->
</dependencies>
<!--
uncomment for enhanced cucumber-jvm reporting
http://www.masterthought.net/section/cucumber-reporting
<repositories>
<repository>
<id>repo.bodar.com</id>
<url>http://repo.bodar.com</url>
</repository>
</repositories>
-->
</project>

View File

@ -0,0 +1,54 @@
/*
* 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 domainapp.integtests.bootstrap;
import org.apache.isis.core.commons.config.IsisConfiguration;
import org.apache.isis.core.integtestsupport.IsisSystemForTest;
import org.apache.isis.objectstore.jdo.datanucleus.DataNucleusPersistenceMechanismInstaller;
import org.apache.isis.objectstore.jdo.datanucleus.IsisConfigurationForJdoIntegTests;
public class SimpleAppSystemInitializer {
public static void initIsft() {
IsisSystemForTest isft = IsisSystemForTest.getElseNull();
if(isft == null) {
isft = new SimpleAppSystemBuilder().build().setUpSystem();
IsisSystemForTest.set(isft);
}
}
private static class SimpleAppSystemBuilder extends IsisSystemForTest.Builder {
public SimpleAppSystemBuilder() {
withLoggingAt(org.apache.log4j.Level.INFO);
with(testConfiguration());
with(new DataNucleusPersistenceMechanismInstaller());
// services annotated with @DomainService
withServicesIn( "domainapp" );
}
private static IsisConfiguration testConfiguration() {
final IsisConfigurationForJdoIntegTests testConfiguration = new IsisConfigurationForJdoIntegTests();
testConfiguration.addRegisterEntitiesPackagePrefix("domainapp.dom.modules");
return testConfiguration;
}
}
}

View File

@ -0,0 +1,41 @@
/**
O * 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 domainapp.integtests.specglue;
import org.apache.isis.core.specsupport.scenarios.ScenarioExecutionScope;
import org.apache.isis.core.specsupport.specs.CukeGlueAbstract;
import cucumber.api.java.After;
import cucumber.api.java.Before;
import domainapp.integtests.bootstrap.SimpleAppSystemInitializer;
public class BootstrappingGlue extends CukeGlueAbstract {
@Before(value={"@integration"}, order=100)
public void beforeScenarioIntegrationScope() {
org.apache.log4j.PropertyConfigurator.configure("logging.properties");
SimpleAppSystemInitializer.initIsft();
before(ScenarioExecutionScope.INTEGRATION);
}
@After
public void afterScenario(cucumber.api.Scenario sc) {
assertMocksSatisfied();
after(sc);
}
}

View File

@ -0,0 +1,31 @@
/**
* 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 domainapp.integtests.specglue;
import org.apache.isis.core.specsupport.specs.CukeGlueAbstract;
import cucumber.api.java.Before;
import domainapp.fixture.scenarios.RecreateSimpleObjects;
public class CatalogOfFixturesGlue extends CukeGlueAbstract {
@Before(value={"@integration", "@SimpleObjectsFixture"}, order=20000)
public void integrationFixtures() throws Throwable {
scenarioExecution().install(new RecreateSimpleObjects());
}
}

View File

@ -0,0 +1,50 @@
/**
* 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 domainapp.integtests.specglue.modules.simple;
import java.util.List;
import java.util.UUID;
import org.apache.isis.core.specsupport.specs.CukeGlueAbstract;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.When;
import domainapp.dom.modules.simple.SimpleObject;
import domainapp.dom.modules.simple.SimpleObjects;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
public class SimpleObjectGlue extends CukeGlueAbstract {
@Given("^there are.* (\\d+) simple objects$")
public void there_are_N_simple_objects(int n) throws Throwable {
try {
final List<SimpleObject> findAll = service(SimpleObjects.class).listAll();
assertThat(findAll.size(), is(n));
putVar("list", "all", findAll);
} finally {
assertMocksSatisfied();
}
}
@When("^I create a new simple object$")
public void I_create_a_new_simple_object() throws Throwable {
service(SimpleObjects.class).create(UUID.randomUUID().toString());
}
}

View File

@ -0,0 +1,39 @@
/**
* 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 domainapp.integtests.specs;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
/**
* Runs scenarios in all <tt>.feature</tt> files (this package and any subpackages).
*/
@RunWith(Cucumber.class)
@CucumberOptions(
format = {
"html:target/cucumber-html-report"
,"json:target/cucumber.json"
},
glue={"classpath:domainapp.integtests.specglue"},
strict = true,
tags = { "~@backlog", "~@ignore" })
public class RunSpecs {
// intentionally empty
}

View File

@ -0,0 +1,26 @@
#
# 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.
#
@SimpleObjectsFixture
Feature: List and Create New Simple Objects
@integration
Scenario: Existing simple objects can be listed and new ones created
Given there are initially 3 simple objects
When I create a new simple object
Then there are 4 simple objects

View File

@ -0,0 +1,39 @@
/*
* 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 domainapp.integtests.tests;
import org.junit.BeforeClass;
import org.apache.isis.core.integtestsupport.IntegrationTestAbstract;
import org.apache.isis.core.integtestsupport.scenarios.ScenarioExecutionForIntegration;
import domainapp.integtests.bootstrap.SimpleAppSystemInitializer;
public abstract class SimpleAppIntegTest extends IntegrationTestAbstract {
@BeforeClass
public static void initClass() {
org.apache.log4j.PropertyConfigurator.configure("logging.properties");
SimpleAppSystemInitializer.initIsft();
// instantiating will install onto ThreadLocal
new ScenarioExecutionForIntegration();
}
}

View File

@ -0,0 +1,121 @@
/*
* 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 domainapp.integtests.tests.modules.simple;
import javax.inject.Inject;
import org.junit.Before;
import org.junit.Test;
import org.apache.isis.applib.DomainObjectContainer;
import org.apache.isis.applib.fixturescripts.FixtureScripts;
import org.apache.isis.applib.services.wrapper.DisabledException;
import org.apache.isis.applib.services.wrapper.InvalidException;
import domainapp.dom.modules.simple.SimpleObject;
import domainapp.fixture.scenarios.RecreateSimpleObjects;
import domainapp.integtests.tests.SimpleAppIntegTest;
import static org.assertj.core.api.Assertions.assertThat;
public class SimpleObjectIntegTest extends SimpleAppIntegTest {
@Inject
FixtureScripts fixtureScripts;
RecreateSimpleObjects fs;
SimpleObject simpleObjectPojo;
SimpleObject simpleObjectWrapped;
@Before
public void setUp() throws Exception {
// given
fs = new RecreateSimpleObjects().setNumber(1);
fixtureScripts.runFixtureScript(fs, null);
simpleObjectPojo = fs.getSimpleObjects().get(0);
assertThat(simpleObjectPojo).isNotNull();
simpleObjectWrapped = wrap(simpleObjectPojo);
}
public static class Name extends SimpleObjectIntegTest {
@Test
public void accessible() throws Exception {
// when
final String name = simpleObjectWrapped.getName();
// then
assertThat(name).isEqualTo(fs.NAMES.get(0));
}
@Test
public void cannotBeUpdatedDirectly() throws Exception {
// expect
expectedExceptions.expect(DisabledException.class);
// when
simpleObjectWrapped.setName("new name");
}
}
public static class UpdateName extends SimpleObjectIntegTest {
@Test
public void happyCase() throws Exception {
// when
simpleObjectWrapped.updateName("new name");
// then
assertThat(simpleObjectWrapped.getName()).isEqualTo("new name");
}
@Test
public void failsValidation() throws Exception {
// expect
expectedExceptions.expect(InvalidException.class);
expectedExceptions.expectMessage("Exclamation mark is not allowed");
// when
simpleObjectWrapped.updateName("new name!");
}
}
public static class Title extends SimpleObjectIntegTest {
@Inject
DomainObjectContainer container;
@Test
public void interpolatesName() throws Exception {
// given
final String name = simpleObjectWrapped.getName();
// when
final String title = container.titleOf(simpleObjectWrapped);
// then
assertThat(title).isEqualTo("Object: " + name);
}
}
}

View File

@ -0,0 +1,143 @@
/*
* 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 domainapp.integtests.tests.modules.simple;
import java.sql.SQLIntegrityConstraintViolationException;
import java.util.List;
import javax.inject.Inject;
import com.google.common.base.Throwables;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.junit.Test;
import org.apache.isis.applib.fixturescripts.FixtureScript;
import org.apache.isis.applib.fixturescripts.FixtureScripts;
import domainapp.dom.modules.simple.SimpleObject;
import domainapp.dom.modules.simple.SimpleObjects;
import domainapp.fixture.modules.simple.SimpleObjectsTearDown;
import domainapp.fixture.scenarios.RecreateSimpleObjects;
import domainapp.integtests.tests.SimpleAppIntegTest;
import static org.assertj.core.api.Assertions.assertThat;
public class SimpleObjectsIntegTest extends SimpleAppIntegTest {
@Inject
FixtureScripts fixtureScripts;
@Inject
SimpleObjects simpleObjects;
public static class ListAll extends SimpleObjectsIntegTest {
@Test
public void happyCase() throws Exception {
// given
RecreateSimpleObjects fs = new RecreateSimpleObjects();
fixtureScripts.runFixtureScript(fs, null);
nextTransaction();
// when
final List<SimpleObject> all = wrap(simpleObjects).listAll();
// then
assertThat(all).hasSize(fs.getSimpleObjects().size());
SimpleObject simpleObject = wrap(all.get(0));
assertThat(simpleObject.getName()).isEqualTo(fs.getSimpleObjects().get(0).getName());
}
@Test
public void whenNone() throws Exception {
// given
FixtureScript fs = new SimpleObjectsTearDown();
fixtureScripts.runFixtureScript(fs, null);
nextTransaction();
// when
final List<SimpleObject> all = wrap(simpleObjects).listAll();
// then
assertThat(all).hasSize(0);
}
}
public static class Create extends SimpleObjectsIntegTest {
@Test
public void happyCase() throws Exception {
// given
FixtureScript fs = new SimpleObjectsTearDown();
fixtureScripts.runFixtureScript(fs, null);
nextTransaction();
// when
wrap(simpleObjects).create("Faz");
// then
final List<SimpleObject> all = wrap(simpleObjects).listAll();
assertThat(all).hasSize(1);
}
@Test
public void whenAlreadyExists() throws Exception {
// given
FixtureScript fs = new SimpleObjectsTearDown();
fixtureScripts.runFixtureScript(fs, null);
nextTransaction();
wrap(simpleObjects).create("Faz");
nextTransaction();
// then
expectedExceptions.expectCause(causalChainContains(SQLIntegrityConstraintViolationException.class));
// when
wrap(simpleObjects).create("Faz");
nextTransaction();
}
private static Matcher<? extends Throwable> causalChainContains(final Class<?> cls) {
return new TypeSafeMatcher<Throwable>() {
@Override
protected boolean matchesSafely(Throwable item) {
final List<Throwable> causalChain = Throwables.getCausalChain(item);
for (Throwable throwable : causalChain) {
if(cls.isAssignableFrom(throwable.getClass())){
return true;
}
}
return false;
}
@Override
public void describeTo(Description description) {
description.appendText("exception with causal chain containing " + cls.getSimpleName());
}
};
}
}
}