Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#882 create a shared project #1020

Merged
merged 7 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/cart-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ jobs:
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- uses: ./.github/workflows/actions
- name: Run Maven Build Command
run: mvn clean install -pl cart -am
- name: Run Maven Checkstyle
if: ${{ env.FROM_ORIGINAL_REPOSITORY == 'true' }}
run: mvn checkstyle:checkstyle -f cart -Dcheckstyle.output.file=cart-checkstyle-result.xml
run: mvn checkstyle:checkstyle -pl cart -am -Dcheckstyle.output.file=cart-checkstyle-result.xml
- name: Upload Checkstyle Result
if: ${{ env.FROM_ORIGINAL_REPOSITORY == 'true' }}
uses: jwgmeligmeyling/checkstyle-github-action@master
with:
path: '**/cart-checkstyle-result.xml'
- name: Run Maven Verify
run: mvn clean verify -f cart
- name: Test Results
uses: dorny/test-reporter@v1
if: ${{ env.FROM_ORIGINAL_REPOSITORY == 'true' && (success() || failure()) }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/customer-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ jobs:
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- uses: ./.github/workflows/actions
- name: Run Maven Build Command
run: mvn clean install -pl customer -am
- name: Run Maven Checkstyle
if: ${{ env.FROM_ORIGINAL_REPOSITORY == 'true' }}
run: mvn checkstyle:checkstyle -f customer -Dcheckstyle.output.file=customer-checkstyle-result.xml
run: mvn checkstyle:checkstyle -pl customer -am -Dcheckstyle.output.file=customer-checkstyle-result.xml
- name: Upload Checkstyle Result
if: ${{ env.FROM_ORIGINAL_REPOSITORY == 'true' }}
uses: jwgmeligmeyling/checkstyle-github-action@master
with:
path: '**/customer-checkstyle-result.xml'
- name: Run Maven Verify
run: mvn clean verify -f customer
- name: Test Results
uses: dorny/test-reporter@v1
if: ${{ env.FROM_ORIGINAL_REPOSITORY == 'true' && (success() || failure()) }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/inventory-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ jobs:
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- uses: ./.github/workflows/actions
- name: Run Maven Build Command
run: mvn clean install -pl inventory -am
- name: Run Maven Checkstyle
if: ${{ env.FROM_ORIGINAL_REPOSITORY == 'true' }}
run: mvn checkstyle:checkstyle -f inventory -Dcheckstyle.output.file=inventory-checkstyle-result.xml
run: mvn checkstyle:checkstyle -pl inventory -am -Dcheckstyle.output.file=inventory-checkstyle-result.xml
- name: Upload Checkstyle Result
if: ${{ env.FROM_ORIGINAL_REPOSITORY == 'true' }}
uses: jwgmeligmeyling/checkstyle-github-action@master
with:
path: '**/inventory-checkstyle-result.xml'
- name: Run Maven Verify
run: mvn verify -f inventory
- name: Test Results
uses: dorny/test-reporter@v1
if: ${{ env.FROM_ORIGINAL_REPOSITORY == 'true' && (success() || failure()) }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/location-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ jobs:
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- uses: ./.github/workflows/actions
- name: Run Maven Build Command
run: mvn clean install -pl location -am
- name: Run Maven Checkstyle
if: ${{ env.FROM_ORIGINAL_REPOSITORY == 'true' }}
run: mvn checkstyle:checkstyle -f location -Dcheckstyle.output.file=location-checkstyle-result.xml
run: mvn checkstyle:checkstyle -pl location -am -Dcheckstyle.output.file=location-checkstyle-result.xml
- name: Upload Checkstyle Result
if: ${{ env.FROM_ORIGINAL_REPOSITORY == 'true' }}
uses: jwgmeligmeyling/checkstyle-github-action@master
with:
path: '**/location-checkstyle-result.xml'
- name: Run Maven Verify
run: mvn clean verify -f location
- name: Test Results
uses: dorny/test-reporter@v1
if: ${{ env.FROM_ORIGINAL_REPOSITORY == 'true' && (success() || failure()) }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/product-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- uses: ./.github/workflows/actions
- name: Run Maven Build Command
run: mvn clean install -pl product -am
- name: Run Maven Checkstyle
if: ${{ env.FROM_ORIGINAL_REPOSITORY == 'true' }}
run: mvn checkstyle:checkstyle -pl product -am -Dcheckstyle.output.file=product-checkstyle-result.xml
Expand All @@ -35,8 +37,6 @@ jobs:
uses: jwgmeligmeyling/checkstyle-github-action@master
with:
path: '**/product-checkstyle-result.xml'
- name: Run Maven Verify
run: mvn clean verify -f product
- name: Test Results
uses: dorny/test-reporter@v1
if: ${{ env.FROM_ORIGINAL_REPOSITORY == 'true' && (success() || failure()) }}
Expand Down
8 changes: 7 additions & 1 deletion cart/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.yas</groupId>
Expand Down Expand Up @@ -48,6 +49,11 @@
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
</dependency>
<dependency>
<groupId>com.yas</groupId>
<artifactId>common-library</artifactId>
<version>${revision}</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
30 changes: 12 additions & 18 deletions cart/src/it/java/com/yas/cart/service/CartServiceIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import static org.mockito.Mockito.when;

import com.yas.cart.config.IntegrationTestConfiguration;
import com.yas.cart.exception.BadRequestException;
import com.yas.cart.exception.NotFoundException;
import com.yas.cart.model.Cart;
import com.yas.cart.model.CartItem;
import com.yas.cart.repository.CartItemRepository;
Expand All @@ -17,6 +15,8 @@
import com.yas.cart.viewmodel.CartItemVm;
import com.yas.cart.viewmodel.CartListVm;
import com.yas.cart.viewmodel.ProductThumbnailVm;
import com.yas.commonlibrary.exception.BadRequestException;
import com.yas.commonlibrary.exception.NotFoundException;
import java.util.List;
import java.util.Set;
import org.junit.jupiter.api.AfterEach;
Expand All @@ -33,31 +33,25 @@
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
class CartServiceIT {

final String customerId1 = "customer-1";
private Cart cart1;

private Cart cart2;

@Autowired
private CartRepository cartRepository;

@Autowired
private CartItemRepository cartItemRepository;

@MockBean
private ProductService productService;

@Autowired
private CartService cartService;

final String customerId1 = "customer-1";

@BeforeEach
void setUp() {

cart1 = cartRepository.save(Cart
.builder().customerId(customerId1).build());
.builder().customerId(customerId1).build());
cart2 = cartRepository.save(Cart
.builder().customerId("customer-2").build());
.builder().customerId("customer-2").build());

CartItem cartItem1 = new CartItem();
cartItem1.setProductId(1L);
Expand Down Expand Up @@ -131,7 +125,7 @@ void removeCartItemListByProductIdList_SomeProductsExist_RemovesThem() {
void removeCartItemListByProductIdList_NoCartItems_ThrowBadRequestException() {

Cart cart3 = cartRepository.save(Cart
.builder().customerId("customer-3").build());
.builder().customerId("customer-3").build());

cartRepository.save(cart3);

Expand Down Expand Up @@ -179,7 +173,7 @@ void countNumberItemInCart_NoCart_ReturnsZero() {
void countNumberItemInCart_EmptyCart_ReturnsZero() {

Cart cart3 = cartRepository.save(Cart
.builder().customerId("customer-3").build());
.builder().customerId("customer-3").build());

cartRepository.save(cart3);

Expand All @@ -197,11 +191,11 @@ void countNumberItemInCart_NonEmptyCart_ReturnsCorrectCount() {
void addToCart_ProductsExist_AddsItemsToNewCart() {

List<CartItemVm> cartItemVms = List.of(
new CartItemVm(1L, 2, 10L)
new CartItemVm(1L, 2, 10L)
);

List<ProductThumbnailVm> productThumbnails = List.of(
new ProductThumbnailVm(1L, "A21", "A22", "A23")
new ProductThumbnailVm(1L, "A21", "A22", "A23")
);

when(productService.getProducts(List.of(1L))).thenReturn(productThumbnails);
Expand All @@ -217,11 +211,11 @@ void addToCart_ProductsExist_AddsItemsToNewCart() {
@Test
void addToCart_ProductsExist_AddsItemsToExistingCart() {
List<CartItemVm> cartItemVms = List.of(
new CartItemVm(3L, 2, 10L)
new CartItemVm(3L, 2, 10L)
);

List<ProductThumbnailVm> productThumbnails = List.of(
new ProductThumbnailVm(3L, "A21", "A22", "A23")
new ProductThumbnailVm(3L, "A21", "A22", "A23")
);

when(productService.getProducts(List.of(3L))).thenReturn(productThumbnails);
Expand All @@ -248,7 +242,7 @@ void addToCart_SomeProductsDoNotExist_ThrowsNotFoundException() {

assertThat(thrownException).isInstanceOf(NotFoundException.class);
assertThat(thrownException.getMessage())
.isEqualTo("Not found product [2]");
.isEqualTo("Not found product [2]");

}

Expand Down
2 changes: 2 additions & 0 deletions cart/src/it/java/com/yas/cart/service/ProductServiceIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.context.annotation.ComponentScan;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

@SpringBootTest
@Testcontainers
@ComponentScan(basePackages = {"com.yas.commonlibrary"})
class ProductServiceIT {
@Container
@ServiceConnection
Expand Down
3 changes: 0 additions & 3 deletions cart/src/it/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# Setting Spring context path & port
server.servlet.context-path=/v1
server.port=8084

spring.jpa.hibernate.ddl-auto=update
spring.liquibase.enabled=false

# Setting Spring profile
spring.profiles.active=test

spring.security.oauth2.resourceserver.jwt.issuer-uri=test
springdoc.oauthflow.authorization-url=test
springdoc.oauthflow.token-url=test
Loading
Loading