Skip to content

Commit

Permalink
change createSnapshotPao to createOrUpdatePao with type snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
raejohanek committed Jul 17, 2024
1 parent ee0940e commit 75e6cb3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package bio.terra.service.snapshot.flight;

import bio.terra.policy.model.TpsObjectType;
import bio.terra.policy.model.TpsPolicyInput;
import bio.terra.policy.model.TpsPolicyInputs;
import bio.terra.service.policy.PolicyService;
import bio.terra.service.policy.exception.PolicyConflictException;
import bio.terra.stairway.FlightContext;
import bio.terra.stairway.Step;
import bio.terra.stairway.StepResult;
Expand All @@ -30,11 +30,7 @@ public StepResult createPaoStep(FlightContext flightContext) throws InterruptedE
UUID snapshotId = getSnapshotId(flightContext);
TpsPolicyInput protectedDataPolicy = PolicyService.getProtectedDataPolicyInput();
TpsPolicyInputs policyInputs = new TpsPolicyInputs().addInputsItem(protectedDataPolicy);
try {
policyService.createSnapshotPao(snapshotId, policyInputs);
} catch (PolicyConflictException ex) {
logger.warn("Policy access object already exists for snapshot {}", snapshotId);
}
policyService.createOrUpdatePao(snapshotId, TpsObjectType.SNAPSHOT, policyInputs);
}
return StepResult.getStepResultSuccess();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

import bio.terra.common.category.Unit;
import bio.terra.policy.model.TpsObjectType;
import bio.terra.policy.model.TpsPolicyInput;
import bio.terra.policy.model.TpsPolicyInputs;
import bio.terra.service.policy.PolicyService;
import bio.terra.service.policy.exception.PolicyConflictException;
import bio.terra.service.snapshot.flight.create.CreateSnapshotPolicyStep;
import bio.terra.stairway.FlightContext;
import bio.terra.stairway.StepResult;
Expand Down Expand Up @@ -39,28 +38,18 @@ void testProtectedDataPolicyDoUndo() throws Exception {
CreateSnapshotPolicyStep step = new CreateSnapshotPolicyStep(policyService, true, SNAPSHOT_ID);
StepResult doResult = step.doStep(flightContext);
assertThat(doResult.getStepStatus(), equalTo(StepStatus.STEP_RESULT_SUCCESS));
verify(policyService).createSnapshotPao(SNAPSHOT_ID, policies);
verify(policyService).createOrUpdatePao(SNAPSHOT_ID, TpsObjectType.SNAPSHOT, policies);
StepResult undoResult = step.undoStep(flightContext);
assertThat(undoResult.getStepStatus(), equalTo(StepStatus.STEP_RESULT_SUCCESS));
verify(policyService).deletePaoIfExists(SNAPSHOT_ID);
}

@Test
void testProtectedDataPolicyAlreadyExists() throws Exception {
CreateSnapshotPolicyStep step = new CreateSnapshotPolicyStep(policyService, true, SNAPSHOT_ID);
var exception = new PolicyConflictException("Policy access object already exists");
doThrow(exception).when(policyService).createSnapshotPao(SNAPSHOT_ID, policies);
StepResult doResult = step.doStep(flightContext);
assertThat(doResult.getStepStatus(), equalTo(StepStatus.STEP_RESULT_SUCCESS));
verify(policyService).createSnapshotPao(SNAPSHOT_ID, policies);
}

@Test
void testNoPolicyDoUndo() throws Exception {
CreateSnapshotPolicyStep step = new CreateSnapshotPolicyStep(policyService, false, SNAPSHOT_ID);
StepResult doResult = step.doStep(flightContext);
assertThat(doResult.getStepStatus(), equalTo(StepStatus.STEP_RESULT_SUCCESS));
verify(policyService, never()).createSnapshotPao(SNAPSHOT_ID, policies);
verify(policyService, never()).createOrUpdatePao(SNAPSHOT_ID, TpsObjectType.SNAPSHOT, policies);
StepResult undoResult = step.undoStep(flightContext);
assertThat(undoResult.getStepStatus(), equalTo(StepStatus.STEP_RESULT_SUCCESS));
verify(policyService, never()).deletePaoIfExists(SNAPSHOT_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.mockito.Mockito.when;

import bio.terra.common.category.Unit;
import bio.terra.policy.model.TpsObjectType;
import bio.terra.policy.model.TpsPolicyInput;
import bio.terra.policy.model.TpsPolicyInputs;
import bio.terra.service.dataset.Dataset;
Expand Down Expand Up @@ -64,7 +65,7 @@ void testDeletePolicyDoUndo() throws Exception {

StepResult undoResult = step.undoStep(flightContext);
assertThat(undoResult.getStepStatus(), equalTo(StepStatus.STEP_RESULT_SUCCESS));
verify(policyService).createSnapshotPao(SNAPSHOT_ID, policies);
verify(policyService).createOrUpdatePao(SNAPSHOT_ID, TpsObjectType.SNAPSHOT, policies);
}

@Test
Expand Down

0 comments on commit 75e6cb3

Please sign in to comment.