Skip to content

Commit

Permalink
Merge pull request #22 from mohamed-taman/develop
Browse files Browse the repository at this point in the history
Project Updates
  • Loading branch information
mohamed-taman authored Aug 9, 2021
2 parents 7edabce + ff2f87d commit 22459a2
Show file tree
Hide file tree
Showing 45 changed files with 768 additions and 708 deletions.
8 changes: 4 additions & 4 deletions .mvn/wrapper/MavenWrapperDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ public class MavenWrapperDownloader {
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";

/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";
".mvn/wrapper/maven-wrapper.properties";

/**
* Path where the maven-wrapper.jar will be saved to.
*/
private static final String MAVEN_WRAPPER_JAR_PATH =
".mvn/wrapper/maven-wrapper.jar";
".mvn/wrapper/maven-wrapper.jar";

/**
* Name of the property which should be used to override the default download url for the wrapper.
Expand Down Expand Up @@ -77,7 +77,7 @@ public static void main(String args[]) {
if (!outputFile.getParentFile().exists()) {
if (!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
Expand Down
115 changes: 82 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,34 @@

A set of interacting microservices, representing a very basic banking system.

- This project is a development of a small set of **Spring Boot** projects, with a database in-memory.
- This project is a development of a small set of **Spring Boot** projects, with a database
in-memory.

---

## Better Code Hub
I analysed this repository according to the clean code standards on [Better Code Hub](https://bettercodehub.com/) just to get an independent opinion of how bad the code is. Surprisingly, the compliance score is high!

I analysed this repository according to the clean code standards
on [Better Code Hub](https://bettercodehub.com/) just to get an independent opinion of how bad the
code is. Surprisingly, the compliance score is high!

## Getting started

### Project Management
1. I have used GitHub projects to manage my tasks in the **Harvest Bank** project. [Project Link](https://github.com/mohamed-taman/Harvest-Bank/projects/1)
2. All MVP tasks are assigned to the **Harvest Bank MVP Milestone**. [Milestone Link](https://github.com/mohamed-taman/Harvest-Bank/milestone/1?closed=1)
3. I used Pull requests to manages and close my tasks. [Tasks Link](https://github.com/mohamed-taman/Harvest-Bank/issues?q=)
4. Finally, I have added releases to manage small features sprints until the final release v1.5. [Releases Link](https://github.com/mohamed-taman/Harvest-Bank/releases)

1. I have used GitHub projects to manage my tasks in the **Harvest Bank**
project. [Project Link](https://github.com/mohamed-taman/Harvest-Bank/projects/1)
2. All MVP tasks are assigned to the **Harvest Bank MVP Milestone**
. [Milestone Link](https://github.com/mohamed-taman/Harvest-Bank/milestone/1?closed=1)
3. I used Pull requests to manages and close my
tasks. [Tasks Link](https://github.com/mohamed-taman/Harvest-Bank/issues?q=)
4. Finally, I have added releases to manage small features sprints until the final release
v1.5. [Releases Link](https://github.com/mohamed-taman/Harvest-Bank/releases)

### System components Structure

Let's explain first the system structure to understand its components:

```
Harvest-Bank --> Parent folder.
|- docs --> All docs and diagrams.
Expand All @@ -33,6 +46,7 @@ Harvest-Bank --> Parent folder.
|- stop-em-all.sh --> Stop all services runs in standalone mode.
|- test-em-all.sh --> This will start all Microservices landscape and test them, then shutdown Microservices after test finishes (use switch start and stop)
```

Now, as we have learned about different system components, then let's start.

### System Boundary - μServices Landscape
Expand All @@ -42,41 +56,52 @@ Now, as we have learned about different system components, then let's start.
### Required software

The following are the initially required software pieces:
1. **Maven**: Apache Maven is a software project management and comprehension tool, it can be downloaded from here https://maven.apache.org/download.cgi

1. **Maven**: Apache Maven is a software project management and comprehension tool, it can be
downloaded from here https://maven.apache.org/download.cgi
1. **Git**: it can be downloaded and installed from https://git-scm.com/downloads
1. **Java, JDK 15 RC**: it can be downloaded and installed from https://jdk.java.net/15/
1. **curl**: this command-line tool for testing HTTP-based APIs can be downloaded and installed from https://curl.haxx.se/download.html
1. **jq**: This command-line JSON processor can be downloaded and installed from https://stedolan.github.io/jq/download/
1. **curl**: this command-line tool for testing HTTP-based APIs can be downloaded and installed
from https://curl.haxx.se/download.html
1. **jq**: This command-line JSON processor can be downloaded and installed
from https://stedolan.github.io/jq/download/

Follow the installation guide for each software website link and check your software versions from the command line to verify that they are all installed correctly.
Follow the installation guide for each software website link and check your software versions from
the command line to verify that they are all installed correctly.

## Using an IDE

I recommend that you work with your Java code using an IDE that supports the development of Spring Boot applications such as **Spring Tool Suite** or **IntelliJ IDEA Ultimate Edition**.
I recommend that you work with your Java code using an IDE that supports the development of Spring
Boot applications such as **Spring Tool Suite** or **IntelliJ IDEA Ultimate Edition**.

So you can use the Spring Boot Dashboard to run the services, run each Microservice test case, and many more.
So you can use the Spring Boot Dashboard to run the services, run each Microservice test case, and
many more.

All you have to do is just fire up your favorit IDE **->** open or import the parent folder `Harvest-Bank`, and everything will be ready for you.
All you have to do is just fire up your favorit IDE **->** open or import the parent
folder `Harvest-Bank`, and everything will be ready for you.

## Playing With Harvest Bank Project

### Cloning It

The first thing to do is to open **git bash** command line, and then simply you can clone the project under any of your favorite places as the following:
The first thing to do is to open **git bash** command line, and then simply you can clone the
project under any of your favorite places as the following:

```bash
> git clone https://github.com/mohamed-taman/Harvest-Bank.git
```

### Build & Test Them In Isolation

To build and run the test cases for each service & shared modules in the project, we need to do the following:
To build and run the test cases for each service & shared modules in the project, we need to do the
following:

#### First: Build & Install Shared Dependencies

> This done only for the first time or any new changes or versions of shared modules and POMs.
To build and install `bank-build-chassis`, and `bank-services-chassis` POMs, and `bank-common` shared library, from the root folder `Harvest-Bank`, run the following command:
To build and install `bank-build-chassis`, and `bank-services-chassis` POMs, and `bank-common`
shared library, from the root folder `Harvest-Bank`, run the following command:

```bash
mohamed_taman:Harvest-Bank$ ./setup.sh
Expand All @@ -100,14 +125,18 @@ Done successfully.
Woohoo, building & installing all project modules are finished successfully.
The project is ready for the next step. :)
```

#### Second: Build & Test Microservices
Now it is the time to build our **3 microservices** and run each service unit and integration tests in isolation by running the following commands:

Now it is the time to build our **3 microservices** and run each service unit and integration tests
in isolation by running the following commands:

```bash
mohamed_taman:Harvest-Bank$ ./mvnw clean verify
```

All build commands and test suite for each microservice should run successfully, and the final output should be like this:
All build commands and test suite for each microservice should run successfully, and the final
output should be like this:

```bash
-------< org.siriusxi.blueharvest.bank:Harvest-Bank-aggregator >--------
Expand All @@ -134,13 +163,16 @@ All build commands and test suite for each microservice should run successfully,
```

### Running Them All
Now it's the time to run all of our Microservices, and it's straightforward, just run the following commands:

Now it's the time to run all of our Microservices, and it's straightforward, just run the following
commands:

```bash
mohamed_taman:Harvest-Bank$ ./run-em-all.sh
```

All the **services**, In-memory **databases**, will run in parallel in a detach mode, and the command output will print the following to console:
All the **services**, In-memory **databases**, will run in parallel in a detach mode, and the
command output will print the following to console:

```bash
Starting [Harvest Bank] μServices ....
Expand All @@ -150,21 +182,31 @@ Starting [account-service] μService.... Done
Starting [customer-service] μService.... Done
Starting [transaction-service] μService.... Done
```

### Access Bank APIs
You can manually test the whole system through `Customer Service` APIs within its **OpenAPI** interface at the following URL [http://localhost:8090/swagger-ui.html](http://localhost:8090/swagger-ui.html)

#### System Behaviours
1. If you execute get customers through `/bank/api/v1/customers`, it will return pre-defined seven customers.
2. If you tried to pass through `/bank/api/v1/customers/{id}/accounts` the following:

1. If you execute get customers through `/bank/api/v1/customers`, it will return pre-defined seven
customers.
2. If you tried to pass through `/bank/api/v1/customers/{id}/accounts` the following:
1. A none exist customer {Id} system will return **404** (*Not Found*) with error message.
2. A minus customer {Id} or Initial Credit, System will return **422** (*Unprocessable Entity*) with an error message.
3. An invalid format customer {Id} or Initial Credit, System will return **400** (*Bad Request*) with an error message.
2. A minus customer {Id} or Initial Credit, System will return **422** (*Unprocessable Entity*)
with an error message.
3. An invalid format customer {Id} or Initial Credit, System will return **400** (*Bad Request*)
with an error message.
3. If the initial credit is 0.0, the system expects to create an account and no transaction.
4. If the initial credit is > 0.0, i.e., 100, The system is expected to create a new account with a balance of 100. A new transaction with the amount of 100 and customer balance will be 100.
5. Suppose another create account call happened to the same customer. In that case, the system will do what is done at point **#4**. The customer balance will be *updated* to reflect the sum of all accounts balances and transaction amounts.
4. If the initial credit is > 0.0, i.e., 100, The system is expected to create a new account with a
balance of 100. A new transaction with the amount of 100 and customer balance will be 100.
5. Suppose another create account call happened to the same customer. In that case, the system will
do what is done at point **#4**. The customer balance will be *updated* to reflect the sum of all
accounts balances and transaction amounts.

### Stopping Them All
Now it's the time to stop all of our Microservices, and it's straightforward, just run the following commands:

Now it's the time to stop all of our Microservices, and it's straightforward, just run the following
commands:

```bash
mohamed_taman:Harvest-Bank$ ./stop-em-all.sh
Expand All @@ -188,16 +230,20 @@ Stopping μService at port 8092 ....
{"message":"Shutting down, bye..."}
μService at port 8092 stopped successfully ....
```

### Testing Them All
Now it's time to test all the application functionality as one part. To do so just run the following automation test script:

Now it's time to test all the application functionality as one part. To do so just run the following
automation test script:

```bash
mohamed_taman:Harvest-Bank$ ./test-em-all.sh start stop
```

You can use `stop` switch with `start`, that will
1. **Start** the whole microservices landscape,
2. **Run** the system black-box tests, if successful then
You can use `stop` switch with `start`, that will

1. **Start** the whole microservices landscape,
2. **Run** the system black-box tests, if successful then
3. **Stop** the whole microservices.

The result will look like this:
Expand Down Expand Up @@ -272,11 +318,14 @@ Stopping μService at port 8092 ....

### Closing The Story

Finally, hope you enjoyed the application and find it useful. If you would like to enhance please open **PR**, and finally give it a 🌟.
Finally, hope you enjoyed the application and find it useful. If you would like to enhance please
open **PR**, and finally give it a 🌟.

## The End
Happy Coding 😊

Happy Coding 😊

## License

Copyright (C) 2020 Mohamed Taman, Licensed under the **Apache-2.0 License**.

11 changes: 6 additions & 5 deletions bank-base/bank-build-chassis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.0-M2</version>
<version>2.5.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand All @@ -18,15 +18,15 @@
<packaging>pom</packaging>

<properties>
<java.version>15</java.version>
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<!-- Dependencies versions properties -->
<maven.compiler.plugin.version>3.8.1</maven.compiler.plugin.version>
<maven.surefire.plugin.version>3.0.0-M4</maven.surefire.plugin.version>
<maven.failsafe.plugin.version>3.0.0-M4</maven.failsafe.plugin.version>
<org.lombok.version>1.18.12</org.lombok.version>
<maven.surefire.plugin.version>3.0.0-M5</maven.surefire.plugin.version>
<maven.failsafe.plugin.version>3.0.0-M5</maven.failsafe.plugin.version>
<org.lombok.version>1.18.20</org.lombok.version>
</properties>

<dependencies>
Expand All @@ -35,6 +35,7 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
<version>${org.lombok.version}</version>
</dependency>
<!-- End - POJO creation made easy -->
</dependencies>
Expand Down
12 changes: 6 additions & 6 deletions bank-base/bank-services-chassis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
<!-- <exclusions>-->
<!-- <exclusion>-->
<!-- <groupId>org.junit.vintage</groupId>-->
<!-- <artifactId>junit-vintage-engine</artifactId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
2 changes: 1 addition & 1 deletion bank-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.11.2</version>
<version>2.12.4</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.List;

public record Account(@JsonProperty("customerId") int customerId,
@JsonProperty("balance") BigDecimal balance,
@JsonProperty("type") AccountType type,
@JsonProperty("transactions") List<Transaction> transactions) {
}
@JsonProperty("balance") BigDecimal balance,
@JsonProperty("type") AccountType type,
@JsonProperty("transactions") List<Transaction> transactions){
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@
* @implNote Since it is a record and not normal POJO, so it needs some customizations
* to be serialized to JSON and this is done with method
* <code>GlobalConfiguration.jacksonCustomizer()</code>.
*
* @see java.lang.Record
* @author mohamed.taman
* @version v0.1
* @see java.lang.Record
* @since v0.1
*/
public record CustomerAggregate(
@JsonProperty("id") int id,
@JsonProperty("name") String firstName,
@JsonProperty("Surname")String lastName,
@JsonProperty("balance") BigDecimal balance,
@JsonProperty("accounts") List<Account> accounts) {
}
@JsonProperty("id") int id,
@JsonProperty("name") String firstName,
@JsonProperty("Surname")String lastName,
@JsonProperty("balance") BigDecimal balance,
@JsonProperty("accounts") List<Account> accounts){
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
import java.math.BigDecimal;

public record Transaction(@JsonProperty("accountId") int accountId,
@JsonProperty("type") TransactionType type,
@JsonProperty("amount") BigDecimal amount) {
}
@JsonProperty("type") TransactionType type,
@JsonProperty("amount") BigDecimal amount){
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
@RequiredArgsConstructor
public class TransactionDTO {

@NonNull
private int accountId;
@NonNull
private int accountId;

@NonNull
private BigDecimal amount;
@NonNull
private BigDecimal amount;
}
Loading

0 comments on commit 22459a2

Please sign in to comment.