Skip to content
Open
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
129 changes: 87 additions & 42 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import org.apache.tools.ant.filters.ReplaceTokens
import org.springframework.cloud.contract.verifier.config.TestFramework

//plugins
plugins {
id 'java'
id 'org.springframework.boot' version '2.5.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'org.springframework.cloud.contract' version '3.0.3'
id 'com.gorylenko.gradle-git-properties' version '2.3.1'
//doc
id 'org.springdoc.openapi-gradle-plugin' version '1.3.3'
id 'org.asciidoctor.jvm.convert' version '3.3.2'
id 'com.github.johnrengelman.processes' version '0.5.0'
// id 'maven-publish'
// Core
id 'jacoco'

// Spring
id 'org.springframework.boot'
id 'io.spring.dependency-management'
id 'org.springframework.cloud.contract'
id 'com.gorylenko.gradle-git-properties'

//doc
id 'org.springdoc.openapi-gradle-plugin'
id 'org.asciidoctor.jvm.convert'
id 'com.github.johnrengelman.processes'

// Tests
id 'com.adarshr.test-logger'
}

group = 'com.neueda.java-blocking-microservice-chassis'
description = 'Java Blocking Microservice Chassis'
version = '0.0.1-SNAPSHOT'
Expand All @@ -22,6 +29,8 @@ ext {
snippetsDir = file 'build/generated-snippets'
springCloudVersion = '2020.0.3'
springDocVersion = '1.5.10'
springRestdocsVersion = '2.0.5.RELEASE'
springBlockSwitchVersion = '0.6.0'
testcontainersVersion = '1.15.3'
managementPort = '8081'
}
Expand Down Expand Up @@ -53,46 +62,63 @@ configurations {
}

repositories {
mavenCentral()
maven { url 'https://repo.spring.io/release' }
}
repositories {

mavenCentral()
maven { url 'https://repo.spring.io/release' }
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator:2.5.3'
implementation 'org.springframework.cloud:spring-cloud-starter-sleuth:3.0.3'
implementation 'org.liquibase:liquibase-core:4.3.5'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa:2.5.3'
implementation 'org.projectlombok:lombok:1.18.20'
implementation 'org.springframework.boot:spring-boot-starter-validation:2.5.3'
implementation 'org.springframework.boot:spring-boot-configuration-processor:2.5.3'
implementation 'org.springframework.boot:spring-boot-starter-web:2.5.3'
implementation 'org.springdoc:springdoc-openapi-ui:1.5.10'
implementation 'jakarta.validation:jakarta.validation-api:2.0.2'
implementation 'io.swagger.core.v3:swagger-models:2.1.9'
implementation 'org.junit.jupiter:junit-jupiter-api:5.7.2'
runtimeOnly 'org.springframework.boot:spring-boot-devtools:2.5.3'
runtimeOnly 'com.h2database:h2:1.4.200'
testImplementation 'org.springframework.boot:spring-boot-starter-test:2.5.3'
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc:2.0.5.RELEASE'
testImplementation 'io.rest-assured:spring-mock-mvc:4.3.3'
testImplementation 'org.postgresql:postgresql:42.2.23'
testImplementation 'org.testcontainers:postgresql:1.16.0'
testImplementation 'org.testcontainers:junit-jupiter:1.16.0'
testImplementation 'org.testcontainers:jdbc:1.16.0'
testImplementation 'org.springframework.cloud:spring-cloud-starter-contract-verifier:3.0.3'
testImplementation 'org.springframework.cloud:spring-cloud-starter-contract-stub-runner:3.0.3'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
mavenBom "org.testcontainers:testcontainers-bom:${testcontainersVersion}"
mavenBom"org.springframework:spring-context:${springVersion}"
mavenBom"org.springdoc:springdoc-openapi-ui:${springdocOpenapiuiVersion}"
}

}

dependencies {
//Used to monitoring and manage application
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.cloud:spring-cloud-starter-sleuth'

// used for Persistence data
implementation 'org.liquibase:liquibase-core'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'

//API Documentation
implementation 'org.springdoc:springdoc-openapi-ui:1.5.10'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you still using the version here?

testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'

//testing
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.rest-assured:spring-mock-mvc'
implementation 'jakarta.validation:jakarta.validation-api'
implementation 'io.swagger.core.v3:swagger-models'

// Development Tools used to develop an application
annotationProcessor 'org.projectlombok:lombok'
annotationProcessor 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-configuration-processor'
runtimeOnly 'com.h2database:h2'
runtimeOnly 'org.springframework.boot:spring-boot-devtools'

//used to build Restfull web
implementation 'org.springframework.boot:spring-boot-starter-web'

//Test Containers
intTestRuntimeOnly 'org.postgresql:postgresql'
intTestImplementation 'org.testcontainers:postgresql'
intTestRuntimeOnly 'org.testcontainers:junit-jupiter'
intTestImplementation 'org.testcontainers:jdbc'

//Contract Testing
testImplementation 'org.springframework.cloud:spring-cloud-starter-contract-verifier'
testImplementation 'org.springframework.cloud:spring-cloud-starter-contract-stub-runner'
implementation 'org.junit.jupiter:junit-jupiter-api'


}
processResources {
eachFile {
if (relativeSourcePath ==~ /^(config\/)?application(-\w+)?.(ya?ml|properties)$/) {
Expand Down Expand Up @@ -154,8 +180,27 @@ contractTest {
test {
useJUnitPlatform { excludeEngines 'junit-vintage' }
outputs.dir snippetsDir
}

finalizedBy jacocoTestReport
}
testlogger {
theme 'mocha'
showExceptions true
showStackTraces true
showFullStackTraces false
showCauses true
slowThreshold 2000
showSummary true
showSimpleNames false
showPassed true
showSkipped true
showFailed true
showStandardStreams false
showPassedStandardStreams true
showSkippedStandardStreams true
showFailedStandardStreams true
logLevel 'lifecycle'
}
jacocoTestReport.dependsOn test
asciidoctor {
// By convention it sets
// sourceDir to src/docs/asciidoc
Expand Down
19 changes: 19 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
org.gradle.daemon=true
org.gradle.caching=false

# Spring Plugin Versions
sprinbBootVersion=2.5.4
springVersion = 5.0.3.RELEASE
springDependencyManagementVersion=1.0.11.RELEASE
springContractVersion=3.0.3
gitPropertiesVersion=2.3.1

# Docs Plugin Versions
gradleProcessesVersion=0.5.0
springdocOpenapiVersion=1.3.3
asciidoctorConvertVersion=3.3.2
springdocOpenapiuiVersion=1.5.10

# Tests Plugin Versions
testLoggerVersion=3.0.0

22 changes: 22 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
pluginManagement {
//plugins
plugins {
// Core
id 'jacoco'

// Spring
id 'org.springframework.boot' version sprinbBootVersion
id 'io.spring.dependency-management' version springDependencyManagementVersion
id 'org.springframework.cloud.contract' version springContractVersion
id 'com.gorylenko.gradle-git-properties' version gitPropertiesVersion

//doc
id 'org.springdoc.openapi-gradle-plugin' version springdocOpenapiVersion
id 'org.springdoc.openapi-ui' version springdocOpenapiuiVersion
id 'org.asciidoctor.jvm.convert' version asciidoctorConvertVersion
id 'com.github.johnrengelman.processes' version gradleProcessesVersion

// Tests
id 'com.adarshr.test-logger' version testLoggerVersion
}
}
rootProject.name = 'java-blocking-microservice-chassis'
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class JavaBlockingMicroserviceChassisApplicationTests {
class JavaBlockingMicroserviceChassisApplicationIT {

@Test
void contextLoads() {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;


@Slf4j
public class PostgresTestContainer {

Expand All @@ -24,4 +23,4 @@ private static void setDatasourceProperties(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.username", postgresContainer::getUsername);
registry.add("spring.datasource.password", postgresContainer::getPassword);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.Set;

import static org.assertj.core.api.BDDAssertions.then;

@DataJpaTest
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
class ChassisRepositoryIT extends PostgresTestContainer {
Expand All @@ -41,7 +40,7 @@ void shouldFindByName() {
List<ChassisEntity> result = underTest.findByName(name);

//then
BDDAssertions.then(result).isEqualTo(expected);
BDDAssertions.then(result).isEqualTo(expected);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.neueda.blocking.chassis.service;


import com.neueda.blocking.chassis.entity.ChassisEntity;
import com.neueda.blocking.chassis.model.Chassis;
import com.neueda.blocking.chassis.repository.ChassisRepository;
Expand All @@ -18,7 +19,7 @@
import static org.mockito.Mockito.when;

@SpringJUnitConfig(ChassisService.class)
class ChassisServiceTests {
class ChassisServiceIT {

@MockBean
private ChassisRepository chassisRepository;
Expand All @@ -32,8 +33,8 @@ void testRetrieveAllChassis()
{
//Given
List<ChassisEntity> chassisEntity = List.of(
new ChassisEntity(1L,"name","description 1"),
new ChassisEntity(2L,"name","description 2"));
new ChassisEntity(1L,"name","description 1"),
new ChassisEntity(2L,"name","description 2"));
when(chassisRepository.findAll())
.thenReturn(chassisEntity);

Expand Down
57 changes: 57 additions & 0 deletions src/intTest/resources/config/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
spring:
main:
banner-mode: off

h2:
console:
enabled: on

sql:
init:
mode: never

liquibase:
enabled: false
change-log: "classpath:/db/changelog/db.changelog-master.xml"
test-rollback-on-update: on

jpa:
show-sql: true
generate-ddl: true
hibernate:
ddl-auto: create-drop

codec:
log-request-details: on

server:
error:
include-exception: on
include-stacktrace: always

client:
base-url: https://mock.server.com

springdoc:
api-docs:
enabled: off

apidoc:
title: Java Blocking Microservice Test
description: Microservice Test for Blocking Restful API with Spring Boot
version: Test

debug: off
trace: off
logging:
level:
root: error
web: trace
sql: trace
org:
springframework:
jdbc:
datasource: trace
liquibase:
database: trace

17 changes: 17 additions & 0 deletions src/intTest/resources/db/changelog/db-test.changelog-master.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.4.xsd">

<preConditions>
<and>
<dbms type="postgresql"/>
<runningAs username="test"/>
</and>
</preConditions>

<include relativeToChangelogFile="true" file="v1/create-table-changelog.xml"/>
<include relativeToChangelogFile="true" file="v1/insert-data-changelog.xml"/>

</databaseChangeLog>
1 change: 1 addition & 0 deletions src/intTest/resources/db/delete_all_chassis_entity.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DELETE FROM chassis_entity;
1 change: 1 addition & 0 deletions src/intTest/resources/db/insert_one_chassis_entity.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO chassis_entity(name, description) VALUES ('integration test', 'description text');
Loading