Skip to content

Commit

Permalink
Update DB Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mythicaeda committed Feb 13, 2024
1 parent 6fb2e12 commit 514f089
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,17 @@ void assignPreset(int presetId, int activityId, int planId, String userSession)
}
}

void unassignPreset(int presetId, int activityId, int planId) throws SQLException {
try(final var statement = connection.createStatement()){
statement.execute(
//language=sql
"""
delete from preset_to_directive
where (preset_id, activity_id, plan_id) = (%d, %d, %d);
""".formatted(presetId, activityId, planId));
}
}


int insertConstraintPlan(int plan_id, String name, String definition, User user) throws SQLException {
try(final var statement = connection.createStatement()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2983,11 +2983,11 @@ void deleteActivityReanchorDoesNotImpactRelatedPlans() throws SQLException{
@Nested
class PresetTests{
private final gov.nasa.jpl.aerie.database.PresetTests presetTests = new gov.nasa.jpl.aerie.database.PresetTests();
{ presetTests.setConnection(helper);}

// Activities added in branches keep their preset information when merged
@Test
void presetPersistsWithAdd() throws SQLException{
presetTests.setConnection(helper);
merlinHelper.insertActivityType(missionModelId, "test-activity");
final int planId = merlinHelper.insertPlan(missionModelId);
final int branchId = duplicatePlan(planId, "Add Preset Branch");
Expand All @@ -3010,7 +3010,6 @@ void presetPersistsWithAdd() throws SQLException{
// The preset set in the supplying activity persists
@Test
void presetPersistsWithModify() throws SQLException{
presetTests.setConnection(helper);
merlinHelper.insertActivityType(missionModelId, "test-activity");
final int planId = merlinHelper.insertPlan(missionModelId);
final int activityId = merlinHelper.insertActivity(planId);
Expand All @@ -3033,7 +3032,6 @@ void presetPersistsWithModify() throws SQLException{
// If the preset used in a snapshot is deleted during the merge, the activity does not have a preset after the merge.
@Test
void postMergeNoPresetIfPresetDeleted() throws SQLException{
presetTests.setConnection(helper);
merlinHelper.insertActivityType(missionModelId, "test-activity");
final int planId = merlinHelper.insertPlan(missionModelId);
final int branchId = duplicatePlan(planId, "Delete Preset Branch");
Expand All @@ -3053,6 +3051,61 @@ void postMergeNoPresetIfPresetDeleted() throws SQLException{
assertNull(presetTests.getPresetAssignedToActivity(activityId, planId));
assertNull(presetTests.getPresetAssignedToActivity(activityId, branchId));
}

// Presets set in prior snapshots don't affect the merge
@Test
void presetOnlyPullsFromSourceSnapshot() throws SQLException {
merlinHelper.insertActivityType(missionModelId, "test-activity");
final int presetId = merlinHelper.insertPreset(missionModelId, "Demo Preset", "test-activity");

// Create a manual snapshot with a preset
final int planId = merlinHelper.insertPlan(missionModelId);
final int activityId = merlinHelper.insertActivity(planId);
merlinHelper.assignPreset(presetId, activityId, planId, merlinHelper.admin.session());
createSnapshot(planId);

// Remove preset from plan before branching
merlinHelper.unassignPreset(presetId, activityId, planId);
final int branchId = duplicatePlan(planId, "Delete Preset Branch");
updateActivityName("new name", activityId, branchId);

// Merge
final int mergeRQId = createMergeRequest(planId, branchId);
beginMerge(mergeRQId);
commitMerge(mergeRQId);

// Assertions
assertNull(presetTests.getPresetAssignedToActivity(activityId, planId));
assertNull(presetTests.getPresetAssignedToActivity(activityId, branchId));
}

@Test
void presetUnaffectedByUnrelatedSnapshot() throws SQLException {
merlinHelper.insertActivityType(missionModelId, "test-activity");
final int presetId = merlinHelper.insertPreset(missionModelId, "Demo Preset", "test-activity");

// Create a snapshot of an unrelated plan with a preset set
final int unrelatedPlanId = merlinHelper.insertPlan(missionModelId);
final int unrelatedActivityId = merlinHelper.insertActivity(unrelatedPlanId);
merlinHelper.assignPreset(presetId, unrelatedActivityId, unrelatedPlanId, merlinHelper.admin.session());
createSnapshot(unrelatedPlanId);

// Setup working plan
final int planId = merlinHelper.insertPlan(missionModelId);
final int activityId = merlinHelper.insertActivity(planId);
final int branchId = duplicatePlan(planId, "Delete Preset Branch");
updateActivityName("new name", activityId, branchId);

// Merge
final int mergeRQId = createMergeRequest(planId, branchId);
beginMerge(mergeRQId);
commitMerge(mergeRQId);

// Assertions
assertNull(presetTests.getPresetAssignedToActivity(activityId, planId));
assertNull(presetTests.getPresetAssignedToActivity(activityId, branchId));
assertEquals(presetId, presetTests.getPresetAssignedToActivity(unrelatedActivityId, unrelatedPlanId).id());
}
}

@Nested
Expand Down

0 comments on commit 514f089

Please sign in to comment.