Search in sources :

Example 1 with Product

use of com.wooyoo.learning.dao.domain.Product in project spring-boot-mybatis-with-redis by Lovelcp.

the class SpringBootMybatisWithRedisApplicationTests method test.

@Test
public void test() {
    long productId = 1;
    Product product = restTemplate.getForObject("http://localhost:" + port + "/product/" + productId, Product.class);
    assertThat(product.getPrice()).isEqualTo(200);
    Product newProduct = new Product();
    long newPrice = new Random().nextLong();
    newProduct.setName("new name");
    newProduct.setPrice(newPrice);
    restTemplate.put("http://localhost:" + port + "/product/" + productId, newProduct);
    Product testProduct = restTemplate.getForObject("http://localhost:" + port + "/product/" + productId, Product.class);
    assertThat(testProduct.getPrice()).isEqualTo(newPrice);
}
Also used : Random(java.util.Random) Product(com.wooyoo.learning.dao.domain.Product) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 2 with Product

use of com.wooyoo.learning.dao.domain.Product in project spring-boot-mybatis-with-redis by Lovelcp.

the class ProductController method updateProductInfo.

@PutMapping("/{id}")
public Product updateProductInfo(@PathVariable("id") Long productId, @RequestBody Product newProduct) {
    Product product = productMapper.select(productId);
    if (product == null) {
        throw new ProductNotFoundException(productId);
    }
    product.setName(newProduct.getName());
    product.setPrice(newProduct.getPrice());
    productMapper.update(product);
    return product;
}
Also used : Product(com.wooyoo.learning.dao.domain.Product) PutMapping(org.springframework.web.bind.annotation.PutMapping)

Aggregations

Product (com.wooyoo.learning.dao.domain.Product)2 Random (java.util.Random)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 PutMapping (org.springframework.web.bind.annotation.PutMapping)1