Skip to content

Commit

Permalink
modify plan derivation group test
Browse files Browse the repository at this point in the history
  • Loading branch information
pranav-super committed Oct 21, 2024
1 parent 17c2cd5 commit 26ab129
Showing 1 changed file with 98 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import java.io.IOException;
import java.sql.Connection;
import java.sql.Date;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -69,6 +70,7 @@ protected record ExternalEvent(String key, String event_type_name, String source
}
protected record ExternalSource(String key, String source_type_name, String derivation_group_name, String valid_at, String start_time, String end_time, String created_at){}
protected record DerivedEvent(String key, String event_type_name, String source_key, String derivation_group_name, String start_time, String duration, String source_range, String valid_at){}
protected record PlanDerivationGroup(int plan_id, String derivation_group_name, boolean acknowledged){}
//endregion


Expand Down Expand Up @@ -2099,67 +2101,113 @@ void deleteEventTypeWithRemainingEvent() throws SQLException {
//endregion


//region Miscellaneous
//region Derivation Group Association Tests
/**
* This test ensures that a derivation group can be associated with a plan. This behavior is very simple and doesn't
* have many derivative cases besides merging of plans, and that behavior is handled in a test in
* PlanCollaborationTests.java.
* The following test Derivation Group/Plan Association behavior.
*/
@Test
void associateDerivationGroupWithBasePlan() throws SQLException {
// upload a mission model
final int fileId = merlinHelper.insertFileUpload();
final int missionModelId = merlinHelper.insertMissionModel(fileId);
@Nested
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class PlanDerivationGroupTests {
/**
* This test ensures that a derivation group can be associated with a plan, specifically checking that when the
* "acknowledged" field is set, "last_acknowledged_at" is updated, but no other derivation groups or plans
* (and their associations are affected)
*/
@Test
void associateDerivationGroupWithBasePlan() throws SQLException {
// upload a mission model
final int fileId = merlinHelper.insertFileUpload();
final int missionModelId = merlinHelper.insertMissionModel(fileId);

// upload derivation group A and B
String derivationGroupNameControl = "Control";
String derivationGroupNameDelta = "Delta";
upload_source(derivationGroupNameControl, false);
upload_source(derivationGroupNameDelta, true);

// create plan "control", as well as one that would face an update to an associated derivation group "delta"
final int planIdControl = merlinHelper.insertPlan(missionModelId, merlinHelper.user.name(), "control");
final int planIdDelta = merlinHelper.insertPlan(missionModelId, merlinHelper.user.name(), "delta");

// associate the two derivation groups with it
assertDoesNotThrow(() -> associateDerivationGroupWithPlan(planIdControl, derivationGroupNameControl));
assertDoesNotThrow(() -> associateDerivationGroupWithPlan(planIdDelta, derivationGroupNameControl));
assertDoesNotThrow(() -> associateDerivationGroupWithPlan(planIdDelta, derivationGroupNameDelta));

// check that acknowledged is true for all entries
try (final var statement = connection.createStatement()) {
// create the event type
var res = statement.executeQuery(
// language=sql
"""
SELECT * FROM merlin.plan_derivation_group;
"""
);

// upload derivation group A
String derivationGroupName = "A";
upload_source(derivationGroupName, false);
List<PlanDerivationGroup> results = new ArrayList<>();
while (res.next()) {
results.add(
new PlanDerivationGroup(
res.getInt("plan_id"),
res.getString("derivation_group_name"),
res.getBoolean("acknowledged")
)
);
}

// create plan "base"
final int parentPlanId = merlinHelper.insertPlan(missionModelId, merlinHelper.user.name(), "base");
List<PlanDerivationGroup> expectedResults = List.of(
new PlanDerivationGroup(planIdControl, derivationGroupNameControl, true),
new PlanDerivationGroup(planIdDelta, derivationGroupNameControl, true),
new PlanDerivationGroup(planIdDelta, derivationGroupNameDelta, true)
);

// associate the derivation group with it
assertDoesNotThrow(() -> associateDerivationGroupWithPlan(parentPlanId, derivationGroupName));
assertEquals(expectedResults.size(), results.size());
assertTrue(results.containsAll(expectedResults));
}

// check that acknowledged is true
try(final var statement = connection.createStatement()) {
// create the event type
var res = statement.executeQuery(
// language=sql
"""
SELECT * FROM merlin.plan_derivation_group;
"""
// insert a source to the changing derivation group
insertExternalSource(
new ExternalSource(
"A.json",
SOURCE_TYPE,
derivationGroupNameDelta,
"2024-01-19 00:00:01+00",
"2024-01-01 00:00:00+00",
"2024-01-07 00:00:00+00",
CREATED_AT
)
);

assertTrue(res.next());
assertTrue(res.getBoolean("acknowledged"));
}
// check that acknowledged is now false for all non control (delta only) entries, true otherwise
try (final var statement = connection.createStatement()) {
// create the event type
var res = statement.executeQuery(
// language=sql
"""
SELECT * FROM merlin.plan_derivation_group;
"""
);

// insert a source
insertExternalSource(
new ExternalSource(
"A.json",
SOURCE_TYPE,
derivationGroupName,
"2024-01-19 00:00:01+00",
"2024-01-01 00:00:00+00",
"2024-01-07 00:00:00+00",
CREATED_AT
)
);
List<PlanDerivationGroup> results = new ArrayList<>();
while (res.next()) {
results.add(
new PlanDerivationGroup(
res.getInt("plan_id"),
res.getString("derivation_group_name"),
res.getBoolean("acknowledged")
)
);
}

// check that acknowledged is now false
try(final var statement = connection.createStatement()) {
// create the event type
var res = statement.executeQuery(
// language=sql
"""
SELECT * FROM merlin.plan_derivation_group;
"""
);
List<PlanDerivationGroup> expectedResults = List.of(
new PlanDerivationGroup(planIdControl, derivationGroupNameControl, true),
new PlanDerivationGroup(planIdDelta, derivationGroupNameControl, true),
new PlanDerivationGroup(planIdDelta, derivationGroupNameDelta, false)
);

assertTrue(res.next());
assertFalse(res.getBoolean("acknowledged"));
assertEquals(expectedResults.size(), results.size());
assertTrue(results.containsAll(expectedResults));
}
}
}
//endregion
Expand Down

0 comments on commit 26ab129

Please sign in to comment.