diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/nucleus/testsupport/runcontinuityplugin/RunContinuityPluginData.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/nucleus/testsupport/runcontinuityplugin/RunContinuityPluginData.java index fdc3ca009..c3334e5bb 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/nucleus/testsupport/runcontinuityplugin/RunContinuityPluginData.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/nucleus/testsupport/runcontinuityplugin/RunContinuityPluginData.java @@ -31,6 +31,39 @@ private Data(Data data) { locked = data.locked; } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((consumers == null) ? 0 : consumers.hashCode()); + result = prime * result + (locked ? 1231 : 1237); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof Data)) { + return false; + } + Data other = (Data) obj; + if (consumers == null) { + if (other.consumers != null) { + return false; + } + } else if (!consumers.equals(other.consumers)) { + return false; + } + if (locked != other.locked) { + return false; + } + return true; + } + + + } /** @@ -105,7 +138,7 @@ public List>> getConsumers() { } @Override - public PluginDataBuilder getCloneBuilder() { + public Builder getCloneBuilder() { return new Builder(data); } @@ -117,4 +150,31 @@ public boolean allPlansComplete() { return data.consumers.isEmpty(); } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((data == null) ? 0 : data.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof RunContinuityPluginData)) { + return false; + } + RunContinuityPluginData other = (RunContinuityPluginData) obj; + if (data == null) { + if (other.data != null) { + return false; + } + } else if (!data.equals(other.data)) { + return false; + } + return true; + } + } diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/globalproperties/datamanagers/GlobalPropertiesPluginData.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/globalproperties/datamanagers/GlobalPropertiesPluginData.java index 1c2e34e83..2edfaba1c 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/globalproperties/datamanagers/GlobalPropertiesPluginData.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/globalproperties/datamanagers/GlobalPropertiesPluginData.java @@ -409,7 +409,7 @@ private static void validateGlobalPropertyIdExists(final Data data, final Global } @Override - public PluginDataBuilder getCloneBuilder() { + public Builder getCloneBuilder() { return new Builder(data); } diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/groups/datamanagers/GroupsPluginData.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/groups/datamanagers/GroupsPluginData.java index 2d79e664e..067561161 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/groups/datamanagers/GroupsPluginData.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/groups/datamanagers/GroupsPluginData.java @@ -620,6 +620,13 @@ public Builder setNextGroupIdValue(int nextGroupIdValue) { data.nextGroupIdValue = nextGroupIdValue; return this; } + + public Builder resetNextGroupIdValue() { + ensureDataMutability(); + data.nextGroupIdValue = -1; + return this; + } + private void validateData() { @@ -1030,7 +1037,7 @@ public int getGroupCount() { } @Override - public PluginDataBuilder getCloneBuilder() { + public Builder getCloneBuilder() { return new Builder(data); } diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/groups/support/GroupError.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/groups/support/GroupError.java index 8f51d5cc4..f06a0c4ac 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/groups/support/GroupError.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/groups/support/GroupError.java @@ -10,7 +10,7 @@ public enum GroupError implements ContractError { NEGATIVE_GROUP_ID("group id is negative"), NEGATIVE_GROUP_COUNT("group count is negative"), - NEXT_GROUP_ID_TOO_SMALL("The next gropu id must exceed all extant group ids"), + NEXT_GROUP_ID_TOO_SMALL("The next group id must exceed all extant group ids"), NULL_GROUP_INITIALIZATION_DATA("Null group initialization data"), NULL_GROUP_DATA_MANAGER("Null group data manager"), NULL_GROUP_PLUGIN_DATA("null groupsplugin data"), NULL_GROUP_POPULATION_REPORT_PLUGIN_DATA("Null group population report plugin data"), diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/materials/datamangers/MaterialsPluginData.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/materials/datamangers/MaterialsPluginData.java index 151bf3cf9..3dc8633d8 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/materials/datamangers/MaterialsPluginData.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/materials/datamangers/MaterialsPluginData.java @@ -1755,7 +1755,7 @@ public Boolean isStageOffered(final StageId stageId) { } @Override - public PluginDataBuilder getCloneBuilder() { + public Builder getCloneBuilder() { return new Builder(data); } diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/partitions/datamanagers/PartitionsPluginData.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/partitions/datamanagers/PartitionsPluginData.java index 82c30b660..d764ae2c4 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/partitions/datamanagers/PartitionsPluginData.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/partitions/datamanagers/PartitionsPluginData.java @@ -109,7 +109,7 @@ public boolean supportsRunContinuity() { } @Override - public PluginDataBuilder getCloneBuilder() { + public Builder getCloneBuilder() { return new Builder(new Data(data)); } diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/partitions/testsupport/attributes/AttributesPluginData.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/partitions/testsupport/attributes/AttributesPluginData.java index 1be56941a..65c809919 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/partitions/testsupport/attributes/AttributesPluginData.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/partitions/testsupport/attributes/AttributesPluginData.java @@ -297,8 +297,7 @@ public Set getAttributeIds() { } @Override - public PluginDataBuilder getCloneBuilder() { - + public Builder getCloneBuilder() { return new Builder(data); } diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/people/datamanagers/PeoplePluginData.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/people/datamanagers/PeoplePluginData.java index 830c2a6c1..6f0fc2ae4 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/people/datamanagers/PeoplePluginData.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/people/datamanagers/PeoplePluginData.java @@ -265,6 +265,14 @@ public Builder setPersonCount(int personCount) { data.personCount = personCount; return this; } + /** + * Resets the person count + */ + public Builder resetPersonCount() { + ensureDataMutability(); + data.personCount = -1; + return this; + } /** * Sets the time for the last person added to the population. Defaults to zero. @@ -297,7 +305,7 @@ public List getPersonRanges() { } @Override - public PluginDataBuilder getCloneBuilder() { + public Builder getCloneBuilder() { return new Builder(data); } diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/personproperties/datamanagers/PersonPropertiesPluginData.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/personproperties/datamanagers/PersonPropertiesPluginData.java index e9c6453e7..27f7238c7 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/personproperties/datamanagers/PersonPropertiesPluginData.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/personproperties/datamanagers/PersonPropertiesPluginData.java @@ -447,7 +447,7 @@ public Set getPersonPropertyIds() { } @Override - public PluginDataBuilder getCloneBuilder() { + public Builder getCloneBuilder() { return new Builder(data); } diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/regions/datamanagers/RegionsPluginData.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/regions/datamanagers/RegionsPluginData.java index a0fbc2366..fc6a44b8b 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/regions/datamanagers/RegionsPluginData.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/regions/datamanagers/RegionsPluginData.java @@ -78,8 +78,8 @@ public Data(Data data) { } personRegions.addAll(data.personRegions); personAdditionMode = data.personAdditionMode; - - locked = data.locked; + personArrivalTimes.addAll(data.personArrivalTimes); + locked = data.locked; } @Override @@ -327,7 +327,7 @@ private void setPersonAdditionMode(PersonAdditionMode personAdditionMode) { public Builder addPerson(final PersonId personId, final RegionId regionId) { ensureDataMutability(); validatePersonId(personId); - validateRegionIdNotNull(regionId); + validateRegionIdNotNull(regionId); setPersonAdditionMode(PersonAdditionMode.REGION_ONLY); int personIndex = personId.getValue(); while (personIndex >= data.personRegions.size()) { @@ -568,7 +568,7 @@ public boolean getPersonRegionArrivalTrackingPolicy() { } @Override - public PluginDataBuilder getCloneBuilder() { + public Builder getCloneBuilder() { return new Builder(data); } diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/reports/support/ReportPeriod.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/reports/support/ReportPeriod.java index 7adc85df0..416a4684f 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/reports/support/ReportPeriod.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/reports/support/ReportPeriod.java @@ -5,5 +5,10 @@ * periodicity of the report. */ public enum ReportPeriod { - HOURLY, DAILY, END_OF_SIMULATION + HOURLY, DAILY, END_OF_SIMULATION; + + public ReportPeriod next() { + int index = (ordinal()+1) % ReportPeriod.values().length; + return ReportPeriod.values()[index]; + } } diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/resources/datamanagers/ResourcesPluginData.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/resources/datamanagers/ResourcesPluginData.java index 3123e88c0..379fb13bd 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/resources/datamanagers/ResourcesPluginData.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/resources/datamanagers/ResourcesPluginData.java @@ -845,7 +845,7 @@ public Set getRegionIds() { } @Override - public PluginDataBuilder getCloneBuilder() { + public Builder getCloneBuilder() { return new Builder(data); } diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/stochastics/datamanagers/StochasticsPluginData.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/stochastics/datamanagers/StochasticsPluginData.java index dba873d69..1ec757bdc 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/stochastics/datamanagers/StochasticsPluginData.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/plugins/stochastics/datamanagers/StochasticsPluginData.java @@ -27,7 +27,7 @@ private StochasticsPluginData(Data data) { } @Override - public PluginDataBuilder getCloneBuilder() { + public Builder getCloneBuilder() { return new Builder(data); } diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/nucleus/testsupport/runcontinuityplugin/AT_RunContinuityPluginData.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/nucleus/testsupport/runcontinuityplugin/AT_RunContinuityPluginData.java index df4e4f221..e07a0120e 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/nucleus/testsupport/runcontinuityplugin/AT_RunContinuityPluginData.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/nucleus/testsupport/runcontinuityplugin/AT_RunContinuityPluginData.java @@ -2,6 +2,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -64,10 +65,20 @@ public void testGetCloneBuilder() { } RunContinuityPluginData runContinuityPluginData = builder.build(); - RunContinuityPluginData cloneRunContinuityPluginData = // - (RunContinuityPluginData) runContinuityPluginData.getCloneBuilder().build(); + // show that the returned clone builder will build an identical instance if no + // mutations are made + RunContinuityPluginData.Builder cloneBuilder = runContinuityPluginData.getCloneBuilder(); + assertNotNull(cloneBuilder); + assertEquals(runContinuityPluginData, cloneBuilder.build()); + + // show that the clone builder builds a distinct instance if any mutation is + // made + + // addContextConsumer + cloneBuilder = runContinuityPluginData.getCloneBuilder(); + cloneBuilder.addContextConsumer(2.5,(c)->{}); + assertNotEquals(runContinuityPluginData, cloneBuilder.build()); - assertEquals(runContinuityPluginData.getConsumers(), cloneRunContinuityPluginData.getConsumers()); } } diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/nucleus/testsupport/testplugin/AT_TestPluginData.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/nucleus/testsupport/testplugin/AT_TestPluginData.java index 611e917f3..523784cf2 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/nucleus/testsupport/testplugin/AT_TestPluginData.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/nucleus/testsupport/testplugin/AT_TestPluginData.java @@ -46,11 +46,11 @@ public void testBuilder() { @Test @UnitTestMethod(target = TestPluginData.class, name = "getTestDataManager", args = { Object.class }) public void testGetTestDataManagerType() { - TestPluginData testPluginData = TestPluginData .builder()// - .addTestDataManager("A", () -> new TestDataManager1())// - .addTestDataManager("B", () -> new TestDataManager2())// - .addTestDataManager("C", () -> new TestDataManager3())// - .build();// + TestPluginData testPluginData = TestPluginData.builder()// + .addTestDataManager("A", () -> new TestDataManager1())// + .addTestDataManager("B", () -> new TestDataManager2())// + .addTestDataManager("C", () -> new TestDataManager3())// + .build();// // show that the aliased data manager types are retrievable Optional optional1 = testPluginData.getTestDataManager("A"); @@ -152,7 +152,7 @@ public void testGetTestReportPlans() { } } - + @Test @UnitTestMethod(target = TestPluginData.class, name = "getTestActorAliases", args = {}) public void testGetTestActorAliases() { @@ -174,7 +174,7 @@ public void testGetTestActorAliases() { assertEquals(expectedAliases, actualAliases); } - + @Test @UnitTestMethod(target = TestPluginData.class, name = "getTestReportAliases", args = {}) public void testGetTestReportAliases() { @@ -228,12 +228,48 @@ public void testGetCloneBuilder() { // build the plugin data TestPluginData testPluginData = builder.build(); - // show that the clone builder is properly initialized -- i.e. it will - // immediately build a clone of the plugin data + // show that the returned clone builder will build an identical instance if no + // mutations are made TestPluginData.Builder cloneBuilder = testPluginData.getCloneBuilder(); assertNotNull(cloneBuilder); + assertEquals(testPluginData, cloneBuilder.build()); + + // show that the clone builder builds a distinct instance if any mutation is + // made + + // addPluginDependency + cloneBuilder = testPluginData.getCloneBuilder(); + PluginId pluginId = new PluginId() { + }; + cloneBuilder.addPluginDependency(pluginId); + assertNotEquals(testPluginData, cloneBuilder.build()); + + // addTestActorPlan + cloneBuilder = testPluginData.getCloneBuilder(); + cloneBuilder.addTestActorPlan("actor", new TestActorPlan(0.0, (c) -> { + })); + assertNotEquals(testPluginData, cloneBuilder.build()); + + // addTestDataManager + cloneBuilder = testPluginData.getCloneBuilder(); + cloneBuilder.addTestDataManager("dm", () -> null); + assertNotEquals(testPluginData, cloneBuilder.build()); + + /* + * addTestDataManager -- note that we cloned twice to ensure the dm exists in + * the original and thus we can add the dm plan + */ TestPluginData testPluginData2 = cloneBuilder.build(); - assertEquals(testPluginData, testPluginData2); + cloneBuilder = testPluginData2.getCloneBuilder(); + cloneBuilder.addTestDataManagerPlan("dm", new TestDataManagerPlan(4.5, (c) -> { + })); + assertNotEquals(testPluginData, cloneBuilder.build()); + + // addTestReportPlan + cloneBuilder = testPluginData.getCloneBuilder(); + cloneBuilder.addTestReportPlan("report", new TestReportPlan(4.5, (c) -> { + })); + assertNotEquals(testPluginData, cloneBuilder.build()); } @@ -301,7 +337,8 @@ public void testGetTestDataManagerAliases() { } @Test - @UnitTestMethod(target = TestPluginData.Builder.class, name = "addTestActorPlan", args = { Object.class, TestActorPlan.class }) + @UnitTestMethod(target = TestPluginData.Builder.class, name = "addTestActorPlan", args = { Object.class, + TestActorPlan.class }) public void testAddTestActorPlan() { // create a few plans Map> testActorPlanMap = new LinkedHashMap<>(); @@ -339,9 +376,10 @@ public void testAddTestActorPlan() { assertEquals(expectedPlans, actualPlans); } } - + @Test - @UnitTestMethod(target = TestPluginData.Builder.class, name = "addTestReportPlan", args = { Object.class, TestReportPlan.class }) + @UnitTestMethod(target = TestPluginData.Builder.class, name = "addTestReportPlan", args = { Object.class, + TestReportPlan.class }) public void testAddTestReportPlan() { // create a few plans Map> testReportPlanMap = new LinkedHashMap<>(); @@ -379,10 +417,10 @@ public void testAddTestReportPlan() { assertEquals(expectedPlans, actualPlans); } } - - + @Test - @UnitTestMethod(target = TestPluginData.Builder.class, name = "addTestDataManager", args = { Object.class, Supplier.class }) + @UnitTestMethod(target = TestPluginData.Builder.class, name = "addTestDataManager", args = { Object.class, + Supplier.class }) public void testAddTestDataManager() { // create a few plans @@ -400,12 +438,14 @@ public void testAddTestDataManager() { TestPluginData testPluginData = builder.build(); // show that the plugin data contains the expected plans - LinkedHashSet actualDataManagerAliases = new LinkedHashSet<>(testPluginData.getTestDataManagerAliases()); + LinkedHashSet actualDataManagerAliases = new LinkedHashSet<>( + testPluginData.getTestDataManagerAliases()); assertEquals(expectedDataManagerAliases, actualDataManagerAliases); } @Test - @UnitTestMethod(target = TestPluginData.Builder.class, name = "addTestDataManagerPlan", args = { Object.class, TestDataManagerPlan.class }) + @UnitTestMethod(target = TestPluginData.Builder.class, name = "addTestDataManagerPlan", args = { Object.class, + TestDataManagerPlan.class }) public void testAddTestDataManagerPlan() { // create a few plans Map> testDataManagerPlanMap = new LinkedHashMap<>(); @@ -474,7 +514,8 @@ public void testAddPluginDependency() { } // precondition test: if the plugin id is null - ContractException contractException = assertThrows(ContractException.class, () -> TestPluginData.builder().addPluginDependency(null)); + ContractException contractException = assertThrows(ContractException.class, + () -> TestPluginData.builder().addPluginDependency(null)); assertEquals(TestError.NULL_PLUGIN_ID, contractException.getErrorType()); } @@ -502,74 +543,74 @@ public void testEquals() { TestDataManagerPlan testDataManagerPlan2 = new TestDataManagerPlan(0, (c) -> { }); - TestPluginData testPluginData1 = TestPluginData .builder()// - .addPluginDependency(simplePluginIdA)// - .addTestActorPlan("actor", testActorPlan1)// - .addTestDataManagerPlan("dm", testDataManagerPlan1)// - .addTestDataManager("dm", supplier1)// - .build(); + TestPluginData testPluginData1 = TestPluginData.builder()// + .addPluginDependency(simplePluginIdA)// + .addTestActorPlan("actor", testActorPlan1)// + .addTestDataManagerPlan("dm", testDataManagerPlan1)// + .addTestDataManager("dm", supplier1)// + .build(); // identical inputs - TestPluginData testPluginData2 = TestPluginData .builder()// - .addPluginDependency(simplePluginIdA)// - .addTestActorPlan("actor", testActorPlan1)// - .addTestDataManagerPlan("dm", testDataManagerPlan1)// - .addTestDataManager("dm", supplier1)// - .build(); + TestPluginData testPluginData2 = TestPluginData.builder()// + .addPluginDependency(simplePluginIdA)// + .addTestActorPlan("actor", testActorPlan1)// + .addTestDataManagerPlan("dm", testDataManagerPlan1)// + .addTestDataManager("dm", supplier1)// + .build(); assertEquals(testPluginData1, testPluginData2); // with different plugin dependencies - TestPluginData testPluginData3 = TestPluginData .builder()// - .addPluginDependency(simplePluginIdB)// - .addTestActorPlan("actor", testActorPlan1)// - .addTestDataManagerPlan("dm", testDataManagerPlan1)// - .addTestDataManager("dm", supplier1)// - .build(); + TestPluginData testPluginData3 = TestPluginData.builder()// + .addPluginDependency(simplePluginIdB)// + .addTestActorPlan("actor", testActorPlan1)// + .addTestDataManagerPlan("dm", testDataManagerPlan1)// + .addTestDataManager("dm", supplier1)// + .build(); assertNotEquals(testPluginData1, testPluginData3); testPluginData3 = TestPluginData.builder()// - .addPluginDependency(simplePluginIdA)// - .addPluginDependency(simplePluginIdB)// - .addTestActorPlan("actor", testActorPlan1)// - .addTestDataManagerPlan("dm", testDataManagerPlan1)// - .addTestDataManager("dm", supplier1)// - .build(); + .addPluginDependency(simplePluginIdA)// + .addPluginDependency(simplePluginIdB)// + .addTestActorPlan("actor", testActorPlan1)// + .addTestDataManagerPlan("dm", testDataManagerPlan1)// + .addTestDataManager("dm", supplier1)// + .build(); assertNotEquals(testPluginData1, testPluginData3); // with different actor plans - TestPluginData testPluginData4 = TestPluginData .builder()// - .addPluginDependency(simplePluginIdA)// - .addTestActorPlan("actor", testActorPlan2)// - .addTestDataManagerPlan("dm", testDataManagerPlan1)// - .addTestDataManager("dm", supplier1)// - .build(); + TestPluginData testPluginData4 = TestPluginData.builder()// + .addPluginDependency(simplePluginIdA)// + .addTestActorPlan("actor", testActorPlan2)// + .addTestDataManagerPlan("dm", testDataManagerPlan1)// + .addTestDataManager("dm", supplier1)// + .build(); assertEquals(testPluginData1, testPluginData4); testPluginData4 = TestPluginData.builder()// - .addPluginDependency(simplePluginIdA)// - .addTestActorPlan("actor2", testActorPlan1)// - .addTestDataManagerPlan("dm", testDataManagerPlan1)// - .addTestDataManager("dm", supplier1)// - .build(); + .addPluginDependency(simplePluginIdA)// + .addTestActorPlan("actor2", testActorPlan1)// + .addTestDataManagerPlan("dm", testDataManagerPlan1)// + .addTestDataManager("dm", supplier1)// + .build(); assertNotEquals(testPluginData1, testPluginData4); // with different data manager plans - TestPluginData testPluginData5 = TestPluginData .builder()// - .addPluginDependency(simplePluginIdA)// - .addTestActorPlan("actor", testActorPlan1)// - .addTestDataManagerPlan("dm", testDataManagerPlan2)// - .addTestDataManager("dm", supplier1)// - .build(); + TestPluginData testPluginData5 = TestPluginData.builder()// + .addPluginDependency(simplePluginIdA)// + .addTestActorPlan("actor", testActorPlan1)// + .addTestDataManagerPlan("dm", testDataManagerPlan2)// + .addTestDataManager("dm", supplier1)// + .build(); assertEquals(testPluginData1, testPluginData5); // with different data manager suppliers - TestPluginData testPluginData6 = TestPluginData .builder()// - .addPluginDependency(simplePluginIdA)// - .addTestActorPlan("actor", testActorPlan1)// - .addTestDataManagerPlan("dm", testDataManagerPlan1)// - .addTestDataManager("dm", supplier2)// - .build(); + TestPluginData testPluginData6 = TestPluginData.builder()// + .addPluginDependency(simplePluginIdA)// + .addTestActorPlan("actor", testActorPlan1)// + .addTestDataManagerPlan("dm", testDataManagerPlan1)// + .addTestDataManager("dm", supplier2)// + .build(); assertNotEquals(testPluginData1, testPluginData6); } @@ -578,8 +619,7 @@ public void testEquals() { @UnitTestMethod(target = TestPluginData.class, name = "hashCode", args = {}) public void testHashCode() { /* - * Show that equal objects have equal hash codes over a few example - * cases + * Show that equal objects have equal hash codes over a few example cases */ SimplePluginId simplePluginIdA = new SimplePluginId("A"); @@ -595,58 +635,58 @@ public void testHashCode() { TestDataManagerPlan testDataManagerPlan2 = new TestDataManagerPlan(0, (c) -> { }); - TestPluginData testPluginData1 = TestPluginData .builder()// - .addPluginDependency(simplePluginIdA)// - .addTestActorPlan("actor", testActorPlan1)// - .addTestDataManagerPlan("dm", testDataManagerPlan1)// - .addTestDataManager("dm", supplier1)// - .build(); + TestPluginData testPluginData1 = TestPluginData.builder()// + .addPluginDependency(simplePluginIdA)// + .addTestActorPlan("actor", testActorPlan1)// + .addTestDataManagerPlan("dm", testDataManagerPlan1)// + .addTestDataManager("dm", supplier1)// + .build(); // identical inputs - TestPluginData testPluginData2 = TestPluginData .builder()// - .addPluginDependency(simplePluginIdA)// - .addTestActorPlan("actor", testActorPlan1)// - .addTestDataManagerPlan("dm", testDataManagerPlan1)// - .addTestDataManager("dm", supplier1)// - .build(); + TestPluginData testPluginData2 = TestPluginData.builder()// + .addPluginDependency(simplePluginIdA)// + .addTestActorPlan("actor", testActorPlan1)// + .addTestDataManagerPlan("dm", testDataManagerPlan1)// + .addTestDataManager("dm", supplier1)// + .build(); assertEquals(testPluginData1.hashCode(), testPluginData2.hashCode()); testPluginData1 = TestPluginData.builder()// - .addPluginDependency(simplePluginIdA)// - .addPluginDependency(simplePluginIdB)// - .addTestActorPlan("actor", testActorPlan2)// - .addTestDataManagerPlan("dm", testDataManagerPlan1)// - .addTestDataManager("dm", supplier2)// - .build(); + .addPluginDependency(simplePluginIdA)// + .addPluginDependency(simplePluginIdB)// + .addTestActorPlan("actor", testActorPlan2)// + .addTestDataManagerPlan("dm", testDataManagerPlan1)// + .addTestDataManager("dm", supplier2)// + .build(); testPluginData2 = TestPluginData.builder()// - .addPluginDependency(simplePluginIdA)// - .addPluginDependency(simplePluginIdB)// - .addTestActorPlan("actor", testActorPlan2)// - .addTestDataManagerPlan("dm", testDataManagerPlan1)// - .addTestDataManager("dm", supplier2)// - .build(); + .addPluginDependency(simplePluginIdA)// + .addPluginDependency(simplePluginIdB)// + .addTestActorPlan("actor", testActorPlan2)// + .addTestDataManagerPlan("dm", testDataManagerPlan1)// + .addTestDataManager("dm", supplier2)// + .build(); assertEquals(testPluginData1.hashCode(), testPluginData2.hashCode()); testPluginData1 = TestPluginData.builder()// - .addPluginDependency(simplePluginIdA)// - .addPluginDependency(simplePluginIdB)// - .addTestActorPlan("actor", testActorPlan1)// - .addTestActorPlan("actor", testActorPlan2)// - .addTestDataManagerPlan("dm", testDataManagerPlan2)// - .addTestDataManager("dm", supplier2)// - .build(); + .addPluginDependency(simplePluginIdA)// + .addPluginDependency(simplePluginIdB)// + .addTestActorPlan("actor", testActorPlan1)// + .addTestActorPlan("actor", testActorPlan2)// + .addTestDataManagerPlan("dm", testDataManagerPlan2)// + .addTestDataManager("dm", supplier2)// + .build(); testPluginData2 = TestPluginData.builder()// - .addPluginDependency(simplePluginIdA)// - .addPluginDependency(simplePluginIdB)// - .addTestActorPlan("actor", testActorPlan1)// - .addTestActorPlan("actor", testActorPlan2)// - .addTestDataManagerPlan("dm", testDataManagerPlan2)// - .addTestDataManager("dm", supplier2)// - .build(); + .addPluginDependency(simplePluginIdA)// + .addPluginDependency(simplePluginIdB)// + .addTestActorPlan("actor", testActorPlan1)// + .addTestActorPlan("actor", testActorPlan2)// + .addTestDataManagerPlan("dm", testDataManagerPlan2)// + .addTestDataManager("dm", supplier2)// + .build(); assertEquals(testPluginData1.hashCode(), testPluginData2.hashCode()); diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/globalproperties/datamanagers/AT_GlobalPropertiesPluginData.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/globalproperties/datamanagers/AT_GlobalPropertiesPluginData.java index 573c63738..c84730899 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/globalproperties/datamanagers/AT_GlobalPropertiesPluginData.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/globalproperties/datamanagers/AT_GlobalPropertiesPluginData.java @@ -18,8 +18,6 @@ import org.apache.commons.math3.random.RandomGenerator; import org.junit.jupiter.api.Test; -import gov.hhs.aspr.ms.gcm.nucleus.PluginData; -import gov.hhs.aspr.ms.gcm.nucleus.PluginDataBuilder; import gov.hhs.aspr.ms.gcm.plugins.globalproperties.support.GlobalPropertyId; import gov.hhs.aspr.ms.gcm.plugins.globalproperties.support.SimpleGlobalPropertyId; import gov.hhs.aspr.ms.gcm.plugins.globalproperties.testsupport.TestGlobalPropertyId; @@ -31,928 +29,939 @@ public class AT_GlobalPropertiesPluginData { - @Test - @UnitTestMethod(target = GlobalPropertiesPluginData.Builder.class, name = "build", args = {}) - public void testBuild() { - - GlobalPropertiesPluginData globalInitialData = GlobalPropertiesPluginData.builder().build(); - assertNotNull(globalInitialData); - - PropertyDefinition propertyDefinition = PropertyDefinition.builder().setType(Integer.class).setDefaultValue(34) - .build(); - GlobalPropertyId globalPropertyId1 = new SimpleGlobalPropertyId("id 1"); - GlobalPropertyId globalPropertyId2 = new SimpleGlobalPropertyId("id 2"); - - // show that the builder clears its contents on build - GlobalPropertiesPluginData.Builder builder = GlobalPropertiesPluginData.builder();// - builder.defineGlobalProperty(globalPropertyId1, propertyDefinition, 0)// - .build(); - - builder = GlobalPropertiesPluginData.builder();// - GlobalPropertiesPluginData globalPropertiesPluginData = builder.build(); - assertTrue(globalPropertiesPluginData.getGlobalPropertyIds().isEmpty()); - - /* - * precondition test: if a global property value was associated with a global - * property id that was not defined - */ - - ContractException contractException = assertThrows(ContractException.class, () -> { - GlobalPropertiesPluginData.builder()// - .defineGlobalProperty(globalPropertyId1, propertyDefinition, 0)// - .setGlobalPropertyValue(globalPropertyId2, 67, 0)// - .build(); - }); - assertEquals(PropertyError.UNKNOWN_PROPERTY_ID, contractException.getErrorType()); - - /* - * precondition test: if a global property value was associated with a global - * property id that is incompatible with the corresponding property definition. - */ - - contractException = assertThrows(ContractException.class, () -> { - GlobalPropertiesPluginData.builder()// - .defineGlobalProperty(globalPropertyId1, propertyDefinition, 0)// - .setGlobalPropertyValue(globalPropertyId1, "bad value", 0)// - .build(); - }); - assertEquals(PropertyError.INCOMPATIBLE_VALUE, contractException.getErrorType()); - - /* - * precondition test: if a global property time is less than the corresponding - * property definition creation time. - */ - - contractException = assertThrows(ContractException.class, () -> { - GlobalPropertiesPluginData.builder()// - .defineGlobalProperty(globalPropertyId1, propertyDefinition, 3.6)// - .setGlobalPropertyValue(globalPropertyId1, 12, 2.2)// - .build(); - }); - assertEquals(PropertyError.INCOMPATIBLE_TIME, contractException.getErrorType()); - - /* - * precondition test: if a global property definition has no default value and - * there is also no corresponding property value assignment. - */ - contractException = assertThrows(ContractException.class, () -> { - GlobalPropertiesPluginData.builder()// - .defineGlobalProperty(globalPropertyId1, - PropertyDefinition.builder().setType(Integer.class).build(), 0)// - .build(); - }); - assertEquals(PropertyError.INSUFFICIENT_PROPERTY_VALUE_ASSIGNMENT, contractException.getErrorType()); - - } - - @Test - @UnitTestMethod(target = GlobalPropertiesPluginData.Builder.class, name = "defineGlobalProperty", args = { - GlobalPropertyId.class, PropertyDefinition.class, double.class }) - public void testDefineGlobalProperty() { - GlobalPropertiesPluginData.Builder builder = GlobalPropertiesPluginData.builder(); - - // create a container to hold the expected property definitions - Map expectedPropertyDefinitions = new LinkedHashMap<>(); - Map expectedPropertyDefinitionCreationTimes = new LinkedHashMap<>(); - - // define a few global properties - PropertyDefinition propertyDefinition = PropertyDefinition.builder().setType(Integer.class).setDefaultValue(34) - .build(); - PropertyDefinition propertyDefinition2 = PropertyDefinition.builder().setType(Integer.class).setDefaultValue(57) - .build(); - GlobalPropertyId globalPropertyId = new SimpleGlobalPropertyId("id 1"); - builder.defineGlobalProperty(globalPropertyId, propertyDefinition2, 2.5); - // replacing data to show that the value persists - builder.defineGlobalProperty(globalPropertyId, propertyDefinition, 0); - // adding duplicate data to show that the value persists - builder.defineGlobalProperty(globalPropertyId, propertyDefinition, 3.4); - expectedPropertyDefinitions.put(globalPropertyId, propertyDefinition); - expectedPropertyDefinitionCreationTimes.put(globalPropertyId, 3.4); - - propertyDefinition = PropertyDefinition.builder().setType(Double.class).setDefaultValue(234.34).build(); - propertyDefinition2 = PropertyDefinition.builder().setType(Double.class).setDefaultValue(795.88).build(); - globalPropertyId = new SimpleGlobalPropertyId("id 2"); - builder.defineGlobalProperty(globalPropertyId, propertyDefinition2, 2.0); - // replacing data to show that the value persists - builder.defineGlobalProperty(globalPropertyId, propertyDefinition, 2.9); - // adding duplicate data to show that the value persists - builder.defineGlobalProperty(globalPropertyId, propertyDefinition, 3.1); - expectedPropertyDefinitions.put(globalPropertyId, propertyDefinition); - expectedPropertyDefinitionCreationTimes.put(globalPropertyId, 3.1); - - propertyDefinition = PropertyDefinition.builder().setType(String.class).setDefaultValue("default value") - .build(); - propertyDefinition2 = PropertyDefinition.builder().setType(String.class).setDefaultValue("second default") - .build(); - globalPropertyId = new SimpleGlobalPropertyId("id 3"); - builder.defineGlobalProperty(globalPropertyId, propertyDefinition2, 0.5); - // replacing data to show that the value persists - builder.defineGlobalProperty(globalPropertyId, propertyDefinition, 6.8); - // adding duplicate data to show that the value persists - builder.defineGlobalProperty(globalPropertyId, propertyDefinition, 2.1); - expectedPropertyDefinitions.put(globalPropertyId, propertyDefinition); - expectedPropertyDefinitionCreationTimes.put(globalPropertyId, 2.1); - - // build the initial data - GlobalPropertiesPluginData globalInitialData = builder.build(); - - // show that the expected property ids are there - Set actualGlobalPropertyIds = globalInitialData.getGlobalPropertyIds(); - Set expectedGlobalPropertyIds = expectedPropertyDefinitions.keySet(); - assertEquals(expectedGlobalPropertyIds, actualGlobalPropertyIds); - - // show that the property definitions are retrieved by their ids - for (GlobalPropertyId gpid : expectedPropertyDefinitions.keySet()) { - PropertyDefinition expectedPropertyDefinition = expectedPropertyDefinitions.get(gpid); - PropertyDefinition actualPropertyDefinition = globalInitialData.getGlobalPropertyDefinition(gpid); - assertEquals(expectedPropertyDefinition, actualPropertyDefinition); - } - - // show that the property creation times are correct - for (GlobalPropertyId gpid : expectedPropertyDefinitionCreationTimes.keySet()) { - Double expectedTime = expectedPropertyDefinitionCreationTimes.get(gpid); - Double actualTime = globalInitialData.getGlobalPropertyDefinitionTime(gpid); - assertEquals(expectedTime, actualTime); - } - - // precondition tests - - // if the global property id is null - PropertyDefinition propDef = PropertyDefinition.builder().setType(Integer.class).setDefaultValue(17).build(); - ContractException contractException = assertThrows(ContractException.class, - () -> builder.defineGlobalProperty(null, propDef, 0)); - assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); - - // if the property definition is null - contractException = assertThrows(ContractException.class, - () -> builder.defineGlobalProperty(new SimpleGlobalPropertyId("id"), null, 0)); - assertEquals(PropertyError.NULL_PROPERTY_DEFINITION, contractException.getErrorType()); - - } - - @Test - @UnitTestMethod(target = GlobalPropertiesPluginData.Builder.class, name = "setGlobalPropertyValue", args = { - GlobalPropertyId.class, Object.class, double.class }) - public void testSetGlobalPropertyValue() { - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(170390875787254562L); - - GlobalPropertiesPluginData.Builder builder = GlobalPropertiesPluginData.builder(); - - // show there are some properties in the support enum - assertTrue(TestGlobalPropertyId.values().length > 0); - - // define some properties - Set expectedGlobalPropertyIds = new LinkedHashSet<>(); - for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { - PropertyDefinition propertyDefinition = PropertyDefinition.builder().setType(Integer.class) - .setDefaultValue(0).build(); - builder.defineGlobalProperty(testGlobalPropertyId, propertyDefinition, 0); - expectedGlobalPropertyIds.add(testGlobalPropertyId); - } - // create a container for the expected values of the properties - Map expectedValues = new LinkedHashMap<>(); - Map expectedTimes = new LinkedHashMap<>(); - - // set the values - boolean useProperty = true; - for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { - if (useProperty) { - int value = randomGenerator.nextInt(); - int value2 = randomGenerator.nextInt(); - double time = randomGenerator.nextDouble(); - builder.setGlobalPropertyValue(testGlobalPropertyId, value2, time); - // replacing data to show that the value persists - time = randomGenerator.nextDouble(); - builder.setGlobalPropertyValue(testGlobalPropertyId, value, time); - // duplicating data to show that the value persists - time = randomGenerator.nextDouble(); - builder.setGlobalPropertyValue(testGlobalPropertyId, value, time); - expectedValues.put(testGlobalPropertyId, value); - expectedTimes.put(testGlobalPropertyId, time); - } - useProperty = !useProperty; - } - - // build the initial data - GlobalPropertiesPluginData globalInitialData = builder.build(); - - // show that the expected property ids are there - Set actualGlobalPropertyIds = globalInitialData.getGlobalPropertyIds(); - - assertEquals(expectedGlobalPropertyIds, actualGlobalPropertyIds); - - // show that the expected values are present - for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { - Object expectedValue = expectedValues.get(testGlobalPropertyId); - Optional optionalValue = globalInitialData.getGlobalPropertyValue(testGlobalPropertyId); - - if (expectedValue == null) { - assertFalse(optionalValue.isPresent()); - } else { - assertTrue(optionalValue.isPresent()); - Object actualValue = optionalValue.get(); - assertEquals(expectedValue, actualValue); - } - } - - // show that the expected times are present - for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { - Double expectedTime = expectedTimes.get(testGlobalPropertyId); - Optional optionalTime = globalInitialData.getGlobalPropertyTime(testGlobalPropertyId); - - if (expectedTime == null) { - assertFalse(optionalTime.isPresent()); - } else { - assertTrue(optionalTime.isPresent()); - Double actualTime = optionalTime.get(); - assertEquals(expectedTime, actualTime); - } - } - - /* - * precondition tests -- Note that invalid values are not covered here. The - * build() validates the values to see if they are compatible with the - * corresponding definitions. - */ - - // if the global property id is null - ContractException contractException = assertThrows(ContractException.class, - () -> builder.setGlobalPropertyValue(null, 5, 0)); - assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); - - // if the global property value is null - contractException = assertThrows(ContractException.class, - () -> builder.setGlobalPropertyValue(TestGlobalPropertyId.GLOBAL_PROPERTY_1_BOOLEAN_MUTABLE, null, 0)); - assertEquals(PropertyError.NULL_PROPERTY_VALUE, contractException.getErrorType()); - - } - - @Test - @UnitTestMethod(target = GlobalPropertiesPluginData.class, name = "builder", args = {}) - public void testBuilder() { - // show that the builder can be created - assertNotNull(GlobalPropertiesPluginData.builder()); - } - - @Test - @UnitTestMethod(target = GlobalPropertiesPluginData.class, name = "getGlobalPropertyDefinition", args = { - GlobalPropertyId.class }) - public void testGetGlobalPropertyDefinition() { - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(5427251266091264753L); - - GlobalPropertiesPluginData.Builder builder = GlobalPropertiesPluginData.builder(); - - // show there are some properties in the support enum - assertTrue(TestGlobalPropertyId.values().length > 0); - - // create a container for the expected values of the properties - Map expectedGlobalPropertyDefinitions = new LinkedHashMap<>(); - Map expectedGlobalPropertyDefinitionTimes = new LinkedHashMap<>(); - - // define some properties - - for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { - PropertyDefinition propertyDefinition = PropertyDefinition.builder().setType(Integer.class) - .setDefaultValue(0).build(); - double time = randomGenerator.nextDouble(); - builder.defineGlobalProperty(testGlobalPropertyId, propertyDefinition, time); - expectedGlobalPropertyDefinitions.put(testGlobalPropertyId, propertyDefinition); - expectedGlobalPropertyDefinitionTimes.put(testGlobalPropertyId, time); - } - - // show that the expected property definitions are present - GlobalPropertiesPluginData globalInitialData = builder.build(); - - for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { - PropertyDefinition expectedPropertyDefinition = expectedGlobalPropertyDefinitions.get(testGlobalPropertyId); - PropertyDefinition actualPropertyDefinition = globalInitialData - .getGlobalPropertyDefinition(testGlobalPropertyId); - assertEquals(expectedPropertyDefinition, actualPropertyDefinition); - - Double expetedTime = expectedGlobalPropertyDefinitionTimes.get(testGlobalPropertyId); - Double actualTime = globalInitialData.getGlobalPropertyDefinitionTime(testGlobalPropertyId); - assertEquals(expetedTime, actualTime); - - } - - // precondition tests - ContractException contractException = assertThrows(ContractException.class, - () -> globalInitialData.getGlobalPropertyDefinition(null)); - assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); - - contractException = assertThrows(ContractException.class, - () -> globalInitialData.getGlobalPropertyDefinition(TestGlobalPropertyId.getUnknownGlobalPropertyId())); - assertEquals(PropertyError.UNKNOWN_PROPERTY_ID, contractException.getErrorType()); - - } - - @Test - @UnitTestMethod(target = GlobalPropertiesPluginData.class, name = "getGlobalPropertyDefinitions", args = {}) - public void testGetGlobalPropertyDefinitions() { - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(5427251266091264753L); - - GlobalPropertiesPluginData.Builder builder = GlobalPropertiesPluginData.builder(); - - // show there are some properties in the support enum - assertTrue(TestGlobalPropertyId.values().length > 0); - - // create a container for the expected values of the properties - Map expectedGlobalPropertyDefinitions = new LinkedHashMap<>(); - - // define some properties - - for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { - PropertyDefinition propertyDefinition = PropertyDefinition.builder().setType(Integer.class) - .setDefaultValue(0).build(); - double time = randomGenerator.nextDouble(); - builder.defineGlobalProperty(testGlobalPropertyId, propertyDefinition, time); - expectedGlobalPropertyDefinitions.put(testGlobalPropertyId, propertyDefinition); - } - - // show that the expected property definitions are present - GlobalPropertiesPluginData globalInitialData = builder.build(); - - assertEquals(expectedGlobalPropertyDefinitions, globalInitialData.getGlobalPropertyDefinitions()); - } - - @Test - @UnitTestMethod(target = GlobalPropertiesPluginData.class, name = "getGlobalPropertyDefinitionTimes", args = {}) - public void testGetGlobalPropertyDefinitionTimes() { - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(5427251266091264753L); - - GlobalPropertiesPluginData.Builder builder = GlobalPropertiesPluginData.builder(); - - // show there are some properties in the support enum - assertTrue(TestGlobalPropertyId.values().length > 0); - - // create a container for the expected values of the properties - Map expectedGlobalPropertyDefinitionTimes = new LinkedHashMap<>(); - - // define some properties - - for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { - PropertyDefinition propertyDefinition = PropertyDefinition.builder().setType(Integer.class) - .setDefaultValue(0).build(); - double time = randomGenerator.nextDouble(); - builder.defineGlobalProperty(testGlobalPropertyId, propertyDefinition, time); - expectedGlobalPropertyDefinitionTimes.put(testGlobalPropertyId, time); - } - - // show that the expected property definitions are present - GlobalPropertiesPluginData globalInitialData = builder.build(); - - assertEquals(expectedGlobalPropertyDefinitionTimes, globalInitialData.getGlobalPropertyDefinitionTimes()); - } - - @Test - @UnitTestMethod(target = GlobalPropertiesPluginData.class, name = "getGlobalPropertyIds", args = {}) - public void testGetGlobalPropertyIds() { - - GlobalPropertiesPluginData.Builder builder = GlobalPropertiesPluginData.builder(); - - // show there are some properties in the support enum - assertTrue(TestGlobalPropertyId.values().length > 0); - - // create a container for the expected values of the properties - Set expectedGlobalPropertyIds = new LinkedHashSet<>(); - - // define some properties - - for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { - PropertyDefinition propertyDefinition = PropertyDefinition.builder()// - .setType(Integer.class)// - .setDefaultValue(0)// - .build(); - builder.defineGlobalProperty(testGlobalPropertyId, propertyDefinition, 0); - expectedGlobalPropertyIds.add(testGlobalPropertyId); - } - - // show that the expected values are present - GlobalPropertiesPluginData globalInitialData = builder.build(); - assertEquals(expectedGlobalPropertyIds, globalInitialData.getGlobalPropertyIds()); - } - - @Test - @UnitTestMethod(target = GlobalPropertiesPluginData.class, name = "getGlobalPropertyValue", args = { - GlobalPropertyId.class }) - public void testGetGlobalPropertyValue() { - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(4250048639082754761L); - - GlobalPropertiesPluginData.Builder builder = GlobalPropertiesPluginData.builder(); - - // show there are some properties in the support enum - assertTrue(TestGlobalPropertyId.values().length > 0); - - // define some properties - for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { - PropertyDefinition propertyDefinition = PropertyDefinition.builder().setType(Integer.class) - .setDefaultValue(0).build(); - builder.defineGlobalProperty(testGlobalPropertyId, propertyDefinition, 0); - } - // create a container for the expected values of the properties - Map expectedValues = new LinkedHashMap<>(); - - // set about half of the values - boolean shouldSetValue = true; - for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { - if (shouldSetValue) { - int value = randomGenerator.nextInt(); - builder.setGlobalPropertyValue(testGlobalPropertyId, value, 0); - expectedValues.put(testGlobalPropertyId, value); - } - shouldSetValue = !shouldSetValue; - } - - // show that the expected values are present - GlobalPropertiesPluginData globalPropertiesPluginData = builder.build(); - for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { - Object expectedValue = expectedValues.get(testGlobalPropertyId); - Optional optionalValue = globalPropertiesPluginData.getGlobalPropertyValue(testGlobalPropertyId); - if (expectedValue == null) { - assertFalse(optionalValue.isPresent()); - } else { - assertTrue(optionalValue.isPresent()); - Object actualValue = optionalValue.get(); - assertEquals(expectedValue, actualValue); - } - } - - /* - * precondition tests -- Note that invalid values are not covered here. The - * build() validates the values to see if they are compatible with the - * corresponding definitions. - */ - - // if the global property id is null - ContractException contractException = assertThrows(ContractException.class, - () -> globalPropertiesPluginData.getGlobalPropertyValue(null)); - assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); - - // if the global property value is null - contractException = assertThrows(ContractException.class, () -> globalPropertiesPluginData - .getGlobalPropertyValue(TestGlobalPropertyId.getUnknownGlobalPropertyId())); - assertEquals(PropertyError.UNKNOWN_PROPERTY_ID, contractException.getErrorType()); - - } - - @Test - @UnitTestMethod(target = GlobalPropertiesPluginData.class, name = "getGlobalPropertyValues", args = {}) - public void testGetGlobalPropertyValues() { - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(4250048639082754761L); - - GlobalPropertiesPluginData.Builder builder = GlobalPropertiesPluginData.builder(); - - // show there are some properties in the support enum - assertTrue(TestGlobalPropertyId.values().length > 0); - - // define some properties - for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { - PropertyDefinition propertyDefinition = PropertyDefinition.builder().setType(Integer.class) - .setDefaultValue(0).build(); - builder.defineGlobalProperty(testGlobalPropertyId, propertyDefinition, 0); - } - // create a container for the expected values of the properties - Map expectedValues = new LinkedHashMap<>(); - - // set about half of the values - boolean shouldSetValue = true; - for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { - if (shouldSetValue) { - int value = randomGenerator.nextInt(); - builder.setGlobalPropertyValue(testGlobalPropertyId, value, 0); - expectedValues.put(testGlobalPropertyId, value); - } - shouldSetValue = !shouldSetValue; - } - - GlobalPropertiesPluginData globalPropertiesPluginData = builder.build(); - - assertEquals(expectedValues, globalPropertiesPluginData.getGlobalPropertyValues()); - } - - @Test - @UnitTestMethod(target = GlobalPropertiesPluginData.class, name = "getCloneBuilder", args = {}) - public void testGetCloneBuilder() { - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(9113503089361379130L); - GlobalPropertiesPluginData.Builder builder = GlobalPropertiesPluginData.builder(); - - for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { - double time = randomGenerator.nextDouble(); - builder.defineGlobalProperty(testGlobalPropertyId, testGlobalPropertyId.getPropertyDefinition(), time); - time += randomGenerator.nextDouble(); - builder.setGlobalPropertyValue(testGlobalPropertyId, - testGlobalPropertyId.getRandomPropertyValue(randomGenerator), time); - } - - GlobalPropertiesPluginData globalPropertiesPluginData = builder.build(); - PluginDataBuilder cloneBuilder = globalPropertiesPluginData.getCloneBuilder(); - assertNotNull(cloneBuilder); - PluginData pluginData = cloneBuilder.build(); - assertTrue(pluginData instanceof GlobalPropertiesPluginData); - GlobalPropertiesPluginData cloneGlobalPropertiesPluginData = (GlobalPropertiesPluginData) pluginData; - - assertEquals(globalPropertiesPluginData, cloneGlobalPropertiesPluginData); - - } - - @Test - @UnitTestMethod(target = GlobalPropertiesPluginData.class, name = "getGlobalPropertyDefinitionTime", args = { - GlobalPropertyId.class }) - public void testGetGlobalPropertyDefinitionTime() { - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(5487507072126661304L); - - GlobalPropertiesPluginData.Builder builder = GlobalPropertiesPluginData.builder(); - - // show there are some properties in the support enum - assertTrue(TestGlobalPropertyId.values().length > 0); - - // create a container for the expected values of the properties - Map expectedGlobalPropertyDefinitions = new LinkedHashMap<>(); - Map expectedGlobalPropertyDefinitionTimes = new LinkedHashMap<>(); - - // define some properties - - for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { - PropertyDefinition propertyDefinition = PropertyDefinition.builder().setType(Integer.class) - .setDefaultValue(0).build(); - double time = randomGenerator.nextDouble(); - builder.defineGlobalProperty(testGlobalPropertyId, propertyDefinition, time); - expectedGlobalPropertyDefinitions.put(testGlobalPropertyId, propertyDefinition); - expectedGlobalPropertyDefinitionTimes.put(testGlobalPropertyId, time); - } - - // show that the expected property definitions are present - GlobalPropertiesPluginData globalInitialData = builder.build(); - - for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { - PropertyDefinition expectedPropertyDefinition = expectedGlobalPropertyDefinitions.get(testGlobalPropertyId); - PropertyDefinition actualPropertyDefinition = globalInitialData - .getGlobalPropertyDefinition(testGlobalPropertyId); - assertEquals(expectedPropertyDefinition, actualPropertyDefinition); - - Double expetedTime = expectedGlobalPropertyDefinitionTimes.get(testGlobalPropertyId); - Double actualTime = globalInitialData.getGlobalPropertyDefinitionTime(testGlobalPropertyId); - assertEquals(expetedTime, actualTime); - - } - - // precondition tests - ContractException contractException = assertThrows(ContractException.class, - () -> globalInitialData.getGlobalPropertyDefinition(null)); - assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); - - contractException = assertThrows(ContractException.class, - () -> globalInitialData.getGlobalPropertyDefinition(TestGlobalPropertyId.getUnknownGlobalPropertyId())); - assertEquals(PropertyError.UNKNOWN_PROPERTY_ID, contractException.getErrorType()); - - } - - @Test - @UnitTestMethod(target = GlobalPropertiesPluginData.class, name = "getGlobalPropertyTime", args = { - GlobalPropertyId.class }) - public void testGetGlobalPropertyTime() { - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(4250048639082754761L); - - GlobalPropertiesPluginData.Builder builder = GlobalPropertiesPluginData.builder(); - - // show there are some properties in the support enum - assertTrue(TestGlobalPropertyId.values().length > 0); - - // define some properties -- note that we do not set default values to - // test that the values provided explicitly will properly replace the - // default values. - for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { - PropertyDefinition propertyDefinition = PropertyDefinition.builder()// - .setType(Integer.class)// - .setDefaultValue(0)// - .build(); - builder.defineGlobalProperty(testGlobalPropertyId, propertyDefinition, 0.0); - } - // create a container for the expected values of the properties - Map expectedTimes = new LinkedHashMap<>(); - - // set the times for half of the properties - int counter = 0; - for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { - if (counter % 2 == 0) { - int value = randomGenerator.nextInt(); - double time = randomGenerator.nextDouble() + 0.1; - builder.setGlobalPropertyValue(testGlobalPropertyId, value, time); - expectedTimes.put(testGlobalPropertyId, time); - } - counter++; - } - - // show that the expected times are present - GlobalPropertiesPluginData globalPropertiesPluginData = builder.build(); - for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { - Double expectedTime = expectedTimes.get(testGlobalPropertyId); - Optional optionalTime = globalPropertiesPluginData.getGlobalPropertyTime(testGlobalPropertyId); - if (expectedTime == null) { - assertFalse(optionalTime.isPresent()); - } else { - assertTrue(optionalTime.isPresent()); - Double actualTime = optionalTime.get(); - assertEquals(expectedTime, actualTime); - } - } - - /* - * precondition tests -- Note that invalid values are not covered here. The - * build() validates the values to see if they are compatible with the - * corresponding definitions. - */ - - // if the global property id is null - ContractException contractException = assertThrows(ContractException.class, - () -> globalPropertiesPluginData.getGlobalPropertyValue(null)); - assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); - - // if the global property value is null - contractException = assertThrows(ContractException.class, () -> globalPropertiesPluginData - .getGlobalPropertyValue(TestGlobalPropertyId.getUnknownGlobalPropertyId())); - assertEquals(PropertyError.UNKNOWN_PROPERTY_ID, contractException.getErrorType()); - - } - - @Test - @UnitTestMethod(target = GlobalPropertiesPluginData.class, name = "getGlobalPropertyTimes", args = {}) - public void testGetGlobalPropertyTimes() { - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(4250048639082754761L); - - GlobalPropertiesPluginData.Builder builder = GlobalPropertiesPluginData.builder(); - - // show there are some properties in the support enum - assertTrue(TestGlobalPropertyId.values().length > 0); - - // define some properties -- note that we do not set default values to - // test that the values provided explicitly will properly replace the - // default values. - for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { - PropertyDefinition propertyDefinition = PropertyDefinition.builder()// - .setType(Integer.class)// - .setDefaultValue(0)// - .build(); - builder.defineGlobalProperty(testGlobalPropertyId, propertyDefinition, 0.0); - } - // create a container for the expected values of the properties - Map expectedTimes = new LinkedHashMap<>(); - - // set the times for half of the properties - int counter = 0; - for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { - if (counter % 2 == 0) { - int value = randomGenerator.nextInt(); - double time = randomGenerator.nextDouble() + 0.1; - builder.setGlobalPropertyValue(testGlobalPropertyId, value, time); - expectedTimes.put(testGlobalPropertyId, time); - } - counter++; - } - - // show that the expected times are present - GlobalPropertiesPluginData globalPropertiesPluginData = builder.build(); - - assertEquals(expectedTimes, globalPropertiesPluginData.getGlobalPropertyTimes()); - } - - @Test - @UnitTestMethod(target = GlobalPropertiesPluginData.class, name = "equals", args = { Object.class }) - public void testEquals() { - // we first set up a few items that will clarify the production of - // plugin datas - - Object v_5 = 5; - Object v_12 = 12; - Object v_25 = 15; - Object v_a = "a"; - Object v_b = "b"; - - GlobalPropertyId p1 = TestGlobalPropertyId.getUnknownGlobalPropertyId(); - GlobalPropertyId p2 = TestGlobalPropertyId.getUnknownGlobalPropertyId(); - - PropertyDefinition d1 = PropertyDefinition.builder()// - .setType(Integer.class)// - .setDefaultValue(v_5)// - .build(); - - PropertyDefinition d2 = PropertyDefinition.builder()// - .setType(String.class)// - .setDefaultValue(v_a)// - .build(); - - Double t_0 = 0.0; - Double t_1 = 1.0; - Double t_2 = 2.0; - - // just a single definition -- this will act as our base case - GlobalPropertiesPluginData g1 = GlobalPropertiesPluginData.builder()// - .defineGlobalProperty(p1, d1, t_0)// - .build(); - - // set the property value that has the same time and value as the - // property definition - GlobalPropertiesPluginData g2 = GlobalPropertiesPluginData.builder()// - .defineGlobalProperty(p1, d1, t_0)// - .setGlobalPropertyValue(p1, v_5, t_0)// - .build(); - - GlobalPropertiesPluginData g3 = GlobalPropertiesPluginData.builder()// - .setGlobalPropertyValue(p1, v_5, t_0)// - .defineGlobalProperty(p1, d1, t_0)// - .build(); - - // change the value of the property - GlobalPropertiesPluginData g4 = GlobalPropertiesPluginData.builder()// - .defineGlobalProperty(p1, d1, t_0)// - .setGlobalPropertyValue(p1, v_25, t_0)// - .build(); - - // change the time of the property - GlobalPropertiesPluginData g5 = GlobalPropertiesPluginData.builder()// - .defineGlobalProperty(p1, d1, t_0)// - .setGlobalPropertyValue(p1, v_5, t_1)// - .build(); - - // introduce a new property definition - GlobalPropertiesPluginData g6 = GlobalPropertiesPluginData.builder()// - .defineGlobalProperty(p1, d1, t_0)// - .defineGlobalProperty(p2, d2, t_1)// - .build(); - - // add several values and definitions - GlobalPropertiesPluginData g7 = GlobalPropertiesPluginData.builder()// - .defineGlobalProperty(p1, d1, t_0)// - .defineGlobalProperty(p2, d2, t_1)// - .setGlobalPropertyValue(p1, v_25, t_2)// - .setGlobalPropertyValue(p2, v_b, t_2)// - .setGlobalPropertyValue(p1, v_12, t_1)// - .build(); - - // add the same details, but in a different order, preserving the last - // assignments - GlobalPropertiesPluginData g8 = GlobalPropertiesPluginData.builder()// - .setGlobalPropertyValue(p1, v_25, t_2)// - .defineGlobalProperty(p2, d2, t_1)// - .defineGlobalProperty(p1, d1, t_0)// - .setGlobalPropertyValue(p1, v_12, t_1)// - .setGlobalPropertyValue(p2, v_b, t_2)// - .build(); - - // reflexive - assertEquals(g1, g1); - assertEquals(g2, g2); - assertEquals(g4, g4); - assertEquals(g5, g5); - assertEquals(g6, g6); - assertEquals(g7, g7); - assertEquals(g8, g8); - - // symmetric and transitive - - assertEquals(g2, g3); - assertEquals(g3, g2); - - // non-equality from small changes - assertNotEquals(g1, g2); - assertNotEquals(g1, g3); - assertNotEquals(g1, g4); - assertNotEquals(g1, g5); - assertNotEquals(g1, g6); - - // ordering of action should have no effect - assertEquals(g7, g8); - - } - - @Test - @UnitTestMethod(target = GlobalPropertiesPluginData.class, name = "hashCode", args = {}) - public void testHashCode() { - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(2653491508465183354L); - Object v_5 = 5; - Object v_12 = 12; - Object v_25 = 15; - Object v_a = "a"; - Object v_b = "b"; - - GlobalPropertyId p1 = TestGlobalPropertyId.getUnknownGlobalPropertyId(); - GlobalPropertyId p2 = TestGlobalPropertyId.getUnknownGlobalPropertyId(); - - PropertyDefinition d1 = PropertyDefinition.builder()// - .setType(Integer.class)// - .setDefaultValue(v_5)// - .build(); - - PropertyDefinition d2 = PropertyDefinition.builder()// - .setType(String.class)// - .setDefaultValue(v_a)// - .build(); - - Double t_0 = 0.0; - Double t_1 = 1.0; - Double t_2 = 2.0; - - // equal objects have equal hash codes - // add several values and definitions - GlobalPropertiesPluginData g7 = GlobalPropertiesPluginData.builder()// - .defineGlobalProperty(p1, d1, t_0)// - .defineGlobalProperty(p2, d2, t_1)// - .setGlobalPropertyValue(p1, v_25, t_2).setGlobalPropertyValue(p2, v_b, t_2) - .setGlobalPropertyValue(p1, v_12, t_1).build(); - - // add the same details, but in a different order, preserving the last - // assignments - GlobalPropertiesPluginData g8 = GlobalPropertiesPluginData.builder()// - .setGlobalPropertyValue(p1, v_25, t_2).defineGlobalProperty(p2, d2, t_1)// - .defineGlobalProperty(p1, d1, t_0)// - .setGlobalPropertyValue(p1, v_12, t_1).setGlobalPropertyValue(p2, v_b, t_2).build(); - - assertEquals(g7, g8); - assertEquals(g7.hashCode(), g8.hashCode()); - - // hash codes are reasonably distributed - - Set hashCodes = new LinkedHashSet<>(); - for (int i = 0; i < 100; i++) { - GlobalPropertiesPluginData.Builder builder = GlobalPropertiesPluginData.builder(); - for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { - if (randomGenerator.nextBoolean()) { - double time = randomGenerator.nextDouble(); - builder.defineGlobalProperty(testGlobalPropertyId, testGlobalPropertyId.getPropertyDefinition(), - time); - - if (randomGenerator.nextBoolean() - || testGlobalPropertyId.getPropertyDefinition().getDefaultValue().isEmpty()) { - time += 0.1; - builder.setGlobalPropertyValue(testGlobalPropertyId, - testGlobalPropertyId.getRandomPropertyValue(randomGenerator), time); - } - } - } - GlobalPropertiesPluginData globalPropertiesPluginData = builder.build(); - hashCodes.add(globalPropertiesPluginData.hashCode()); - } - assertTrue(hashCodes.size() > 90); - } - - @Test - @UnitTestMethod(target = GlobalPropertiesPluginData.class, name = "toString", args = {}) - public void testToString() { - - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(8337912786649642023L); - - /* - * Demonstrate a typical example with a full string. We will add all of the - * standard test definitions in the usual order, but will only add a few of the - * property values in reverse order. Note that we will cover the #3 member which - * does not have a corresponding default value. - */ - GlobalPropertiesPluginData.Builder builder = GlobalPropertiesPluginData.builder(); - - Map definitionTimes = new LinkedHashMap<>(); - - for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { - double time = randomGenerator.nextInt(1000); - definitionTimes.put(testGlobalPropertyId, time); - builder.defineGlobalProperty(testGlobalPropertyId, testGlobalPropertyId.getPropertyDefinition(), time); - } - - List propertiesForValueSetting = new ArrayList<>(); - propertiesForValueSetting.add(TestGlobalPropertyId.GLOBAL_PROPERTY_6_DOUBLE_IMMUTABLE); - propertiesForValueSetting.add(TestGlobalPropertyId.GLOBAL_PROPERTY_3_DOUBLE_MUTABLE); - propertiesForValueSetting.add(TestGlobalPropertyId.GLOBAL_PROPERTY_1_BOOLEAN_MUTABLE); - - for (TestGlobalPropertyId testGlobalPropertyId : propertiesForValueSetting) { - double time = definitionTimes.get(testGlobalPropertyId) + randomGenerator.nextInt(100); - builder.setGlobalPropertyValue(testGlobalPropertyId, - testGlobalPropertyId.getRandomPropertyValue(randomGenerator), time); - } - - GlobalPropertiesPluginData globalPropertiesPluginData = builder.build(); - - String expectedValue = "GlobalPropertiesPluginData [data=Data [globalPropertyDefinitions" - + "={GLOBAL_PROPERTY_1_BOOLEAN_MUTABLE=PropertyDefinition [type=class java.lang.Boolean" - + ", propertyValuesAreMutable=true, defaultValue=false], GLOBAL_PROPERTY_2_INTEGER_MUTABLE" - + "=PropertyDefinition [type=class java.lang.Integer, propertyValuesAreMutable=true, " - + "defaultValue=0], GLOBAL_PROPERTY_3_DOUBLE_MUTABLE=PropertyDefinition [type=class " - + "java.lang.Double, propertyValuesAreMutable=true, defaultValue=null], " - + "GLOBAL_PROPERTY_4_BOOLEAN_IMMUTABLE=PropertyDefinition [type=class java.lang.Boolean, " - + "propertyValuesAreMutable=false, defaultValue=false], GLOBAL_PROPERTY_5_INTEGER_IMMUTABLE=" - + "PropertyDefinition [type=class java.lang.Integer, propertyValuesAreMutable=false" - + ", defaultValue=0], GLOBAL_PROPERTY_6_DOUBLE_IMMUTABLE=PropertyDefinition [type=class " - + "java.lang.Double, propertyValuesAreMutable=false, defaultValue=0.0]}, " - + "globalPropertyDefinitionTimes={GLOBAL_PROPERTY_1_BOOLEAN_MUTABLE=852.0, " - + "GLOBAL_PROPERTY_2_INTEGER_MUTABLE=835.0, GLOBAL_PROPERTY_3_DOUBLE_MUTABLE=156.0, " - + "GLOBAL_PROPERTY_4_BOOLEAN_IMMUTABLE=505.0, GLOBAL_PROPERTY_5_INTEGER_IMMUTABLE=956.0, " - + "GLOBAL_PROPERTY_6_DOUBLE_IMMUTABLE=191.0}, globalPropertyValues={" - + "GLOBAL_PROPERTY_6_DOUBLE_IMMUTABLE=0.09917206486092223, GLOBAL_PROPERTY_3_DOUBLE_MUTABLE=" - + "0.07709107250291058, GLOBAL_PROPERTY_1_BOOLEAN_MUTABLE=false}, globalPropertyTimes={" - + "GLOBAL_PROPERTY_6_DOUBLE_IMMUTABLE=255.0, GLOBAL_PROPERTY_3_DOUBLE_MUTABLE=168.0, " - + "GLOBAL_PROPERTY_1_BOOLEAN_MUTABLE=877.0}, locked=true]]"; - - String actualValue = globalPropertiesPluginData.toString(); - - assertEquals(expectedValue, actualValue); - } + @Test + @UnitTestMethod(target = GlobalPropertiesPluginData.Builder.class, name = "build", args = {}) + public void testBuild() { + + GlobalPropertiesPluginData globalInitialData = GlobalPropertiesPluginData.builder().build(); + assertNotNull(globalInitialData); + + PropertyDefinition propertyDefinition = PropertyDefinition.builder().setType(Integer.class).setDefaultValue(34) + .build(); + GlobalPropertyId globalPropertyId1 = new SimpleGlobalPropertyId("id 1"); + GlobalPropertyId globalPropertyId2 = new SimpleGlobalPropertyId("id 2"); + + // show that the builder clears its contents on build + GlobalPropertiesPluginData.Builder builder = GlobalPropertiesPluginData.builder();// + builder.defineGlobalProperty(globalPropertyId1, propertyDefinition, 0)// + .build(); + + builder = GlobalPropertiesPluginData.builder();// + GlobalPropertiesPluginData globalPropertiesPluginData = builder.build(); + assertTrue(globalPropertiesPluginData.getGlobalPropertyIds().isEmpty()); + + /* + * precondition test: if a global property value was associated with a global + * property id that was not defined + */ + + ContractException contractException = assertThrows(ContractException.class, () -> { + GlobalPropertiesPluginData.builder()// + .defineGlobalProperty(globalPropertyId1, propertyDefinition, 0)// + .setGlobalPropertyValue(globalPropertyId2, 67, 0)// + .build(); + }); + assertEquals(PropertyError.UNKNOWN_PROPERTY_ID, contractException.getErrorType()); + + /* + * precondition test: if a global property value was associated with a global + * property id that is incompatible with the corresponding property definition. + */ + + contractException = assertThrows(ContractException.class, () -> { + GlobalPropertiesPluginData.builder()// + .defineGlobalProperty(globalPropertyId1, propertyDefinition, 0)// + .setGlobalPropertyValue(globalPropertyId1, "bad value", 0)// + .build(); + }); + assertEquals(PropertyError.INCOMPATIBLE_VALUE, contractException.getErrorType()); + + /* + * precondition test: if a global property time is less than the corresponding + * property definition creation time. + */ + + contractException = assertThrows(ContractException.class, () -> { + GlobalPropertiesPluginData.builder()// + .defineGlobalProperty(globalPropertyId1, propertyDefinition, 3.6)// + .setGlobalPropertyValue(globalPropertyId1, 12, 2.2)// + .build(); + }); + assertEquals(PropertyError.INCOMPATIBLE_TIME, contractException.getErrorType()); + + /* + * precondition test: if a global property definition has no default value and + * there is also no corresponding property value assignment. + */ + contractException = assertThrows(ContractException.class, () -> { + GlobalPropertiesPluginData.builder()// + .defineGlobalProperty(globalPropertyId1, + PropertyDefinition.builder().setType(Integer.class).build(), 0)// + .build(); + }); + assertEquals(PropertyError.INSUFFICIENT_PROPERTY_VALUE_ASSIGNMENT, contractException.getErrorType()); + + } + + @Test + @UnitTestMethod(target = GlobalPropertiesPluginData.Builder.class, name = "defineGlobalProperty", args = { + GlobalPropertyId.class, PropertyDefinition.class, double.class }) + public void testDefineGlobalProperty() { + GlobalPropertiesPluginData.Builder builder = GlobalPropertiesPluginData.builder(); + + // create a container to hold the expected property definitions + Map expectedPropertyDefinitions = new LinkedHashMap<>(); + Map expectedPropertyDefinitionCreationTimes = new LinkedHashMap<>(); + + // define a few global properties + PropertyDefinition propertyDefinition = PropertyDefinition.builder().setType(Integer.class).setDefaultValue(34) + .build(); + PropertyDefinition propertyDefinition2 = PropertyDefinition.builder().setType(Integer.class).setDefaultValue(57) + .build(); + GlobalPropertyId globalPropertyId = new SimpleGlobalPropertyId("id 1"); + builder.defineGlobalProperty(globalPropertyId, propertyDefinition2, 2.5); + // replacing data to show that the value persists + builder.defineGlobalProperty(globalPropertyId, propertyDefinition, 0); + // adding duplicate data to show that the value persists + builder.defineGlobalProperty(globalPropertyId, propertyDefinition, 3.4); + expectedPropertyDefinitions.put(globalPropertyId, propertyDefinition); + expectedPropertyDefinitionCreationTimes.put(globalPropertyId, 3.4); + + propertyDefinition = PropertyDefinition.builder().setType(Double.class).setDefaultValue(234.34).build(); + propertyDefinition2 = PropertyDefinition.builder().setType(Double.class).setDefaultValue(795.88).build(); + globalPropertyId = new SimpleGlobalPropertyId("id 2"); + builder.defineGlobalProperty(globalPropertyId, propertyDefinition2, 2.0); + // replacing data to show that the value persists + builder.defineGlobalProperty(globalPropertyId, propertyDefinition, 2.9); + // adding duplicate data to show that the value persists + builder.defineGlobalProperty(globalPropertyId, propertyDefinition, 3.1); + expectedPropertyDefinitions.put(globalPropertyId, propertyDefinition); + expectedPropertyDefinitionCreationTimes.put(globalPropertyId, 3.1); + + propertyDefinition = PropertyDefinition.builder().setType(String.class).setDefaultValue("default value") + .build(); + propertyDefinition2 = PropertyDefinition.builder().setType(String.class).setDefaultValue("second default") + .build(); + globalPropertyId = new SimpleGlobalPropertyId("id 3"); + builder.defineGlobalProperty(globalPropertyId, propertyDefinition2, 0.5); + // replacing data to show that the value persists + builder.defineGlobalProperty(globalPropertyId, propertyDefinition, 6.8); + // adding duplicate data to show that the value persists + builder.defineGlobalProperty(globalPropertyId, propertyDefinition, 2.1); + expectedPropertyDefinitions.put(globalPropertyId, propertyDefinition); + expectedPropertyDefinitionCreationTimes.put(globalPropertyId, 2.1); + + // build the initial data + GlobalPropertiesPluginData globalInitialData = builder.build(); + + // show that the expected property ids are there + Set actualGlobalPropertyIds = globalInitialData.getGlobalPropertyIds(); + Set expectedGlobalPropertyIds = expectedPropertyDefinitions.keySet(); + assertEquals(expectedGlobalPropertyIds, actualGlobalPropertyIds); + + // show that the property definitions are retrieved by their ids + for (GlobalPropertyId gpid : expectedPropertyDefinitions.keySet()) { + PropertyDefinition expectedPropertyDefinition = expectedPropertyDefinitions.get(gpid); + PropertyDefinition actualPropertyDefinition = globalInitialData.getGlobalPropertyDefinition(gpid); + assertEquals(expectedPropertyDefinition, actualPropertyDefinition); + } + + // show that the property creation times are correct + for (GlobalPropertyId gpid : expectedPropertyDefinitionCreationTimes.keySet()) { + Double expectedTime = expectedPropertyDefinitionCreationTimes.get(gpid); + Double actualTime = globalInitialData.getGlobalPropertyDefinitionTime(gpid); + assertEquals(expectedTime, actualTime); + } + + // precondition tests + + // if the global property id is null + PropertyDefinition propDef = PropertyDefinition.builder().setType(Integer.class).setDefaultValue(17).build(); + ContractException contractException = assertThrows(ContractException.class, + () -> builder.defineGlobalProperty(null, propDef, 0)); + assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); + + // if the property definition is null + contractException = assertThrows(ContractException.class, + () -> builder.defineGlobalProperty(new SimpleGlobalPropertyId("id"), null, 0)); + assertEquals(PropertyError.NULL_PROPERTY_DEFINITION, contractException.getErrorType()); + + } + + @Test + @UnitTestMethod(target = GlobalPropertiesPluginData.Builder.class, name = "setGlobalPropertyValue", args = { + GlobalPropertyId.class, Object.class, double.class }) + public void testSetGlobalPropertyValue() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(170390875787254562L); + + GlobalPropertiesPluginData.Builder builder = GlobalPropertiesPluginData.builder(); + + // show there are some properties in the support enum + assertTrue(TestGlobalPropertyId.values().length > 0); + + // define some properties + Set expectedGlobalPropertyIds = new LinkedHashSet<>(); + for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { + PropertyDefinition propertyDefinition = PropertyDefinition.builder().setType(Integer.class) + .setDefaultValue(0).build(); + builder.defineGlobalProperty(testGlobalPropertyId, propertyDefinition, 0); + expectedGlobalPropertyIds.add(testGlobalPropertyId); + } + // create a container for the expected values of the properties + Map expectedValues = new LinkedHashMap<>(); + Map expectedTimes = new LinkedHashMap<>(); + + // set the values + boolean useProperty = true; + for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { + if (useProperty) { + int value = randomGenerator.nextInt(); + int value2 = randomGenerator.nextInt(); + double time = randomGenerator.nextDouble(); + builder.setGlobalPropertyValue(testGlobalPropertyId, value2, time); + // replacing data to show that the value persists + time = randomGenerator.nextDouble(); + builder.setGlobalPropertyValue(testGlobalPropertyId, value, time); + // duplicating data to show that the value persists + time = randomGenerator.nextDouble(); + builder.setGlobalPropertyValue(testGlobalPropertyId, value, time); + expectedValues.put(testGlobalPropertyId, value); + expectedTimes.put(testGlobalPropertyId, time); + } + useProperty = !useProperty; + } + + // build the initial data + GlobalPropertiesPluginData globalInitialData = builder.build(); + + // show that the expected property ids are there + Set actualGlobalPropertyIds = globalInitialData.getGlobalPropertyIds(); + + assertEquals(expectedGlobalPropertyIds, actualGlobalPropertyIds); + + // show that the expected values are present + for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { + Object expectedValue = expectedValues.get(testGlobalPropertyId); + Optional optionalValue = globalInitialData.getGlobalPropertyValue(testGlobalPropertyId); + + if (expectedValue == null) { + assertFalse(optionalValue.isPresent()); + } else { + assertTrue(optionalValue.isPresent()); + Object actualValue = optionalValue.get(); + assertEquals(expectedValue, actualValue); + } + } + + // show that the expected times are present + for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { + Double expectedTime = expectedTimes.get(testGlobalPropertyId); + Optional optionalTime = globalInitialData.getGlobalPropertyTime(testGlobalPropertyId); + + if (expectedTime == null) { + assertFalse(optionalTime.isPresent()); + } else { + assertTrue(optionalTime.isPresent()); + Double actualTime = optionalTime.get(); + assertEquals(expectedTime, actualTime); + } + } + + /* + * precondition tests -- Note that invalid values are not covered here. The + * build() validates the values to see if they are compatible with the + * corresponding definitions. + */ + + // if the global property id is null + ContractException contractException = assertThrows(ContractException.class, + () -> builder.setGlobalPropertyValue(null, 5, 0)); + assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); + + // if the global property value is null + contractException = assertThrows(ContractException.class, + () -> builder.setGlobalPropertyValue(TestGlobalPropertyId.GLOBAL_PROPERTY_1_BOOLEAN_MUTABLE, null, 0)); + assertEquals(PropertyError.NULL_PROPERTY_VALUE, contractException.getErrorType()); + + } + + @Test + @UnitTestMethod(target = GlobalPropertiesPluginData.class, name = "builder", args = {}) + public void testBuilder() { + // show that the builder can be created + assertNotNull(GlobalPropertiesPluginData.builder()); + } + + @Test + @UnitTestMethod(target = GlobalPropertiesPluginData.class, name = "getGlobalPropertyDefinition", args = { + GlobalPropertyId.class }) + public void testGetGlobalPropertyDefinition() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(5427251266091264753L); + + GlobalPropertiesPluginData.Builder builder = GlobalPropertiesPluginData.builder(); + + // show there are some properties in the support enum + assertTrue(TestGlobalPropertyId.values().length > 0); + + // create a container for the expected values of the properties + Map expectedGlobalPropertyDefinitions = new LinkedHashMap<>(); + Map expectedGlobalPropertyDefinitionTimes = new LinkedHashMap<>(); + + // define some properties + + for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { + PropertyDefinition propertyDefinition = PropertyDefinition.builder().setType(Integer.class) + .setDefaultValue(0).build(); + double time = randomGenerator.nextDouble(); + builder.defineGlobalProperty(testGlobalPropertyId, propertyDefinition, time); + expectedGlobalPropertyDefinitions.put(testGlobalPropertyId, propertyDefinition); + expectedGlobalPropertyDefinitionTimes.put(testGlobalPropertyId, time); + } + + // show that the expected property definitions are present + GlobalPropertiesPluginData globalInitialData = builder.build(); + + for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { + PropertyDefinition expectedPropertyDefinition = expectedGlobalPropertyDefinitions.get(testGlobalPropertyId); + PropertyDefinition actualPropertyDefinition = globalInitialData + .getGlobalPropertyDefinition(testGlobalPropertyId); + assertEquals(expectedPropertyDefinition, actualPropertyDefinition); + + Double expetedTime = expectedGlobalPropertyDefinitionTimes.get(testGlobalPropertyId); + Double actualTime = globalInitialData.getGlobalPropertyDefinitionTime(testGlobalPropertyId); + assertEquals(expetedTime, actualTime); + + } + + // precondition tests + ContractException contractException = assertThrows(ContractException.class, + () -> globalInitialData.getGlobalPropertyDefinition(null)); + assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); + + contractException = assertThrows(ContractException.class, + () -> globalInitialData.getGlobalPropertyDefinition(TestGlobalPropertyId.getUnknownGlobalPropertyId())); + assertEquals(PropertyError.UNKNOWN_PROPERTY_ID, contractException.getErrorType()); + + } + + @Test + @UnitTestMethod(target = GlobalPropertiesPluginData.class, name = "getGlobalPropertyDefinitions", args = {}) + public void testGetGlobalPropertyDefinitions() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(5427251266091264753L); + + GlobalPropertiesPluginData.Builder builder = GlobalPropertiesPluginData.builder(); + + // show there are some properties in the support enum + assertTrue(TestGlobalPropertyId.values().length > 0); + + // create a container for the expected values of the properties + Map expectedGlobalPropertyDefinitions = new LinkedHashMap<>(); + + // define some properties + + for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { + PropertyDefinition propertyDefinition = PropertyDefinition.builder().setType(Integer.class) + .setDefaultValue(0).build(); + double time = randomGenerator.nextDouble(); + builder.defineGlobalProperty(testGlobalPropertyId, propertyDefinition, time); + expectedGlobalPropertyDefinitions.put(testGlobalPropertyId, propertyDefinition); + } + + // show that the expected property definitions are present + GlobalPropertiesPluginData globalInitialData = builder.build(); + + assertEquals(expectedGlobalPropertyDefinitions, globalInitialData.getGlobalPropertyDefinitions()); + } + + @Test + @UnitTestMethod(target = GlobalPropertiesPluginData.class, name = "getGlobalPropertyDefinitionTimes", args = {}) + public void testGetGlobalPropertyDefinitionTimes() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(5427251266091264753L); + + GlobalPropertiesPluginData.Builder builder = GlobalPropertiesPluginData.builder(); + + // show there are some properties in the support enum + assertTrue(TestGlobalPropertyId.values().length > 0); + + // create a container for the expected values of the properties + Map expectedGlobalPropertyDefinitionTimes = new LinkedHashMap<>(); + + // define some properties + + for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { + PropertyDefinition propertyDefinition = PropertyDefinition.builder().setType(Integer.class) + .setDefaultValue(0).build(); + double time = randomGenerator.nextDouble(); + builder.defineGlobalProperty(testGlobalPropertyId, propertyDefinition, time); + expectedGlobalPropertyDefinitionTimes.put(testGlobalPropertyId, time); + } + + // show that the expected property definitions are present + GlobalPropertiesPluginData globalInitialData = builder.build(); + + assertEquals(expectedGlobalPropertyDefinitionTimes, globalInitialData.getGlobalPropertyDefinitionTimes()); + } + + @Test + @UnitTestMethod(target = GlobalPropertiesPluginData.class, name = "getGlobalPropertyIds", args = {}) + public void testGetGlobalPropertyIds() { + + GlobalPropertiesPluginData.Builder builder = GlobalPropertiesPluginData.builder(); + + // show there are some properties in the support enum + assertTrue(TestGlobalPropertyId.values().length > 0); + + // create a container for the expected values of the properties + Set expectedGlobalPropertyIds = new LinkedHashSet<>(); + + // define some properties + + for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { + PropertyDefinition propertyDefinition = PropertyDefinition.builder()// + .setType(Integer.class)// + .setDefaultValue(0)// + .build(); + builder.defineGlobalProperty(testGlobalPropertyId, propertyDefinition, 0); + expectedGlobalPropertyIds.add(testGlobalPropertyId); + } + + // show that the expected values are present + GlobalPropertiesPluginData globalInitialData = builder.build(); + assertEquals(expectedGlobalPropertyIds, globalInitialData.getGlobalPropertyIds()); + } + + @Test + @UnitTestMethod(target = GlobalPropertiesPluginData.class, name = "getGlobalPropertyValue", args = { + GlobalPropertyId.class }) + public void testGetGlobalPropertyValue() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(4250048639082754761L); + + GlobalPropertiesPluginData.Builder builder = GlobalPropertiesPluginData.builder(); + + // show there are some properties in the support enum + assertTrue(TestGlobalPropertyId.values().length > 0); + + // define some properties + for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { + PropertyDefinition propertyDefinition = PropertyDefinition.builder().setType(Integer.class) + .setDefaultValue(0).build(); + builder.defineGlobalProperty(testGlobalPropertyId, propertyDefinition, 0); + } + // create a container for the expected values of the properties + Map expectedValues = new LinkedHashMap<>(); + + // set about half of the values + boolean shouldSetValue = true; + for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { + if (shouldSetValue) { + int value = randomGenerator.nextInt(); + builder.setGlobalPropertyValue(testGlobalPropertyId, value, 0); + expectedValues.put(testGlobalPropertyId, value); + } + shouldSetValue = !shouldSetValue; + } + + // show that the expected values are present + GlobalPropertiesPluginData globalPropertiesPluginData = builder.build(); + for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { + Object expectedValue = expectedValues.get(testGlobalPropertyId); + Optional optionalValue = globalPropertiesPluginData.getGlobalPropertyValue(testGlobalPropertyId); + if (expectedValue == null) { + assertFalse(optionalValue.isPresent()); + } else { + assertTrue(optionalValue.isPresent()); + Object actualValue = optionalValue.get(); + assertEquals(expectedValue, actualValue); + } + } + + /* + * precondition tests -- Note that invalid values are not covered here. The + * build() validates the values to see if they are compatible with the + * corresponding definitions. + */ + + // if the global property id is null + ContractException contractException = assertThrows(ContractException.class, + () -> globalPropertiesPluginData.getGlobalPropertyValue(null)); + assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); + + // if the global property value is null + contractException = assertThrows(ContractException.class, () -> globalPropertiesPluginData + .getGlobalPropertyValue(TestGlobalPropertyId.getUnknownGlobalPropertyId())); + assertEquals(PropertyError.UNKNOWN_PROPERTY_ID, contractException.getErrorType()); + + } + + @Test + @UnitTestMethod(target = GlobalPropertiesPluginData.class, name = "getGlobalPropertyValues", args = {}) + public void testGetGlobalPropertyValues() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(4250048639082754761L); + + GlobalPropertiesPluginData.Builder builder = GlobalPropertiesPluginData.builder(); + + // show there are some properties in the support enum + assertTrue(TestGlobalPropertyId.values().length > 0); + + // define some properties + for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { + PropertyDefinition propertyDefinition = PropertyDefinition.builder().setType(Integer.class) + .setDefaultValue(0).build(); + builder.defineGlobalProperty(testGlobalPropertyId, propertyDefinition, 0); + } + // create a container for the expected values of the properties + Map expectedValues = new LinkedHashMap<>(); + + // set about half of the values + boolean shouldSetValue = true; + for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { + if (shouldSetValue) { + int value = randomGenerator.nextInt(); + builder.setGlobalPropertyValue(testGlobalPropertyId, value, 0); + expectedValues.put(testGlobalPropertyId, value); + } + shouldSetValue = !shouldSetValue; + } + + GlobalPropertiesPluginData globalPropertiesPluginData = builder.build(); + + assertEquals(expectedValues, globalPropertiesPluginData.getGlobalPropertyValues()); + } + + @Test + @UnitTestMethod(target = GlobalPropertiesPluginData.class, name = "getCloneBuilder", args = {}) + public void testGetCloneBuilder() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(9113503089361379130L); + GlobalPropertiesPluginData.Builder builder = GlobalPropertiesPluginData.builder(); + + for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { + double time = randomGenerator.nextDouble(); + builder.defineGlobalProperty(testGlobalPropertyId, testGlobalPropertyId.getPropertyDefinition(), time); + time += randomGenerator.nextDouble(); + builder.setGlobalPropertyValue(testGlobalPropertyId, + testGlobalPropertyId.getRandomPropertyValue(randomGenerator), time); + } + + GlobalPropertiesPluginData globalPropertiesPluginData = builder.build(); + + // show that the returned clone builder will build an identical instance if no + // mutations are made + GlobalPropertiesPluginData.Builder cloneBuilder = globalPropertiesPluginData.getCloneBuilder(); + assertNotNull(cloneBuilder); + assertEquals(globalPropertiesPluginData, cloneBuilder.build()); + + // show that the clone builder builds a distinct instance if any mutation is + // made + + // defineGlobalProperty + cloneBuilder = globalPropertiesPluginData.getCloneBuilder(); + cloneBuilder.defineGlobalProperty(TestGlobalPropertyId.GLOBAL_PROPERTY_3_DOUBLE_MUTABLE,TestGlobalPropertyId.GLOBAL_PROPERTY_3_DOUBLE_MUTABLE.getPropertyDefinition(),0.0); + assertNotEquals(globalPropertiesPluginData, cloneBuilder.build()); + + // setGlobalPropertyValue + cloneBuilder = globalPropertiesPluginData.getCloneBuilder(); + cloneBuilder.setGlobalPropertyValue(TestGlobalPropertyId.GLOBAL_PROPERTY_3_DOUBLE_MUTABLE,2.3,1.0); + assertNotEquals(globalPropertiesPluginData, cloneBuilder.build()); + } + + @Test + @UnitTestMethod(target = GlobalPropertiesPluginData.class, name = "getGlobalPropertyDefinitionTime", args = { + GlobalPropertyId.class }) + public void testGetGlobalPropertyDefinitionTime() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(5487507072126661304L); + + GlobalPropertiesPluginData.Builder builder = GlobalPropertiesPluginData.builder(); + + // show there are some properties in the support enum + assertTrue(TestGlobalPropertyId.values().length > 0); + + // create a container for the expected values of the properties + Map expectedGlobalPropertyDefinitions = new LinkedHashMap<>(); + Map expectedGlobalPropertyDefinitionTimes = new LinkedHashMap<>(); + + // define some properties + + for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { + PropertyDefinition propertyDefinition = PropertyDefinition.builder().setType(Integer.class) + .setDefaultValue(0).build(); + double time = randomGenerator.nextDouble(); + builder.defineGlobalProperty(testGlobalPropertyId, propertyDefinition, time); + expectedGlobalPropertyDefinitions.put(testGlobalPropertyId, propertyDefinition); + expectedGlobalPropertyDefinitionTimes.put(testGlobalPropertyId, time); + } + + // show that the expected property definitions are present + GlobalPropertiesPluginData globalInitialData = builder.build(); + + for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { + PropertyDefinition expectedPropertyDefinition = expectedGlobalPropertyDefinitions.get(testGlobalPropertyId); + PropertyDefinition actualPropertyDefinition = globalInitialData + .getGlobalPropertyDefinition(testGlobalPropertyId); + assertEquals(expectedPropertyDefinition, actualPropertyDefinition); + + Double expetedTime = expectedGlobalPropertyDefinitionTimes.get(testGlobalPropertyId); + Double actualTime = globalInitialData.getGlobalPropertyDefinitionTime(testGlobalPropertyId); + assertEquals(expetedTime, actualTime); + + } + + // precondition tests + ContractException contractException = assertThrows(ContractException.class, + () -> globalInitialData.getGlobalPropertyDefinition(null)); + assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); + + contractException = assertThrows(ContractException.class, + () -> globalInitialData.getGlobalPropertyDefinition(TestGlobalPropertyId.getUnknownGlobalPropertyId())); + assertEquals(PropertyError.UNKNOWN_PROPERTY_ID, contractException.getErrorType()); + + } + + @Test + @UnitTestMethod(target = GlobalPropertiesPluginData.class, name = "getGlobalPropertyTime", args = { + GlobalPropertyId.class }) + public void testGetGlobalPropertyTime() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(4250048639082754761L); + + GlobalPropertiesPluginData.Builder builder = GlobalPropertiesPluginData.builder(); + + // show there are some properties in the support enum + assertTrue(TestGlobalPropertyId.values().length > 0); + + // define some properties -- note that we do not set default values to + // test that the values provided explicitly will properly replace the + // default values. + for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { + PropertyDefinition propertyDefinition = PropertyDefinition.builder()// + .setType(Integer.class)// + .setDefaultValue(0)// + .build(); + builder.defineGlobalProperty(testGlobalPropertyId, propertyDefinition, 0.0); + } + // create a container for the expected values of the properties + Map expectedTimes = new LinkedHashMap<>(); + + // set the times for half of the properties + int counter = 0; + for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { + if (counter % 2 == 0) { + int value = randomGenerator.nextInt(); + double time = randomGenerator.nextDouble() + 0.1; + builder.setGlobalPropertyValue(testGlobalPropertyId, value, time); + expectedTimes.put(testGlobalPropertyId, time); + } + counter++; + } + + // show that the expected times are present + GlobalPropertiesPluginData globalPropertiesPluginData = builder.build(); + for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { + Double expectedTime = expectedTimes.get(testGlobalPropertyId); + Optional optionalTime = globalPropertiesPluginData.getGlobalPropertyTime(testGlobalPropertyId); + if (expectedTime == null) { + assertFalse(optionalTime.isPresent()); + } else { + assertTrue(optionalTime.isPresent()); + Double actualTime = optionalTime.get(); + assertEquals(expectedTime, actualTime); + } + } + + /* + * precondition tests -- Note that invalid values are not covered here. The + * build() validates the values to see if they are compatible with the + * corresponding definitions. + */ + + // if the global property id is null + ContractException contractException = assertThrows(ContractException.class, + () -> globalPropertiesPluginData.getGlobalPropertyValue(null)); + assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); + + // if the global property value is null + contractException = assertThrows(ContractException.class, () -> globalPropertiesPluginData + .getGlobalPropertyValue(TestGlobalPropertyId.getUnknownGlobalPropertyId())); + assertEquals(PropertyError.UNKNOWN_PROPERTY_ID, contractException.getErrorType()); + + } + + @Test + @UnitTestMethod(target = GlobalPropertiesPluginData.class, name = "getGlobalPropertyTimes", args = {}) + public void testGetGlobalPropertyTimes() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(4250048639082754761L); + + GlobalPropertiesPluginData.Builder builder = GlobalPropertiesPluginData.builder(); + + // show there are some properties in the support enum + assertTrue(TestGlobalPropertyId.values().length > 0); + + // define some properties -- note that we do not set default values to + // test that the values provided explicitly will properly replace the + // default values. + for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { + PropertyDefinition propertyDefinition = PropertyDefinition.builder()// + .setType(Integer.class)// + .setDefaultValue(0)// + .build(); + builder.defineGlobalProperty(testGlobalPropertyId, propertyDefinition, 0.0); + } + // create a container for the expected values of the properties + Map expectedTimes = new LinkedHashMap<>(); + + // set the times for half of the properties + int counter = 0; + for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { + if (counter % 2 == 0) { + int value = randomGenerator.nextInt(); + double time = randomGenerator.nextDouble() + 0.1; + builder.setGlobalPropertyValue(testGlobalPropertyId, value, time); + expectedTimes.put(testGlobalPropertyId, time); + } + counter++; + } + + // show that the expected times are present + GlobalPropertiesPluginData globalPropertiesPluginData = builder.build(); + + assertEquals(expectedTimes, globalPropertiesPluginData.getGlobalPropertyTimes()); + } + + @Test + @UnitTestMethod(target = GlobalPropertiesPluginData.class, name = "equals", args = { Object.class }) + public void testEquals() { + // we first set up a few items that will clarify the production of + // plugin datas + + Object v_5 = 5; + Object v_12 = 12; + Object v_25 = 15; + Object v_a = "a"; + Object v_b = "b"; + + GlobalPropertyId p1 = TestGlobalPropertyId.getUnknownGlobalPropertyId(); + GlobalPropertyId p2 = TestGlobalPropertyId.getUnknownGlobalPropertyId(); + + PropertyDefinition d1 = PropertyDefinition.builder()// + .setType(Integer.class)// + .setDefaultValue(v_5)// + .build(); + + PropertyDefinition d2 = PropertyDefinition.builder()// + .setType(String.class)// + .setDefaultValue(v_a)// + .build(); + + Double t_0 = 0.0; + Double t_1 = 1.0; + Double t_2 = 2.0; + + // just a single definition -- this will act as our base case + GlobalPropertiesPluginData g1 = GlobalPropertiesPluginData.builder()// + .defineGlobalProperty(p1, d1, t_0)// + .build(); + + // set the property value that has the same time and value as the + // property definition + GlobalPropertiesPluginData g2 = GlobalPropertiesPluginData.builder()// + .defineGlobalProperty(p1, d1, t_0)// + .setGlobalPropertyValue(p1, v_5, t_0)// + .build(); + + GlobalPropertiesPluginData g3 = GlobalPropertiesPluginData.builder()// + .setGlobalPropertyValue(p1, v_5, t_0)// + .defineGlobalProperty(p1, d1, t_0)// + .build(); + + // change the value of the property + GlobalPropertiesPluginData g4 = GlobalPropertiesPluginData.builder()// + .defineGlobalProperty(p1, d1, t_0)// + .setGlobalPropertyValue(p1, v_25, t_0)// + .build(); + + // change the time of the property + GlobalPropertiesPluginData g5 = GlobalPropertiesPluginData.builder()// + .defineGlobalProperty(p1, d1, t_0)// + .setGlobalPropertyValue(p1, v_5, t_1)// + .build(); + + // introduce a new property definition + GlobalPropertiesPluginData g6 = GlobalPropertiesPluginData.builder()// + .defineGlobalProperty(p1, d1, t_0)// + .defineGlobalProperty(p2, d2, t_1)// + .build(); + + // add several values and definitions + GlobalPropertiesPluginData g7 = GlobalPropertiesPluginData.builder()// + .defineGlobalProperty(p1, d1, t_0)// + .defineGlobalProperty(p2, d2, t_1)// + .setGlobalPropertyValue(p1, v_25, t_2)// + .setGlobalPropertyValue(p2, v_b, t_2)// + .setGlobalPropertyValue(p1, v_12, t_1)// + .build(); + + // add the same details, but in a different order, preserving the last + // assignments + GlobalPropertiesPluginData g8 = GlobalPropertiesPluginData.builder()// + .setGlobalPropertyValue(p1, v_25, t_2)// + .defineGlobalProperty(p2, d2, t_1)// + .defineGlobalProperty(p1, d1, t_0)// + .setGlobalPropertyValue(p1, v_12, t_1)// + .setGlobalPropertyValue(p2, v_b, t_2)// + .build(); + + // reflexive + assertEquals(g1, g1); + assertEquals(g2, g2); + assertEquals(g4, g4); + assertEquals(g5, g5); + assertEquals(g6, g6); + assertEquals(g7, g7); + assertEquals(g8, g8); + + // symmetric and transitive + + assertEquals(g2, g3); + assertEquals(g3, g2); + + // non-equality from small changes + assertNotEquals(g1, g2); + assertNotEquals(g1, g3); + assertNotEquals(g1, g4); + assertNotEquals(g1, g5); + assertNotEquals(g1, g6); + + // ordering of action should have no effect + assertEquals(g7, g8); + + } + + @Test + @UnitTestMethod(target = GlobalPropertiesPluginData.class, name = "hashCode", args = {}) + public void testHashCode() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(2653491508465183354L); + Object v_5 = 5; + Object v_12 = 12; + Object v_25 = 15; + Object v_a = "a"; + Object v_b = "b"; + + GlobalPropertyId p1 = TestGlobalPropertyId.getUnknownGlobalPropertyId(); + GlobalPropertyId p2 = TestGlobalPropertyId.getUnknownGlobalPropertyId(); + + PropertyDefinition d1 = PropertyDefinition.builder()// + .setType(Integer.class)// + .setDefaultValue(v_5)// + .build(); + + PropertyDefinition d2 = PropertyDefinition.builder()// + .setType(String.class)// + .setDefaultValue(v_a)// + .build(); + + Double t_0 = 0.0; + Double t_1 = 1.0; + Double t_2 = 2.0; + + // equal objects have equal hash codes + // add several values and definitions + GlobalPropertiesPluginData g7 = GlobalPropertiesPluginData.builder()// + .defineGlobalProperty(p1, d1, t_0)// + .defineGlobalProperty(p2, d2, t_1)// + .setGlobalPropertyValue(p1, v_25, t_2).setGlobalPropertyValue(p2, v_b, t_2) + .setGlobalPropertyValue(p1, v_12, t_1).build(); + + // add the same details, but in a different order, preserving the last + // assignments + GlobalPropertiesPluginData g8 = GlobalPropertiesPluginData.builder()// + .setGlobalPropertyValue(p1, v_25, t_2).defineGlobalProperty(p2, d2, t_1)// + .defineGlobalProperty(p1, d1, t_0)// + .setGlobalPropertyValue(p1, v_12, t_1).setGlobalPropertyValue(p2, v_b, t_2).build(); + + assertEquals(g7, g8); + assertEquals(g7.hashCode(), g8.hashCode()); + + // hash codes are reasonably distributed + + Set hashCodes = new LinkedHashSet<>(); + for (int i = 0; i < 100; i++) { + GlobalPropertiesPluginData.Builder builder = GlobalPropertiesPluginData.builder(); + for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { + if (randomGenerator.nextBoolean()) { + double time = randomGenerator.nextDouble(); + builder.defineGlobalProperty(testGlobalPropertyId, testGlobalPropertyId.getPropertyDefinition(), + time); + + if (randomGenerator.nextBoolean() + || testGlobalPropertyId.getPropertyDefinition().getDefaultValue().isEmpty()) { + time += 0.1; + builder.setGlobalPropertyValue(testGlobalPropertyId, + testGlobalPropertyId.getRandomPropertyValue(randomGenerator), time); + } + } + } + GlobalPropertiesPluginData globalPropertiesPluginData = builder.build(); + hashCodes.add(globalPropertiesPluginData.hashCode()); + } + assertTrue(hashCodes.size() > 90); + } + + @Test + @UnitTestMethod(target = GlobalPropertiesPluginData.class, name = "toString", args = {}) + public void testToString() { + + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(8337912786649642023L); + + /* + * Demonstrate a typical example with a full string. We will add all of the + * standard test definitions in the usual order, but will only add a few of the + * property values in reverse order. Note that we will cover the #3 member which + * does not have a corresponding default value. + */ + GlobalPropertiesPluginData.Builder builder = GlobalPropertiesPluginData.builder(); + + Map definitionTimes = new LinkedHashMap<>(); + + for (TestGlobalPropertyId testGlobalPropertyId : TestGlobalPropertyId.values()) { + double time = randomGenerator.nextInt(1000); + definitionTimes.put(testGlobalPropertyId, time); + builder.defineGlobalProperty(testGlobalPropertyId, testGlobalPropertyId.getPropertyDefinition(), time); + } + + List propertiesForValueSetting = new ArrayList<>(); + propertiesForValueSetting.add(TestGlobalPropertyId.GLOBAL_PROPERTY_6_DOUBLE_IMMUTABLE); + propertiesForValueSetting.add(TestGlobalPropertyId.GLOBAL_PROPERTY_3_DOUBLE_MUTABLE); + propertiesForValueSetting.add(TestGlobalPropertyId.GLOBAL_PROPERTY_1_BOOLEAN_MUTABLE); + + for (TestGlobalPropertyId testGlobalPropertyId : propertiesForValueSetting) { + double time = definitionTimes.get(testGlobalPropertyId) + randomGenerator.nextInt(100); + builder.setGlobalPropertyValue(testGlobalPropertyId, + testGlobalPropertyId.getRandomPropertyValue(randomGenerator), time); + } + + GlobalPropertiesPluginData globalPropertiesPluginData = builder.build(); + + String expectedValue = "GlobalPropertiesPluginData [data=Data [globalPropertyDefinitions" + + "={GLOBAL_PROPERTY_1_BOOLEAN_MUTABLE=PropertyDefinition [type=class java.lang.Boolean" + + ", propertyValuesAreMutable=true, defaultValue=false], GLOBAL_PROPERTY_2_INTEGER_MUTABLE" + + "=PropertyDefinition [type=class java.lang.Integer, propertyValuesAreMutable=true, " + + "defaultValue=0], GLOBAL_PROPERTY_3_DOUBLE_MUTABLE=PropertyDefinition [type=class " + + "java.lang.Double, propertyValuesAreMutable=true, defaultValue=null], " + + "GLOBAL_PROPERTY_4_BOOLEAN_IMMUTABLE=PropertyDefinition [type=class java.lang.Boolean, " + + "propertyValuesAreMutable=false, defaultValue=false], GLOBAL_PROPERTY_5_INTEGER_IMMUTABLE=" + + "PropertyDefinition [type=class java.lang.Integer, propertyValuesAreMutable=false" + + ", defaultValue=0], GLOBAL_PROPERTY_6_DOUBLE_IMMUTABLE=PropertyDefinition [type=class " + + "java.lang.Double, propertyValuesAreMutable=false, defaultValue=0.0]}, " + + "globalPropertyDefinitionTimes={GLOBAL_PROPERTY_1_BOOLEAN_MUTABLE=852.0, " + + "GLOBAL_PROPERTY_2_INTEGER_MUTABLE=835.0, GLOBAL_PROPERTY_3_DOUBLE_MUTABLE=156.0, " + + "GLOBAL_PROPERTY_4_BOOLEAN_IMMUTABLE=505.0, GLOBAL_PROPERTY_5_INTEGER_IMMUTABLE=956.0, " + + "GLOBAL_PROPERTY_6_DOUBLE_IMMUTABLE=191.0}, globalPropertyValues={" + + "GLOBAL_PROPERTY_6_DOUBLE_IMMUTABLE=0.09917206486092223, GLOBAL_PROPERTY_3_DOUBLE_MUTABLE=" + + "0.07709107250291058, GLOBAL_PROPERTY_1_BOOLEAN_MUTABLE=false}, globalPropertyTimes={" + + "GLOBAL_PROPERTY_6_DOUBLE_IMMUTABLE=255.0, GLOBAL_PROPERTY_3_DOUBLE_MUTABLE=168.0, " + + "GLOBAL_PROPERTY_1_BOOLEAN_MUTABLE=877.0}, locked=true]]"; + + String actualValue = globalPropertiesPluginData.toString(); + + assertEquals(expectedValue, actualValue); + } } diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/globalproperties/reports/AT_GlobalPropertyReportPluginData.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/globalproperties/reports/AT_GlobalPropertyReportPluginData.java index 99b625918..48e5b5f04 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/globalproperties/reports/AT_GlobalPropertyReportPluginData.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/globalproperties/reports/AT_GlobalPropertyReportPluginData.java @@ -24,547 +24,561 @@ public class AT_GlobalPropertyReportPluginData { - @Test - @UnitTestMethod(target = GlobalPropertyReportPluginData.class, name = "builder", args = {}) - public void testBuilder() { - GlobalPropertyReportPluginData.Builder builder = GlobalPropertyReportPluginData.builder(); - assertNotNull(builder); - } - - @Test - @UnitTestMethod(target = GlobalPropertyReportPluginData.Builder.class, name = "build", args = {}) - public void testBuild() { - // the specific capabilities are covered elsewhere - - // precondition test: if the report period is not assigned - ContractException contractException = assertThrows(ContractException.class, () -> // - GlobalPropertyReportPluginData.builder()// - .build()); - assertEquals(ReportError.NULL_REPORT_LABEL, contractException.getErrorType()); - } - - @Test - @UnitTestMethod(target = GlobalPropertyReportPluginData.Builder.class, name = "setReportLabel", args = { - ReportLabel.class }) - public void testSetReportLabel() { - - for (int i = 0; i < 30; i++) { - ReportLabel expectedReportLabel = new SimpleReportLabel(i); - GlobalPropertyReportPluginData personPropertyReportPluginData = // - GlobalPropertyReportPluginData.builder()// - .setReportLabel(expectedReportLabel)// - .build(); - - assertEquals(expectedReportLabel, personPropertyReportPluginData.getReportLabel()); - } - - // precondition: if the report label is null - ContractException contractException = assertThrows(ContractException.class, () -> { - GlobalPropertyReportPluginData.builder().setReportLabel(null); - }); - assertEquals(ReportError.NULL_REPORT_LABEL, contractException.getErrorType()); - } - - @Test - @UnitTestMethod(target = GlobalPropertyReportPluginData.Builder.class, name = "setDefaultInclusion", args = { - boolean.class }) - public void testSetDefaultInclusion() { - ReportLabel reportLabel = new SimpleReportLabel("report label"); - - // show the default value is true - GlobalPropertyReportPluginData globalPropertyReportPluginData = // - GlobalPropertyReportPluginData.builder()// - .setReportLabel(reportLabel)// - .build(); - assertEquals(true, globalPropertyReportPluginData.getDefaultInclusionPolicy()); - - globalPropertyReportPluginData = // - GlobalPropertyReportPluginData.builder()// - .setReportLabel(reportLabel)// - .setDefaultInclusion(true)// - .build(); - assertEquals(true, globalPropertyReportPluginData.getDefaultInclusionPolicy()); - - globalPropertyReportPluginData = // - GlobalPropertyReportPluginData.builder()// . - .setReportLabel(reportLabel)// - .setDefaultInclusion(false)// - .build(); - assertEquals(false, globalPropertyReportPluginData.getDefaultInclusionPolicy()); - - } - - @Test - @UnitTestMethod(target = GlobalPropertyReportPluginData.Builder.class, name = "includeGlobalProperty", args = { - GlobalPropertyId.class }) - public void testIncludeGlobalProperty() { - ReportLabel reportLabel = new SimpleReportLabel("report label"); - - // show the default is non-inclusion - GlobalPropertyReportPluginData personPropertyReportPluginData = // - GlobalPropertyReportPluginData.builder()// - .setReportLabel(reportLabel)// - .build(); - assertTrue(personPropertyReportPluginData.getIncludedProperties().isEmpty()); - - // show that inclusion alone works - Set expectedGlobalPropertyIds = new LinkedHashSet<>(); - - expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_1_BOOLEAN_MUTABLE); - expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_4_BOOLEAN_IMMUTABLE); - expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_2_INTEGER_MUTABLE); - - GlobalPropertyReportPluginData.Builder builder = GlobalPropertyReportPluginData.builder()// - .setReportLabel(reportLabel);// - - for (GlobalPropertyId globalPropertyId : expectedGlobalPropertyIds) { - builder.includeGlobalProperty(globalPropertyId); - } - - personPropertyReportPluginData = builder.build(); - assertEquals(expectedGlobalPropertyIds, personPropertyReportPluginData.getIncludedProperties()); - - // show that inclusion will override exclusion - expectedGlobalPropertyIds.clear(); - - expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_1_BOOLEAN_MUTABLE); - expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_4_BOOLEAN_IMMUTABLE); - expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_2_INTEGER_MUTABLE); - - builder = GlobalPropertyReportPluginData.builder()// - .setReportLabel(reportLabel);// - - for (GlobalPropertyId globalPropertyId : expectedGlobalPropertyIds) { - builder.excludeGlobalProperty(globalPropertyId); - builder.includeGlobalProperty(globalPropertyId); - } - - personPropertyReportPluginData = builder.build(); - assertEquals(expectedGlobalPropertyIds, personPropertyReportPluginData.getIncludedProperties()); - - // precondition: if the person property id is null - ContractException contractException = assertThrows(ContractException.class, () -> { - GlobalPropertyReportPluginData.builder().includeGlobalProperty(null); - }); - assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); - } - - @Test - @UnitTestMethod(target = GlobalPropertyReportPluginData.Builder.class, name = "excludeGlobalProperty", args = { - GlobalPropertyId.class }) - public void testExcludePersonProperty() { - ReportLabel reportLabel = new SimpleReportLabel("report label"); - - // show the default is non-exclusion - GlobalPropertyReportPluginData personPropertyReportPluginData = // - GlobalPropertyReportPluginData.builder()// - .setReportLabel(reportLabel)// - .build(); - assertTrue(personPropertyReportPluginData.getExcludedProperties().isEmpty()); - - // show that exclusion alone works - Set expectedGlobalPropertyIds = new LinkedHashSet<>(); - - expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_1_BOOLEAN_MUTABLE); - expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_4_BOOLEAN_IMMUTABLE); - expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_2_INTEGER_MUTABLE); - - GlobalPropertyReportPluginData.Builder builder = GlobalPropertyReportPluginData.builder()// - .setReportLabel(reportLabel);// - - for (GlobalPropertyId globalPropertyId : expectedGlobalPropertyIds) { - builder.excludeGlobalProperty(globalPropertyId); - } - - personPropertyReportPluginData = builder.build(); - assertEquals(expectedGlobalPropertyIds, personPropertyReportPluginData.getExcludedProperties()); - - // show that exclusion will override inclusion - expectedGlobalPropertyIds.clear(); - - expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_1_BOOLEAN_MUTABLE); - expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_4_BOOLEAN_IMMUTABLE); - expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_2_INTEGER_MUTABLE); - - builder = GlobalPropertyReportPluginData.builder()// - .setReportLabel(reportLabel);// - - for (GlobalPropertyId globalPropertyId : expectedGlobalPropertyIds) { - builder.includeGlobalProperty(globalPropertyId); - builder.excludeGlobalProperty(globalPropertyId); - } - - personPropertyReportPluginData = builder.build(); - assertEquals(expectedGlobalPropertyIds, personPropertyReportPluginData.getExcludedProperties()); - - // precondition: if the person property id is null - ContractException contractException = assertThrows(ContractException.class, () -> { - GlobalPropertyReportPluginData.builder().excludeGlobalProperty(null); - }); - assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); - } + @Test + @UnitTestMethod(target = GlobalPropertyReportPluginData.class, name = "builder", args = {}) + public void testBuilder() { + GlobalPropertyReportPluginData.Builder builder = GlobalPropertyReportPluginData.builder(); + assertNotNull(builder); + } + + @Test + @UnitTestMethod(target = GlobalPropertyReportPluginData.Builder.class, name = "build", args = {}) + public void testBuild() { + // the specific capabilities are covered elsewhere + + // precondition test: if the report period is not assigned + ContractException contractException = assertThrows(ContractException.class, () -> // + GlobalPropertyReportPluginData.builder()// + .build()); + assertEquals(ReportError.NULL_REPORT_LABEL, contractException.getErrorType()); + } + + @Test + @UnitTestMethod(target = GlobalPropertyReportPluginData.Builder.class, name = "setReportLabel", args = { + ReportLabel.class }) + public void testSetReportLabel() { + + for (int i = 0; i < 30; i++) { + ReportLabel expectedReportLabel = new SimpleReportLabel(i); + GlobalPropertyReportPluginData personPropertyReportPluginData = // + GlobalPropertyReportPluginData.builder()// + .setReportLabel(expectedReportLabel)// + .build(); + + assertEquals(expectedReportLabel, personPropertyReportPluginData.getReportLabel()); + } + + // precondition: if the report label is null + ContractException contractException = assertThrows(ContractException.class, () -> { + GlobalPropertyReportPluginData.builder().setReportLabel(null); + }); + assertEquals(ReportError.NULL_REPORT_LABEL, contractException.getErrorType()); + } + + @Test + @UnitTestMethod(target = GlobalPropertyReportPluginData.Builder.class, name = "setDefaultInclusion", args = { + boolean.class }) + public void testSetDefaultInclusion() { + ReportLabel reportLabel = new SimpleReportLabel("report label"); + + // show the default value is true + GlobalPropertyReportPluginData globalPropertyReportPluginData = // + GlobalPropertyReportPluginData.builder()// + .setReportLabel(reportLabel)// + .build(); + assertEquals(true, globalPropertyReportPluginData.getDefaultInclusionPolicy()); + + globalPropertyReportPluginData = // + GlobalPropertyReportPluginData.builder()// + .setReportLabel(reportLabel)// + .setDefaultInclusion(true)// + .build(); + assertEquals(true, globalPropertyReportPluginData.getDefaultInclusionPolicy()); + + globalPropertyReportPluginData = // + GlobalPropertyReportPluginData.builder()// . + .setReportLabel(reportLabel)// + .setDefaultInclusion(false)// + .build(); + assertEquals(false, globalPropertyReportPluginData.getDefaultInclusionPolicy()); + + } + + @Test + @UnitTestMethod(target = GlobalPropertyReportPluginData.Builder.class, name = "includeGlobalProperty", args = { + GlobalPropertyId.class }) + public void testIncludeGlobalProperty() { + ReportLabel reportLabel = new SimpleReportLabel("report label"); + + // show the default is non-inclusion + GlobalPropertyReportPluginData personPropertyReportPluginData = // + GlobalPropertyReportPluginData.builder()// + .setReportLabel(reportLabel)// + .build(); + assertTrue(personPropertyReportPluginData.getIncludedProperties().isEmpty()); + + // show that inclusion alone works + Set expectedGlobalPropertyIds = new LinkedHashSet<>(); + + expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_1_BOOLEAN_MUTABLE); + expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_4_BOOLEAN_IMMUTABLE); + expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_2_INTEGER_MUTABLE); + + GlobalPropertyReportPluginData.Builder builder = GlobalPropertyReportPluginData.builder()// + .setReportLabel(reportLabel);// + + for (GlobalPropertyId globalPropertyId : expectedGlobalPropertyIds) { + builder.includeGlobalProperty(globalPropertyId); + } + + personPropertyReportPluginData = builder.build(); + assertEquals(expectedGlobalPropertyIds, personPropertyReportPluginData.getIncludedProperties()); + + // show that inclusion will override exclusion + expectedGlobalPropertyIds.clear(); + + expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_1_BOOLEAN_MUTABLE); + expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_4_BOOLEAN_IMMUTABLE); + expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_2_INTEGER_MUTABLE); + + builder = GlobalPropertyReportPluginData.builder()// + .setReportLabel(reportLabel);// + + for (GlobalPropertyId globalPropertyId : expectedGlobalPropertyIds) { + builder.excludeGlobalProperty(globalPropertyId); + builder.includeGlobalProperty(globalPropertyId); + } + + personPropertyReportPluginData = builder.build(); + assertEquals(expectedGlobalPropertyIds, personPropertyReportPluginData.getIncludedProperties()); + + // precondition: if the person property id is null + ContractException contractException = assertThrows(ContractException.class, () -> { + GlobalPropertyReportPluginData.builder().includeGlobalProperty(null); + }); + assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); + } + + @Test + @UnitTestMethod(target = GlobalPropertyReportPluginData.Builder.class, name = "excludeGlobalProperty", args = { + GlobalPropertyId.class }) + public void testExcludePersonProperty() { + ReportLabel reportLabel = new SimpleReportLabel("report label"); + + // show the default is non-exclusion + GlobalPropertyReportPluginData personPropertyReportPluginData = // + GlobalPropertyReportPluginData.builder()// + .setReportLabel(reportLabel)// + .build(); + assertTrue(personPropertyReportPluginData.getExcludedProperties().isEmpty()); + + // show that exclusion alone works + Set expectedGlobalPropertyIds = new LinkedHashSet<>(); + + expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_1_BOOLEAN_MUTABLE); + expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_4_BOOLEAN_IMMUTABLE); + expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_2_INTEGER_MUTABLE); + + GlobalPropertyReportPluginData.Builder builder = GlobalPropertyReportPluginData.builder()// + .setReportLabel(reportLabel);// + + for (GlobalPropertyId globalPropertyId : expectedGlobalPropertyIds) { + builder.excludeGlobalProperty(globalPropertyId); + } + + personPropertyReportPluginData = builder.build(); + assertEquals(expectedGlobalPropertyIds, personPropertyReportPluginData.getExcludedProperties()); + + // show that exclusion will override inclusion + expectedGlobalPropertyIds.clear(); + + expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_1_BOOLEAN_MUTABLE); + expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_4_BOOLEAN_IMMUTABLE); + expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_2_INTEGER_MUTABLE); + + builder = GlobalPropertyReportPluginData.builder()// + .setReportLabel(reportLabel);// + + for (GlobalPropertyId globalPropertyId : expectedGlobalPropertyIds) { + builder.includeGlobalProperty(globalPropertyId); + builder.excludeGlobalProperty(globalPropertyId); + } + + personPropertyReportPluginData = builder.build(); + assertEquals(expectedGlobalPropertyIds, personPropertyReportPluginData.getExcludedProperties()); + + // precondition: if the person property id is null + ContractException contractException = assertThrows(ContractException.class, () -> { + GlobalPropertyReportPluginData.builder().excludeGlobalProperty(null); + }); + assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); + } - @Test - @UnitTestMethod(target = GlobalPropertyReportPluginData.class, name = "getReportLabel", args = {}) - public void testGetReportLabel() { - for (int i = 0; i < 30; i++) { - ReportLabel expectedReportLabel = new SimpleReportLabel(i); - GlobalPropertyReportPluginData globalPropertyReportPluginData = // - GlobalPropertyReportPluginData.builder()// - .setReportLabel(expectedReportLabel)// - .build(); + @Test + @UnitTestMethod(target = GlobalPropertyReportPluginData.class, name = "getReportLabel", args = {}) + public void testGetReportLabel() { + for (int i = 0; i < 30; i++) { + ReportLabel expectedReportLabel = new SimpleReportLabel(i); + GlobalPropertyReportPluginData globalPropertyReportPluginData = // + GlobalPropertyReportPluginData.builder()// + .setReportLabel(expectedReportLabel)// + .build(); - assertEquals(expectedReportLabel, globalPropertyReportPluginData.getReportLabel()); - } + assertEquals(expectedReportLabel, globalPropertyReportPluginData.getReportLabel()); + } - } + } - @Test - @UnitTestMethod(target = GlobalPropertyReportPluginData.class, name = "getIncludedProperties", args = {}) - public void testGetIncludedProperties() { - ReportLabel reportLabel = new SimpleReportLabel("report label"); + @Test + @UnitTestMethod(target = GlobalPropertyReportPluginData.class, name = "getIncludedProperties", args = {}) + public void testGetIncludedProperties() { + ReportLabel reportLabel = new SimpleReportLabel("report label"); - // show the default is non-inclusion - GlobalPropertyReportPluginData personPropertyReportPluginData = // - GlobalPropertyReportPluginData.builder()// - - .setReportLabel(reportLabel)// - .build(); - assertTrue(personPropertyReportPluginData.getIncludedProperties().isEmpty()); - - // show that inclusion alone works - Set expectedGlobalPropertyIds = new LinkedHashSet<>(); - - expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_1_BOOLEAN_MUTABLE); - expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_4_BOOLEAN_IMMUTABLE); - expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_2_INTEGER_MUTABLE); - - GlobalPropertyReportPluginData.Builder builder = GlobalPropertyReportPluginData.builder()// - .setReportLabel(reportLabel);// - - for (GlobalPropertyId globalPropertyId : expectedGlobalPropertyIds) { - builder.includeGlobalProperty(globalPropertyId); - } - - personPropertyReportPluginData = builder.build(); - assertEquals(expectedGlobalPropertyIds, personPropertyReportPluginData.getIncludedProperties()); - - // show that inclusion will override exclusion - expectedGlobalPropertyIds.clear(); - - expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_1_BOOLEAN_MUTABLE); - expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_4_BOOLEAN_IMMUTABLE); - expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_2_INTEGER_MUTABLE); - - builder = GlobalPropertyReportPluginData.builder()// - .setReportLabel(reportLabel);// + // show the default is non-inclusion + GlobalPropertyReportPluginData personPropertyReportPluginData = // + GlobalPropertyReportPluginData.builder()// + + .setReportLabel(reportLabel)// + .build(); + assertTrue(personPropertyReportPluginData.getIncludedProperties().isEmpty()); + + // show that inclusion alone works + Set expectedGlobalPropertyIds = new LinkedHashSet<>(); + + expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_1_BOOLEAN_MUTABLE); + expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_4_BOOLEAN_IMMUTABLE); + expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_2_INTEGER_MUTABLE); + + GlobalPropertyReportPluginData.Builder builder = GlobalPropertyReportPluginData.builder()// + .setReportLabel(reportLabel);// + + for (GlobalPropertyId globalPropertyId : expectedGlobalPropertyIds) { + builder.includeGlobalProperty(globalPropertyId); + } + + personPropertyReportPluginData = builder.build(); + assertEquals(expectedGlobalPropertyIds, personPropertyReportPluginData.getIncludedProperties()); + + // show that inclusion will override exclusion + expectedGlobalPropertyIds.clear(); + + expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_1_BOOLEAN_MUTABLE); + expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_4_BOOLEAN_IMMUTABLE); + expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_2_INTEGER_MUTABLE); + + builder = GlobalPropertyReportPluginData.builder()// + .setReportLabel(reportLabel);// - for (GlobalPropertyId globalPropertyId : expectedGlobalPropertyIds) { - builder.excludeGlobalProperty(globalPropertyId); - builder.includeGlobalProperty(globalPropertyId); - } - - personPropertyReportPluginData = builder.build(); - assertEquals(expectedGlobalPropertyIds, personPropertyReportPluginData.getIncludedProperties()); - - } - - @Test - @UnitTestMethod(target = GlobalPropertyReportPluginData.class, name = "getExcludedProperties", args = {}) - public void testGetExcludedProperties() { - ReportLabel reportLabel = new SimpleReportLabel("report label"); - - // show the default is non-exclusion - GlobalPropertyReportPluginData globalPropertyReportPluginData = // - GlobalPropertyReportPluginData.builder()// - .setReportLabel(reportLabel)// - .build(); - assertTrue(globalPropertyReportPluginData.getExcludedProperties().isEmpty()); - - // show that exclusion alone works - Set expectedGlobalPropertyIds = new LinkedHashSet<>(); - - expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_1_BOOLEAN_MUTABLE); - expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_4_BOOLEAN_IMMUTABLE); - expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_4_BOOLEAN_IMMUTABLE); - - GlobalPropertyReportPluginData.Builder builder = GlobalPropertyReportPluginData.builder()// - .setReportLabel(reportLabel);// - - for (GlobalPropertyId globalPropertyId : expectedGlobalPropertyIds) { - builder.excludeGlobalProperty(globalPropertyId); - } - - globalPropertyReportPluginData = builder.build(); - assertEquals(expectedGlobalPropertyIds, globalPropertyReportPluginData.getExcludedProperties()); - - // show that exclusion will override inclusion - expectedGlobalPropertyIds.clear(); - - expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_1_BOOLEAN_MUTABLE); - expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_4_BOOLEAN_IMMUTABLE); - expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_4_BOOLEAN_IMMUTABLE); - - builder = GlobalPropertyReportPluginData.builder()// - .setReportLabel(reportLabel);// - - for (GlobalPropertyId globalPropertyId : expectedGlobalPropertyIds) { - builder.includeGlobalProperty(globalPropertyId); - builder.excludeGlobalProperty(globalPropertyId); - } - - globalPropertyReportPluginData = builder.build(); - assertEquals(expectedGlobalPropertyIds, globalPropertyReportPluginData.getExcludedProperties()); - - } - - @Test - @UnitTestMethod(target = GlobalPropertyReportPluginData.class, name = "getDefaultInclusionPolicy", args = {}) - public void testGetDefaultInclusionPolicy() { - ReportLabel reportLabel = new SimpleReportLabel("report label"); - - // show the default value is true - GlobalPropertyReportPluginData globalPropertyReportPluginData = // - GlobalPropertyReportPluginData.builder()// - .setReportLabel(reportLabel)// - .build(); - assertEquals(true, globalPropertyReportPluginData.getDefaultInclusionPolicy()); - - globalPropertyReportPluginData = // - GlobalPropertyReportPluginData.builder()// - .setReportLabel(reportLabel)// - .setDefaultInclusion(true)// - .build(); - assertEquals(true, globalPropertyReportPluginData.getDefaultInclusionPolicy()); - - globalPropertyReportPluginData = // - GlobalPropertyReportPluginData.builder()// - .setReportLabel(reportLabel)// - .setDefaultInclusion(false)// - .build(); - assertEquals(false, globalPropertyReportPluginData.getDefaultInclusionPolicy()); - } - - @Test - @UnitTestMethod(target = GlobalPropertyReportPluginData.class, name = "getCloneBuilder", args = {}) - public void testGetCloneBuilder() { - - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(7759639255438669162L); - for (int i = 0; i < 10; i++) { - - // build a GlobalPropertyReportPluginData from random inputs - ReportLabel reportLabel = new SimpleReportLabel(randomGenerator.nextInt()); - - GlobalPropertyReportPluginData.Builder builder = // - GlobalPropertyReportPluginData.builder()// - .setReportLabel(reportLabel); - - for (int j = 0; j < 10; j++) { - TestGlobalPropertyId testGlobalPropertyId = TestGlobalPropertyId - .getRandomGlobalPropertyId(randomGenerator); - if (randomGenerator.nextBoolean()) { - builder.includeGlobalProperty(testGlobalPropertyId); - } else { - builder.excludeGlobalProperty(testGlobalPropertyId); - } - } - - builder.setDefaultInclusion(randomGenerator.nextBoolean()).build(); - - GlobalPropertyReportPluginData globalPropertyReportPluginData = builder.build(); - - // create the clone builder and have it build - GlobalPropertyReportPluginData cloneGlobalPropertyReportPluginData = globalPropertyReportPluginData - .getCloneBuilder().build(); - - // the result should equal the original if the clone builder was - // initialized with the correct state - assertEquals(globalPropertyReportPluginData, cloneGlobalPropertyReportPluginData); - - } - } - - @Test - @UnitTestMethod(target = GlobalPropertyReportPluginData.class, name = "equals", args = { Object.class }) - public void testEquals() { - - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(7376599865331451959L); - for (int i = 0; i < 10; i++) { - // build a GlobalPropertyReportPluginData from the same random - // inputs - GlobalPropertyReportPluginData.Builder builder1 = GlobalPropertyReportPluginData.builder(); - GlobalPropertyReportPluginData.Builder builder2 = GlobalPropertyReportPluginData.builder(); - - ReportLabel reportLabel = new SimpleReportLabel(randomGenerator.nextInt(100)); - builder1.setReportLabel(reportLabel); - builder2.setReportLabel(reportLabel); - - for (int j = 0; j < 10; j++) { - TestGlobalPropertyId testGlobalPropertyId = TestGlobalPropertyId - .getRandomGlobalPropertyId(randomGenerator); - if (randomGenerator.nextBoolean()) { - builder1.includeGlobalProperty(testGlobalPropertyId); - builder2.includeGlobalProperty(testGlobalPropertyId); - } else { - builder1.excludeGlobalProperty(testGlobalPropertyId); - builder2.excludeGlobalProperty(testGlobalPropertyId); - } - } - - boolean defaultInclusion = randomGenerator.nextBoolean(); - builder1.setDefaultInclusion(defaultInclusion).build(); - builder2.setDefaultInclusion(defaultInclusion).build(); - - GlobalPropertyReportPluginData globalPropertyReportPluginData1 = builder1.build(); - GlobalPropertyReportPluginData globalPropertyReportPluginData2 = builder2.build(); - - assertEquals(globalPropertyReportPluginData1, globalPropertyReportPluginData2); - - // show that plugin datas with different inputs are not equal - - // change the default inclusion - globalPropertyReportPluginData2 = // - globalPropertyReportPluginData1.getCloneBuilder()// - .setDefaultInclusion(!defaultInclusion)// - .build(); - assertNotEquals(globalPropertyReportPluginData2, globalPropertyReportPluginData1); - - // change the report label - reportLabel = new SimpleReportLabel(1000); - globalPropertyReportPluginData2 = // - globalPropertyReportPluginData1.getCloneBuilder()// - .setReportLabel(reportLabel)// - .build(); - assertNotEquals(globalPropertyReportPluginData2, globalPropertyReportPluginData1); - - // change an included property id - if (!globalPropertyReportPluginData1.getIncludedProperties().isEmpty()) { - GlobalPropertyId globalPropertyId = globalPropertyReportPluginData1.getIncludedProperties().iterator() - .next(); - globalPropertyReportPluginData2 = // - globalPropertyReportPluginData1.getCloneBuilder()// - .excludeGlobalProperty(globalPropertyId)// - .build(); - assertNotEquals(globalPropertyReportPluginData2, globalPropertyReportPluginData1); - } - // change an excluded property id - if (!globalPropertyReportPluginData1.getExcludedProperties().isEmpty()) { - GlobalPropertyId globalPropertyId = globalPropertyReportPluginData1.getExcludedProperties().iterator() - .next(); - globalPropertyReportPluginData2 = // - globalPropertyReportPluginData1.getCloneBuilder()// - .includeGlobalProperty(globalPropertyId)// - .build(); - assertNotEquals(globalPropertyReportPluginData2, globalPropertyReportPluginData1); - } - - } - - } - - @Test - @UnitTestMethod(target = GlobalPropertyReportPluginData.class, name = "hashCode", args = {}) - public void testHashCode() { - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(8483458328908100435L); - - Set observedHashCodes = new LinkedHashSet<>(); - for (int i = 0; i < 50; i++) { - // build a GlobalPropertyReportPluginData from the same random - // inputs - GlobalPropertyReportPluginData.Builder builder1 = GlobalPropertyReportPluginData.builder(); - GlobalPropertyReportPluginData.Builder builder2 = GlobalPropertyReportPluginData.builder(); - - ReportLabel reportLabel = new SimpleReportLabel(randomGenerator.nextInt(100)); - builder1.setReportLabel(reportLabel); - builder2.setReportLabel(reportLabel); - - for (int j = 0; j < 10; j++) { - TestGlobalPropertyId testGlobalPropertyId = TestGlobalPropertyId - .getRandomGlobalPropertyId(randomGenerator); - if (randomGenerator.nextBoolean()) { - builder1.includeGlobalProperty(testGlobalPropertyId); - builder2.includeGlobalProperty(testGlobalPropertyId); - } else { - builder1.excludeGlobalProperty(testGlobalPropertyId); - builder2.excludeGlobalProperty(testGlobalPropertyId); - } - } - - boolean defaultInclusion = randomGenerator.nextBoolean(); - builder1.setDefaultInclusion(defaultInclusion).build(); - builder2.setDefaultInclusion(defaultInclusion).build(); - - GlobalPropertyReportPluginData globalPropertyReportPluginData1 = builder1.build(); - GlobalPropertyReportPluginData globalPropertyReportPluginData2 = builder2.build(); - - // show that the hash code is stable - int hashCode = globalPropertyReportPluginData1.hashCode(); - assertEquals(hashCode, globalPropertyReportPluginData1.hashCode()); - assertEquals(hashCode, globalPropertyReportPluginData1.hashCode()); - assertEquals(hashCode, globalPropertyReportPluginData1.hashCode()); - assertEquals(hashCode, globalPropertyReportPluginData1.hashCode()); - - // show that equal objects have equal hash codes - assertEquals(globalPropertyReportPluginData1.hashCode(), globalPropertyReportPluginData2.hashCode()); - - // collect the hashcode - observedHashCodes.add(globalPropertyReportPluginData1.hashCode()); - } - - /* - * The hash codes should be dispersed -- we only show that they are unique - * values -- this is dependent on the random seed - */ - assertEquals(50, observedHashCodes.size()); - - } - - @Test - @UnitTestMethod(target = GlobalPropertyReportPluginData.class, name = "toString", args = {}) - public void testToString() { - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(7759639255438669162L); - for (int i = 0; i < 10; i++) { - - // build a GlobalPropertyReportPluginData from random inputs - ReportLabel reportLabel = new SimpleReportLabel(randomGenerator.nextInt()); - - GlobalPropertyReportPluginData.Builder builder = // - GlobalPropertyReportPluginData.builder()// - .setReportLabel(reportLabel); - - StringBuilder sb = new StringBuilder(); - - sb.append("GlobalPropertyReportPluginData [data=").append("Data [reportLabel=").append(reportLabel) - .append(", includedProperties="); - - Set includedProperties = new LinkedHashSet<>(); - Set excludedProperties = new LinkedHashSet<>(); - - for (int j = 0; j < 10; j++) { - TestGlobalPropertyId testGlobalPropertyId = TestGlobalPropertyId - .getRandomGlobalPropertyId(randomGenerator); - if (randomGenerator.nextBoolean()) { - builder.includeGlobalProperty(testGlobalPropertyId); - includedProperties.add(testGlobalPropertyId); - excludedProperties.remove(testGlobalPropertyId); - } else { - builder.excludeGlobalProperty(testGlobalPropertyId); - excludedProperties.add(testGlobalPropertyId); - includedProperties.remove(testGlobalPropertyId); - } - } - - boolean defaultInclusionPolicy = randomGenerator.nextBoolean(); - builder.setDefaultInclusion(defaultInclusionPolicy).build(); - - sb.append(includedProperties).append(", excludedProperties=").append(excludedProperties) - .append(", defaultInclusionPolicy=").append(defaultInclusionPolicy).append(", locked=").append(true) - .append("]").append("]"); - - GlobalPropertyReportPluginData globalPropertyReportPluginData = builder.build(); - - assertEquals(sb.toString(), globalPropertyReportPluginData.toString()); - - } - } + for (GlobalPropertyId globalPropertyId : expectedGlobalPropertyIds) { + builder.excludeGlobalProperty(globalPropertyId); + builder.includeGlobalProperty(globalPropertyId); + } + + personPropertyReportPluginData = builder.build(); + assertEquals(expectedGlobalPropertyIds, personPropertyReportPluginData.getIncludedProperties()); + + } + + @Test + @UnitTestMethod(target = GlobalPropertyReportPluginData.class, name = "getExcludedProperties", args = {}) + public void testGetExcludedProperties() { + ReportLabel reportLabel = new SimpleReportLabel("report label"); + + // show the default is non-exclusion + GlobalPropertyReportPluginData globalPropertyReportPluginData = // + GlobalPropertyReportPluginData.builder()// + .setReportLabel(reportLabel)// + .build(); + assertTrue(globalPropertyReportPluginData.getExcludedProperties().isEmpty()); + + // show that exclusion alone works + Set expectedGlobalPropertyIds = new LinkedHashSet<>(); + + expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_1_BOOLEAN_MUTABLE); + expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_4_BOOLEAN_IMMUTABLE); + expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_4_BOOLEAN_IMMUTABLE); + + GlobalPropertyReportPluginData.Builder builder = GlobalPropertyReportPluginData.builder()// + .setReportLabel(reportLabel);// + + for (GlobalPropertyId globalPropertyId : expectedGlobalPropertyIds) { + builder.excludeGlobalProperty(globalPropertyId); + } + + globalPropertyReportPluginData = builder.build(); + assertEquals(expectedGlobalPropertyIds, globalPropertyReportPluginData.getExcludedProperties()); + + // show that exclusion will override inclusion + expectedGlobalPropertyIds.clear(); + + expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_1_BOOLEAN_MUTABLE); + expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_4_BOOLEAN_IMMUTABLE); + expectedGlobalPropertyIds.add(TestGlobalPropertyId.GLOBAL_PROPERTY_4_BOOLEAN_IMMUTABLE); + + builder = GlobalPropertyReportPluginData.builder()// + .setReportLabel(reportLabel);// + + for (GlobalPropertyId globalPropertyId : expectedGlobalPropertyIds) { + builder.includeGlobalProperty(globalPropertyId); + builder.excludeGlobalProperty(globalPropertyId); + } + + globalPropertyReportPluginData = builder.build(); + assertEquals(expectedGlobalPropertyIds, globalPropertyReportPluginData.getExcludedProperties()); + + } + + @Test + @UnitTestMethod(target = GlobalPropertyReportPluginData.class, name = "getDefaultInclusionPolicy", args = {}) + public void testGetDefaultInclusionPolicy() { + ReportLabel reportLabel = new SimpleReportLabel("report label"); + + // show the default value is true + GlobalPropertyReportPluginData globalPropertyReportPluginData = // + GlobalPropertyReportPluginData.builder()// + .setReportLabel(reportLabel)// + .build(); + assertEquals(true, globalPropertyReportPluginData.getDefaultInclusionPolicy()); + + globalPropertyReportPluginData = // + GlobalPropertyReportPluginData.builder()// + .setReportLabel(reportLabel)// + .setDefaultInclusion(true)// + .build(); + assertEquals(true, globalPropertyReportPluginData.getDefaultInclusionPolicy()); + + globalPropertyReportPluginData = // + GlobalPropertyReportPluginData.builder()// + .setReportLabel(reportLabel)// + .setDefaultInclusion(false)// + .build(); + assertEquals(false, globalPropertyReportPluginData.getDefaultInclusionPolicy()); + } + + @Test + @UnitTestMethod(target = GlobalPropertyReportPluginData.class, name = "getCloneBuilder", args = {}) + public void testGetCloneBuilder() { + + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(7759639255438669162L); + + // build a GlobalPropertyReportPluginData from random inputs + ReportLabel reportLabel = new SimpleReportLabel(randomGenerator.nextInt()); + + GlobalPropertyReportPluginData.Builder builder = // + GlobalPropertyReportPluginData.builder()// + .setReportLabel(reportLabel); + + builder.includeGlobalProperty(TestGlobalPropertyId.GLOBAL_PROPERTY_1_BOOLEAN_MUTABLE); + builder.includeGlobalProperty(TestGlobalPropertyId.GLOBAL_PROPERTY_2_INTEGER_MUTABLE); + builder.excludeGlobalProperty(TestGlobalPropertyId.GLOBAL_PROPERTY_3_DOUBLE_MUTABLE); + builder.excludeGlobalProperty(TestGlobalPropertyId.GLOBAL_PROPERTY_4_BOOLEAN_IMMUTABLE); + + builder.setDefaultInclusion(true).build(); + + GlobalPropertyReportPluginData globalPropertyReportPluginData = builder.build(); + + // show that the returned clone builder will build an identical instance if no + // mutations are made + GlobalPropertyReportPluginData.Builder cloneBuilder = globalPropertyReportPluginData.getCloneBuilder(); + assertNotNull(cloneBuilder); + assertEquals(globalPropertyReportPluginData, cloneBuilder.build()); + + // show that the clone builder builds a distinct instance if any mutation is + // made + + // includeGlobalProperty + cloneBuilder = globalPropertyReportPluginData.getCloneBuilder(); + cloneBuilder.includeGlobalProperty(TestGlobalPropertyId.GLOBAL_PROPERTY_3_DOUBLE_MUTABLE); + assertNotEquals(globalPropertyReportPluginData, cloneBuilder.build()); + + // excludeGlobalProperty + cloneBuilder = globalPropertyReportPluginData.getCloneBuilder(); + cloneBuilder.excludeGlobalProperty(TestGlobalPropertyId.GLOBAL_PROPERTY_1_BOOLEAN_MUTABLE); + assertNotEquals(globalPropertyReportPluginData, cloneBuilder.build()); + + // setDefaultInclusion + cloneBuilder = globalPropertyReportPluginData.getCloneBuilder(); + cloneBuilder.setDefaultInclusion(false); + assertNotEquals(globalPropertyReportPluginData, cloneBuilder.build()); + + // setDefaultInclusion + cloneBuilder = globalPropertyReportPluginData.getCloneBuilder(); + cloneBuilder.setReportLabel(new SimpleReportLabel("asdf")); + assertNotEquals(globalPropertyReportPluginData, cloneBuilder.build()); + + } + + @Test + @UnitTestMethod(target = GlobalPropertyReportPluginData.class, name = "equals", args = { Object.class }) + public void testEquals() { + + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(7376599865331451959L); + for (int i = 0; i < 10; i++) { + // build a GlobalPropertyReportPluginData from the same random + // inputs + GlobalPropertyReportPluginData.Builder builder1 = GlobalPropertyReportPluginData.builder(); + GlobalPropertyReportPluginData.Builder builder2 = GlobalPropertyReportPluginData.builder(); + + ReportLabel reportLabel = new SimpleReportLabel(randomGenerator.nextInt(100)); + builder1.setReportLabel(reportLabel); + builder2.setReportLabel(reportLabel); + + for (int j = 0; j < 10; j++) { + TestGlobalPropertyId testGlobalPropertyId = TestGlobalPropertyId + .getRandomGlobalPropertyId(randomGenerator); + if (randomGenerator.nextBoolean()) { + builder1.includeGlobalProperty(testGlobalPropertyId); + builder2.includeGlobalProperty(testGlobalPropertyId); + } else { + builder1.excludeGlobalProperty(testGlobalPropertyId); + builder2.excludeGlobalProperty(testGlobalPropertyId); + } + } + + boolean defaultInclusion = randomGenerator.nextBoolean(); + builder1.setDefaultInclusion(defaultInclusion).build(); + builder2.setDefaultInclusion(defaultInclusion).build(); + + GlobalPropertyReportPluginData globalPropertyReportPluginData1 = builder1.build(); + GlobalPropertyReportPluginData globalPropertyReportPluginData2 = builder2.build(); + + assertEquals(globalPropertyReportPluginData1, globalPropertyReportPluginData2); + + // show that plugin datas with different inputs are not equal + + // change the default inclusion + globalPropertyReportPluginData2 = // + globalPropertyReportPluginData1.getCloneBuilder()// + .setDefaultInclusion(!defaultInclusion)// + .build(); + assertNotEquals(globalPropertyReportPluginData2, globalPropertyReportPluginData1); + + // change the report label + reportLabel = new SimpleReportLabel(1000); + globalPropertyReportPluginData2 = // + globalPropertyReportPluginData1.getCloneBuilder()// + .setReportLabel(reportLabel)// + .build(); + assertNotEquals(globalPropertyReportPluginData2, globalPropertyReportPluginData1); + + // change an included property id + if (!globalPropertyReportPluginData1.getIncludedProperties().isEmpty()) { + GlobalPropertyId globalPropertyId = globalPropertyReportPluginData1.getIncludedProperties().iterator() + .next(); + globalPropertyReportPluginData2 = // + globalPropertyReportPluginData1.getCloneBuilder()// + .excludeGlobalProperty(globalPropertyId)// + .build(); + assertNotEquals(globalPropertyReportPluginData2, globalPropertyReportPluginData1); + } + // change an excluded property id + if (!globalPropertyReportPluginData1.getExcludedProperties().isEmpty()) { + GlobalPropertyId globalPropertyId = globalPropertyReportPluginData1.getExcludedProperties().iterator() + .next(); + globalPropertyReportPluginData2 = // + globalPropertyReportPluginData1.getCloneBuilder()// + .includeGlobalProperty(globalPropertyId)// + .build(); + assertNotEquals(globalPropertyReportPluginData2, globalPropertyReportPluginData1); + } + + } + + } + + @Test + @UnitTestMethod(target = GlobalPropertyReportPluginData.class, name = "hashCode", args = {}) + public void testHashCode() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(8483458328908100435L); + + Set observedHashCodes = new LinkedHashSet<>(); + for (int i = 0; i < 50; i++) { + // build a GlobalPropertyReportPluginData from the same random + // inputs + GlobalPropertyReportPluginData.Builder builder1 = GlobalPropertyReportPluginData.builder(); + GlobalPropertyReportPluginData.Builder builder2 = GlobalPropertyReportPluginData.builder(); + + ReportLabel reportLabel = new SimpleReportLabel(randomGenerator.nextInt(100)); + builder1.setReportLabel(reportLabel); + builder2.setReportLabel(reportLabel); + + for (int j = 0; j < 10; j++) { + TestGlobalPropertyId testGlobalPropertyId = TestGlobalPropertyId + .getRandomGlobalPropertyId(randomGenerator); + if (randomGenerator.nextBoolean()) { + builder1.includeGlobalProperty(testGlobalPropertyId); + builder2.includeGlobalProperty(testGlobalPropertyId); + } else { + builder1.excludeGlobalProperty(testGlobalPropertyId); + builder2.excludeGlobalProperty(testGlobalPropertyId); + } + } + + boolean defaultInclusion = randomGenerator.nextBoolean(); + builder1.setDefaultInclusion(defaultInclusion).build(); + builder2.setDefaultInclusion(defaultInclusion).build(); + + GlobalPropertyReportPluginData globalPropertyReportPluginData1 = builder1.build(); + GlobalPropertyReportPluginData globalPropertyReportPluginData2 = builder2.build(); + + // show that the hash code is stable + int hashCode = globalPropertyReportPluginData1.hashCode(); + assertEquals(hashCode, globalPropertyReportPluginData1.hashCode()); + assertEquals(hashCode, globalPropertyReportPluginData1.hashCode()); + assertEquals(hashCode, globalPropertyReportPluginData1.hashCode()); + assertEquals(hashCode, globalPropertyReportPluginData1.hashCode()); + + // show that equal objects have equal hash codes + assertEquals(globalPropertyReportPluginData1.hashCode(), globalPropertyReportPluginData2.hashCode()); + + // collect the hashcode + observedHashCodes.add(globalPropertyReportPluginData1.hashCode()); + } + + /* + * The hash codes should be dispersed -- we only show that they are unique + * values -- this is dependent on the random seed + */ + assertEquals(50, observedHashCodes.size()); + + } + + @Test + @UnitTestMethod(target = GlobalPropertyReportPluginData.class, name = "toString", args = {}) + public void testToString() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(7759639255438669162L); + for (int i = 0; i < 10; i++) { + + // build a GlobalPropertyReportPluginData from random inputs + ReportLabel reportLabel = new SimpleReportLabel(randomGenerator.nextInt()); + + GlobalPropertyReportPluginData.Builder builder = // + GlobalPropertyReportPluginData.builder()// + .setReportLabel(reportLabel); + + StringBuilder sb = new StringBuilder(); + + sb.append("GlobalPropertyReportPluginData [data=").append("Data [reportLabel=").append(reportLabel) + .append(", includedProperties="); + + Set includedProperties = new LinkedHashSet<>(); + Set excludedProperties = new LinkedHashSet<>(); + + for (int j = 0; j < 10; j++) { + TestGlobalPropertyId testGlobalPropertyId = TestGlobalPropertyId + .getRandomGlobalPropertyId(randomGenerator); + if (randomGenerator.nextBoolean()) { + builder.includeGlobalProperty(testGlobalPropertyId); + includedProperties.add(testGlobalPropertyId); + excludedProperties.remove(testGlobalPropertyId); + } else { + builder.excludeGlobalProperty(testGlobalPropertyId); + excludedProperties.add(testGlobalPropertyId); + includedProperties.remove(testGlobalPropertyId); + } + } + + boolean defaultInclusionPolicy = randomGenerator.nextBoolean(); + builder.setDefaultInclusion(defaultInclusionPolicy).build(); + + sb.append(includedProperties).append(", excludedProperties=").append(excludedProperties) + .append(", defaultInclusionPolicy=").append(defaultInclusionPolicy).append(", locked=").append(true) + .append("]").append("]"); + + GlobalPropertyReportPluginData globalPropertyReportPluginData = builder.build(); + + assertEquals(sb.toString(), globalPropertyReportPluginData.toString()); + + } + } } diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/groups/datamanagers/AT_GroupsPluginData.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/groups/datamanagers/AT_GroupsPluginData.java index 668815c2b..7d5c3f258 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/groups/datamanagers/AT_GroupsPluginData.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/groups/datamanagers/AT_GroupsPluginData.java @@ -22,7 +22,6 @@ import org.apache.commons.math3.util.FastMath; import org.junit.jupiter.api.Test; -import gov.hhs.aspr.ms.gcm.nucleus.PluginData; import gov.hhs.aspr.ms.gcm.plugins.groups.datamanagers.GroupsPluginData.GroupSpecification; import gov.hhs.aspr.ms.gcm.plugins.groups.support.GroupError; import gov.hhs.aspr.ms.gcm.plugins.groups.support.GroupId; @@ -44,1514 +43,1519 @@ public class AT_GroupsPluginData { - @Test - @UnitTestMethod(target = GroupsPluginData.class, name = "builder", args = {}) - public void testBuilder() { - assertNotNull(GroupsPluginData.builder()); - } - - @Test - @UnitTestMethod(target = GroupsPluginData.Builder.class, name = "build", args = {}) - public void testBuild() { - // show that the builder does not return null - assertNotNull(GroupsPluginData.builder().build()); - - // show that the builder clears its state on build invocation - - GroupsPluginData groupInitialData = GroupsPluginData.builder() // - .associatePersonToGroup(new GroupId(0), new PersonId(0))// - .addGroupTypeId(TestGroupTypeId.GROUP_TYPE_1)// - .addGroup(new GroupId(0), TestGroupTypeId.GROUP_TYPE_1)// - .defineGroupProperty(TestGroupTypeId.GROUP_TYPE_1, - TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK, - TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK.getPropertyDefinition())// - .setGroupPropertyValue(new GroupId(0), TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK, - true)// - .build();// - - assertFalse(groupInitialData.getGroupIds().isEmpty()); - assertFalse(groupInitialData.getGroupTypeIds().isEmpty()); - - groupInitialData = GroupsPluginData.builder().build(); - assertTrue(groupInitialData.getGroupIds().isEmpty()); - assertTrue(groupInitialData.getGroupTypeIds().isEmpty()); - - // precondition test: if a person was added to a group that was not - // defined - ContractException contractException = assertThrows(ContractException.class, () -> { - GroupsPluginData.Builder builder = GroupsPluginData.builder(); - builder.associatePersonToGroup(new GroupId(0), new PersonId(0)).build(); - }); - assertEquals(GroupError.UNKNOWN_GROUP_ID, contractException.getErrorType()); - - // precondition test: if a group was added with a group type id that was - // not - // defined - contractException = assertThrows(ContractException.class, () -> { - GroupsPluginData.Builder builder = GroupsPluginData.builder(); - builder.addGroup(new GroupId(0), TestGroupTypeId.GROUP_TYPE_1).build(); - }); - assertEquals(GroupError.UNKNOWN_GROUP_TYPE_ID, contractException.getErrorType()); - - // precondition test: if a group property definition was defined for a - // group - // type id that - // was not defined. - contractException = assertThrows(ContractException.class, () -> { - GroupsPluginData.Builder builder = GroupsPluginData.builder(); - builder.defineGroupProperty(TestGroupTypeId.GROUP_TYPE_1, // - TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK, // - TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK.getPropertyDefinition()// - ).build(); - }); - - assertEquals(GroupError.UNKNOWN_GROUP_TYPE_ID, contractException.getErrorType()); - - // precondition test: if a group property value was set for a group id - // that was - // not - // defined. - contractException = assertThrows(ContractException.class, () -> { - GroupsPluginData.Builder builder = GroupsPluginData.builder(); - builder.addGroupTypeId(TestGroupTypeId.GROUP_TYPE_1); - builder.defineGroupProperty(TestGroupTypeId.GROUP_TYPE_1, - TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK, - TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK.getPropertyDefinition()); - builder.setGroupPropertyValue(new GroupId(0), - TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK, true); - builder.build(); - }); - assertEquals(GroupError.UNKNOWN_GROUP_ID, contractException.getErrorType()); - - // precondition test: if a group property value is added for a group - // property id - // that is - // not associated with the group. - contractException = assertThrows(ContractException.class, () -> { - GroupsPluginData.Builder builder = GroupsPluginData.builder(); - builder.addGroupTypeId(TestGroupTypeId.GROUP_TYPE_1); - builder.defineGroupProperty(TestGroupTypeId.GROUP_TYPE_1, - TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK, - TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK.getPropertyDefinition()); - builder.setGroupPropertyValue(new GroupId(0), - TestGroupPropertyId.GROUP_PROPERTY_1_2_INTEGER_MUTABLE_NO_TRACK, 15); - builder.addGroup(new GroupId(0), TestGroupTypeId.GROUP_TYPE_1); - builder.build(); - }); - assertEquals(PropertyError.UNKNOWN_PROPERTY_ID, contractException.getErrorType()); - - // precondition test: if a group property value is added that is - // incompatible - // with the - // corresponding property definition - contractException = assertThrows(ContractException.class, () -> { - GroupsPluginData.Builder builder = GroupsPluginData.builder(); - builder.addGroupTypeId(TestGroupTypeId.GROUP_TYPE_1); - builder.defineGroupProperty(TestGroupTypeId.GROUP_TYPE_1, - TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK, - TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK.getPropertyDefinition()); - builder.setGroupPropertyValue(new GroupId(0), - TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK, 15); - builder.addGroup(new GroupId(0), TestGroupTypeId.GROUP_TYPE_1); - builder.build(); - }); - assertEquals(PropertyError.INCOMPATIBLE_VALUE, contractException.getErrorType()); - - /* - * precondition test: if a group does not have a group property value assigned - * when the corresponding property definition lacks a default value. - */ - contractException = assertThrows(ContractException.class, () -> { - GroupsPluginData.Builder builder = GroupsPluginData.builder(); - builder.addGroupTypeId(TestGroupTypeId.GROUP_TYPE_1); - builder.defineGroupProperty(TestGroupTypeId.GROUP_TYPE_1, - TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK, - PropertyDefinition.builder().setType(Boolean.class).build()); - builder.addGroup(new GroupId(0), TestGroupTypeId.GROUP_TYPE_1); - builder.build(); - }); - assertEquals(PropertyError.INSUFFICIENT_PROPERTY_VALUE_ASSIGNMENT, contractException.getErrorType()); - - } - - @Test - @UnitTestMethod(target = GroupsPluginData.Builder.class, name = "addGroupTypeId", args = { GroupTypeId.class }) - public void testAddGroupTypeId() { - GroupsPluginData.Builder builder = GroupsPluginData.builder(); - for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { - builder.addGroupTypeId(testGroupTypeId); - builder.addGroupTypeId(testGroupTypeId); - } - GroupsPluginData groupInitialData = builder.build(); - - // show that the group type ids exist in the groupInitialData - assertEquals(EnumSet.allOf(TestGroupTypeId.class), groupInitialData.getGroupTypeIds()); - - // precondition test: if the group type id is null - ContractException contractException = assertThrows(ContractException.class, - () -> GroupsPluginData.builder().addGroupTypeId(null)); - assertEquals(GroupError.NULL_GROUP_TYPE_ID, contractException.getErrorType()); - } - - @Test - @UnitTestMethod(target = GroupsPluginData.Builder.class, name = "addGroup", args = { GroupId.class, - GroupTypeId.class }) - public void testAddGroup() { - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(6428717083105095287L); - GroupsPluginData.Builder builder = GroupsPluginData.builder(); - Map> expectedGroupIds = new LinkedHashMap<>(); - for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { - expectedGroupIds.put(testGroupTypeId, new LinkedHashSet<>()); - builder.addGroupTypeId(testGroupTypeId); - } - - for (int i = 0; i < 100; i++) { - TestGroupTypeId randomGroupTypeId = TestGroupTypeId.getRandomGroupTypeId(randomGenerator); - - GroupId groupId = new GroupId(i*2+1); - builder.addGroup(groupId, randomGroupTypeId); - // adding duplicate group data to show the last value persists - randomGroupTypeId = randomGroupTypeId.next(); - builder.addGroup(groupId, randomGroupTypeId); - expectedGroupIds.get(randomGroupTypeId).add(groupId); - } - - Map> actualGroupIds = new LinkedHashMap<>(); - for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { - actualGroupIds.put(testGroupTypeId, new LinkedHashSet<>()); - } - - GroupsPluginData groupsPluginData = builder.build(); - for (GroupId groupId : groupsPluginData.getGroupIds()) { - GroupTypeId groupTypeId = groupsPluginData.getGroupTypeId(groupId); - actualGroupIds.get(groupTypeId).add(groupId); - } - - // show that the group ids that were added are present in the - // groupInitialData - assertEquals(expectedGroupIds, actualGroupIds); - - // precondition test: if the group id is null - ContractException contractException = assertThrows(ContractException.class, - () -> GroupsPluginData.builder().addGroup(null, TestGroupTypeId.GROUP_TYPE_1)); - assertEquals(GroupError.NULL_GROUP_ID, contractException.getErrorType()); - - // precondition test: if the group type id is null - contractException = assertThrows(ContractException.class, - () -> GroupsPluginData.builder().addGroup(new GroupId(0), null)); - assertEquals(GroupError.NULL_GROUP_TYPE_ID, contractException.getErrorType()); - - } - - @Test - @UnitTestMethod(target = GroupsPluginData.Builder.class, name = "defineGroupProperty", args = { GroupTypeId.class, - GroupPropertyId.class, PropertyDefinition.class }) - public void testDefineGroupProperty() { - GroupsPluginData.Builder builder = GroupsPluginData.builder(); - - for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { - builder.addGroupTypeId(testGroupTypeId); - } - - // showing that duplicate values persist - for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId.values()) { - PropertyDefinition propertyDefinition = testGroupPropertyId.next().getPropertyDefinition(); - builder.defineGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId, - propertyDefinition); - propertyDefinition = testGroupPropertyId.getPropertyDefinition(); - builder.defineGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId, - propertyDefinition); - } - - GroupsPluginData groupInitialData = builder.build(); - - // show that each property definition that was added is present in the - // groupInitialData - for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId.values()) { - PropertyDefinition expectedPropertyDefinition = testGroupPropertyId.getPropertyDefinition(); - PropertyDefinition actualPropertyDefinition = groupInitialData - .getGroupPropertyDefinition(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); - assertEquals(expectedPropertyDefinition, actualPropertyDefinition); - } - - TestGroupTypeId testGroupTypeId = TestGroupTypeId.GROUP_TYPE_1; - TestGroupPropertyId groupPropertyId = TestGroupPropertyId.GROUP_PROPERTY_1_2_INTEGER_MUTABLE_NO_TRACK; - PropertyDefinition propertyDefinition = groupPropertyId.getPropertyDefinition(); - - // precondition test: if the group type id is null - ContractException contractException = assertThrows(ContractException.class, - () -> GroupsPluginData.builder().defineGroupProperty(null, groupPropertyId, propertyDefinition)); - assertEquals(GroupError.NULL_GROUP_TYPE_ID, contractException.getErrorType()); - - // precondition test: if the group property id is null - contractException = assertThrows(ContractException.class, - () -> GroupsPluginData.builder().defineGroupProperty(testGroupTypeId, null, propertyDefinition)); - assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); - - // precondition test: if the property definition is null - contractException = assertThrows(ContractException.class, - () -> GroupsPluginData.builder().defineGroupProperty(testGroupTypeId, groupPropertyId, null)); - assertEquals(PropertyError.NULL_PROPERTY_DEFINITION, contractException.getErrorType()); - } - - @Test - @UnitTestMethod(target = GroupsPluginData.Builder.class, name = "setGroupPropertyValue", args = { GroupId.class, - GroupPropertyId.class, Object.class }) - public void testSetGroupPropertyValue() { - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(206512993284256660L); - - GroupsPluginData.Builder builder = GroupsPluginData.builder(); - - // add in the group types - for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { - builder.addGroupTypeId(testGroupTypeId); - } - - // define the group properties - for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId.values()) { - builder.defineGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId, - testGroupPropertyId.getPropertyDefinition()); - } - - // create a container to hold expected values - Set expectedValues = new LinkedHashSet<>(); - - /* - * Add a few groups and set about half of the property values, leaving the other - * half to be defined by the default values of the corresponding property - * definitions. - */ - TestGroupTypeId testGroupTypeId = TestGroupTypeId.GROUP_TYPE_1; - for (int i = 0; i < 10; i++) { - GroupId groupId = new GroupId(i); - builder.addGroup(groupId, testGroupTypeId); - - Set testGroupPropertyIds = TestGroupPropertyId - .getTestGroupPropertyIds(testGroupTypeId); - for (TestGroupPropertyId testGroupPropertyId : testGroupPropertyIds) { - if (randomGenerator.nextBoolean()) { - Object value = testGroupPropertyId.getRandomPropertyValue(randomGenerator); - builder.setGroupPropertyValue(groupId, testGroupPropertyId, value); - value = testGroupPropertyId.getRandomPropertyValue(randomGenerator); - builder.setGroupPropertyValue(groupId, testGroupPropertyId, value); - expectedValues.add(new MultiKey(groupId, testGroupPropertyId, value)); - } - } - // move to the next group type id - testGroupTypeId = testGroupTypeId.next(); - } - - // build the group initial data - GroupsPluginData groupInitialData = builder.build(); - - // show that the expected group property values are present - Set actualValues = new LinkedHashSet<>(); - for (GroupId groupId : groupInitialData.getGroupIds()) { - for (GroupPropertyValue groupPropertyValue : groupInitialData.getGroupPropertyValues(groupId)) { - MultiKey multiKey = new MultiKey(groupId, groupPropertyValue.groupPropertyId(), - groupPropertyValue.value()); - actualValues.add(multiKey); - } - } - - assertEquals(expectedValues, actualValues); - - TestGroupPropertyId groupPropertyId = TestGroupPropertyId.GROUP_PROPERTY_1_2_INTEGER_MUTABLE_NO_TRACK; - - // precondition test: if the group id is null - ContractException contractException = assertThrows(ContractException.class, - () -> GroupsPluginData.builder().setGroupPropertyValue(null, groupPropertyId, 10)); - assertEquals(GroupError.NULL_GROUP_ID, contractException.getErrorType()); - - // precondition test: if the group property id is null - contractException = assertThrows(ContractException.class, - () -> GroupsPluginData.builder().setGroupPropertyValue(new GroupId(0), null, 10)); - assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); - - // precondition test: if the group property value is null - contractException = assertThrows(ContractException.class, - () -> GroupsPluginData.builder().setGroupPropertyValue(new GroupId(0), groupPropertyId, null)); - assertEquals(PropertyError.NULL_PROPERTY_VALUE, contractException.getErrorType()); - } - - @Test - @UnitTestMethod(target = GroupsPluginData.Builder.class, name = "setNextGroupIdValue", args = { int.class }) - public void testSetNextGroupIdValue() { - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(2784010859295212357L); - - GroupsPluginData.Builder groupPluginDataBuilder = GroupsPluginData.builder(); - for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { - groupPluginDataBuilder.addGroupTypeId(testGroupTypeId); - } - for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId.values()) { - groupPluginDataBuilder.defineGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId, - testGroupPropertyId.getPropertyDefinition()); - } - - int nextGroupId = randomGenerator.nextInt(100); - groupPluginDataBuilder.setNextGroupIdValue(nextGroupId); - - GroupsPluginData pluginData = groupPluginDataBuilder.build(); - - assertEquals(nextGroupId, pluginData.getNextGroupIdValue()); - - // preconditions: - // value is negative - ContractException contractException = assertThrows(ContractException.class, () -> { - GroupsPluginData.builder().setNextGroupIdValue(-1); - }); - - assertEquals(GroupError.NEGATIVE_GROUP_ID, contractException.getErrorType()); - } - - @Test - @UnitTestMethod(target = GroupsPluginData.Builder.class, name = "associatePersonToGroup", args = { GroupId.class, - PersonId.class }) - public void testAssociatePersonToGroup() { - - Random random = new Random(7282493148489771700L); - - Map expectedGroupAssignments = new LinkedHashMap<>(); - - GroupsPluginData.Builder builder = GroupsPluginData.builder(); - // add in the group types - for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { - builder.addGroupTypeId(testGroupTypeId); - } - - // create some people - List personIds = new ArrayList<>(); - for (int i = 0; i < 100; i++) { - personIds.add(i); - } - - /* - * Add a few groups and add to those groups 0 to 9 randomly selected people. - * Record the assignments in the expected data structure. - */ - TestGroupTypeId testGroupTypeId = TestGroupTypeId.GROUP_TYPE_1; - for (int i = 0; i < 20; i++) { - // add the group - - builder.addGroup(new GroupId(i), testGroupTypeId); - testGroupTypeId = testGroupTypeId.next(); - // select some people and add them to the group - Collections.shuffle(personIds, random); - int count = random.nextInt(10); - for (int j = 0; j < count; j++) { - builder.associatePersonToGroup(new GroupId(i), new PersonId(personIds.get(j))); - MultiKey multiKey = new MultiKey(new GroupId(i), new PersonId(personIds.get(j))); - expectedGroupAssignments.putIfAbsent(multiKey, new MutableInteger()); - expectedGroupAssignments.get(multiKey).increment(); - } - } - - // build the group initial data - GroupsPluginData groupsPluginData = builder.build(); - - // show that the group memberships are as expected - Map actualGroupAssignments = new LinkedHashMap<>(); - - for (int i = 0; i < groupsPluginData.getPersonCount(); i++) { - PersonId personId = new PersonId(i); - for (GroupId groupId : groupsPluginData.getGroupsForPerson(personId)) { - MultiKey multiKey = new MultiKey(groupId, personId); - actualGroupAssignments.putIfAbsent(multiKey, new MutableInteger()); - actualGroupAssignments.get(multiKey).increment(); - } - } - - assertEquals(expectedGroupAssignments, actualGroupAssignments); - - // precondition test: if the group id is null - ContractException contractException = assertThrows(ContractException.class, - () -> GroupsPluginData.builder().associatePersonToGroup(null, new PersonId(0))); - assertEquals(GroupError.NULL_GROUP_ID, contractException.getErrorType()); - - // precondition test: if the person id is null - contractException = assertThrows(ContractException.class, - () -> GroupsPluginData.builder().associatePersonToGroup(new GroupId(0), null)); - assertEquals(PersonError.NULL_PERSON_ID, contractException.getErrorType()); - } - - @Test - @UnitTestMethod(target = GroupsPluginData.class, name = "getGroupPropertyDefinition", args = { GroupTypeId.class, - GroupPropertyId.class }) - public void testGetGroupPropertyDefinition() { - - GroupsPluginData.Builder builder = GroupsPluginData.builder(); - - for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { - builder.addGroupTypeId(testGroupTypeId); - } - - for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId.values()) { - - builder.defineGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId, - testGroupPropertyId.getPropertyDefinition()); - } - - GroupsPluginData groupInitialData = builder.build(); - - // show that each property definition that was added is present in the - // groupInitialData - for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId.values()) { - PropertyDefinition expectedPropertyDefinition = testGroupPropertyId.getPropertyDefinition(); - PropertyDefinition actualPropertyDefinition = groupInitialData - .getGroupPropertyDefinition(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); - assertEquals(expectedPropertyDefinition, actualPropertyDefinition); - } - - // precondition tests - - // if the group type id is null - ContractException contractException = assertThrows(ContractException.class, () -> groupInitialData - .getGroupPropertyDefinition(null, TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK)); - assertEquals(GroupError.NULL_GROUP_TYPE_ID, contractException.getErrorType()); - - // if the group type id is unknown - contractException = assertThrows(ContractException.class, - () -> groupInitialData.getGroupPropertyDefinition(TestGroupTypeId.getUnknownGroupTypeId(), - TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK)); - assertEquals(GroupError.UNKNOWN_GROUP_TYPE_ID, contractException.getErrorType()); - - // if the group property id is null - contractException = assertThrows(ContractException.class, - () -> groupInitialData.getGroupPropertyDefinition(TestGroupTypeId.GROUP_TYPE_1, null)); - assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); - - // if the group property id is not associated with the group type id via - // a property definition - contractException = assertThrows(ContractException.class, - () -> groupInitialData.getGroupPropertyDefinition(TestGroupTypeId.GROUP_TYPE_1, - TestGroupPropertyId.getUnknownGroupPropertyId())); - assertEquals(PropertyError.UNKNOWN_PROPERTY_ID, contractException.getErrorType()); - - // if the group property id is not associated with the group type id via - // a property definition - contractException = assertThrows(ContractException.class, - () -> groupInitialData.getGroupPropertyDefinition(TestGroupTypeId.GROUP_TYPE_1, - TestGroupPropertyId.GROUP_PROPERTY_2_1_BOOLEAN_MUTABLE_TRACK)); - assertEquals(PropertyError.UNKNOWN_PROPERTY_ID, contractException.getErrorType()); - - } - - @Test - @UnitTestMethod(target = GroupsPluginData.class, name = "getGroupPropertyIds", args = { GroupTypeId.class }) - public void testGetGroupPropertyIds() { - - GroupsPluginData.Builder builder = GroupsPluginData.builder(); - - for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { - builder.addGroupTypeId(testGroupTypeId); - } - - for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId.values()) { - builder.defineGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId, - testGroupPropertyId.getPropertyDefinition()); - } - - GroupsPluginData groupInitialData = builder.build(); - - // show that the group properties for each group type match expectations - for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { - Set actualGroupPropertyIds = groupInitialData.getGroupPropertyIds(testGroupTypeId); - Set expectedGroupPropertyIds = TestGroupPropertyId - .getTestGroupPropertyIds(testGroupTypeId); - assertEquals(expectedGroupPropertyIds, actualGroupPropertyIds); - } - - // precondition tests - // if the group type id is null - ContractException contractException = assertThrows(ContractException.class, - () -> groupInitialData.getGroupPropertyIds(null)); - assertEquals(GroupError.NULL_GROUP_TYPE_ID, contractException.getErrorType()); - - // if the group type id is unknown - contractException = assertThrows(ContractException.class, - () -> groupInitialData.getGroupPropertyIds(TestGroupTypeId.getUnknownGroupTypeId())); - assertEquals(GroupError.UNKNOWN_GROUP_TYPE_ID, contractException.getErrorType()); - - } - - @Test - @UnitTestMethod(target = GroupsPluginData.class, name = "getGroupPropertyValues", args = { GroupId.class }) - public void testGetGroupPropertyValues() { - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(8435308203966252001L); - - GroupsPluginData.Builder builder = GroupsPluginData.builder(); - - // add in the group types - for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { - builder.addGroupTypeId(testGroupTypeId); - } - - // define the group properties - for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId.values()) { - builder.defineGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId, - testGroupPropertyId.getPropertyDefinition()); - } - - // create a container to hold expected values - Set expectedValues = new LinkedHashSet<>(); - - /* - * Add a few groups and set about half of the property values, leaving the other - * half to be defined by the default values of the corresponding property - * definitions. - */ - int groupCount = 10; - - TestGroupTypeId testGroupTypeId = TestGroupTypeId.GROUP_TYPE_1; - for (int i = 0; i < groupCount; i++) { - GroupId groupId = new GroupId(i); - builder.addGroup(groupId, testGroupTypeId); - - Set testGroupPropertyIds = TestGroupPropertyId - .getTestGroupPropertyIds(testGroupTypeId); - for (TestGroupPropertyId testGroupPropertyId : testGroupPropertyIds) { - if (randomGenerator.nextBoolean()) { - Object value = testGroupPropertyId.getRandomPropertyValue(randomGenerator); - builder.setGroupPropertyValue(groupId, testGroupPropertyId, value); - expectedValues.add(new MultiKey(groupId, testGroupPropertyId, value)); - } - } - // move to the next group type id - testGroupTypeId = testGroupTypeId.next(); - } - - // build the group initial data - GroupsPluginData groupsPluginData = builder.build(); - - // show that the expected group property values are present - Set actualValues = new LinkedHashSet<>(); - for (GroupId groupId : groupsPluginData.getGroupIds()) { - for (GroupPropertyValue groupPropertyValue : groupsPluginData.getGroupPropertyValues(groupId)) { - MultiKey multiKey = new MultiKey(groupId, groupPropertyValue.groupPropertyId(), - groupPropertyValue.value()); - actualValues.add(multiKey); - } - } - - assertEquals(expectedValues, actualValues); - - // precondition tests - - // if the group id is null - ContractException contractException = assertThrows(ContractException.class, - () -> groupsPluginData.getGroupPropertyValues(null)); - assertEquals(GroupError.NULL_GROUP_ID, contractException.getErrorType()); - - // if the group id is unknown - contractException = assertThrows(ContractException.class, - () -> groupsPluginData.getGroupPropertyValues(new GroupId(10000))); - assertEquals(GroupError.UNKNOWN_GROUP_ID, contractException.getErrorType()); - } - - @Test - @UnitTestMethod(target = GroupsPluginData.class, name = "getGroupTypeIds", args = {}) - public void testGetGroupTypeIds() { - GroupsPluginData.Builder builder = GroupsPluginData.builder(); - for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { - builder.addGroupTypeId(testGroupTypeId); - } - GroupsPluginData groupInitialData = builder.build(); - - // show that the group type ids exist in the groupInitialData - assertEquals(EnumSet.allOf(TestGroupTypeId.class), groupInitialData.getGroupTypeIds()); - } - - @Test - @UnitTestMethod(target = GroupsPluginData.class, name = "getGroupIds", args = {}) - public void testGetGroupIds() { - GroupsPluginData.Builder builder = GroupsPluginData.builder(); - int masterGroupId = 0; - Set expectedGroupIds = new LinkedHashSet<>(); - for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { - builder.addGroupTypeId(testGroupTypeId); - - GroupId groupId = new GroupId(masterGroupId++); - builder.addGroup(groupId, testGroupTypeId); - expectedGroupIds.add(groupId); - - groupId = new GroupId(masterGroupId++); - builder.addGroup(groupId, testGroupTypeId); - expectedGroupIds.add(groupId); - } - GroupsPluginData groupInitialData = builder.build(); - - // show that the group ids that were added are present in the - // groupInitialData - assertEquals(expectedGroupIds, new LinkedHashSet<>(groupInitialData.getGroupIds())); - - } - - @Test - @UnitTestMethod(target = GroupsPluginData.class, name = "getGroupsForPerson", args = { PersonId.class }) - public void testGetGroupsForPerson() { - - Random random = new Random(4685636461674441597L); - - Set expectedGroupAssignments = new LinkedHashSet<>(); - - GroupsPluginData.Builder builder = GroupsPluginData.builder(); - // add in the group types - for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { - builder.addGroupTypeId(testGroupTypeId); - } - - // create some people - List people = new ArrayList<>(); - for (int i = 0; i < 100; i++) { - people.add(new PersonId(i)); - } - - /* - * Add a few groups and add to those groups 0 to 9 randomly selected people. - * Record the assignments in the expected data structure. - */ - TestGroupTypeId testGroupTypeId = TestGroupTypeId.GROUP_TYPE_1; - for (int i = 0; i < 20; i++) { - // add the group - GroupId groupId = new GroupId(i); - builder.addGroup(groupId, testGroupTypeId); - - testGroupTypeId = testGroupTypeId.next(); - - // select some people and add them to the group - Collections.shuffle(people, random); - int count = random.nextInt(10); - for (int j = 0; j < count; j++) { - PersonId personId = people.get(j); - builder.associatePersonToGroup(groupId, personId); - MultiKey multiKey = new MultiKey(groupId, personId); - expectedGroupAssignments.add(multiKey); - } - } - - // build the group initial data - GroupsPluginData groupInitialData = builder.build(); - - // show that the group memberships are as expected - Set actualGroupAssignments = new LinkedHashSet<>(); - for (int i = 0; i < groupInitialData.getPersonCount(); i++) { - PersonId personId = new PersonId(i); - for (GroupId groupId : groupInitialData.getGroupsForPerson(personId)) { - MultiKey multiKey = new MultiKey(groupId, personId); - actualGroupAssignments.add(multiKey); - } - } - - assertEquals(expectedGroupAssignments, actualGroupAssignments); - - } - - @Test - @UnitTestMethod(target = GroupsPluginData.class, name = "getGroupTypeId", args = { GroupId.class }) - public void testGetGroupTypeId() { - - GroupsPluginData.Builder builder = GroupsPluginData.builder(); - int masterGroupId = 0; - Map expectedGroupTypes = new LinkedHashMap<>(); - for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { - builder.addGroupTypeId(testGroupTypeId); - - GroupId groupId = new GroupId(masterGroupId++); - builder.addGroup(groupId, testGroupTypeId); - expectedGroupTypes.put(groupId, testGroupTypeId); - - groupId = new GroupId(masterGroupId++); - builder.addGroup(groupId, testGroupTypeId); - expectedGroupTypes.put(groupId, testGroupTypeId); - } - GroupsPluginData groupInitialData = builder.build(); - - for (GroupId groupId : expectedGroupTypes.keySet()) { - GroupTypeId expecctedGroupTypeId = expectedGroupTypes.get(groupId); - GroupTypeId actualGroupTypeId = groupInitialData.getGroupTypeId(groupId); - assertEquals(expecctedGroupTypeId, actualGroupTypeId); - } - - // precondition tests - - // if the group id is null - ContractException contractException = assertThrows(ContractException.class, - () -> groupInitialData.getGroupTypeId(null)); - assertEquals(GroupError.NULL_GROUP_ID, contractException.getErrorType()); - - // if the group id is unknown - contractException = assertThrows(ContractException.class, - () -> groupInitialData.getGroupTypeId(new GroupId(1000000))); - assertEquals(GroupError.UNKNOWN_GROUP_ID, contractException.getErrorType()); - - } - - @Test - @UnitTestMethod(target = GroupsPluginData.class, name = "getCloneBuilder", args = {}) - public void testGetCloneBuilder() { - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(9130589441333999144L); - - GroupsPluginData.Builder groupPluginDataBuilder = GroupsPluginData.builder(); - for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { - groupPluginDataBuilder.addGroupTypeId(testGroupTypeId); - } - for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId.values()) { - groupPluginDataBuilder.defineGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId, - testGroupPropertyId.getPropertyDefinition()); - } - int groupCount = 10; - List groups = new ArrayList<>(); - for (int i = 0; i < groupCount; i++) { - GroupId groupId = new GroupId(i); - groups.add(groupId); - TestGroupTypeId groupTypeId = TestGroupTypeId.getRandomGroupTypeId(randomGenerator); - groupPluginDataBuilder.addGroup(groupId, groupTypeId); - for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId.getTestGroupPropertyIds(groupTypeId)) { - if (randomGenerator.nextBoolean()) { - Object randomPropertyValue = testGroupPropertyId.getRandomPropertyValue(randomGenerator); - groupPluginDataBuilder.setGroupPropertyValue(groupId, testGroupPropertyId, randomPropertyValue); - } - } - } - - int personCount = 100; - - for (int i = 0; i < personCount; i++) { - PersonId personId = new PersonId(i); - int numberOfGroups = randomGenerator.nextInt(5); - Collections.sort(groups); - for (int j = 0; j < numberOfGroups; j++) { - GroupId groupId = groups.get(j); - groupPluginDataBuilder.associatePersonToGroup(groupId, personId); - } - } - GroupsPluginData groupsPluginData = groupPluginDataBuilder.build(); - - PluginData pluginData = groupsPluginData.getCloneBuilder().build(); - - // show that the clone plugin data has the correct type - assertTrue(pluginData instanceof GroupsPluginData); - - GroupsPluginData cloneGroupPluginData = (GroupsPluginData) pluginData; - - // show that the two plugin datas have the same groups - assertEquals(groupsPluginData.getGroupIds(), cloneGroupPluginData.getGroupIds()); - - // show that the two plugin datas have the same group types - assertEquals(groupsPluginData.getGroupTypeIds(), cloneGroupPluginData.getGroupTypeIds()); - - // show that the two plugin datas have the same group property ids - for (GroupTypeId groupTypeId : groupsPluginData.getGroupTypeIds()) { - assertEquals(groupsPluginData.getGroupPropertyIds(groupTypeId), - cloneGroupPluginData.getGroupPropertyIds(groupTypeId)); - // show that the two plugin datas have the same group property - // definitions - for (GroupPropertyId groupPropertyId : groupsPluginData.getGroupPropertyIds(groupTypeId)) { - PropertyDefinition expectedPropertyDefinition = groupsPluginData.getGroupPropertyDefinition(groupTypeId, - groupPropertyId); - PropertyDefinition actualPropertyDefinition = cloneGroupPluginData - .getGroupPropertyDefinition(groupTypeId, groupPropertyId); - assertEquals(expectedPropertyDefinition, actualPropertyDefinition); - } - } - - // show that the two plugin datas have the same groups - assertEquals(groupsPluginData.getGroupIds(), cloneGroupPluginData.getGroupIds()); - - // show that the groups have the same types - for (GroupId groupId : groupsPluginData.getGroupIds()) { - GroupTypeId expectedGroupTypeId = groupsPluginData.getGroupTypeId(groupId); - GroupTypeId actualGroupTypeId = cloneGroupPluginData.getGroupTypeId(groupId); - assertEquals(expectedGroupTypeId, actualGroupTypeId); - // show that the groups have the property values - Map expectedPropertyValues = new LinkedHashMap<>(); - Map actualPropertyValues = new LinkedHashMap<>(); - for (GroupPropertyValue groupPropertyValue : groupsPluginData.getGroupPropertyValues(groupId)) { - GroupPropertyId groupPropertyId = groupPropertyValue.groupPropertyId(); - Object value = groupPropertyValue.value(); - expectedPropertyValues.put(groupPropertyId, value); - } - for (GroupPropertyValue groupPropertyValue : cloneGroupPluginData.getGroupPropertyValues(groupId)) { - GroupPropertyId groupPropertyId = groupPropertyValue.groupPropertyId(); - Object value = groupPropertyValue.value(); - actualPropertyValues.put(groupPropertyId, value); - } - assertEquals(expectedPropertyValues, actualPropertyValues); - - // show that the groups have the members - assertEquals(groupsPluginData.getPersonCount(), cloneGroupPluginData.getPersonCount()); - for (int i = 0; i < groupsPluginData.getPersonCount(); i++) { - PersonId personId = new PersonId(i); - Set expectedGroups = new LinkedHashSet<>(groupsPluginData.getGroupsForPerson(personId)); - Set actualGroups = new LinkedHashSet<>(cloneGroupPluginData.getGroupsForPerson(personId)); - assertEquals(expectedGroups, actualGroups); - } - } - } - - @Test - @UnitTestMethod(target = GroupsPluginData.class, name = "getPersonCount", args = {}) - public void testGetPersonCount() { - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(7910883193674079461L); - - GroupsPluginData.Builder groupPluginDataBuilder = GroupsPluginData.builder(); - for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { - groupPluginDataBuilder.addGroupTypeId(testGroupTypeId); - } - for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId.values()) { - groupPluginDataBuilder.defineGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId, - testGroupPropertyId.getPropertyDefinition()); - } - int groupCount = 10; - List groups = new ArrayList<>(); - for (int i = 0; i < groupCount; i++) { - GroupId groupId = new GroupId(i); - groups.add(groupId); - TestGroupTypeId groupTypeId = TestGroupTypeId.getRandomGroupTypeId(randomGenerator); - groupPluginDataBuilder.addGroup(groupId, groupTypeId); - for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId.getTestGroupPropertyIds(groupTypeId)) { - if (randomGenerator.nextBoolean()) { - Object randomPropertyValue = testGroupPropertyId.getRandomPropertyValue(randomGenerator); - groupPluginDataBuilder.setGroupPropertyValue(groupId, testGroupPropertyId, randomPropertyValue); - } - } - } - - int totalPeopleCount = 0; - for (GroupId groupId : groups) { - int peopleCount = randomGenerator.nextInt(100); - int currTotalPeopleCount = totalPeopleCount; - totalPeopleCount += peopleCount; - for (int i = currTotalPeopleCount; i < totalPeopleCount; i++) { - PersonId personId = new PersonId(i); - groupPluginDataBuilder.associatePersonToGroup(groupId, personId); - } - } - - GroupsPluginData groupsPluginData = groupPluginDataBuilder.build(); - - // show that the total people count is NOT 0 - assertTrue(totalPeopleCount > 0); - - // show that the group person count is equal to the total people count - assertEquals(totalPeopleCount, groupsPluginData.getPersonCount()); - } - - @Test - @UnitTestMethod(target = GroupsPluginData.class, name = "getNextGroupIdValue", args = {}) - public void testGetNextGroupIdValue() { - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(2784010859295212357L); - - GroupsPluginData.Builder groupPluginDataBuilder = GroupsPluginData.builder(); - for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { - groupPluginDataBuilder.addGroupTypeId(testGroupTypeId); - } - for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId.values()) { - groupPluginDataBuilder.defineGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId, - testGroupPropertyId.getPropertyDefinition()); - } - int groupCount = 10; - List groups = new ArrayList<>(); - for (int i = 0; i < groupCount; i++) { - GroupId groupId = new GroupId(i); - groups.add(groupId); - TestGroupTypeId groupTypeId = TestGroupTypeId.getRandomGroupTypeId(randomGenerator); - groupPluginDataBuilder.addGroup(groupId, groupTypeId); - for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId.getTestGroupPropertyIds(groupTypeId)) { - if (randomGenerator.nextBoolean()) { - Object randomPropertyValue = testGroupPropertyId.getRandomPropertyValue(randomGenerator); - groupPluginDataBuilder.setGroupPropertyValue(groupId, testGroupPropertyId, randomPropertyValue); - } - } - } - - GroupsPluginData pluginData = groupPluginDataBuilder.build(); - - assertEquals(groupCount, pluginData.getNextGroupIdValue()); - - pluginData = groupPluginDataBuilder.setNextGroupIdValue(groupCount + 10).build(); - - assertEquals(groupCount + 10, pluginData.getNextGroupIdValue()); - } - - @Test - @UnitTestMethod(target = GroupsPluginData.class, name = "getGroupCount", args = {}) - public void testGetGroupCount() { - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(669154335225022584L); - - for (int i = 0; i < 10; i++) { - GroupsPluginData.Builder groupPluginDataBuilder = GroupsPluginData.builder(); - - for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.getShuffledTestGroupTypeIds(randomGenerator)) { - groupPluginDataBuilder.addGroupTypeId(testGroupTypeId); - } - - int groupCount = randomGenerator.nextInt(50) + 10; - List groups = new ArrayList<>(); - for (int j = 0; j < groupCount; j++) { - GroupId groupId = new GroupId(j); - groups.add(groupId); - TestGroupTypeId groupTypeId = TestGroupTypeId.getRandomGroupTypeId(randomGenerator); - groupPluginDataBuilder.addGroup(groupId, groupTypeId); - } - - int totalPeopleCount = 0; - for (GroupId groupId : groups) { - int peopleCount = randomGenerator.nextInt(100); - int currTotalPeopleCount = totalPeopleCount; - totalPeopleCount += peopleCount; - for (int j = currTotalPeopleCount; j < totalPeopleCount; j++) { - PersonId personId = new PersonId(j); - groupPluginDataBuilder.associatePersonToGroup(groupId, personId); - } - } - - GroupsPluginData pluginData = groupPluginDataBuilder.build(); - - assertEquals(groupCount, pluginData.getGroupCount()); - } - } - - @Test - @UnitTestMethod(target = GroupsPluginData.class, name = "getPeopleForGroup", args = { GroupId.class }) - public void testGetPeopleForGroup() { - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(4825370554814301264L); - - for (int i = 0; i < 10; i++) { - GroupsPluginData.Builder groupPluginDataBuilder = GroupsPluginData.builder(); - - List> groupToPeopleMemberships = new ArrayList<>(); - - for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.getShuffledTestGroupTypeIds(randomGenerator)) { - groupPluginDataBuilder.addGroupTypeId(testGroupTypeId); - } - - int groupCount = 10; - List groups = new ArrayList<>(); - for (int j = 0; j < groupCount; j++) { - GroupId groupId = new GroupId(j); - groups.add(groupId); - TestGroupTypeId groupTypeId = TestGroupTypeId.getRandomGroupTypeId(randomGenerator); - groupPluginDataBuilder.addGroup(groupId, groupTypeId); - } - - int totalPeopleCount = 0; - for (GroupId groupId : groups) { - int peopleCount = randomGenerator.nextInt(100); - int currTotalPeopleCount = totalPeopleCount; - totalPeopleCount += peopleCount; - for (int j = currTotalPeopleCount; j < totalPeopleCount; j++) { - PersonId personId = new PersonId(j); - groupPluginDataBuilder.associatePersonToGroup(groupId, personId); - - int groupIndex = groupId.getValue(); - - while (groupIndex >= groupToPeopleMemberships.size()) { - groupToPeopleMemberships.add(null); - } - - List people = groupToPeopleMemberships.get(groupIndex); - if (people == null) { - people = new ArrayList<>(); - groupToPeopleMemberships.set(groupIndex, people); - } - - people.add(personId); - } - } - - GroupsPluginData pluginData = groupPluginDataBuilder.build(); - - for (int j = 0; j < groupToPeopleMemberships.size(); j++) { - List personIds = groupToPeopleMemberships.get(j); - - if (personIds == null) { - assertEquals(Collections.unmodifiableList(new ArrayList<>()), - pluginData.getPeopleForGroup(new GroupId(j))); - } else { - assertEquals(personIds, pluginData.getPeopleForGroup(new GroupId(j))); - } - } - } - } - - @Test - @UnitTestMethod(target = GroupsPluginData.class, name = "getGroupPropertyDefinitions", args = {}) - public void testGetPropertyDefinitions() { - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(9107021630953219230L); - - for (int i = 0; i < 10; i++) { - GroupsPluginData.Builder groupPluginDataBuilder = GroupsPluginData.builder(); - - Map> groupPropertyDefinitions = new LinkedHashMap<>(); - - for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.getShuffledTestGroupTypeIds(randomGenerator)) { - groupPluginDataBuilder.addGroupTypeId(testGroupTypeId); - - for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId - .getShuffledTestGroupPropertyIds(testGroupTypeId, randomGenerator)) { - groupPluginDataBuilder.defineGroupProperty(testGroupPropertyId.getTestGroupTypeId(), - testGroupPropertyId, testGroupPropertyId.getPropertyDefinition()); - - Map propertyDefinitionsMap = groupPropertyDefinitions - .get(testGroupTypeId); - if (propertyDefinitionsMap == null) { - propertyDefinitionsMap = new LinkedHashMap<>(); - groupPropertyDefinitions.put(testGroupTypeId, propertyDefinitionsMap); - } - propertyDefinitionsMap.put(testGroupPropertyId, testGroupPropertyId.getPropertyDefinition()); - } - } - - GroupsPluginData pluginData = groupPluginDataBuilder.build(); - - assertEquals(groupPropertyDefinitions, pluginData.getGroupPropertyDefinitions()); - } - } - - @Test - @UnitTestMethod(target = GroupsPluginData.class, name = "hashCode", args = {}) - public void testHashCode() { - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(386194196593528301L); - - List people = new ArrayList<>(); - - for (int i = 0; i < 100; i++) { - people.add(new PersonId(i)); - } - - long sameSeed = randomGenerator.nextLong(); - GroupsPluginData groupsPluginData1 = GroupsTestPluginFactory.getStandardGroupsPluginData(2, 10, people, - sameSeed); - GroupsPluginData groupsPluginData2 = GroupsTestPluginFactory.getStandardGroupsPluginData(2, 10, people, - randomGenerator.nextLong()); - GroupsPluginData groupsPluginData3 = GroupsTestPluginFactory.getStandardGroupsPluginData(2, 5, people, - sameSeed); - GroupsPluginData groupsPluginData4 = GroupsTestPluginFactory.getStandardGroupsPluginData(2, 5, people, - randomGenerator.nextLong()); - GroupsPluginData groupsPluginData5 = GroupsTestPluginFactory.getStandardGroupsPluginData(1, 10, people, - sameSeed); - GroupsPluginData groupsPluginData6 = GroupsTestPluginFactory.getStandardGroupsPluginData(3, 10, people, - randomGenerator.nextLong()); - GroupsPluginData groupsPluginData7 = GroupsTestPluginFactory.getStandardGroupsPluginData(3, 5, people, - sameSeed); - GroupsPluginData groupsPluginData8 = GroupsTestPluginFactory.getStandardGroupsPluginData(3, 5, people, - randomGenerator.nextLong()); - GroupsPluginData groupsPluginData9 = GroupsTestPluginFactory.getStandardGroupsPluginData(2, 10, people, - sameSeed); - - assertEquals(groupsPluginData1.hashCode(), groupsPluginData1.hashCode()); - - assertNotEquals(groupsPluginData1.hashCode(), groupsPluginData2.hashCode()); - assertNotEquals(groupsPluginData1.hashCode(), groupsPluginData3.hashCode()); - assertNotEquals(groupsPluginData1.hashCode(), groupsPluginData4.hashCode()); - assertNotEquals(groupsPluginData1.hashCode(), groupsPluginData5.hashCode()); - assertNotEquals(groupsPluginData1.hashCode(), groupsPluginData6.hashCode()); - assertNotEquals(groupsPluginData1.hashCode(), groupsPluginData7.hashCode()); - assertNotEquals(groupsPluginData1.hashCode(), groupsPluginData8.hashCode()); - - assertNotEquals(groupsPluginData1.hashCode(), groupsPluginData3.hashCode()); - assertNotEquals(groupsPluginData1.hashCode(), groupsPluginData4.hashCode()); - assertNotEquals(groupsPluginData1.hashCode(), groupsPluginData5.hashCode()); - assertNotEquals(groupsPluginData1.hashCode(), groupsPluginData6.hashCode()); - assertNotEquals(groupsPluginData1.hashCode(), groupsPluginData7.hashCode()); - assertNotEquals(groupsPluginData1.hashCode(), groupsPluginData8.hashCode()); - - assertNotEquals(groupsPluginData3.hashCode(), groupsPluginData4.hashCode()); - assertNotEquals(groupsPluginData3.hashCode(), groupsPluginData5.hashCode()); - assertNotEquals(groupsPluginData3.hashCode(), groupsPluginData6.hashCode()); - assertNotEquals(groupsPluginData3.hashCode(), groupsPluginData7.hashCode()); - assertNotEquals(groupsPluginData3.hashCode(), groupsPluginData8.hashCode()); - - assertNotEquals(groupsPluginData4.hashCode(), groupsPluginData5.hashCode()); - assertNotEquals(groupsPluginData4.hashCode(), groupsPluginData6.hashCode()); - assertNotEquals(groupsPluginData4.hashCode(), groupsPluginData7.hashCode()); - assertNotEquals(groupsPluginData4.hashCode(), groupsPluginData8.hashCode()); - - assertNotEquals(groupsPluginData5.hashCode(), groupsPluginData6.hashCode()); - assertNotEquals(groupsPluginData5.hashCode(), groupsPluginData7.hashCode()); - assertNotEquals(groupsPluginData5.hashCode(), groupsPluginData8.hashCode()); - - assertNotEquals(groupsPluginData6.hashCode(), groupsPluginData7.hashCode()); - assertNotEquals(groupsPluginData6.hashCode(), groupsPluginData8.hashCode()); - - assertNotEquals(groupsPluginData7.hashCode(), groupsPluginData8.hashCode()); - - assertEquals(groupsPluginData1.hashCode(), groupsPluginData9.hashCode()); - } - - @Test - @UnitTestMethod(target = GroupsPluginData.class, name = "equals", args = { Object.class }) - public void testEquals() { - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(1974882207275712576L); - - List people = new ArrayList<>(); - - for (int i = 0; i < 100; i++) { - people.add(new PersonId(i)); - } - - long sameSeed = randomGenerator.nextLong(); - GroupsPluginData groupsPluginData1 = GroupsTestPluginFactory.getStandardGroupsPluginData(2, 10, people, - sameSeed); - GroupsPluginData groupsPluginData2 = GroupsTestPluginFactory.getStandardGroupsPluginData(2, 10, people, - randomGenerator.nextLong()); - GroupsPluginData groupsPluginData3 = GroupsTestPluginFactory.getStandardGroupsPluginData(2, 5, people, - sameSeed); - GroupsPluginData groupsPluginData4 = GroupsTestPluginFactory.getStandardGroupsPluginData(2, 5, people, - randomGenerator.nextLong()); - GroupsPluginData groupsPluginData5 = GroupsTestPluginFactory.getStandardGroupsPluginData(1, 10, people, - sameSeed); - GroupsPluginData groupsPluginData6 = GroupsTestPluginFactory.getStandardGroupsPluginData(3, 10, people, - randomGenerator.nextLong()); - GroupsPluginData groupsPluginData7 = GroupsTestPluginFactory.getStandardGroupsPluginData(3, 5, people, - sameSeed); - GroupsPluginData groupsPluginData8 = GroupsTestPluginFactory.getStandardGroupsPluginData(3, 5, people, - randomGenerator.nextLong()); - GroupsPluginData groupsPluginData9 = GroupsTestPluginFactory.getStandardGroupsPluginData(2, 10, people, - sameSeed); - - assertEquals(groupsPluginData1, groupsPluginData1); - - assertNotEquals(groupsPluginData1, null); - - assertNotEquals(groupsPluginData1, new Object()); - - assertNotEquals(groupsPluginData1, groupsPluginData2); - assertNotEquals(groupsPluginData1, groupsPluginData3); - assertNotEquals(groupsPluginData1, groupsPluginData4); - assertNotEquals(groupsPluginData1, groupsPluginData5); - assertNotEquals(groupsPluginData1, groupsPluginData6); - assertNotEquals(groupsPluginData1, groupsPluginData7); - assertNotEquals(groupsPluginData1, groupsPluginData8); - - assertNotEquals(groupsPluginData1, groupsPluginData3); - assertNotEquals(groupsPluginData1, groupsPluginData4); - assertNotEquals(groupsPluginData1, groupsPluginData5); - assertNotEquals(groupsPluginData1, groupsPluginData6); - assertNotEquals(groupsPluginData1, groupsPluginData7); - assertNotEquals(groupsPluginData1, groupsPluginData8); - - assertNotEquals(groupsPluginData3, groupsPluginData4); - assertNotEquals(groupsPluginData3, groupsPluginData5); - assertNotEquals(groupsPluginData3, groupsPluginData6); - assertNotEquals(groupsPluginData3, groupsPluginData7); - assertNotEquals(groupsPluginData3, groupsPluginData8); - - assertNotEquals(groupsPluginData4, groupsPluginData5); - assertNotEquals(groupsPluginData4, groupsPluginData6); - assertNotEquals(groupsPluginData4, groupsPluginData7); - assertNotEquals(groupsPluginData4, groupsPluginData8); - - assertNotEquals(groupsPluginData5, groupsPluginData6); - assertNotEquals(groupsPluginData5, groupsPluginData7); - assertNotEquals(groupsPluginData5, groupsPluginData8); - - assertNotEquals(groupsPluginData6, groupsPluginData7); - assertNotEquals(groupsPluginData6, groupsPluginData8); - - assertNotEquals(groupsPluginData7, groupsPluginData8); - - assertEquals(groupsPluginData1, groupsPluginData9); - - } - - @Test - @UnitTestMethod(target = GroupsPluginData.class, name = "toString", args = {}) - public void testToString() { - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(523034536833646355L); - - for (int i = 0; i < 10; i++) { - GroupsPluginData.Builder groupPluginDataBuilder = GroupsPluginData.builder(); - - int nextGroupIdValue = -1; - Map> groupPropertyDefinitions = new LinkedHashMap<>(); - Set groupTypeIds = new LinkedHashSet<>(); - List> personToGroupsMemberships = new ArrayList<>(); - List> groupToPeopleMemberships = new ArrayList<>(); - List groupSpecifications = new ArrayList<>(); - - for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.getShuffledTestGroupTypeIds(randomGenerator)) { - groupPluginDataBuilder.addGroupTypeId(testGroupTypeId); - groupTypeIds.add(testGroupTypeId); - - for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId - .getShuffledTestGroupPropertyIds(testGroupTypeId, randomGenerator)) { - groupPluginDataBuilder.defineGroupProperty(testGroupPropertyId.getTestGroupTypeId(), - testGroupPropertyId, testGroupPropertyId.getPropertyDefinition()); - - Map propertyDefinitionsMap = groupPropertyDefinitions - .get(testGroupTypeId); - if (propertyDefinitionsMap == null) { - propertyDefinitionsMap = new LinkedHashMap<>(); - groupPropertyDefinitions.put(testGroupTypeId, propertyDefinitionsMap); - } - propertyDefinitionsMap.put(testGroupPropertyId, testGroupPropertyId.getPropertyDefinition()); - } - } - - int groupCount = 10; - List groups = new ArrayList<>(); - for (int j = 0; j < groupCount; j++) { - GroupId groupId = new GroupId(j); - groups.add(groupId); - TestGroupTypeId groupTypeId = TestGroupTypeId.getRandomGroupTypeId(randomGenerator); - groupPluginDataBuilder.addGroup(groupId, groupTypeId); - - while (j >= groupSpecifications.size()) { - groupSpecifications.add(null); - } - - GroupSpecification groupSpecification = groupSpecifications.get(j); - if (groupSpecification == null) { - groupSpecification = new GroupSpecification(); - groupSpecification.groupId = groupId; - groupSpecifications.set(j, groupSpecification); - } - groupSpecification.groupTypeId = groupTypeId; - - for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId - .getTestGroupPropertyIds(groupTypeId)) { - if (randomGenerator.nextBoolean()) { - Object randomPropertyValue = testGroupPropertyId.getRandomPropertyValue(randomGenerator); - groupPluginDataBuilder.setGroupPropertyValue(groupId, testGroupPropertyId, randomPropertyValue); - - while (j >= groupSpecifications.size()) { - groupSpecifications.add(null); - } - - List groupPropertyValues = groupSpecification.groupPropertyValues; - if (groupPropertyValues == null) { - groupPropertyValues = new ArrayList<>(); - groupSpecification.groupPropertyValues = groupPropertyValues; - } - - Iterator iterator = groupSpecification.groupPropertyValues.iterator(); - while (iterator.hasNext()) { - GroupPropertyValue next = iterator.next(); - if (next.groupPropertyId().equals(testGroupPropertyId)) { - iterator.remove(); - break; - } - } - - GroupPropertyValue groupPropertyValue = new GroupPropertyValue(testGroupPropertyId, - randomPropertyValue); - groupPropertyValues.add(groupPropertyValue); - } - } - } - - int totalPeopleCount = 0; - for (GroupId groupId : groups) { - int peopleCount = randomGenerator.nextInt(100); - int currTotalPeopleCount = totalPeopleCount; - totalPeopleCount += peopleCount; - for (int j = currTotalPeopleCount; j < totalPeopleCount; j++) { - PersonId personId = new PersonId(j); - groupPluginDataBuilder.associatePersonToGroup(groupId, personId); - - while (j >= personToGroupsMemberships.size()) { - personToGroupsMemberships.add(null); - } - - List personToGroupMembership = personToGroupsMemberships.get(j); - if (personToGroupMembership == null) { - personToGroupMembership = new ArrayList<>(); - personToGroupsMemberships.set(j, personToGroupMembership); - } - - personToGroupMembership.add(groupId); - - int groupIndex = groupId.getValue(); - - while (groupIndex >= groupToPeopleMemberships.size()) { - groupToPeopleMemberships.add(null); - } - - List people = groupToPeopleMemberships.get(groupIndex); - if (people == null) { - people = new ArrayList<>(); - groupToPeopleMemberships.set(groupIndex, people); - } - - people.add(personId); - } - } - - for (GroupSpecification groupSpecification : groupSpecifications) { - if (groupSpecification != null) { - nextGroupIdValue = FastMath.max(nextGroupIdValue, groupSpecification.groupId.getValue()); - } - } - nextGroupIdValue++; - - GroupsPluginData pluginData = groupPluginDataBuilder.build(); - - StringBuilder dataSb = new StringBuilder(); - dataSb.append("Data [nextGroupIdValue="); - dataSb.append(nextGroupIdValue); - dataSb.append(", groupPropertyDefinitions="); - dataSb.append(groupPropertyDefinitions); - dataSb.append(", groupTypeIds="); - dataSb.append(groupTypeIds); - dataSb.append(", groupSpecifications="); - dataSb.append(groupSpecifications); - dataSb.append(", personToGroupsMemberships="); - dataSb.append(personToGroupsMemberships); - dataSb.append(", groupToPeopleMemberships="); - dataSb.append(groupToPeopleMemberships); - dataSb.append("]"); - - StringBuilder pluginDataSb = new StringBuilder(); - pluginDataSb.append("GroupsPluginData [data="); - pluginDataSb.append(dataSb.toString()); - pluginDataSb.append("]"); - - assertEquals(pluginDataSb.toString(), pluginData.toString()); - } - } - - - - @Test - @UnitTestMethod(target = GroupsPluginData.Builder.class, name = "addGroupToPerson", args = {GroupId.class, PersonId.class }) - public void testAddGroupToPerson() { - - Random random = new Random(7282493148489771700L); - - Map expectedGroupAssignments = new LinkedHashMap<>(); - - GroupsPluginData.Builder builder = GroupsPluginData.builder(); - // add in the group types - for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { - builder.addGroupTypeId(testGroupTypeId); - } - - // create some people - List personIds = new ArrayList<>(); - for (int i = 0; i < 100; i++) { - personIds.add(i); - } - - /* - * Add a few groups and add to those groups 0 to 9 randomly selected people. - * Record the assignments in the expected data structure. - */ - TestGroupTypeId testGroupTypeId = TestGroupTypeId.GROUP_TYPE_1; - for (int i = 0; i < 20; i++) { - // add the group - - builder.addGroup(new GroupId(i), testGroupTypeId); - testGroupTypeId = testGroupTypeId.next(); - // select some people and add them to the group - Collections.shuffle(personIds, random); - int count = random.nextInt(10); - for (int j = 0; j < count; j++) { - builder.addGroupToPerson(new GroupId(i), new PersonId(personIds.get(j))); - builder.addPersonToGroup(new PersonId(personIds.get(j)), new GroupId(i)); - MultiKey multiKey = new MultiKey(new GroupId(i), new PersonId(personIds.get(j))); - expectedGroupAssignments.putIfAbsent(multiKey, new MutableInteger()); - expectedGroupAssignments.get(multiKey).increment(); - } - } - - // build the group initial data - GroupsPluginData groupsPluginData = builder.build(); - - // show that the group memberships are as expected - Map actualGroupAssignments = new LinkedHashMap<>(); - - for (int i = 0; i < groupsPluginData.getPersonCount(); i++) { - PersonId personId = new PersonId(i); - for (GroupId groupId : groupsPluginData.getGroupsForPerson(personId)) { - MultiKey multiKey = new MultiKey(groupId, personId); - actualGroupAssignments.putIfAbsent(multiKey, new MutableInteger()); - actualGroupAssignments.get(multiKey).increment(); - } - } - - assertEquals(expectedGroupAssignments, actualGroupAssignments); - - // precondition test: if the group id is null - ContractException contractException = assertThrows(ContractException.class, - () -> GroupsPluginData.builder().associatePersonToGroup(null, new PersonId(0))); - assertEquals(GroupError.NULL_GROUP_ID, contractException.getErrorType()); - - // precondition test: if the person id is null - contractException = assertThrows(ContractException.class, - () -> GroupsPluginData.builder().associatePersonToGroup(new GroupId(0), null)); - assertEquals(PersonError.NULL_PERSON_ID, contractException.getErrorType()); - } - - @Test - @UnitTestMethod(target = GroupsPluginData.Builder.class, name = "addPersonToGroup", args = {PersonId.class, GroupId.class }) - public void testAddPersonToGroup() { - - Random random = new Random(7282493148489771700L); - - Map expectedGroupAssignments = new LinkedHashMap<>(); - - GroupsPluginData.Builder builder = GroupsPluginData.builder(); - // add in the group types - for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { - builder.addGroupTypeId(testGroupTypeId); - } - - // create some people - List personIds = new ArrayList<>(); - for (int i = 0; i < 100; i++) { - personIds.add(i); - } - - /* - * Add a few groups and add to those groups 0 to 9 randomly selected people. - * Record the assignments in the expected data structure. - */ - TestGroupTypeId testGroupTypeId = TestGroupTypeId.GROUP_TYPE_1; - for (int i = 0; i < 20; i++) { - // add the group - - builder.addGroup(new GroupId(i), testGroupTypeId); - testGroupTypeId = testGroupTypeId.next(); - // select some people and add them to the group - Collections.shuffle(personIds, random); - int count = random.nextInt(10); - for (int j = 0; j < count; j++) { - builder.addGroupToPerson(new GroupId(i), new PersonId(personIds.get(j))); - builder.addPersonToGroup(new PersonId(personIds.get(j)), new GroupId(i)); - MultiKey multiKey = new MultiKey(new GroupId(i), new PersonId(personIds.get(j))); - expectedGroupAssignments.putIfAbsent(multiKey, new MutableInteger()); - expectedGroupAssignments.get(multiKey).increment(); - } - } - - // build the group initial data - GroupsPluginData groupsPluginData = builder.build(); - - // show that the group memberships are as expected - Map actualGroupAssignments = new LinkedHashMap<>(); - - for (int i = 0; i < groupsPluginData.getPersonCount(); i++) { - PersonId personId = new PersonId(i); - for (GroupId groupId : groupsPluginData.getGroupsForPerson(personId)) { - MultiKey multiKey = new MultiKey(groupId, personId); - actualGroupAssignments.putIfAbsent(multiKey, new MutableInteger()); - actualGroupAssignments.get(multiKey).increment(); - } - } - - assertEquals(expectedGroupAssignments, actualGroupAssignments); - - // precondition test: if the group id is null - ContractException contractException = assertThrows(ContractException.class, - () -> GroupsPluginData.builder().associatePersonToGroup(null, new PersonId(0))); - assertEquals(GroupError.NULL_GROUP_ID, contractException.getErrorType()); - - // precondition test: if the person id is null - contractException = assertThrows(ContractException.class, - () -> GroupsPluginData.builder().associatePersonToGroup(new GroupId(0), null)); - assertEquals(PersonError.NULL_PERSON_ID, contractException.getErrorType()); - } + @Test + @UnitTestMethod(target = GroupsPluginData.class, name = "builder", args = {}) + public void testBuilder() { + assertNotNull(GroupsPluginData.builder()); + } + + @Test + @UnitTestMethod(target = GroupsPluginData.Builder.class, name = "build", args = {}) + public void testBuild() { + // show that the builder does not return null + assertNotNull(GroupsPluginData.builder().build()); + + // show that the builder clears its state on build invocation + + GroupsPluginData groupInitialData = GroupsPluginData.builder() // + .associatePersonToGroup(new GroupId(0), new PersonId(0))// + .addGroupTypeId(TestGroupTypeId.GROUP_TYPE_1)// + .addGroup(new GroupId(0), TestGroupTypeId.GROUP_TYPE_1)// + .defineGroupProperty(TestGroupTypeId.GROUP_TYPE_1, + TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK, + TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK.getPropertyDefinition())// + .setGroupPropertyValue(new GroupId(0), TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK, + true)// + .build();// + + assertFalse(groupInitialData.getGroupIds().isEmpty()); + assertFalse(groupInitialData.getGroupTypeIds().isEmpty()); + + groupInitialData = GroupsPluginData.builder().build(); + assertTrue(groupInitialData.getGroupIds().isEmpty()); + assertTrue(groupInitialData.getGroupTypeIds().isEmpty()); + + // precondition test: if a person was added to a group that was not + // defined + ContractException contractException = assertThrows(ContractException.class, () -> { + GroupsPluginData.Builder builder = GroupsPluginData.builder(); + builder.associatePersonToGroup(new GroupId(0), new PersonId(0)).build(); + }); + assertEquals(GroupError.UNKNOWN_GROUP_ID, contractException.getErrorType()); + + // precondition test: if a group was added with a group type id that was + // not + // defined + contractException = assertThrows(ContractException.class, () -> { + GroupsPluginData.Builder builder = GroupsPluginData.builder(); + builder.addGroup(new GroupId(0), TestGroupTypeId.GROUP_TYPE_1).build(); + }); + assertEquals(GroupError.UNKNOWN_GROUP_TYPE_ID, contractException.getErrorType()); + + // precondition test: if a group property definition was defined for a + // group + // type id that + // was not defined. + contractException = assertThrows(ContractException.class, () -> { + GroupsPluginData.Builder builder = GroupsPluginData.builder(); + builder.defineGroupProperty(TestGroupTypeId.GROUP_TYPE_1, // + TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK, // + TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK.getPropertyDefinition()// + ).build(); + }); + + assertEquals(GroupError.UNKNOWN_GROUP_TYPE_ID, contractException.getErrorType()); + + // precondition test: if a group property value was set for a group id + // that was + // not + // defined. + contractException = assertThrows(ContractException.class, () -> { + GroupsPluginData.Builder builder = GroupsPluginData.builder(); + builder.addGroupTypeId(TestGroupTypeId.GROUP_TYPE_1); + builder.defineGroupProperty(TestGroupTypeId.GROUP_TYPE_1, + TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK, + TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK.getPropertyDefinition()); + builder.setGroupPropertyValue(new GroupId(0), + TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK, true); + builder.build(); + }); + assertEquals(GroupError.UNKNOWN_GROUP_ID, contractException.getErrorType()); + + // precondition test: if a group property value is added for a group + // property id + // that is + // not associated with the group. + contractException = assertThrows(ContractException.class, () -> { + GroupsPluginData.Builder builder = GroupsPluginData.builder(); + builder.addGroupTypeId(TestGroupTypeId.GROUP_TYPE_1); + builder.defineGroupProperty(TestGroupTypeId.GROUP_TYPE_1, + TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK, + TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK.getPropertyDefinition()); + builder.setGroupPropertyValue(new GroupId(0), + TestGroupPropertyId.GROUP_PROPERTY_1_2_INTEGER_MUTABLE_NO_TRACK, 15); + builder.addGroup(new GroupId(0), TestGroupTypeId.GROUP_TYPE_1); + builder.build(); + }); + assertEquals(PropertyError.UNKNOWN_PROPERTY_ID, contractException.getErrorType()); + + // precondition test: if a group property value is added that is + // incompatible + // with the + // corresponding property definition + contractException = assertThrows(ContractException.class, () -> { + GroupsPluginData.Builder builder = GroupsPluginData.builder(); + builder.addGroupTypeId(TestGroupTypeId.GROUP_TYPE_1); + builder.defineGroupProperty(TestGroupTypeId.GROUP_TYPE_1, + TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK, + TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK.getPropertyDefinition()); + builder.setGroupPropertyValue(new GroupId(0), + TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK, 15); + builder.addGroup(new GroupId(0), TestGroupTypeId.GROUP_TYPE_1); + builder.build(); + }); + assertEquals(PropertyError.INCOMPATIBLE_VALUE, contractException.getErrorType()); + + /* + * precondition test: if a group does not have a group property value assigned + * when the corresponding property definition lacks a default value. + */ + contractException = assertThrows(ContractException.class, () -> { + GroupsPluginData.Builder builder = GroupsPluginData.builder(); + builder.addGroupTypeId(TestGroupTypeId.GROUP_TYPE_1); + builder.defineGroupProperty(TestGroupTypeId.GROUP_TYPE_1, + TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK, + PropertyDefinition.builder().setType(Boolean.class).build()); + builder.addGroup(new GroupId(0), TestGroupTypeId.GROUP_TYPE_1); + builder.build(); + }); + assertEquals(PropertyError.INSUFFICIENT_PROPERTY_VALUE_ASSIGNMENT, contractException.getErrorType()); + + } + + @Test + @UnitTestMethod(target = GroupsPluginData.Builder.class, name = "addGroupTypeId", args = { GroupTypeId.class }) + public void testAddGroupTypeId() { + GroupsPluginData.Builder builder = GroupsPluginData.builder(); + for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { + builder.addGroupTypeId(testGroupTypeId); + builder.addGroupTypeId(testGroupTypeId); + } + GroupsPluginData groupInitialData = builder.build(); + + // show that the group type ids exist in the groupInitialData + assertEquals(EnumSet.allOf(TestGroupTypeId.class), groupInitialData.getGroupTypeIds()); + + // precondition test: if the group type id is null + ContractException contractException = assertThrows(ContractException.class, + () -> GroupsPluginData.builder().addGroupTypeId(null)); + assertEquals(GroupError.NULL_GROUP_TYPE_ID, contractException.getErrorType()); + } + + @Test + @UnitTestMethod(target = GroupsPluginData.Builder.class, name = "addGroup", args = { GroupId.class, + GroupTypeId.class }) + public void testAddGroup() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(6428717083105095287L); + GroupsPluginData.Builder builder = GroupsPluginData.builder(); + Map> expectedGroupIds = new LinkedHashMap<>(); + for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { + expectedGroupIds.put(testGroupTypeId, new LinkedHashSet<>()); + builder.addGroupTypeId(testGroupTypeId); + } + + for (int i = 0; i < 100; i++) { + TestGroupTypeId randomGroupTypeId = TestGroupTypeId.getRandomGroupTypeId(randomGenerator); + + GroupId groupId = new GroupId(i * 2 + 1); + builder.addGroup(groupId, randomGroupTypeId); + // adding duplicate group data to show the last value persists + randomGroupTypeId = randomGroupTypeId.next(); + builder.addGroup(groupId, randomGroupTypeId); + expectedGroupIds.get(randomGroupTypeId).add(groupId); + } + + Map> actualGroupIds = new LinkedHashMap<>(); + for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { + actualGroupIds.put(testGroupTypeId, new LinkedHashSet<>()); + } + + GroupsPluginData groupsPluginData = builder.build(); + for (GroupId groupId : groupsPluginData.getGroupIds()) { + GroupTypeId groupTypeId = groupsPluginData.getGroupTypeId(groupId); + actualGroupIds.get(groupTypeId).add(groupId); + } + + // show that the group ids that were added are present in the + // groupInitialData + assertEquals(expectedGroupIds, actualGroupIds); + + // precondition test: if the group id is null + ContractException contractException = assertThrows(ContractException.class, + () -> GroupsPluginData.builder().addGroup(null, TestGroupTypeId.GROUP_TYPE_1)); + assertEquals(GroupError.NULL_GROUP_ID, contractException.getErrorType()); + + // precondition test: if the group type id is null + contractException = assertThrows(ContractException.class, + () -> GroupsPluginData.builder().addGroup(new GroupId(0), null)); + assertEquals(GroupError.NULL_GROUP_TYPE_ID, contractException.getErrorType()); + + } + + @Test + @UnitTestMethod(target = GroupsPluginData.Builder.class, name = "defineGroupProperty", args = { GroupTypeId.class, + GroupPropertyId.class, PropertyDefinition.class }) + public void testDefineGroupProperty() { + GroupsPluginData.Builder builder = GroupsPluginData.builder(); + + for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { + builder.addGroupTypeId(testGroupTypeId); + } + + // showing that duplicate values persist + for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId.values()) { + PropertyDefinition propertyDefinition = testGroupPropertyId.next().getPropertyDefinition(); + builder.defineGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId, + propertyDefinition); + propertyDefinition = testGroupPropertyId.getPropertyDefinition(); + builder.defineGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId, + propertyDefinition); + } + + GroupsPluginData groupInitialData = builder.build(); + + // show that each property definition that was added is present in the + // groupInitialData + for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId.values()) { + PropertyDefinition expectedPropertyDefinition = testGroupPropertyId.getPropertyDefinition(); + PropertyDefinition actualPropertyDefinition = groupInitialData + .getGroupPropertyDefinition(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); + assertEquals(expectedPropertyDefinition, actualPropertyDefinition); + } + + TestGroupTypeId testGroupTypeId = TestGroupTypeId.GROUP_TYPE_1; + TestGroupPropertyId groupPropertyId = TestGroupPropertyId.GROUP_PROPERTY_1_2_INTEGER_MUTABLE_NO_TRACK; + PropertyDefinition propertyDefinition = groupPropertyId.getPropertyDefinition(); + + // precondition test: if the group type id is null + ContractException contractException = assertThrows(ContractException.class, + () -> GroupsPluginData.builder().defineGroupProperty(null, groupPropertyId, propertyDefinition)); + assertEquals(GroupError.NULL_GROUP_TYPE_ID, contractException.getErrorType()); + + // precondition test: if the group property id is null + contractException = assertThrows(ContractException.class, + () -> GroupsPluginData.builder().defineGroupProperty(testGroupTypeId, null, propertyDefinition)); + assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); + + // precondition test: if the property definition is null + contractException = assertThrows(ContractException.class, + () -> GroupsPluginData.builder().defineGroupProperty(testGroupTypeId, groupPropertyId, null)); + assertEquals(PropertyError.NULL_PROPERTY_DEFINITION, contractException.getErrorType()); + } + + @Test + @UnitTestMethod(target = GroupsPluginData.Builder.class, name = "setGroupPropertyValue", args = { GroupId.class, + GroupPropertyId.class, Object.class }) + public void testSetGroupPropertyValue() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(206512993284256660L); + + GroupsPluginData.Builder builder = GroupsPluginData.builder(); + + // add in the group types + for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { + builder.addGroupTypeId(testGroupTypeId); + } + + // define the group properties + for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId.values()) { + builder.defineGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId, + testGroupPropertyId.getPropertyDefinition()); + } + + // create a container to hold expected values + Set expectedValues = new LinkedHashSet<>(); + + /* + * Add a few groups and set about half of the property values, leaving the other + * half to be defined by the default values of the corresponding property + * definitions. + */ + TestGroupTypeId testGroupTypeId = TestGroupTypeId.GROUP_TYPE_1; + for (int i = 0; i < 10; i++) { + GroupId groupId = new GroupId(i); + builder.addGroup(groupId, testGroupTypeId); + + Set testGroupPropertyIds = TestGroupPropertyId + .getTestGroupPropertyIds(testGroupTypeId); + for (TestGroupPropertyId testGroupPropertyId : testGroupPropertyIds) { + if (randomGenerator.nextBoolean()) { + Object value = testGroupPropertyId.getRandomPropertyValue(randomGenerator); + builder.setGroupPropertyValue(groupId, testGroupPropertyId, value); + value = testGroupPropertyId.getRandomPropertyValue(randomGenerator); + builder.setGroupPropertyValue(groupId, testGroupPropertyId, value); + expectedValues.add(new MultiKey(groupId, testGroupPropertyId, value)); + } + } + // move to the next group type id + testGroupTypeId = testGroupTypeId.next(); + } + + // build the group initial data + GroupsPluginData groupInitialData = builder.build(); + + // show that the expected group property values are present + Set actualValues = new LinkedHashSet<>(); + for (GroupId groupId : groupInitialData.getGroupIds()) { + for (GroupPropertyValue groupPropertyValue : groupInitialData.getGroupPropertyValues(groupId)) { + MultiKey multiKey = new MultiKey(groupId, groupPropertyValue.groupPropertyId(), + groupPropertyValue.value()); + actualValues.add(multiKey); + } + } + + assertEquals(expectedValues, actualValues); + + TestGroupPropertyId groupPropertyId = TestGroupPropertyId.GROUP_PROPERTY_1_2_INTEGER_MUTABLE_NO_TRACK; + + // precondition test: if the group id is null + ContractException contractException = assertThrows(ContractException.class, + () -> GroupsPluginData.builder().setGroupPropertyValue(null, groupPropertyId, 10)); + assertEquals(GroupError.NULL_GROUP_ID, contractException.getErrorType()); + + // precondition test: if the group property id is null + contractException = assertThrows(ContractException.class, + () -> GroupsPluginData.builder().setGroupPropertyValue(new GroupId(0), null, 10)); + assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); + + // precondition test: if the group property value is null + contractException = assertThrows(ContractException.class, + () -> GroupsPluginData.builder().setGroupPropertyValue(new GroupId(0), groupPropertyId, null)); + assertEquals(PropertyError.NULL_PROPERTY_VALUE, contractException.getErrorType()); + } + + @Test + @UnitTestMethod(target = GroupsPluginData.Builder.class, name = "setNextGroupIdValue", args = { int.class }) + public void testSetNextGroupIdValue() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(2784010859295212357L); + + GroupsPluginData.Builder groupPluginDataBuilder = GroupsPluginData.builder(); + for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { + groupPluginDataBuilder.addGroupTypeId(testGroupTypeId); + } + for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId.values()) { + groupPluginDataBuilder.defineGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId, + testGroupPropertyId.getPropertyDefinition()); + } + + int nextGroupId = randomGenerator.nextInt(100); + groupPluginDataBuilder.setNextGroupIdValue(nextGroupId); + + GroupsPluginData pluginData = groupPluginDataBuilder.build(); + + assertEquals(nextGroupId, pluginData.getNextGroupIdValue()); + + // preconditions: + // value is negative + ContractException contractException = assertThrows(ContractException.class, () -> { + GroupsPluginData.builder().setNextGroupIdValue(-1); + }); + + assertEquals(GroupError.NEGATIVE_GROUP_ID, contractException.getErrorType()); + } + + @Test + @UnitTestMethod(target = GroupsPluginData.Builder.class, name = "associatePersonToGroup", args = { GroupId.class, + PersonId.class }) + public void testAssociatePersonToGroup() { + + Random random = new Random(7282493148489771700L); + + Map expectedGroupAssignments = new LinkedHashMap<>(); + + GroupsPluginData.Builder builder = GroupsPluginData.builder(); + // add in the group types + for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { + builder.addGroupTypeId(testGroupTypeId); + } + + // create some people + List personIds = new ArrayList<>(); + for (int i = 0; i < 100; i++) { + personIds.add(i); + } + + /* + * Add a few groups and add to those groups 0 to 9 randomly selected people. + * Record the assignments in the expected data structure. + */ + TestGroupTypeId testGroupTypeId = TestGroupTypeId.GROUP_TYPE_1; + for (int i = 0; i < 20; i++) { + // add the group + + builder.addGroup(new GroupId(i), testGroupTypeId); + testGroupTypeId = testGroupTypeId.next(); + // select some people and add them to the group + Collections.shuffle(personIds, random); + int count = random.nextInt(10); + for (int j = 0; j < count; j++) { + builder.associatePersonToGroup(new GroupId(i), new PersonId(personIds.get(j))); + MultiKey multiKey = new MultiKey(new GroupId(i), new PersonId(personIds.get(j))); + expectedGroupAssignments.putIfAbsent(multiKey, new MutableInteger()); + expectedGroupAssignments.get(multiKey).increment(); + } + } + + // build the group initial data + GroupsPluginData groupsPluginData = builder.build(); + + // show that the group memberships are as expected + Map actualGroupAssignments = new LinkedHashMap<>(); + + for (int i = 0; i < groupsPluginData.getPersonCount(); i++) { + PersonId personId = new PersonId(i); + for (GroupId groupId : groupsPluginData.getGroupsForPerson(personId)) { + MultiKey multiKey = new MultiKey(groupId, personId); + actualGroupAssignments.putIfAbsent(multiKey, new MutableInteger()); + actualGroupAssignments.get(multiKey).increment(); + } + } + + assertEquals(expectedGroupAssignments, actualGroupAssignments); + + // precondition test: if the group id is null + ContractException contractException = assertThrows(ContractException.class, + () -> GroupsPluginData.builder().associatePersonToGroup(null, new PersonId(0))); + assertEquals(GroupError.NULL_GROUP_ID, contractException.getErrorType()); + + // precondition test: if the person id is null + contractException = assertThrows(ContractException.class, + () -> GroupsPluginData.builder().associatePersonToGroup(new GroupId(0), null)); + assertEquals(PersonError.NULL_PERSON_ID, contractException.getErrorType()); + } + + @Test + @UnitTestMethod(target = GroupsPluginData.class, name = "getGroupPropertyDefinition", args = { GroupTypeId.class, + GroupPropertyId.class }) + public void testGetGroupPropertyDefinition() { + + GroupsPluginData.Builder builder = GroupsPluginData.builder(); + + for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { + builder.addGroupTypeId(testGroupTypeId); + } + + for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId.values()) { + + builder.defineGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId, + testGroupPropertyId.getPropertyDefinition()); + } + + GroupsPluginData groupInitialData = builder.build(); + + // show that each property definition that was added is present in the + // groupInitialData + for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId.values()) { + PropertyDefinition expectedPropertyDefinition = testGroupPropertyId.getPropertyDefinition(); + PropertyDefinition actualPropertyDefinition = groupInitialData + .getGroupPropertyDefinition(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); + assertEquals(expectedPropertyDefinition, actualPropertyDefinition); + } + + // precondition tests + + // if the group type id is null + ContractException contractException = assertThrows(ContractException.class, () -> groupInitialData + .getGroupPropertyDefinition(null, TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK)); + assertEquals(GroupError.NULL_GROUP_TYPE_ID, contractException.getErrorType()); + + // if the group type id is unknown + contractException = assertThrows(ContractException.class, + () -> groupInitialData.getGroupPropertyDefinition(TestGroupTypeId.getUnknownGroupTypeId(), + TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK)); + assertEquals(GroupError.UNKNOWN_GROUP_TYPE_ID, contractException.getErrorType()); + + // if the group property id is null + contractException = assertThrows(ContractException.class, + () -> groupInitialData.getGroupPropertyDefinition(TestGroupTypeId.GROUP_TYPE_1, null)); + assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); + + // if the group property id is not associated with the group type id via + // a property definition + contractException = assertThrows(ContractException.class, + () -> groupInitialData.getGroupPropertyDefinition(TestGroupTypeId.GROUP_TYPE_1, + TestGroupPropertyId.getUnknownGroupPropertyId())); + assertEquals(PropertyError.UNKNOWN_PROPERTY_ID, contractException.getErrorType()); + + // if the group property id is not associated with the group type id via + // a property definition + contractException = assertThrows(ContractException.class, + () -> groupInitialData.getGroupPropertyDefinition(TestGroupTypeId.GROUP_TYPE_1, + TestGroupPropertyId.GROUP_PROPERTY_2_1_BOOLEAN_MUTABLE_TRACK)); + assertEquals(PropertyError.UNKNOWN_PROPERTY_ID, contractException.getErrorType()); + + } + + @Test + @UnitTestMethod(target = GroupsPluginData.class, name = "getGroupPropertyIds", args = { GroupTypeId.class }) + public void testGetGroupPropertyIds() { + + GroupsPluginData.Builder builder = GroupsPluginData.builder(); + + for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { + builder.addGroupTypeId(testGroupTypeId); + } + + for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId.values()) { + builder.defineGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId, + testGroupPropertyId.getPropertyDefinition()); + } + + GroupsPluginData groupInitialData = builder.build(); + + // show that the group properties for each group type match expectations + for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { + Set actualGroupPropertyIds = groupInitialData.getGroupPropertyIds(testGroupTypeId); + Set expectedGroupPropertyIds = TestGroupPropertyId + .getTestGroupPropertyIds(testGroupTypeId); + assertEquals(expectedGroupPropertyIds, actualGroupPropertyIds); + } + + // precondition tests + // if the group type id is null + ContractException contractException = assertThrows(ContractException.class, + () -> groupInitialData.getGroupPropertyIds(null)); + assertEquals(GroupError.NULL_GROUP_TYPE_ID, contractException.getErrorType()); + + // if the group type id is unknown + contractException = assertThrows(ContractException.class, + () -> groupInitialData.getGroupPropertyIds(TestGroupTypeId.getUnknownGroupTypeId())); + assertEquals(GroupError.UNKNOWN_GROUP_TYPE_ID, contractException.getErrorType()); + + } + + @Test + @UnitTestMethod(target = GroupsPluginData.class, name = "getGroupPropertyValues", args = { GroupId.class }) + public void testGetGroupPropertyValues() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(8435308203966252001L); + + GroupsPluginData.Builder builder = GroupsPluginData.builder(); + + // add in the group types + for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { + builder.addGroupTypeId(testGroupTypeId); + } + + // define the group properties + for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId.values()) { + builder.defineGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId, + testGroupPropertyId.getPropertyDefinition()); + } + + // create a container to hold expected values + Set expectedValues = new LinkedHashSet<>(); + + /* + * Add a few groups and set about half of the property values, leaving the other + * half to be defined by the default values of the corresponding property + * definitions. + */ + int groupCount = 10; + + TestGroupTypeId testGroupTypeId = TestGroupTypeId.GROUP_TYPE_1; + for (int i = 0; i < groupCount; i++) { + GroupId groupId = new GroupId(i); + builder.addGroup(groupId, testGroupTypeId); + + Set testGroupPropertyIds = TestGroupPropertyId + .getTestGroupPropertyIds(testGroupTypeId); + for (TestGroupPropertyId testGroupPropertyId : testGroupPropertyIds) { + if (randomGenerator.nextBoolean()) { + Object value = testGroupPropertyId.getRandomPropertyValue(randomGenerator); + builder.setGroupPropertyValue(groupId, testGroupPropertyId, value); + expectedValues.add(new MultiKey(groupId, testGroupPropertyId, value)); + } + } + // move to the next group type id + testGroupTypeId = testGroupTypeId.next(); + } + + // build the group initial data + GroupsPluginData groupsPluginData = builder.build(); + + // show that the expected group property values are present + Set actualValues = new LinkedHashSet<>(); + for (GroupId groupId : groupsPluginData.getGroupIds()) { + for (GroupPropertyValue groupPropertyValue : groupsPluginData.getGroupPropertyValues(groupId)) { + MultiKey multiKey = new MultiKey(groupId, groupPropertyValue.groupPropertyId(), + groupPropertyValue.value()); + actualValues.add(multiKey); + } + } + + assertEquals(expectedValues, actualValues); + + // precondition tests + + // if the group id is null + ContractException contractException = assertThrows(ContractException.class, + () -> groupsPluginData.getGroupPropertyValues(null)); + assertEquals(GroupError.NULL_GROUP_ID, contractException.getErrorType()); + + // if the group id is unknown + contractException = assertThrows(ContractException.class, + () -> groupsPluginData.getGroupPropertyValues(new GroupId(10000))); + assertEquals(GroupError.UNKNOWN_GROUP_ID, contractException.getErrorType()); + } + + @Test + @UnitTestMethod(target = GroupsPluginData.class, name = "getGroupTypeIds", args = {}) + public void testGetGroupTypeIds() { + GroupsPluginData.Builder builder = GroupsPluginData.builder(); + for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { + builder.addGroupTypeId(testGroupTypeId); + } + GroupsPluginData groupInitialData = builder.build(); + + // show that the group type ids exist in the groupInitialData + assertEquals(EnumSet.allOf(TestGroupTypeId.class), groupInitialData.getGroupTypeIds()); + } + + @Test + @UnitTestMethod(target = GroupsPluginData.class, name = "getGroupIds", args = {}) + public void testGetGroupIds() { + GroupsPluginData.Builder builder = GroupsPluginData.builder(); + int masterGroupId = 0; + Set expectedGroupIds = new LinkedHashSet<>(); + for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { + builder.addGroupTypeId(testGroupTypeId); + + GroupId groupId = new GroupId(masterGroupId++); + builder.addGroup(groupId, testGroupTypeId); + expectedGroupIds.add(groupId); + + groupId = new GroupId(masterGroupId++); + builder.addGroup(groupId, testGroupTypeId); + expectedGroupIds.add(groupId); + } + GroupsPluginData groupInitialData = builder.build(); + + // show that the group ids that were added are present in the + // groupInitialData + assertEquals(expectedGroupIds, new LinkedHashSet<>(groupInitialData.getGroupIds())); + + } + + @Test + @UnitTestMethod(target = GroupsPluginData.class, name = "getGroupsForPerson", args = { PersonId.class }) + public void testGetGroupsForPerson() { + + Random random = new Random(4685636461674441597L); + + Set expectedGroupAssignments = new LinkedHashSet<>(); + + GroupsPluginData.Builder builder = GroupsPluginData.builder(); + // add in the group types + for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { + builder.addGroupTypeId(testGroupTypeId); + } + + // create some people + List people = new ArrayList<>(); + for (int i = 0; i < 100; i++) { + people.add(new PersonId(i)); + } + + /* + * Add a few groups and add to those groups 0 to 9 randomly selected people. + * Record the assignments in the expected data structure. + */ + TestGroupTypeId testGroupTypeId = TestGroupTypeId.GROUP_TYPE_1; + for (int i = 0; i < 20; i++) { + // add the group + GroupId groupId = new GroupId(i); + builder.addGroup(groupId, testGroupTypeId); + + testGroupTypeId = testGroupTypeId.next(); + + // select some people and add them to the group + Collections.shuffle(people, random); + int count = random.nextInt(10); + for (int j = 0; j < count; j++) { + PersonId personId = people.get(j); + builder.associatePersonToGroup(groupId, personId); + MultiKey multiKey = new MultiKey(groupId, personId); + expectedGroupAssignments.add(multiKey); + } + } + + // build the group initial data + GroupsPluginData groupInitialData = builder.build(); + + // show that the group memberships are as expected + Set actualGroupAssignments = new LinkedHashSet<>(); + for (int i = 0; i < groupInitialData.getPersonCount(); i++) { + PersonId personId = new PersonId(i); + for (GroupId groupId : groupInitialData.getGroupsForPerson(personId)) { + MultiKey multiKey = new MultiKey(groupId, personId); + actualGroupAssignments.add(multiKey); + } + } + + assertEquals(expectedGroupAssignments, actualGroupAssignments); + + } + + @Test + @UnitTestMethod(target = GroupsPluginData.class, name = "getGroupTypeId", args = { GroupId.class }) + public void testGetGroupTypeId() { + + GroupsPluginData.Builder builder = GroupsPluginData.builder(); + int masterGroupId = 0; + Map expectedGroupTypes = new LinkedHashMap<>(); + for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { + builder.addGroupTypeId(testGroupTypeId); + + GroupId groupId = new GroupId(masterGroupId++); + builder.addGroup(groupId, testGroupTypeId); + expectedGroupTypes.put(groupId, testGroupTypeId); + + groupId = new GroupId(masterGroupId++); + builder.addGroup(groupId, testGroupTypeId); + expectedGroupTypes.put(groupId, testGroupTypeId); + } + GroupsPluginData groupInitialData = builder.build(); + + for (GroupId groupId : expectedGroupTypes.keySet()) { + GroupTypeId expecctedGroupTypeId = expectedGroupTypes.get(groupId); + GroupTypeId actualGroupTypeId = groupInitialData.getGroupTypeId(groupId); + assertEquals(expecctedGroupTypeId, actualGroupTypeId); + } + + // precondition tests + + // if the group id is null + ContractException contractException = assertThrows(ContractException.class, + () -> groupInitialData.getGroupTypeId(null)); + assertEquals(GroupError.NULL_GROUP_ID, contractException.getErrorType()); + + // if the group id is unknown + contractException = assertThrows(ContractException.class, + () -> groupInitialData.getGroupTypeId(new GroupId(1000000))); + assertEquals(GroupError.UNKNOWN_GROUP_ID, contractException.getErrorType()); + + } + + @Test + @UnitTestMethod(target = GroupsPluginData.class, name = "getCloneBuilder", args = {}) + public void testGetCloneBuilder() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(9130589441333999144L); + + GroupsPluginData.Builder groupPluginDataBuilder = GroupsPluginData.builder(); + for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { + groupPluginDataBuilder.addGroupTypeId(testGroupTypeId); + } + for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId.values()) { + groupPluginDataBuilder.defineGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId, + testGroupPropertyId.getPropertyDefinition()); + } + int groupCount = 10; + List groups = new ArrayList<>(); + for (int i = 0; i < groupCount; i++) { + GroupId groupId = new GroupId(i); + groups.add(groupId); + TestGroupTypeId groupTypeId = TestGroupTypeId.getRandomGroupTypeId(randomGenerator); + groupPluginDataBuilder.addGroup(groupId, groupTypeId); + for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId.getTestGroupPropertyIds(groupTypeId)) { + if (randomGenerator.nextBoolean()) { + Object randomPropertyValue = testGroupPropertyId.getRandomPropertyValue(randomGenerator); + groupPluginDataBuilder.setGroupPropertyValue(groupId, testGroupPropertyId, randomPropertyValue); + } + } + } + + int personCount = 100; + + for (int i = 0; i < personCount; i++) { + PersonId personId = new PersonId(i); + int numberOfGroups = randomGenerator.nextInt(5); + Collections.sort(groups); + for (int j = 0; j < numberOfGroups; j++) { + GroupId groupId = groups.get(j); + groupPluginDataBuilder.associatePersonToGroup(groupId, personId); + } + } + GroupsPluginData groupsPluginData = groupPluginDataBuilder.build(); + + //////////////////// + + // show that the returned clone builder will build an identical instance if no + // mutations are made + GroupsPluginData.Builder cloneBuilder = groupsPluginData.getCloneBuilder(); + assertNotNull(cloneBuilder); + assertEquals(groupsPluginData, cloneBuilder.build()); + + // show that the clone builder builds a distinct instance if any mutation is + // made + + // addGroup + cloneBuilder = groupsPluginData.getCloneBuilder(); + cloneBuilder.resetNextGroupIdValue(); + cloneBuilder.addGroup(new GroupId(groupCount), TestGroupTypeId.GROUP_TYPE_1); + assertNotEquals(groupsPluginData, cloneBuilder.build()); + + // setNextGroupIdValue + cloneBuilder = groupsPluginData.getCloneBuilder(); + cloneBuilder.setNextGroupIdValue(1000); + assertNotEquals(groupsPluginData, cloneBuilder.build()); + + // addGroupToPerson and addPersonToGroup must be performed together + cloneBuilder = groupsPluginData.getCloneBuilder(); + cloneBuilder.addGroupToPerson(new GroupId(0), new PersonId(1045)); + cloneBuilder.addPersonToGroup(new PersonId(1045), new GroupId(0)); + assertNotEquals(groupsPluginData, cloneBuilder.build()); + + // associatePersonToGroup + cloneBuilder = groupsPluginData.getCloneBuilder(); + cloneBuilder.associatePersonToGroup(new GroupId(0), new PersonId(1045)); + assertNotEquals(groupsPluginData, cloneBuilder.build()); + + // addGroupTypeId + cloneBuilder = groupsPluginData.getCloneBuilder(); + cloneBuilder.addGroupTypeId(TestGroupTypeId.getUnknownGroupTypeId()); + assertNotEquals(groupsPluginData, cloneBuilder.build()); + + // defineGroupProperty + cloneBuilder = groupsPluginData.getCloneBuilder(); + PropertyDefinition propertyDefinition = PropertyDefinition.builder()// + .setDefaultValue(123)// + .setPropertyValueMutability(true)// + .setType(Integer.class)// + .build(); + cloneBuilder.defineGroupProperty(TestGroupTypeId.GROUP_TYPE_1, TestGroupPropertyId.getUnknownGroupPropertyId(), + propertyDefinition); + assertNotEquals(groupsPluginData, cloneBuilder.build()); + + + // setGroupPropertyValue + cloneBuilder = groupsPluginData.getCloneBuilder(); + GroupTypeId groupTypeId = groupsPluginData.getGroupTypeId(new GroupId(0)); + TestGroupPropertyId selectedTestGroupPropertyId = null; + for(TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId.values()) { + if(testGroupPropertyId.getTestGroupTypeId().equals(groupTypeId)) { + selectedTestGroupPropertyId = testGroupPropertyId; + break; + } + } + + Object propertyValue = selectedTestGroupPropertyId.getRandomPropertyValue(randomGenerator); + cloneBuilder.setGroupPropertyValue(new GroupId(0),selectedTestGroupPropertyId,propertyValue); + assertNotEquals(groupsPluginData, cloneBuilder.build()); + + } + + @Test + @UnitTestMethod(target = GroupsPluginData.class, name = "getPersonCount", args = {}) + public void testGetPersonCount() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(7910883193674079461L); + + GroupsPluginData.Builder groupPluginDataBuilder = GroupsPluginData.builder(); + for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { + groupPluginDataBuilder.addGroupTypeId(testGroupTypeId); + } + for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId.values()) { + groupPluginDataBuilder.defineGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId, + testGroupPropertyId.getPropertyDefinition()); + } + int groupCount = 10; + List groups = new ArrayList<>(); + for (int i = 0; i < groupCount; i++) { + GroupId groupId = new GroupId(i); + groups.add(groupId); + TestGroupTypeId groupTypeId = TestGroupTypeId.getRandomGroupTypeId(randomGenerator); + groupPluginDataBuilder.addGroup(groupId, groupTypeId); + for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId.getTestGroupPropertyIds(groupTypeId)) { + if (randomGenerator.nextBoolean()) { + Object randomPropertyValue = testGroupPropertyId.getRandomPropertyValue(randomGenerator); + groupPluginDataBuilder.setGroupPropertyValue(groupId, testGroupPropertyId, randomPropertyValue); + } + } + } + + int totalPeopleCount = 0; + for (GroupId groupId : groups) { + int peopleCount = randomGenerator.nextInt(100); + int currTotalPeopleCount = totalPeopleCount; + totalPeopleCount += peopleCount; + for (int i = currTotalPeopleCount; i < totalPeopleCount; i++) { + PersonId personId = new PersonId(i); + groupPluginDataBuilder.associatePersonToGroup(groupId, personId); + } + } + + GroupsPluginData groupsPluginData = groupPluginDataBuilder.build(); + + // show that the total people count is NOT 0 + assertTrue(totalPeopleCount > 0); + + // show that the group person count is equal to the total people count + assertEquals(totalPeopleCount, groupsPluginData.getPersonCount()); + } + + @Test + @UnitTestMethod(target = GroupsPluginData.class, name = "getNextGroupIdValue", args = {}) + public void testGetNextGroupIdValue() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(2784010859295212357L); + + GroupsPluginData.Builder groupPluginDataBuilder = GroupsPluginData.builder(); + for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { + groupPluginDataBuilder.addGroupTypeId(testGroupTypeId); + } + for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId.values()) { + groupPluginDataBuilder.defineGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId, + testGroupPropertyId.getPropertyDefinition()); + } + int groupCount = 10; + List groups = new ArrayList<>(); + for (int i = 0; i < groupCount; i++) { + GroupId groupId = new GroupId(i); + groups.add(groupId); + TestGroupTypeId groupTypeId = TestGroupTypeId.getRandomGroupTypeId(randomGenerator); + groupPluginDataBuilder.addGroup(groupId, groupTypeId); + for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId.getTestGroupPropertyIds(groupTypeId)) { + if (randomGenerator.nextBoolean()) { + Object randomPropertyValue = testGroupPropertyId.getRandomPropertyValue(randomGenerator); + groupPluginDataBuilder.setGroupPropertyValue(groupId, testGroupPropertyId, randomPropertyValue); + } + } + } + + GroupsPluginData pluginData = groupPluginDataBuilder.build(); + + assertEquals(groupCount, pluginData.getNextGroupIdValue()); + + pluginData = groupPluginDataBuilder.setNextGroupIdValue(groupCount + 10).build(); + + assertEquals(groupCount + 10, pluginData.getNextGroupIdValue()); + } + + @Test + @UnitTestMethod(target = GroupsPluginData.class, name = "getGroupCount", args = {}) + public void testGetGroupCount() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(669154335225022584L); + + for (int i = 0; i < 10; i++) { + GroupsPluginData.Builder groupPluginDataBuilder = GroupsPluginData.builder(); + + for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.getShuffledTestGroupTypeIds(randomGenerator)) { + groupPluginDataBuilder.addGroupTypeId(testGroupTypeId); + } + + int groupCount = randomGenerator.nextInt(50) + 10; + List groups = new ArrayList<>(); + for (int j = 0; j < groupCount; j++) { + GroupId groupId = new GroupId(j); + groups.add(groupId); + TestGroupTypeId groupTypeId = TestGroupTypeId.getRandomGroupTypeId(randomGenerator); + groupPluginDataBuilder.addGroup(groupId, groupTypeId); + } + + int totalPeopleCount = 0; + for (GroupId groupId : groups) { + int peopleCount = randomGenerator.nextInt(100); + int currTotalPeopleCount = totalPeopleCount; + totalPeopleCount += peopleCount; + for (int j = currTotalPeopleCount; j < totalPeopleCount; j++) { + PersonId personId = new PersonId(j); + groupPluginDataBuilder.associatePersonToGroup(groupId, personId); + } + } + + GroupsPluginData pluginData = groupPluginDataBuilder.build(); + + assertEquals(groupCount, pluginData.getGroupCount()); + } + } + + @Test + @UnitTestMethod(target = GroupsPluginData.class, name = "getPeopleForGroup", args = { GroupId.class }) + public void testGetPeopleForGroup() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(4825370554814301264L); + + for (int i = 0; i < 10; i++) { + GroupsPluginData.Builder groupPluginDataBuilder = GroupsPluginData.builder(); + + List> groupToPeopleMemberships = new ArrayList<>(); + + for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.getShuffledTestGroupTypeIds(randomGenerator)) { + groupPluginDataBuilder.addGroupTypeId(testGroupTypeId); + } + + int groupCount = 10; + List groups = new ArrayList<>(); + for (int j = 0; j < groupCount; j++) { + GroupId groupId = new GroupId(j); + groups.add(groupId); + TestGroupTypeId groupTypeId = TestGroupTypeId.getRandomGroupTypeId(randomGenerator); + groupPluginDataBuilder.addGroup(groupId, groupTypeId); + } + + int totalPeopleCount = 0; + for (GroupId groupId : groups) { + int peopleCount = randomGenerator.nextInt(100); + int currTotalPeopleCount = totalPeopleCount; + totalPeopleCount += peopleCount; + for (int j = currTotalPeopleCount; j < totalPeopleCount; j++) { + PersonId personId = new PersonId(j); + groupPluginDataBuilder.associatePersonToGroup(groupId, personId); + + int groupIndex = groupId.getValue(); + + while (groupIndex >= groupToPeopleMemberships.size()) { + groupToPeopleMemberships.add(null); + } + + List people = groupToPeopleMemberships.get(groupIndex); + if (people == null) { + people = new ArrayList<>(); + groupToPeopleMemberships.set(groupIndex, people); + } + + people.add(personId); + } + } + + GroupsPluginData pluginData = groupPluginDataBuilder.build(); + + for (int j = 0; j < groupToPeopleMemberships.size(); j++) { + List personIds = groupToPeopleMemberships.get(j); + + if (personIds == null) { + assertEquals(Collections.unmodifiableList(new ArrayList<>()), + pluginData.getPeopleForGroup(new GroupId(j))); + } else { + assertEquals(personIds, pluginData.getPeopleForGroup(new GroupId(j))); + } + } + } + } + + @Test + @UnitTestMethod(target = GroupsPluginData.class, name = "getGroupPropertyDefinitions", args = {}) + public void testGetPropertyDefinitions() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(9107021630953219230L); + + for (int i = 0; i < 10; i++) { + GroupsPluginData.Builder groupPluginDataBuilder = GroupsPluginData.builder(); + + Map> groupPropertyDefinitions = new LinkedHashMap<>(); + + for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.getShuffledTestGroupTypeIds(randomGenerator)) { + groupPluginDataBuilder.addGroupTypeId(testGroupTypeId); + + for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId + .getShuffledTestGroupPropertyIds(testGroupTypeId, randomGenerator)) { + groupPluginDataBuilder.defineGroupProperty(testGroupPropertyId.getTestGroupTypeId(), + testGroupPropertyId, testGroupPropertyId.getPropertyDefinition()); + + Map propertyDefinitionsMap = groupPropertyDefinitions + .get(testGroupTypeId); + if (propertyDefinitionsMap == null) { + propertyDefinitionsMap = new LinkedHashMap<>(); + groupPropertyDefinitions.put(testGroupTypeId, propertyDefinitionsMap); + } + propertyDefinitionsMap.put(testGroupPropertyId, testGroupPropertyId.getPropertyDefinition()); + } + } + + GroupsPluginData pluginData = groupPluginDataBuilder.build(); + + assertEquals(groupPropertyDefinitions, pluginData.getGroupPropertyDefinitions()); + } + } + + @Test + @UnitTestMethod(target = GroupsPluginData.class, name = "hashCode", args = {}) + public void testHashCode() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(386194196593528301L); + + List people = new ArrayList<>(); + + for (int i = 0; i < 100; i++) { + people.add(new PersonId(i)); + } + + long sameSeed = randomGenerator.nextLong(); + GroupsPluginData groupsPluginData1 = GroupsTestPluginFactory.getStandardGroupsPluginData(2, 10, people, + sameSeed); + GroupsPluginData groupsPluginData2 = GroupsTestPluginFactory.getStandardGroupsPluginData(2, 10, people, + randomGenerator.nextLong()); + GroupsPluginData groupsPluginData3 = GroupsTestPluginFactory.getStandardGroupsPluginData(2, 5, people, + sameSeed); + GroupsPluginData groupsPluginData4 = GroupsTestPluginFactory.getStandardGroupsPluginData(2, 5, people, + randomGenerator.nextLong()); + GroupsPluginData groupsPluginData5 = GroupsTestPluginFactory.getStandardGroupsPluginData(1, 10, people, + sameSeed); + GroupsPluginData groupsPluginData6 = GroupsTestPluginFactory.getStandardGroupsPluginData(3, 10, people, + randomGenerator.nextLong()); + GroupsPluginData groupsPluginData7 = GroupsTestPluginFactory.getStandardGroupsPluginData(3, 5, people, + sameSeed); + GroupsPluginData groupsPluginData8 = GroupsTestPluginFactory.getStandardGroupsPluginData(3, 5, people, + randomGenerator.nextLong()); + GroupsPluginData groupsPluginData9 = GroupsTestPluginFactory.getStandardGroupsPluginData(2, 10, people, + sameSeed); + + assertEquals(groupsPluginData1.hashCode(), groupsPluginData1.hashCode()); + + assertNotEquals(groupsPluginData1.hashCode(), groupsPluginData2.hashCode()); + assertNotEquals(groupsPluginData1.hashCode(), groupsPluginData3.hashCode()); + assertNotEquals(groupsPluginData1.hashCode(), groupsPluginData4.hashCode()); + assertNotEquals(groupsPluginData1.hashCode(), groupsPluginData5.hashCode()); + assertNotEquals(groupsPluginData1.hashCode(), groupsPluginData6.hashCode()); + assertNotEquals(groupsPluginData1.hashCode(), groupsPluginData7.hashCode()); + assertNotEquals(groupsPluginData1.hashCode(), groupsPluginData8.hashCode()); + + assertNotEquals(groupsPluginData1.hashCode(), groupsPluginData3.hashCode()); + assertNotEquals(groupsPluginData1.hashCode(), groupsPluginData4.hashCode()); + assertNotEquals(groupsPluginData1.hashCode(), groupsPluginData5.hashCode()); + assertNotEquals(groupsPluginData1.hashCode(), groupsPluginData6.hashCode()); + assertNotEquals(groupsPluginData1.hashCode(), groupsPluginData7.hashCode()); + assertNotEquals(groupsPluginData1.hashCode(), groupsPluginData8.hashCode()); + + assertNotEquals(groupsPluginData3.hashCode(), groupsPluginData4.hashCode()); + assertNotEquals(groupsPluginData3.hashCode(), groupsPluginData5.hashCode()); + assertNotEquals(groupsPluginData3.hashCode(), groupsPluginData6.hashCode()); + assertNotEquals(groupsPluginData3.hashCode(), groupsPluginData7.hashCode()); + assertNotEquals(groupsPluginData3.hashCode(), groupsPluginData8.hashCode()); + + assertNotEquals(groupsPluginData4.hashCode(), groupsPluginData5.hashCode()); + assertNotEquals(groupsPluginData4.hashCode(), groupsPluginData6.hashCode()); + assertNotEquals(groupsPluginData4.hashCode(), groupsPluginData7.hashCode()); + assertNotEquals(groupsPluginData4.hashCode(), groupsPluginData8.hashCode()); + + assertNotEquals(groupsPluginData5.hashCode(), groupsPluginData6.hashCode()); + assertNotEquals(groupsPluginData5.hashCode(), groupsPluginData7.hashCode()); + assertNotEquals(groupsPluginData5.hashCode(), groupsPluginData8.hashCode()); + + assertNotEquals(groupsPluginData6.hashCode(), groupsPluginData7.hashCode()); + assertNotEquals(groupsPluginData6.hashCode(), groupsPluginData8.hashCode()); + + assertNotEquals(groupsPluginData7.hashCode(), groupsPluginData8.hashCode()); + + assertEquals(groupsPluginData1.hashCode(), groupsPluginData9.hashCode()); + } + + @Test + @UnitTestMethod(target = GroupsPluginData.class, name = "equals", args = { Object.class }) + public void testEquals() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(1974882207275712576L); + + List people = new ArrayList<>(); + + for (int i = 0; i < 100; i++) { + people.add(new PersonId(i)); + } + + long sameSeed = randomGenerator.nextLong(); + GroupsPluginData groupsPluginData1 = GroupsTestPluginFactory.getStandardGroupsPluginData(2, 10, people, + sameSeed); + GroupsPluginData groupsPluginData2 = GroupsTestPluginFactory.getStandardGroupsPluginData(2, 10, people, + randomGenerator.nextLong()); + GroupsPluginData groupsPluginData3 = GroupsTestPluginFactory.getStandardGroupsPluginData(2, 5, people, + sameSeed); + GroupsPluginData groupsPluginData4 = GroupsTestPluginFactory.getStandardGroupsPluginData(2, 5, people, + randomGenerator.nextLong()); + GroupsPluginData groupsPluginData5 = GroupsTestPluginFactory.getStandardGroupsPluginData(1, 10, people, + sameSeed); + GroupsPluginData groupsPluginData6 = GroupsTestPluginFactory.getStandardGroupsPluginData(3, 10, people, + randomGenerator.nextLong()); + GroupsPluginData groupsPluginData7 = GroupsTestPluginFactory.getStandardGroupsPluginData(3, 5, people, + sameSeed); + GroupsPluginData groupsPluginData8 = GroupsTestPluginFactory.getStandardGroupsPluginData(3, 5, people, + randomGenerator.nextLong()); + GroupsPluginData groupsPluginData9 = GroupsTestPluginFactory.getStandardGroupsPluginData(2, 10, people, + sameSeed); + + assertEquals(groupsPluginData1, groupsPluginData1); + + assertNotEquals(groupsPluginData1, null); + + assertNotEquals(groupsPluginData1, new Object()); + + assertNotEquals(groupsPluginData1, groupsPluginData2); + assertNotEquals(groupsPluginData1, groupsPluginData3); + assertNotEquals(groupsPluginData1, groupsPluginData4); + assertNotEquals(groupsPluginData1, groupsPluginData5); + assertNotEquals(groupsPluginData1, groupsPluginData6); + assertNotEquals(groupsPluginData1, groupsPluginData7); + assertNotEquals(groupsPluginData1, groupsPluginData8); + + assertNotEquals(groupsPluginData1, groupsPluginData3); + assertNotEquals(groupsPluginData1, groupsPluginData4); + assertNotEquals(groupsPluginData1, groupsPluginData5); + assertNotEquals(groupsPluginData1, groupsPluginData6); + assertNotEquals(groupsPluginData1, groupsPluginData7); + assertNotEquals(groupsPluginData1, groupsPluginData8); + + assertNotEquals(groupsPluginData3, groupsPluginData4); + assertNotEquals(groupsPluginData3, groupsPluginData5); + assertNotEquals(groupsPluginData3, groupsPluginData6); + assertNotEquals(groupsPluginData3, groupsPluginData7); + assertNotEquals(groupsPluginData3, groupsPluginData8); + + assertNotEquals(groupsPluginData4, groupsPluginData5); + assertNotEquals(groupsPluginData4, groupsPluginData6); + assertNotEquals(groupsPluginData4, groupsPluginData7); + assertNotEquals(groupsPluginData4, groupsPluginData8); + + assertNotEquals(groupsPluginData5, groupsPluginData6); + assertNotEquals(groupsPluginData5, groupsPluginData7); + assertNotEquals(groupsPluginData5, groupsPluginData8); + + assertNotEquals(groupsPluginData6, groupsPluginData7); + assertNotEquals(groupsPluginData6, groupsPluginData8); + + assertNotEquals(groupsPluginData7, groupsPluginData8); + + assertEquals(groupsPluginData1, groupsPluginData9); + + } + + @Test + @UnitTestMethod(target = GroupsPluginData.class, name = "toString", args = {}) + public void testToString() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(523034536833646355L); + + for (int i = 0; i < 10; i++) { + GroupsPluginData.Builder groupPluginDataBuilder = GroupsPluginData.builder(); + + int nextGroupIdValue = -1; + Map> groupPropertyDefinitions = new LinkedHashMap<>(); + Set groupTypeIds = new LinkedHashSet<>(); + List> personToGroupsMemberships = new ArrayList<>(); + List> groupToPeopleMemberships = new ArrayList<>(); + List groupSpecifications = new ArrayList<>(); + + for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.getShuffledTestGroupTypeIds(randomGenerator)) { + groupPluginDataBuilder.addGroupTypeId(testGroupTypeId); + groupTypeIds.add(testGroupTypeId); + + for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId + .getShuffledTestGroupPropertyIds(testGroupTypeId, randomGenerator)) { + groupPluginDataBuilder.defineGroupProperty(testGroupPropertyId.getTestGroupTypeId(), + testGroupPropertyId, testGroupPropertyId.getPropertyDefinition()); + + Map propertyDefinitionsMap = groupPropertyDefinitions + .get(testGroupTypeId); + if (propertyDefinitionsMap == null) { + propertyDefinitionsMap = new LinkedHashMap<>(); + groupPropertyDefinitions.put(testGroupTypeId, propertyDefinitionsMap); + } + propertyDefinitionsMap.put(testGroupPropertyId, testGroupPropertyId.getPropertyDefinition()); + } + } + + int groupCount = 10; + List groups = new ArrayList<>(); + for (int j = 0; j < groupCount; j++) { + GroupId groupId = new GroupId(j); + groups.add(groupId); + TestGroupTypeId groupTypeId = TestGroupTypeId.getRandomGroupTypeId(randomGenerator); + groupPluginDataBuilder.addGroup(groupId, groupTypeId); + + while (j >= groupSpecifications.size()) { + groupSpecifications.add(null); + } + + GroupSpecification groupSpecification = groupSpecifications.get(j); + if (groupSpecification == null) { + groupSpecification = new GroupSpecification(); + groupSpecification.groupId = groupId; + groupSpecifications.set(j, groupSpecification); + } + groupSpecification.groupTypeId = groupTypeId; + + for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId + .getTestGroupPropertyIds(groupTypeId)) { + if (randomGenerator.nextBoolean()) { + Object randomPropertyValue = testGroupPropertyId.getRandomPropertyValue(randomGenerator); + groupPluginDataBuilder.setGroupPropertyValue(groupId, testGroupPropertyId, randomPropertyValue); + + while (j >= groupSpecifications.size()) { + groupSpecifications.add(null); + } + + List groupPropertyValues = groupSpecification.groupPropertyValues; + if (groupPropertyValues == null) { + groupPropertyValues = new ArrayList<>(); + groupSpecification.groupPropertyValues = groupPropertyValues; + } + + Iterator iterator = groupSpecification.groupPropertyValues.iterator(); + while (iterator.hasNext()) { + GroupPropertyValue next = iterator.next(); + if (next.groupPropertyId().equals(testGroupPropertyId)) { + iterator.remove(); + break; + } + } + + GroupPropertyValue groupPropertyValue = new GroupPropertyValue(testGroupPropertyId, + randomPropertyValue); + groupPropertyValues.add(groupPropertyValue); + } + } + } + + int totalPeopleCount = 0; + for (GroupId groupId : groups) { + int peopleCount = randomGenerator.nextInt(100); + int currTotalPeopleCount = totalPeopleCount; + totalPeopleCount += peopleCount; + for (int j = currTotalPeopleCount; j < totalPeopleCount; j++) { + PersonId personId = new PersonId(j); + groupPluginDataBuilder.associatePersonToGroup(groupId, personId); + + while (j >= personToGroupsMemberships.size()) { + personToGroupsMemberships.add(null); + } + + List personToGroupMembership = personToGroupsMemberships.get(j); + if (personToGroupMembership == null) { + personToGroupMembership = new ArrayList<>(); + personToGroupsMemberships.set(j, personToGroupMembership); + } + + personToGroupMembership.add(groupId); + + int groupIndex = groupId.getValue(); + + while (groupIndex >= groupToPeopleMemberships.size()) { + groupToPeopleMemberships.add(null); + } + + List people = groupToPeopleMemberships.get(groupIndex); + if (people == null) { + people = new ArrayList<>(); + groupToPeopleMemberships.set(groupIndex, people); + } + + people.add(personId); + } + } + + for (GroupSpecification groupSpecification : groupSpecifications) { + if (groupSpecification != null) { + nextGroupIdValue = FastMath.max(nextGroupIdValue, groupSpecification.groupId.getValue()); + } + } + nextGroupIdValue++; + + GroupsPluginData pluginData = groupPluginDataBuilder.build(); + + StringBuilder dataSb = new StringBuilder(); + dataSb.append("Data [nextGroupIdValue="); + dataSb.append(nextGroupIdValue); + dataSb.append(", groupPropertyDefinitions="); + dataSb.append(groupPropertyDefinitions); + dataSb.append(", groupTypeIds="); + dataSb.append(groupTypeIds); + dataSb.append(", groupSpecifications="); + dataSb.append(groupSpecifications); + dataSb.append(", personToGroupsMemberships="); + dataSb.append(personToGroupsMemberships); + dataSb.append(", groupToPeopleMemberships="); + dataSb.append(groupToPeopleMemberships); + dataSb.append("]"); + + StringBuilder pluginDataSb = new StringBuilder(); + pluginDataSb.append("GroupsPluginData [data="); + pluginDataSb.append(dataSb.toString()); + pluginDataSb.append("]"); + + assertEquals(pluginDataSb.toString(), pluginData.toString()); + } + } + + @Test + @UnitTestMethod(target = GroupsPluginData.Builder.class, name = "addGroupToPerson", args = { GroupId.class, + PersonId.class }) + public void testAddGroupToPerson() { + + Random random = new Random(7282493148489771700L); + + Map expectedGroupAssignments = new LinkedHashMap<>(); + + GroupsPluginData.Builder builder = GroupsPluginData.builder(); + // add in the group types + for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { + builder.addGroupTypeId(testGroupTypeId); + } + + // create some people + List personIds = new ArrayList<>(); + for (int i = 0; i < 100; i++) { + personIds.add(i); + } + + /* + * Add a few groups and add to those groups 0 to 9 randomly selected people. + * Record the assignments in the expected data structure. + */ + TestGroupTypeId testGroupTypeId = TestGroupTypeId.GROUP_TYPE_1; + for (int i = 0; i < 20; i++) { + // add the group + + builder.addGroup(new GroupId(i), testGroupTypeId); + testGroupTypeId = testGroupTypeId.next(); + // select some people and add them to the group + Collections.shuffle(personIds, random); + int count = random.nextInt(10); + for (int j = 0; j < count; j++) { + builder.addGroupToPerson(new GroupId(i), new PersonId(personIds.get(j))); + builder.addPersonToGroup(new PersonId(personIds.get(j)), new GroupId(i)); + MultiKey multiKey = new MultiKey(new GroupId(i), new PersonId(personIds.get(j))); + expectedGroupAssignments.putIfAbsent(multiKey, new MutableInteger()); + expectedGroupAssignments.get(multiKey).increment(); + } + } + + // build the group initial data + GroupsPluginData groupsPluginData = builder.build(); + + // show that the group memberships are as expected + Map actualGroupAssignments = new LinkedHashMap<>(); + + for (int i = 0; i < groupsPluginData.getPersonCount(); i++) { + PersonId personId = new PersonId(i); + for (GroupId groupId : groupsPluginData.getGroupsForPerson(personId)) { + MultiKey multiKey = new MultiKey(groupId, personId); + actualGroupAssignments.putIfAbsent(multiKey, new MutableInteger()); + actualGroupAssignments.get(multiKey).increment(); + } + } + + assertEquals(expectedGroupAssignments, actualGroupAssignments); + + // precondition test: if the group id is null + ContractException contractException = assertThrows(ContractException.class, + () -> GroupsPluginData.builder().associatePersonToGroup(null, new PersonId(0))); + assertEquals(GroupError.NULL_GROUP_ID, contractException.getErrorType()); + + // precondition test: if the person id is null + contractException = assertThrows(ContractException.class, + () -> GroupsPluginData.builder().associatePersonToGroup(new GroupId(0), null)); + assertEquals(PersonError.NULL_PERSON_ID, contractException.getErrorType()); + } + + @Test + @UnitTestMethod(target = GroupsPluginData.Builder.class, name = "addPersonToGroup", args = { PersonId.class, + GroupId.class }) + public void testAddPersonToGroup() { + + Random random = new Random(7282493148489771700L); + + Map expectedGroupAssignments = new LinkedHashMap<>(); + + GroupsPluginData.Builder builder = GroupsPluginData.builder(); + // add in the group types + for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.values()) { + builder.addGroupTypeId(testGroupTypeId); + } + + // create some people + List personIds = new ArrayList<>(); + for (int i = 0; i < 100; i++) { + personIds.add(i); + } + + /* + * Add a few groups and add to those groups 0 to 9 randomly selected people. + * Record the assignments in the expected data structure. + */ + TestGroupTypeId testGroupTypeId = TestGroupTypeId.GROUP_TYPE_1; + for (int i = 0; i < 20; i++) { + // add the group + + builder.addGroup(new GroupId(i), testGroupTypeId); + testGroupTypeId = testGroupTypeId.next(); + // select some people and add them to the group + Collections.shuffle(personIds, random); + int count = random.nextInt(10); + for (int j = 0; j < count; j++) { + builder.addGroupToPerson(new GroupId(i), new PersonId(personIds.get(j))); + builder.addPersonToGroup(new PersonId(personIds.get(j)), new GroupId(i)); + MultiKey multiKey = new MultiKey(new GroupId(i), new PersonId(personIds.get(j))); + expectedGroupAssignments.putIfAbsent(multiKey, new MutableInteger()); + expectedGroupAssignments.get(multiKey).increment(); + } + } + + // build the group initial data + GroupsPluginData groupsPluginData = builder.build(); + + // show that the group memberships are as expected + Map actualGroupAssignments = new LinkedHashMap<>(); + + for (int i = 0; i < groupsPluginData.getPersonCount(); i++) { + PersonId personId = new PersonId(i); + for (GroupId groupId : groupsPluginData.getGroupsForPerson(personId)) { + MultiKey multiKey = new MultiKey(groupId, personId); + actualGroupAssignments.putIfAbsent(multiKey, new MutableInteger()); + actualGroupAssignments.get(multiKey).increment(); + } + } + + assertEquals(expectedGroupAssignments, actualGroupAssignments); + + // precondition test: if the group id is null + ContractException contractException = assertThrows(ContractException.class, + () -> GroupsPluginData.builder().associatePersonToGroup(null, new PersonId(0))); + assertEquals(GroupError.NULL_GROUP_ID, contractException.getErrorType()); + + // precondition test: if the person id is null + contractException = assertThrows(ContractException.class, + () -> GroupsPluginData.builder().associatePersonToGroup(new GroupId(0), null)); + assertEquals(PersonError.NULL_PERSON_ID, contractException.getErrorType()); + } } diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/groups/reports/AT_GroupPopulationReportPluginData.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/groups/reports/AT_GroupPopulationReportPluginData.java index 2fda7d2a2..578699bbe 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/groups/reports/AT_GroupPopulationReportPluginData.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/groups/reports/AT_GroupPopulationReportPluginData.java @@ -138,17 +138,33 @@ public void testGetCloneBuilder() { ReportLabel reportLabel = new SimpleReportLabel(randomGenerator.nextInt()); ReportPeriod reportPeriod = ReportPeriod.values()[randomGenerator.nextInt(ReportPeriod.values().length)]; - GroupPopulationReportPluginData proupPopulationReportPluginData = // + GroupPopulationReportPluginData groupPopulationReportPluginData = // GroupPopulationReportPluginData .builder()// .setReportPeriod(reportPeriod)// - .setReportLabel(reportLabel).build(); - - // create the clone builder and have it build - GroupPopulationReportPluginData cloneGroupPopulationReportPluginData = proupPopulationReportPluginData.getCloneBuilder().build(); + .setReportLabel(reportLabel)// + .build(); - // the result should equal the original if the clone builder was - // initialized with the correct state - assertEquals(proupPopulationReportPluginData, cloneGroupPopulationReportPluginData); + // show that the returned clone builder will build an identical instance if no + // mutations are made + GroupPopulationReportPluginData.Builder cloneBuilder = groupPopulationReportPluginData.getCloneBuilder(); + assertNotNull(cloneBuilder); + assertEquals(groupPopulationReportPluginData, cloneBuilder.build()); + + // show that the clone builder builds a distinct instance if any mutation is + // made + + // setReportLabel + cloneBuilder = groupPopulationReportPluginData.getCloneBuilder(); + cloneBuilder.setReportLabel(new SimpleReportLabel("asdf")); + assertNotEquals(groupPopulationReportPluginData, cloneBuilder.build()); + + // setReportPeriod + cloneBuilder = groupPopulationReportPluginData.getCloneBuilder(); + int index = (reportPeriod.ordinal()+1)%ReportPeriod.values().length; + reportPeriod = ReportPeriod.values()[index]; + cloneBuilder.setReportPeriod(reportPeriod); + assertNotEquals(groupPopulationReportPluginData, cloneBuilder.build()); + } } diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/groups/reports/AT_GroupPropertyReportPluginData.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/groups/reports/AT_GroupPropertyReportPluginData.java index e6ef1bd95..1859751c0 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/groups/reports/AT_GroupPropertyReportPluginData.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/groups/reports/AT_GroupPropertyReportPluginData.java @@ -31,807 +31,839 @@ public class AT_GroupPropertyReportPluginData { - @Test - @UnitTestMethod(target = GroupPropertyReportPluginData.class, name = "builder", args = {}) - public void testBuilder() { - GroupPropertyReportPluginData.Builder builder = GroupPropertyReportPluginData.builder(); - assertNotNull(builder); - } - - @Test - @UnitTestMethod(target = GroupPropertyReportPluginData.Builder.class, name = "build", args = {}) - public void testBuild() { - // the specific capabilities are covered elsewhere - - // precondition test: if the report period is not assigned - ContractException contractException = assertThrows(ContractException.class, () -> // - GroupPropertyReportPluginData.builder()// - .setReportLabel(new SimpleReportLabel(getClass()))// - .build()); - assertEquals(ReportError.NULL_REPORT_PERIOD, contractException.getErrorType()); - - // precondition test: if the report label is not assigned - contractException = assertThrows(ContractException.class, () -> // - GroupPropertyReportPluginData.builder()// - .setReportPeriod(ReportPeriod.DAILY)// - .build()); - assertEquals(ReportError.NULL_REPORT_LABEL, contractException.getErrorType()); - - } - - @Test - @UnitTestMethod(target = GroupPropertyReportPluginData.Builder.class, name = "setReportLabel", args = { - ReportLabel.class }) - public void testSetReportLabel() { - - for (int i = 0; i < 30; i++) { - ReportLabel expectedReportLabel = new SimpleReportLabel(i); - GroupPropertyReportPluginData groupPropertyReportPluginData = // - GroupPropertyReportPluginData.builder()// - .setReportPeriod(ReportPeriod.DAILY)// - .setReportLabel(expectedReportLabel)// - .build(); - - assertEquals(expectedReportLabel, groupPropertyReportPluginData.getReportLabel()); - } - - // precondition: if the report label is null - ContractException contractException = assertThrows(ContractException.class, () -> { - GroupPropertyReportPluginData.builder().setReportLabel(null); - }); - assertEquals(ReportError.NULL_REPORT_LABEL, contractException.getErrorType()); - } - - @Test - @UnitTestMethod(target = GroupPropertyReportPluginData.Builder.class, name = "setReportPeriod", args = { - ReportPeriod.class }) - public void testSetReportPeriod() { - - ReportLabel reportLabel = new SimpleReportLabel("report label"); - for (ReportPeriod reportPeriod : ReportPeriod.values()) { - - GroupPropertyReportPluginData groupPropertyReportPluginData = // - GroupPropertyReportPluginData.builder()// - .setReportPeriod(reportPeriod)// - .setReportLabel(reportLabel)// - .build(); - - assertEquals(reportPeriod, groupPropertyReportPluginData.getReportPeriod()); - } - - // precondition: if the report period is null - ContractException contractException = assertThrows(ContractException.class, () -> { - GroupPropertyReportPluginData.builder().setReportPeriod(null); - }); - assertEquals(ReportError.NULL_REPORT_PERIOD, contractException.getErrorType()); - } - - @Test - @UnitTestMethod(target = GroupPropertyReportPluginData.Builder.class, name = "setDefaultInclusion", args = { - boolean.class }) - public void testSetDefaultInclusion() { - ReportLabel reportLabel = new SimpleReportLabel("report label"); - ReportPeriod reportPeriod = ReportPeriod.DAILY; - - // show the default value is true - GroupPropertyReportPluginData groupPropertyReportPluginData = // - GroupPropertyReportPluginData.builder()// - .setReportPeriod(reportPeriod)// - .setReportLabel(reportLabel)// - .build(); - assertEquals(true, groupPropertyReportPluginData.getDefaultInclusionPolicy()); - - groupPropertyReportPluginData = // - GroupPropertyReportPluginData.builder()// - .setReportPeriod(reportPeriod)// - .setReportLabel(reportLabel)// - .setDefaultInclusion(true)// - .build(); - assertEquals(true, groupPropertyReportPluginData.getDefaultInclusionPolicy()); - - groupPropertyReportPluginData = // - GroupPropertyReportPluginData.builder()// - .setReportPeriod(reportPeriod)// - .setReportLabel(reportLabel)// - .setDefaultInclusion(false)// - .build(); - assertEquals(false, groupPropertyReportPluginData.getDefaultInclusionPolicy()); - - } - - @Test - @UnitTestMethod(target = GroupPropertyReportPluginData.Builder.class, name = "includeGroupProperty", args = { - GroupTypeId.class, GroupPropertyId.class }) - public void testIncludeGroupProperty() { - ReportLabel reportLabel = new SimpleReportLabel("report label"); - ReportPeriod reportPeriod = ReportPeriod.DAILY; - - GroupPropertyReportPluginData groupPropertyReportPluginData = // - GroupPropertyReportPluginData.builder()// - .setReportPeriod(reportPeriod)// - .setReportLabel(reportLabel)// - .build(); - assertTrue(groupPropertyReportPluginData.getIncludedProperties(TestGroupTypeId.GROUP_TYPE_1).isEmpty()); - - // show that inclusion alone works - Set expectedGroupPropertyIds = new LinkedHashSet<>(); - Set expectedMultiKeys = new LinkedHashSet<>(); - - expectedGroupPropertyIds.add(TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK); - expectedGroupPropertyIds.add(TestGroupPropertyId.GROUP_PROPERTY_1_2_INTEGER_MUTABLE_NO_TRACK); - expectedGroupPropertyIds.add(TestGroupPropertyId.GROUP_PROPERTY_2_3_DOUBLE_MUTABLE_TRACK); - - GroupPropertyReportPluginData.Builder builder = GroupPropertyReportPluginData.builder()// - .setReportPeriod(reportPeriod)// - .setReportLabel(reportLabel);// - - for (TestGroupPropertyId testGroupPropertyId : expectedGroupPropertyIds) { - builder.includeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); - expectedMultiKeys.add(new MultiKey(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId)); - } - - Set actualMultiKeys = new LinkedHashSet<>(); - groupPropertyReportPluginData = builder.build(); - for (GroupTypeId testGroupTypeId : groupPropertyReportPluginData.getGroupTypeIds()) { - for (GroupPropertyId testGroupPropertyId : groupPropertyReportPluginData - .getIncludedProperties(testGroupTypeId)) { - actualMultiKeys.add(new MultiKey(testGroupTypeId, testGroupPropertyId)); - } - } - - assertEquals(expectedMultiKeys, actualMultiKeys); - - // show that inclusion will override exclusion - - builder = GroupPropertyReportPluginData.builder()// - .setReportPeriod(reportPeriod)// - .setReportLabel(reportLabel);// - - for (TestGroupPropertyId testGroupPropertyId : expectedGroupPropertyIds) { - builder.excludeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); - builder.includeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); - expectedMultiKeys.add(new MultiKey(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId)); - } - - groupPropertyReportPluginData = builder.build(); - - actualMultiKeys = new LinkedHashSet<>(); - groupPropertyReportPluginData = builder.build(); - for (GroupTypeId testGroupTypeId : groupPropertyReportPluginData.getGroupTypeIds()) { - for (GroupPropertyId testGroupPropertyId : groupPropertyReportPluginData - .getIncludedProperties(testGroupTypeId)) { - actualMultiKeys.add(new MultiKey(testGroupTypeId, testGroupPropertyId)); - } - } - - assertEquals(expectedMultiKeys, actualMultiKeys); - - // precondition: if the group type id is null - ContractException contractException = assertThrows(ContractException.class, () -> { - GroupPropertyReportPluginData.builder().includeGroupProperty(null, - TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK); - }); - assertEquals(GroupError.NULL_GROUP_TYPE_ID, contractException.getErrorType()); - - // precondition: if the group property id is null - contractException = assertThrows(ContractException.class, () -> { - GroupPropertyReportPluginData.builder().includeGroupProperty(TestGroupTypeId.GROUP_TYPE_1, null); - }); - assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); - - } - - @Test - @UnitTestMethod(target = GroupPropertyReportPluginData.Builder.class, name = "excludeGroupProperty", args = { - GroupTypeId.class, GroupPropertyId.class }) - public void testExcludeGroupProperty() { - ReportLabel reportLabel = new SimpleReportLabel("report label"); - ReportPeriod reportPeriod = ReportPeriod.DAILY; - - GroupPropertyReportPluginData groupPropertyReportPluginData = // - GroupPropertyReportPluginData.builder()// - .setReportPeriod(reportPeriod)// - .setReportLabel(reportLabel)// - .build(); - assertTrue(groupPropertyReportPluginData.getIncludedProperties(TestGroupTypeId.GROUP_TYPE_1).isEmpty()); - - // show that exclusion alone works - Set expectedGroupPropertyIds = new LinkedHashSet<>(); - Set expectedMultiKeys = new LinkedHashSet<>(); - - expectedGroupPropertyIds.add(TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK); - expectedGroupPropertyIds.add(TestGroupPropertyId.GROUP_PROPERTY_1_2_INTEGER_MUTABLE_NO_TRACK); - expectedGroupPropertyIds.add(TestGroupPropertyId.GROUP_PROPERTY_2_3_DOUBLE_MUTABLE_TRACK); - - GroupPropertyReportPluginData.Builder builder = GroupPropertyReportPluginData.builder()// - .setReportPeriod(reportPeriod)// - .setReportLabel(reportLabel);// - - for (TestGroupPropertyId testGroupPropertyId : expectedGroupPropertyIds) { - builder.excludeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); - expectedMultiKeys.add(new MultiKey(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId)); - } - - Set actualMultiKeys = new LinkedHashSet<>(); - groupPropertyReportPluginData = builder.build(); - for (GroupTypeId testGroupTypeId : groupPropertyReportPluginData.getGroupTypeIds()) { - for (GroupPropertyId testGroupPropertyId : groupPropertyReportPluginData - .getExcludedProperties(testGroupTypeId)) { - actualMultiKeys.add(new MultiKey(testGroupTypeId, testGroupPropertyId)); - } - } - - assertEquals(expectedMultiKeys, actualMultiKeys); - - // show that exclusion will override exclusion - - builder = GroupPropertyReportPluginData.builder()// - .setReportPeriod(reportPeriod)// - .setReportLabel(reportLabel);// - - for (TestGroupPropertyId testGroupPropertyId : expectedGroupPropertyIds) { - builder.includeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); - builder.excludeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); - - expectedMultiKeys.add(new MultiKey(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId)); - } - - groupPropertyReportPluginData = builder.build(); - - actualMultiKeys = new LinkedHashSet<>(); - groupPropertyReportPluginData = builder.build(); - for (GroupTypeId testGroupTypeId : groupPropertyReportPluginData.getGroupTypeIds()) { - for (GroupPropertyId testGroupPropertyId : groupPropertyReportPluginData - .getExcludedProperties(testGroupTypeId)) { - actualMultiKeys.add(new MultiKey(testGroupTypeId, testGroupPropertyId)); - } - } - - assertEquals(expectedMultiKeys, actualMultiKeys); - - // precondition: if the group type id is null - ContractException contractException = assertThrows(ContractException.class, () -> { - GroupPropertyReportPluginData.builder().excludeGroupProperty(null, - TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK); - }); - assertEquals(GroupError.NULL_GROUP_TYPE_ID, contractException.getErrorType()); - - // precondition: if the group property id is null - contractException = assertThrows(ContractException.class, () -> { - GroupPropertyReportPluginData.builder().excludeGroupProperty(TestGroupTypeId.GROUP_TYPE_1, null); - }); - assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); - } - - @Test - @UnitTestMethod(target = GroupPropertyReportPluginData.class, name = "getReportLabel", args = {}) - public void testGetReportLabel() { - for (int i = 0; i < 30; i++) { - ReportLabel expectedReportLabel = new SimpleReportLabel(i); - GroupPropertyReportPluginData groupPropertyReportPluginData = // - GroupPropertyReportPluginData.builder()// - .setReportPeriod(ReportPeriod.DAILY)// - .setReportLabel(expectedReportLabel)// - .build(); - - assertEquals(expectedReportLabel, groupPropertyReportPluginData.getReportLabel()); - } - - } - - @Test - @UnitTestMethod(target = GroupPropertyReportPluginData.class, name = "getReportPeriod", args = {}) - public void testGetReportPeriod() { - ReportLabel reportLabel = new SimpleReportLabel("report label"); - for (ReportPeriod reportPeriod : ReportPeriod.values()) { - - GroupPropertyReportPluginData groupPropertyReportPluginData = // - GroupPropertyReportPluginData.builder()// - .setReportPeriod(reportPeriod)// - .setReportLabel(reportLabel)// - .build(); - - assertEquals(reportPeriod, groupPropertyReportPluginData.getReportPeriod()); - } - } - - @Test - @UnitTestMethod(target = GroupPropertyReportPluginData.class, name = "getIncludedProperties", args = { - GroupTypeId.class }) - - public void testGetIncludedProperties() { - ReportLabel reportLabel = new SimpleReportLabel("report label"); - ReportPeriod reportPeriod = ReportPeriod.DAILY; - - GroupPropertyReportPluginData groupPropertyReportPluginData = // - GroupPropertyReportPluginData.builder()// - .setReportPeriod(reportPeriod)// - .setReportLabel(reportLabel)// - .build(); - assertTrue(groupPropertyReportPluginData.getIncludedProperties(TestGroupTypeId.GROUP_TYPE_1).isEmpty()); - - // show that inclusion alone works - Set expectedGroupPropertyIds = new LinkedHashSet<>(); - Set expectedMultiKeys = new LinkedHashSet<>(); - - expectedGroupPropertyIds.add(TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK); - expectedGroupPropertyIds.add(TestGroupPropertyId.GROUP_PROPERTY_1_2_INTEGER_MUTABLE_NO_TRACK); - expectedGroupPropertyIds.add(TestGroupPropertyId.GROUP_PROPERTY_2_3_DOUBLE_MUTABLE_TRACK); - - GroupPropertyReportPluginData.Builder builder = GroupPropertyReportPluginData.builder()// - .setReportPeriod(reportPeriod)// - .setReportLabel(reportLabel);// - - for (TestGroupPropertyId testGroupPropertyId : expectedGroupPropertyIds) { - builder.includeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); - expectedMultiKeys.add(new MultiKey(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId)); - } - - Set actualMultiKeys = new LinkedHashSet<>(); - groupPropertyReportPluginData = builder.build(); - for (GroupTypeId testGroupTypeId : groupPropertyReportPluginData.getGroupTypeIds()) { - for (GroupPropertyId testGroupPropertyId : groupPropertyReportPluginData - .getIncludedProperties(testGroupTypeId)) { - actualMultiKeys.add(new MultiKey(testGroupTypeId, testGroupPropertyId)); - } - } - - assertEquals(expectedMultiKeys, actualMultiKeys); - - // show that inclusion will override exclusion - - builder = GroupPropertyReportPluginData.builder()// - .setReportPeriod(reportPeriod)// - .setReportLabel(reportLabel);// - - for (TestGroupPropertyId testGroupPropertyId : expectedGroupPropertyIds) { - builder.excludeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); - builder.includeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); - expectedMultiKeys.add(new MultiKey(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId)); - } - - groupPropertyReportPluginData = builder.build(); - - actualMultiKeys = new LinkedHashSet<>(); - groupPropertyReportPluginData = builder.build(); - for (GroupTypeId testGroupTypeId : groupPropertyReportPluginData.getGroupTypeIds()) { - for (GroupPropertyId testGroupPropertyId : groupPropertyReportPluginData - .getIncludedProperties(testGroupTypeId)) { - actualMultiKeys.add(new MultiKey(testGroupTypeId, testGroupPropertyId)); - } - } - - assertEquals(expectedMultiKeys, actualMultiKeys); - - // precondition: if the group type id is null - ContractException contractException = assertThrows(ContractException.class, () -> { - GroupPropertyReportPluginData groupPropertyReportPluginData2 = GroupPropertyReportPluginData.builder() - .setReportLabel(reportLabel).setReportPeriod(reportPeriod).build(); - groupPropertyReportPluginData2.getIncludedProperties(null); - }); - assertEquals(GroupError.NULL_GROUP_TYPE_ID, contractException.getErrorType()); - - } - - @Test - @UnitTestMethod(target = GroupPropertyReportPluginData.class, name = "getExcludedProperties", args = { - GroupTypeId.class }) - public void testGetExcludedProperties() { - ReportLabel reportLabel = new SimpleReportLabel("report label"); - ReportPeriod reportPeriod = ReportPeriod.DAILY; - - GroupPropertyReportPluginData groupPropertyReportPluginData = // - GroupPropertyReportPluginData.builder()// - .setReportPeriod(reportPeriod)// - .setReportLabel(reportLabel)// - .build(); - assertTrue(groupPropertyReportPluginData.getIncludedProperties(TestGroupTypeId.GROUP_TYPE_1).isEmpty()); - - // show that exclusion alone works - Set expectedGroupPropertyIds = new LinkedHashSet<>(); - Set expectedMultiKeys = new LinkedHashSet<>(); - - expectedGroupPropertyIds.add(TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK); - expectedGroupPropertyIds.add(TestGroupPropertyId.GROUP_PROPERTY_1_2_INTEGER_MUTABLE_NO_TRACK); - expectedGroupPropertyIds.add(TestGroupPropertyId.GROUP_PROPERTY_2_3_DOUBLE_MUTABLE_TRACK); - - GroupPropertyReportPluginData.Builder builder = GroupPropertyReportPluginData.builder()// - .setReportPeriod(reportPeriod)// - .setReportLabel(reportLabel);// - - for (TestGroupPropertyId testGroupPropertyId : expectedGroupPropertyIds) { - builder.excludeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); - expectedMultiKeys.add(new MultiKey(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId)); - } - - Set actualMultiKeys = new LinkedHashSet<>(); - groupPropertyReportPluginData = builder.build(); - for (GroupTypeId testGroupTypeId : groupPropertyReportPluginData.getGroupTypeIds()) { - for (GroupPropertyId testGroupPropertyId : groupPropertyReportPluginData - .getExcludedProperties(testGroupTypeId)) { - actualMultiKeys.add(new MultiKey(testGroupTypeId, testGroupPropertyId)); - } - } - - assertEquals(expectedMultiKeys, actualMultiKeys); - - // show that exclusion will override exclusion - - builder = GroupPropertyReportPluginData.builder()// - .setReportPeriod(reportPeriod)// - .setReportLabel(reportLabel);// - - for (TestGroupPropertyId testGroupPropertyId : expectedGroupPropertyIds) { - builder.includeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); - builder.excludeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); - - expectedMultiKeys.add(new MultiKey(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId)); - } - - groupPropertyReportPluginData = builder.build(); - - actualMultiKeys = new LinkedHashSet<>(); - groupPropertyReportPluginData = builder.build(); - for (GroupTypeId testGroupTypeId : groupPropertyReportPluginData.getGroupTypeIds()) { - for (GroupPropertyId testGroupPropertyId : groupPropertyReportPluginData - .getExcludedProperties(testGroupTypeId)) { - actualMultiKeys.add(new MultiKey(testGroupTypeId, testGroupPropertyId)); - } - } - - assertEquals(expectedMultiKeys, actualMultiKeys); - - // precondition: if the group type id is null - ContractException contractException = assertThrows(ContractException.class, () -> { - GroupPropertyReportPluginData groupPropertyReportPluginData2 = GroupPropertyReportPluginData.builder() - .setReportLabel(reportLabel).setReportPeriod(reportPeriod).build(); - groupPropertyReportPluginData2.getExcludedProperties(null); - }); - assertEquals(GroupError.NULL_GROUP_TYPE_ID, contractException.getErrorType()); - } - - @Test - @UnitTestMethod(target = GroupPropertyReportPluginData.class, name = "getDefaultInclusionPolicy", args = {}) - public void testGetDefaultInclusionPolicy() { - ReportLabel reportLabel = new SimpleReportLabel("report label"); - ReportPeriod reportPeriod = ReportPeriod.DAILY; - - // show the default value is true - GroupPropertyReportPluginData groupPropertyReportPluginData = // - GroupPropertyReportPluginData.builder()// - .setReportPeriod(reportPeriod)// - .setReportLabel(reportLabel)// - .build(); - assertEquals(true, groupPropertyReportPluginData.getDefaultInclusionPolicy()); - - groupPropertyReportPluginData = // - GroupPropertyReportPluginData.builder()// - .setReportPeriod(reportPeriod)// - .setReportLabel(reportLabel)// - .setDefaultInclusion(true)// - .build(); - assertEquals(true, groupPropertyReportPluginData.getDefaultInclusionPolicy()); - - groupPropertyReportPluginData = // - GroupPropertyReportPluginData.builder()// - .setReportPeriod(reportPeriod)// - .setReportLabel(reportLabel)// - .setDefaultInclusion(false)// - .build(); - assertEquals(false, groupPropertyReportPluginData.getDefaultInclusionPolicy()); - } - - @Test - @UnitTestMethod(target = GroupPropertyReportPluginData.class, name = "getCloneBuilder", args = {}) - public void testGetCloneBuilder() { - - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(7759639255438669162L); - - for (int i = 0; i < 10; i++) { - - // build a GroupPropertyReportPluginData from random inputs - ReportLabel reportLabel = new SimpleReportLabel(randomGenerator.nextInt()); - ReportPeriod reportPeriod = ReportPeriod.values()[randomGenerator.nextInt(ReportPeriod.values().length)]; - - GroupPropertyReportPluginData.Builder builder = // - GroupPropertyReportPluginData.builder()// - .setReportPeriod(reportPeriod)// - .setReportLabel(reportLabel); - - for (int j = 0; j < 10; j++) { - TestGroupPropertyId testGroupPropertyId = TestGroupPropertyId - .getRandomTestGroupPropertyId(randomGenerator); - if (randomGenerator.nextBoolean()) { - builder.includeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); - } else { - builder.excludeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); - } - } - - builder.setDefaultInclusion(randomGenerator.nextBoolean()).build(); - - GroupPropertyReportPluginData groupPropertyReportPluginData = builder.build(); - - // create the clone builder and have it build - GroupPropertyReportPluginData cloneGroupPropertyReportPluginData = groupPropertyReportPluginData - .getCloneBuilder().build(); - - // the result should equal the original if the clone builder was - // initialized with the correct state - assertEquals(groupPropertyReportPluginData, cloneGroupPropertyReportPluginData); - - } - } - - @Test - @UnitTestMethod(target = GroupPropertyReportPluginData.class, name = "equals", args = { Object.class }) - public void testEquals() { - - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(7759639255438669162L); - for (int i = 0; i < 10; i++) { - // build a GroupPropertyReportPluginData from the same random - // inputs - GroupPropertyReportPluginData.Builder builder1 = GroupPropertyReportPluginData.builder(); - GroupPropertyReportPluginData.Builder builder2 = GroupPropertyReportPluginData.builder(); - - ReportLabel reportLabel = new SimpleReportLabel(randomGenerator.nextInt(100)); - builder1.setReportLabel(reportLabel); - builder2.setReportLabel(reportLabel); - - ReportPeriod reportPeriod = ReportPeriod.values()[randomGenerator.nextInt(ReportPeriod.values().length)]; - builder1.setReportPeriod(reportPeriod); - builder2.setReportPeriod(reportPeriod); - - for (int j = 0; j < 10; j++) { - TestGroupPropertyId testGroupPropertyId = TestGroupPropertyId - .getRandomTestGroupPropertyId(randomGenerator); - if (randomGenerator.nextBoolean()) { - builder1.includeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); - builder2.includeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); - } else { - builder1.excludeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); - builder2.excludeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); - } - } - - boolean defaultInclusion = randomGenerator.nextBoolean(); - builder1.setDefaultInclusion(defaultInclusion).build(); - builder2.setDefaultInclusion(defaultInclusion).build(); - - GroupPropertyReportPluginData groupPropertyReportPluginData1 = builder1.build(); - GroupPropertyReportPluginData groupPropertyReportPluginData2 = builder2.build(); - - assertEquals(groupPropertyReportPluginData1, groupPropertyReportPluginData2); - - // show that plugin datas with different inputs are not equal - - // change the default inclusion - groupPropertyReportPluginData2 = // - groupPropertyReportPluginData1.getCloneBuilder()// - .setDefaultInclusion(!defaultInclusion)// - .build(); - assertNotEquals(groupPropertyReportPluginData2, groupPropertyReportPluginData1); - - // change the report period - int ord = reportPeriod.ordinal() + 1; - ord = ord % ReportPeriod.values().length; - reportPeriod = ReportPeriod.values()[ord]; - groupPropertyReportPluginData2 = // - groupPropertyReportPluginData1.getCloneBuilder()// - .setReportPeriod(reportPeriod)// - .build(); - assertNotEquals(groupPropertyReportPluginData2, groupPropertyReportPluginData1); - - // change the report label - reportLabel = new SimpleReportLabel(1000); - groupPropertyReportPluginData2 = // - groupPropertyReportPluginData1.getCloneBuilder()// - .setReportLabel(reportLabel)// - .build(); - assertNotEquals(groupPropertyReportPluginData2, groupPropertyReportPluginData1); - - // change an included property id - for (GroupTypeId testGroupTypeId : groupPropertyReportPluginData1.getGroupTypeIds()) { - if (!groupPropertyReportPluginData1.getIncludedProperties(testGroupTypeId).isEmpty()) { - GroupPropertyId testGroupPropertyId = groupPropertyReportPluginData1 - .getIncludedProperties(testGroupTypeId).iterator().next(); - groupPropertyReportPluginData2 = // - groupPropertyReportPluginData1.getCloneBuilder()// - .excludeGroupProperty(testGroupTypeId, testGroupPropertyId)// - .build(); - assertNotEquals(groupPropertyReportPluginData2, groupPropertyReportPluginData1); - } - } - // change an excluded property id - for (GroupTypeId testGroupTypeId : groupPropertyReportPluginData1.getGroupTypeIds()) { - if (!groupPropertyReportPluginData1.getExcludedProperties(testGroupTypeId).isEmpty()) { - GroupPropertyId testGroupPropertyId = groupPropertyReportPluginData1 - .getExcludedProperties(testGroupTypeId).iterator().next(); - groupPropertyReportPluginData2 = // - groupPropertyReportPluginData1.getCloneBuilder()// - .includeGroupProperty(testGroupTypeId, testGroupPropertyId)// - .build(); - assertNotEquals(groupPropertyReportPluginData2, groupPropertyReportPluginData1); - } - } - } - - } - - @Test - @UnitTestMethod(target = GroupPropertyReportPluginData.class, name = "hashCode", args = {}) - public void testHashCode() { - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(9079768427072825406L); - - Set observedHashCodes = new LinkedHashSet<>(); - for (int i = 0; i < 50; i++) { - // build a GroupPropertyReportPluginData from the same random - // inputs - GroupPropertyReportPluginData.Builder builder1 = GroupPropertyReportPluginData.builder(); - GroupPropertyReportPluginData.Builder builder2 = GroupPropertyReportPluginData.builder(); - - ReportLabel reportLabel = new SimpleReportLabel(randomGenerator.nextInt(100)); - builder1.setReportLabel(reportLabel); - builder2.setReportLabel(reportLabel); - - ReportPeriod reportPeriod = ReportPeriod.values()[randomGenerator.nextInt(ReportPeriod.values().length)]; - builder1.setReportPeriod(reportPeriod); - builder2.setReportPeriod(reportPeriod); - - for (int j = 0; j < 10; j++) { - TestGroupPropertyId testGroupPropertyId = TestGroupPropertyId - .getRandomTestGroupPropertyId(randomGenerator); - if (randomGenerator.nextBoolean()) { - builder1.includeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); - builder2.includeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); - } else { - builder1.excludeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); - builder2.excludeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); - } - } - - boolean defaultInclusion = randomGenerator.nextBoolean(); - builder1.setDefaultInclusion(defaultInclusion).build(); - builder2.setDefaultInclusion(defaultInclusion).build(); - - GroupPropertyReportPluginData groupPropertyReportPluginData1 = builder1.build(); - GroupPropertyReportPluginData groupPropertyReportPluginData2 = builder2.build(); - - // show that the hash code is stable - int hashCode = groupPropertyReportPluginData1.hashCode(); - assertEquals(hashCode, groupPropertyReportPluginData1.hashCode()); - assertEquals(hashCode, groupPropertyReportPluginData1.hashCode()); - assertEquals(hashCode, groupPropertyReportPluginData1.hashCode()); - assertEquals(hashCode, groupPropertyReportPluginData1.hashCode()); - - // show that equal objects have equal hash codes - assertEquals(groupPropertyReportPluginData1.hashCode(), groupPropertyReportPluginData2.hashCode()); - - // collect the hashcode - observedHashCodes.add(groupPropertyReportPluginData1.hashCode()); - } - - /* - * The hash codes should be dispersed -- we only show that they are unique - * values -- this is dependent on the random seed - */ - assertEquals(50, observedHashCodes.size()); - - } - - @Test - @UnitTestMethod(target = GroupPropertyReportPluginData.class, name = "getGroupTypeIds", args = {}) - public void testGetGroupTypeIds() { - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(626906625322362256L); - - for (int i = 0; i < 50; i++) { - GroupPropertyReportPluginData.Builder builder1 = GroupPropertyReportPluginData.builder(); - - ReportLabel reportLabel = new SimpleReportLabel(randomGenerator.nextInt(100)); - builder1.setReportLabel(reportLabel); - - ReportPeriod reportPeriod = ReportPeriod.values()[randomGenerator.nextInt(ReportPeriod.values().length)]; - builder1.setReportPeriod(reportPeriod); - - Set expectedGroupTypeIds = new LinkedHashSet<>(); - - int propertyCount = randomGenerator.nextInt(3) + 1; - for (int j = 0; j < propertyCount; j++) { - TestGroupPropertyId testGroupPropertyId = TestGroupPropertyId - .getRandomTestGroupPropertyId(randomGenerator); - expectedGroupTypeIds.add(testGroupPropertyId.getTestGroupTypeId()); - if (randomGenerator.nextBoolean()) { - builder1.includeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); - } else { - builder1.excludeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); - } - } - - boolean defaultInclusion = randomGenerator.nextBoolean(); - builder1.setDefaultInclusion(defaultInclusion).build(); - - GroupPropertyReportPluginData groupPropertyReportPluginData = builder1.build(); - - assertEquals(expectedGroupTypeIds, groupPropertyReportPluginData.getGroupTypeIds()); - } - - } - - @Test - @UnitTestMethod(target = GroupPropertyReportPluginData.class, name = "toString", args = {}) - public void testToString() { - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(2394011517139293620L); - for (int i = 0; i < 10; i++) { - GroupPropertyReportPluginData.Builder builder = GroupPropertyReportPluginData.builder(); - - ReportLabel reportLabel = new SimpleReportLabel(randomGenerator.nextInt(100)); - builder.setReportLabel(reportLabel); - - ReportPeriod reportPeriod = ReportPeriod.values()[randomGenerator.nextInt(ReportPeriod.values().length)]; - builder.setReportPeriod(reportPeriod); - - Map> includedIds = new LinkedHashMap<>(); - Map> excludedIds = new LinkedHashMap<>(); - - for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.getShuffledTestGroupTypeIds(randomGenerator)) { - for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId - .getShuffledTestGroupPropertyIds(testGroupTypeId, randomGenerator)) { - if (randomGenerator.nextBoolean()) { - builder.includeGroupProperty(testGroupTypeId, testGroupPropertyId); - Set set = includedIds.get(testGroupTypeId); - if (set == null) { - set = new LinkedHashSet<>(); - includedIds.put(testGroupTypeId, set); - } - set.add(testGroupPropertyId); - set = excludedIds.get(testGroupTypeId); - if (set != null) { - set.remove(testGroupPropertyId); - } - } else { - builder.excludeGroupProperty(testGroupTypeId, testGroupPropertyId); - Set set = excludedIds.get(testGroupTypeId); - if (set == null) { - set = new LinkedHashSet<>(); - excludedIds.put(testGroupTypeId, set); - } - set.add(testGroupPropertyId); - set = includedIds.get(testGroupTypeId); - if (set != null) { - set.remove(testGroupPropertyId); - } - } - } - } - - boolean defaultInclusion = randomGenerator.nextBoolean(); - builder.setDefaultInclusion(defaultInclusion).build(); - - GroupPropertyReportPluginData groupPropertyReportPluginData = builder.build(); - - StringBuilder sb = new StringBuilder(); - sb.append("GroupPropertyReportPluginData [data="); - - StringBuilder superDataBuilder = new StringBuilder(); - superDataBuilder.append("Data [reportLabel="); - superDataBuilder.append(reportLabel); - superDataBuilder.append(", reportPeriod="); - superDataBuilder.append(reportPeriod); - - StringBuilder dataBuilder = new StringBuilder(); - dataBuilder.append(superDataBuilder.toString()); - dataBuilder.append(", includedProperties="); - dataBuilder.append(includedIds); - dataBuilder.append(", excludedProperties="); - dataBuilder.append(excludedIds); - dataBuilder.append(", defaultInclusionPolicy="); - dataBuilder.append(defaultInclusion); - dataBuilder.append("]"); - - sb.append(dataBuilder.toString()); - sb.append("]"); - - assertEquals(sb.toString(), groupPropertyReportPluginData.toString()); - } - } + @Test + @UnitTestMethod(target = GroupPropertyReportPluginData.class, name = "builder", args = {}) + public void testBuilder() { + GroupPropertyReportPluginData.Builder builder = GroupPropertyReportPluginData.builder(); + assertNotNull(builder); + } + + @Test + @UnitTestMethod(target = GroupPropertyReportPluginData.Builder.class, name = "build", args = {}) + public void testBuild() { + // the specific capabilities are covered elsewhere + + // precondition test: if the report period is not assigned + ContractException contractException = assertThrows(ContractException.class, () -> // + GroupPropertyReportPluginData.builder()// + .setReportLabel(new SimpleReportLabel(getClass()))// + .build()); + assertEquals(ReportError.NULL_REPORT_PERIOD, contractException.getErrorType()); + + // precondition test: if the report label is not assigned + contractException = assertThrows(ContractException.class, () -> // + GroupPropertyReportPluginData.builder()// + .setReportPeriod(ReportPeriod.DAILY)// + .build()); + assertEquals(ReportError.NULL_REPORT_LABEL, contractException.getErrorType()); + + } + + @Test + @UnitTestMethod(target = GroupPropertyReportPluginData.Builder.class, name = "setReportLabel", args = { + ReportLabel.class }) + public void testSetReportLabel() { + + for (int i = 0; i < 30; i++) { + ReportLabel expectedReportLabel = new SimpleReportLabel(i); + GroupPropertyReportPluginData groupPropertyReportPluginData = // + GroupPropertyReportPluginData.builder()// + .setReportPeriod(ReportPeriod.DAILY)// + .setReportLabel(expectedReportLabel)// + .build(); + + assertEquals(expectedReportLabel, groupPropertyReportPluginData.getReportLabel()); + } + + // precondition: if the report label is null + ContractException contractException = assertThrows(ContractException.class, () -> { + GroupPropertyReportPluginData.builder().setReportLabel(null); + }); + assertEquals(ReportError.NULL_REPORT_LABEL, contractException.getErrorType()); + } + + @Test + @UnitTestMethod(target = GroupPropertyReportPluginData.Builder.class, name = "setReportPeriod", args = { + ReportPeriod.class }) + public void testSetReportPeriod() { + + ReportLabel reportLabel = new SimpleReportLabel("report label"); + for (ReportPeriod reportPeriod : ReportPeriod.values()) { + + GroupPropertyReportPluginData groupPropertyReportPluginData = // + GroupPropertyReportPluginData.builder()// + .setReportPeriod(reportPeriod)// + .setReportLabel(reportLabel)// + .build(); + + assertEquals(reportPeriod, groupPropertyReportPluginData.getReportPeriod()); + } + + // precondition: if the report period is null + ContractException contractException = assertThrows(ContractException.class, () -> { + GroupPropertyReportPluginData.builder().setReportPeriod(null); + }); + assertEquals(ReportError.NULL_REPORT_PERIOD, contractException.getErrorType()); + } + + @Test + @UnitTestMethod(target = GroupPropertyReportPluginData.Builder.class, name = "setDefaultInclusion", args = { + boolean.class }) + public void testSetDefaultInclusion() { + ReportLabel reportLabel = new SimpleReportLabel("report label"); + ReportPeriod reportPeriod = ReportPeriod.DAILY; + + // show the default value is true + GroupPropertyReportPluginData groupPropertyReportPluginData = // + GroupPropertyReportPluginData.builder()// + .setReportPeriod(reportPeriod)// + .setReportLabel(reportLabel)// + .build(); + assertEquals(true, groupPropertyReportPluginData.getDefaultInclusionPolicy()); + + groupPropertyReportPluginData = // + GroupPropertyReportPluginData.builder()// + .setReportPeriod(reportPeriod)// + .setReportLabel(reportLabel)// + .setDefaultInclusion(true)// + .build(); + assertEquals(true, groupPropertyReportPluginData.getDefaultInclusionPolicy()); + + groupPropertyReportPluginData = // + GroupPropertyReportPluginData.builder()// + .setReportPeriod(reportPeriod)// + .setReportLabel(reportLabel)// + .setDefaultInclusion(false)// + .build(); + assertEquals(false, groupPropertyReportPluginData.getDefaultInclusionPolicy()); + + } + + @Test + @UnitTestMethod(target = GroupPropertyReportPluginData.Builder.class, name = "includeGroupProperty", args = { + GroupTypeId.class, GroupPropertyId.class }) + public void testIncludeGroupProperty() { + ReportLabel reportLabel = new SimpleReportLabel("report label"); + ReportPeriod reportPeriod = ReportPeriod.DAILY; + + GroupPropertyReportPluginData groupPropertyReportPluginData = // + GroupPropertyReportPluginData.builder()// + .setReportPeriod(reportPeriod)// + .setReportLabel(reportLabel)// + .build(); + assertTrue(groupPropertyReportPluginData.getIncludedProperties(TestGroupTypeId.GROUP_TYPE_1).isEmpty()); + + // show that inclusion alone works + Set expectedGroupPropertyIds = new LinkedHashSet<>(); + Set expectedMultiKeys = new LinkedHashSet<>(); + + expectedGroupPropertyIds.add(TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK); + expectedGroupPropertyIds.add(TestGroupPropertyId.GROUP_PROPERTY_1_2_INTEGER_MUTABLE_NO_TRACK); + expectedGroupPropertyIds.add(TestGroupPropertyId.GROUP_PROPERTY_2_3_DOUBLE_MUTABLE_TRACK); + + GroupPropertyReportPluginData.Builder builder = GroupPropertyReportPluginData.builder()// + .setReportPeriod(reportPeriod)// + .setReportLabel(reportLabel);// + + for (TestGroupPropertyId testGroupPropertyId : expectedGroupPropertyIds) { + builder.includeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); + expectedMultiKeys.add(new MultiKey(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId)); + } + + Set actualMultiKeys = new LinkedHashSet<>(); + groupPropertyReportPluginData = builder.build(); + for (GroupTypeId testGroupTypeId : groupPropertyReportPluginData.getGroupTypeIds()) { + for (GroupPropertyId testGroupPropertyId : groupPropertyReportPluginData + .getIncludedProperties(testGroupTypeId)) { + actualMultiKeys.add(new MultiKey(testGroupTypeId, testGroupPropertyId)); + } + } + + assertEquals(expectedMultiKeys, actualMultiKeys); + + // show that inclusion will override exclusion + + builder = GroupPropertyReportPluginData.builder()// + .setReportPeriod(reportPeriod)// + .setReportLabel(reportLabel);// + + for (TestGroupPropertyId testGroupPropertyId : expectedGroupPropertyIds) { + builder.excludeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); + builder.includeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); + expectedMultiKeys.add(new MultiKey(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId)); + } + + groupPropertyReportPluginData = builder.build(); + + actualMultiKeys = new LinkedHashSet<>(); + groupPropertyReportPluginData = builder.build(); + for (GroupTypeId testGroupTypeId : groupPropertyReportPluginData.getGroupTypeIds()) { + for (GroupPropertyId testGroupPropertyId : groupPropertyReportPluginData + .getIncludedProperties(testGroupTypeId)) { + actualMultiKeys.add(new MultiKey(testGroupTypeId, testGroupPropertyId)); + } + } + + assertEquals(expectedMultiKeys, actualMultiKeys); + + // precondition: if the group type id is null + ContractException contractException = assertThrows(ContractException.class, () -> { + GroupPropertyReportPluginData.builder().includeGroupProperty(null, + TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK); + }); + assertEquals(GroupError.NULL_GROUP_TYPE_ID, contractException.getErrorType()); + + // precondition: if the group property id is null + contractException = assertThrows(ContractException.class, () -> { + GroupPropertyReportPluginData.builder().includeGroupProperty(TestGroupTypeId.GROUP_TYPE_1, null); + }); + assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); + + } + + @Test + @UnitTestMethod(target = GroupPropertyReportPluginData.Builder.class, name = "excludeGroupProperty", args = { + GroupTypeId.class, GroupPropertyId.class }) + public void testExcludeGroupProperty() { + ReportLabel reportLabel = new SimpleReportLabel("report label"); + ReportPeriod reportPeriod = ReportPeriod.DAILY; + + GroupPropertyReportPluginData groupPropertyReportPluginData = // + GroupPropertyReportPluginData.builder()// + .setReportPeriod(reportPeriod)// + .setReportLabel(reportLabel)// + .build(); + assertTrue(groupPropertyReportPluginData.getIncludedProperties(TestGroupTypeId.GROUP_TYPE_1).isEmpty()); + + // show that exclusion alone works + Set expectedGroupPropertyIds = new LinkedHashSet<>(); + Set expectedMultiKeys = new LinkedHashSet<>(); + + expectedGroupPropertyIds.add(TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK); + expectedGroupPropertyIds.add(TestGroupPropertyId.GROUP_PROPERTY_1_2_INTEGER_MUTABLE_NO_TRACK); + expectedGroupPropertyIds.add(TestGroupPropertyId.GROUP_PROPERTY_2_3_DOUBLE_MUTABLE_TRACK); + + GroupPropertyReportPluginData.Builder builder = GroupPropertyReportPluginData.builder()// + .setReportPeriod(reportPeriod)// + .setReportLabel(reportLabel);// + + for (TestGroupPropertyId testGroupPropertyId : expectedGroupPropertyIds) { + builder.excludeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); + expectedMultiKeys.add(new MultiKey(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId)); + } + + Set actualMultiKeys = new LinkedHashSet<>(); + groupPropertyReportPluginData = builder.build(); + for (GroupTypeId testGroupTypeId : groupPropertyReportPluginData.getGroupTypeIds()) { + for (GroupPropertyId testGroupPropertyId : groupPropertyReportPluginData + .getExcludedProperties(testGroupTypeId)) { + actualMultiKeys.add(new MultiKey(testGroupTypeId, testGroupPropertyId)); + } + } + + assertEquals(expectedMultiKeys, actualMultiKeys); + + // show that exclusion will override exclusion + + builder = GroupPropertyReportPluginData.builder()// + .setReportPeriod(reportPeriod)// + .setReportLabel(reportLabel);// + + for (TestGroupPropertyId testGroupPropertyId : expectedGroupPropertyIds) { + builder.includeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); + builder.excludeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); + + expectedMultiKeys.add(new MultiKey(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId)); + } + + groupPropertyReportPluginData = builder.build(); + + actualMultiKeys = new LinkedHashSet<>(); + groupPropertyReportPluginData = builder.build(); + for (GroupTypeId testGroupTypeId : groupPropertyReportPluginData.getGroupTypeIds()) { + for (GroupPropertyId testGroupPropertyId : groupPropertyReportPluginData + .getExcludedProperties(testGroupTypeId)) { + actualMultiKeys.add(new MultiKey(testGroupTypeId, testGroupPropertyId)); + } + } + + assertEquals(expectedMultiKeys, actualMultiKeys); + + // precondition: if the group type id is null + ContractException contractException = assertThrows(ContractException.class, () -> { + GroupPropertyReportPluginData.builder().excludeGroupProperty(null, + TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK); + }); + assertEquals(GroupError.NULL_GROUP_TYPE_ID, contractException.getErrorType()); + + // precondition: if the group property id is null + contractException = assertThrows(ContractException.class, () -> { + GroupPropertyReportPluginData.builder().excludeGroupProperty(TestGroupTypeId.GROUP_TYPE_1, null); + }); + assertEquals(PropertyError.NULL_PROPERTY_ID, contractException.getErrorType()); + } + + @Test + @UnitTestMethod(target = GroupPropertyReportPluginData.class, name = "getReportLabel", args = {}) + public void testGetReportLabel() { + for (int i = 0; i < 30; i++) { + ReportLabel expectedReportLabel = new SimpleReportLabel(i); + GroupPropertyReportPluginData groupPropertyReportPluginData = // + GroupPropertyReportPluginData.builder()// + .setReportPeriod(ReportPeriod.DAILY)// + .setReportLabel(expectedReportLabel)// + .build(); + + assertEquals(expectedReportLabel, groupPropertyReportPluginData.getReportLabel()); + } + + } + + @Test + @UnitTestMethod(target = GroupPropertyReportPluginData.class, name = "getReportPeriod", args = {}) + public void testGetReportPeriod() { + ReportLabel reportLabel = new SimpleReportLabel("report label"); + for (ReportPeriod reportPeriod : ReportPeriod.values()) { + + GroupPropertyReportPluginData groupPropertyReportPluginData = // + GroupPropertyReportPluginData.builder()// + .setReportPeriod(reportPeriod)// + .setReportLabel(reportLabel)// + .build(); + + assertEquals(reportPeriod, groupPropertyReportPluginData.getReportPeriod()); + } + } + + @Test + @UnitTestMethod(target = GroupPropertyReportPluginData.class, name = "getIncludedProperties", args = { + GroupTypeId.class }) + + public void testGetIncludedProperties() { + ReportLabel reportLabel = new SimpleReportLabel("report label"); + ReportPeriod reportPeriod = ReportPeriod.DAILY; + + GroupPropertyReportPluginData groupPropertyReportPluginData = // + GroupPropertyReportPluginData.builder()// + .setReportPeriod(reportPeriod)// + .setReportLabel(reportLabel)// + .build(); + assertTrue(groupPropertyReportPluginData.getIncludedProperties(TestGroupTypeId.GROUP_TYPE_1).isEmpty()); + + // show that inclusion alone works + Set expectedGroupPropertyIds = new LinkedHashSet<>(); + Set expectedMultiKeys = new LinkedHashSet<>(); + + expectedGroupPropertyIds.add(TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK); + expectedGroupPropertyIds.add(TestGroupPropertyId.GROUP_PROPERTY_1_2_INTEGER_MUTABLE_NO_TRACK); + expectedGroupPropertyIds.add(TestGroupPropertyId.GROUP_PROPERTY_2_3_DOUBLE_MUTABLE_TRACK); + + GroupPropertyReportPluginData.Builder builder = GroupPropertyReportPluginData.builder()// + .setReportPeriod(reportPeriod)// + .setReportLabel(reportLabel);// + + for (TestGroupPropertyId testGroupPropertyId : expectedGroupPropertyIds) { + builder.includeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); + expectedMultiKeys.add(new MultiKey(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId)); + } + + Set actualMultiKeys = new LinkedHashSet<>(); + groupPropertyReportPluginData = builder.build(); + for (GroupTypeId testGroupTypeId : groupPropertyReportPluginData.getGroupTypeIds()) { + for (GroupPropertyId testGroupPropertyId : groupPropertyReportPluginData + .getIncludedProperties(testGroupTypeId)) { + actualMultiKeys.add(new MultiKey(testGroupTypeId, testGroupPropertyId)); + } + } + + assertEquals(expectedMultiKeys, actualMultiKeys); + + // show that inclusion will override exclusion + + builder = GroupPropertyReportPluginData.builder()// + .setReportPeriod(reportPeriod)// + .setReportLabel(reportLabel);// + + for (TestGroupPropertyId testGroupPropertyId : expectedGroupPropertyIds) { + builder.excludeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); + builder.includeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); + expectedMultiKeys.add(new MultiKey(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId)); + } + + groupPropertyReportPluginData = builder.build(); + + actualMultiKeys = new LinkedHashSet<>(); + groupPropertyReportPluginData = builder.build(); + for (GroupTypeId testGroupTypeId : groupPropertyReportPluginData.getGroupTypeIds()) { + for (GroupPropertyId testGroupPropertyId : groupPropertyReportPluginData + .getIncludedProperties(testGroupTypeId)) { + actualMultiKeys.add(new MultiKey(testGroupTypeId, testGroupPropertyId)); + } + } + + assertEquals(expectedMultiKeys, actualMultiKeys); + + // precondition: if the group type id is null + ContractException contractException = assertThrows(ContractException.class, () -> { + GroupPropertyReportPluginData groupPropertyReportPluginData2 = GroupPropertyReportPluginData.builder() + .setReportLabel(reportLabel).setReportPeriod(reportPeriod).build(); + groupPropertyReportPluginData2.getIncludedProperties(null); + }); + assertEquals(GroupError.NULL_GROUP_TYPE_ID, contractException.getErrorType()); + + } + + @Test + @UnitTestMethod(target = GroupPropertyReportPluginData.class, name = "getExcludedProperties", args = { + GroupTypeId.class }) + public void testGetExcludedProperties() { + ReportLabel reportLabel = new SimpleReportLabel("report label"); + ReportPeriod reportPeriod = ReportPeriod.DAILY; + + GroupPropertyReportPluginData groupPropertyReportPluginData = // + GroupPropertyReportPluginData.builder()// + .setReportPeriod(reportPeriod)// + .setReportLabel(reportLabel)// + .build(); + assertTrue(groupPropertyReportPluginData.getIncludedProperties(TestGroupTypeId.GROUP_TYPE_1).isEmpty()); + + // show that exclusion alone works + Set expectedGroupPropertyIds = new LinkedHashSet<>(); + Set expectedMultiKeys = new LinkedHashSet<>(); + + expectedGroupPropertyIds.add(TestGroupPropertyId.GROUP_PROPERTY_1_1_BOOLEAN_MUTABLE_NO_TRACK); + expectedGroupPropertyIds.add(TestGroupPropertyId.GROUP_PROPERTY_1_2_INTEGER_MUTABLE_NO_TRACK); + expectedGroupPropertyIds.add(TestGroupPropertyId.GROUP_PROPERTY_2_3_DOUBLE_MUTABLE_TRACK); + + GroupPropertyReportPluginData.Builder builder = GroupPropertyReportPluginData.builder()// + .setReportPeriod(reportPeriod)// + .setReportLabel(reportLabel);// + + for (TestGroupPropertyId testGroupPropertyId : expectedGroupPropertyIds) { + builder.excludeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); + expectedMultiKeys.add(new MultiKey(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId)); + } + + Set actualMultiKeys = new LinkedHashSet<>(); + groupPropertyReportPluginData = builder.build(); + for (GroupTypeId testGroupTypeId : groupPropertyReportPluginData.getGroupTypeIds()) { + for (GroupPropertyId testGroupPropertyId : groupPropertyReportPluginData + .getExcludedProperties(testGroupTypeId)) { + actualMultiKeys.add(new MultiKey(testGroupTypeId, testGroupPropertyId)); + } + } + + assertEquals(expectedMultiKeys, actualMultiKeys); + + // show that exclusion will override exclusion + + builder = GroupPropertyReportPluginData.builder()// + .setReportPeriod(reportPeriod)// + .setReportLabel(reportLabel);// + + for (TestGroupPropertyId testGroupPropertyId : expectedGroupPropertyIds) { + builder.includeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); + builder.excludeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); + + expectedMultiKeys.add(new MultiKey(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId)); + } + + groupPropertyReportPluginData = builder.build(); + + actualMultiKeys = new LinkedHashSet<>(); + groupPropertyReportPluginData = builder.build(); + for (GroupTypeId testGroupTypeId : groupPropertyReportPluginData.getGroupTypeIds()) { + for (GroupPropertyId testGroupPropertyId : groupPropertyReportPluginData + .getExcludedProperties(testGroupTypeId)) { + actualMultiKeys.add(new MultiKey(testGroupTypeId, testGroupPropertyId)); + } + } + + assertEquals(expectedMultiKeys, actualMultiKeys); + + // precondition: if the group type id is null + ContractException contractException = assertThrows(ContractException.class, () -> { + GroupPropertyReportPluginData groupPropertyReportPluginData2 = GroupPropertyReportPluginData.builder() + .setReportLabel(reportLabel).setReportPeriod(reportPeriod).build(); + groupPropertyReportPluginData2.getExcludedProperties(null); + }); + assertEquals(GroupError.NULL_GROUP_TYPE_ID, contractException.getErrorType()); + } + + @Test + @UnitTestMethod(target = GroupPropertyReportPluginData.class, name = "getDefaultInclusionPolicy", args = {}) + public void testGetDefaultInclusionPolicy() { + ReportLabel reportLabel = new SimpleReportLabel("report label"); + ReportPeriod reportPeriod = ReportPeriod.DAILY; + + // show the default value is true + GroupPropertyReportPluginData groupPropertyReportPluginData = // + GroupPropertyReportPluginData.builder()// + .setReportPeriod(reportPeriod)// + .setReportLabel(reportLabel)// + .build(); + assertEquals(true, groupPropertyReportPluginData.getDefaultInclusionPolicy()); + + groupPropertyReportPluginData = // + GroupPropertyReportPluginData.builder()// + .setReportPeriod(reportPeriod)// + .setReportLabel(reportLabel)// + .setDefaultInclusion(true)// + .build(); + assertEquals(true, groupPropertyReportPluginData.getDefaultInclusionPolicy()); + + groupPropertyReportPluginData = // + GroupPropertyReportPluginData.builder()// + .setReportPeriod(reportPeriod)// + .setReportLabel(reportLabel)// + .setDefaultInclusion(false)// + .build(); + assertEquals(false, groupPropertyReportPluginData.getDefaultInclusionPolicy()); + } + + @Test + @UnitTestMethod(target = GroupPropertyReportPluginData.class, name = "getCloneBuilder", args = {}) + public void testGetCloneBuilder() { + + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(7759639255438669162L); + + for (int i = 0; i < 10; i++) { + + // build a GroupPropertyReportPluginData from random inputs + ReportLabel reportLabel = new SimpleReportLabel(randomGenerator.nextInt()); + ReportPeriod reportPeriod = ReportPeriod.values()[randomGenerator.nextInt(ReportPeriod.values().length)]; + + GroupPropertyReportPluginData.Builder builder = // + GroupPropertyReportPluginData.builder()// + .setReportPeriod(reportPeriod)// + .setReportLabel(reportLabel); + + for (int j = 0; j < 10; j++) { + TestGroupPropertyId testGroupPropertyId = TestGroupPropertyId + .getRandomTestGroupPropertyId(randomGenerator); + + if (testGroupPropertyId != TestGroupPropertyId.GROUP_PROPERTY_3_3_DOUBLE_IMMUTABLE_NO_TRACK) { + if (randomGenerator.nextBoolean()) { + builder.includeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); + } else { + builder.excludeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); + } + } + } + + builder.setDefaultInclusion(randomGenerator.nextBoolean()).build(); + + GroupPropertyReportPluginData groupPropertyReportPluginData = builder.build(); + + // show that the returned clone builder will build an identical instance if no + // mutations are made + GroupPropertyReportPluginData.Builder cloneBuilder = groupPropertyReportPluginData.getCloneBuilder(); + assertNotNull(cloneBuilder); + assertEquals(groupPropertyReportPluginData, cloneBuilder.build()); + + // show that the clone builder builds a distinct instance if any mutation is + // made + + // setReportLabel + cloneBuilder = groupPropertyReportPluginData.getCloneBuilder(); + cloneBuilder.setReportLabel(new SimpleReportLabel("report label")); + assertNotEquals(groupPropertyReportPluginData, cloneBuilder.build()); + + // setDefaultInclusion + cloneBuilder = groupPropertyReportPluginData.getCloneBuilder(); + cloneBuilder.setDefaultInclusion(!groupPropertyReportPluginData.getDefaultInclusionPolicy()); + assertNotEquals(groupPropertyReportPluginData, cloneBuilder.build()); + + // setReportPeriod + cloneBuilder = groupPropertyReportPluginData.getCloneBuilder(); + cloneBuilder.setReportPeriod(reportPeriod.next()); + assertNotEquals(groupPropertyReportPluginData, cloneBuilder.build()); + + // includeGroupProperty + cloneBuilder = groupPropertyReportPluginData.getCloneBuilder(); + cloneBuilder.includeGroupProperty( + TestGroupPropertyId.GROUP_PROPERTY_3_3_DOUBLE_IMMUTABLE_NO_TRACK.getTestGroupTypeId(), + TestGroupPropertyId.GROUP_PROPERTY_3_3_DOUBLE_IMMUTABLE_NO_TRACK); + assertNotEquals(groupPropertyReportPluginData, cloneBuilder.build()); + + // includeGroupProperty + cloneBuilder = groupPropertyReportPluginData.getCloneBuilder(); + cloneBuilder.excludeGroupProperty( + TestGroupPropertyId.GROUP_PROPERTY_3_3_DOUBLE_IMMUTABLE_NO_TRACK.getTestGroupTypeId(), + TestGroupPropertyId.GROUP_PROPERTY_3_3_DOUBLE_IMMUTABLE_NO_TRACK); + assertNotEquals(groupPropertyReportPluginData, cloneBuilder.build()); + } + } + + @Test + @UnitTestMethod(target = GroupPropertyReportPluginData.class, name = "equals", args = { Object.class }) + public void testEquals() { + + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(7759639255438669162L); + for (int i = 0; i < 10; i++) { + // build a GroupPropertyReportPluginData from the same random + // inputs + GroupPropertyReportPluginData.Builder builder1 = GroupPropertyReportPluginData.builder(); + GroupPropertyReportPluginData.Builder builder2 = GroupPropertyReportPluginData.builder(); + + ReportLabel reportLabel = new SimpleReportLabel(randomGenerator.nextInt(100)); + builder1.setReportLabel(reportLabel); + builder2.setReportLabel(reportLabel); + + ReportPeriod reportPeriod = ReportPeriod.values()[randomGenerator.nextInt(ReportPeriod.values().length)]; + builder1.setReportPeriod(reportPeriod); + builder2.setReportPeriod(reportPeriod); + + for (int j = 0; j < 10; j++) { + TestGroupPropertyId testGroupPropertyId = TestGroupPropertyId + .getRandomTestGroupPropertyId(randomGenerator); + if (randomGenerator.nextBoolean()) { + builder1.includeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); + builder2.includeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); + } else { + builder1.excludeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); + builder2.excludeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); + } + } + + boolean defaultInclusion = randomGenerator.nextBoolean(); + builder1.setDefaultInclusion(defaultInclusion).build(); + builder2.setDefaultInclusion(defaultInclusion).build(); + + GroupPropertyReportPluginData groupPropertyReportPluginData1 = builder1.build(); + GroupPropertyReportPluginData groupPropertyReportPluginData2 = builder2.build(); + + assertEquals(groupPropertyReportPluginData1, groupPropertyReportPluginData2); + + // show that plugin datas with different inputs are not equal + + // change the default inclusion + groupPropertyReportPluginData2 = // + groupPropertyReportPluginData1.getCloneBuilder()// + .setDefaultInclusion(!defaultInclusion)// + .build(); + assertNotEquals(groupPropertyReportPluginData2, groupPropertyReportPluginData1); + + // change the report period + int ord = reportPeriod.ordinal() + 1; + ord = ord % ReportPeriod.values().length; + reportPeriod = ReportPeriod.values()[ord]; + groupPropertyReportPluginData2 = // + groupPropertyReportPluginData1.getCloneBuilder()// + .setReportPeriod(reportPeriod)// + .build(); + assertNotEquals(groupPropertyReportPluginData2, groupPropertyReportPluginData1); + + // change the report label + reportLabel = new SimpleReportLabel(1000); + groupPropertyReportPluginData2 = // + groupPropertyReportPluginData1.getCloneBuilder()// + .setReportLabel(reportLabel)// + .build(); + assertNotEquals(groupPropertyReportPluginData2, groupPropertyReportPluginData1); + + // change an included property id + for (GroupTypeId testGroupTypeId : groupPropertyReportPluginData1.getGroupTypeIds()) { + if (!groupPropertyReportPluginData1.getIncludedProperties(testGroupTypeId).isEmpty()) { + GroupPropertyId testGroupPropertyId = groupPropertyReportPluginData1 + .getIncludedProperties(testGroupTypeId).iterator().next(); + groupPropertyReportPluginData2 = // + groupPropertyReportPluginData1.getCloneBuilder()// + .excludeGroupProperty(testGroupTypeId, testGroupPropertyId)// + .build(); + assertNotEquals(groupPropertyReportPluginData2, groupPropertyReportPluginData1); + } + } + // change an excluded property id + for (GroupTypeId testGroupTypeId : groupPropertyReportPluginData1.getGroupTypeIds()) { + if (!groupPropertyReportPluginData1.getExcludedProperties(testGroupTypeId).isEmpty()) { + GroupPropertyId testGroupPropertyId = groupPropertyReportPluginData1 + .getExcludedProperties(testGroupTypeId).iterator().next(); + groupPropertyReportPluginData2 = // + groupPropertyReportPluginData1.getCloneBuilder()// + .includeGroupProperty(testGroupTypeId, testGroupPropertyId)// + .build(); + assertNotEquals(groupPropertyReportPluginData2, groupPropertyReportPluginData1); + } + } + } + + } + + @Test + @UnitTestMethod(target = GroupPropertyReportPluginData.class, name = "hashCode", args = {}) + public void testHashCode() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(9079768427072825406L); + + Set observedHashCodes = new LinkedHashSet<>(); + for (int i = 0; i < 50; i++) { + // build a GroupPropertyReportPluginData from the same random + // inputs + GroupPropertyReportPluginData.Builder builder1 = GroupPropertyReportPluginData.builder(); + GroupPropertyReportPluginData.Builder builder2 = GroupPropertyReportPluginData.builder(); + + ReportLabel reportLabel = new SimpleReportLabel(randomGenerator.nextInt(100)); + builder1.setReportLabel(reportLabel); + builder2.setReportLabel(reportLabel); + + ReportPeriod reportPeriod = ReportPeriod.values()[randomGenerator.nextInt(ReportPeriod.values().length)]; + builder1.setReportPeriod(reportPeriod); + builder2.setReportPeriod(reportPeriod); + + for (int j = 0; j < 10; j++) { + TestGroupPropertyId testGroupPropertyId = TestGroupPropertyId + .getRandomTestGroupPropertyId(randomGenerator); + if (randomGenerator.nextBoolean()) { + builder1.includeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); + builder2.includeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); + } else { + builder1.excludeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); + builder2.excludeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); + } + } + + boolean defaultInclusion = randomGenerator.nextBoolean(); + builder1.setDefaultInclusion(defaultInclusion).build(); + builder2.setDefaultInclusion(defaultInclusion).build(); + + GroupPropertyReportPluginData groupPropertyReportPluginData1 = builder1.build(); + GroupPropertyReportPluginData groupPropertyReportPluginData2 = builder2.build(); + + // show that the hash code is stable + int hashCode = groupPropertyReportPluginData1.hashCode(); + assertEquals(hashCode, groupPropertyReportPluginData1.hashCode()); + assertEquals(hashCode, groupPropertyReportPluginData1.hashCode()); + assertEquals(hashCode, groupPropertyReportPluginData1.hashCode()); + assertEquals(hashCode, groupPropertyReportPluginData1.hashCode()); + + // show that equal objects have equal hash codes + assertEquals(groupPropertyReportPluginData1.hashCode(), groupPropertyReportPluginData2.hashCode()); + + // collect the hashcode + observedHashCodes.add(groupPropertyReportPluginData1.hashCode()); + } + + /* + * The hash codes should be dispersed -- we only show that they are unique + * values -- this is dependent on the random seed + */ + assertEquals(50, observedHashCodes.size()); + + } + + @Test + @UnitTestMethod(target = GroupPropertyReportPluginData.class, name = "getGroupTypeIds", args = {}) + public void testGetGroupTypeIds() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(626906625322362256L); + + for (int i = 0; i < 50; i++) { + GroupPropertyReportPluginData.Builder builder1 = GroupPropertyReportPluginData.builder(); + + ReportLabel reportLabel = new SimpleReportLabel(randomGenerator.nextInt(100)); + builder1.setReportLabel(reportLabel); + + ReportPeriod reportPeriod = ReportPeriod.values()[randomGenerator.nextInt(ReportPeriod.values().length)]; + builder1.setReportPeriod(reportPeriod); + + Set expectedGroupTypeIds = new LinkedHashSet<>(); + + int propertyCount = randomGenerator.nextInt(3) + 1; + for (int j = 0; j < propertyCount; j++) { + TestGroupPropertyId testGroupPropertyId = TestGroupPropertyId + .getRandomTestGroupPropertyId(randomGenerator); + expectedGroupTypeIds.add(testGroupPropertyId.getTestGroupTypeId()); + if (randomGenerator.nextBoolean()) { + builder1.includeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); + } else { + builder1.excludeGroupProperty(testGroupPropertyId.getTestGroupTypeId(), testGroupPropertyId); + } + } + + boolean defaultInclusion = randomGenerator.nextBoolean(); + builder1.setDefaultInclusion(defaultInclusion).build(); + + GroupPropertyReportPluginData groupPropertyReportPluginData = builder1.build(); + + assertEquals(expectedGroupTypeIds, groupPropertyReportPluginData.getGroupTypeIds()); + } + + } + + @Test + @UnitTestMethod(target = GroupPropertyReportPluginData.class, name = "toString", args = {}) + public void testToString() { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(2394011517139293620L); + for (int i = 0; i < 10; i++) { + GroupPropertyReportPluginData.Builder builder = GroupPropertyReportPluginData.builder(); + + ReportLabel reportLabel = new SimpleReportLabel(randomGenerator.nextInt(100)); + builder.setReportLabel(reportLabel); + + ReportPeriod reportPeriod = ReportPeriod.values()[randomGenerator.nextInt(ReportPeriod.values().length)]; + builder.setReportPeriod(reportPeriod); + + Map> includedIds = new LinkedHashMap<>(); + Map> excludedIds = new LinkedHashMap<>(); + + for (TestGroupTypeId testGroupTypeId : TestGroupTypeId.getShuffledTestGroupTypeIds(randomGenerator)) { + for (TestGroupPropertyId testGroupPropertyId : TestGroupPropertyId + .getShuffledTestGroupPropertyIds(testGroupTypeId, randomGenerator)) { + if (randomGenerator.nextBoolean()) { + builder.includeGroupProperty(testGroupTypeId, testGroupPropertyId); + Set set = includedIds.get(testGroupTypeId); + if (set == null) { + set = new LinkedHashSet<>(); + includedIds.put(testGroupTypeId, set); + } + set.add(testGroupPropertyId); + set = excludedIds.get(testGroupTypeId); + if (set != null) { + set.remove(testGroupPropertyId); + } + } else { + builder.excludeGroupProperty(testGroupTypeId, testGroupPropertyId); + Set set = excludedIds.get(testGroupTypeId); + if (set == null) { + set = new LinkedHashSet<>(); + excludedIds.put(testGroupTypeId, set); + } + set.add(testGroupPropertyId); + set = includedIds.get(testGroupTypeId); + if (set != null) { + set.remove(testGroupPropertyId); + } + } + } + } + + boolean defaultInclusion = randomGenerator.nextBoolean(); + builder.setDefaultInclusion(defaultInclusion).build(); + + GroupPropertyReportPluginData groupPropertyReportPluginData = builder.build(); + + StringBuilder sb = new StringBuilder(); + sb.append("GroupPropertyReportPluginData [data="); + + StringBuilder superDataBuilder = new StringBuilder(); + superDataBuilder.append("Data [reportLabel="); + superDataBuilder.append(reportLabel); + superDataBuilder.append(", reportPeriod="); + superDataBuilder.append(reportPeriod); + + StringBuilder dataBuilder = new StringBuilder(); + dataBuilder.append(superDataBuilder.toString()); + dataBuilder.append(", includedProperties="); + dataBuilder.append(includedIds); + dataBuilder.append(", excludedProperties="); + dataBuilder.append(excludedIds); + dataBuilder.append(", defaultInclusionPolicy="); + dataBuilder.append(defaultInclusion); + dataBuilder.append("]"); + + sb.append(dataBuilder.toString()); + sb.append("]"); + + assertEquals(sb.toString(), groupPropertyReportPluginData.toString()); + } + } } diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/materials/datamanagers/AT_MaterialsPluginData.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/materials/datamanagers/AT_MaterialsPluginData.java index c9387d307..76ea86bde 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/materials/datamanagers/AT_MaterialsPluginData.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/materials/datamanagers/AT_MaterialsPluginData.java @@ -18,8 +18,6 @@ import org.apache.commons.math3.random.RandomGenerator; import org.junit.jupiter.api.Test; -import gov.hhs.aspr.ms.gcm.nucleus.PluginData; -import gov.hhs.aspr.ms.gcm.nucleus.PluginDataBuilder; import gov.hhs.aspr.ms.gcm.plugins.materials.datamangers.MaterialsPluginData; import gov.hhs.aspr.ms.gcm.plugins.materials.support.BatchId; import gov.hhs.aspr.ms.gcm.plugins.materials.support.BatchPropertyId; @@ -2423,19 +2421,111 @@ public void testGetCloneBuilder() { } MaterialsPluginData materialsPluginData = builder.build(); - // show the clone builder is not null - PluginDataBuilder cloneBuilder = materialsPluginData.getCloneBuilder(); - assertNotNull(cloneBuilder); - // show that the clone plugin data is not null - PluginData pluginData = cloneBuilder.build(); - assertNotNull(pluginData); - - // show that the clone plugin data has the correct type - assertTrue(pluginData instanceof MaterialsPluginData); - MaterialsPluginData clonePluginData = (MaterialsPluginData) pluginData; - - assertEquals(materialsPluginData, clonePluginData); + // show that the returned clone builder will build an identical instance if no + // mutations are made + MaterialsPluginData.Builder cloneBuilder = materialsPluginData.getCloneBuilder(); + assertNotNull(cloneBuilder); + assertEquals(materialsPluginData, cloneBuilder.build()); + + // show that the clone builder builds a distinct instance if any mutation is + // made + + // addBatch and addBatchToMaterialsProducerInventory + cloneBuilder = materialsPluginData.getCloneBuilder(); + cloneBuilder.addBatch(new BatchId(1000), TestMaterialId.MATERIAL_2, 123.3); + cloneBuilder.addBatchToMaterialsProducerInventory(new BatchId(1000), + TestMaterialsProducerId.MATERIALS_PRODUCER_1); + assertNotEquals(materialsPluginData, cloneBuilder.build()); + assertFalse(materialsPluginData.getBatchIds().contains(new BatchId(1000))); + + // addBatchToStage + cloneBuilder = materialsPluginData.getCloneBuilder(); + cloneBuilder.addBatch(new BatchId(1000), TestMaterialId.MATERIAL_2, 123.3); + StageId stageId = materialsPluginData.getStageIds().iterator().next(); + cloneBuilder.addBatchToStage(stageId, new BatchId(1000)); + assertNotEquals(materialsPluginData, cloneBuilder.build()); + assertFalse(materialsPluginData.getBatchIds().contains(new BatchId(1000))); + + // addMaterial + cloneBuilder = materialsPluginData.getCloneBuilder(); + cloneBuilder.addMaterial(TestMaterialId.getUnknownMaterialId()); + assertNotEquals(materialsPluginData, cloneBuilder.build()); + + // addMaterialsProducerId + cloneBuilder = materialsPluginData.getCloneBuilder(); + MaterialsProducerId materialsProducerId = TestMaterialsProducerId.getUnknownMaterialsProducerId(); + cloneBuilder.addMaterialsProducerId(materialsProducerId); + for (TestMaterialsProducerPropertyId testMaterialsProducerPropertyId : TestMaterialsProducerPropertyId + .values()) { + if (testMaterialsProducerPropertyId.getPropertyDefinition().getDefaultValue().isEmpty()) { + Object propertyValue = testMaterialsProducerPropertyId.getRandomPropertyValue(randomGenerator); + cloneBuilder.setMaterialsProducerPropertyValue(materialsProducerId, testMaterialsProducerPropertyId, + propertyValue); + } + } + assertNotEquals(materialsPluginData, cloneBuilder.build()); + assertFalse(materialsPluginData.getMaterialsProducerIds().contains(materialsProducerId)); + + // addStage and addStageToMaterialProducer + cloneBuilder = materialsPluginData.getCloneBuilder(); + cloneBuilder.addStage(new StageId(1000), false); + cloneBuilder.addStageToMaterialProducer(new StageId(1000), TestMaterialsProducerId.MATERIALS_PRODUCER_1); + assertNotEquals(materialsPluginData, cloneBuilder.build()); + assertFalse(materialsPluginData.getStageIds().contains(new StageId(1000))); + + // defineBatchProperty + cloneBuilder = materialsPluginData.getCloneBuilder(); + PropertyDefinition propertyDefinition = PropertyDefinition.builder().setType(Integer.class).setDefaultValue(12) + .setPropertyValueMutability(true).build(); + BatchPropertyId batchPropertyId = TestBatchPropertyId.getUnknownBatchPropertyId(); + cloneBuilder.defineBatchProperty(TestMaterialId.MATERIAL_1, batchPropertyId, propertyDefinition); + assertNotEquals(materialsPluginData, cloneBuilder.build()); + assertFalse(materialsPluginData.getBatchPropertyIds(TestMaterialId.MATERIAL_1).contains(batchPropertyId)); + + // defineMaterialsProducerProperty + cloneBuilder = materialsPluginData.getCloneBuilder(); + cloneBuilder.defineMaterialsProducerProperty( + TestMaterialsProducerPropertyId.getUnknownMaterialsProducerPropertyId(), propertyDefinition); + assertNotEquals(materialsPluginData, cloneBuilder.build()); + + // setBatchPropertyValue + cloneBuilder = materialsPluginData.getCloneBuilder(); + TestMaterialId batchMaterial = materialsPluginData.getBatchMaterial(new BatchId(0)); + TestBatchPropertyId selectedTestBatchPropertyId = null; + for (TestBatchPropertyId testBatchPropertyId : TestBatchPropertyId.values()) { + if (testBatchPropertyId.getTestMaterialId().equals(batchMaterial)) { + selectedTestBatchPropertyId = testBatchPropertyId; + break; + } + } + Object propertyValue = selectedTestBatchPropertyId.getRandomPropertyValue(randomGenerator); + cloneBuilder.setBatchPropertyValue(new BatchId(0), selectedTestBatchPropertyId, propertyValue); + assertNotEquals(materialsPluginData, cloneBuilder.build()); + + // setMaterialsProducerPropertyValue + cloneBuilder = materialsPluginData.getCloneBuilder(); + TestMaterialsProducerPropertyId testMaterialsProducerPropertyId = TestMaterialsProducerPropertyId.MATERIALS_PRODUCER_PROPERTY_2_INTEGER_MUTABLE_NO_TRACK; + propertyValue = testMaterialsProducerPropertyId.getRandomPropertyValue(randomGenerator); + cloneBuilder.setMaterialsProducerPropertyValue(TestMaterialsProducerId.MATERIALS_PRODUCER_1, + testMaterialsProducerPropertyId, propertyValue); + assertNotEquals(materialsPluginData, cloneBuilder.build()); + + // setMaterialsProducerPropertyValue + cloneBuilder = materialsPluginData.getCloneBuilder(); + cloneBuilder.setMaterialsProducerResourceLevel(TestMaterialsProducerId.MATERIALS_PRODUCER_1, + TestResourceId.RESOURCE_2, 56L); + assertNotEquals(materialsPluginData, cloneBuilder.build()); + + // setNextBatchRecordId + cloneBuilder = materialsPluginData.getCloneBuilder(); + cloneBuilder.setNextBatchRecordId(100000); + assertNotEquals(materialsPluginData, cloneBuilder.build()); + + // setNextStageRecordId + cloneBuilder = materialsPluginData.getCloneBuilder(); + cloneBuilder.setNextStageRecordId(100000); + assertNotEquals(materialsPluginData, cloneBuilder.build()); } @@ -2731,15 +2821,14 @@ public void testHashCode() { assertTrue(hashCodes.size() > 95); } - @Test @UnitTestMethod(target = MaterialsPluginData.class, name = "toString", args = {}) public void testToString() { MaterialsPluginData randomMaterialsPluginData = getRandomMaterialsPluginData(8064459530862960720L); - //The expected value was manually verified + // The expected value was manually verified String expectedValue = "MaterialsPluginData [data=Data [materialsProducerIds=[MATERIALS_PRODUCER_1], materialIds=[MATERIAL_1, MATERIAL_2], batchPropertyDefinitions={MATERIAL_1={BATCH_PROPERTY_1_1_BOOLEAN_IMMUTABLE_NO_TRACK=PropertyDefinition [type=class java.lang.Boolean, propertyValuesAreMutable=false, defaultValue=false], BATCH_PROPERTY_1_2_INTEGER_MUTABLE_NO_TRACK=PropertyDefinition [type=class java.lang.Integer, propertyValuesAreMutable=true, defaultValue=null], BATCH_PROPERTY_1_3_DOUBLE_MUTABLE_NO_TRACK=PropertyDefinition [type=class java.lang.Double, propertyValuesAreMutable=true, defaultValue=null]}, MATERIAL_2={BATCH_PROPERTY_2_1_BOOLEAN_MUTABLE_TRACK=PropertyDefinition [type=class java.lang.Boolean, propertyValuesAreMutable=true, defaultValue=false], BATCH_PROPERTY_2_2_INTEGER_IMMUTABLE_TRACK=PropertyDefinition [type=class java.lang.Integer, propertyValuesAreMutable=false, defaultValue=0], BATCH_PROPERTY_2_3_DOUBLE_MUTABLE_TRACK=PropertyDefinition [type=class java.lang.Double, propertyValuesAreMutable=true, defaultValue=0.0]}}, materialsProducerPropertyDefinitions={MATERIALS_PRODUCER_PROPERTY_1_BOOLEAN_MUTABLE_NO_TRACK=PropertyDefinition [type=class java.lang.Boolean, propertyValuesAreMutable=true, defaultValue=false], MATERIALS_PRODUCER_PROPERTY_2_INTEGER_MUTABLE_NO_TRACK=PropertyDefinition [type=class java.lang.Integer, propertyValuesAreMutable=true, defaultValue=null]}, materialsProducerPropertyValues={MATERIALS_PRODUCER_1={MATERIALS_PRODUCER_PROPERTY_1_BOOLEAN_MUTABLE_NO_TRACK=true, MATERIALS_PRODUCER_PROPERTY_2_INTEGER_MUTABLE_NO_TRACK=-1137930538}}, materialsProducerResourceLevels={MATERIALS_PRODUCER_1={RESOURCE_1=354}}, batchIds=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], batchMaterials={0=MATERIAL_2, 1=MATERIAL_1, 2=MATERIAL_1, 3=MATERIAL_1, 4=MATERIAL_2, 5=MATERIAL_2, 6=MATERIAL_1, 7=MATERIAL_1, 8=MATERIAL_2, 9=MATERIAL_1, 10=MATERIAL_2}, batchAmounts={0=0.37700109658565584, 1=0.6121304249912323, 2=0.2327292009900117, 3=0.5848445304496632, 4=0.3626526310416065, 5=0.8141764231338207, 6=0.7282094630729463, 7=0.2911578167148421, 8=0.3813260302130712, 9=0.038100504160549775, 10=0.294860719409465}, materialsProducerInventoryBatches={MATERIALS_PRODUCER_1=[0, 1, 3, 6, 7, 9, 10]}, batchPropertyValues={1={BATCH_PROPERTY_1_1_BOOLEAN_IMMUTABLE_NO_TRACK=true, BATCH_PROPERTY_1_2_INTEGER_MUTABLE_NO_TRACK=-2092162941, BATCH_PROPERTY_1_3_DOUBLE_MUTABLE_NO_TRACK=0.580252301720191}, 3={BATCH_PROPERTY_1_1_BOOLEAN_IMMUTABLE_NO_TRACK=true, BATCH_PROPERTY_1_2_INTEGER_MUTABLE_NO_TRACK=1273654431, BATCH_PROPERTY_1_3_DOUBLE_MUTABLE_NO_TRACK=0.8140217670183427}, 6={BATCH_PROPERTY_1_1_BOOLEAN_IMMUTABLE_NO_TRACK=true, BATCH_PROPERTY_1_2_INTEGER_MUTABLE_NO_TRACK=1631575277, BATCH_PROPERTY_1_3_DOUBLE_MUTABLE_NO_TRACK=0.8263248505964975}, 9={BATCH_PROPERTY_1_1_BOOLEAN_IMMUTABLE_NO_TRACK=false, BATCH_PROPERTY_1_2_INTEGER_MUTABLE_NO_TRACK=1716954844, BATCH_PROPERTY_1_3_DOUBLE_MUTABLE_NO_TRACK=0.9459982578081394}, 2={BATCH_PROPERTY_1_2_INTEGER_MUTABLE_NO_TRACK=-1465030731, BATCH_PROPERTY_1_3_DOUBLE_MUTABLE_NO_TRACK=0.828428083842786}, 7={BATCH_PROPERTY_1_2_INTEGER_MUTABLE_NO_TRACK=-894472152, BATCH_PROPERTY_1_3_DOUBLE_MUTABLE_NO_TRACK=0.7150821622079484}, 4={BATCH_PROPERTY_2_1_BOOLEAN_MUTABLE_TRACK=true, BATCH_PROPERTY_2_2_INTEGER_IMMUTABLE_TRACK=771315814}, 8={BATCH_PROPERTY_2_1_BOOLEAN_MUTABLE_TRACK=true, BATCH_PROPERTY_2_2_INTEGER_IMMUTABLE_TRACK=-2000257358, BATCH_PROPERTY_2_3_DOUBLE_MUTABLE_TRACK=0.5783721359816127}, 10={BATCH_PROPERTY_2_1_BOOLEAN_MUTABLE_TRACK=true}}, stageIds=[0, 1, 2, 3, 4, 5], stageOffers={0=false, 1=true, 2=true, 3=false, 4=true, 5=true}, materialsProducerStages={MATERIALS_PRODUCER_1=[0, 1, 2, 3, 4, 5]}, stageBatches={5=[2], 4=[4], 3=[5], 2=[8]}, nextBatchRecordId=20, nextStageRecordId=14]]"; - + String actualValue = randomMaterialsPluginData.toString(); assertEquals(expectedValue, actualValue); diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/materials/reports/AT_BatchStatusReportPluginData.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/materials/reports/AT_BatchStatusReportPluginData.java index 3ac935d6b..7639c928e 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/materials/reports/AT_BatchStatusReportPluginData.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/materials/reports/AT_BatchStatusReportPluginData.java @@ -12,6 +12,7 @@ import org.apache.commons.math3.random.RandomGenerator; import org.junit.jupiter.api.Test; +import gov.hhs.aspr.ms.gcm.plugins.materials.reports.BatchStatusReportPluginData.Builder; import gov.hhs.aspr.ms.gcm.plugins.reports.support.ReportError; import gov.hhs.aspr.ms.gcm.plugins.reports.support.ReportLabel; import gov.hhs.aspr.ms.gcm.plugins.reports.support.SimpleReportLabel; @@ -93,14 +94,18 @@ public void testGetCloneBuilder() { .setReportLabel(reportLabel); BatchStatusReportPluginData batchStatusReportPluginData = builder.build(); - - // create the clone builder and have it build - BatchStatusReportPluginData cloneBatchStatusReportPluginData = batchStatusReportPluginData.getCloneBuilder() - .build(); - - // the result should equal the original if the clone builder was - // initialized with the correct state - assertEquals(batchStatusReportPluginData, cloneBatchStatusReportPluginData); + + //show that the returned clone builder will build an identical instance if no mutations are made + Builder cloneBuilder = batchStatusReportPluginData.getCloneBuilder(); + assertNotNull(cloneBuilder); + assertEquals(batchStatusReportPluginData, cloneBuilder.build()); + + //show that the clone builder builds a distinct instance if any mutation is made + + //setReportLabel + cloneBuilder = batchStatusReportPluginData.getCloneBuilder(); + cloneBuilder.setReportLabel(new SimpleReportLabel("asdf")); + assertNotEquals(batchStatusReportPluginData,cloneBuilder.build()); } } diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/materials/reports/AT_MaterialsProducerPropertyReportPluginData.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/materials/reports/AT_MaterialsProducerPropertyReportPluginData.java index e544580ee..e80c562dc 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/materials/reports/AT_MaterialsProducerPropertyReportPluginData.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/materials/reports/AT_MaterialsProducerPropertyReportPluginData.java @@ -95,13 +95,20 @@ public void testGetCloneBuilder() { MaterialsProducerPropertyReportPluginData materialsProducerPropertyReportPluginData = builder.build(); - // create the clone builder and have it build - MaterialsProducerPropertyReportPluginData cloneMaterialsProducerPropertyReportPluginData = materialsProducerPropertyReportPluginData - .getCloneBuilder().build(); + // show that the returned clone builder will build an identical instance if no + // mutations are made + MaterialsProducerPropertyReportPluginData.Builder cloneBuilder = materialsProducerPropertyReportPluginData.getCloneBuilder(); + assertNotNull(cloneBuilder); + assertEquals(materialsProducerPropertyReportPluginData, cloneBuilder.build()); + + // show that the clone builder builds a distinct instance if any mutation is + // made + + // setReportLabel + cloneBuilder = materialsProducerPropertyReportPluginData.getCloneBuilder(); + cloneBuilder.setReportLabel(new SimpleReportLabel("asdf")); + assertNotEquals(materialsProducerPropertyReportPluginData, cloneBuilder.build()); - // the result should equal the original if the clone builder was - // initialized with the correct state - assertEquals(materialsProducerPropertyReportPluginData, cloneMaterialsProducerPropertyReportPluginData); } } diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/materials/reports/AT_MaterialsProducerResourceReportPluginData.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/materials/reports/AT_MaterialsProducerResourceReportPluginData.java index fc328006a..cbcd3aa3c 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/materials/reports/AT_MaterialsProducerResourceReportPluginData.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/materials/reports/AT_MaterialsProducerResourceReportPluginData.java @@ -93,12 +93,20 @@ public void testGetCloneBuilder() { MaterialsProducerResourceReportPluginData materialsProducerResourceReportPluginData = builder.build(); - // create the clone builder and have it build - MaterialsProducerResourceReportPluginData cloneMaterialsProducerResourceReportPluginData = materialsProducerResourceReportPluginData.getCloneBuilder().build(); + // show that the returned clone builder will build an identical instance if no + // mutations are made + MaterialsProducerResourceReportPluginData.Builder cloneBuilder = materialsProducerResourceReportPluginData.getCloneBuilder(); + assertNotNull(cloneBuilder); + assertEquals(materialsProducerResourceReportPluginData, cloneBuilder.build()); + + // show that the clone builder builds a distinct instance if any mutation is + // made + + // setReportLabel + cloneBuilder = materialsProducerResourceReportPluginData.getCloneBuilder(); + cloneBuilder.setReportLabel(new SimpleReportLabel("asdf")); + assertNotEquals(materialsProducerResourceReportPluginData, cloneBuilder.build()); - // the result should equal the original if the clone builder was - // initialized with the correct state - assertEquals(materialsProducerResourceReportPluginData, cloneMaterialsProducerResourceReportPluginData); } } diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/materials/reports/AT_StageReportPluginData.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/materials/reports/AT_StageReportPluginData.java index 0a05422e8..fb6f5dfa9 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/materials/reports/AT_StageReportPluginData.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/materials/reports/AT_StageReportPluginData.java @@ -93,13 +93,21 @@ public void testGetCloneBuilder() { StageReportPluginData stageReportPluginData = builder.build(); - // create the clone builder and have it build - StageReportPluginData cloneStageReportPluginData = stageReportPluginData.getCloneBuilder().build(); + // show that the returned clone builder will build an identical instance if no + // mutations are made + StageReportPluginData.Builder cloneBuilder = stageReportPluginData.getCloneBuilder(); + assertNotNull(cloneBuilder); + assertEquals(stageReportPluginData, cloneBuilder.build()); - // the result should equal the original if the clone builder was - // initialized with the correct state - assertEquals(stageReportPluginData, cloneStageReportPluginData); + // show that the clone builder builds a distinct instance if any mutation is + // made + // setReportLabel + cloneBuilder = stageReportPluginData.getCloneBuilder(); + cloneBuilder.setReportLabel(new SimpleReportLabel("asdf")); + assertNotEquals(stageReportPluginData, cloneBuilder.build()); + + } } diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/partitions/datamanagers/AT_PartitionsPluginData.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/partitions/datamanagers/AT_PartitionsPluginData.java index 3070b6536..04c7c48d7 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/partitions/datamanagers/AT_PartitionsPluginData.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/partitions/datamanagers/AT_PartitionsPluginData.java @@ -25,10 +25,28 @@ public void testGetCloneBuilder() { PartitionsPluginData p1 = PartitionsPluginData.builder().setRunContinuitySupport(true).build(); PluginData p2 = p1.getCloneBuilder().build(); assertEquals(p1, p2); + + p1 = PartitionsPluginData.builder().setRunContinuitySupport(false).build(); p2 = p1.getCloneBuilder().build(); assertEquals(p1, p2); + + + // show that the returned clone builder will build an identical instance if no + // mutations are made + PartitionsPluginData.Builder cloneBuilder = p1.getCloneBuilder(); + assertNotNull(cloneBuilder); + assertEquals(p1, cloneBuilder.build()); + + // show that the clone builder builds a distinct instance if any mutation is + // made + + // defineGlobalProperty + cloneBuilder = p1.getCloneBuilder(); + cloneBuilder.setRunContinuitySupport(true); + assertNotEquals(p1, cloneBuilder.build()); + } @Test diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/partitions/testsupport/attributes/AT_AttributesPluginData.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/partitions/testsupport/attributes/AT_AttributesPluginData.java index 385ce0881..e7fb9ca86 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/partitions/testsupport/attributes/AT_AttributesPluginData.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/partitions/testsupport/attributes/AT_AttributesPluginData.java @@ -2,6 +2,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -21,8 +22,6 @@ import org.apache.commons.math3.random.RandomGenerator; import org.junit.jupiter.api.Test; -import gov.hhs.aspr.ms.gcm.nucleus.PluginData; -import gov.hhs.aspr.ms.gcm.nucleus.PluginDataBuilder; import gov.hhs.aspr.ms.gcm.plugins.partitions.testsupport.attributes.support.AttributeDefinition; import gov.hhs.aspr.ms.gcm.plugins.partitions.testsupport.attributes.support.AttributeError; import gov.hhs.aspr.ms.gcm.plugins.partitions.testsupport.attributes.support.AttributeId; @@ -130,21 +129,25 @@ public void testGetCloneBuilder() { for (TestAttributeId testAttributeId : TestAttributeId.values()) { builder.defineAttribute(testAttributeId, testAttributeId.getAttributeDefinition()); } - AttributesPluginData attributesPluginData = builder.build(); - PluginDataBuilder cloneBuilder = attributesPluginData.getCloneBuilder(); - assertNotNull(cloneBuilder); - - PluginData pluginData = cloneBuilder.build(); - - assertTrue(pluginData instanceof AttributesPluginData); - - AttributesPluginData clonePluginData = (AttributesPluginData) pluginData; - assertEquals(attributesPluginData.getAttributeIds(), clonePluginData.getAttributeIds()); - for (TestAttributeId testAttributeId : TestAttributeId.values()) { - assertEquals(attributesPluginData.getAttributeDefinition(testAttributeId), - clonePluginData.getAttributeDefinition(testAttributeId)); - } + + //show that the returned clone builder will build an identical instance if no mutations are made + AttributesPluginData.Builder cloneBuilder = attributesPluginData.getCloneBuilder(); + assertNotNull(cloneBuilder); + assertEquals(attributesPluginData,cloneBuilder.build()); + + + //show that the clone builder builds a distinct instance if any mutation is made + + //defineAttribute + cloneBuilder = attributesPluginData.getCloneBuilder(); + cloneBuilder.defineAttribute(TestAttributeId.getUnknownAttributeId(), TestAttributeId.DOUBLE_0.getAttributeDefinition()); + assertNotEquals(attributesPluginData,cloneBuilder.build()); + + //setPersonAttributeValue + cloneBuilder = attributesPluginData.getCloneBuilder(); + cloneBuilder.setPersonAttributeValue(new PersonId(123),TestAttributeId.BOOLEAN_0, false); + assertNotEquals(attributesPluginData,cloneBuilder.build()); } @Test diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/people/datamanagers/AT_PeoplePluginData.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/people/datamanagers/AT_PeoplePluginData.java index af57872c3..d5d1b36dd 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/people/datamanagers/AT_PeoplePluginData.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/people/datamanagers/AT_PeoplePluginData.java @@ -2,6 +2,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -14,7 +15,6 @@ import org.apache.commons.math3.random.RandomGenerator; import org.junit.jupiter.api.Test; -import gov.hhs.aspr.ms.gcm.nucleus.PluginData; import gov.hhs.aspr.ms.gcm.plugins.people.support.PersonError; import gov.hhs.aspr.ms.gcm.plugins.people.support.PersonId; import gov.hhs.aspr.ms.gcm.plugins.people.support.PersonRange; @@ -210,13 +210,41 @@ public void testSetPersonCount() { @UnitTestMethod(target = PeoplePluginData.class, name = "getCloneBuilder", args = {}) public void testGetCloneBuilder() { - PeoplePluginData pluginData = PeoplePluginData.builder()// - .addPersonRange(new PersonRange(3, 9)).addPersonRange(new PersonRange(8, 12)) - .addPersonRange(new PersonRange(15, 19)).build(); + PeoplePluginData peoplePluginData = PeoplePluginData.builder()// + .addPersonRange(new PersonRange(3, 9))// + .addPersonRange(new PersonRange(8, 12))// + .addPersonRange(new PersonRange(15, 19))// + .setPersonCount(50).build(); + + // show that the returned clone builder will build an identical instance if no + // mutations are made + PeoplePluginData.Builder cloneBuilder = peoplePluginData.getCloneBuilder(); + assertNotNull(cloneBuilder); + assertEquals(peoplePluginData, cloneBuilder.build()); + + // show that the clone builder builds a distinct instance if any mutation is + // made + + // addPersonRange + cloneBuilder = peoplePluginData.getCloneBuilder(); + cloneBuilder.addPersonRange(new PersonRange(22, 25)); + assertNotEquals(peoplePluginData, cloneBuilder.build()); + + // setAssignmentTime + cloneBuilder = peoplePluginData.getCloneBuilder(); + cloneBuilder.setAssignmentTime(123.4); + assertNotEquals(peoplePluginData, cloneBuilder.build()); + + // setPersonCount + cloneBuilder = peoplePluginData.getCloneBuilder(); + cloneBuilder.setPersonCount(123); + assertNotEquals(peoplePluginData, cloneBuilder.build()); + + // resetPersonCount + cloneBuilder = peoplePluginData.getCloneBuilder(); + cloneBuilder.resetPersonCount(); + assertNotEquals(peoplePluginData, cloneBuilder.build()); - PluginData pluginData2 = pluginData.getCloneBuilder().build(); - - assertEquals(pluginData, pluginData2); } @Test @@ -295,22 +323,22 @@ private PeoplePluginData getRandomPeoplePluginData(long seed) { int low = 1; int high = 1; int rangeCount = randomGenerator.nextInt(3) + 1; - + for (int i = 0; i < rangeCount; i++) { low += randomGenerator.nextInt(10); - high = low + randomGenerator.nextInt(10) + 1; - builder.addPersonRange(new PersonRange(low, high)); - low = high+1; - + high = low + randomGenerator.nextInt(10) + 1; + builder.addPersonRange(new PersonRange(low, high)); + low = high + 1; + } builder.setAssignmentTime(randomGenerator.nextDouble() * 100 - 50); - int personCount = high+randomGenerator.nextInt(5)+1; + int personCount = high + randomGenerator.nextInt(5) + 1; builder.setPersonCount(personCount); return builder.build(); } - + @Test @UnitTestMethod(target = PeoplePluginData.class, name = "equals", args = { Object.class }) public void testEquals() { @@ -347,50 +375,46 @@ public void testEquals() { } assertEquals(100, set.size()); } - + @Test @UnitTestMethod(target = PeoplePluginData.class, name = "hashCode", args = {}) public void testHashCode() { RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(6496930019491275913L); - - //equal objects have equal hash codes + + // equal objects have equal hash codes for (int i = 0; i < 30; i++) { long seed = randomGenerator.nextLong(); PeoplePluginData pluginData1 = getRandomPeoplePluginData(seed); PeoplePluginData pluginData2 = getRandomPeoplePluginData(seed); - - assertEquals(pluginData1 ,pluginData2); - assertEquals(pluginData1.hashCode() ,pluginData2.hashCode()); - + + assertEquals(pluginData1, pluginData2); + assertEquals(pluginData1.hashCode(), pluginData2.hashCode()); + } - - //hash codes are reasonably distributed + + // hash codes are reasonably distributed Set hashCodes = new LinkedHashSet<>(); for (int i = 0; i < 100; i++) { PeoplePluginData pluginData = getRandomPeoplePluginData(randomGenerator.nextLong()); hashCodes.add(pluginData.hashCode()); } - assertTrue(hashCodes.size()>95); + assertTrue(hashCodes.size() > 95); } - + @Test @UnitTestMethod(target = PeoplePluginData.class, name = "toString", args = {}) public void testToString() { PeoplePluginData pluginData = getRandomPeoplePluginData(8839731936101813165L); - + String actualValue = pluginData.toString(); - - //Expected value validated by inspection - String expectedValue = "PeoplePluginData [data=Data [" - + "personCount=34, " - + "personRanges=[" - + "PersonRange [lowPersonId=4, highPersonId=13], " - + "PersonRange [lowPersonId=19, highPersonId=20], " - + "PersonRange [lowPersonId=27, highPersonId=30]], " - + "assignmentTime=49.458417619948875, " + + // Expected value validated by inspection + String expectedValue = "PeoplePluginData [data=Data [" + "personCount=34, " + "personRanges=[" + + "PersonRange [lowPersonId=4, highPersonId=13], " + "PersonRange [lowPersonId=19, highPersonId=20], " + + "PersonRange [lowPersonId=27, highPersonId=30]], " + "assignmentTime=49.458417619948875, " + "locked=true]]"; assertEquals(expectedValue, actualValue); - + } } diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/personproperties/datamanagers/AT_PersonPropertyPluginData.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/personproperties/datamanagers/AT_PersonPropertyPluginData.java index 69eae30f1..e2db2bcb6 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/personproperties/datamanagers/AT_PersonPropertyPluginData.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/personproperties/datamanagers/AT_PersonPropertyPluginData.java @@ -17,8 +17,6 @@ import org.apache.commons.math3.random.RandomGenerator; import org.junit.jupiter.api.Test; -import gov.hhs.aspr.ms.gcm.nucleus.PluginData; -import gov.hhs.aspr.ms.gcm.nucleus.PluginDataBuilder; import gov.hhs.aspr.ms.gcm.plugins.people.support.PersonError; import gov.hhs.aspr.ms.gcm.plugins.people.support.PersonId; import gov.hhs.aspr.ms.gcm.plugins.personproperties.support.PersonPropertyError; @@ -434,15 +432,38 @@ public void testGetCloneBuilder() { } } } + + //forcing a particular value for later use + pluginBuilder.setPersonPropertyValue(new PersonId(0), TestPersonPropertyId.PERSON_PROPERTY_1_BOOLEAN_MUTABLE_NO_TRACK,true); - PersonPropertiesPluginData expectedPluginData = pluginBuilder.build(); + PersonPropertiesPluginData personPropertiesPluginData = pluginBuilder.build(); - PluginDataBuilder cloneBuilder = expectedPluginData.getCloneBuilder(); + // show that the returned clone builder will build an identical instance if no + // mutations are made + PersonPropertiesPluginData.Builder cloneBuilder = personPropertiesPluginData.getCloneBuilder(); assertNotNull(cloneBuilder); - PluginData actualPluginData = cloneBuilder.build(); + assertEquals(personPropertiesPluginData, cloneBuilder.build()); + + // show that the clone builder builds a distinct instance if any mutation is + // made + + // definePersonProperty + cloneBuilder = personPropertiesPluginData.getCloneBuilder(); + TestPersonPropertyId testPersonPropertyId = TestPersonPropertyId.PERSON_PROPERTY_1_BOOLEAN_MUTABLE_NO_TRACK; + cloneBuilder.definePersonProperty(testPersonPropertyId, testPersonPropertyId.getPropertyDefinition(), 2.7, + false); + assertNotEquals(personPropertiesPluginData, cloneBuilder.build()); + + // setPersonPropertyTime + cloneBuilder = personPropertiesPluginData.getCloneBuilder(); + cloneBuilder.setPersonPropertyTime(new PersonId(0), testPersonPropertyId, 2.5); + assertNotEquals(personPropertiesPluginData, cloneBuilder.build()); + + // setPersonPropertyValue -- we know that the current value is true + cloneBuilder = personPropertiesPluginData.getCloneBuilder(); + cloneBuilder.setPersonPropertyValue(new PersonId(0), testPersonPropertyId, false); + assertNotEquals(personPropertiesPluginData, cloneBuilder.build()); - // show that the two plugin datas are equal - assertEquals(expectedPluginData, actualPluginData); } @@ -1210,10 +1231,8 @@ public void testToString() { PersonPropertiesPluginData personPropertiesPluginData = builder.build(); String actualValue = personPropertiesPluginData.toString(); - - - - String expectedValue ="PersonPropertiesPluginData [data=Data [personPropertyDefinitions=" + + String expectedValue = "PersonPropertiesPluginData [data=Data [personPropertyDefinitions=" + "{PERSON_PROPERTY_1_BOOLEAN_MUTABLE_NO_TRACK=PropertyDefinition [type=class java.lang.Boolean," + " propertyValuesAreMutable=true, defaultValue=false], PERSON_PROPERTY_2_INTEGER_MUTABLE_NO_TRACK=PropertyDefinition" + " [type=class java.lang.Integer, propertyValuesAreMutable=true, defaultValue=0], " @@ -1278,8 +1297,7 @@ public void testToString() { + "null, null, null, null, null, 79.52059465811621, null, 72.35392133239016, null, 75.13846509635269, " + "null, 75.4774777727181, null, 77.77386975625731, null, 76.46205411237824, null, 70.54554388234095, " + "null, 72.92650170630496, null, 78.75239401434217, null, 77.34177298897009]}]]"; - - + assertEquals(expectedValue, actualValue); } diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/personproperties/reports/AT_PersonPropertyInteractionReportPluginData.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/personproperties/reports/AT_PersonPropertyInteractionReportPluginData.java index 9f9eac346..31ed05a8d 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/personproperties/reports/AT_PersonPropertyInteractionReportPluginData.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/personproperties/reports/AT_PersonPropertyInteractionReportPluginData.java @@ -2,6 +2,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -150,16 +151,39 @@ public void testGetCloneBuilder() { builder.addPersonPropertyId(testPersonPropertyId); } } - + builder.addPersonPropertyId(TestPersonPropertyId.PERSON_PROPERTY_1_BOOLEAN_MUTABLE_NO_TRACK); + PersonPropertyInteractionReportPluginData personPropertyInteractionReportPluginData = builder.build(); - // create the clone builder and have it build - PersonPropertyInteractionReportPluginData clonePersonPropertyInteractionReportPluginData = personPropertyInteractionReportPluginData - .getCloneBuilder().build(); - - // the result should equal the original if the clone builder was - // initialized with the correct state - assertEquals(personPropertyInteractionReportPluginData, clonePersonPropertyInteractionReportPluginData); + // show that the returned clone builder will build an identical instance if no + // mutations are made + PersonPropertyInteractionReportPluginData.Builder cloneBuilder = personPropertyInteractionReportPluginData.getCloneBuilder(); + assertNotNull(cloneBuilder); + assertEquals(personPropertyInteractionReportPluginData, cloneBuilder.build()); + + // show that the clone builder builds a distinct instance if any mutation is + // made + + // addPersonPropertyId + cloneBuilder = personPropertyInteractionReportPluginData.getCloneBuilder(); + cloneBuilder.addPersonPropertyId(TestPersonPropertyId.getUnknownPersonPropertyId()); + assertNotEquals(personPropertyInteractionReportPluginData, cloneBuilder.build()); + + // removePersonPropertyId + cloneBuilder = personPropertyInteractionReportPluginData.getCloneBuilder(); + cloneBuilder.removePersonPropertyId(TestPersonPropertyId.PERSON_PROPERTY_1_BOOLEAN_MUTABLE_NO_TRACK); + assertNotEquals(personPropertyInteractionReportPluginData, cloneBuilder.build()); + + // setReportLabel + cloneBuilder = personPropertyInteractionReportPluginData.getCloneBuilder(); + cloneBuilder.setReportLabel(new SimpleReportLabel("asdf")); + assertNotEquals(personPropertyInteractionReportPluginData, cloneBuilder.build()); + + // setReportPeriod + cloneBuilder = personPropertyInteractionReportPluginData.getCloneBuilder(); + ReportPeriod nextReportPeriod = personPropertyInteractionReportPluginData.getReportPeriod().next(); + cloneBuilder.setReportPeriod(nextReportPeriod); + assertNotEquals(personPropertyInteractionReportPluginData, cloneBuilder.build()); } } diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/personproperties/reports/AT_PersonPropertyReportPluginData.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/personproperties/reports/AT_PersonPropertyReportPluginData.java index 7b9926570..20c327560 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/personproperties/reports/AT_PersonPropertyReportPluginData.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/personproperties/reports/AT_PersonPropertyReportPluginData.java @@ -444,19 +444,47 @@ public void testGetCloneBuilder() { builder.excludePersonProperty(testPersonPropertyId); } } - + //forcing some values for later use + builder.includePersonProperty(TestPersonPropertyId.PERSON_PROPERTY_8_INTEGER_IMMUTABLE_NO_TRACK); + builder.excludePersonProperty(TestPersonPropertyId.PERSON_PROPERTY_9_DOUBLE_MUTABLE_NO_TRACK); + builder.setDefaultInclusion(randomGenerator.nextBoolean()).build(); PersonPropertyReportPluginData personPropertyReportPluginData = builder.build(); - // create the clone builder and have it build - PersonPropertyReportPluginData clonePersonPropertyReportPluginData = personPropertyReportPluginData - .getCloneBuilder().build(); - - // the result should equal the original if the clone builder was - // initialized with the correct state - assertEquals(personPropertyReportPluginData, clonePersonPropertyReportPluginData); - + // show that the returned clone builder will build an identical instance if no + // mutations are made + PersonPropertyReportPluginData.Builder cloneBuilder = personPropertyReportPluginData.getCloneBuilder(); + assertNotNull(cloneBuilder); + assertEquals(personPropertyReportPluginData, cloneBuilder.build()); + + // show that the clone builder builds a distinct instance if any mutation is + // made + + // excludePersonProperty + cloneBuilder = personPropertyReportPluginData.getCloneBuilder(); + cloneBuilder.excludePersonProperty(TestPersonPropertyId.PERSON_PROPERTY_8_INTEGER_IMMUTABLE_NO_TRACK); + assertNotEquals(personPropertyReportPluginData, cloneBuilder.build()); + + // includePersonProperty + cloneBuilder = personPropertyReportPluginData.getCloneBuilder(); + cloneBuilder.includePersonProperty(TestPersonPropertyId.PERSON_PROPERTY_9_DOUBLE_MUTABLE_NO_TRACK); + assertNotEquals(personPropertyReportPluginData, cloneBuilder.build()); + + // setDefaultInclusion + cloneBuilder = personPropertyReportPluginData.getCloneBuilder(); + cloneBuilder.setDefaultInclusion(!personPropertyReportPluginData.getDefaultInclusionPolicy()); + assertNotEquals(personPropertyReportPluginData, cloneBuilder.build()); + + // setReportLabel + cloneBuilder = personPropertyReportPluginData.getCloneBuilder(); + cloneBuilder.setReportLabel(new SimpleReportLabel("asdf")); + assertNotEquals(personPropertyReportPluginData, cloneBuilder.build()); + + // setReportPeriod + cloneBuilder = personPropertyReportPluginData.getCloneBuilder(); + cloneBuilder.setReportPeriod(personPropertyReportPluginData.getReportPeriod().next()); + assertNotEquals(personPropertyReportPluginData, cloneBuilder.build()); } } diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/regions/datamanagers/AT_RegionsPluginData.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/regions/datamanagers/AT_RegionsPluginData.java index 0d16f2368..47ca9c12c 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/regions/datamanagers/AT_RegionsPluginData.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/regions/datamanagers/AT_RegionsPluginData.java @@ -2,6 +2,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -21,7 +22,6 @@ import org.apache.commons.math3.util.FastMath; import org.junit.jupiter.api.Test; -import gov.hhs.aspr.ms.gcm.nucleus.PluginData; import gov.hhs.aspr.ms.gcm.plugins.people.support.PersonError; import gov.hhs.aspr.ms.gcm.plugins.people.support.PersonId; import gov.hhs.aspr.ms.gcm.plugins.properties.support.PropertyDefinition; @@ -654,88 +654,180 @@ public void testSetPersonRegionArrivalTracking() { @Test @UnitTestMethod(target = RegionsPluginData.class, name = "getCloneBuilder", args = {}) public void testGetCloneBuilder() { - RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(6712645837048772782L); + /* + * The tracking of person arrival times and the existence of non-defalut region + * property definition is sensitive. In order to fully test the cloneBuilder + * mechanisms we must create four distinct tests that allow each mutation on the + * clone to be tested properly. + */ + + testGetCloneBuilder_subTest1(); + testGetCloneBuilder_subTest2(); + testGetCloneBuilder_subTest3(); + testGetCloneBuilder_subTest4(); + } + + private RegionsPluginData getRegionsPluginData(boolean containsPeople, boolean useArrivalTracking, + boolean useEmptyDefaultProperties, long seed) { + RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(seed); RegionsPluginData.Builder regionPluginDataBuilder = RegionsPluginData.builder(); - regionPluginDataBuilder.setPersonRegionArrivalTracking(true); + regionPluginDataBuilder.setPersonRegionArrivalTracking(useArrivalTracking); for (TestRegionId testRegionId : TestRegionId.values()) { regionPluginDataBuilder.addRegion(testRegionId); } + for (TestRegionPropertyId testRegionPropertyId : TestRegionPropertyId.values()) { - regionPluginDataBuilder.defineRegionProperty(testRegionPropertyId, - testRegionPropertyId.getPropertyDefinition()); + boolean defaultPresent = testRegionPropertyId.getPropertyDefinition().getDefaultValue().isPresent(); + + if (defaultPresent || useEmptyDefaultProperties) { + // this is a valid property + regionPluginDataBuilder.defineRegionProperty(testRegionPropertyId, + testRegionPropertyId.getPropertyDefinition()); + } } for (TestRegionId testRegionId : TestRegionId.values()) { for (TestRegionPropertyId testRegionPropertyId : TestRegionPropertyId.values()) { - if (testRegionPropertyId.getPropertyDefinition().getDefaultValue().isEmpty() - || randomGenerator.nextBoolean()) { - Object randomPropertyValue = testRegionPropertyId.getRandomPropertyValue(randomGenerator); - regionPluginDataBuilder.setRegionPropertyValue(testRegionId, testRegionPropertyId, - randomPropertyValue); + boolean defaultPresent = testRegionPropertyId.getPropertyDefinition().getDefaultValue().isPresent(); + if (defaultPresent || useEmptyDefaultProperties) { + // this is a valid property + + if (!defaultPresent || randomGenerator.nextBoolean()) { + Object randomPropertyValue = testRegionPropertyId.getRandomPropertyValue(randomGenerator); + regionPluginDataBuilder.setRegionPropertyValue(testRegionId, testRegionPropertyId, + randomPropertyValue); + } + } } } - int personCount = 100; + + int personCount = 0; + if (containsPeople) { + personCount = 100; + } for (int i = 0; i < personCount; i++) { PersonId personId = new PersonId(i * 2 + 5); TestRegionId randomRegionId = TestRegionId.getRandomRegionId(randomGenerator); - regionPluginDataBuilder.addPerson(personId, randomRegionId, 0.0); + if (useArrivalTracking) { + regionPluginDataBuilder.addPerson(personId, randomRegionId, 0.0); + } else { + regionPluginDataBuilder.addPerson(personId, randomRegionId); + } } - RegionsPluginData regionsPluginData = regionPluginDataBuilder.build(); + return regionPluginDataBuilder.build(); + } - PluginData pluginData = regionsPluginData.getCloneBuilder().build(); + private void testGetCloneBuilder_subTest1() { + + boolean containsPeople = true; + boolean useArrivalTracking = true; + boolean useEmptyDefaultProperties = true; + long seed = 6712645837048772782L; + + RegionsPluginData regionsPluginData = getRegionsPluginData(containsPeople, useArrivalTracking, + useEmptyDefaultProperties, seed); + + // show that the returned clone builder will build an identical instance if no + // mutations are made + RegionsPluginData.Builder cloneBuilder = regionsPluginData.getCloneBuilder(); + assertNotNull(cloneBuilder); + assertEquals(regionsPluginData, cloneBuilder.build()); + + // show that the clone builder builds a distinct instance if any mutation is + // made + + // addPerson(PersonId, RegionId,Double) + cloneBuilder = regionsPluginData.getCloneBuilder(); + cloneBuilder.addPerson(new PersonId(1000), TestRegionId.REGION_1, 123.7); + assertNotEquals(regionsPluginData, cloneBuilder.build()); + + // defineRegionProperty + cloneBuilder = regionsPluginData.getCloneBuilder(); + PropertyDefinition propertyDefinition = PropertyDefinition.builder()// + .setDefaultValue(4)// + .setType(Integer.class)// + .setPropertyValueMutability(true)// + .build(); + cloneBuilder.defineRegionProperty(TestRegionPropertyId.getUnknownRegionPropertyId(), propertyDefinition); + assertNotEquals(regionsPluginData, cloneBuilder.build()); - // show that the clone plugin data has the correct type - assertTrue(pluginData instanceof RegionsPluginData); - RegionsPluginData cloneRegionPluginData = (RegionsPluginData) pluginData; + // setRegionPropertyValue + cloneBuilder = regionsPluginData.getCloneBuilder(); + cloneBuilder.setRegionPropertyValue(TestRegionId.REGION_1, + TestRegionPropertyId.REGION_PROPERTY_3_DOUBLE_MUTABLE, 34.6); + assertNotEquals(regionsPluginData, cloneBuilder.build()); - // show that the two plugin datas have the same arrival tracking policy - assertEquals(regionsPluginData.getPersonRegionArrivalTrackingPolicy(), - cloneRegionPluginData.getPersonRegionArrivalTrackingPolicy()); + } - // show that the two plugin datas have the same region ids - assertEquals(regionsPluginData.getRegionIds(), cloneRegionPluginData.getRegionIds()); + private void testGetCloneBuilder_subTest2() { + boolean containsPeople = true; + boolean useArrivalTracking = false; + boolean useEmptyDefaultProperties = true; + long seed = 927079288013081717L; + RegionsPluginData regionsPluginData = getRegionsPluginData(containsPeople, useArrivalTracking, + useEmptyDefaultProperties, seed); - // show that the two plugin datas have the same region property ids - assertEquals(regionsPluginData.getRegionPropertyIds(), cloneRegionPluginData.getRegionPropertyIds()); + // show that the returned clone builder will build an identical instance if no + // mutations are made + RegionsPluginData.Builder cloneBuilder = regionsPluginData.getCloneBuilder(); + assertNotNull(cloneBuilder); + assertEquals(regionsPluginData, cloneBuilder.build()); - // show that the two plugin datas have the same region property - // definitions - for (RegionPropertyId regionPropertyId : regionsPluginData.getRegionPropertyIds()) { - PropertyDefinition expectedPropertyDefinition = regionsPluginData - .getRegionPropertyDefinition(regionPropertyId); - PropertyDefinition actualPropertyDefinition = cloneRegionPluginData - .getRegionPropertyDefinition(regionPropertyId); - assertEquals(expectedPropertyDefinition, actualPropertyDefinition); - } + // show that the clone builder builds a distinct instance if any mutation is + // made - // show that the two plugin datas have the same region property values - for (RegionId regionId : regionsPluginData.getRegionIds()) { - Map expectedRegionPropertyValues = regionsPluginData - .getRegionPropertyValues(regionId); - Map actualRegionPropertyValues = cloneRegionPluginData - .getRegionPropertyValues(regionId); - assertEquals(expectedRegionPropertyValues, actualRegionPropertyValues); - } + // addPerson(PersonId, RegionId) + cloneBuilder = regionsPluginData.getCloneBuilder(); + cloneBuilder.addPerson(new PersonId(1000), TestRegionId.REGION_1); + assertNotEquals(regionsPluginData, cloneBuilder.build()); - // show that the two plugin datas have the same people and region - // assignments + } - int pluginPersonCount = regionsPluginData.getPersonCount(); - int clonePluginPersonCount = cloneRegionPluginData.getPersonCount(); - assertEquals(pluginPersonCount, clonePluginPersonCount); + private void testGetCloneBuilder_subTest3() { + boolean containsPeople = true; + boolean useArrivalTracking = true; + boolean useEmptyDefaultProperties = false; + long seed = 514836872882449614L; + RegionsPluginData regionsPluginData = getRegionsPluginData(containsPeople, useArrivalTracking, + useEmptyDefaultProperties, seed); + + // show that the returned clone builder will build an identical instance if no + // mutations are made + RegionsPluginData.Builder cloneBuilder = regionsPluginData.getCloneBuilder(); + assertNotNull(cloneBuilder); + assertEquals(regionsPluginData, cloneBuilder.build()); + + // show that the clone builder builds a distinct instance if any mutation is + // made + + // addRegion + cloneBuilder = regionsPluginData.getCloneBuilder(); + cloneBuilder.addRegion(TestRegionId.getUnknownRegionId()); + assertNotEquals(regionsPluginData, cloneBuilder.build()); + } - for (int i = 0; i < pluginPersonCount; i++) { - PersonId personId = new PersonId(i); - boolean isPresentInPluginData = regionsPluginData.getPersonRegion(personId).isPresent(); - boolean isPresentInClonePluginData = cloneRegionPluginData.getPersonRegion(personId).isPresent(); - assertEquals(isPresentInPluginData, isPresentInClonePluginData); - if (isPresentInPluginData) { - RegionId expectedRegionId = regionsPluginData.getPersonRegion(personId).get(); - RegionId actualRegionId = cloneRegionPluginData.getPersonRegion(personId).get(); - assertEquals(expectedRegionId, actualRegionId); - } - } + private void testGetCloneBuilder_subTest4() { + boolean containsPeople = false; + boolean useArrivalTracking = true; + boolean useEmptyDefaultProperties = true; + long seed = 5969645744439416482L; + RegionsPluginData regionsPluginData = getRegionsPluginData(containsPeople, useArrivalTracking, + useEmptyDefaultProperties, seed); + + // show that the returned clone builder will build an identical instance if no + // mutations are made + RegionsPluginData.Builder cloneBuilder = regionsPluginData.getCloneBuilder(); + assertNotNull(cloneBuilder); + assertEquals(regionsPluginData, cloneBuilder.build()); + + // show that the clone builder builds a distinct instance if any mutation is + // made + + // setPersonRegionArrivalTracking + cloneBuilder = regionsPluginData.getCloneBuilder(); + cloneBuilder.setPersonRegionArrivalTracking(!regionsPluginData.getPersonRegionArrivalTrackingPolicy()); + assertNotEquals(regionsPluginData, cloneBuilder.build()); } @@ -898,60 +990,53 @@ public void testEquals() { @UnitTestMethod(target = RegionsPluginData.class, name = "hashCode", args = {}) public void testHashCode() { RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(586211957860853353L); - + // equal objects have equal hash codes for (int i = 0; i < 30; i++) { long seed = randomGenerator.nextLong(); RegionsPluginData regionsPluginData1 = getRandomRegionsPluginData(seed); RegionsPluginData regionsPluginData2 = getRandomRegionsPluginData(seed); - assertEquals(regionsPluginData1,regionsPluginData2); - assertEquals(regionsPluginData1.hashCode(),regionsPluginData2.hashCode()); + assertEquals(regionsPluginData1, regionsPluginData2); + assertEquals(regionsPluginData1.hashCode(), regionsPluginData2.hashCode()); } - - //hash codes are reasonably distributed + + // hash codes are reasonably distributed Set hashCodes = new LinkedHashSet<>(); - for (int i = 0; i < 100; i++) { + for (int i = 0; i < 100; i++) { RegionsPluginData regionsPluginData = getRandomRegionsPluginData(randomGenerator.nextLong()); hashCodes.add(regionsPluginData.hashCode()); } assertEquals(100, hashCodes.size()); - + } - - // RegionsPluginData public java.lang.String plugins.regions.datamanagers.RegionsPluginData.toString() - + @Test @UnitTestMethod(target = RegionsPluginData.class, name = "toString", args = {}) public void testToString() { RegionsPluginData regionsPluginData = getRandomRegionsPluginData(6728844980805060979L); - + String actualValue = regionsPluginData.toString(); - - //expected value manually verified - String expectedValue = "RegionsPluginData [data=Data [" - + "regionPropertyDefinitions={" + // expected value manually verified + String expectedValue = "RegionsPluginData [data=Data [" + "regionPropertyDefinitions={" + "REGION_PROPERTY_3_DOUBLE_MUTABLE=PropertyDefinition [type=class java.lang.Double, propertyValuesAreMutable=true, defaultValue=0.0], " + "REGION_PROPERTY_5_INTEGER_IMMUTABLE=PropertyDefinition [type=class java.lang.Integer, propertyValuesAreMutable=false, defaultValue=0]}, " - + + "regionIds=[REGION_3, REGION_1, REGION_4], " - + + "trackRegionArrivalTimes=true, " - - + "regionPropertyValues={" - + "REGION_1={REGION_PROPERTY_5_INTEGER_IMMUTABLE=1769994519}, " + + + "regionPropertyValues={" + "REGION_1={REGION_PROPERTY_5_INTEGER_IMMUTABLE=1769994519}, " + "REGION_3={REGION_PROPERTY_5_INTEGER_IMMUTABLE=706454702}}, " - + + "personRegions=[null, REGION_4, null, REGION_3, null, REGION_1, null, REGION_3, null, REGION_1], " - - + + "personArrivalTimes=[null, 0.008078132587675535, null, 0.7027533190641975, null, 0.38173962849044774, null, 0.7955082969867588, null, 0.9457602126490658], " - - + + "locked=true]]"; - + assertEquals(expectedValue, actualValue); } } diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/regions/reports/AT_RegionPropertyReportPluginData.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/regions/reports/AT_RegionPropertyReportPluginData.java index 80772ee03..f7b0164b3 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/regions/reports/AT_RegionPropertyReportPluginData.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/regions/reports/AT_RegionPropertyReportPluginData.java @@ -368,19 +368,43 @@ public void testGetCloneBuilder() { builder.excludeRegionProperty(testRegionPropertyId); } } + //force some values for later + builder.includeRegionProperty(TestRegionPropertyId.REGION_PROPERTY_1_BOOLEAN_MUTABLE); + builder.excludeRegionProperty(TestRegionPropertyId.REGION_PROPERTY_2_INTEGER_MUTABLE); + builder.setDefaultInclusion(randomGenerator.nextBoolean()).build(); RegionPropertyReportPluginData regionPropertyReportPluginData = builder.build(); - // create the clone builder and have it build - RegionPropertyReportPluginData cloneRegionPropertyReportPluginData = regionPropertyReportPluginData - .getCloneBuilder().build(); - - // the result should equal the original if the clone builder was - // initialized with the correct state - assertEquals(regionPropertyReportPluginData, cloneRegionPropertyReportPluginData); - + // show that the returned clone builder will build an identical instance if no + // mutations are made + RegionPropertyReportPluginData.Builder cloneBuilder = regionPropertyReportPluginData.getCloneBuilder(); + assertNotNull(cloneBuilder); + assertEquals(regionPropertyReportPluginData, cloneBuilder.build()); + + // show that the clone builder builds a distinct instance if any mutation is + // made + + // excludeRegionProperty + cloneBuilder = regionPropertyReportPluginData.getCloneBuilder(); + cloneBuilder.excludeRegionProperty(TestRegionPropertyId.REGION_PROPERTY_1_BOOLEAN_MUTABLE); + assertNotEquals(regionPropertyReportPluginData, cloneBuilder.build()); + + // includeRegionProperty + cloneBuilder = regionPropertyReportPluginData.getCloneBuilder(); + cloneBuilder.includeRegionProperty(TestRegionPropertyId.REGION_PROPERTY_2_INTEGER_MUTABLE); + assertNotEquals(regionPropertyReportPluginData, cloneBuilder.build()); + + // setDefaultInclusion + cloneBuilder = regionPropertyReportPluginData.getCloneBuilder(); + cloneBuilder.setDefaultInclusion(!regionPropertyReportPluginData.getDefaultInclusionPolicy()); + assertNotEquals(regionPropertyReportPluginData, cloneBuilder.build()); + + // setReportLabel + cloneBuilder = regionPropertyReportPluginData.getCloneBuilder(); + cloneBuilder.setReportLabel(new SimpleReportLabel("asdf")); + assertNotEquals(regionPropertyReportPluginData, cloneBuilder.build()); } } diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/regions/reports/AT_RegionTransferReportPluginData.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/regions/reports/AT_RegionTransferReportPluginData.java index 814da3e26..12ba39b43 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/regions/reports/AT_RegionTransferReportPluginData.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/regions/reports/AT_RegionTransferReportPluginData.java @@ -147,13 +147,24 @@ public void testGetCloneBuilder() { RegionTransferReportPluginData regionTransferReportPluginData = builder.build(); - // create the clone builder and have it build - RegionTransferReportPluginData cloneRegionTransferReportPluginData = regionTransferReportPluginData - .getCloneBuilder().build(); - - // the result should equal the original if the clone builder was - // initialized with the correct state - assertEquals(regionTransferReportPluginData, cloneRegionTransferReportPluginData); + // show that the returned clone builder will build an identical instance if no + // mutations are made + RegionTransferReportPluginData.Builder cloneBuilder = regionTransferReportPluginData.getCloneBuilder(); + assertNotNull(cloneBuilder); + assertEquals(regionTransferReportPluginData, cloneBuilder.build()); + + // show that the clone builder builds a distinct instance if any mutation is + // made + + // setReportLabel + cloneBuilder = regionTransferReportPluginData.getCloneBuilder(); + cloneBuilder.setReportLabel(new SimpleReportLabel("asdf")); + assertNotEquals(regionTransferReportPluginData, cloneBuilder.build()); + + // setReportPeriod + cloneBuilder = regionTransferReportPluginData.getCloneBuilder(); + cloneBuilder.setReportPeriod(regionTransferReportPluginData.getReportPeriod().next()); + assertNotEquals(regionTransferReportPluginData, cloneBuilder.build()); } } diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/reports/support/AT_ReportPeriod.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/reports/support/AT_ReportPeriod.java new file mode 100644 index 000000000..4fddee08e --- /dev/null +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/reports/support/AT_ReportPeriod.java @@ -0,0 +1,24 @@ +package gov.hhs.aspr.ms.gcm.plugins.reports.support; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +import gov.hhs.aspr.ms.util.annotations.UnitTestMethod; + +public class AT_ReportPeriod { + + @Test + @UnitTestMethod(target = ReportPeriod.class, name = "next", args = {}) + public void testNext() { + + for (ReportPeriod reportPeriod : ReportPeriod.values()) { + int n = ReportPeriod.values().length; + int index = (reportPeriod.ordinal() + 1) % n; + ReportPeriod expectedValue = ReportPeriod.values()[index]; + ReportPeriod actualValue = reportPeriod.next(); + assertEquals(expectedValue, actualValue); + } + + } +} diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/resources/datamanagers/AT_ResourcesPluginData.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/resources/datamanagers/AT_ResourcesPluginData.java index e212ed820..0cc4edf00 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/resources/datamanagers/AT_ResourcesPluginData.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/resources/datamanagers/AT_ResourcesPluginData.java @@ -2,6 +2,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -17,7 +18,6 @@ import org.apache.commons.math3.random.RandomGenerator; import org.junit.jupiter.api.Test; -import gov.hhs.aspr.ms.gcm.nucleus.PluginData; import gov.hhs.aspr.ms.gcm.plugins.people.support.PersonError; import gov.hhs.aspr.ms.gcm.plugins.people.support.PersonId; import gov.hhs.aspr.ms.gcm.plugins.properties.support.PropertyDefinition; @@ -1416,15 +1416,46 @@ public void testGetCloneBuilder() { ResourcesPluginData resourcesPluginData = pluginDataBuilder.build(); - PluginData pluginData = resourcesPluginData.getCloneBuilder().build(); + // show that the returned clone builder will build an identical instance if no + // mutations are made + ResourcesPluginData.Builder cloneBuilder = resourcesPluginData.getCloneBuilder(); + assertNotNull(cloneBuilder); + assertEquals(resourcesPluginData, cloneBuilder.build()); - // show that the plugin data is of the expected type - assertTrue(pluginData instanceof ResourcesPluginData); - - ResourcesPluginData cloneResourcesPluginData = (ResourcesPluginData) pluginData; - - assertEquals(resourcesPluginData, cloneResourcesPluginData); + // show that the clone builder builds a distinct instance if any mutation is + // made + // addResource + cloneBuilder = resourcesPluginData.getCloneBuilder(); + cloneBuilder.addResource(TestResourceId.getUnknownResourceId(),2.5,false); + assertNotEquals(resourcesPluginData, cloneBuilder.build()); + + // defineResourceProperty + cloneBuilder = resourcesPluginData.getCloneBuilder(); + PropertyDefinition propertyDefinition = PropertyDefinition.builder().setDefaultValue(6).setType(Integer.class).setPropertyValueMutability(true).build(); + cloneBuilder.defineResourceProperty(TestResourceId.RESOURCE_1,TestResourcePropertyId.getUnknownResourcePropertyId(),propertyDefinition); + assertNotEquals(resourcesPluginData, cloneBuilder.build()); + + // setPersonResourceLevel + cloneBuilder = resourcesPluginData.getCloneBuilder(); + cloneBuilder.setPersonResourceLevel(new PersonId(1000),TestResourceId.RESOURCE_3,234L); + assertNotEquals(resourcesPluginData, cloneBuilder.build()); + + // setPersonResourceTime + cloneBuilder = resourcesPluginData.getCloneBuilder(); + cloneBuilder.setPersonResourceTime(new PersonId(1000),TestResourceId.RESOURCE_3,64.745); + assertNotEquals(resourcesPluginData, cloneBuilder.build()); + + // setRegionResourceLevel + cloneBuilder = resourcesPluginData.getCloneBuilder(); + cloneBuilder.setRegionResourceLevel(TestRegionId.REGION_1,TestResourceId.RESOURCE_3,234L); + assertNotEquals(resourcesPluginData, cloneBuilder.build()); + + // setResourcePropertyValue + cloneBuilder = resourcesPluginData.getCloneBuilder(); + cloneBuilder.setResourcePropertyValue(TestResourceId.RESOURCE_1,TestResourcePropertyId.ResourceProperty_1_3_DOUBLE_MUTABLE,18.6); + assertNotEquals(resourcesPluginData, cloneBuilder.build()); + } diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/resources/reports/AT_PersonResourceReportPluginData.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/resources/reports/AT_PersonResourceReportPluginData.java index 79dbede8d..4464e5c5f 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/resources/reports/AT_PersonResourceReportPluginData.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/resources/reports/AT_PersonResourceReportPluginData.java @@ -443,18 +443,47 @@ public void testGetCloneBuilder() { builder.excludeResource(testResourceId); } } + // force some values for later use + builder.includeResource(TestResourceId.RESOURCE_1); + builder.excludeResource(TestResourceId.RESOURCE_2); builder.setDefaultInclusion(randomGenerator.nextBoolean()).build(); PersonResourceReportPluginData personResourceReportPluginData = builder.build(); - // create the clone builder and have it build - PersonResourceReportPluginData clonePersonResourceReportPluginData = personResourceReportPluginData - .getCloneBuilder().build(); - - // the result should equal the original if the clone builder was - // initialized with the correct state - assertEquals(personResourceReportPluginData, clonePersonResourceReportPluginData); + // show that the returned clone builder will build an identical instance if no + // mutations are made + PersonResourceReportPluginData.Builder cloneBuilder = personResourceReportPluginData.getCloneBuilder(); + assertNotNull(cloneBuilder); + assertEquals(personResourceReportPluginData, cloneBuilder.build()); + + // show that the clone builder builds a distinct instance if any mutation is + // made + + // excludeResource + cloneBuilder = personResourceReportPluginData.getCloneBuilder(); + cloneBuilder.excludeResource(TestResourceId.RESOURCE_1); + assertNotEquals(personResourceReportPluginData, cloneBuilder.build()); + + // includeResource + cloneBuilder = personResourceReportPluginData.getCloneBuilder(); + cloneBuilder.includeResource(TestResourceId.RESOURCE_2); + assertNotEquals(personResourceReportPluginData, cloneBuilder.build()); + + // setDefaultInclusion + cloneBuilder = personResourceReportPluginData.getCloneBuilder(); + cloneBuilder.setDefaultInclusion(!personResourceReportPluginData.getDefaultInclusionPolicy()); + assertNotEquals(personResourceReportPluginData, cloneBuilder.build()); + + // setReportLabel + cloneBuilder = personResourceReportPluginData.getCloneBuilder(); + cloneBuilder.setReportLabel(new SimpleReportLabel("asdf")); + assertNotEquals(personResourceReportPluginData, cloneBuilder.build()); + + // setReportPeriod + cloneBuilder = personResourceReportPluginData.getCloneBuilder(); + cloneBuilder.setReportPeriod(personResourceReportPluginData.getReportPeriod().next()); + assertNotEquals(personResourceReportPluginData, cloneBuilder.build()); } } @@ -601,8 +630,8 @@ public void testHashCode() { } /* - * The hash codes should be dispersed -- we only show that they are - * unique values -- this is dependent on the random seed + * The hash codes should be dispersed -- we only show that they are unique + * values -- this is dependent on the random seed */ assertEquals(50, observedHashCodes.size()); @@ -612,22 +641,21 @@ public void testHashCode() { @UnitTestMethod(target = PersonResourceReportPluginData.class, name = "toString", args = {}) public void testToString() { PersonResourceReportPluginData personResourceReportPluginData = PersonResourceReportPluginData.builder()// - .setReportLabel(new SimpleReportLabel("report label"))// - .setDefaultInclusion(true)// - .setReportPeriod(ReportPeriod.DAILY)// - .includeResource(TestResourceId.RESOURCE_1)// - .includeResource(TestResourceId.RESOURCE_3)// - .excludeResource(TestResourceId.RESOURCE_2)// - .excludeResource(TestResourceId.RESOURCE_4)// - .build();// - - String actualValue = - personResourceReportPluginData.toString(); - + .setReportLabel(new SimpleReportLabel("report label"))// + .setDefaultInclusion(true)// + .setReportPeriod(ReportPeriod.DAILY)// + .includeResource(TestResourceId.RESOURCE_1)// + .includeResource(TestResourceId.RESOURCE_3)// + .excludeResource(TestResourceId.RESOURCE_2)// + .excludeResource(TestResourceId.RESOURCE_4)// + .build();// + + String actualValue = personResourceReportPluginData.toString(); + String expectedValue = "PersonResourceReportPluginData [data=Data [reportLabel=SimpleReportLabel [value=report label]," + " reportPeriod=DAILY, includedResourceIds=[RESOURCE_1, RESOURCE_3], excludedResourceIds=[RESOURCE_2, RESOURCE_4]," + " defaultInclusionPolicy=true]]"; - + assertEquals(actualValue, expectedValue); } diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/resources/reports/AT_ResourcePropertyReportPluginData.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/resources/reports/AT_ResourcePropertyReportPluginData.java index ce67e2f96..b008229d7 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/resources/reports/AT_ResourcePropertyReportPluginData.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/resources/reports/AT_ResourcePropertyReportPluginData.java @@ -93,12 +93,20 @@ public void testGetCloneBuilder() { ResourcePropertyReportPluginData resourcePropertyReportPluginData = builder.build(); - // create the clone builder and have it build - ResourcePropertyReportPluginData cloneResourcePropertyReportPluginData = resourcePropertyReportPluginData.getCloneBuilder().build(); + // show that the returned clone builder will build an identical instance if no + // mutations are made + ResourcePropertyReportPluginData.Builder cloneBuilder = resourcePropertyReportPluginData.getCloneBuilder(); + assertNotNull(cloneBuilder); + assertEquals(resourcePropertyReportPluginData, cloneBuilder.build()); + + // show that the clone builder builds a distinct instance if any mutation is + // made + + // setReportLabel + cloneBuilder = resourcePropertyReportPluginData.getCloneBuilder(); + cloneBuilder.setReportLabel(new SimpleReportLabel("asdf")); + assertNotEquals(resourcePropertyReportPluginData, cloneBuilder.build()); - // the result should equal the original if the clone builder was - // initialized with the correct state - assertEquals(resourcePropertyReportPluginData, cloneResourcePropertyReportPluginData); } } diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/resources/reports/AT_ResourceReportPluginData.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/resources/reports/AT_ResourceReportPluginData.java index 668c9c5fd..1764f77e9 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/resources/reports/AT_ResourceReportPluginData.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/resources/reports/AT_ResourceReportPluginData.java @@ -443,17 +443,47 @@ public void testGetCloneBuilder() { builder.excludeResource(testResourceId); } } + //force some values for later use + builder.includeResource(TestResourceId.RESOURCE_1); + builder.excludeResource(TestResourceId.RESOURCE_2); builder.setDefaultInclusion(randomGenerator.nextBoolean()).build(); ResourceReportPluginData resourceReportPluginData = builder.build(); - // create the clone builder and have it build - ResourceReportPluginData cloneResourceReportPluginData = resourceReportPluginData.getCloneBuilder().build(); - - // the result should equal the original if the clone builder was - // initialized with the correct state - assertEquals(resourceReportPluginData, cloneResourceReportPluginData); + // show that the returned clone builder will build an identical instance if no + // mutations are made + ResourceReportPluginData.Builder cloneBuilder = resourceReportPluginData.getCloneBuilder(); + assertNotNull(cloneBuilder); + assertEquals(resourceReportPluginData, cloneBuilder.build()); + + // show that the clone builder builds a distinct instance if any mutation is + // made + + // excludeResource + cloneBuilder = resourceReportPluginData.getCloneBuilder(); + cloneBuilder.excludeResource(TestResourceId.RESOURCE_1); + assertNotEquals(resourceReportPluginData, cloneBuilder.build()); + + // includeResource + cloneBuilder = resourceReportPluginData.getCloneBuilder(); + cloneBuilder.includeResource(TestResourceId.RESOURCE_2); + assertNotEquals(resourceReportPluginData, cloneBuilder.build()); + + // setDefaultInclusion + cloneBuilder = resourceReportPluginData.getCloneBuilder(); + cloneBuilder.setDefaultInclusion(!resourceReportPluginData.getDefaultInclusionPolicy()); + assertNotEquals(resourceReportPluginData, cloneBuilder.build()); + + // setReportLabel + cloneBuilder = resourceReportPluginData.getCloneBuilder(); + cloneBuilder.setReportLabel(new SimpleReportLabel("asdf")); + assertNotEquals(resourceReportPluginData, cloneBuilder.build()); + + // setReportPeriod + cloneBuilder = resourceReportPluginData.getCloneBuilder(); + cloneBuilder.setReportPeriod(resourceReportPluginData.getReportPeriod().next()); + assertNotEquals(resourceReportPluginData, cloneBuilder.build()); } } diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/stochastics/AT_StochasticsPluginData.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/stochastics/AT_StochasticsPluginData.java index e14c6f75d..ccb93177b 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/stochastics/AT_StochasticsPluginData.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/plugins/stochastics/AT_StochasticsPluginData.java @@ -2,6 +2,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -18,7 +19,6 @@ import org.apache.commons.math3.random.RandomGenerator; import org.junit.jupiter.api.Test; -import gov.hhs.aspr.ms.gcm.nucleus.PluginDataBuilder; import gov.hhs.aspr.ms.gcm.plugins.stochastics.datamanagers.StochasticsPluginData; import gov.hhs.aspr.ms.gcm.plugins.stochastics.support.RandomNumberGeneratorId; import gov.hhs.aspr.ms.gcm.plugins.stochastics.support.StochasticsError; @@ -42,13 +42,27 @@ public void testGetCloneBuilder() { .addRNG(TestRandomGeneratorId.COMET, wellState)// .build();// - // show that the clone builder is not null - PluginDataBuilder cloneBuilder = stochasticsPluginData.getCloneBuilder(); + // show that the returned clone builder will build an identical instance if no + // mutations are made + StochasticsPluginData.Builder cloneBuilder = stochasticsPluginData.getCloneBuilder(); assertNotNull(cloneBuilder); - StochasticsPluginData cloneData = (StochasticsPluginData) cloneBuilder.build(); + assertEquals(stochasticsPluginData, cloneBuilder.build()); + + // show that the clone builder builds a distinct instance if any mutation is + // made + + // addRNG + cloneBuilder = stochasticsPluginData.getCloneBuilder(); + wellState = WellState.builder().setSeed(6937151566492160140L).build(); + cloneBuilder.addRNG(TestRandomGeneratorId.CUPID, wellState); + assertNotEquals(stochasticsPluginData, cloneBuilder.build()); + + // setMainRNGState + cloneBuilder = stochasticsPluginData.getCloneBuilder(); + wellState = WellState.builder().setSeed(1286993379829775736L).build(); + cloneBuilder.setMainRNGState(wellState); + assertNotEquals(stochasticsPluginData, cloneBuilder.build()); - // show that the clone builder is properly initialized - assertEquals(cloneData, stochasticsPluginData); } @@ -256,7 +270,7 @@ public void testHashCode() { } assertEquals(100, hashCodes.size()); } - + @Test @UnitTestMethod(target = StochasticsPluginData.class, name = "toString", args = {}) public void testToString() { @@ -264,14 +278,17 @@ public void testToString() { String actualValue = stochasticsPluginData.toString(); /* - * Expected value manually verified. It is impractical to use the full string for verification, so we will assert that certain critical substrings are contained as expected. + * Expected value manually verified. It is impractical to use the full string + * for verification, so we will assert that certain critical substrings are + * contained as expected. */ - assertTrue(actualValue.contains("StochasticsPluginData [data=Data [wellState=WellState [data=Data [seed=-3890456017103968429")); - assertTrue(actualValue.contains("VIXEN=WellState [data=Data [seed=-9202547125755605402")); + assertTrue(actualValue.contains( + "StochasticsPluginData [data=Data [wellState=WellState [data=Data [seed=-3890456017103968429")); + assertTrue(actualValue.contains("VIXEN=WellState [data=Data [seed=-9202547125755605402")); assertTrue(actualValue.contains("DONNER=WellState [data=Data [seed=-4994162167240462248")); assertTrue(actualValue.contains("PRANCER=WellState [data=Data [seed=2580414198424993374")); - assertTrue(actualValue.contains("BLITZEN=WellState [data=Data [seed=-3565866373405448731")); - assertTrue(actualValue.contains("DANCER=WellState [data=Data [seed=3656710085871564729")); + assertTrue(actualValue.contains("BLITZEN=WellState [data=Data [seed=-3565866373405448731")); + assertTrue(actualValue.contains("DANCER=WellState [data=Data [seed=3656710085871564729")); } }