SpringCloud Contract etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
SpringCloud Contract etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

18 Eylül 2023 Pazartesi

SpringCloud Contract WireMock

Giriş
SpringCloud Contract WireMock kullanmaya gerek var mı bilmiyor. Çünkü karışık. Bunun yerine Java koduyla test REST uçları açmak daha kolay olabilir

Maven
Şu satırı dahil ederiz
<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-contract-wiremock</artifactId>
   <version>4.0.4</version>
</dependency>
Örnek
Şöyle yaparız
import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock;

@SpringBootApplication
@AutoConfigureWireMock()
public class SpringStubServerApplication {

  public static void main(String[] args) {
    SpringApplication.run(SpringStubServerApplication.class, args);
  }
}
Açıklaması şöyle
We need to add the AutoConfigureWireMock annotation to start a WireMock server in the context of the Spring application. This will bind the port, HTTPS port, and stub files and locations of the WireMock server when the Spring Boot application is started.
application.yaml şöyledir
spring:
  application:
    name: wiremock-service
  main:
    web-application-type: none

wiremock:
  server:
    files: classpath:/__files
    stubs: classpath:/mappings

logging:
  level:
    org.springframework.cloud.contract.wiremock: debug
    org.springframework.web.client: debug
    com.github.tomakehurst.wiremock: trace
files ile cevap olarak gönderilecek JSON dosyaları tanımlanır
stubs ile REST noktaları tanımlanır

 


15 Kasım 2020 Pazar

SpringCloud Contract

Giriş
Mikroservis mimarisine geçtikçe, test mantığı da değişmeye başlıyor. Bazı notlarım şöyle

Contract Testing Nedir?
Açıklaması şöyle. Mikroservis mimarisinde monolitik uygulamadaki gibi uçtan uca (end-to-end) test yapılamadığı için mikroservisi tek başına test etme yoluna gidiliyor.
It is a technique that allows us to test the integration of several applications, verifying in each one of them that the messages sent or received (depending on their role consumer/producer) conform to an agreement that is documented in a contract.
Mikroservisi test ederken, testlere hem consumer, hem de producer açısından bakabiliriz. Yani
Consumer-Driven Contract Testing
Producer-Driven Contract Testing
yapabiliriz. Bu iki yöntemin testleri de biraz farklı oluyor. Farkların açıklaması şöyle
- In the consumer, we will have tests where the requests will be made to a “stub” of the producer which will comply with the defined agreement.
- In the producer, we will have tests where requests based on the defined agreement will be made.
Pact JVM
Bir örnek burada

Spring Cloud Contract Nedir?
Açıklaması şöyle
Spring Cloud Contract is an umbrella project holding solutions that help users in successfully implementing the Consumer Driven Contracts approach. Currently Spring Cloud Contract consists of the Spring Cloud Contract Verifier project.