Commit 1a6f0322 authored by Sumaiyya Burney's avatar Sumaiyya Burney

Fixes delete and update tests

parent 2fd1bc10
...@@ -36,6 +36,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; ...@@ -36,6 +36,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import java.util.Random;
import java.util.UUID; import java.util.UUID;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
...@@ -90,7 +91,8 @@ class ProductControllerTest { ...@@ -90,7 +91,8 @@ class ProductControllerTest {
.expectBodyList(Product.class) .expectBodyList(Product.class)
.consumeWith(product ->{ .consumeWith(product ->{
List<Product> products = product.getResponseBody(); List<Product> products = product.getResponseBody();
products.forEach( p ->{ assert products != null;
products.forEach(p ->{
assertNotNull(p.getSku()); assertNotNull(p.getSku());
assertNotNull(p.getUpc()); assertNotNull(p.getUpc());
System.out.println("Product SKU: " + p.getSku()); System.out.println("Product SKU: " + p.getSku());
...@@ -115,14 +117,42 @@ class ProductControllerTest { ...@@ -115,14 +117,42 @@ class ProductControllerTest {
*/ */
@Test @Test
public void testDeleteProduct(){ public void testDeleteProduct(){
String sku = "SH=1123"; Product deleteLater = new Product("SH=1123", "3d2dsd9cm", "Blue Sweater", "A nice red sweater", 23.99f, 45,
webTestClient.delete().uri("/api/products".concat("/{sku}"),sku) "", "SweatCo", "Sweatshirts");
webTestClient.get()
.uri("/api/products".concat("/{productSku}"), deleteLater.getSku())
.exchange()
.expectStatus().isNotFound();
webTestClient.post()
.uri("/api/products")
.contentType(MediaType.valueOf(MediaType.APPLICATION_JSON_VALUE))
.body(Mono.just(deleteLater), Product.class)
.exchange()
.expectStatus().isOk()
.expectBody(Product.class);
webTestClient.delete()
.uri("/api/products".concat("/{productSku}"), deleteLater.getSku())
.accept(MediaType.valueOf(MediaType.APPLICATION_JSON_VALUE)) .accept(MediaType.valueOf(MediaType.APPLICATION_JSON_VALUE))
.exchange() .exchange()
.expectStatus().isOk() .expectStatus().isOk()
.expectBody(Void.class); .expectBody(Void.class);
System.out.println("Deletion Successful. Ending test..."); webTestClient.get()
.uri("/api/products".concat("/{productSku}"), deleteLater.getSku())
.exchange()
.expectStatus().isNotFound();
// String sku = "SH=1123";
// webTestClient.delete().uri("/api/products".concat("/{sku}"),sku)
// .accept(MediaType.valueOf(MediaType.APPLICATION_JSON_VALUE))
// .exchange()
// .expectStatus().isOk()
// .expectBody(Void.class);
//
// System.out.println("Deletion Successful. Ending test...");
} }
@Test @Test
...@@ -142,10 +172,11 @@ class ProductControllerTest { ...@@ -142,10 +172,11 @@ class ProductControllerTest {
@Test @Test
public void updateProduct(){ public void updateProduct(){
double newPrice = 49.99; Random rd = new Random();
String sku = "SH=1123"; float newPrice = rd.nextFloat()*100;
String sku = "SKU-PUT";
Product product = new Product(sku, "3d2dsd9cm", "Blue Sweater", Product product = new Product(sku, "3d2dsd9cm", "Blue Sweater",
"A Nice red sweater", (float) newPrice, 45, "", "A Nice red sweater", newPrice, 45, "",
"SweatCo", "Sweatshirts"); "SweatCo", "Sweatshirts");
webTestClient.put().uri("/api/products".concat("/{sku}"),sku) webTestClient.put().uri("/api/products".concat("/{sku}"),sku)
.contentType(MediaType.valueOf(MediaType.APPLICATION_JSON_VALUE)) .contentType(MediaType.valueOf(MediaType.APPLICATION_JSON_VALUE))
...@@ -162,7 +193,7 @@ class ProductControllerTest { ...@@ -162,7 +193,7 @@ class ProductControllerTest {
double newPrice = 49.99; double newPrice = 49.99;
String sku = "SH=2021"; String sku = "SH=2021";
Product product = new Product(sku, "3d2dsd9cm", "Blue Sweater", Product product = new Product(sku, "3d2dsd9cm", "Blue Sweater",
"A Nice red sweater", (float) 23.99, 45, "", "A Nice red sweater", 23.99f, 45, "",
"SweatCo", "Sweatshirts"); "SweatCo", "Sweatshirts");
webTestClient.put().uri("/api/products".concat("/{sku}"),sku) webTestClient.put().uri("/api/products".concat("/{sku}"),sku)
.contentType(MediaType.valueOf(MediaType.APPLICATION_JSON_VALUE)) .contentType(MediaType.valueOf(MediaType.APPLICATION_JSON_VALUE))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment