Skip to content

Commit

Permalink
refactoring to remove method created for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eviltester committed Dec 31, 2024
1 parent d673020 commit 2f5c1fe
Show file tree
Hide file tree
Showing 35 changed files with 196 additions and 219 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> x_challenger_header = getXChallengerHeader(challenger.getXChallenger());

Expand Down Expand Up @@ -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<String, String> x_challenger_header = getXChallengerHeader(challenger.getXChallenger());

Expand All @@ -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<String, String> x_challenger_header = getXChallengerHeader(challenger.getXChallenger());

Expand Down Expand Up @@ -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, "");
Expand Down Expand Up @@ -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()));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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();
Expand All @@ -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,
Expand Down Expand Up @@ -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().
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@

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;
import uk.co.compendiumdev.thingifier.core.domain.definitions.field.definition.FieldType;
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 {

Expand All @@ -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");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@

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;
import uk.co.compendiumdev.thingifier.core.domain.definitions.field.definition.FieldType;
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 {

Expand All @@ -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");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@

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;
import uk.co.compendiumdev.thingifier.core.domain.definitions.field.definition.FieldType;
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 {

Expand All @@ -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");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -193,7 +193,7 @@ public void connectionTesting() {
List<EntityInstance> 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);
Expand Down
Loading

0 comments on commit 2f5c1fe

Please sign in to comment.