Commit d205dffe authored by Khai Yuan ​Liew's avatar Khai Yuan ​Liew

[AFP-55] Modifiy GET controller test

parent dd26d3cf
...@@ -13,10 +13,16 @@ import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWeb ...@@ -13,10 +13,16 @@ import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWeb
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.web.reactive.function.client.WebClient;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ExtendWith(SpringExtension.class) @ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
...@@ -37,10 +43,11 @@ class ProductControllerTest { ...@@ -37,10 +43,11 @@ class ProductControllerTest {
void testFindAllProducts(){ void testFindAllProducts(){
webTestClient.get() webTestClient.get()
.uri("/api/products") .uri("/api/products")
.header(HttpHeaders.ACCEPT, "application/json")
.exchange() .exchange()
.expectStatus().isOk() .expectStatus().isOk()
.expectBodyList(Product.class); .expectHeader().contentType(MediaType.APPLICATION_JSON_VALUE)
.returnResult(Product.class)
.getResponseBody();
} }
......
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