From ba0657bf6b71001db12ff3f03f422b6d80bd7a90 Mon Sep 17 00:00:00 2001 From: devatherock Date: Thu, 18 May 2023 21:11:20 -0500 Subject: [PATCH] test: Finished writing integration tests Closes #9 --- .circleci/config.yml | 5 ++- CHANGELOG.md | 1 + Makefile | 6 ++- build.gradle | 2 +- docker-compose-remote.yml | 11 +++++ .../RemoteUrlsIntegrationSpec.groovy | 10 +++++ .../controllers/RemoteUrlsSpec.groovy | 40 +++++++++++++++++++ .../controllers/RemoteUrlsTestSpec.groovy | 10 +++++ src/test/resources/application-remote.yml | 5 +++ 9 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 docker-compose-remote.yml create mode 100644 src/integrationTest/groovy/io.github.devatherock/ldapsearch.controllers/RemoteUrlsIntegrationSpec.groovy create mode 100644 src/test/groovy/io/github/devatherock/ldapsearch/controllers/RemoteUrlsSpec.groovy create mode 100644 src/test/groovy/io/github/devatherock/ldapsearch/controllers/RemoteUrlsTestSpec.groovy create mode 100644 src/test/resources/application-remote.yml diff --git a/.circleci/config.yml b/.circleci/config.yml index 5172693..1b0dd59 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -122,7 +122,7 @@ jobs: - attach_workspace: at: ~/ldap-search-api - run: | - make integration-test + make integration-test remote-integration-test - store_test_results: path: build/test-results @@ -165,6 +165,7 @@ workflows: context: - docker-credentials - sonar-credentials + - jumpcloud-credentials requires: - validate_yamls - docker/publish: @@ -182,6 +183,7 @@ workflows: - integration_test: context: - docker-credentials + - jumpcloud-credentials requires: - publish - notify: @@ -221,6 +223,7 @@ workflows: context: - docker-credentials - sonar-credentials + - jumpcloud-credentials <<: *pr_filter requires: - validate_yamls \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index b311827..5c8dbae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Upgraded micronaut to `3.9.1` - Upgraded gradle to `7.6.1` and Java to 17 - Upgraded spotless to `6.18.0` +- Upgraded lombok to `1.18.26` ## [0.3.0] - 2021-08-28 ### Added diff --git a/Makefile b/Makefile index d8334a2..b9e9334 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,11 @@ clean: ./gradlew clean integration-test: docker-compose up & - ./gradlew integrationTest + ./gradlew integrationTest --tests '*ControllerIntegrationSpec*' + docker-compose down +remote-integration-test: + docker-compose -f docker-compose-remote.yml up & + ./gradlew integrationTest --tests '*RemoteUrlsIntegrationSpec*' docker-compose down docker-build: ./gradlew clean build -Dgraalvm=true diff --git a/build.gradle b/build.gradle index efddf63..669153a 100644 --- a/build.gradle +++ b/build.gradle @@ -26,7 +26,7 @@ micronaut { } dependencies { - def lombokVersion = '1.18.16' + def lombokVersion = '1.18.26' annotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion annotationProcessor("io.micronaut.openapi:micronaut-openapi") diff --git a/docker-compose-remote.yml b/docker-compose-remote.yml new file mode 100644 index 0000000..f7f6a09 --- /dev/null +++ b/docker-compose-remote.yml @@ -0,0 +1,11 @@ +version: '3.7' +services: + + ldap-search-api: + image: devatherock/ldap-search-api:latest + network_mode: "host" + environment: + LDAP_HOST: ldaps://ldap.jumpcloud.com:636 + LDAP_USERNAME: $JUMPCLOUD_USERNAME + LDAP_PASSWORD: $JUMPCLOUD_PASSWORD + LDAP_BASE_DN: $JUMPCLOUD_BASE_DN \ No newline at end of file diff --git a/src/integrationTest/groovy/io.github.devatherock/ldapsearch.controllers/RemoteUrlsIntegrationSpec.groovy b/src/integrationTest/groovy/io.github.devatherock/ldapsearch.controllers/RemoteUrlsIntegrationSpec.groovy new file mode 100644 index 0000000..5b750b7 --- /dev/null +++ b/src/integrationTest/groovy/io.github.devatherock/ldapsearch.controllers/RemoteUrlsIntegrationSpec.groovy @@ -0,0 +1,10 @@ +package io.github.devatherock.ldapsearch.controllers + +import io.micronaut.test.extensions.spock.annotation.MicronautTest + +/** + * Integration test that calls remote endpoints + */ +@MicronautTest(propertySources = 'classpath:application-integration.yml', startApplication = false) +class RemoteUrlsIntegrationSpec extends RemoteUrlsSpec { +} diff --git a/src/test/groovy/io/github/devatherock/ldapsearch/controllers/RemoteUrlsSpec.groovy b/src/test/groovy/io/github/devatherock/ldapsearch/controllers/RemoteUrlsSpec.groovy new file mode 100644 index 0000000..e508c01 --- /dev/null +++ b/src/test/groovy/io/github/devatherock/ldapsearch/controllers/RemoteUrlsSpec.groovy @@ -0,0 +1,40 @@ +package io.github.devatherock.ldapsearch.controllers + +import javax.inject.Inject + +import groovy.json.JsonSlurper + +import io.micronaut.http.HttpRequest +import io.micronaut.http.client.HttpClient +import io.micronaut.http.client.annotation.Client +import io.micronaut.http.uri.UriBuilder +import spock.lang.Specification + +/** + * Test that calls remote endpoints. Needed for proper netty SSL reflection config + */ +abstract class RemoteUrlsSpec extends Specification { + + @Inject + @Client('${test.server.url}') + HttpClient httpClient + + JsonSlurper slurper = new JsonSlurper() + + void 'test search - get specific user'() { + when: + String response = httpClient.toBlocking().retrieve( + HttpRequest.GET(UriBuilder.of('/search') + .queryParam('filter', 'uid=test').build()) + ) + + then: + def json = slurper.parseText(response) + json.size() == 1 + json[0]['givenName'] == 'Test' + json[0]['sn'] == 'User' + json[0]['objectClass'].containsAll(['top', 'person', 'organizationalPerson', 'inetOrgPerson']) + json[0]['uid'] == 'test' + json[0]['cn'] == 'Test User' + } +} diff --git a/src/test/groovy/io/github/devatherock/ldapsearch/controllers/RemoteUrlsTestSpec.groovy b/src/test/groovy/io/github/devatherock/ldapsearch/controllers/RemoteUrlsTestSpec.groovy new file mode 100644 index 0000000..0a9f844 --- /dev/null +++ b/src/test/groovy/io/github/devatherock/ldapsearch/controllers/RemoteUrlsTestSpec.groovy @@ -0,0 +1,10 @@ +package io.github.devatherock.ldapsearch.controllers + +import io.micronaut.test.extensions.spock.annotation.MicronautTest + +/** + * Unit test that calls remote endpoints + */ +@MicronautTest(propertySources = ['classpath:application-test.yml', 'classpath:application-remote.yml']) +class RemoteUrlsTestSpec extends RemoteUrlsSpec { +} diff --git a/src/test/resources/application-remote.yml b/src/test/resources/application-remote.yml new file mode 100644 index 0000000..d48e6ca --- /dev/null +++ b/src/test/resources/application-remote.yml @@ -0,0 +1,5 @@ +ldap: + host: ldaps://ldap.jumpcloud.com:636 + username: ${JUMPCLOUD_USERNAME} + password: ${JUMPCLOUD_PASSWORD} + base-dn: ${JUMPCLOUD_BASE_DN} \ No newline at end of file