Uses java-11 in naked objects

This commit is contained in:
Anurag Agarwal
2020-08-08 00:41:58 +00:00
parent b0ac4c1ca3
commit a5038c4329
17 changed files with 84 additions and 132 deletions

View File

@ -25,7 +25,6 @@ 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;
/**
@ -40,7 +39,7 @@ public final class SimpleAppSystemInitializer {
* Init test system
*/
public static void initIsft() {
IsisSystemForTest isft = IsisSystemForTest.getElseNull();
var isft = IsisSystemForTest.getElseNull();
if (isft == null) {
isft = new SimpleAppSystemBuilder().build().setUpSystem();
IsisSystemForTest.set(isft);
@ -51,15 +50,13 @@ public final class SimpleAppSystemInitializer {
public SimpleAppSystemBuilder() {
with(testConfiguration());
with(new DataNucleusPersistenceMechanismInstaller());
// services annotated with @DomainService
withServicesIn("domainapp");
}
private static IsisConfiguration testConfiguration() {
final IsisConfigurationForJdoIntegTests testConfiguration =
new IsisConfigurationForJdoIntegTests();
final var testConfiguration = new IsisConfigurationForJdoIntegTests();
testConfiguration.addRegisterEntitiesPackagePrefix("domainapp.dom.modules");
return testConfiguration;

View File

@ -23,10 +23,9 @@
package domainapp.integtests.specglue;
import org.apache.isis.core.specsupport.specs.CukeGlueAbstract;
import cucumber.api.java.Before;
import domainapp.fixture.scenarios.RecreateSimpleObjects;
import org.apache.isis.core.specsupport.specs.CukeGlueAbstract;
/**
* Test Execution to append a fixture of SimpleObjects
@ -34,7 +33,7 @@ import domainapp.fixture.scenarios.RecreateSimpleObjects;
public class CatalogOfFixturesGlue extends CukeGlueAbstract {
@Before(value = {"@integration", "@SimpleObjectsFixture"}, order = 20000)
public void integrationFixtures() throws Throwable {
public void integrationFixtures() {
scenarioExecution().install(new RecreateSimpleObjects());
}
}

View File

@ -28,9 +28,7 @@ import static org.junit.Assert.assertThat;
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 java.util.List;
import java.util.UUID;
import org.apache.isis.core.specsupport.specs.CukeGlueAbstract;
@ -40,9 +38,9 @@ import org.apache.isis.core.specsupport.specs.CukeGlueAbstract;
public class SimpleObjectGlue extends CukeGlueAbstract {
@Given("^there are.* (\\d+) simple objects$")
public void thereAreNumSimpleObjects(int n) throws Throwable {
public void thereAreNumSimpleObjects(int n) {
try {
final List<SimpleObject> findAll = service(SimpleObjects.class).listAll();
final var findAll = service(SimpleObjects.class).listAll();
assertThat(findAll.size(), is(n));
putVar("list", "all", findAll);
@ -52,7 +50,7 @@ public class SimpleObjectGlue extends CukeGlueAbstract {
}
@When("^I create a new simple object$")
public void createNewSimpleObject() throws Throwable {
public void createNewSimpleObject() {
service(SimpleObjects.class).create(UUID.randomUUID().toString());
}

View File

@ -26,8 +26,10 @@ package domainapp.integtests.tests.modules.simple;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import domainapp.dom.modules.simple.SimpleObject;
import domainapp.fixture.scenarios.RecreateSimpleObjects;
import domainapp.integtests.tests.SimpleAppIntegTest;
import javax.inject.Inject;
import org.apache.isis.applib.DomainObjectContainer;
import org.apache.isis.applib.fixturescripts.FixtureScripts;
import org.apache.isis.applib.services.wrapper.DisabledException;
@ -35,10 +37,6 @@ import org.apache.isis.applib.services.wrapper.InvalidException;
import org.junit.Before;
import org.junit.Test;
import domainapp.dom.modules.simple.SimpleObject;
import domainapp.fixture.scenarios.RecreateSimpleObjects;
import domainapp.integtests.tests.SimpleAppIntegTest;
/**
* Test Fixtures with Simple Objects
*/
@ -56,7 +54,7 @@ public class SimpleObjectIntegTest extends SimpleAppIntegTest {
private static final String NEW_NAME = "new name";
@Before
public void setUp() throws Exception {
public void setUp() {
// given
fs = new RecreateSimpleObjects().setNumber(1);
fixtureScripts.runFixtureScript(fs, null);
@ -68,15 +66,15 @@ public class SimpleObjectIntegTest extends SimpleAppIntegTest {
}
@Test
public void testNameAccessible() throws Exception {
// when
final String name = simpleObjectWrapped.getName();
public void testNameAccessible() {
/* when */
final var name = simpleObjectWrapped.getName();
// then
assertEquals(fs.names.get(0), name);
}
@Test
public void testNameCannotBeUpdatedDirectly() throws Exception {
public void testNameCannotBeUpdatedDirectly() {
// expect
expectedExceptions.expect(DisabledException.class);
@ -86,7 +84,7 @@ public class SimpleObjectIntegTest extends SimpleAppIntegTest {
}
@Test
public void testUpdateName() throws Exception {
public void testUpdateName() {
// when
simpleObjectWrapped.updateName(NEW_NAME);
@ -96,7 +94,7 @@ public class SimpleObjectIntegTest extends SimpleAppIntegTest {
}
@Test
public void testUpdateNameFailsValidation() throws Exception {
public void testUpdateNameFailsValidation() {
// expect
expectedExceptions.expect(InvalidException.class);
@ -107,13 +105,13 @@ public class SimpleObjectIntegTest extends SimpleAppIntegTest {
}
@Test
public void testInterpolatesName() throws Exception {
public void testInterpolatesName() {
// given
final String name = simpleObjectWrapped.getName();
final var name = simpleObjectWrapped.getName();
// when
final String title = container.titleOf(simpleObjectWrapped);
final var title = container.titleOf(simpleObjectWrapped);
// then
assertEquals("Object: " + name, title);

View File

@ -25,11 +25,13 @@ package domainapp.integtests.tests.modules.simple;
import static org.junit.Assert.assertEquals;
import com.google.common.base.Throwables;
import domainapp.dom.modules.simple.SimpleObjects;
import domainapp.fixture.modules.simple.SimpleObjectsTearDown;
import domainapp.fixture.scenarios.RecreateSimpleObjects;
import domainapp.integtests.tests.SimpleAppIntegTest;
import java.sql.SQLIntegrityConstraintViolationException;
import java.util.List;
import javax.inject.Inject;
import org.apache.isis.applib.fixturescripts.FixtureScript;
import org.apache.isis.applib.fixturescripts.FixtureScripts;
import org.hamcrest.Description;
@ -37,14 +39,6 @@ import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.junit.Test;
import com.google.common.base.Throwables;
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;
/**
* Fixture Pattern Integration Test
*/
@ -56,25 +50,25 @@ public class SimpleObjectsIntegTest extends SimpleAppIntegTest {
SimpleObjects simpleObjects;
@Test
public void testListAll() throws Exception {
public void testListAll() {
// given
RecreateSimpleObjects fs = new RecreateSimpleObjects();
var fs = new RecreateSimpleObjects();
fixtureScripts.runFixtureScript(fs, null);
nextTransaction();
// when
final List<SimpleObject> all = wrap(simpleObjects).listAll();
final var all = wrap(simpleObjects).listAll();
// then
assertEquals(fs.getSimpleObjects().size(), all.size());
SimpleObject simpleObject = wrap(all.get(0));
var simpleObject = wrap(all.get(0));
assertEquals(fs.getSimpleObjects().get(0).getName(), simpleObject.getName());
}
@Test
public void testListAllWhenNone() throws Exception {
public void testListAllWhenNone() {
// given
FixtureScript fs = new SimpleObjectsTearDown();
@ -82,14 +76,14 @@ public class SimpleObjectsIntegTest extends SimpleAppIntegTest {
nextTransaction();
// when
final List<SimpleObject> all = wrap(simpleObjects).listAll();
final var all = wrap(simpleObjects).listAll();
// then
assertEquals(0, all.size());
}
@Test
public void testCreate() throws Exception {
public void testCreate() {
// given
FixtureScript fs = new SimpleObjectsTearDown();
@ -100,12 +94,12 @@ public class SimpleObjectsIntegTest extends SimpleAppIntegTest {
wrap(simpleObjects).create("Faz");
// then
final List<SimpleObject> all = wrap(simpleObjects).listAll();
final var all = wrap(simpleObjects).listAll();
assertEquals(1, all.size());
}
@Test
public void testCreateWhenAlreadyExists() throws Exception {
public void testCreateWhenAlreadyExists() {
// given
FixtureScript fs = new SimpleObjectsTearDown();
@ -115,24 +109,24 @@ public class SimpleObjectsIntegTest extends SimpleAppIntegTest {
nextTransaction();
// then
expectedExceptions.expectCause(causalChainContains(SQLIntegrityConstraintViolationException.class));
expectedExceptions
.expectCause(causalChainContains(SQLIntegrityConstraintViolationException.class));
// when
wrap(simpleObjects).create("Faz");
nextTransaction();
}
@SuppressWarnings("SameParameterValue")
private static Matcher<? extends Throwable> causalChainContains(final Class<?> cls) {
return new TypeSafeMatcher<Throwable>() {
return new TypeSafeMatcher<>() {
@Override
@SuppressWarnings("UnstableApiUsage")
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;
final var causalChain = Throwables.getCausalChain(item);
return causalChain.stream()
.map(Throwable::getClass)
.allMatch(cls::isAssignableFrom);
}
@Override