Skip to content

Commit

Permalink
Rename examples project to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Thijsiez committed Nov 12, 2024
1 parent 9f2202a commit 2b793b7
Show file tree
Hide file tree
Showing 21 changed files with 102 additions and 106 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./examples
working-directory: ./tests
steps:
- uses: actions/checkout@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Release Checklist
- Run all tests to make sure there are no regressions
- Update the `version` in gradle.properties to match this release's tag
- Update all unpinned dependencies in both the library and examples project's gradle.properties
- Update all unpinned dependencies in both the library and tests project's gradle.properties
- Make sure the versions in the README's Requirements section match the used dependency versions
- Add a new section to the CHANGELOG describing what has changed
- Update the versions in the README's Getting Started section
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ A dynamic, type-safe way to write your queries
[Changelog](CHANGELOG.md) | [Contributing](CONTRIBUTING.md)

## Getting Started
Examples given use Gradle's Kotlin DSL
<details open>
<summary><b>Gradle Kotlin DSL</b></summary>

Add the KSP Gradle plugin to your build file
```kotlin
plugins {
Expand Down Expand Up @@ -60,6 +62,7 @@ project.afterEvaluate {
}
}
```
</details>

## Requirements
- Quarkus version `3.9.2` or newer
Expand Down
50 changes: 0 additions & 50 deletions examples/src/main/kotlin/ch/icken/Examples.kt

This file was deleted.

49 changes: 0 additions & 49 deletions examples/src/test/kotlin/ch/icken/model/ExamplesTest.kt

This file was deleted.

File renamed without changes.
6 changes: 6 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# panache-kotlin-dsl Tests
This projects contains integration tests for panache-kotlin-dsl.
These have been pulled into a separate project so KSP can be run like it would be by an implementing project,
and thus produces representative test results.
This also helps in making sure the API provided by panache-kotlin-dsl does not regress,
and that the main project is not cluttered up with code pertaining to code quality scans etc.
5 changes: 2 additions & 3 deletions examples/build.gradle.kts → tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ kover {
filters {
//Exclude non-library classes/packages
excludes {
classes("ch.icken.ExamplesKt")
packages("ch.icken.model")
}
}
Expand All @@ -80,8 +79,8 @@ sonar {
property("sonar.projectName", "panache-kotlin-dsl")
property("sonar.coverage.jacoco.xmlReportPaths", "**/build/reports/kover/report.xml")
//Exclude non-library classes/packages
property("sonar.coverage.exclusions", "**/ch/icken/model/*,**/ch/icken/Examples.kt")
property("sonar.exclusions", "**/ch/icken/model/*,**/ch/icken/Examples.kt")
property("sonar.coverage.exclusions", "**/ch/icken/model/*")
property("sonar.exclusions", "**/ch/icken/model/*")
}
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/settings.gradle.kts → tests/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ pluginManagement {
project(":panache-kotlin-dsl").projectDir = file("..")
}

rootProject.name = "examples"
rootProject.name = "tests"
File renamed without changes.
87 changes: 87 additions & 0 deletions tests/src/test/kotlin/ch/icken/model/QueryTests.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright 2023-2024 Thijs Koppen
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package ch.icken.model

import ch.icken.model.generated.*
import ch.icken.query.*
import io.quarkus.test.junit.QuarkusTest
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertInstanceOf
import org.junit.jupiter.api.Test
import java.time.LocalDate

@QuarkusTest
class QueryTests {

@Test
fun findJohn() {

//WHERE FIRST_NAME = 'John'
//Using type-safe sealed result wrapper
val john = Employee.where { firstName eq "John" }.singleSafe()

assertInstanceOf(PanacheSingleResult.Result::class.java, john)
}

@Test
fun countNotMen() {

//SELECT COUNT(*) FROM EMPLOYEE WHERE GENDER != 'M'
val numberOfNotMen = Employee.count { gender neq Employee.Gender.M }

assertEquals(4, numberOfNotMen)
}

@Test
fun bornBeforeEpoch() {

//WHERE BIRTH_DATE < 1970-01-01
val bornBeforeEpoch = Employee.multiple { birthDate lt LocalDate.EPOCH }

assertEquals(2, bornBeforeEpoch.size)
}

@Test
fun findAllSons() {

//WHERE LAST_NAME LIKE '%son'
//Using find, which allows Panache pagination etc. to be used still
val sons = Employee.find { lastName like "%son" }.list()

assertEquals(2, sons.size)
}

@Test
fun averageSalary() {

//WHERE (SALARY > 50000.0 AND SALARY <= 60000.0)
// OR SALARY BETWEEN 75000.0 AND 85000.0
//Then we take the average using Java 8 streams
val averageSalary = Employee
.where {
salary.gt(50_000.0)
.and { salary lte 60_000.0 }
}
.or { salary.between(75_000.0, 85_000.0) }
.stream()
.mapToDouble { it.salary }
.average()
.orElse(0.0)

assertEquals(67_500.0, averageSalary)
}
}

0 comments on commit 2b793b7

Please sign in to comment.