package jnpf.elnService.impl;
|
|
import jnpf.base.ActionResult;
|
import jnpf.exception.DataException;
|
import jnpf.lims.api.TestWorkItemSnapshotApi;
|
import jnpf.lims.api.model.TestWorkItemRequestIdentityActorRequest;
|
import jnpf.lims.api.model.TestWorkItemRequestIdentityBatch;
|
import jnpf.lims.api.model.TestWorkItemRequestIdentity;
|
import jnpf.lims.api.model.TestWorkItemSnapshotActorRequest;
|
import jnpf.lims.api.model.TestWorkItemSnapshotBatch;
|
import jnpf.lims.api.model.TestWorkItemSnapshotRequest;
|
import org.junit.Test;
|
|
import java.util.Arrays;
|
import java.util.Map;
|
import java.util.concurrent.atomic.AtomicReference;
|
|
import static org.junit.Assert.assertEquals;
|
|
public class LimsTestRequestIdentityLookupAdapterTest {
|
|
@Test
|
public void mapsOnlySuccessfulStableIdentitiesAndKeepsTheTenantBoundary() {
|
AtomicReference<TestWorkItemRequestIdentityActorRequest> captured =
|
new AtomicReference<>();
|
TestWorkItemRequestIdentityBatch batch = new TestWorkItemRequestIdentityBatch();
|
batch.getItems().add(identity("item-1", "request-1", "SUCCESS"));
|
batch.getItems().add(identity("item-2", null, "NOT_FOUND"));
|
TestWorkItemSnapshotApi api = api(actor -> {
|
captured.set(actor);
|
return ActionResult.success("ok", batch);
|
});
|
|
Map<String, jnpf.elnService.ElnTestRequestIdentityLookup.Identity> result =
|
new LimsTestRequestIdentityLookupAdapter(api)
|
.resolve("tenant-a", Arrays.asList("item-1", "item-2"));
|
|
assertEquals("tenant-a", captured.get().getTenantId());
|
assertEquals(Arrays.asList("item-1", "item-2"),
|
captured.get().getRequest().getTestWorkItemIds());
|
assertEquals(1, result.size());
|
assertEquals("request-1", result.get("item-1").getTestRequestId());
|
assertEquals("pending_audit", result.get("item-1").getTaskStatus());
|
}
|
|
@Test(expected = DataException.class)
|
public void rejectsRemoteFailureInsteadOfReturningNoMatches() {
|
TestWorkItemSnapshotApi api = api(actor -> ActionResult.fail("identity unavailable"));
|
new LimsTestRequestIdentityLookupAdapter(api)
|
.resolve("tenant-a", Arrays.asList("item-1"));
|
}
|
|
@Test(expected = DataException.class)
|
public void reportsMissingStableIdentityInsteadOfConvertingItToNotFound() {
|
TestWorkItemRequestIdentityBatch batch = new TestWorkItemRequestIdentityBatch();
|
batch.getItems().add(identity("item-1", null, "TEST_REQUEST_INVALID"));
|
TestWorkItemSnapshotApi api = api(actor -> ActionResult.success("ok", batch));
|
new LimsTestRequestIdentityLookupAdapter(api)
|
.resolve("tenant-a", Arrays.asList("item-1"));
|
}
|
|
private static TestWorkItemRequestIdentity identity(
|
String itemId, String requestId, String outcome) {
|
TestWorkItemRequestIdentity item = new TestWorkItemRequestIdentity();
|
item.setTestWorkItemId(itemId);
|
item.setTestRequestId(requestId);
|
item.setTaskStatus("pending_audit");
|
item.setOutcomeCode(outcome);
|
return item;
|
}
|
|
private static TestWorkItemSnapshotApi api(IdentityResponder responder) {
|
return new TestWorkItemSnapshotApi() {
|
@Override
|
public ActionResult<TestWorkItemSnapshotBatch> snapshots(
|
TestWorkItemSnapshotRequest request) {
|
return ActionResult.fail("unused");
|
}
|
|
@Override
|
public ActionResult<TestWorkItemSnapshotBatch> snapshotsAsActor(
|
TestWorkItemSnapshotActorRequest request) {
|
return ActionResult.fail("unused");
|
}
|
|
@Override
|
public ActionResult<TestWorkItemRequestIdentityBatch> requestIdentitiesAsActor(
|
TestWorkItemRequestIdentityActorRequest request) {
|
return responder.respond(request);
|
}
|
};
|
}
|
|
@FunctionalInterface
|
private interface IdentityResponder {
|
ActionResult<TestWorkItemRequestIdentityBatch> respond(
|
TestWorkItemRequestIdentityActorRequest request);
|
}
|
}
|