Skip to content

Commit

Permalink
Merge pull request #23 from devatherock/integration-tests
Browse files Browse the repository at this point in the history
test: Finished writing integration tests
  • Loading branch information
devatherock authored May 19, 2023
2 parents 362a481 + ba0657b commit 37466e0
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -165,6 +165,7 @@ workflows:
context:
- docker-credentials
- sonar-credentials
- jumpcloud-credentials
requires:
- validate_yamls
- docker/publish:
Expand All @@ -182,6 +183,7 @@ workflows:
- integration_test:
context:
- docker-credentials
- jumpcloud-credentials
requires:
- publish
- notify:
Expand Down Expand Up @@ -221,6 +223,7 @@ workflows:
context:
- docker-credentials
- sonar-credentials
- jumpcloud-credentials
<<: *pr_filter
requires:
- validate_yamls
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
11 changes: 11 additions & 0 deletions docker-compose-remote.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
@@ -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'
}
}
Original file line number Diff line number Diff line change
@@ -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 {
}
5 changes: 5 additions & 0 deletions src/test/resources/application-remote.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ldap:
host: ldaps://ldap.jumpcloud.com:636
username: ${JUMPCLOUD_USERNAME}
password: ${JUMPCLOUD_PASSWORD}
base-dn: ${JUMPCLOUD_BASE_DN}

0 comments on commit 37466e0

Please sign in to comment.