diff --git a/challenger/src/test/java/uk/co/compendiumdev/challenger/http/completechallenges/ChallengeCompleteTest.java b/challenger/src/test/java/uk/co/compendiumdev/challenger/http/completechallenges/ChallengeCompleteTest.java index 4caf910e..dd35c28e 100644 --- a/challenger/src/test/java/uk/co/compendiumdev/challenger/http/completechallenges/ChallengeCompleteTest.java +++ b/challenger/src/test/java/uk/co/compendiumdev/challenger/http/completechallenges/ChallengeCompleteTest.java @@ -487,7 +487,7 @@ public void canPostTodosUpdatePass() { ensureAtMostXTodoAvailable(10); final EntityInstanceCollection todos = ChallengeMain.getChallenger().getThingifier().getThingInstancesNamed("todo", challenger.getXChallenger()); - final EntityInstance todo = todos.createManagedInstance(); + final EntityInstance todo = todos.addInstance( new EntityInstance(todos.definition())); Map x_challenger_header = getXChallengerHeader(challenger.getXChallenger()); @@ -634,7 +634,7 @@ public void canDeleteTodosPass() { ensureAtMostXTodoAvailable(10); final EntityInstanceCollection todos = ChallengeMain.getChallenger().getThingifier().getThingInstancesNamed("todo", challenger.getXChallenger()); - final EntityInstance todo = todos.createManagedInstance(); + final EntityInstance todo = todos.addInstance( new EntityInstance(todos.definition())); Map x_challenger_header = getXChallengerHeader(challenger.getXChallenger()); @@ -653,7 +653,7 @@ public void canDeleteTodosPass() { public void canGetSpecificTodoPass() { final EntityInstanceCollection todos = ChallengeMain.getChallenger().getThingifier().getThingInstancesNamed("todo", challenger.getXChallenger()); - final EntityInstance todo = todos.createManagedInstance(); + final EntityInstance todo = todos.addInstance(new EntityInstance(todos.definition())); Map x_challenger_header = getXChallengerHeader(challenger.getXChallenger()); @@ -769,8 +769,8 @@ public void canFilterTodoPass() { final EntityInstanceCollection todos = ChallengeMain.getChallenger().getThingifier().getThingInstancesNamed("todo", challenger.getXChallenger()); - todos.createManagedInstance().setValue("doneStatus", "true"); - todos.createManagedInstance().setValue("doneStatus", "false"); + todos.addInstance(new EntityInstance(todos.definition())).setValue("doneStatus", "true"); + todos.addInstance(new EntityInstance(todos.definition())).setValue("doneStatus", "false"); final HttpResponseDetails response = http.send("/todos?doneStatus=true", "GET", x_challenger_header, ""); @@ -1121,10 +1121,10 @@ public void canDeleteAllTodos() { // add some todos in case this is not the last test - todos.createManagedInstance(); - todos.createManagedInstance(); - todos.createManagedInstance(); - todos.createManagedInstance(); + todos.addInstance(new EntityInstance(todos.definition())); + todos.addInstance(new EntityInstance(todos.definition())); + todos.addInstance(new EntityInstance(todos.definition())); + todos.addInstance(new EntityInstance(todos.definition())); } diff --git a/ercoremodel/src/main/java/uk/co/compendiumdev/thingifier/core/domain/instances/EntityInstanceCollection.java b/ercoremodel/src/main/java/uk/co/compendiumdev/thingifier/core/domain/instances/EntityInstanceCollection.java index ba2efd05..bd8da7d8 100644 --- a/ercoremodel/src/main/java/uk/co/compendiumdev/thingifier/core/domain/instances/EntityInstanceCollection.java +++ b/ercoremodel/src/main/java/uk/co/compendiumdev/thingifier/core/domain/instances/EntityInstanceCollection.java @@ -137,12 +137,6 @@ public EntityInstance addInstance(EntityInstance instance) { return instance; } - /* create and add */ - // TODO: this looks like it was added to support testing, consider removing and adding to a test helper - public EntityInstance createManagedInstance() { - return addInstance( new EntityInstance(definition)); - } - public int countInstances() { return instances.size(); } diff --git a/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/EntityRelModelTest.java b/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/EntityRelModelTest.java index c7f53808..49f05091 100644 --- a/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/EntityRelModelTest.java +++ b/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/EntityRelModelTest.java @@ -81,7 +81,7 @@ public void canFindAThingInAModel() { EntityInstanceCollection thing = erm.getInstanceData().getInstanceCollectionForEntityNamed("thing"); - final EntityInstance instance = thing.createManagedInstance(); + final EntityInstance instance = thing.addInstance(new EntityInstance(thing.definition())); final String thingGUID1 = instance.getPrimaryKeyValue(); Assertions.assertNotNull( @@ -98,7 +98,7 @@ public void canDeleteAThingInAModel() { erm.createEntityDefinition("thing", "things"); EntityInstanceCollection thing = erm.getInstanceData().getInstanceCollectionForEntityNamed("thing"); - final EntityInstance instance = thing.createManagedInstance(); + final EntityInstance instance = thing.addInstance(new EntityInstance(thing.definition())); erm.getInstanceData().deleteEntityInstance(instance); final String thingGUID = instance.getPrimaryKeyValue(); @@ -118,11 +118,11 @@ public void canClearAllDataInAModel() { erm.createEntityDefinition("thing2", "thing2"); EntityInstanceCollection thing2 = erm.getInstanceData().getInstanceCollectionForEntityNamed("thing2"); - thing.createManagedInstance(); - thing.createManagedInstance(); - thing2.createManagedInstance(); - thing2.createManagedInstance(); - thing2.createManagedInstance(); + thing.addInstance(new EntityInstance(thing.definition())); + thing.addInstance(new EntityInstance(thing.definition())); + thing2.addInstance(new EntityInstance(thing2.definition())); + thing2.addInstance(new EntityInstance(thing2.definition())); + thing2.addInstance(new EntityInstance(thing2.definition())); Assertions.assertEquals(2, erm.getInstanceData().getAllInstanceCollections().size()); Assertions.assertEquals(2, @@ -195,13 +195,13 @@ public void canDeleteAThingWithRelationships() { getReversedRelationship(). setOptionality(Optionality.MANDATORY_RELATIONSHIP); - final EntityInstance mainThing = thing.createManagedInstance(); + final EntityInstance mainThing = thing.addInstance(new EntityInstance(thing.definition())); mainThing.getRelationships().connect("things", - dependent.createManagedInstance()); + dependent.addInstance(new EntityInstance(dependent.definition()))); mainThing.getRelationships().connect("things", - dependent.createManagedInstance()); + dependent.addInstance(new EntityInstance(dependent.definition()))); mainThing.getRelationships().connect("things", - dependent.createManagedInstance()); + dependent.addInstance(new EntityInstance(dependent.definition()))); Assertions.assertEquals(2, erm.getInstanceData().getAllInstanceCollections().size()); Assertions.assertEquals(3, mainThing.getRelationships(). diff --git a/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/ThingTest.java b/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/ThingTest.java index 362cdbe3..9504f4aa 100644 --- a/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/ThingTest.java +++ b/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/ThingTest.java @@ -24,12 +24,12 @@ public void thingUsageExample(){ person.definition(). addFields(Field.is("name", STRING), Field.is("age", INTEGER)); - EntityInstance bob = person.createManagedInstance(). + EntityInstance bob = person.addInstance(new EntityInstance(person.definition())). setValue("name","Bob"); bob.setValue("age", "56"); - EntityInstance eris = person.createManagedInstance(). + EntityInstance eris = person.addInstance(new EntityInstance(person.definition())). setValue("name","Eris").setValue("age", "1000"); Assertions.assertEquals(2, person.countInstances()); @@ -52,12 +52,12 @@ public void moreThingUsageExamples(){ Assertions.assertTrue(url.definition().hasFieldNameDefined("visited")); - url.createManagedInstance(). + url.addInstance(new EntityInstance(url.definition())). setValue("name","EvilTester.com"). setValue("url", "http://eviltester.com"); - url.createManagedInstance(). + url.addInstance(new EntityInstance(url.definition())). setValue("name","JavaForTesters.com"). setValue("url", "http://javaForTesters.com"); diff --git a/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/domain/instances/RelationshipInstanceTest.java b/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/domain/instances/RelationshipInstanceTest.java index 1be358fb..babf4ae1 100644 --- a/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/domain/instances/RelationshipInstanceTest.java +++ b/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/domain/instances/RelationshipInstanceTest.java @@ -19,8 +19,8 @@ void canCreateARelationshipInstance(){ ); RelationshipDefinition defn = RelationshipDefinition.create(vector); - final EntityInstance fromInstance = thingfrom.createManagedInstance(); - final EntityInstance toInstance = thingfrom.createManagedInstance(); + final EntityInstance fromInstance = thingfrom.addInstance(new EntityInstance(thingfrom.definition())); + final EntityInstance toInstance = thingfrom.addInstance(new EntityInstance(thingfrom.definition())); RelationshipVectorInstance rel = new RelationshipVectorInstance( vector, fromInstance, toInstance); @@ -32,7 +32,7 @@ void canCreateARelationshipInstance(){ Assertions.assertTrue(rel.involves(fromInstance)); Assertions.assertTrue(rel.involves(toInstance)); - Assertions.assertFalse(rel.involves(thingfrom.createManagedInstance())); + Assertions.assertFalse(rel.involves(thingfrom.addInstance(new EntityInstance(thingfrom.definition())))); Assertions.assertEquals(toInstance, rel.getOtherThingInstance(fromInstance)); Assertions.assertEquals(fromInstance, rel.getOtherThingInstance(toInstance)); diff --git a/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/domain/instances/RelationshipsTest.java b/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/domain/instances/RelationshipsTest.java index 2584ec01..6e8cbe69 100644 --- a/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/domain/instances/RelationshipsTest.java +++ b/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/domain/instances/RelationshipsTest.java @@ -31,8 +31,8 @@ void baseData(){ defn = RelationshipDefinition.create(vector); - fromInstance = thingfrom.createManagedInstance(); - toInstance = thingto.createManagedInstance(); + fromInstance = thingfrom.addInstance(new EntityInstance(thingfrom.definition())); + toInstance = thingto.addInstance(new EntityInstance(thingto.definition())); } @Test @@ -97,7 +97,7 @@ void cannotConnectToThingWhenRelationshipIsNotForTypePassedIn(){ final EntityInstanceRelationships relationships = new EntityInstanceRelationships(fromInstance); - final EntityInstance instance = thingfrom.createManagedInstance(); + final EntityInstance instance = thingfrom.addInstance(new EntityInstance(thingfrom.definition())); final IllegalArgumentException e = Assertions.assertThrows(IllegalArgumentException.class, () -> relationships.connect( diff --git a/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/query/QueryFiltersBooleanTest.java b/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/query/QueryFiltersBooleanTest.java index 32fde9d7..1ad50f08 100644 --- a/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/query/QueryFiltersBooleanTest.java +++ b/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/query/QueryFiltersBooleanTest.java @@ -3,7 +3,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import uk.co.compendiumdev.thingifier.core.EntityRelModel; import uk.co.compendiumdev.thingifier.core.domain.instances.EntityInstanceCollection; @@ -11,9 +10,7 @@ import uk.co.compendiumdev.thingifier.core.domain.definitions.field.definition.Field; import uk.co.compendiumdev.thingifier.core.domain.instances.EntityInstance; -import java.util.HashMap; import java.util.List; -import java.util.Map; public class QueryFiltersBooleanTest { @@ -35,10 +32,10 @@ public void setupCollectionTestData(){ EntityInstanceCollection thing = erModel.getInstanceData().getInstanceCollectionForEntityNamed("thing"); - thing.createManagedInstance().setValue("truefalse", "true"); - thing.createManagedInstance().setValue("truefalse", "true"); - thing.createManagedInstance().setValue("truefalse", "true"); - thing.createManagedInstance().setValue("truefalse", "false"); + thing.addInstance( new EntityInstance(thing.definition())).setValue("truefalse", "true"); + thing.addInstance( new EntityInstance(thing.definition())).setValue("truefalse", "true"); + thing.addInstance( new EntityInstance(thing.definition())).setValue("truefalse", "true"); + thing.addInstance(new EntityInstance(thing.definition())).setValue("truefalse", "false"); } diff --git a/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/query/QueryFiltersFloatTest.java b/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/query/QueryFiltersFloatTest.java index 3d6c4e1a..84296c97 100644 --- a/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/query/QueryFiltersFloatTest.java +++ b/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/query/QueryFiltersFloatTest.java @@ -3,7 +3,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import uk.co.compendiumdev.thingifier.core.EntityRelModel; import uk.co.compendiumdev.thingifier.core.domain.definitions.field.definition.Field; @@ -11,9 +10,7 @@ import uk.co.compendiumdev.thingifier.core.domain.instances.EntityInstance; import uk.co.compendiumdev.thingifier.core.domain.instances.EntityInstanceCollection; -import java.util.HashMap; import java.util.List; -import java.util.Map; public class QueryFiltersFloatTest { @@ -29,10 +26,10 @@ public void setupCollectionTestData(){ EntityInstanceCollection thing = erModel.getInstanceData().getInstanceCollectionForEntityNamed("thing"); - thing.createManagedInstance().setValue("float", "4.4"); - thing.createManagedInstance().setValue("float", "1.1"); - thing.createManagedInstance().setValue("float", "3.3"); - thing.createManagedInstance().setValue("float", "2.2"); + thing.addInstance(new EntityInstance(thing.definition())).setValue("float", "4.4"); + thing.addInstance(new EntityInstance(thing.definition())).setValue("float", "1.1"); + thing.addInstance(new EntityInstance(thing.definition())).setValue("float", "3.3"); + thing.addInstance(new EntityInstance(thing.definition())).setValue("float", "2.2"); } diff --git a/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/query/QueryFiltersIdTest.java b/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/query/QueryFiltersIdTest.java index 4f57ff15..ef6fcad3 100644 --- a/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/query/QueryFiltersIdTest.java +++ b/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/query/QueryFiltersIdTest.java @@ -27,10 +27,10 @@ public void setupCollectionTestData(){ EntityInstanceCollection thing = erModel.getInstanceData().getInstanceCollectionForEntityNamed("thing"); // fakeid is a proxy for the actual id which always starts at 1 and auto increments - thing.createManagedInstance().setValue("fakeid", "1"); - thing.createManagedInstance().setValue("fakeid", "2"); - thing.createManagedInstance().setValue("fakeid", "3"); - thing.createManagedInstance().setValue("fakeid", "4"); + thing.addInstance(new EntityInstance(thing.definition())).setValue("fakeid", "1"); + thing.addInstance(new EntityInstance(thing.definition())).setValue("fakeid", "2"); + thing.addInstance(new EntityInstance(thing.definition())).setValue("fakeid", "3"); + thing.addInstance(new EntityInstance(thing.definition())).setValue("fakeid", "4"); } diff --git a/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/query/QueryFiltersIntegerTest.java b/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/query/QueryFiltersIntegerTest.java index eea137b7..2495e0aa 100644 --- a/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/query/QueryFiltersIntegerTest.java +++ b/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/query/QueryFiltersIntegerTest.java @@ -3,7 +3,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import uk.co.compendiumdev.thingifier.core.EntityRelModel; import uk.co.compendiumdev.thingifier.core.domain.definitions.field.definition.Field; @@ -11,9 +10,7 @@ import uk.co.compendiumdev.thingifier.core.domain.instances.EntityInstance; import uk.co.compendiumdev.thingifier.core.domain.instances.EntityInstanceCollection; -import java.util.HashMap; import java.util.List; -import java.util.Map; public class QueryFiltersIntegerTest { @@ -33,10 +30,10 @@ public void setupCollectionTestData(){ EntityInstanceCollection thing = erModel.getInstanceData().getInstanceCollectionForEntityNamed("thing"); - thing.createManagedInstance().setValue("int", "3"); - thing.createManagedInstance().setValue("int", "1"); - thing.createManagedInstance().setValue("int", "4"); - thing.createManagedInstance().setValue("int", "2"); + thing.addInstance(new EntityInstance(thing.definition())).setValue("int", "3"); + thing.addInstance(new EntityInstance(thing.definition())).setValue("int", "1"); + thing.addInstance(new EntityInstance(thing.definition())).setValue("int", "4"); + thing.addInstance(new EntityInstance(thing.definition())).setValue("int", "2"); } diff --git a/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/query/QueryFiltersStringTest.java b/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/query/QueryFiltersStringTest.java index d272951b..0a064a37 100644 --- a/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/query/QueryFiltersStringTest.java +++ b/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/query/QueryFiltersStringTest.java @@ -25,10 +25,10 @@ public void setupCollectionTestData(){ EntityInstanceCollection thing = erModel.getInstanceData().getInstanceCollectionForEntityNamed("thing"); - thing.createManagedInstance().setValue("string", "one"); - thing.createManagedInstance().setValue("string", "two"); - thing.createManagedInstance().setValue("string", "three"); - thing.createManagedInstance().setValue("string", "four"); + thing.addInstance(new EntityInstance(thing.definition())).setValue("string", "one"); + thing.addInstance(new EntityInstance(thing.definition())).setValue("string", "two"); + thing.addInstance(new EntityInstance(thing.definition())).setValue("string", "three"); + thing.addInstance(new EntityInstance(thing.definition())).setValue("string", "four"); } diff --git a/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/query/SortingViaQueryFiltersTest.java b/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/query/SortingViaQueryFiltersTest.java index daa2234b..75b7c952 100644 --- a/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/query/SortingViaQueryFiltersTest.java +++ b/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/query/SortingViaQueryFiltersTest.java @@ -9,9 +9,7 @@ import uk.co.compendiumdev.thingifier.core.domain.instances.EntityInstance; import uk.co.compendiumdev.thingifier.core.domain.instances.EntityInstanceCollection; -import java.util.HashMap; import java.util.List; -import java.util.Map; public class SortingViaQueryFiltersTest { @@ -35,13 +33,13 @@ public void setupThingifier(){ @Test public void canSortIntViaAQuery(){ - final EntityInstance thing1 = thing.createManagedInstance(); + final EntityInstance thing1 = thing.addInstance(new EntityInstance(thing.definition())); thing1.setValue("int", "1"); - final EntityInstance thing2 = thing.createManagedInstance(); + final EntityInstance thing2 = thing.addInstance(new EntityInstance(thing.definition())); thing2.setValue("int", "2"); - final EntityInstance thing3 = thing.createManagedInstance(); + final EntityInstance thing3 = thing.addInstance(new EntityInstance(thing.definition())); thing3.setValue("int", "3"); QueryFilterParams params = new QueryFilterParams(); @@ -93,10 +91,10 @@ public void canSortViaAQuery(){ EntityInstanceCollection thing = aThingifier.getInstanceData().getInstanceCollectionForEntityNamed("thing"); - final EntityInstance trueThing = thing.createManagedInstance(); + final EntityInstance trueThing = thing.addInstance(new EntityInstance(thing.definition())); trueThing.setValue("truefalse", "true"); - final EntityInstance falseThing = thing.createManagedInstance(); + final EntityInstance falseThing = thing.addInstance(new EntityInstance(thing.definition())); falseThing.setValue("truefalse", "false"); QueryFilterParams params = new QueryFilterParams(); diff --git a/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/query/TodoManagerQueryEngineTest.java b/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/query/TodoManagerQueryEngineTest.java index 76229819..38d36a08 100644 --- a/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/query/TodoManagerQueryEngineTest.java +++ b/ercoremodel/src/test/java/uk/co/compendiumdev/thingifier/core/query/TodoManagerQueryEngineTest.java @@ -56,15 +56,15 @@ public void createDefinitions(){ final EntityInstanceCollection categories = todoManager.getInstanceData().getInstanceCollectionForEntityNamed("category"); projects = todoManager.getInstanceData().getInstanceCollectionForEntityNamed("project"); - paperwork = todos.createManagedInstance().setValue("title", "scan paperwork"); + paperwork = todos.addInstance(new EntityInstance(todos.definition())).setValue("title", "scan paperwork"); //System.out.println(new Gson().toJson(JsonThing.asJsonObject(paperwork))); - filework = todos.createManagedInstance().setValue("title", "file paperwork"); + filework = todos.addInstance(new EntityInstance(todos.definition())).setValue("title", "file paperwork"); - officeCategory = categories.createManagedInstance().setValue("title", "Office"); + officeCategory = categories.addInstance(new EntityInstance(categories.definition())).setValue("title", "Office"); - EntityInstance homeCategory = categories.createManagedInstance().setValue("title", "Home"); + EntityInstance homeCategory = categories.addInstance(new EntityInstance(categories.definition())).setValue("title", "Home"); paperwork.getRelationships().connect("categories", officeCategory); @@ -193,7 +193,7 @@ public void connectionTesting() { List queryResults; // - EntityInstance officeWork = projects.createManagedInstance().setValue("title", "Office Work"); + EntityInstance officeWork = projects.addInstance(new EntityInstance(projects.definition())).setValue("title", "Office Work"); officeWork.getRelationships().connect("tasks", paperwork); officeWork.getRelationships().connect("tasks", filework); diff --git a/examplemodels/src/main/java/uk/co/compendiumdev/thingifier/application/data/TodoAPIDataPopulator.java b/examplemodels/src/main/java/uk/co/compendiumdev/thingifier/application/data/TodoAPIDataPopulator.java index f6b52235..a28df1ed 100644 --- a/examplemodels/src/main/java/uk/co/compendiumdev/thingifier/application/data/TodoAPIDataPopulator.java +++ b/examplemodels/src/main/java/uk/co/compendiumdev/thingifier/application/data/TodoAPIDataPopulator.java @@ -1,8 +1,8 @@ package uk.co.compendiumdev.thingifier.application.data; -import uk.co.compendiumdev.thingifier.core.EntityRelModel; import uk.co.compendiumdev.thingifier.core.domain.definitions.ERSchema; import uk.co.compendiumdev.thingifier.core.domain.instances.ERInstanceData; +import uk.co.compendiumdev.thingifier.core.domain.instances.EntityInstance; import uk.co.compendiumdev.thingifier.core.domain.instances.EntityInstanceCollection; import uk.co.compendiumdev.thingifier.core.domain.datapopulator.DataPopulator; @@ -24,7 +24,7 @@ public void populate(final ERSchema schema, final ERInstanceData database) { EntityInstanceCollection todo = database.getInstanceCollectionForEntityNamed("todo"); for(String todoItem : todos){ - todo.createManagedInstance(). + todo.addInstance(new EntityInstance(todo.definition())). setValue("title", todoItem); } } diff --git a/examplemodels/src/main/java/uk/co/compendiumdev/thingifier/application/data/TodoManagerAPIDataPopulator.java b/examplemodels/src/main/java/uk/co/compendiumdev/thingifier/application/data/TodoManagerAPIDataPopulator.java index bb3851e6..a34aef69 100644 --- a/examplemodels/src/main/java/uk/co/compendiumdev/thingifier/application/data/TodoManagerAPIDataPopulator.java +++ b/examplemodels/src/main/java/uk/co/compendiumdev/thingifier/application/data/TodoManagerAPIDataPopulator.java @@ -1,6 +1,5 @@ package uk.co.compendiumdev.thingifier.application.data; -import uk.co.compendiumdev.thingifier.core.EntityRelModel; import uk.co.compendiumdev.thingifier.core.domain.definitions.ERSchema; import uk.co.compendiumdev.thingifier.core.domain.instances.ERInstanceData; import uk.co.compendiumdev.thingifier.core.domain.instances.EntityInstanceCollection; @@ -12,24 +11,24 @@ public class TodoManagerAPIDataPopulator implements DataPopulator { public void populate(final ERSchema schema, final ERInstanceData database) { EntityInstanceCollection todo = database.getInstanceCollectionForEntityNamed("todo"); - EntityInstance paperwork = todo.createManagedInstance(). + EntityInstance paperwork = todo.addInstance(new EntityInstance(todo.definition())). setValue("title", "scan paperwork"); - EntityInstance filework = todo.createManagedInstance(). + EntityInstance filework = todo.addInstance(new EntityInstance(todo.definition())). setValue("title", "file paperwork"); EntityInstanceCollection category = database.getInstanceCollectionForEntityNamed("category"); - EntityInstance officeCategory = category.createManagedInstance(). + EntityInstance officeCategory = category.addInstance(new EntityInstance(category.definition())). setValue("title", "Office"); - EntityInstance homeCategory = category.createManagedInstance(). + EntityInstance homeCategory = category.addInstance(new EntityInstance(category.definition())). setValue("title", "Home"); EntityInstanceCollection project = database.getInstanceCollectionForEntityNamed("project"); - EntityInstance officeWork = project.createManagedInstance(). + EntityInstance officeWork = project.addInstance(new EntityInstance(project.definition())). setValue("title", "Office Work"); officeWork.getRelationships().connect("tasks", paperwork); diff --git a/swaggerizer/src/test/java/uk/co/compendiumdev/thingifier/swaggerizer/TodoAPITestDataPopulator.java b/swaggerizer/src/test/java/uk/co/compendiumdev/thingifier/swaggerizer/TodoAPITestDataPopulator.java index 97e23cb5..b51e2989 100644 --- a/swaggerizer/src/test/java/uk/co/compendiumdev/thingifier/swaggerizer/TodoAPITestDataPopulator.java +++ b/swaggerizer/src/test/java/uk/co/compendiumdev/thingifier/swaggerizer/TodoAPITestDataPopulator.java @@ -1,8 +1,8 @@ package uk.co.compendiumdev.thingifier.swaggerizer; -import uk.co.compendiumdev.thingifier.core.EntityRelModel; import uk.co.compendiumdev.thingifier.core.domain.definitions.ERSchema; import uk.co.compendiumdev.thingifier.core.domain.instances.ERInstanceData; +import uk.co.compendiumdev.thingifier.core.domain.instances.EntityInstance; import uk.co.compendiumdev.thingifier.core.domain.instances.EntityInstanceCollection; import uk.co.compendiumdev.thingifier.core.domain.datapopulator.DataPopulator; @@ -24,7 +24,7 @@ public void populate(final ERSchema schema, final ERInstanceData database) { EntityInstanceCollection todo = database.getInstanceCollectionForEntityNamed("todo"); for(String todoItem : todos){ - todo.createManagedInstance(). + todo.addInstance(new EntityInstance(todo.definition())). setValue("title", todoItem); } } diff --git a/thingifier/src/test/java/uk/co/compendiumdev/UsageTest.java b/thingifier/src/test/java/uk/co/compendiumdev/UsageTest.java index 03a3e84f..bcf76510 100644 --- a/thingifier/src/test/java/uk/co/compendiumdev/UsageTest.java +++ b/thingifier/src/test/java/uk/co/compendiumdev/UsageTest.java @@ -49,7 +49,7 @@ public void thingifierCanManageThings(){ Assertions.assertTrue(urls.definition().hasFieldNameDefined("url")); Assertions.assertTrue(urls.definition().hasFieldNameDefined("name")); - urls.createManagedInstance(). + urls.addInstance(new EntityInstance(urls.definition())). setValue("name","EvilTester.com"). setValue("url","http://eviltester.com"); @@ -57,7 +57,8 @@ public void thingifierCanManageThings(){ user.addFields(Field.is("name", STRING)); - EntityInstance alan = things.getThingInstancesNamed("USER", EntityRelModel.DEFAULT_DATABASE_NAME).createManagedInstance(). + EntityInstanceCollection entityInstanceCollection = things.getThingInstancesNamed("USER", EntityRelModel.DEFAULT_DATABASE_NAME); + EntityInstance alan = entityInstanceCollection.addInstance(new EntityInstance(entityInstanceCollection.definition())). setValue("name","alan"); diff --git a/thingifier/src/test/java/uk/co/compendiumdev/api_non_http/SimpleVerbPutEntityInstanceApiNonHttpTest.java b/thingifier/src/test/java/uk/co/compendiumdev/api_non_http/SimpleVerbPutEntityInstanceApiNonHttpTest.java index 5617e08f..13c3ccf2 100644 --- a/thingifier/src/test/java/uk/co/compendiumdev/api_non_http/SimpleVerbPutEntityInstanceApiNonHttpTest.java +++ b/thingifier/src/test/java/uk/co/compendiumdev/api_non_http/SimpleVerbPutEntityInstanceApiNonHttpTest.java @@ -2,7 +2,6 @@ import com.google.gson.Gson; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import uk.co.compendiumdev.thingifier.Thingifier; import uk.co.compendiumdev.thingifier.api.http.HttpApiRequest; @@ -68,7 +67,7 @@ public void putCanAmendExistingInstance() { requestBody = new HashMap(); requestBody.put("title", "My Office Work"); - EntityInstance officeWork = instances.createManagedInstance(). + EntityInstance officeWork = instances.addInstance(new EntityInstance(instances.definition())). setValue("title", "An Existing instances"); String officeWorkGuid = officeWork.getPrimaryKeyValue(); @@ -99,7 +98,7 @@ public void putCanAmendExistingInstancesWhenOptionalFieldsAreMissing() { EntityInstanceCollection instances = thingifier.getThingInstancesNamed("entity", EntityRelModel.DEFAULT_DATABASE_NAME); // create something to amend with PUT - EntityInstance officeWork = instances.createManagedInstance(). + EntityInstance officeWork = instances.addInstance(new EntityInstance(instances.definition())). setValue("title", "An Existing instances"). setValue("description", "Existing Description"); @@ -128,7 +127,7 @@ public void putFailCanNotAmendExistingInstancesWhenMandatoryFieldsAreMissing() { EntityInstanceCollection instances = thingifier.getThingInstancesNamed("entity", EntityRelModel.DEFAULT_DATABASE_NAME); // create something to amend with PUT - EntityInstance officeWork = instances.createManagedInstance(). + EntityInstance officeWork = instances.addInstance(new EntityInstance(instances.definition())). setValue("description", "An Existing instance title"); String officeWorkGuid = officeWork.getPrimaryKeyValue(); @@ -159,7 +158,7 @@ public void putFailCanNotAmendPrimaryKey() { // PUT - EntityInstance officeWork = instances.createManagedInstance(). + EntityInstance officeWork = instances.addInstance(new EntityInstance(instances.definition())). setValue("title", "An Existing instances"). setValue("description", "my original description"); @@ -244,7 +243,7 @@ public void putFailCanNotAmendAutoGuid() { // PUT - EntityInstance officeWork = myInstances.createManagedInstance(). + EntityInstance officeWork = myInstances.addInstance(new EntityInstance(myInstances.definition())). setValue("title", "An Existing instance"); String originalID = officeWork.getPrimaryKeyValue(); diff --git a/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/ModelsTest.java b/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/ModelsTest.java index 88093776..89985dd0 100644 --- a/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/ModelsTest.java +++ b/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/ModelsTest.java @@ -39,7 +39,7 @@ public void createAndDelete(){ final EntityInstanceCollection todos = todoManager.getThingInstancesNamed("todo", EntityRelModel.DEFAULT_DATABASE_NAME); for(int todoCount=0; todoCount < 100; todoCount++){ - todos.createManagedInstance(). + todos.addInstance(new EntityInstance(todos.definition())). setValue("title", "title " + System.nanoTime()); } @@ -56,14 +56,14 @@ public void createAndDeleteRelationships(){ final EntityInstanceCollection todos = todoManager.getThingInstancesNamed("todo", EntityRelModel.DEFAULT_DATABASE_NAME); for(int todoCount=0; todoCount < 100; todoCount++){ - todos.createManagedInstance(). + todos.addInstance(new EntityInstance(todos.definition())). setValue("title", "title " + System.nanoTime()); } final EntityInstanceCollection projects = todoManager.getThingInstancesNamed("project", EntityRelModel.DEFAULT_DATABASE_NAME); for(int todoCount=0; todoCount < 50; todoCount++){ - projects.createManagedInstance(). + projects.addInstance(new EntityInstance(projects.definition())). setValue("title", "title " + System.nanoTime()); } diff --git a/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/api_non_http/RelationshipApiNonHttpTest.java b/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/api_non_http/RelationshipApiNonHttpTest.java index 6b35be3a..636f1669 100644 --- a/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/api_non_http/RelationshipApiNonHttpTest.java +++ b/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/api_non_http/RelationshipApiNonHttpTest.java @@ -77,10 +77,10 @@ public void getCanReturnInstancesOfARelationship(){ ApiResponse apiresponse; - EntityInstance paperwork = todo.createManagedInstance(). + EntityInstance paperwork = todo.addInstance(new EntityInstance(todo.definition())). setValue("title", "Todo for relating"); - EntityInstance myNewProject = project.createManagedInstance(). + EntityInstance myNewProject = project.addInstance(new EntityInstance(project.definition())). setValue("title", "My New Project " + System.currentTimeMillis()); myNewProject.getRelationships().connect("tasks", paperwork); @@ -114,11 +114,11 @@ public void deleteCanDeleteARelationship(){ ApiResponse apiresponse; - EntityInstance paperwork = todo.createManagedInstance(). + EntityInstance paperwork = todo.addInstance(new EntityInstance(todo.definition())). setValue("title", "Todo for amending"); - EntityInstance myNewProject = project.createManagedInstance(). + EntityInstance myNewProject = project.addInstance(new EntityInstance(project.definition())). setValue("title", "My New Project " + System.currentTimeMillis()); myNewProject.getRelationships().connect("tasks", paperwork); @@ -153,10 +153,10 @@ public void deleteCanDeleteAThingInARelationship(){ ApiResponse apiresponse; - EntityInstance paperwork = todo.createManagedInstance(). + EntityInstance paperwork = todo.addInstance(new EntityInstance(todo.definition())). setValue("title", "Todo for amending"); - EntityInstance myNewProject = project.createManagedInstance(). + EntityInstance myNewProject = project.addInstance(new EntityInstance(project.definition())). setValue("title", "My New Project " + System.currentTimeMillis()); @@ -195,10 +195,10 @@ public void postCanCreateARelationship(){ ApiResponse apiresponse; - EntityInstance paperwork = todo.createManagedInstance(). + EntityInstance paperwork = todo.addInstance(new EntityInstance(todo.definition())). setValue("title", "Todo for amending"); - EntityInstance myNewProject = project.createManagedInstance(). + EntityInstance myNewProject = project.addInstance(new EntityInstance(project.definition())). setValue("title", "My New Project " + System.currentTimeMillis()); @@ -244,10 +244,10 @@ public void postCanCreateARelationship(){ public void postCanCreateARelationshipUsingAPI() { - EntityInstance myNewProject = project.createManagedInstance(). + EntityInstance myNewProject = project.addInstance(new EntityInstance(project.definition())). setValue("title", "Project For Relationships"); - EntityInstance relTodo = todo.createManagedInstance(). + EntityInstance relTodo = todo.addInstance(new EntityInstance(todo.definition())). setValue("title", "Todo for relationship testing"); @@ -281,11 +281,11 @@ public void postCanCreateARelationshipUsingAPI() { public void postCanCreateARelationshipUsingReversalRelationshipAPI() { - EntityInstance myNewProject = project.createManagedInstance(). + EntityInstance myNewProject = project.addInstance(new EntityInstance(project.definition())). setValue("title", "Project For Relationships " + System.currentTimeMillis()); - EntityInstance relTodo = todo.createManagedInstance(). + EntityInstance relTodo = todo.addInstance(new EntityInstance(todo.definition())). setValue("title", "Todo for relationship testing " + System.currentTimeMillis()); // Create a relationship with POST @@ -352,10 +352,10 @@ public void postCanCreateARelationshipUsingReversalRelationshipAPI() { public void deleteARelationshipUsingReversalRelationshipAPI() { - EntityInstance myNewProject = project.createManagedInstance(). + EntityInstance myNewProject = project.addInstance(new EntityInstance(project.definition())). setValue("title", "Project For Relationships " + System.currentTimeMillis()); - EntityInstance relTodo = todo.createManagedInstance(). + EntityInstance relTodo = todo.addInstance(new EntityInstance(todo.definition())). setValue("title", "Todo for relationship testing " + System.currentTimeMillis()); // Create a relationship with POST @@ -410,10 +410,10 @@ public void deleteARelationshipUsingReversalRelationshipAPI() { public void deleteAThingInAReversalRelationship() { - EntityInstance myNewProject = project.createManagedInstance(). + EntityInstance myNewProject = project.addInstance(new EntityInstance(project.definition())). setValue("title", "Project For Relationships " + System.currentTimeMillis()); - EntityInstance relTodo = todo.createManagedInstance(). + EntityInstance relTodo = todo.addInstance(new EntityInstance(todo.definition())). setValue("title", "Todo for relationship testing " + System.currentTimeMillis()); // Create a relationship with POST @@ -470,7 +470,7 @@ public void deleteAThingInAReversalRelationship() { public void postCanCreateARelationshipAndTodoAtSameTimeUsingAPI() { - EntityInstance myNewProject = project.createManagedInstance(). + EntityInstance myNewProject = project.addInstance(new EntityInstance(project.definition())). setValue("title", "Project For Relationships"); @@ -527,7 +527,7 @@ public void postCanCreateAReverseRelationshipAndProjectAtSameTimeUsingAPI() { // Create a thing and relate through a reverse relationship e.g. POST todo/GUID/task-of - EntityInstance relTodo = todo.createManagedInstance(). + EntityInstance relTodo = todo.addInstance(new EntityInstance(todo.definition())). setValue("title", "Todo for relationship testing " + System.currentTimeMillis()); @@ -585,8 +585,7 @@ public void postCanCreateAReverseRelationshipAndProjectAtSameTimeUsingAPI() { public void postCanCreateAMandatoryRelationshipFromEstimateAndTodoAtSameTimeUsingAPI() { - - EntityInstance myTodo = todo.createManagedInstance(). + EntityInstance myTodo = todo.addInstance(new EntityInstance(todo.definition())). setValue("title", "an estimated todo"); final EntityInstanceCollection estimates = todoManager.getThingInstancesNamed("estimate", EntityRelModel.DEFAULT_DATABASE_NAME); @@ -645,7 +644,7 @@ public void postCanCreateAMandatoryRelationshipFromEstimateAndTodoAtSameTimeUsin @Test public void postCanNotCreateEstimateWithoutAMandatoryRelationshipUsingAPI() { - EntityInstance myTodo = todo.createManagedInstance(). + EntityInstance myTodo = todo.addInstance(new EntityInstance(todo.definition())). setValue("title", "an estimated todo"); final EntityInstanceCollection estimates = todoManager.getThingInstancesNamed("estimate", EntityRelModel.DEFAULT_DATABASE_NAME); @@ -671,7 +670,7 @@ public void postCanNotCreateEstimateWithoutAMandatoryRelationshipUsingAPI() { @Test public void postCanCreateEstimateAMandatoryRelationshipUsingAPI() { - EntityInstance myTodo = todo.createManagedInstance(). + EntityInstance myTodo = todo.addInstance(new EntityInstance(todo.definition())). setValue("title", "an estimated todo"); diff --git a/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/api_non_http/VerbDeleteEntityInstanceApiNonHttpTest.java b/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/api_non_http/VerbDeleteEntityInstanceApiNonHttpTest.java index cfb9b3ef..c5de4e59 100644 --- a/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/api_non_http/VerbDeleteEntityInstanceApiNonHttpTest.java +++ b/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/api_non_http/VerbDeleteEntityInstanceApiNonHttpTest.java @@ -52,7 +52,7 @@ public void createDefinitions() { public void deleteAnEntityInstanceAPI() { ApiResponse apiresponse; - EntityInstance officeWork = project.createManagedInstance(). + EntityInstance officeWork = project.addInstance(new EntityInstance(project.definition())). setValue("title", "An Existing Project"); Assertions.assertEquals(1, project.countInstances()); diff --git a/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/api_non_http/VerbGetEntityInstanceApiNonHttpTest.java b/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/api_non_http/VerbGetEntityInstanceApiNonHttpTest.java index 6f7ea50b..38a93c8b 100644 --- a/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/api_non_http/VerbGetEntityInstanceApiNonHttpTest.java +++ b/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/api_non_http/VerbGetEntityInstanceApiNonHttpTest.java @@ -55,14 +55,14 @@ public void getCanReturnASingleEntityInstance() { todoManager.apiConfig().setReturnSingleGetItemsAsCollection(false); // add some data - todo.createManagedInstance().setValue("title", "My Title" + System.nanoTime()); - todo.createManagedInstance().setValue("title", "My Title" + System.nanoTime()); + todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "My Title" + System.nanoTime()); + todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "My Title" + System.nanoTime()); - EntityInstance findThis = todo.createManagedInstance(). + EntityInstance findThis = todo.addInstance(new EntityInstance(todo.definition())). setValue("title", "My Title" + System.nanoTime()); - todo.createManagedInstance().setValue("title", "My Title" + System.nanoTime()); + todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "My Title" + System.nanoTime()); ApiResponse apiResponse = todoManager.api().get("/todo/" + findThis.getPrimaryKeyValue(), new QueryFilterParams(), new HttpHeadersBlock()); @@ -86,14 +86,14 @@ public void getCanReturnASingleEntityInstanceAsACollection() { todoManager.apiConfig().setReturnSingleGetItemsAsCollection(true); // add some data - todo.createManagedInstance().setValue("title", "My Title" + System.nanoTime()); - todo.createManagedInstance().setValue("title", "My Title" + System.nanoTime()); + todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "My Title" + System.nanoTime()); + todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "My Title" + System.nanoTime()); - EntityInstance findThis = todo.createManagedInstance(). + EntityInstance findThis = todo.addInstance(new EntityInstance(todo.definition())). setValue("title", "My Title" + System.nanoTime()); - todo.createManagedInstance().setValue("title", "My Title" + System.nanoTime()); + todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "My Title" + System.nanoTime()); ApiResponse apiResponse = todoManager.api().get("/todo/" + findThis.getPrimaryKeyValue(), new QueryFilterParams(), new HttpHeadersBlock()); @@ -117,10 +117,10 @@ public void getCanReturnMultipleEntityInstances() { todoManager.apiConfig().setReturnSingleGetItemsAsCollection(false); // add some data - todo.createManagedInstance().setValue("title", "My Title" + System.nanoTime()); - todo.createManagedInstance().setValue("title", "My Title" + System.nanoTime()); - todo.createManagedInstance().setValue("title", "My Title" + System.nanoTime()); - todo.createManagedInstance().setValue("title", "My Title" + System.nanoTime()); + todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "My Title" + System.nanoTime()); + todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "My Title" + System.nanoTime()); + todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "My Title" + System.nanoTime()); + todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "My Title" + System.nanoTime()); ApiResponse apiResponse = todoManager.api().get("/todo", new QueryFilterParams(), new HttpHeadersBlock()); @@ -152,10 +152,10 @@ public void getCanReturnMultipleEntityInstancesFromEndpoint() { todoManager.apiConfig().setReturnSingleGetItemsAsCollection(true); // add some data - todo.createManagedInstance().setValue("title", "My Title" + System.nanoTime()); - todo.createManagedInstance().setValue("title", "My Title" + System.nanoTime()); - todo.createManagedInstance().setValue("title", "My Title" + System.nanoTime()); - todo.createManagedInstance().setValue("title", "My Title" + System.nanoTime()); + todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "My Title" + System.nanoTime()); + todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "My Title" + System.nanoTime()); + todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "My Title" + System.nanoTime()); + todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "My Title" + System.nanoTime()); ApiResponse apiResponse = todoManager.api().get("/todo", new QueryFilterParams(), new HttpHeadersBlock()); diff --git a/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/api_non_http/VerbPostEntityInstanceApiNonHttpTest.java b/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/api_non_http/VerbPostEntityInstanceApiNonHttpTest.java index 43fc97f3..98be8377 100644 --- a/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/api_non_http/VerbPostEntityInstanceApiNonHttpTest.java +++ b/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/api_non_http/VerbPostEntityInstanceApiNonHttpTest.java @@ -144,7 +144,7 @@ public void postCanCreateAnEntityWhichPassesValidationWithMinimumFields() { @Test public void postCanAmendAnExistingEntity() { - EntityInstance relTodo = todo.createManagedInstance(). + EntityInstance relTodo = todo.addInstance(new EntityInstance(todo.definition())). setValue("title", "Todo for amending"); @@ -205,7 +205,7 @@ public void postFailCannotAmendEntityInstanceWhenValidationErrorsAPI() { String originalTitle = "Todo for amending " + System.currentTimeMillis(); String originalDescription = "my description " + System.currentTimeMillis(); - EntityInstance amendTodo = todo.createManagedInstance(). + EntityInstance amendTodo = todo.addInstance(new EntityInstance(todo.definition())). setValue("title", originalTitle).setValue("description", originalDescription); @@ -253,7 +253,7 @@ public void putCanAmendExistingProject() { requestBody = new HashMap<>(); requestBody.put("title", "My Office Work"); - EntityInstance officeWork = project.createManagedInstance(). + EntityInstance officeWork = project.addInstance(new EntityInstance(project.definition())). setValue("title", "An Existing Project"); String officeWorkGuid = officeWork.getPrimaryKeyValue(); @@ -305,7 +305,7 @@ public void postFailCannotCreateEntityInstanceWhenValidationErrorsAPI() { requestBody.put("title", "A new TODO Item"); requestBody.put("doneStatus", "FALSEY"); - EntityInstance paperwork = todo.createManagedInstance(). + EntityInstance paperwork = todo.addInstance(new EntityInstance(todo.definition())). setValue("title", "Todo for amending"); apiresponse = todoManager.api().post(String.format("todo/%s", paperwork.getPrimaryKeyValue()), getSimpleParser(requestBody), new HttpHeadersBlock()); diff --git a/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/api_non_http/VerbPutEntityInstanceApiNonHttpTest.java b/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/api_non_http/VerbPutEntityInstanceApiNonHttpTest.java index eda7c50a..b9a2bfcf 100644 --- a/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/api_non_http/VerbPutEntityInstanceApiNonHttpTest.java +++ b/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/api_non_http/VerbPutEntityInstanceApiNonHttpTest.java @@ -69,7 +69,7 @@ public void putCanAmendExistingProject() { requestBody = new HashMap(); requestBody.put("title", "My Office Work"); - EntityInstance officeWork = project.createManagedInstance(). + EntityInstance officeWork = project.addInstance(new EntityInstance(project.definition())). setValue("title", "An Existing Project"); String officeWorkGuid = officeWork.getPrimaryKeyValue(); @@ -100,7 +100,7 @@ public void putCanAmendExistingProjectByUsingDefaultFieldValues() { // PUT - EntityInstance officeWork = project.createManagedInstance(). + EntityInstance officeWork = project.addInstance(new EntityInstance(project.definition())). setValue("title", "An Existing Project"). setValue("description", "my original description"); @@ -135,7 +135,7 @@ public void putCanNotAmendGUID() { // PUT - EntityInstance officeWork = project.createManagedInstance(). + EntityInstance officeWork = project.addInstance(new EntityInstance(project.definition())). setValue("title", "An Existing Project"). setValue("description", "my original description"); @@ -250,7 +250,7 @@ public void putCanNotCreateAnEntityInstanceWithADuplicateId() { final Field anIdField = Field.is("id", FieldType.AUTO_INCREMENT); project.definition().addField(anIdField); - final EntityInstance instance = project.createManagedInstance(); + final EntityInstance instance = project.addInstance(new EntityInstance(project.definition())); // Want to PUT requestBody = new HashMap(); @@ -288,7 +288,7 @@ public void putFailValidationEntityInstanceAPI() { Assertions.assertTrue(apiresponse.hasABody()); - EntityInstance paperwork = todo.createManagedInstance().setValue("title", "Todo for amending"); + EntityInstance paperwork = todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "Todo for amending"); // Mandatory field validation PUT amend requestBody = new HashMap(); @@ -338,7 +338,7 @@ public void putFailCannotAmendEntityInstanceWhenValidationErrors() { ApiResponse apiresponse; - EntityInstance paperwork = todo.createManagedInstance().setValue("title", "Todo for amending"); + EntityInstance paperwork = todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "Todo for amending"); // Mandatory field validation PUT amend requestBody = new HashMap(); diff --git a/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/http_api/DeleteRequestTest.java b/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/http_api/DeleteRequestTest.java index 6ea05b98..f41f66db 100644 --- a/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/http_api/DeleteRequestTest.java +++ b/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/http_api/DeleteRequestTest.java @@ -38,7 +38,7 @@ public void createDefinitions() { public void canDeleteItem(){ - final EntityInstance instance = todo.createManagedInstance().setValue("title", "my title"); + final EntityInstance instance = todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "my title"); Assertions.assertEquals(1, todo.countInstances()); @@ -56,7 +56,7 @@ public void canDeleteItem(){ public void cannotDeleteItemThatDoesNotExist(){ - final EntityInstance instance = todo.createManagedInstance().setValue("title", "my title"); + final EntityInstance instance = todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "my title"); Assertions.assertEquals(1, todo.countInstances()); @@ -74,7 +74,7 @@ public void cannotDeleteItemThatDoesNotExist(){ public void cannotDeleteRootItem(){ - final EntityInstance instance = todo.createManagedInstance().setValue("title", "my title"); + final EntityInstance instance = todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "my title"); Assertions.assertEquals(1, todo.countInstances()); diff --git a/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/http_api/JsonRequestResponseTest.java b/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/http_api/JsonRequestResponseTest.java index 23becfec..6fa9b09e 100644 --- a/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/http_api/JsonRequestResponseTest.java +++ b/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/http_api/JsonRequestResponseTest.java @@ -56,7 +56,7 @@ public void canGetAnEmptyJsonItemsCollection() { public void canGetJsonItems() { - todo.createManagedInstance().setValue("title", "my title"); + todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "my title"); HttpApiRequest request = new HttpApiRequest("/todos"); request.getHeaders().putAll(HeadersSupport.acceptJson()); @@ -77,7 +77,7 @@ public void canGetJsonItems() { public void canGetJsonItemAsACollection() { todoManager.apiConfig().setReturnSingleGetItemsAsCollection(true); - final EntityInstance aTodo = todo.createManagedInstance().setValue("title", "my title"); + final EntityInstance aTodo = todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "my title"); HttpApiRequest request = new HttpApiRequest("/todos/" + aTodo.getPrimaryKeyValue()); request.getHeaders().putAll(HeadersSupport.acceptJson()); @@ -98,8 +98,8 @@ public void canGetJsonItemAsACollection() { public void canGetMultipleJsonItems() { - todo.createManagedInstance().setValue("title", "my title"); - todo.createManagedInstance().setValue("title", "my other title"); + todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "my title"); + todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "my other title"); HttpApiRequest request = new HttpApiRequest("todos"); request.getHeaders().putAll(HeadersSupport.acceptJson()); @@ -120,8 +120,8 @@ public void canGetMultipleJsonItems() { public void cannotGetFromMissingEndpoint() { - todo.createManagedInstance().setValue("title", "my title"); - todo.createManagedInstance().setValue("title", "my other title"); + todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "my title"); + todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "my other title"); HttpApiRequest request = new HttpApiRequest("todos" + System.nanoTime()); request.getHeaders().putAll(HeadersSupport.acceptJson()); @@ -235,7 +235,7 @@ public void canPostAndCreateAnItemWithJsonAndReceiveXml() { @Test public void canPostToAmendAnItemWithJson() { - final EntityInstance atodo = todo.createManagedInstance().setValue("title", "my title"); + final EntityInstance atodo = todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "my title"); Assertions.assertEquals(1, todo.countInstances()); @@ -271,7 +271,7 @@ public void canPostToAmendAnItemWithJson() { @Test public void canPutToAmendAnItemWithJson() { - final EntityInstance atodo = todo.createManagedInstance().setValue("title", "my title"); + final EntityInstance atodo = todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "my title"); Assertions.assertEquals(1, todo.countInstances()); diff --git a/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/http_api/RelationshipHttpTest.java b/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/http_api/RelationshipHttpTest.java index 0ea601f7..c18b0a92 100644 --- a/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/http_api/RelationshipHttpTest.java +++ b/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/http_api/RelationshipHttpTest.java @@ -39,9 +39,9 @@ public void createDefinitions() { @Test public void canCreateARelationshipBetweenProjectAndTodoViaTasks(){ - final EntityInstance atodo = todo.createManagedInstance().setValue("title", "a TODO"); + final EntityInstance atodo = todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "a TODO"); - final EntityInstance aproject = project.createManagedInstance().setValue("title", "a Project"); + final EntityInstance aproject = project.addInstance(new EntityInstance(project.definition())).setValue("title", "a Project"); Assertions.assertEquals(0, aproject.getRelationships().getConnectedItems("tasks").size()); @@ -63,9 +63,9 @@ public void canCreateARelationshipBetweenProjectAndTodoViaTasks(){ @Test public void canCreateARelationshipBetweenProjectAndTodoViaTasksUsingID(){ - final EntityInstance atodo = todo.createManagedInstance().setValue("title", "a TODO"); + final EntityInstance atodo = todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "a TODO"); - final EntityInstance aproject = project.createManagedInstance().setValue("title", "a Project"); + final EntityInstance aproject = project.addInstance(new EntityInstance(project.definition())).setValue("title", "a Project"); Assertions.assertEquals(0, aproject.getRelationships().getConnectedItems("tasks").size()); @@ -90,7 +90,7 @@ public void canCreateARelationshipBetweenProjectAndTodoViaTasksUsingID(){ @Test public void canCreateARelationshipAndTodoBetweenProjectAndTodoViaTasks(){ - final EntityInstance aproject = project.createManagedInstance().setValue("title", "a Project"); + final EntityInstance aproject = project.addInstance(new EntityInstance(project.definition())).setValue("title", "a Project"); Assertions.assertEquals(0, aproject.getRelationships().getConnectedItems("tasks").size()); Assertions.assertEquals(0,todo.countInstances()); @@ -120,9 +120,9 @@ public void canCreateARelationshipAndTodoBetweenProjectAndTodoViaTasks(){ public void cannotCreateARelationshipBetweenProjectAndCategoryViaTasks(){ - final EntityInstance acategory = categories.createManagedInstance().setValue("title", "a Category"); + final EntityInstance acategory = categories.addInstance(new EntityInstance(categories.definition())).setValue("title", "a Category"); - final EntityInstance aproject = project.createManagedInstance().setValue("title", "a Project"); + final EntityInstance aproject = project.addInstance(new EntityInstance(project.definition())).setValue("title", "a Project"); Assertions.assertEquals(0, aproject.getRelationships().getConnectedItems("tasks").size()); @@ -150,9 +150,9 @@ public void cannotCreateARelationshipBetweenProjectAndCategoryViaTasks(){ public void cannotCreateARelationshipWhenGivenGuidDoesNotExist(){ - final EntityInstance atodo = todo.createManagedInstance().setValue("title", "a TODO"); + final EntityInstance atodo = todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "a TODO"); - final EntityInstance aproject = project.createManagedInstance().setValue("title", "a Project"); + final EntityInstance aproject = project.addInstance(new EntityInstance(project.definition())).setValue("title", "a Project"); Assertions.assertEquals(0, aproject.getRelationships().getConnectedItems("tasks").size()); @@ -179,9 +179,9 @@ public void cannotCreateARelationshipWhenGivenGuidDoesNotExist(){ public void canCreateARelationshipBetweenCategoryAndTodoViaTodos(){ - final EntityInstance acategory = categories.createManagedInstance().setValue("title", "a Category"); + final EntityInstance acategory = categories.addInstance(new EntityInstance(categories.definition())).setValue("title", "a Category"); - final EntityInstance atodo = todo.createManagedInstance().setValue("title", "a TODO"); + final EntityInstance atodo = todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "a TODO"); Assertions.assertEquals(0, acategory.getRelationships().getConnectedItems("todos").size()); @@ -203,7 +203,7 @@ public void canCreateARelationshipBetweenCategoryAndTodoViaTodos(){ @Test public void canCreateARelationshipAndTodoBetweenCategoryAndTodoViaTodos(){ - final EntityInstance acategory = categories.createManagedInstance().setValue("title", "a Category"); + final EntityInstance acategory = categories.addInstance(new EntityInstance(categories.definition())).setValue("title", "a Category"); Assertions.assertEquals(0, acategory.getRelationships().getConnectedItems("todos").size()); Assertions.assertEquals(0,todo.countInstances()); @@ -233,9 +233,9 @@ public void canCreateARelationshipAndTodoBetweenCategoryAndTodoViaTodos(){ @Test public void canCreateARelationshipBetweenProjectAndTodoViaTasksUsingXml(){ - final EntityInstance atodo = todo.createManagedInstance().setValue("title", "a TODO"); + final EntityInstance atodo = todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "a TODO"); - final EntityInstance aproject = project.createManagedInstance().setValue("title", "a Project"); + final EntityInstance aproject = project.addInstance(new EntityInstance(project.definition())).setValue("title", "a Project"); Assertions.assertEquals(0, aproject.getRelationships().getConnectedItems("tasks").size()); @@ -255,9 +255,9 @@ public void canCreateARelationshipBetweenProjectAndTodoViaTasksUsingXml(){ @Test public void canDeleteARelationshipBetweenProjectAndTodoViaTasks(){ - final EntityInstance atodo = todo.createManagedInstance().setValue("title", "a TODO"); + final EntityInstance atodo = todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "a TODO"); - final EntityInstance aproject = project.createManagedInstance().setValue("title", "a Project"); + final EntityInstance aproject = project.addInstance(new EntityInstance(project.definition())).setValue("title", "a Project"); aproject.getRelationships().connect("tasks", atodo); @@ -282,9 +282,9 @@ public void canDeleteARelationshipBetweenProjectAndTodoViaTasks(){ public void canDeleteARelationshipBetweenCategoryAndTodoViaTodos(){ - final EntityInstance acategory = categories.createManagedInstance().setValue("title", "a Category"); + final EntityInstance acategory = categories.addInstance(new EntityInstance(categories.definition())).setValue("title", "a Category"); - final EntityInstance atodo = todo.createManagedInstance().setValue("title", "a TODO"); + final EntityInstance atodo = todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "a TODO"); acategory.getRelationships().connect("todos", atodo); @@ -344,7 +344,7 @@ public void canNotCreateEstimateWithoutMandatoryRelationship(){ @Test public void canCreateAnEstimateForTodoMandatoryRelationship(){ - final EntityInstance atodo = todo.createManagedInstance().setValue("title", "a TODO for estimating"); + final EntityInstance atodo = todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "a TODO for estimating"); HttpApiRequest request = new HttpApiRequest("todos/" + atodo.getPrimaryKeyValue() + "/estimates" ); @@ -367,11 +367,10 @@ public void canCreateAnEstimateForTodoMandatoryRelationship(){ public void canDeleteAnEstimateWhenTodoDeletedBecauseOfMandatoryRelationship(){ - - final EntityInstance atodo = todo.createManagedInstance().setValue("title", "a TODO for estimating"); + final EntityInstance atodo = todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "a TODO for estimating"); final EntityInstanceCollection estimates = todoManager.getThingInstancesNamed("estimate", EntityRelModel.DEFAULT_DATABASE_NAME); - final EntityInstance anEstimate = estimates.createManagedInstance().setValue("duration", "7"); + final EntityInstance anEstimate = estimates.addInstance(new EntityInstance(estimates.definition())).setValue("duration", "7"); anEstimate.getRelationships().connect("estimate", atodo); @@ -395,11 +394,10 @@ public void canDeleteAnEstimateWhenTodoDeletedBecauseOfMandatoryRelationship(){ public void canGetEstimatesViaRelationship(){ - - final EntityInstance atodo = todo.createManagedInstance().setValue("title", "a TODO for estimating"); + final EntityInstance atodo = todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "a TODO for estimating"); final EntityInstanceCollection estimates = todoManager.getThingInstancesNamed("estimate", EntityRelModel.DEFAULT_DATABASE_NAME); - final EntityInstance anEstimate = estimates.createManagedInstance().setValue("duration", "7").setValue("description", "an estimate"); + final EntityInstance anEstimate = estimates.addInstance(new EntityInstance(estimates.definition())).setValue("duration", "7").setValue("description", "an estimate"); anEstimate.getRelationships().connect("estimate", atodo); diff --git a/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/http_api/XmlRequestResponseTest.java b/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/http_api/XmlRequestResponseTest.java index 0691b926..a111e76b 100644 --- a/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/http_api/XmlRequestResponseTest.java +++ b/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/http_api/XmlRequestResponseTest.java @@ -13,8 +13,6 @@ import uk.co.compendiumdev.thingifier.api.response.ApiResponse; import uk.co.compendiumdev.thingifier.core.domain.instances.EntityInstance; -import java.util.UUID; - public class XmlRequestResponseTest { @@ -58,7 +56,7 @@ public void canGetAnEmptyXmlItemsCollection(){ public void canGetXmlItemsWhenAskedForXml(){ - todo.createManagedInstance().setValue("title", "my title"); + todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "my title"); HttpApiRequest request = new HttpApiRequest("todos"); request.getHeaders().putAll(HeadersSupport.acceptXml()); @@ -74,7 +72,7 @@ public void canGetXmlItemsWhenAskedForXml(){ public void canGetXmlErrorMessagesWhenAskedForXml(){ - todo.createManagedInstance().setValue("title", "my title"); + todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "my title"); HttpApiRequest request = new HttpApiRequest("todosyoohoo"); request.getHeaders().putAll(HeadersSupport.acceptXml()); @@ -133,7 +131,7 @@ public void canPostAndCreateAnItemWithXml(){ @Test public void canPostAndAmendAnItemWithXml(){ - final EntityInstance atodo = todo.createManagedInstance().setValue("title", "my title"); + final EntityInstance atodo = todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "my title"); Assertions.assertEquals(1, todo.countInstances()); @@ -210,7 +208,7 @@ public void canPutAndCreateAnItemWithXmlAndReceiveJson(){ @Test public void canPutToAmendAnItemWithJson(){ - final EntityInstance atodo = todo.createManagedInstance().setValue("title", "my title"); + final EntityInstance atodo = todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "my title"); Assertions.assertEquals(1, todo.countInstances()); diff --git a/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/unit/BasicTodoManagerTest.java b/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/unit/BasicTodoManagerTest.java index 96596f76..5f1ba873 100644 --- a/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/unit/BasicTodoManagerTest.java +++ b/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/unit/BasicTodoManagerTest.java @@ -45,10 +45,10 @@ public void relationshipDefinitionCheck(){ EntityInstanceCollection todo = todoManager.getThingInstancesNamed("todo", EntityRelModel.DEFAULT_DATABASE_NAME); EntityInstanceCollection project = todoManager.getThingInstancesNamed("project", EntityRelModel.DEFAULT_DATABASE_NAME); - EntityInstance paperwork = todo.createManagedInstance().setValue("title", "scan paperwork"); - EntityInstance filework = todo.createManagedInstance().setValue("title", "file paperwork"); + EntityInstance paperwork = todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "scan paperwork"); + EntityInstance filework = todo.addInstance(new EntityInstance(todo.definition())).setValue("title", "file paperwork"); - EntityInstance officeWork = project.createManagedInstance().setValue("title", "Office Work"); + EntityInstance officeWork = project.addInstance(new EntityInstance(project.definition())).setValue("title", "Office Work"); officeWork.getRelationships().connect("tasks", paperwork); officeWork.getRelationships().connect("tasks", filework); @@ -77,11 +77,11 @@ public void createAndAmendSomeTodos(){ EntityInstanceCollection todos = todoManager.getThingInstancesNamed("todo", EntityRelModel.DEFAULT_DATABASE_NAME); - EntityInstance tidy = todos.createManagedInstance(). + EntityInstance tidy = todos.addInstance(new EntityInstance(todos.definition())). setValue("title", "Tidy up my room"). setValue("description", "I need to tidy up my room because it is a mess"); - EntityInstance paperwork = todos.createManagedInstance(). + EntityInstance paperwork = todos.addInstance(new EntityInstance(todos.definition())). setValue("title","Do Paperwork"). setValue("description", "Scan everything in, upload to document management system and file paperwork"); @@ -102,7 +102,7 @@ public void createAndDeleteTodos(){ int originalTodosCount = todos.countInstances(); - EntityInstance tidy = todos.createManagedInstance(). + EntityInstance tidy = todos.addInstance(new EntityInstance(todos.definition())). setValue("title","Delete this todo"). setValue("description", "I need to be deleted"); diff --git a/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/unit/OptionalityRelationshipTest.java b/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/unit/OptionalityRelationshipTest.java index 146005a9..f01ed583 100644 --- a/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/unit/OptionalityRelationshipTest.java +++ b/thingifier/src/test/java/uk/co/compendiumdev/casestudy/todomanager/unit/OptionalityRelationshipTest.java @@ -35,14 +35,14 @@ public void byDefaultRelationshipsAreOptional(){ EntityInstanceCollection projects = todoManager.getThingInstancesNamed("project", EntityRelModel.DEFAULT_DATABASE_NAME); - EntityInstance aProject = projects.createManagedInstance().setValue("title", "myproject"); + EntityInstance aProject = projects.addInstance(new EntityInstance(projects.definition())).setValue("title", "myproject"); Assertions.assertTrue(aProject.validate().isValid()); EntityInstanceCollection todos = todoManager.getThingInstancesNamed("todo", EntityRelModel.DEFAULT_DATABASE_NAME); - EntityInstance tidy = todos.createManagedInstance(). + EntityInstance tidy = todos.addInstance(new EntityInstance(todos.definition())). setValue("title", "Tidy up my room"). setValue("description", "I need to tidy up my room because it is a mess"); @@ -56,13 +56,13 @@ public void anEstimateWithoutATodoIsInvalid(){ EntityInstanceCollection todos = todoManager.getThingInstancesNamed("todo", EntityRelModel.DEFAULT_DATABASE_NAME); - EntityInstance tidy = todos.createManagedInstance(). + EntityInstance tidy = todos.addInstance(new EntityInstance(todos.definition())). setValue("title", "Tidy up my room"). setValue("description", "I need to tidy up my room because it is a mess"); EntityInstanceCollection estimates = todoManager.getThingInstancesNamed("estimate", EntityRelModel.DEFAULT_DATABASE_NAME); - EntityInstance tidyRoomEstimate = estimates.createManagedInstance(). + EntityInstance tidyRoomEstimate = estimates.addInstance(new EntityInstance(estimates.definition())). setValue("duration", "1"); // it should be invalid because the estimate does not have a relationship with a to do @@ -75,13 +75,13 @@ public void anEstimateMustHaveATodoToBeValid(){ EntityInstanceCollection todos = todoManager.getThingInstancesNamed("todo", EntityRelModel.DEFAULT_DATABASE_NAME); - EntityInstance tidy = todos.createManagedInstance(). + EntityInstance tidy = todos.addInstance(new EntityInstance(todos.definition())). setValue("title", "Tidy up my room"). setValue("description", "I need to tidy up my room because it is a mess"); EntityInstanceCollection estimates = todoManager.getThingInstancesNamed("estimate", EntityRelModel.DEFAULT_DATABASE_NAME); - EntityInstance tidyRoomEstimate = estimates.createManagedInstance(). + EntityInstance tidyRoomEstimate = estimates.addInstance(new EntityInstance(estimates.definition())). setValue("duration", "1"); tidyRoomEstimate.getRelationships().connect("estimate", tidy); @@ -102,14 +102,14 @@ public void deleteAlsoCoversMandatoryOptionalityRelationships(){ EntityInstanceCollection todos = todoManager.getThingInstancesNamed("todo", EntityRelModel.DEFAULT_DATABASE_NAME); - EntityInstance tidy = todos.createManagedInstance(). + EntityInstance tidy = todos.addInstance(new EntityInstance(todos.definition())). setValue("title", "Tidy up my room"). setValue("description", "I need to tidy up my room because it is a mess"); EntityInstanceCollection estimates = todoManager.getThingInstancesNamed("estimate", EntityRelModel.DEFAULT_DATABASE_NAME); - EntityInstance tidyRoomEstimate = estimates.createManagedInstance(). + EntityInstance tidyRoomEstimate = estimates.addInstance(new EntityInstance(estimates.definition())). setValue("duration", "1"); tidyRoomEstimate.getRelationships().connect("estimate", tidy); diff --git a/thingifier/src/test/java/uk/co/compendiumdev/thingifier/api/http/requests/ThingifierHttpApiRequestHandlingTest.java b/thingifier/src/test/java/uk/co/compendiumdev/thingifier/api/http/requests/ThingifierHttpApiRequestHandlingTest.java index 32cc8de4..75d7e0a1 100644 --- a/thingifier/src/test/java/uk/co/compendiumdev/thingifier/api/http/requests/ThingifierHttpApiRequestHandlingTest.java +++ b/thingifier/src/test/java/uk/co/compendiumdev/thingifier/api/http/requests/ThingifierHttpApiRequestHandlingTest.java @@ -47,7 +47,7 @@ public void aGetRequestWillCreateNewSessionWithDatabase(){ // add a thing final EntityInstanceCollection thing = thingifier.getERmodel().getInstanceData("other_things").getInstanceCollectionForEntityNamed("thing"); - final EntityInstance existingInstance = thing.createManagedInstance().setValue("title", "My Title" + System.nanoTime()); + final EntityInstance existingInstance = thing.addInstance(new EntityInstance(thing.definition())).setValue("title", "My Title" + System.nanoTime()); final HttpApiResponse response2 = api.get(new HttpApiRequest("/things/" + existingInstance.getPrimaryKeyValue()).setHeaders(headers)); @@ -67,7 +67,7 @@ public void populate(final ERSchema schema, final ERInstanceData database) { EntityInstanceCollection things = database.getInstanceCollectionForEntityNamed("thing"); for(String thingTitle : titles){ - things.createManagedInstance().setValue("title", thingTitle); + things.addInstance(new EntityInstance(things.definition())).setValue("title", thingTitle); } } }; @@ -145,7 +145,7 @@ public void aDeleteRequestWillCreateNewSessionWithDatabase(){ getInstanceData("other_things"). getInstanceCollectionForEntityNamed("thing"); - EntityInstance anInstance = thingInstances.createManagedInstance(); + EntityInstance anInstance = thingInstances.addInstance(new EntityInstance(thingInstances.definition())); Assertions.assertEquals(1, thingInstances.countInstances()); diff --git a/thingifier/src/test/java/uk/co/compendiumdev/thingifier/api/non_http/IdBasedInstanceNonHttpTest.java b/thingifier/src/test/java/uk/co/compendiumdev/thingifier/api/non_http/IdBasedInstanceNonHttpTest.java index 16945637..ee756c3f 100644 --- a/thingifier/src/test/java/uk/co/compendiumdev/thingifier/api/non_http/IdBasedInstanceNonHttpTest.java +++ b/thingifier/src/test/java/uk/co/compendiumdev/thingifier/api/non_http/IdBasedInstanceNonHttpTest.java @@ -42,7 +42,7 @@ public void canGetAThingUsingGuidFromDefaultSession(){ Thingifier model = getThingifier(); final EntityInstanceCollection thing = model.getThingInstancesNamed("thing", EntityRelModel.DEFAULT_DATABASE_NAME); - final EntityInstance existingInstance = thing.createManagedInstance().setValue("title", + final EntityInstance existingInstance = thing.addInstance(new EntityInstance(thing.definition())).setValue("title", "My Title" + System.nanoTime()); // no session header so use default session @@ -57,7 +57,7 @@ public void canGetAThingUsingIdFromDefaultSession(){ Thingifier model = getThingifier(); final EntityInstanceCollection thing = model.getThingInstancesNamed("thing", EntityRelModel.DEFAULT_DATABASE_NAME); - final EntityInstance existingInstance = thing.createManagedInstance().setValue("title", + final EntityInstance existingInstance = thing.addInstance(new EntityInstance(thing.definition())).setValue("title", "My Title" + System.nanoTime()); // no session header so use default session @@ -83,7 +83,7 @@ public void canGetAThingUsingGuidFromCustomSession(){ // add instance to custom session final EntityInstanceCollection thing = model.getERmodel().getInstanceData("other_things").getInstanceCollectionForEntityNamed("thing"); - final EntityInstance existingInstance = thing.createManagedInstance().setValue("title", "My Title" + System.nanoTime()); + final EntityInstance existingInstance = thing.addInstance(new EntityInstance(thing.definition())).setValue("title", "My Title" + System.nanoTime()); final ApiResponse idApiResponse2 = model.api().get("/thing/" + existingInstance.getPrimaryKeyValue(), new QueryFilterParams(), headers); Assertions.assertEquals(200, idApiResponse2.getStatusCode()); @@ -106,7 +106,7 @@ public void canGetAThingUsingIdFromCustomSession(){ // add instance to custom session final EntityInstanceCollection thing = model.getERmodel().getInstanceData("other_things").getInstanceCollectionForEntityNamed("thing"); - final EntityInstance existingInstance = thing.createManagedInstance().setValue("title", "My Title" + System.nanoTime()); + final EntityInstance existingInstance = thing.addInstance(new EntityInstance(thing.definition())).setValue("title", "My Title" + System.nanoTime()); final ApiResponse idApiResponse2 = model.api().get("/thing/" + existingInstance.getFieldValue("id").asString(), new QueryFilterParams(), headers); Assertions.assertEquals(200, idApiResponse2.getStatusCode()); diff --git a/thingifier/src/test/java/uk/co/compendiumdev/thingifier/api/response/ApiResponseAsJsonTest.java b/thingifier/src/test/java/uk/co/compendiumdev/thingifier/api/response/ApiResponseAsJsonTest.java index 05a9b620..b8e647b6 100644 --- a/thingifier/src/test/java/uk/co/compendiumdev/thingifier/api/response/ApiResponseAsJsonTest.java +++ b/thingifier/src/test/java/uk/co/compendiumdev/thingifier/api/response/ApiResponseAsJsonTest.java @@ -109,7 +109,7 @@ public void response200WithInstance(){ todo.addFields( Field.is("title", STRING)); EntityInstanceCollection todos = thingifier.getThingInstancesNamed("todo", EntityRelModel.DEFAULT_DATABASE_NAME); - EntityInstance aTodo = todos.createManagedInstance().setValue("title", "a todo"); + EntityInstance aTodo = todos.addInstance(new EntityInstance(todos.definition())).setValue("title", "a todo"); ApiResponse response = ApiResponse.success().returnSingleInstance(aTodo); @@ -136,8 +136,8 @@ public void response200WithInstances(){ todo.addFields( Field.is("title", STRING)); EntityInstanceCollection todos = thingifier.getThingInstancesNamed("todo", EntityRelModel.DEFAULT_DATABASE_NAME); - EntityInstance aTodo = todos.createManagedInstance().setValue("title", "a todo"); - EntityInstance anotherTodo = todos.createManagedInstance().setValue("title", "another todo"); + EntityInstance aTodo = todos.addInstance(new EntityInstance(todos.definition())).setValue("title", "a todo"); + EntityInstance anotherTodo = todos.addInstance(new EntityInstance(todos.definition())).setValue("title", "another todo"); ApiResponse response = ApiResponse.success().returnInstanceCollection(new ArrayList(todos.getInstances())); diff --git a/thingifier/src/test/java/uk/co/compendiumdev/thingifier/api/response/ApiResponseAsXmlTest.java b/thingifier/src/test/java/uk/co/compendiumdev/thingifier/api/response/ApiResponseAsXmlTest.java index 708f6174..d4c2d32d 100644 --- a/thingifier/src/test/java/uk/co/compendiumdev/thingifier/api/response/ApiResponseAsXmlTest.java +++ b/thingifier/src/test/java/uk/co/compendiumdev/thingifier/api/response/ApiResponseAsXmlTest.java @@ -126,7 +126,7 @@ public void response200WithInstance(){ todo.addFields( Field.is("title", STRING)); EntityInstanceCollection todos = thingifier.getThingInstancesNamed("todo", EntityRelModel.DEFAULT_DATABASE_NAME); - EntityInstance aTodo = todos.createManagedInstance().setValue("title", "a todo"); + EntityInstance aTodo = todos.addInstance(new EntityInstance(todos.definition())).setValue("title", "a todo"); ApiResponse response = ApiResponse.success().returnSingleInstance(aTodo); @@ -154,8 +154,8 @@ public void response200WithInstances(){ todo.addFields( Field.is("title", STRING)); EntityInstanceCollection todos = thingifier.getThingInstancesNamed("todo", EntityRelModel.DEFAULT_DATABASE_NAME); - EntityInstance aTodo = todos.createManagedInstance().setValue("title", "a todo"); - EntityInstance anotherTodo = todos.createManagedInstance().setValue("title", "another todo"); + EntityInstance aTodo = todos.addInstance(new EntityInstance(todos.definition())).setValue("title", "a todo"); + EntityInstance anotherTodo = todos.addInstance(new EntityInstance(todos.definition())).setValue("title", "another todo"); ApiResponse response = ApiResponse.success().returnInstanceCollection(new ArrayList(todos.getInstances())); diff --git a/thingifier/src/test/java/uk/co/compendiumdev/thingifier/api/response/ApiResponseTest.java b/thingifier/src/test/java/uk/co/compendiumdev/thingifier/api/response/ApiResponseTest.java index 00d9b21f..51077251 100644 --- a/thingifier/src/test/java/uk/co/compendiumdev/thingifier/api/response/ApiResponseTest.java +++ b/thingifier/src/test/java/uk/co/compendiumdev/thingifier/api/response/ApiResponseTest.java @@ -88,7 +88,7 @@ public void response200WithInstance(){ todo.addFields( Field.is("title", STRING)); EntityInstanceCollection todos = thingifier.getThingInstancesNamed("todo", EntityRelModel.DEFAULT_DATABASE_NAME); - EntityInstance aTodo = todos.createManagedInstance().setValue("title", "a todo"); + EntityInstance aTodo = todos.addInstance(new EntityInstance(todos.definition())).setValue("title", "a todo"); ApiResponse response = ApiResponse.success().returnSingleInstance(aTodo); @@ -109,8 +109,8 @@ public void response200WithInstances(){ todo.addFields( Field.is("title", STRING)); EntityInstanceCollection todos = thingifier.getThingInstancesNamed("todo", EntityRelModel.DEFAULT_DATABASE_NAME); - EntityInstance aTodo = todos.createManagedInstance().setValue("title", "a todo"); - EntityInstance anotherTodo = todos.createManagedInstance().setValue("title", "another todo"); + EntityInstance aTodo = todos.addInstance(new EntityInstance(todos.definition())).setValue("title", "a todo"); + EntityInstance anotherTodo = todos.addInstance(new EntityInstance(todos.definition())).setValue("title", "another todo"); ApiResponse response = ApiResponse.success().returnInstanceCollection(new ArrayList(todos.getInstances()));