Skip to content

Commit

Permalink
Update UT
Browse files Browse the repository at this point in the history
  • Loading branch information
phhung-axonivy committed Dec 11, 2024
1 parent 3976bf9 commit 2a6b9fa
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class BaseSetup {
protected static final String SAMPLE_PRODUCT_ID = "amazon-comprehend";
protected static final String SAMPLE_PRODUCT_PATH = "/market/connector/amazon-comprehend";
protected static final String SAMPLE_PRODUCT_NAME = "prody Comprehend";
protected static final String SAMPLE_PRODUCT_REPOSITORY_NAME = "axonivy-market/amazon-comprehend";
protected static final Pageable PAGEABLE = PageRequest.of(0, 20,
Sort.by(SortOption.ALPHABETICALLY.getOption()).descending());
protected static final String MOCK_PRODUCT_ID = "bpmn-statistic";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,5 +243,4 @@ void testSyncFirstPublishedDateOfAllProductsSuccess() {
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(ErrorCode.SUCCESSFUL.getCode(), response.getBody().getHelpCode());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.kohsuke.github.GHCommit;
import org.kohsuke.github.GHContent;
import org.kohsuke.github.GHTag;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.exceptions.base.MockitoException;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
Expand All @@ -56,6 +58,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -613,4 +616,26 @@ void testSyncProductsAsUpdateMetaJSONFromGitHub_AddVendorLogo() throws IOExcepti
assertNotNull(result);
assertTrue(result.isEmpty());
}

@Test
void testSyncFirstPublishedDateOfAllProducts() throws IOException {
Product mockProduct = new Product();
mockProduct.setId(SAMPLE_PRODUCT_ID);
mockProduct.setMarketDirectory(SAMPLE_PRODUCT_PATH);
mockProduct.setRepositoryName(SAMPLE_PRODUCT_REPOSITORY_NAME);
List<Product> products = Arrays.asList(mockProduct);
when(productRepo.findAll()).thenReturn(products);
when(productRepo.save(any(Product.class))).thenReturn(mockProduct);
GHTag ghTagVersionOne = new GHTag();
GHTag ghTagVersionTwo = new GHTag();
List<GHTag> tags = Arrays.asList(ghTagVersionOne, ghTagVersionTwo);
when(gitHubService.getRepositoryTags(SAMPLE_PRODUCT_REPOSITORY_NAME)).thenReturn(tags);
assertTrue(productService.syncFirstPublishedDateOfAllProducts());
}

@Test
void testSyncFirstPublishedDateOfAllProductsFailed() {
when(productRepo.findAll()).thenThrow(new MockitoException("Sync FirstPublishedDate of all products failed!"));
assertFalse(productService.syncFirstPublishedDateOfAllProducts());
}
}

0 comments on commit 2a6b9fa

Please sign in to comment.