-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added testcases for service * added testcases for inventory services * added testcases for config, events, and exceptions * minor changes * added few test cases for handler * added test cases for aggregate * removed code smells and added read me file --------- Co-authored-by: shivamm31 <[email protected]>
- Loading branch information
Showing
28 changed files
with
1,668 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"note" : "Please restart the plugin after making changes to the lists below. If you want to mock files of any package, please add the package to packagesToMock list ex org.apache.commons. If you don't want to mock files of any package, please add the package to packagesToNotMock list ex com.google.gson Please make sure the json is a valid json, or it will revert to default list of packages.", | ||
"classesAndPackagesNotToMock" : [ ], | ||
"classesAndPackagesToMock" : [ ] | ||
} |
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,49 @@ | ||
# Inventory Service | ||
|
||
##### Application Overview | ||
|
||
This application is conscientiously crafted to oversee the management of available cars for sale within a system. Leveraging the Axon Framework for CQRS (Command Query Responsibility Segregation) and Event Sourcing, it seamlessly orchestrates the creation of inventory, ensures the storage of product details in a database, and adeptly publishes events to a Google Cloud Pub/Sub topic. | ||
|
||
#### Workflow | ||
|
||
### Inventory Creation | ||
|
||
- It all starts with a CreateProductCommand, managed by the Inventory Aggregate class. | ||
- The aggregate takes care of the command, leading to the triggering of the ProductCreatedEvent. | ||
|
||
### Event Handling | ||
|
||
The ProductEventHandler takes care of the ProductCreatedEvent. | ||
|
||
- It grabs the product information from the event. | ||
- The details are then stored in a database through the ProductRepository. | ||
- On top of that, the PubSubPublisherService is employed to broadcast the product details to a Google Cloud Pub/Sub topic. | ||
|
||
### Google Cloud Pub/Sub Integration: | ||
|
||
- The PubSubPublisherService sets up the Pub/Sub publisher when the application starts using @PostConstruct. | ||
- It handles turning product data into a Pub/Sub message and sends it to the specified topic. | ||
- When the application shuts down with @PreDestroy, the publisher is smoothly stopped. | ||
|
||
### Data Storage | ||
|
||
- Product details are persisted to a database for future reference. | ||
- The ProductRepository handles the database interactions. | ||
|
||
##### Key Components | ||
|
||
### InventoryAggregate | ||
|
||
|
||
|
||
Manages all aspects of product creation, monitors ongoing activities, and stays informed through events to ensure up-to-date awareness of the process. | ||
|
||
### ProductEventHandler | ||
|
||
|
||
Listens for the ProductCreatedEvent, grabs product info from the event, stores it in a database through the ProductRepository, and spreads the word about the product by sharing details on Google Cloud Pub/Sub using the PubSubPublisherService. | ||
|
||
### PubSubPublisherService | ||
|
||
Sets up a Google Cloud Pub/Sub publisher when the application starts, sends product information to a Pub/Sub topic, and ensures a smooth shutdown for the publisher when the application closes. | ||
|
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,2 @@ | ||
config.stopBubbling = true | ||
lombok.addLombokGeneratedAnnotation = true |
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
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
2 changes: 0 additions & 2 deletions
2
inventory-service/src/main/java/com/nashtech/inventory/exception/ProductNotFound.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,11 +1,9 @@ | ||
package com.nashtech.inventory.exception; | ||
|
||
public class ProductNotFound extends RuntimeException { | ||
private String message; | ||
|
||
public ProductNotFound(String message) { | ||
super(message); | ||
this.message = message; | ||
} | ||
|
||
} |
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
54 changes: 54 additions & 0 deletions
54
inventory-service/src/test/java/com/nashtech/inventory/InventoryApplicationTest.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,54 @@ | ||
package com.nashtech.inventory; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
import com.nashtech.inventory.command.interceptors.CreateProductCommandInterceptor; | ||
import com.nashtech.inventory.exception.ProductsServiceEventsErrorHandler; | ||
import org.axonframework.commandhandling.CommandBus; | ||
import org.axonframework.commandhandling.gateway.CommandGateway; | ||
import org.axonframework.config.EventProcessingConfigurer; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.context.ApplicationContext; | ||
|
||
class InventoryApplicationTest { | ||
|
||
CommandGateway commandGateway; | ||
/** | ||
* Test case to ensure that the create product command interceptor is registered successfully. | ||
*/ | ||
@Test | ||
void test_create_product_command_interceptor_registered_successfully() { | ||
ApplicationContext context = mock(ApplicationContext.class); | ||
CommandBus commandBus = mock(CommandBus.class); | ||
CreateProductCommandInterceptor interceptor = mock(CreateProductCommandInterceptor.class); | ||
|
||
when(context.getBean(CreateProductCommandInterceptor.class)).thenReturn(interceptor); | ||
|
||
|
||
InventoryApplication inventoryApplication = new InventoryApplication(commandGateway); | ||
|
||
inventoryApplication.registerCreateProductCommandInterceptor(context, commandBus); | ||
|
||
verify(commandBus).registerDispatchInterceptor(interceptor); | ||
} | ||
|
||
/** | ||
* Test case to ensure that the ProductsServiceEventsErrorHandler is configured successfully. | ||
*/ | ||
@Test | ||
void test_products_service_events_error_handler_configured_successfully() { | ||
EventProcessingConfigurer config = mock(EventProcessingConfigurer.class); | ||
mock(ProductsServiceEventsErrorHandler.class); | ||
|
||
when(config.registerListenerInvocationErrorHandler(eq("product-group"), any())).thenReturn(config); | ||
|
||
InventoryApplication inventoryApplication = new InventoryApplication(commandGateway); | ||
|
||
inventoryApplication.configure(config); | ||
|
||
verify(config).registerListenerInvocationErrorHandler(eq("product-group"), any()); | ||
} | ||
} |
9 changes: 0 additions & 9 deletions
9
inventory-service/src/test/java/com/nashtech/inventory/InventoryServiceApplicationTest.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.