Skip to content

Instantly share code, notes, and snippets.

@up1
Last active September 1, 2023 20:16
Show Gist options
  • Select an option

  • Save up1/579a527696a6ec0e86f08cd90dffd3d5 to your computer and use it in GitHub Desktop.

Select an option

Save up1/579a527696a6ec0e86f08cd90dffd3d5 to your computer and use it in GitHub Desktop.

Revisions

  1. up1 revised this gist Nov 18, 2021. 1 changed file with 15 additions and 0 deletions.
    15 changes: 15 additions & 0 deletions CustomerGatewayTest.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    @SpringBootTest(webEnvironment= WebEnvironment.NONE)
    @AutoConfigureStubRunner(ids = "com.example:provider:+:8081", stubsMode = StubRunnerProperties.StubsMode.LOCAL)
    public class CustomerGatewayTest {

    @Autowired
    private CustomerGateway gateway;

    @Test
    void getAllCustomers() {
    List<Customer> customers = this.gateway.getAllCustomers();
    BDDAssertions.then(customers).size().isEqualTo(2);
    BDDAssertions.then(customers.iterator().next().getId()).isEqualTo(1L);
    BDDAssertions.then(customers.iterator().next().getName()).isEqualTo("Test 01");
    }
    }
  2. up1 revised this gist Nov 18, 2021. 1 changed file with 17 additions and 0 deletions.
    17 changes: 17 additions & 0 deletions BaseTests.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    @SpringBootTest (classes = ProviderApplication.class)
    class BaseTests {

    @Autowired
    private CustomerRestController customerRestController;

    @MockBean
    private CustomerRepository customerRepository;

    @BeforeEach
    public void before() {
    when(this.customerRepository.findAll())
    .thenReturn(Arrays.asList(new Customer(1L, "Test 01"), new Customer(2L, "Test 02")));
    RestAssuredMockMvc.standaloneSetup(this.customerRestController);
    }

    }
  3. up1 created this gist Nov 18, 2021.
    18 changes: 18 additions & 0 deletions first-contract.groovy
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    import org.springframework.cloud.contract.spec.Contract
    import org.springframework.http.HttpHeaders
    import org.springframework.http.MediaType

    Contract.make {
    description "should return all customers"
    request {
    url "/customers"
    method GET()
    }
    response {
    status 200
    headers {
    header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
    }
    body([[id: 1L, name: "Test 01"], [id: 2L, name: "Test 02"]])
    }
    }