Skip to content

Commit

Permalink
MAIN-T-84 Add solr indexing for Documents (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanna-eismant authored Apr 7, 2024
1 parent 6196e11 commit cff3cc0
Show file tree
Hide file tree
Showing 31 changed files with 930 additions and 252 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: tests

on:
# push:
# branches: [ "main" ]
pull_request:
branches: [ "main" ]

Expand All @@ -10,6 +12,21 @@ defaults:

jobs:

qodana:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
args: --project-dir,server,--baseline,qodana.sarif.json
- name: 'Qodana Scan'
uses: JetBrains/[email protected]
env:
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}

unit:
runs-on: ubuntu-latest
permissions:
Expand Down
33 changes: 14 additions & 19 deletions .space.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,29 @@ job("Tests for main branch") {
}

val sharedCoveragePath = "coverage"
container(displayName = "Coverage", image = gradleImageVersion) {
workDir = "server"
container(displayName = "Unit tests with coverage", image = gradleImageVersion) {
shellScript {
content = """
./gradlew koverVerify
mkdir ${'$'}JB_SPACE_FILE_SHARE_PATH/$sharedCoveragePath
cd build/kover/bin-reports
cp -a . ${'$'}JB_SPACE_FILE_SHARE_PATH/$sharedCoveragePath
cd ${'$'}JB_SPACE_FILE_SHARE_PATH/$sharedCoveragePath
ls -la
""".trimIndent()
cd server
./gradlew koverVerify
mkdir ${'$'}JB_SPACE_FILE_SHARE_PATH/$sharedCoveragePath
cd build/kover/bin-reports
cp -a . ${'$'}JB_SPACE_FILE_SHARE_PATH/$sharedCoveragePath
cd ${'$'}JB_SPACE_FILE_SHARE_PATH/$sharedCoveragePath
ls -la
""".trimIndent()
}
}

container(displayName = "Qodana scan", image = "jetbrains/qodana-jvm:latest") {
env["QODANA_TOKEN"] = "{{ project:qodana-token }}"
shellScript {
content = """
qodana \
--coverage-dir ${'$'}JB_SPACE_FILE_SHARE_PATH/$sharedCoveragePath
""".trimIndent()
}
}

container(displayName = "Unit tests", image = gradleImageVersion) {
workDir = "server"
kotlinScript { api ->
api.gradlew("test")
qodana \
--project-dir server \
--baseline qodana.sarif.json \
--coverage-dir ${'$'}JB_SPACE_FILE_SHARE_PATH/$sharedCoveragePath
""".trimIndent()
}
}

Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[![tests](https://github.com/hanna-eismant/doky/actions/workflows/gradle.yml/badge.svg)](https://github.com/hanna-eismant/doky/actions/workflows/gradle.yml)

Swagger documentation url:

`http://{host}/swagger-ui/index.html`

API docs as json:

`http://{host}/api-docs`
674 changes: 674 additions & 0 deletions server/LICENSE

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions server/README.md

This file was deleted.

7 changes: 4 additions & 3 deletions server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ dependencies {

implementation 'org.flywaydb:flyway-core:9.21.0'
implementation 'org.flywaydb:flyway-mysql:9.21.0'
implementation 'mysql:mysql-connector-java:8.0.33'
implementation 'com.mysql:mysql-connector-j:8.3.0'

implementation 'io.jsonwebtoken:jjwt-api:0.11.2'
implementation 'io.jsonwebtoken:jjwt-impl:0.11.2'
Expand All @@ -56,7 +56,8 @@ dependencies {
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-joda:2.13.1'
implementation 'commons-io:commons-io:2.11.0'

implementation 'com.azure:azure-storage-blob:12.22.1'
implementation 'com.azure:azure-storage-blob:12.25.2'
implementation 'org.apache.solr:solr-solrj:9.5.0'

implementation 'net.logstash.logback:logstash-logback-encoder:7.4'

Expand Down Expand Up @@ -105,7 +106,7 @@ testing {
implementation 'org.springframework.boot:spring-boot-starter-test'

implementation 'com.icegreen:greenmail:2.0.1'

implementation 'org.apache.solr:solr-solrj:9.5.0'
}
}
apiTest(JvmTestSuite) {
Expand Down
File renamed without changes.
File renamed without changes.

This file was deleted.

29 changes: 0 additions & 29 deletions server/src/apiTest/resources/application-test.properties

This file was deleted.

11 changes: 0 additions & 11 deletions server/src/apiTest/resources/application.properties

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.hkurh.doky

import org.junit.jupiter.api.Tag
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.ActiveProfiles
import org.springframework.test.context.jdbc.Sql
import org.springframework.test.context.jdbc.SqlMergeMode

@ActiveProfiles("test")
@Tag("integration")
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@SqlMergeMode(SqlMergeMode.MergeMode.MERGE)
@Sql(scripts = ["classpath:sql/create_base_test_data.sql"], executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = ["classpath:sql/cleanup_base_test_data.sql"], executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
class DokyIntegrationTest {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.hkurh.doky

import com.icegreen.greenmail.configuration.GreenMailConfiguration
import com.icegreen.greenmail.util.GreenMail
import com.icegreen.greenmail.util.ServerSetup
import org.junit.jupiter.api.extension.AfterAllCallback
import org.junit.jupiter.api.extension.BeforeAllCallback
import org.junit.jupiter.api.extension.BeforeTestExecutionCallback
import org.junit.jupiter.api.extension.ExtensionContext
import org.junit.jupiter.api.extension.TestInstancePostProcessor

class SmtpServerExtension : BeforeAllCallback, AfterAllCallback, BeforeTestExecutionCallback,
TestInstancePostProcessor {
private val greenMail = GreenMail(ServerSetup(2525, null, ServerSetup.PROTOCOL_SMTP))

override fun beforeAll(context: ExtensionContext?) {
greenMail.apply {
withConfiguration(GreenMailConfiguration.aConfig().withDisabledAuthentication())
start()
}
}

override fun afterAll(context: ExtensionContext?) {
greenMail.stop()
}

override fun beforeTestExecution(context: ExtensionContext?) {
greenMail.purgeEmailFromAllMailboxes()
}

override fun postProcessTestInstance(testInstance: Any?, context: ExtensionContext?) {
testInstance?.javaClass?.getMethod("setSmtpServer", GreenMail::class.java)?.invoke(testInstance, greenMail)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.hkurh.doky.search

import org.apache.solr.client.solrj.SolrClient
import org.apache.solr.common.params.CommonParams
import org.apache.solr.common.params.ModifiableSolrParams
import org.hkurh.doky.DokyIntegrationTest
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.test.context.jdbc.Sql


@DisplayName("DocumentIndexService integration test")
class DocumentIndexServiceIntegrationTest : DokyIntegrationTest() {

@Value("\${doky.search.solr.core.documents:documents-test}")
lateinit var coreName: String

@Autowired
lateinit var documentIndexer: DocumentIndexService

@Autowired
lateinit var solrClient: SolrClient

@BeforeEach
fun setUp() {
solrClient.deleteByQuery(coreName, "*:*")
}

@Test
@Sql(
scripts = ["classpath:sql/DocumentIndexServiceIntegrationTest/setup.sql"],
executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD
)
@Sql(
scripts = ["classpath:sql/DocumentIndexServiceIntegrationTest/cleanup.sql"],
executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD
)
@DisplayName("Should add to index all documents")
fun shouldAddToIndexAllDocuments() {
// when
documentIndexer.fullIndex()

// then
val solrParams = ModifiableSolrParams()
solrParams.add(CommonParams.Q, "*:*")
assertTrue(solrClient.query(coreName, solrParams).results.size == 4)
}
}
Loading

0 comments on commit cff3cc0

Please sign in to comment.