Skip to content

Commit

Permalink
Dont run grpc consumer contract tests
Browse files Browse the repository at this point in the history
  • Loading branch information
edeandrea committed Jan 30, 2025
1 parent 50a9e6e commit d930f33
Showing 1 changed file with 64 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package io.quarkus.sample.superheroes.fight.service;

import static au.com.dius.pact.consumer.dsl.BuilderUtils.filePath;
import static au.com.dius.pact.consumer.dsl.LambdaDsl.newJsonBody;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.*;

import java.time.Duration;
import java.util.Map;
Expand All @@ -18,6 +14,7 @@
import jakarta.ws.rs.core.Response.Status;

import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;

Expand All @@ -38,7 +35,6 @@
import io.quarkus.sample.superheroes.fight.client.VillainClient;
import io.quarkus.sample.superheroes.fight.service.FightServiceConsumerContractTests.PactConsumerContractTestProfile;

import au.com.dius.pact.consumer.dsl.PactBuilder;
import au.com.dius.pact.consumer.dsl.PactDslRootValue;
import au.com.dius.pact.consumer.dsl.PactDslWithProvider;
import au.com.dius.pact.consumer.junit.MockServerConfig;
Expand Down Expand Up @@ -74,12 +70,12 @@
hostInterface = "localhost",
implementation = MockServerImplementation.JavaHttpServer
)
@MockServerConfig(
providerName = "grpc-locations",
port = FightServiceConsumerContractTests.LOCATION_MOCK_PORT,
implementation = MockServerImplementation.Plugin,
registryEntry = "protobuf/transport/grpc"
)
//@MockServerConfig(
// providerName = "grpc-locations",
// port = FightServiceConsumerContractTests.LOCATION_MOCK_PORT,
// implementation = MockServerImplementation.Plugin,
// registryEntry = "protobuf/transport/grpc"
//)
@DisabledIfSystemProperty(named = "quarkus.native.enabled", matches = "true", disabledReason = "Not sure why, but when native profile is active some of these tests fail")
@DisabledIfSystemProperty(named = "isNightlyEcosystemTest", matches = "true", disabledReason = "Nightly Ecosystem tests sometimes cause flaky failures")
public class FightServiceConsumerContractTests extends FightServiceTestsBase {
Expand Down Expand Up @@ -286,59 +282,59 @@ public V4Pact generateImageFromNarrationPact(PactDslWithProvider builder) {
.toPact(V4Pact.class);
}

@Pact(consumer = "rest-fights", provider = "grpc-locations")
public V4Pact helloLocationsPact(PactBuilder builder) {
return builder
.usingPlugin("protobuf")
.expectsToReceive("A hello request", "core/interaction/synchronous-message")
.with(Map.of(
"pact:proto", filePath("src/main/proto/locationservice-v1.proto"),
"pact:content-type", "application/grpc",
"pact:proto-service", "Locations/Hello",
"request", Map.of(),
"response", Map.of(
"message", "matching(regex, '.+', '%s')".formatted(DEFAULT_HELLO_LOCATION_RESPONSE)
)
))
.toPact();
}

@Pact(consumer = "rest-fights", provider = "grpc-locations")
public V4Pact randomLocationFoundPact(PactBuilder builder) {
return builder
.usingPlugin("protobuf")
.expectsToReceive("A request for a random location", "core/interaction/synchronous-message")
.with(Map.of(
"pact:proto", filePath("src/main/proto/locationservice-v1.proto"),
"pact:content-type", "application/grpc",
"pact:proto-service", "Locations/GetRandomLocation",
"request", Map.of(),
"response", Map.of(
"name", "matching(regex, '.+', '%s')".formatted(DEFAULT_LOCATION_NAME),
"picture", "matching(regex, '((http|https):\\/\\/).+', '%s')".formatted(DEFAULT_LOCATION_PICTURE)
)
))
.toPact();
}

@Pact(consumer = "rest-fights", provider = "grpc-locations")
public V4Pact randomLocationNotFoundPact(PactBuilder builder) {
return builder
.usingPlugin("protobuf")
.given("No random location found")
.expectsToReceive("A request for a random location", "core/interaction/synchronous-message")
.with(Map.of(
"pact:proto", filePath("src/main/proto/locationservice-v1.proto"),
"pact:content-type", "application/grpc",
"pact:proto-service", "Locations/GetRandomLocation",
"request", Map.of(),
"responseMetadata", Map.of(
"grpc-status", io.grpc.Status.NOT_FOUND.getCode().name(),
"grpc-message", "A location was not found"
)
))
.toPact();
}
// @Pact(consumer = "rest-fights", provider = "grpc-locations")
// public V4Pact helloLocationsPact(PactBuilder builder) {
// return builder
// .usingPlugin("protobuf")
// .expectsToReceive("A hello request", "core/interaction/synchronous-message")
// .with(Map.of(
// "pact:proto", filePath("src/main/proto/locationservice-v1.proto"),
// "pact:content-type", "application/grpc",
// "pact:proto-service", "Locations/Hello",
// "request", Map.of(),
// "response", Map.of(
// "message", "matching(regex, '.+', '%s')".formatted(DEFAULT_HELLO_LOCATION_RESPONSE)
// )
// ))
// .toPact();
// }
//
// @Pact(consumer = "rest-fights", provider = "grpc-locations")
// public V4Pact randomLocationFoundPact(PactBuilder builder) {
// return builder
// .usingPlugin("protobuf")
// .expectsToReceive("A request for a random location", "core/interaction/synchronous-message")
// .with(Map.of(
// "pact:proto", filePath("src/main/proto/locationservice-v1.proto"),
// "pact:content-type", "application/grpc",
// "pact:proto-service", "Locations/GetRandomLocation",
// "request", Map.of(),
// "response", Map.of(
// "name", "matching(regex, '.+', '%s')".formatted(DEFAULT_LOCATION_NAME),
// "picture", "matching(regex, '((http|https):\\/\\/).+', '%s')".formatted(DEFAULT_LOCATION_PICTURE)
// )
// ))
// .toPact();
// }
//
// @Pact(consumer = "rest-fights", provider = "grpc-locations")
// public V4Pact randomLocationNotFoundPact(PactBuilder builder) {
// return builder
// .usingPlugin("protobuf")
// .given("No random location found")
// .expectsToReceive("A request for a random location", "core/interaction/synchronous-message")
// .with(Map.of(
// "pact:proto", filePath("src/main/proto/locationservice-v1.proto"),
// "pact:content-type", "application/grpc",
// "pact:proto-service", "Locations/GetRandomLocation",
// "request", Map.of(),
// "responseMetadata", Map.of(
// "grpc-status", io.grpc.Status.NOT_FOUND.getCode().name(),
// "grpc-message", "A location was not found"
// )
// ))
// .toPact();
// }

@Test
@PactTestFor(pactMethods = { "randomHeroNotFoundPact", "randomVillainNotFoundPact" })
Expand Down Expand Up @@ -552,6 +548,7 @@ void generateImageFromNarrationSuccess() {

@Test
@PactTestFor(pactMethods = "helloLocationsPact", providerType = ProviderType.SYNCH_MESSAGE)
@Disabled("Seems to be flaky")
void helloLocationsSuccess() {
var message = this.fightService.helloLocations()
.subscribe().withSubscriber(UniAssertSubscriber.create())
Expand All @@ -568,6 +565,7 @@ void helloLocationsSuccess() {

@Test
@PactTestFor(pactMethods = "randomLocationFoundPact", providerType = ProviderType.SYNCH_MESSAGE)
@Disabled("Seems to be flaky")
void findRandomLocationSuccess() {
var location = this.fightService.findRandomLocation()
.subscribe().withSubscriber(UniAssertSubscriber.create())
Expand All @@ -587,6 +585,7 @@ void findRandomLocationSuccess() {

@Test
@PactTestFor(pactMethods = "randomLocationNotFoundPact", providerType = ProviderType.SYNCH_MESSAGE)
@Disabled("Seems to be flaky")
void findRandomLocationNoLocationFound() {
var location = this.fightService.findRandomLocation()
.subscribe().withSubscriber(UniAssertSubscriber.create())
Expand Down

0 comments on commit d930f33

Please sign in to comment.