Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
gtiwari333 committed Dec 25, 2023
2 parents c3b3fb9 + 0865627 commit c0abf59
Show file tree
Hide file tree
Showing 56 changed files with 383 additions and 175 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:

steps:
- uses: actions/checkout@v2
- uses: browser-actions/setup-firefox@v1
- uses: browser-actions/setup-edge@v1

- name: Set up JDK 19
- name: Set up JDK 21
uses: actions/setup-java@v1
with:
java-version: 19
java-version: 21

- name: Build with Maven
run: mvn -B verify --file pom.xml
31 changes: 17 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#### Variations
- Simpler version without KeyCloak and multi-modules is on separate project https://github.com/gtiwari333/spring-boot-blog-app
- Microservice example that uses Spring Cloud features(discovery, gateway, config server etc) is on separate project https://github.com/gtiwari333/spring-boot-microservice-example-java


### App Architecture:
Expand Down Expand Up @@ -62,7 +63,7 @@ Misc:
- Nested comment
- Cache implemented
- Zipkin tracing

- Websocket implemented to show article/comment review status/notifications..

Future: do more stuff
- CQRS with event store/streaming
Expand All @@ -83,7 +84,6 @@ Future: do more stuff
- nested comment query/performance fix
- Signup UI
- vendor neutral security with OIDC
- realtime approval UI
- JfrUnit ( WIP )
-
### Requirements
Expand All @@ -92,7 +92,9 @@ Future: do more stuff
- http://ganeshtiwaridotcomdotnp.blogspot.com/2016/03/configuring-lombok-on-intellij.html
- For eclipse, download the lombok jar, run it, and point to eclipse installation
- Maven
- Docker
- Docker
- Make sure docker is started and running
- Run `$ sudo chmod 666 /var/run/docker.sock` if you get error like this "Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? (Details: [13] Permission denied)"

#### How to Run

Expand All @@ -108,7 +110,7 @@ It contains following applications:

Option 1 - run with manually started ActiveMQ and MySQL servers
- Run ```mvn clean install``` at root
- Run ```docker-compose -f _config/docker-compose.yml up``` at root to start docker containers
- Run ```docker-compose -f config/docker-compose.yml up``` at root to start docker containers
- Go to main-app folder and run ```mvn``` to start the application

Option 2 - automatically start ActiveMQ and MySQL using TestContainer while application is starting
Expand All @@ -120,19 +122,21 @@ Option 3 - run from IDE
- Update run configuration to run maven goal `wro4j:run` Before Launch. It should be after 'Build'


## Run Tests
## Run Tests (use ./mvnw instead of mvn if you want to use maven wrapper)

## It uses TestContainers, which requires Docker to be installed locally.

##### Running full tests

`./mvnw clean verify`
`mvn clean verify`

##### Running unit tests only (it uses maven surefire plugin)

`./mvnw compiler:testCompile resources:testResources surefire:test`
`mvn compiler:testCompile resources:testResources surefire:test`

##### Running integration tests only (it uses maven-failsafe-plugin)

`./mvnw compiler:testCompile resources:testResources failsafe:integration-test`
`mvn compiler:testCompile resources:testResources failsafe:integration-test`

## Code Quality

Expand All @@ -146,8 +150,8 @@ Run sonarqube server using docker
`docker run -e SONAR_ES_BOOTSTRAP_CHECKS_DISABLE=true -p 9000:9000 sonarqube:latest`

Perform scan:
`./mvnw sonar:sonar`
./mvnw sonar:sonar -Dsonar.login=admin -Dsonar.password=admin
`mvn sonar:sonar`
mvn sonar:sonar -Dsonar.login=admin -Dsonar.password=admin

View Reports in SonarQube web ui:

Expand All @@ -160,13 +164,12 @@ View Reports in SonarQube web ui:

### Dependency vulnerability scan

Owasp dependency check plugin is configured. Run `./mvnw dependency-check:check` to run scan and
Owasp dependency check plugin is configured. Run `mvn dependency-check:check` to run scan and
open `dependency-check-report.html` from target to see the report.


## Run Tests Faster using Maven Daemon + parallel run

`mvnd test -Dparallel=all -DperCoreThreadCount=false -DthreadCount=4 -o`
## Run Tests Faster by using parallel maven build
`mvn -T 5 clean package`


Once the application starts, open `http://localhost:8081` on your browser. The default username/passwords are listed on : gt.app.Application.initData, which are:
Expand Down
13 changes: 8 additions & 5 deletions _config/docker-compose.yml → config/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
version: '3'
services:
activemq_artemis:
image: 'jhatdv/activemq-artemis:2.19.1-alpine'
# its not supported in M1 Mac, workaround is to enable Rosetta in Docker
# Docker settings → Features in development → check ☑ Use Rosetta for x86/amd64 emulation on Apple Silicon, and then restart Docker.
image: 'apache/activemq-artemis:2.31.2-alpine'
container_name: activemqArtemis
environment:
- ARTEMIS_USERNAME=admin
- ARTEMIS_USER=admin
- ARTEMIS_PASSWORD=admin
ports:
- 8161:8161 # use this to login
- 8161:8161 # use this to access from browser
- 61616:61616
networks:
- seedappnet
mysql:
image: 'mysql:8.0.30'
image: 'mysql:8.0.35'
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_DATABASE=seedapp
Expand All @@ -22,10 +24,11 @@ services:
networks:
- seedappnet
emailhog:
image: 'mailhog/mailhog'
image: 'richarvey/mailhog'
container_name: mailhog
ports:
- 1025:1025
- 8025:8025 # use this to access from browser
networks:
- seedappnet
zipkin:
Expand Down
8 changes: 8 additions & 0 deletions content-checker/content-checker-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${springdoc-openapi-ui.version}</version>
<optional>true</optional>
</dependency>
</dependencies>
<properties>
<spring.profiles.active>dev</spring.profiles.active>
<build.profile>dev</build.profile>
Expand Down
5 changes: 0 additions & 5 deletions email/email-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,6 @@
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class TestContainerConfig {

static {
var mailHog = new GenericContainer<>("mailhog/mailhog");
var mailHog = new GenericContainer<>("richarvey/mailhog");
mailHog.withExposedPorts(1025);
mailHog.start();

Expand Down
2 changes: 2 additions & 0 deletions main-app/main-orm/lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
config.stopBubbling = true
lombok.addLombokGeneratedAnnotation = true
5 changes: 0 additions & 5 deletions main-app/main-orm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,6 @@

</configuration>
<dependencies>
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-hibernate5</artifactId>
<version>${liquibase.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
Expand Down
2 changes: 2 additions & 0 deletions main-app/main-webapp/lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
config.stopBubbling = true
lombok.addLombokGeneratedAnnotation = true
21 changes: 20 additions & 1 deletion main-app/main-webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jooq</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
Expand Down Expand Up @@ -163,6 +167,10 @@
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
</dependency>

<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator-core</artifactId>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
Expand All @@ -171,7 +179,10 @@
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
</dependency>

<dependency>
<groupId>org.webjars.bower</groupId>
<artifactId>jquery-toast-plugin</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down Expand Up @@ -472,6 +483,14 @@
</executions>
</plugin>

<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<configuration>
<targetClasses>gt.app.modules.*</targetClasses>
<targetTests>gt.app.modules.*</targetTests>
</configuration>
</plugin>

</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.net.InetAddress;
import java.net.UnknownHostException;
Expand All @@ -18,6 +19,7 @@
@Slf4j
@EnableConfigurationProperties(AppProperties.class)
@EnableCaching
@EnableScheduling
public class MainApplication {

public static void main(String[] args) throws UnknownHostException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//@Component
@RequiredArgsConstructor
//@Profile("!test")
public class AppHibernatePropertiesCustomizer implements HibernatePropertiesCustomizer {
class AppHibernatePropertiesCustomizer implements HibernatePropertiesCustomizer {

private final HibernateStatInterceptor statInterceptor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@Profile("withTestContainer")
@Configuration
@Slf4j
public class DockerContainerConfig {
class DockerContainerConfig {

/*
Expand All @@ -31,17 +31,17 @@ public class DockerContainerConfig {

String userPwd = "admin";//use same for all

var mysql = new MySQLContainer<>("mysql:8.0.30").withDatabaseName("seedapp").withUsername(userPwd).withPassword(userPwd);
var mysql = new MySQLContainer<>("mysql:8.0.35").withDatabaseName("seedapp").withUsername(userPwd).withPassword(userPwd);
mysql.start();

var activeMQ = new GenericContainer<>("jhatdv/activemq-artemis:2.19.1-alpine");
activeMQ.setEnv(List.of("ARTEMIS_USERNAME=admin", "ARTEMIS_PASSWORD=admin"));
var activeMQ = new GenericContainer<>("apache/activemq-artemis:2.31.2-alpine");
activeMQ.setEnv(List.of("ARTEMIS_USER=admin", "ARTEMIS_PASSWORD=admin"));
activeMQ.withExposedPorts(61616);
activeMQ.start(); //using default ports

setProperty("ACTIVEMQ_ARTEMIS_HOST", activeMQ.getHost());
setProperty("ACTIVEMQ_ARTEMIS_PORT", Integer.toString(activeMQ.getMappedPort(61616)));
setProperty("ACTIVEMQ_ARTEMIS_USERNAME", userPwd);
setProperty("ACTIVEMQ_ARTEMIS_USER", userPwd);
setProperty("ACTIVEMQ_ARTEMIS_PASSWORD", userPwd);

setProperty("MYSQL_HOST", mysql.getHost());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@Configuration
@EnableFeignClients(basePackages = "gt.app.api")
@Import(FeignClientsConfiguration.class)
public class FeignConfiguration {
class FeignConfiguration {

/**
* Set the Feign specific log level to log client REST requests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@Configuration
@EnableJms
public class JMSConfig {
class JMSConfig {

@Bean
public JmsListenerContainerFactory<?> myFactory(ConnectionFactory connectionFactory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
@EnableJpaAuditing //now @CreatedBy, @LastModifiedBy works
@EnableTransactionManagement
@EnableJpaRepositories(basePackages = "gt.app.modules")
public class JpaConfig {
class JpaConfig {
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

@Configuration
@RequiredArgsConstructor
public class WebMvcConfig implements WebMvcConfigurer {
class WebMvcConfig implements WebMvcConfigurer {

private final WebProperties webProperties;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package gt.app.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

@Configuration
@EnableWebSocketMessageBroker
class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker("/topic");
config.setApplicationDestinationPrefixes("/app");
config.setUserDestinationPrefix("/user"); //default is /user
}

@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/app-websockets-main-endpoint");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import org.hibernate.Interceptor;

import java.io.Serial;
import java.io.Serializable;

@Slf4j
public class HibernateStatInterceptor implements Interceptor {
public class HibernateStatInterceptor implements Interceptor, Serializable {

@Serial
private static final long serialVersionUID = -7875557911815131906L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@Configuration
@Profile("!test")
public class RequestStatisticsConfiguration implements WebMvcConfigurer {
class RequestStatisticsConfiguration implements WebMvcConfigurer {

@Bean
public HibernateStatInterceptor hibernateInterceptor() {
Expand Down
Loading

0 comments on commit c0abf59

Please sign in to comment.