이벤트 order 이벤트 핸들링
This commit is contained in:
@@ -19,21 +19,21 @@ public class ProductChanged extends AbstractEvent{
|
||||
private String productName;
|
||||
private int productPrice;
|
||||
|
||||
// private int productStock;
|
||||
// public int getProductStock() {
|
||||
// return productStock;
|
||||
// }
|
||||
// public void setProductStock(int productStock) {
|
||||
// this.productStock = productStock;
|
||||
// }
|
||||
private int productStock;
|
||||
public int getProductStock() {
|
||||
return productStock;
|
||||
}
|
||||
public void setProductStock(int productStock) {
|
||||
this.productStock = productStock;
|
||||
}
|
||||
|
||||
private int stock;
|
||||
public int getStock() {
|
||||
return stock;
|
||||
}
|
||||
public void setStock(int stock) {
|
||||
this.stock = stock;
|
||||
}
|
||||
// private int stock;
|
||||
// public int getStock() {
|
||||
// return stock;
|
||||
// }
|
||||
// public void setStock(int stock) {
|
||||
// this.stock = stock;
|
||||
// }
|
||||
|
||||
private String imageUrl;
|
||||
|
||||
@@ -48,8 +48,8 @@ public class ProductChanged extends AbstractEvent{
|
||||
this.setProductId(product.getId());
|
||||
this.setProductName(product.getName());
|
||||
this.setProductPrice(product.getPrice());
|
||||
// this.setProductStock(product.getStock());
|
||||
this.setStock(product.getStock());
|
||||
this.setProductStock(product.getStock());
|
||||
// this.setStock(product.getStock());
|
||||
this.setImageUrl(product.getImageUrl());
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,13 @@ public class ProductController {
|
||||
@Autowired
|
||||
ProductService productService;
|
||||
|
||||
// @GetMapping("/item/{productId}")
|
||||
// Product productStockCheck(@PathVariable(value = "productId") Long productId) {
|
||||
// return this.productService.getProductById(productId);
|
||||
// }
|
||||
|
||||
@GetMapping("/product/{productId}")
|
||||
Product productStockCheck(@PathVariable(value = "productId") Long productId) {
|
||||
Product productStockCheck1(@PathVariable(value = "productId") Long productId) {
|
||||
return this.productService.getProductById(productId);
|
||||
}
|
||||
}
|
||||
|
||||
53
src/test/resources/contracts/messaging/productChanged.groovy
Normal file
53
src/test/resources/contracts/messaging/productChanged.groovy
Normal file
@@ -0,0 +1,53 @@
|
||||
package contracts.messaging
|
||||
org.springframework.cloud.contract.spec.Contract.make {
|
||||
description("""
|
||||
spring contract 에서 메세지를 받는 방식은 총 3가지인데,
|
||||
1. input 은 없고 output만 있는 경우
|
||||
2. input 을 받아서 output 으로 보내는 경우
|
||||
3. input 만 있는 경우
|
||||
|
||||
input 에 triggeredBy method 를 호출하는 경우는 보통 input 메세지가 없는 경우이다.
|
||||
|
||||
```
|
||||
given:
|
||||
product changed event occurred
|
||||
when:
|
||||
he applies for a beer
|
||||
then:
|
||||
we'll send a message with a ProductChanged message
|
||||
```
|
||||
|
||||
""")
|
||||
// Label by means of which the output message can be triggered
|
||||
label 'productChanged'
|
||||
// input to the contract
|
||||
input {
|
||||
// the contract will be triggered by a method
|
||||
triggeredBy('productChanged()')
|
||||
}
|
||||
// output message of the contract
|
||||
outputMessage {
|
||||
// destination to which the output message will be sent
|
||||
sentTo 'eventTopic'
|
||||
// the body of the output message
|
||||
body(
|
||||
eventType: "ProductChanged",
|
||||
productId: 1,
|
||||
productName: "TV",
|
||||
productPrice: 10000,
|
||||
productStock: 10,
|
||||
imageUrl: "testUrl"
|
||||
)
|
||||
bodyMatchers {
|
||||
jsonPath('$.eventType', byRegex("ProductChanged"))
|
||||
jsonPath('$.productId', byRegex(nonEmpty()).asLong())
|
||||
jsonPath('$.productName', byRegex(nonEmpty()).asString())
|
||||
jsonPath('$.productPrice', byRegex(nonEmpty()).asLong())
|
||||
jsonPath('$.productStock', byRegex(nonEmpty()).asLong())
|
||||
jsonPath('$.imageUrl', byRegex(nonEmpty()).asString())
|
||||
}
|
||||
headers {
|
||||
messagingContentType(applicationJson())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package contracts.rest
|
||||
|
||||
org.springframework.cloud.contract.spec.Contract.make {
|
||||
request {
|
||||
method 'GET'
|
||||
url ('/product/1')
|
||||
headers {
|
||||
contentType(applicationJson())
|
||||
}
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body(
|
||||
id: 1,
|
||||
name: "TV",
|
||||
price: 10000,
|
||||
stock: 10,
|
||||
imageUrl: "testUrl"
|
||||
)
|
||||
bodyMatchers {
|
||||
jsonPath('$.id', byRegex(nonEmpty()).asLong())
|
||||
jsonPath('$.name', byRegex(nonEmpty()).asString())
|
||||
jsonPath('$.price', byRegex(nonEmpty()).asLong())
|
||||
jsonPath('$.stock', byRegex(nonEmpty()).asLong())
|
||||
jsonPath('$.imageUrl', byRegex(nonEmpty()).asString())
|
||||
}
|
||||
headers {
|
||||
contentType(applicationJson())
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user