diff --git a/build.gradle b/build.gradle deleted file mode 100644 index d101a6064..000000000 --- a/build.gradle +++ /dev/null @@ -1,181 +0,0 @@ -plugins { - id 'org.springframework.boot' - id 'io.spring.dependency-management' - id "org.jetbrains.kotlin.jvm" - id "org.jetbrains.kotlin.plugin.spring" - id "org.jetbrains.kotlin.plugin.jpa" - id "org.jetbrains.kotlin.plugin.allopen" - id "jacoco" - id 'org.sonarqube' version "3.0" -} - -allOpen { - annotation "javax.persistence.Entity" - annotation "javax.persistence.MappedSuperclass" - annotation "javax.persistence.Embeddable" -} - -repositories { - mavenCentral() -} - -dependencies { - implementation "io.kotest:kotest-assertions:$kotestAssertionsVerstion" - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion" - implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion" - implementation "org.springframework.boot:spring-boot-starter-web" - implementation "org.springframework.boot:spring-boot-starter-actuator" - implementation "org.springframework.boot:spring-boot-starter-data-jpa" - implementation "org.springframework.boot:spring-boot-starter-batch" - implementation "org.springframework.boot:spring-boot-starter-security" - implementation "org.springframework.boot:spring-boot-starter-validation" - implementation "org.springframework.security:spring-security-test" - implementation "org.springframework.boot:spring-boot-devtools" - implementation "org.postgresql:postgresql" - implementation "org.flywaydb:flyway-core:$flywayVersion" - - /* Firebase admin */ - implementation group: 'com.google.firebase', name: 'firebase-admin', version: '7.3.0' - - implementation "com.auth0:java-jwt:3.10.3" - implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-csv" - - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2' - implementation "org.apache.logging.log4j:log4j-api-kotlin:$log4jApiKotlinVersion" - - implementation "io.springfox:springfox-swagger-ui:2.10.5" - implementation "io.springfox:springfox-swagger2:2.9.2" - - implementation 'com.amazonaws:aws-java-sdk:1.11.808' - implementation 'com.google.cloud:google-cloud-storage:1.110.0' - - implementation "org.json:json:$jsonVersoin" - implementation 'net.bramp.ffmpeg:ffmpeg:0.6.2' - - testImplementation "org.springframework.boot:spring-boot-starter-webflux" - testImplementation 'org.amshove.kluent:kluent:1.68' //should be deleted after kotest move all of it - testImplementation "org.jetbrains.kotlin:kotlin-test:1.3.72" //should be deleted after kotest move all of it - testImplementation "io.kotest:kotest-assertions:$kotestAssertionsVerstion" - testImplementation "io.kotest:kotest-assertions-core:$kotestAssertionsVerstion" - - testImplementation("org.springframework.boot:spring-boot-starter-test") { - exclude group: "junit" - } - testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion" - testImplementation "io.mockk:mockk:$mockkVersion" - testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion" - testCompile "org.junit.jupiter:junit-jupiter-params:$junitVersion" - - testImplementation("org.testcontainers:testcontainers") - testImplementation "com.natpryce:hamkrest:1.8.0.1" - testImplementation "org.testcontainers:junit-jupiter:$testContainersVersion" - testImplementation "org.testcontainers:postgresql:$testContainersVersion" -} - -compileKotlin { - kotlinOptions { - freeCompilerArgs = ["-Xjsr305=strict"] - jvmTarget = "1.8" - } -} - -compileTestKotlin { - kotlinOptions { - freeCompilerArgs = ["-Xjsr305=strict"] - jvmTarget = "1.8" - } -} - -// --- ktlint - kotlin code style plugin --- -configurations { - ktlint -} - -dependencies { - ktlint "com.pinterest:ktlint:0.38.0" -} - -task ktlintFormat(type: JavaExec, group: "formatting") { - description = "Fix Kotlin code style deviations." - classpath = configurations.ktlint - main = "com.pinterest.ktlint.Main" - args "-F", "src/**/*.kt" -} - -project.task("ktlint", type: JavaExec) { - group = "verification" - description = "Runs ktlint." - main = "com.pinterest.ktlint.Main" - classpath = project.configurations.ktlint - args = [ - "--reporter=plain", - "--reporter=checkstyle,output=${project.buildDir}/reports/ktlint/ktlint-checkstyle-report.xml", - "src/**/*.kt" - ] -} - -project.exec { - commandLine = "git config core.hooksPath .githooks".split(" ") -} - -compileKotlin.dependsOn ktlint - -test { - useJUnitPlatform { options -> - options.excludeTags "integration-test" - } -} - -tasks.test { - finalizedBy(tasks.jacocoTestReport) -} - -tasks.jacocoTestReport { - dependsOn(tasks.test) - - reports { - xml.enabled true - html.enabled true - xml.destination = file(getBuildDir().toString() + File.separator.toString() + "jacoco" + File.separator.toString() + "coverage.xml") - csv.enabled false - html.destination = file(getBuildDir().toString() + File.separator.toString() + "jacoco" + File.separator.toString() + "html") - } - afterEvaluate { - classDirectories.setFrom(files(classDirectories.files.collect { - fileTree(dir: it, exclude: [ - 'com/epam/brn/dto/**', - 'com/epam/brn/model/**', - 'com/epam/brn/config/**', - 'com/epam/brn/exception/**', - 'com/epam/brn/Application*' - ]) - })) - } - getExecutionData().setFrom("$buildDir/jacoco/test.exec") -} - -task integrationTest(type: Test) { task -> - task.useJUnitPlatform { JUnitPlatformOptions options -> - options.includeTags "integration-test" - } - task.shouldRunAfter tasks.test - group 'Verification' - description 'Runs the integration tests on Postgres Test Container.' -} - -sonarqube { - properties { - // Root project information - property 'sonar.projectKey', 'Brain-up_brn' - property 'sonar.organization', 'brain-up' - property 'sonar.host.url', 'https://sonarcloud.io' - - property 'sonar.coverage.jacoco.xmlReportPaths', "./build/jacoco/coverage.xml" - property 'sonar.language','kotlin' - property "sonar.java.coveragePlugin", "jacoco" - property 'sonar.working.directory', "./build/sonar" - property 'sonar.coverage.exclusions', "**/com/epam/brn/dto/**,**/com/epam/brn/model/**," + - "**/com/epam/brn/config/**,**/com/epam/brn/exception/**,**/com/epam/brn/Application*," + - "**/com/epam/brn/service/load/InitialDataLoader*,**/com/epam/brn/service/load/FirebaseUserDataLoader*" - } -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 000000000..dc3cafbfb --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,194 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +val kotestAssertionsVerstion: String by properties +val kotlinVersion: String by properties +val flywayVersion: String by properties +val log4jApiKotlinVersion: String by properties +val jsonVersoin: String by properties +val junitVersion: String by properties +val mockkVersion: String by properties +val testContainersVersion: String by properties + +val ktlint by configurations.creating + +plugins { + id("org.springframework.boot") + id("io.spring.dependency-management") + kotlin("jvm") + kotlin("plugin.spring") + kotlin("plugin.jpa") + id("org.jetbrains.kotlin.plugin.allopen") + jacoco + id("org.sonarqube") version "3.0" +} + +allOpen { + annotation("javax.persistence.Entity") + annotation("javax.persistence.MappedSuperclass") + annotation("javax.persistence.Embeddable") +} + +repositories { + mavenCentral() +} + +dependencies { + implementation("io.kotest:kotest-assertions:$kotestAssertionsVerstion") + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") + implementation("org.jetbrains.kotlin:kotlin-reflect") + implementation("org.springframework.boot:spring-boot-starter-web") + implementation("org.springframework.boot:spring-boot-starter-actuator") + implementation("org.springframework.boot:spring-boot-starter-data-jpa") + implementation("org.springframework.boot:spring-boot-starter-batch") + implementation("org.springframework.boot:spring-boot-starter-security") + implementation("org.springframework.boot:spring-boot-starter-validation") + implementation("org.springframework.security:spring-security-test") + implementation("org.springframework.boot:spring-boot-devtools") + implementation("org.postgresql:postgresql") + implementation("org.flywaydb:flyway-core:$flywayVersion") + + /* Firebase admin */ + implementation("com.google.firebase:firebase-admin:7.3.0") + + implementation("com.auth0:java-jwt:3.10.3") + implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-csv") + + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2") + implementation("org.apache.logging.log4j:log4j-api-kotlin:$log4jApiKotlinVersion") + + implementation("io.springfox:springfox-swagger-ui:2.10.5") + implementation("io.springfox:springfox-swagger2:2.9.2") + + implementation("com.amazonaws:aws-java-sdk:1.11.808") + implementation("com.google.cloud:google-cloud-storage:1.110.0") + + implementation("org.json:json:$jsonVersoin") + implementation("net.bramp.ffmpeg:ffmpeg:0.6.2") + + testImplementation("org.springframework.boot:spring-boot-starter-webflux") + testImplementation("org.amshove.kluent:kluent:1.68") //should be deleted after kotest move all of it + testImplementation("org.jetbrains.kotlin:kotlin-test:1.3.72") //should be deleted after kotest move all of it + testImplementation("io.kotest:kotest-assertions:$kotestAssertionsVerstion") + testImplementation("io.kotest:kotest-assertions-core:$kotestAssertionsVerstion") + + testImplementation("org.springframework.boot:spring-boot-starter-test") { + exclude("junit") + } + testImplementation("org.junit.jupiter:junit-jupiter-api:$junitVersion") + testImplementation("io.mockk:mockk:$mockkVersion") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitVersion") + testImplementation("org.junit.jupiter:junit-jupiter-params:$junitVersion") + + testImplementation("org.testcontainers:testcontainers") + testImplementation("com.natpryce:hamkrest:1.8.0.1") + testImplementation("org.testcontainers:junit-jupiter:$testContainersVersion") + testImplementation("org.testcontainers:postgresql:$testContainersVersion") +} + +tasks.withType { + kotlinOptions { + freeCompilerArgs = listOf("-Xjsr305=strict") + jvmTarget = "1.8" + } +} + +// --- ktlint - kotlin code style plugin --- +configurations { + ktlint +} + +dependencies { + ktlint("com.pinterest:ktlint:0.38.0") +} + +tasks.register("ktlintFormat", JavaExec::class.java) { + description = "Fix Kotlin code style deviations." + group = "formatting" + classpath = ktlint + main = "com.pinterest.ktlint.Main" + args = listOf("-F", "src/**/*.kt") +} + +tasks.register("ktlint", JavaExec::class.java) { + group = "verification" + description = "Runs ktlint." + main = "com.pinterest.ktlint.Main" + classpath = ktlint + args = listOf( + "--reporter=plain", + "--reporter=checkstyle,output=${project.buildDir}/reports/ktlint/ktlint-checkstyle-report.xml", + "src/**/*.kt" + ) +} + +project.exec { + commandLine = "git config core.hooksPath .githooks".split(" ") +} + +tasks.named("compileKotlin") { dependsOn("ktlint") } + +tasks.withType { + useJUnitPlatform { + excludeTags("integration-test") + } +} + +tasks.test { + finalizedBy("jacocoTestReport") +} + +tasks.withType { + dependsOn("test") + + reports { + xml.required.set(true) + html.required.set(true) + xml.outputLocation.set(file("${buildDir}/jacoco/coverage.xml")) + csv.required.set(false) + html.outputLocation.set(file("${buildDir}/jacoco/html")) + } + afterEvaluate { + classDirectories.setFrom(files(classDirectories.files.map { + fileTree(it).apply { + exclude( + "com/epam/brn/dto/**", + "com/epam/brn/model/**", + "com/epam/brn/config/**", + "com/epam/brn/exception/**", + "com/epam/brn/Application*" + ) + } + })) + } + executionData.setFrom("$buildDir/jacoco/test.exec") +} + +task("integrationTest") { + useJUnitPlatform { includeTags("integration-test") } + mustRunAfter(tasks["test"]) + group = "Verification" + description = "Runs the integration tests on Postgres Test Container." +} + +sonarqube { + properties { + // Root project information + property("sonar.projectKey", "Brain-up_brn") + property("sonar.organization", "brain-up") + property("sonar.host.url", "https://sonarcloud.io") + + property("sonar.coverage.jacoco.xmlReportPaths", "./build/jacoco/coverage.xml") + property("sonar.language", "kotlin") + property("sonar.java.coveragePlugin", "jacoco") + property("sonar.working.directory", "./build/sonar") + property( + "sonar.coverage.exclusions", "**/com/epam/brn/dto/**," + + "**/com/epam/brn/model/**," + + "**/com/epam/brn/config/**," + + "**/com/epam/brn/exception/**," + + "**/com/epam/brn/Application*," + + "**/com/epam/brn/service/load/InitialDataLoader*," + + "**/com/epam/brn/service/load/FirebaseUserDataLoader*" + ) + } +} diff --git a/gradle.properties b/gradle.properties index 59c4daaf5..3d00d095c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,8 +1,8 @@ kotlin.code.style=official -springBootVersion=2.4.3 +springBootVersion=2.5.8 springDependencyVersion=1.0.11.RELEASE -kotlinVersion=1.4.20 +kotlinVersion=1.6.10 flywayVersion=6.5.5 junitVersion=5.3.1 mockkVersion=1.12.0 diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index 48f366ec6..000000000 --- a/settings.gradle +++ /dev/null @@ -1,12 +0,0 @@ -pluginManagement { - plugins { - id 'org.springframework.boot' version "$springBootVersion" - id 'io.spring.dependency-management' version "$springDependencyVersion" - id "org.jetbrains.kotlin.jvm" version "$kotlinVersion" - id "org.jetbrains.kotlin.plugin.spring" version "$kotlinVersion" - id "org.jetbrains.kotlin.plugin.jpa" version "$kotlinVersion" - id "org.jetbrains.kotlin.plugin.allopen" version "$kotlinVersion" - } -} - -rootProject.name = 'epam-brn' \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 000000000..2ff5446b4 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,16 @@ +pluginManagement { + val springBootVersion: String by settings + val springDependencyVersion: String by settings + val kotlinVersion: String by settings + + plugins { + id("org.springframework.boot") version springBootVersion + id("io.spring.dependency-management") version springDependencyVersion + kotlin("jvm") version kotlinVersion + kotlin("plugin.spring") version kotlinVersion + kotlin("plugin.jpa") version kotlinVersion + id("org.jetbrains.kotlin.plugin.allopen") version kotlinVersion + } +} + +rootProject.name = "epam-brn" \ No newline at end of file diff --git a/src/test/kotlin/com/epam/brn/service/TokenHelperUtilsTest.kt b/src/test/kotlin/com/epam/brn/service/TokenHelperUtilsTest.kt index 95b11c95c..a7192fdfe 100644 --- a/src/test/kotlin/com/epam/brn/service/TokenHelperUtilsTest.kt +++ b/src/test/kotlin/com/epam/brn/service/TokenHelperUtilsTest.kt @@ -45,7 +45,7 @@ internal class TokenHelperUtilsTest { } @Test - fun `should return null when Authorization header not start with "Bearer "`() { + fun `should return null when Authorization header not start with Bearer`() { // GIVEN every { httpServletRequest.getHeader("Authorization") } returns ("SOME_INFO_TOKEN") // WHEN @@ -56,7 +56,7 @@ internal class TokenHelperUtilsTest { } @Test - fun `should return token data when Authorization header start with "Bearer " and has some info`() { + fun `should return token data when Authorization header start with Bearer and has some info`() { // GIVEN val expectedToken = "SOME_INFO_TOKEN" every { httpServletRequest.getHeader("Authorization") } returns ("Bearer $expectedToken") diff --git a/src/test/kotlin/com/epam/brn/service/UserAccountServiceTest.kt b/src/test/kotlin/com/epam/brn/service/UserAccountServiceTest.kt index eac60ca2e..d8e7765c0 100644 --- a/src/test/kotlin/com/epam/brn/service/UserAccountServiceTest.kt +++ b/src/test/kotlin/com/epam/brn/service/UserAccountServiceTest.kt @@ -407,7 +407,7 @@ internal class UserAccountServiceTest { every { securityContext.authentication } returns authentication every { userAccountRepository.findUserAccountByEmail(email) } returns Optional.of(userAccount) - val returnedListOfHeadphones = userAccountService.getAllHeadphonesForCurrentUser() + val returnedListOfHeadphones = userAccountService.getAllHeadphonesForCurrentUser().toList() // THEN assertThat(returnedListOfHeadphones) diff --git a/src/test/kotlin/com/epam/brn/upload/csv/lopotko/LopotkoProcessorTest.kt b/src/test/kotlin/com/epam/brn/upload/csv/lopotko/LopotkoProcessorTest.kt index 754c41aaa..5eb120896 100644 --- a/src/test/kotlin/com/epam/brn/upload/csv/lopotko/LopotkoProcessorTest.kt +++ b/src/test/kotlin/com/epam/brn/upload/csv/lopotko/LopotkoProcessorTest.kt @@ -63,6 +63,7 @@ internal class LopotkoProcessorTest { 400, words ) + @BeforeEach internal fun setUp() { lopotkoRecordProcessor = LopotkoRecordProcessor( @@ -87,7 +88,7 @@ internal class LopotkoProcessorTest { ofType(String::class) ) } returns Optional.empty() - every { resourceRepositoryMock.saveAll(any()) } returns emptySet() + every { resourceRepositoryMock.saveAll(any>()) } returns emptySet() every { audiometryTaskRepository.findByAudiometryAndFrequencyZoneAndAudiometryGroup( ofType(Audiometry::class),