-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made recommended changes from last pull request.
- Loading branch information
1 parent
2bf84ee
commit 5023e4c
Showing
4 changed files
with
79 additions
and
8 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
...rc/test/java/com/petclinic/bffapigateway/presentationlayer/v2/BillControllerUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.petclinic.bffapigateway.presentationlayer.v2; | ||
|
||
import com.petclinic.bffapigateway.domainclientlayer.BillServiceClient; | ||
import com.petclinic.bffapigateway.dtos.Bills.BillResponseDTO; | ||
import com.petclinic.bffapigateway.dtos.Bills.BillStatus; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient; | ||
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest; | ||
|
||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
import org.springframework.test.web.reactive.server.WebTestClient; | ||
import reactor.core.publisher.Flux; | ||
|
||
import java.time.LocalDate; | ||
|
||
import static org.mockito.Mockito.when; | ||
|
||
@RunWith(SpringRunner.class) | ||
@ContextConfiguration(classes = { | ||
BillController.class, | ||
BillServiceClient.class | ||
}) | ||
@WebFluxTest(controllers = BillController.class) | ||
@AutoConfigureWebTestClient | ||
public class BillControllerUnitTest { | ||
|
||
@Autowired | ||
private WebTestClient webTestClient; | ||
@MockBean | ||
private BillServiceClient billServiceClient; | ||
|
||
private final String baseBillURL = "/api/v2/gateway/bills"; | ||
|
||
private BillResponseDTO billresponse = BillResponseDTO.builder() | ||
.billId("e6c7398e-8ac4-4e10-9ee0-03ef33f0361a") | ||
.customerId("e6c7398e-8ac4-4e10-9ee0-03ef33f0361a") | ||
.visitType("general") | ||
.vetId("3") | ||
.date(LocalDate.parse("2024-10-11")) | ||
.amount(100.0) | ||
.taxedAmount(0.0) | ||
.billStatus(BillStatus.UNPAID) | ||
.dueDate(LocalDate.parse("2024-10-13")) | ||
.build(); | ||
|
||
private BillResponseDTO billresponse2 = BillResponseDTO.builder() | ||
.billId("e6c7398e-8ac4-4e10-9ee0-03ef33f0361b") | ||
.customerId("e6c7398e-8ac4-4e10-9ee0-03ef33f0361a") | ||
.visitType("general") | ||
.vetId("2") | ||
.date(LocalDate.parse("2024-10-11")) | ||
.amount(120.0) | ||
.taxedAmount(10.0) | ||
.billStatus(BillStatus.UNPAID) | ||
.dueDate(LocalDate.parse("2024-10-13")) | ||
.build(); | ||
|
||
|
||
@Test | ||
public void whenGetAllBillsByCustomerId_ThenReturnCustomerBills() { | ||
when(billServiceClient.getBillsByOwnerId("e6c7398e-8ac4-4e10-9ee0-03ef33f0361a")).thenReturn(Flux.just(billresponse, billresponse2)); | ||
webTestClient.get() | ||
.uri(baseBillURL + "/customer/{customerId}", "e6c7398e-8ac4-4e10-9ee0-03ef33f0361a") | ||
.exchange() | ||
.expectStatus().isOk() | ||
.expectBodyList(BillResponseDTO.class) | ||
.hasSize(2) | ||
.contains(billresponse, billresponse2); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters