Skip to content

Commit 7b91f1f

Browse files
committed
update readME file and other optimization.
1 parent dda1211 commit 7b91f1f

File tree

6 files changed

+139
-8
lines changed

6 files changed

+139
-8
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ WORKDIR /home/app
44
RUN gradle clean build --no-daemon -i -x test -x javadoc
55

66
FROM eclipse-temurin:21-jre-alpine
7-
COPY --from=build /home/app/ss-web/build/libs/ss-web.jar /usr/local/lib/sw/app.jar
7+
COPY --from=build /home/app/ss-web/build/libs/ss-web.jar /usr/local/lib/ss/app.jar
88
RUN apk update && apk upgrade libssl3 libcrypto3
99
RUN addgroup -S sw && adduser -S sw -G sw
1010
USER sw
11-
WORKDIR /usr/local/lib/sw
11+
WORKDIR /usr/local/lib/ss
1212
EXPOSE 8080
1313
ENTRYPOINT ["java","-jar","app.jar"]

README.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,131 @@
11
# Seed Multi module demo
22

3+
# Spring boot multi module boiler plate <a id="introduction"></a>
4+
5+
This repository contains boiler-plate codebase using Java, Spring boot as core technology.
6+
7+
# Developer Documentation
8+
9+
To run application locally, this section describes the tooling as well as
10+
the local development setup.
11+
12+
# Module Information
13+
14+
ss-api : It contains utilities like constants, dtos, validators, utility classes.
15+
ss-dao : It contains database entities and repositories.
16+
ss-service : It contains abstraction of business logic.
17+
ss-service-impl : It contains business login.
18+
ss-web : It contains application Configs, Db-migration files, Exception handler, API definition.
19+
20+
## Tooling
21+
22+
| Area | Tool | Download Link | Comment |
23+
|----------|----------|-------------------------------------------------|---------------------------------------------------------------------------------------------------|
24+
| IDE | IntelliJ | https://www.jetbrains.com/idea/download/ | Additionally the [envfile plugin](https://plugins.jetbrains.com/plugin/7861-envfile) is suggested |
25+
| Build | Gradle | https://gradle.org/install/ |
26+
| Runtime | Docker | https://www.docker.com/products/docker-desktop/ | |
27+
| Database | DBeaver | https://dbeaver.io/ |
28+
| IAM | Keycloak | https://www.keycloak.org/ | |
29+
30+
## Local Development Setup
31+
32+
1. Run keycloak and database server
33+
2. Import realm file [app-test-realm.json](src%2Ftest%2Fresources%2Fapp-test-realm.json)
34+
3. Update your env variable in application.yaml file
35+
4. Run [MainApplication.java](src%2Fmain%2Fjava%2Fss%2Fmod%2Fdemo%2FMainApplication.java)
36+
in IDE
37+
5. Open API doc on http://localhost:8080
38+
6. Click on Authorize on swagger UI and on the dialog click again on Authorize.
39+
7. Login with username=valid-user and password=password
40+
41+
## Build application locally
42+
43+
Build with test cases
44+
45+
```
46+
./gradlew build
47+
```
48+
49+
Build without test cases
50+
51+
```
52+
./gradlew build -i -x test
53+
```
54+
55+
## Test Coverage
56+
57+
Jacoco is used to generate the coverage report. The report generation
58+
and the coverage verification are automatically executed after tests.
59+
60+
The generated HTML report can be found under `jacoco-report/html/`
61+
62+
To generate the report run the command
63+
64+
```
65+
./gradlew jacocoTestReport
66+
```
67+
68+
To check the coverage run the command
69+
70+
```
71+
./gradlew jacocoTestCoverageVerification
72+
```
73+
74+
## Common issues and solutions during local setup
75+
76+
#### 1. Can not build with test cases
77+
78+
Test cases are written using the Spring Boot integration test frameworks. These test frameworks start the Spring Boot
79+
test context, which allows us to perform integration testing. In our tests, we utilize the Testcontainers
80+
library (https://java.testcontainers.org/) for managing Docker containers. Specifically, we use Testcontainers to start
81+
PostgreSQL and Keycloak Docker containers locally.
82+
83+
Before running the tests, please ensure that you have Docker runtime installed and that you have the necessary
84+
permissions to run containers.
85+
86+
Alternative, you can skip test during the build with ``` ./gradlew clean build -x test```
87+
88+
#### 2. Database migration related issue
89+
90+
We have implemented database migration using Liquibase (https://www.liquibase.org/). Liquibase allows us to manage
91+
database schema changes effectively.
92+
93+
In case you encounter any database-related issues, you can resolve them by following these steps:
94+
95+
1. Delete all tables from the database.
96+
2. Restart the application.
97+
3. Upon restart, the application will recreate the database schema from scratch.
98+
99+
This process ensures that any issues with the database schema are resolved by recreating it in a fresh state.
100+
101+
## Environment Variables <a id= "environmentVariables"></a>
102+
103+
| name | description | default value |
104+
|--------------------------------|-------------------------------------------------|----------------------------|
105+
| APP_PORT | port number of application | 8080 |
106+
| SECURITY_ENABLE | To keep spring security enable/disable | true |
107+
| KEYCLOAK_REALM_NAME | Realm name of keycloak | SWD |
108+
| KEYCLOAK_CLIENT_ID | Keycloak public client id | pb_backend |
109+
| KEYCLOAK_ROLE_CLIENT_ID | Keycloak private client id | pb_backend |
110+
| KEYCLOAK_AUTH_URL | Keycloak server url | http://localhost:9090/auth |
111+
| DB_HOST | Database host | localhost |
112+
| DB_PORT | Port of database | 5432 |
113+
| DB_NAME | Database name | multi-module-demo |
114+
| USE_SSL | Whether SSL is enabled in database server | false |
115+
| DB_USER | Database username | |
116+
| DB_PASSWORD | Database password | |
117+
| MULTIPART_MAX_FILE_SIZE | Max multiple file size | 50 MB |
118+
| MULTIPART_MAX_REQUEST_SIZE | Max multiple part request size | 51 MB |
119+
| RETRY_CONNECTION_TIMEOUT_MILLI | Duration in millis for retry connection timeout | 200 |
120+
| RETRY_READ_TIMEOUT_MILLI | Duration for read timeout | 500 |
121+
| RETRY_MAX_IDLE_CONNECTION | Duration for idle connection | 10 |
122+
| RETRY_ALIVE_DURATION_MIN | Duration for retry alive | 5 |
123+
| RETRY_MAX_ATTEMPT | Max retry attempt | 5 |
124+
| RETRY_INTERVAL_MILLI | Duration between retry | 2000 |
125+
126+
## Reference of external lib
127+
128+
1. https://www.testcontainers.org/modules/databases/postgres/
129+
2. https://github.com/dasniko/testcontainers-keycloak
130+
3. https://github.com/smartSenseSolutions/smartsense-java-commons
131+

ss-web/src/main/java/ss/mod/demo/SWMainApplication.java renamed to ss-web/src/main/java/ss/mod/demo/MainApplication.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717
* @author Sunil Kanzar
1818
* @since 14th feb 2024
1919
*/
20-
@SpringBootApplication(scanBasePackages = {"ss.mod.demo", "com.smartsensesolutions"})
20+
@SpringBootApplication(scanBasePackages = { "ss.mod.demo", "com.smartsensesolutions" })
2121
@ConfigurationPropertiesScan
2222
@EnableJpaAuditing(auditorAwareRef = "auditorAware")
2323
@EnableAsync
2424
@EnableFeignClients
2525
@EnableScheduling
26-
public class SWMainApplication {
26+
public class MainApplication {
2727

2828
public static void main(String[] args) {
29-
SpringApplication.run(SWMainApplication.class, args);
29+
SpringApplication.run(MainApplication.class, args);
3030
}
3131

3232
}

ss-web/src/main/resources/application.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ app:
1919
name: ${DB_NAME:multi-module-demo}
2020
username: ${DB_USER:root}
2121
password: ${DB_PASSWORD:root}
22+
useSSL: ${USE_SSL:false}
2223
swagger:
2324
clientId: ${KEYCLOAK_CLIENT_ID:swd_public_client}
2425
multipart:
@@ -90,7 +91,7 @@ spring:
9091
database-platform: org.hibernate.dialect.PostgreSQLDialect
9192
show-sql: false
9293
datasource:
93-
url: jdbc:postgresql://${app.database.host}:${app.database.port}/${app.database.name}
94+
url: jdbc:postgresql://${app.database.host}:${app.database.port}/${app.database.name}?useSSL=${app.database.useSSL}
9495
username: ${app.database.username}
9596
password: ${app.database.password}
9697
driverClassName: org.postgresql.Driver

ss-web/src/test/java/ss/mod/demo/util/ContainerContextInitializer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ static String createToken(boolean validUser) {
4343
}
4444
String access_token = keycloakBuilder.build().tokenManager().getAccessToken().getToken();
4545
return BEARER + access_token;
46+
4647
}
4748

4849
@Override

ss-web/src/test/java/ss/mod/demo/web/UserManagementResourceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import org.springframework.test.context.ActiveProfiles;
1818
import org.springframework.test.context.ContextConfiguration;
1919
import org.springframework.test.context.transaction.BeforeTransaction;
20-
import ss.mod.demo.SWMainApplication;
20+
import ss.mod.demo.MainApplication;
2121
import ss.mod.demo.api.constant.ContURI;
2222
import ss.mod.demo.api.model.request.UserRequest;
2323
import ss.mod.demo.api.model.response.ResponseBody;
@@ -28,7 +28,7 @@
2828
import ss.mod.demo.util.constant.TestDataUtil;
2929

3030

31-
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { SWMainApplication.class })
31+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { MainApplication.class })
3232
@ActiveProfiles("test")
3333
@ContextConfiguration(initializers = { ContainerContextInitializer.class })
3434
@TestInstance(TestInstance.Lifecycle.PER_CLASS)

0 commit comments

Comments
 (0)