Skip to content

Commit

Permalink
AJ-1451: More pacts with workspacemanager (#403)
Browse files Browse the repository at this point in the history
AJ-1451: More pacts with `workspacemanager`

Add additional contract coverage to `WsmPactTest` to cover interactions
with `workspacemanager`.
  • Loading branch information
jladieu authored Nov 13, 2023
1 parent 028bced commit d9d9099
Show file tree
Hide file tree
Showing 3 changed files with 373 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import bio.terra.workspace.model.ResourceAttributesUnion;
import bio.terra.workspace.model.ResourceDescription;
import bio.terra.workspace.model.ResourceList;
import com.google.common.annotations.VisibleForTesting;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
Expand Down Expand Up @@ -36,7 +37,8 @@ public TdrSnapshotSupport(
* @param pageSize how many references to return in each paginated request to WSM
* @return the list of unique ids for all pre-existing snapshot references
*/
protected List<UUID> existingPolicySnapshotIds(int pageSize) {
@VisibleForTesting
public List<UUID> existingPolicySnapshotIds(int pageSize) {
return extractSnapshotIds(listAllSnapshots(pageSize));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
import static org.junit.jupiter.api.Assertions.assertThrows;

import au.com.dius.pact.consumer.MockServer;
import au.com.dius.pact.consumer.dsl.PactDslJsonBody;
import au.com.dius.pact.consumer.dsl.PactDslWithProvider;
import au.com.dius.pact.consumer.junit5.PactConsumerTestExt;
import au.com.dius.pact.consumer.junit5.PactConsumerTest;
import au.com.dius.pact.consumer.junit5.PactTestFor;
import au.com.dius.pact.core.model.PactSpecVersion;
import au.com.dius.pact.core.model.RequestResponsePact;
Expand All @@ -21,29 +20,16 @@
import org.databiosphere.workspacedataservice.datarepo.DataRepoDao;
import org.databiosphere.workspacedataservice.datarepo.DataRepoException;
import org.databiosphere.workspacedataservice.datarepo.HttpDataRepoClientFactory;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

@Tag("pact-test")
@ExtendWith(PactConsumerTestExt.class)
class TDRPactTest {

@BeforeEach
void setUp() {
// Without this setup, the HttpClient throws a "No thread-bound request found" error
MockHttpServletRequest request = new MockHttpServletRequest();
// Set the mock request as the current request context
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
}

@PactConsumerTest
@PactTestFor(providerName = "datarepo", pactVersion = PactSpecVersion.V3)
class TdrPactTest {
static final UUID dummySnapshotId = UUID.fromString("12345678-abc9-012d-3456-e7fab89cd01e");

@Pact(consumer = "wds", provider = "datarepo")
@Pact(consumer = "wds")
public RequestResponsePact noSnapshotPact(PactDslWithProvider builder) {
return builder
.given("snapshot with given id doesn't exist", Map.of("id", dummySnapshotId.toString()))
Expand All @@ -56,7 +42,7 @@ public RequestResponsePact noSnapshotPact(PactDslWithProvider builder) {
.toPact();
}

@Pact(consumer = "wds", provider = "datarepo")
@Pact(consumer = "wds")
public RequestResponsePact noAccessToSnapshotPact(PactDslWithProvider builder) {
return builder
.given(
Expand All @@ -71,10 +57,8 @@ public RequestResponsePact noAccessToSnapshotPact(PactDslWithProvider builder) {
.toPact();
}

@Pact(consumer = "wds", provider = "datarepo")
@Pact(consumer = "wds")
public RequestResponsePact userHasAccessToSnapshotPact(PactDslWithProvider builder) {
var snapshotResponseShape =
new PactDslJsonBody().stringValue("id", dummySnapshotId.toString()).stringType("name");
return builder
.given(
"user has access to snapshot with given id", Map.of("id", dummySnapshotId.toString()))
Expand All @@ -101,7 +85,7 @@ public RequestResponsePact userHasAccessToSnapshotPact(PactDslWithProvider build
}

@Test
@PactTestFor(pactMethod = "noSnapshotPact", pactVersion = PactSpecVersion.V3)
@PactTestFor(pactMethod = "noSnapshotPact")
void testNoSnapshot(MockServer mockServer) {
DataRepoClientFactory clientFactory = new HttpDataRepoClientFactory(mockServer.getUrl());
DataRepoDao dataRepoDao = new DataRepoDao(clientFactory);
Expand All @@ -113,7 +97,7 @@ void testNoSnapshot(MockServer mockServer) {
}

@Test
@PactTestFor(pactMethod = "noAccessToSnapshotPact", pactVersion = PactSpecVersion.V3)
@PactTestFor(pactMethod = "noAccessToSnapshotPact")
void testNoAccessToSnapshot(MockServer mockServer) {
DataRepoClientFactory clientFactory = new HttpDataRepoClientFactory(mockServer.getUrl());
DataRepoDao dataRepoDao = new DataRepoDao(clientFactory);
Expand All @@ -125,7 +109,7 @@ void testNoAccessToSnapshot(MockServer mockServer) {
}

@Test
@PactTestFor(pactMethod = "userHasAccessToSnapshotPact", pactVersion = PactSpecVersion.V3)
@PactTestFor(pactMethod = "userHasAccessToSnapshotPact")
void testUserHasAccessToSnapshot(MockServer mockServer) {
DataRepoClientFactory clientFactory = new HttpDataRepoClientFactory(mockServer.getUrl());
DataRepoDao dataRepoDao = new DataRepoDao(clientFactory);
Expand Down
Loading

0 comments on commit d9d9099

Please sign in to comment.