-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MODORDERS-852-Some unit tests are not executed (#824)
* TransactionSummariesServiceTest is fixed TagServiceTest Broken Function Committed FiscalYearServiceTest Broken Function Committed * MODORDERS-852-Some unit tests are not executed changes are made accordingly * MODORDERS-852-Some unit tests are not executed changes are made accordingly * Update ApiTestSuite.java * Update TagServiceTest.java * Update TransactionSummariesServiceTest.java * Update ApiTestSuite.java * Update FiscalYearServiceTest.java * MODORDERS-852-Some unit tests are not executed * MODORDERS-852-Some unit tests are not executed TransactionSummariesServiceTest is fixed TagServiceTest is fixed FiscalYearServiceTest is fixed * Update ApiTestSuite.java * MODORDERS-852-Some unit tests are not executed TransactionSummariesServiceTest is fixed TagServiceTest is fixed FiscalYearServiceTest is fixed * Changes after code review * [MODORDERS-852] - Made some improvements --------- Co-authored-by: Serhii Nosko <[email protected]> Co-authored-by: azizbekxm <[email protected]>
- Loading branch information
1 parent
9d8fc2f
commit caa4a85
Showing
5 changed files
with
94 additions
and
86 deletions.
There are no files selected for viewing
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
75 changes: 39 additions & 36 deletions
75
src/test/java/org/folio/service/finance/FiscalYearServiceTest.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 |
---|---|---|
@@ -1,75 +1,78 @@ | ||
package org.folio.service.finance; | ||
|
||
import static org.folio.TestConfig.mockPort; | ||
import static io.vertx.core.Future.failedFuture; | ||
import static io.vertx.core.Future.succeededFuture; | ||
import static org.folio.TestConstants.ID_DOES_NOT_EXIST; | ||
import static org.folio.TestConstants.X_OKAPI_TOKEN; | ||
import static org.folio.TestConstants.X_OKAPI_USER_ID; | ||
import static org.folio.rest.RestConstants.OKAPI_URL; | ||
import static org.folio.rest.RestVerticle.OKAPI_HEADER_TENANT; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.doReturn; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
import java.util.concurrent.CompletionException; | ||
|
||
import io.vertx.junit5.VertxTestContext; | ||
import org.folio.rest.core.models.RequestEntry; | ||
import org.folio.rest.core.RestClient; | ||
import io.vertx.junit5.VertxExtension; | ||
import org.folio.rest.acq.model.finance.FiscalYear; | ||
|
||
import org.folio.rest.core.exceptions.HttpException; | ||
import org.folio.rest.core.models.RequestContext; | ||
import org.folio.rest.tools.client.interfaces.HttpClientInterface; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import io.restassured.http.Header; | ||
import io.vertx.core.Context; | ||
import io.vertx.core.Future; | ||
import io.vertx.core.Vertx; | ||
import org.mockito.Spy; | ||
|
||
@ExtendWith(VertxExtension.class) | ||
public class FiscalYearServiceTest { | ||
|
||
public static final String TENANT_ID = "ordertest"; | ||
public static final Header X_OKAPI_TENANT = new Header(OKAPI_HEADER_TENANT, TENANT_ID); | ||
|
||
@InjectMocks | ||
private FiscalYearService fiscalYearService; | ||
|
||
private Context ctxMock; | ||
private Map<String, String> okapiHeadersMock; | ||
private HttpClientInterface httpClient; | ||
@Spy | ||
private RestClient restClientMock; | ||
@Mock | ||
private RequestContext requestContextMock; | ||
|
||
@BeforeEach | ||
public void initMocks() { | ||
ctxMock = Vertx.vertx().getOrCreateContext(); | ||
okapiHeadersMock = new HashMap<>(); | ||
okapiHeadersMock.put(OKAPI_URL, "http://localhost:" + mockPort); | ||
okapiHeadersMock.put(X_OKAPI_TOKEN.getName(), X_OKAPI_TOKEN.getValue()); | ||
okapiHeadersMock.put(X_OKAPI_TENANT.getName(), X_OKAPI_TENANT.getValue()); | ||
okapiHeadersMock.put(X_OKAPI_USER_ID.getName(), X_OKAPI_USER_ID.getValue()); | ||
String okapiURL = okapiHeadersMock.getOrDefault(OKAPI_URL, ""); | ||
requestContextMock = new RequestContext(ctxMock, okapiHeadersMock); | ||
MockitoAnnotations.openMocks(this); | ||
} | ||
|
||
@Test | ||
void testShouldReturnCurrentFiscalYearForLedger() { | ||
String ledgerId = UUID.randomUUID().toString(); | ||
|
||
doReturn(succeededFuture(new FiscalYear())) | ||
.when(restClientMock) | ||
.get(any(RequestEntry.class), eq(FiscalYear.class), any(RequestContext.class)); | ||
|
||
FiscalYear fy = fiscalYearService.getCurrentFiscalYear(ledgerId, requestContextMock).result(); | ||
|
||
String ledgerId = UUID.randomUUID() | ||
.toString(); | ||
FiscalYear fy = fiscalYearService.getCurrentFiscalYear(ledgerId, requestContextMock) | ||
.result(); | ||
assertNotNull(fy); | ||
} | ||
|
||
@Test | ||
void testShouldThrowHttpException() { | ||
void testShouldThrowHttpException(VertxTestContext vertxTestContext) { | ||
doReturn(failedFuture(new HttpException(404, "Fiscal year not found"))) | ||
.when(restClientMock) | ||
.get(any(RequestEntry.class), eq(FiscalYear.class), any(RequestContext.class)); | ||
|
||
Future<FiscalYear> result = fiscalYearService.getCurrentFiscalYear(ID_DOES_NOT_EXIST, requestContextMock); | ||
CompletionException expectedException = assertThrows(CompletionException.class, result::result); | ||
|
||
HttpException httpException = (HttpException) expectedException.getCause(); | ||
assertEquals(404, httpException.getCode()); | ||
vertxTestContext.assertFailure(result) | ||
.onComplete(expectedException -> { | ||
HttpException httpException = (HttpException) expectedException.cause(); | ||
assertEquals(404, httpException.getCode()); | ||
assertEquals(result.cause().getMessage(), httpException.getMessage()); | ||
verify(restClientMock).get(any(RequestEntry.class), eq(FiscalYear.class), any(RequestContext.class)); | ||
vertxTestContext.completeNow(); | ||
}); | ||
} | ||
} |
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