From 6c23f1643de53649acdbd26e464fc5965493cabe Mon Sep 17 00:00:00 2001 From: shawnhatch Date: Thu, 27 Jun 2024 15:46:10 -0400 Subject: [PATCH] More plan class refinements and adaptation of those changes to the lesson classes --- .../plugins/model/actors/Vaccinator.java | 5 +- .../plugins/model/actors/SchoolManager.java | 3 +- .../plugins/model/actors/TeleworkManager.java | 3 +- .../plugins/model/actors/EventVaccinator.java | 3 +- .../simulation/nucleus/ConsumerActorPlan.java | 4 +- .../nucleus/ConsumerDataManagerPlan.java | 76 +++++++++++++++++++ .../nucleus/ConsumerReportPlan.java | 54 +++++++++++++ .../nucleus/DataManagerContext.java | 2 +- .../simulation/nucleus/DataManagerPlan.java | 68 +++++------------ .../gcm/simulation/nucleus/ReportContext.java | 2 +- .../ms/gcm/simulation/nucleus/ReportPlan.java | 46 ++--------- .../nucleus/AT_ConsumerDataManagerPlan.java | 45 +++++++++++ .../nucleus/AT_ConsumerReportPlan.java | 34 +++++++++ .../nucleus/AT_DataManagerContext.java | 10 +-- .../nucleus/AT_DataManagerPlan.java | 54 +++++-------- .../simulation/nucleus/AT_ReportContext.java | 20 ++--- .../gcm/simulation/nucleus/AT_ReportPlan.java | 22 +----- 17 files changed, 286 insertions(+), 165 deletions(-) create mode 100644 simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerDataManagerPlan.java create mode 100644 simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerReportPlan.java create mode 100644 simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ConsumerDataManagerPlan.java create mode 100644 simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ConsumerReportPlan.java diff --git a/lessons/lesson-16/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/Vaccinator.java b/lessons/lesson-16/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/Vaccinator.java index 1bbb8f7de..97937ab7d 100644 --- a/lessons/lesson-16/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/Vaccinator.java +++ b/lessons/lesson-16/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/Vaccinator.java @@ -10,6 +10,7 @@ import gov.hhs.aspr.ms.gcm.lessons.plugins.model.PersonProperty; import gov.hhs.aspr.ms.gcm.simulation.nucleus.ActorContext; import gov.hhs.aspr.ms.gcm.simulation.nucleus.ActorPlan; +import gov.hhs.aspr.ms.gcm.simulation.nucleus.ConsumerActorPlan; import gov.hhs.aspr.ms.gcm.simulation.nucleus.EventFilter; import gov.hhs.aspr.ms.gcm.simulation.plugins.globalproperties.datamanagers.GlobalPropertiesDataManager; import gov.hhs.aspr.ms.gcm.simulation.plugins.people.datamanagers.PeopleDataManager; @@ -46,7 +47,7 @@ private void vaccinatePerson(PersonId personId) { if (refusesVaccine) { double planTime = actorContext.getTime() + randomGenerator.nextDouble() * vaccineAttemptInterval; - ActorPlan plan = new ActorPlan(planTime, (c) -> vaccinatePerson(personId)); + ActorPlan plan = new ConsumerActorPlan(planTime, (c) -> vaccinatePerson(personId)); actorContext.addPlan(plan); //record the plan for possible cancellation actorPlans.put(personId, plan); @@ -80,7 +81,7 @@ private void handleVaccineAcceptance(ActorContext actorContext, /* start code_ref= person_properties_vaccinator_plan_vaccination|code_cap= Each unvaccinated person has a planned vaccination based on the VACCINE_ATTEMPT_INTERVAL global property. */ private void planVaccination(PersonId personId) { double planTime = actorContext.getTime() + randomGenerator.nextDouble() * vaccineAttemptInterval; - ActorPlan plan = new ActorPlan(planTime, (c) -> vaccinatePerson(personId)); + ActorPlan plan = new ConsumerActorPlan(planTime, (c) -> vaccinatePerson(personId)); actorContext.addPlan(plan); //record the plan for possible cancellation actorPlans.put(personId, plan); diff --git a/lessons/lesson-17/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/SchoolManager.java b/lessons/lesson-17/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/SchoolManager.java index d1c66b158..c54a543c3 100644 --- a/lessons/lesson-17/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/SchoolManager.java +++ b/lessons/lesson-17/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/SchoolManager.java @@ -10,6 +10,7 @@ import gov.hhs.aspr.ms.gcm.lessons.plugins.model.support.SchoolStatus; import gov.hhs.aspr.ms.gcm.simulation.nucleus.ActorContext; import gov.hhs.aspr.ms.gcm.simulation.nucleus.ActorPlan; +import gov.hhs.aspr.ms.gcm.simulation.nucleus.ConsumerActorPlan; import gov.hhs.aspr.ms.gcm.simulation.plugins.globalproperties.datamanagers.GlobalPropertiesDataManager; import gov.hhs.aspr.ms.gcm.simulation.plugins.groups.datamanagers.GroupsDataManager; import gov.hhs.aspr.ms.gcm.simulation.plugins.groups.support.GroupConstructionInfo; @@ -41,7 +42,7 @@ public void init(ActorContext actorContext) { private void planNextReview() { double planTime = actorContext.getTime() + reviewInterval; - ActorPlan plan = new ActorPlan(planTime,false,this::reviewSchools); + ActorPlan plan = new ConsumerActorPlan(planTime,false,this::reviewSchools); actorContext.addPlan(plan); } diff --git a/lessons/lesson-17/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/TeleworkManager.java b/lessons/lesson-17/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/TeleworkManager.java index 9bfacde4c..e2f77ca42 100644 --- a/lessons/lesson-17/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/TeleworkManager.java +++ b/lessons/lesson-17/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/TeleworkManager.java @@ -11,6 +11,7 @@ import gov.hhs.aspr.ms.gcm.lessons.plugins.model.support.PersonProperty; import gov.hhs.aspr.ms.gcm.simulation.nucleus.ActorContext; import gov.hhs.aspr.ms.gcm.simulation.nucleus.ActorPlan; +import gov.hhs.aspr.ms.gcm.simulation.nucleus.ConsumerActorPlan; import gov.hhs.aspr.ms.gcm.simulation.plugins.globalproperties.datamanagers.GlobalPropertiesDataManager; import gov.hhs.aspr.ms.gcm.simulation.plugins.groups.datamanagers.GroupsDataManager; import gov.hhs.aspr.ms.gcm.simulation.plugins.groups.support.GroupId; @@ -31,7 +32,7 @@ public void init(ActorContext actorContext) { private void scheduleNextReview() { double planTime = actorContext.getTime() + reviewInterval; - ActorPlan plan = new ActorPlan(planTime,false,this::reviewTeleworkStatus); + ActorPlan plan = new ConsumerActorPlan(planTime,false,this::reviewTeleworkStatus); actorContext.addPlan(plan); } diff --git a/lessons/lesson-20/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/EventVaccinator.java b/lessons/lesson-20/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/EventVaccinator.java index 3fce46054..4a4ff40fd 100644 --- a/lessons/lesson-20/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/EventVaccinator.java +++ b/lessons/lesson-20/src/main/java/gov/hhs/aspr/ms/gcm/lessons/plugins/model/actors/EventVaccinator.java @@ -11,6 +11,7 @@ import gov.hhs.aspr.ms.gcm.lessons.plugins.model.support.PersonProperty; import gov.hhs.aspr.ms.gcm.simulation.nucleus.ActorContext; import gov.hhs.aspr.ms.gcm.simulation.nucleus.ActorPlan; +import gov.hhs.aspr.ms.gcm.simulation.nucleus.ConsumerActorPlan; import gov.hhs.aspr.ms.gcm.simulation.nucleus.EventFilter; import gov.hhs.aspr.ms.gcm.simulation.plugins.globalproperties.datamanagers.GlobalPropertiesDataManager; import gov.hhs.aspr.ms.gcm.simulation.plugins.people.datamanagers.PeopleDataManager; @@ -215,7 +216,7 @@ private void intializeCandidatesAndWeights() { * vaccinator selects from maintained sub-populations. */ private void planNextVaccination() { - futurePlan = new ActorPlan(interVaccinationTime + actorContext.getTime(), this::vaccinatePerson); + futurePlan = new ConsumerActorPlan(interVaccinationTime + actorContext.getTime(), this::vaccinatePerson); actorContext.addPlan(futurePlan); } diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerActorPlan.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerActorPlan.java index 39a90dbb7..82dbb58b6 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerActorPlan.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerActorPlan.java @@ -40,7 +40,7 @@ public ConsumerActorPlan(double time, boolean active, long arrivalId, Consumer consumer) { - super(time, true, -1L); + super(time); if (consumer == null) { throw new ContractException(NucleusError.NULL_PLAN_CONSUMER); } @@ -60,7 +60,7 @@ public ConsumerActorPlan(double time, Consumer consumer) { * */ public ConsumerActorPlan(double time, boolean active, Consumer consumer) { - super(time, active, -1L); + super(time, active); if (consumer == null) { throw new ContractException(NucleusError.NULL_PLAN_CONSUMER); } diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerDataManagerPlan.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerDataManagerPlan.java new file mode 100644 index 000000000..d342e68fb --- /dev/null +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerDataManagerPlan.java @@ -0,0 +1,76 @@ +package gov.hhs.aspr.ms.gcm.simulation.nucleus; + +import java.util.function.Consumer; + +import gov.hhs.aspr.ms.util.errors.ContractException; + +public class ConsumerDataManagerPlan extends DataManagerPlan { + + private final Consumer consumer; + + /** + * Constructs the plan scheduled for the given time active status arrivalId and + * consumer + * + * @throw {@link ContractException} + *
    + *
  • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is + * null
  • + *
+ * + */ + public ConsumerDataManagerPlan(double time, boolean active, long arrivalId, Consumer consumer) { + super(time, active, arrivalId); + if (consumer == null) { + throw new ContractException(NucleusError.NULL_PLAN_CONSUMER); + } + + this.consumer = consumer; + } + + /** + * Constructs the plan scheduled for the given time, active status and consumer. + * The arrival id is set to -1L indicating that this is a new, non-deserialized + * plan. + * + * @throw {@link ContractException} + *
    + *
  • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is + * null
  • + *
+ * + */ + public ConsumerDataManagerPlan(double time, boolean active, Consumer consumer) { + super(time, active); + if (consumer == null) { + throw new ContractException(NucleusError.NULL_PLAN_CONSUMER); + } + this.consumer = consumer; + } + + /** + * Constructs the plan scheduled for the given time and consumer. The plan will + * be active.The arrival id is set to -1L indicating that this is a new, + * non-deserialized plan. + * + * @throw {@link ContractException} + *
    + *
  • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is + * null
  • + *
+ * + */ + public ConsumerDataManagerPlan(double time, Consumer consumer) { + super(time); + if (consumer == null) { + throw new ContractException(NucleusError.NULL_PLAN_CONSUMER); + } + + this.consumer = consumer; + } + + @Override + protected void execute(DataManagerContext context) { + this.consumer.accept(context); + } +} diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerReportPlan.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerReportPlan.java new file mode 100644 index 000000000..1487cbe2f --- /dev/null +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ConsumerReportPlan.java @@ -0,0 +1,54 @@ +package gov.hhs.aspr.ms.gcm.simulation.nucleus; + +import java.util.function.Consumer; + +import gov.hhs.aspr.ms.util.errors.ContractException; + +public class ConsumerReportPlan extends ReportPlan { + + private final Consumer consumer; + + /** + * Constructs the plan scheduled for the given time, arrivalId and consumer. + * Report plans are always passive. + * + * @throw {@link ContractException} + *
    + *
  • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is + * null
  • + *
+ * + */ + public ConsumerReportPlan(double time, long arrivalId, Consumer consumer) { + super(time, arrivalId); + if (consumer == null) { + throw new ContractException(NucleusError.NULL_PLAN_CONSUMER); + } + this.consumer = consumer; + } + + /** + * Constructs the plan scheduled for the given time and consumer. Report plans + * are always passive.The arrival id is set to -1L indicating that this is a + * new, non-deserialized plan. + * + * @throw {@link ContractException} + *
    + *
  • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is + * null
  • + *
+ * + */ + public ConsumerReportPlan(double time, Consumer consumer) { + super(time); + if (consumer == null) { + throw new ContractException(NucleusError.NULL_PLAN_CONSUMER); + } + this.consumer = consumer; + } + + @Override + protected void execute(ReportContext context) { + this.consumer.accept(context); + } +} diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/DataManagerContext.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/DataManagerContext.java index b80256053..0dfce12e8 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/DataManagerContext.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/DataManagerContext.java @@ -39,7 +39,7 @@ protected DataManagerContext(DataManagerId dataManagerId, Simulation simulation) * */ public void addPlan(final Consumer consumer, final double planTime) { - simulation.addDataManagerPlan(dataManagerId, new DataManagerPlan(planTime, consumer)); + simulation.addDataManagerPlan(dataManagerId, new ConsumerDataManagerPlan(planTime, consumer)); } /** diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/DataManagerPlan.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/DataManagerPlan.java index 2b53b959d..692112b3b 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/DataManagerPlan.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/DataManagerPlan.java @@ -1,77 +1,49 @@ package gov.hhs.aspr.ms.gcm.simulation.nucleus; -import java.util.function.Consumer; - -import gov.hhs.aspr.ms.util.errors.ContractException; - -public class DataManagerPlan extends Plan { +public abstract class DataManagerPlan extends Plan { // The data manager id is used by the simulation via package access DataManagerId dataManagerId; - private final Consumer consumer; + /** - * Constructs the plan scheduled for the given time active status arrivalId and - * consumer - * - * @throw {@link ContractException} - *
    - *
  • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is - * null
  • - *
+ * Constructs the plan scheduled for the given time active status and arrivalId. * + */ - public DataManagerPlan(double time, boolean active, long arrivalId, Consumer consumer) { + public DataManagerPlan(double time, boolean active, long arrivalId) { super(time, active, arrivalId, Planner.DATA_MANAGER); - if (consumer == null) { - throw new ContractException(NucleusError.NULL_PLAN_CONSUMER); - } - - this.consumer = consumer; + } /** - * Constructs the plan scheduled for the given time, active status and consumer. + * Constructs the plan scheduled for the given time and active status. * The arrival id is set to -1L indicating that this is a new, non-deserialized * plan. - * - * @throw {@link ContractException} - *
    - *
  • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is - * null
  • - *
+ * */ - public DataManagerPlan(double time, boolean active, Consumer consumer) { + public DataManagerPlan(double time, boolean active) { super(time, active, -1L, Planner.DATA_MANAGER); - if (consumer == null) { - throw new ContractException(NucleusError.NULL_PLAN_CONSUMER); - } - this.consumer = consumer; + } /** - * Constructs the plan scheduled for the given time and consumer. The plan will + * Constructs the plan scheduled for the given time. The plan will * be active.The arrival id is set to -1L indicating that this is a new, * non-deserialized plan. * - * @throw {@link ContractException} - *
    - *
  • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is - * null
  • - *
+ * */ - public DataManagerPlan(double time, Consumer consumer) { + public DataManagerPlan(double time) { super(time, true, -1L, Planner.DATA_MANAGER); - if (consumer == null) { - throw new ContractException(NucleusError.NULL_PLAN_CONSUMER); - } - - this.consumer = consumer; - } - - protected void execute(DataManagerContext context) { - this.consumer.accept(context); + } + + /** + * Executes the data manager logic associated with the plan. + */ + protected abstract void execute(DataManagerContext context); + } diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ReportContext.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ReportContext.java index 42f059053..c21c533c4 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ReportContext.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ReportContext.java @@ -43,7 +43,7 @@ protected ReportContext(Simulation simulation) { * */ public void addPlan(final Consumer consumer, final double planTime) { - simulation.addReportPlan(new ReportPlan(planTime, consumer)); + simulation.addReportPlan(new ConsumerReportPlan(planTime, consumer)); } /** diff --git a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ReportPlan.java b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ReportPlan.java index 16684dc9a..2ea59e185 100644 --- a/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ReportPlan.java +++ b/simulation/src/main/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/ReportPlan.java @@ -1,56 +1,26 @@ package gov.hhs.aspr.ms.gcm.simulation.nucleus; -import java.util.function.Consumer; - -import gov.hhs.aspr.ms.util.errors.ContractException; - -public class ReportPlan extends Plan { +public abstract class ReportPlan extends Plan { ReportId reportId; - private final Consumer consumer; + /** - * Constructs the plan scheduled for the given time, arrivalId and consumer. + * Constructs the plan scheduled for the given time and arrivalId. * Report plans are always passive. * - * @throw {@link ContractException} - *
    - *
  • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is - * null
  • - *
- * */ - public ReportPlan(double time, long arrivalId, Consumer consumer) { - super(time, false, arrivalId, Planner.REPORT); - if (consumer == null) { - throw new ContractException(NucleusError.NULL_PLAN_CONSUMER); - } - this.consumer = consumer; + public ReportPlan(double time, long arrivalId) { + super(time, false, arrivalId, Planner.REPORT); } /** - * Constructs the plan scheduled for the given time and consumer. Report plans + * Constructs the plan scheduled for the given time. Report plans * are always passive.The arrival id is set to -1L indicating that this is a * new, non-deserialized plan. - * - * @throw {@link ContractException} - *
    - *
  • {@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is - * null
  • - *
- * */ - public ReportPlan(double time, Consumer consumer) { + public ReportPlan(double time) { super(time, false, -1L, Planner.REPORT); - if (consumer == null) { - throw new ContractException(NucleusError.NULL_PLAN_CONSUMER); - } - this.consumer = consumer; } - protected void execute(ReportContext context) { - if (consumer == null) { - throw new ContractException(NucleusError.NULL_PLAN_CONSUMER); - } - this.consumer.accept(context); - } + protected abstract void execute(ReportContext context); } diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ConsumerDataManagerPlan.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ConsumerDataManagerPlan.java new file mode 100644 index 000000000..1a145677f --- /dev/null +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ConsumerDataManagerPlan.java @@ -0,0 +1,45 @@ +package gov.hhs.aspr.ms.gcm.simulation.nucleus; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.util.function.Consumer; + +import org.junit.jupiter.api.Test; + +import gov.hhs.aspr.ms.util.annotations.UnitTestConstructor; +import gov.hhs.aspr.ms.util.errors.ContractException; + +public class AT_ConsumerDataManagerPlan { + + @Test + @UnitTestConstructor(target = ConsumerDataManagerPlan.class, args = { double.class, Consumer.class }) + public void testConstructor() { + //precondition test: if the consumer is null + ContractException contractException = assertThrows(ContractException.class, () -> { + new ConsumerDataManagerPlan(0, null); + }); + assertEquals(NucleusError.NULL_PLAN_CONSUMER, contractException.getErrorType()); + } + + @Test + @UnitTestConstructor(target = ConsumerDataManagerPlan.class, args = { double.class, boolean.class, Consumer.class }) + public void testConstructor_Active() { + //precondition test: if the consumer is null + ContractException contractException = assertThrows(ContractException.class, () -> { + new ConsumerDataManagerPlan(0, true, null); + }); + assertEquals(NucleusError.NULL_PLAN_CONSUMER, contractException.getErrorType()); + } + + @Test + @UnitTestConstructor(target = ConsumerDataManagerPlan.class, args = { double.class, boolean.class, long.class, + Consumer.class }) + public void testConstructor_Active_Arrival() { + //precondition test: if the consumer is null + ContractException contractException = assertThrows(ContractException.class, () -> { + new ConsumerDataManagerPlan(0, true,34534L, null); + }); + assertEquals(NucleusError.NULL_PLAN_CONSUMER, contractException.getErrorType()); + } +} diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ConsumerReportPlan.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ConsumerReportPlan.java new file mode 100644 index 000000000..8cea57156 --- /dev/null +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ConsumerReportPlan.java @@ -0,0 +1,34 @@ +package gov.hhs.aspr.ms.gcm.simulation.nucleus; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.util.function.Consumer; + +import org.junit.jupiter.api.Test; + +import gov.hhs.aspr.ms.util.annotations.UnitTestConstructor; +import gov.hhs.aspr.ms.util.errors.ContractException; + +public class AT_ConsumerReportPlan { + + @Test + @UnitTestConstructor(target = ConsumerReportPlan.class, args = { double.class, Consumer.class }) + public void testConstructor() { + //precondition test: if the consumer is null + ContractException contractException = assertThrows(ContractException.class, () -> { + new ConsumerReportPlan(0, null); + }); + assertEquals(NucleusError.NULL_PLAN_CONSUMER, contractException.getErrorType()); + } + + @Test + @UnitTestConstructor(target = ConsumerReportPlan.class, args = { double.class, long.class, Consumer.class }) + public void testConstructor_Arrival() { + //precondition test: if the consumer is null + ContractException contractException = assertThrows(ContractException.class, () -> { + new ConsumerReportPlan(0,3453L, null); + }); + assertEquals(NucleusError.NULL_PLAN_CONSUMER, contractException.getErrorType()); + } +} diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_DataManagerContext.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_DataManagerContext.java index 2ec03fff6..1f6c824f4 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_DataManagerContext.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_DataManagerContext.java @@ -324,7 +324,7 @@ public void testAddPlan_Plan() { pluginDataBuilder.addTestDataManagerPlan("dm", new TestDataManagerPlan(4, (context) -> { // schedule two passive plans - context.addPlan(new DataManagerPlan(5, (c) -> { + context.addPlan(new ConsumerDataManagerPlan(5, (c) -> { planExecuted.setValue(true); })); })); @@ -363,7 +363,7 @@ public void testAddPlan_Plan() { .addPlugin(TestPlugin.getTestPlugin(TestPluginData.builder()// .addTestDataManager("dm", () -> new TestDataManager1()) .addTestDataManagerPlan("dm", new TestDataManagerPlan(0, (c) -> { - c.addPlan(new DataManagerPlan(0, true, -2, (c2) -> { + c.addPlan(new ConsumerDataManagerPlan(0, true, -2, (c2) -> { })); })).build()))// .build()// @@ -377,7 +377,7 @@ public void testAddPlan_Plan() { .addPlugin(TestPlugin.getTestPlugin(TestPluginData.builder()// .addTestDataManager("dm", () -> new TestDataManager1()) .addTestDataManagerPlan("dm", new TestDataManagerPlan(0, (c) -> { - c.addPlan(new DataManagerPlan(-10, true, -1, (c2) -> { + c.addPlan(new ConsumerDataManagerPlan(-10, true, -1, (c2) -> { })); })).build()))// .build()// @@ -393,7 +393,7 @@ public void testAddPlan_Plan() { .addTestDataManager("dm", () -> new TestDataManager1()) .addTestDataManagerPlan("dm", new TestDataManagerPlan(0, (c) -> { c.subscribeToSimulationClose(c2 -> { - c2.addPlan(new DataManagerPlan(0, true, -1, (c3) -> { + c2.addPlan(new ConsumerDataManagerPlan(0, true, -1, (c3) -> { })); }); })).build()))// @@ -1110,7 +1110,7 @@ public void testRetrievePlans() { double haltTime = 50; for (int i = 1; i <= 100; i++) { - DataManagerPlan actorPlan = new DataManagerPlan(i, (c) -> { + DataManagerPlan actorPlan = new ConsumerDataManagerPlan(i, (c) -> { }); if (i > 50) { expectedPlans.add(actorPlan); diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_DataManagerPlan.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_DataManagerPlan.java index 3ec9258cc..285a6aa10 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_DataManagerPlan.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_DataManagerPlan.java @@ -1,46 +1,26 @@ package gov.hhs.aspr.ms.gcm.simulation.nucleus; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import java.util.function.Consumer; - import org.junit.jupiter.api.Test; import gov.hhs.aspr.ms.util.annotations.UnitTestConstructor; public class AT_DataManagerPlan { - - @Test - @UnitTestConstructor(target = DataManagerPlan.class, args = { double.class, Consumer.class }) - public void testConstructor() { - for (int i = 0; i < 10; i++) { - DataManagerPlan dataManagerPlan = new DataManagerPlan(i, (c) -> { - }); - - assertNotNull(dataManagerPlan); - } - } - - @Test - @UnitTestConstructor(target = DataManagerPlan.class, args = { double.class, boolean.class, Consumer.class }) - public void testConstructor_Active() { - for (int i = 0; i < 10; i++) { - DataManagerPlan dataManagerPlan = new DataManagerPlan(i, i % 2 == 0, (c) -> { - }); - - assertNotNull(dataManagerPlan); - } - } - - @Test - @UnitTestConstructor(target = DataManagerPlan.class, args = { double.class, boolean.class, long.class, - Consumer.class }) - public void testConstructor_Active_Arrival() { - for (int i = 0; i < 10; i++) { - DataManagerPlan dataManagerPlan = new DataManagerPlan(i, i % 2 == 0, (long) i, (c) -> { - }); - assertNotNull(dataManagerPlan); - } - } + @Test + @UnitTestConstructor(target = DataManagerPlan.class, args = { double.class }) + public void testConstructor() { + // nothing to test + } + + @Test + @UnitTestConstructor(target = DataManagerPlan.class, args = { double.class, boolean.class }) + public void testConstructor_Active() { + // nothing to test + } + + @Test + @UnitTestConstructor(target = DataManagerPlan.class, args = { double.class, boolean.class, long.class }) + public void testConstructor_Active_Arrival() { + // nothing to test + } } diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ReportContext.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ReportContext.java index 726821362..6551a2ae2 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ReportContext.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ReportContext.java @@ -145,7 +145,7 @@ public void testAddPlan_Consumer() { // precondition test : if the plan is added to the simulation after event processing is finished contractException = assertThrows(ContractException.class, () -> testConsumer((c) -> { - c.addPlan(new ReportPlan(0, (c1) -> { + c.addPlan(new ConsumerReportPlan(0, (c1) -> { c1.subscribeToSimulationClose((c2->{ c2.addPlan(c3->{},0); })); @@ -178,20 +178,20 @@ public void testAddPlan_Plan() { pluginDataBuilder.addTestReportPlan("actor", new TestReportPlan(4, (context) -> { // schedule two passive plans - context.addPlan(new ReportPlan(5, (c) -> { + context.addPlan(new ConsumerReportPlan(5, (c) -> { actualOuput.add("A"); })); - context.addPlan(new ReportPlan(6, (c) -> { + context.addPlan(new ConsumerReportPlan(6, (c) -> { actualOuput.add("B"); })); // schedule two more passive plans - context.addPlan(new ReportPlan(8, (c) -> { + context.addPlan(new ConsumerReportPlan(8, (c) -> { actualOuput.add("C"); }));// - context.addPlan(new ReportPlan(9, (c) -> { + context.addPlan(new ConsumerReportPlan(9, (c) -> { actualOuput.add("D"); })); })); @@ -223,23 +223,23 @@ public void testAddPlan_Plan() { // precondition test : if the plan is scheduled for the past contractException = assertThrows(ContractException.class, () -> testConsumer((c) -> { - c.addPlan(new ReportPlan(-1, (c1) -> { + c.addPlan(new ConsumerReportPlan(-1, (c1) -> { })); })); assertEquals(NucleusError.PAST_PLANNING_TIME, contractException.getErrorType()); // precondition test : if the arrival id is less than -1 contractException = assertThrows(ContractException.class, () -> testConsumer((c) -> { - c.addPlan(new ReportPlan(0, -2, (c1) -> { + c.addPlan(new ConsumerReportPlan(0, -2, (c1) -> { })); })); assertEquals(NucleusError.INVALID_PLAN_ARRIVAL_ID, contractException.getErrorType()); // precondition test : if the plan is added to the simulation after event processing is finished contractException = assertThrows(ContractException.class, () -> testConsumer((c) -> { - c.addPlan(new ReportPlan(0, (c1) -> { + c.addPlan(new ConsumerReportPlan(0, (c1) -> { c1.subscribeToSimulationClose((c2->{ - c2.addPlan(new ReportPlan(0,(c3->{}))); + c2.addPlan(new ConsumerReportPlan(0,(c3->{}))); })); })); })); @@ -738,7 +738,7 @@ public void testRetrievePlans() { double haltTime = 50; for (int i = 1; i <= 100; i++) { - ReportPlan actorPlan = new ReportPlan(i, (c) -> { + ReportPlan actorPlan = new ConsumerReportPlan(i, (c) -> { }); if (i > 50) { expectedPlans.add(actorPlan); diff --git a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ReportPlan.java b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ReportPlan.java index cf1d22038..adf446eda 100644 --- a/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ReportPlan.java +++ b/simulation/src/test/java/gov/hhs/aspr/ms/gcm/simulation/nucleus/AT_ReportPlan.java @@ -1,9 +1,5 @@ package gov.hhs.aspr.ms.gcm.simulation.nucleus; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import java.util.function.Consumer; - import org.junit.jupiter.api.Test; import gov.hhs.aspr.ms.util.annotations.UnitTestConstructor; @@ -11,24 +7,14 @@ public class AT_ReportPlan { @Test - @UnitTestConstructor(target = ReportPlan.class, args = { double.class, Consumer.class }) + @UnitTestConstructor(target = ReportPlan.class, args = { double.class}) public void testConstructor() { - for (int i = 0; i < 10; i++) { - ReportPlan reportPlan = new ReportPlan(i, (c) -> { - }); - - assertNotNull(reportPlan); - } + //nothing to test } @Test - @UnitTestConstructor(target = ReportPlan.class, args = { double.class, long.class, Consumer.class }) + @UnitTestConstructor(target = ReportPlan.class, args = { double.class, long.class}) public void testConstructor_Arrival() { - for (int i = 0; i < 10; i++) { - ReportPlan reportPlan = new ReportPlan(i, (long) i, (c) -> { - }); - - assertNotNull(reportPlan); - } + //nothing to test } }