This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
Commit ba7d6c8d authored by Michael Breu's avatar Michael Breu :speech_balloon:
Browse files

Fixing SearchTests: Using TestContainers to set up elasticSearch Server

parent 0f1d456f
Branches
2 merge requests!91Bringing JHipster7.6.0 to production,!88Integrating Update to JHipster 7.6.0 back to Development
image: adoptopenjdk/openjdk11
image: jhipster/jhipster:v7.6.0
cache:
key: '$CI_COMMIT_REF_NAME'
......@@ -15,8 +15,6 @@ stages:
before_script:
- export NG_CLI_ANALYTICS="false"
- export MAVEN_USER_HOME=`pwd`/.maven
- ./mvnw -ntp com.github.eirslett:frontend-maven-plugin:install-node-and-npm@install-node-and-npm -Dmaven.repo.local=$MAVEN_USER_HOME
- ./mvnw -ntp com.github.eirslett:frontend-maven-plugin:npm -Dmaven.repo.local=$MAVEN_USER_HOME
nohttp:
stage: check
......@@ -34,9 +32,19 @@ maven-compile:
expire_in: 1 day
maven-test:
# DinD service is required for Testcontainers
services:
- docker:dind
variables:
# Instruct Testcontainers to use the daemon of DinD.
DOCKER_HOST: 'tcp://docker:2375'
# Improve performance with overlayfs.
DOCKER_DRIVER: overlay2
stage: test
script:
- ./mvnw -ntp verify -P-webapp -Dmaven.repo.local=$MAVEN_USER_HOME
- ./mvnw -ntp verify -P-webapp -Dmaven.repo.local=$MAVEN_USER_HOME -Dspring.profiles.active=testcontainers
artifacts:
reports:
junit:
......@@ -51,7 +59,8 @@ maven-test:
frontend-test:
stage: test
script:
- ./mvnw -ntp com.github.eirslett:frontend-maven-plugin:npm -Dfrontend.npm.arguments='run test' -Dmaven.repo.local=$MAVEN_USER_HOME
- npm install
- npm test
artifacts:
reports:
junit: target/test-results/TESTS-results-jest.xml
......@@ -59,6 +68,7 @@ frontend-test:
- target/test-results
- target/jacoco
expire_in: 1 day
sonar-analyze:
stage: analyze
dependencies:
......@@ -77,7 +87,6 @@ maven-package:
- target/*.jar
- target/classes
expire_in: 1 day
# Uncomment the following line to use gitlabs container registry. You need to adapt the REGISTRY_URL in case you are not using gitlab.com
#docker-push:
# stage: release
......
......@@ -109,6 +109,24 @@
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.16.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.16.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>elasticsearch</artifactId>
<version>1.16.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>tech.jhipster</groupId>
<artifactId>jhipster-framework</artifactId>
......
......@@ -2,13 +2,8 @@ package at.ac.uibk.gitsearch.security.jwt;
import static org.assertj.core.api.Assertions.assertThat;
import at.ac.uibk.gitsearch.management.SecurityMetersService;
import at.ac.uibk.gitsearch.properties.ApplicationProperties;
import at.ac.uibk.gitsearch.security.AuthoritiesConstants;
import io.jsonwebtoken.io.Decoders;
import io.jsonwebtoken.security.Keys;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import java.util.Collections;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpStatus;
......@@ -19,6 +14,12 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.test.util.ReflectionTestUtils;
import at.ac.uibk.gitsearch.management.SecurityMetersService;
import at.ac.uibk.gitsearch.security.AuthoritiesConstants;
import io.jsonwebtoken.io.Decoders;
import io.jsonwebtoken.security.Keys;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import tech.jhipster.config.JHipsterProperties;
class JWTFilterTest {
......
......@@ -23,6 +23,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import javax.ws.rs.NotFoundException;
......@@ -38,24 +39,24 @@ import org.gitlab4j.api.GitLabApiException;
import org.gitlab4j.api.RepositoryApi;
import org.hamcrest.MatcherAssert;
import org.junit.Assert;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.security.test.context.support.WithMockUser;
import at.ac.uibk.gitsearch.GitsearchApp;
import at.ac.uibk.gitsearch.IntegrationTest;
import at.ac.uibk.gitsearch.repository.gitlab.GitLabRepository;
import at.ac.uibk.gitsearch.repository.search.testESService.ElasticSearchTestServerConfiguration;
import at.ac.uibk.gitsearch.repository.search.testESService.ElasticSearchTestConfiguration;
import at.ac.uibk.gitsearch.service.PluginManagementService.ConnectorConfigWrapper;
import at.ac.uibk.gitsearch.service.dto.AutoCompleteEntry;
@SpringBootTest(classes = GitsearchApp.class)
@IntegrationTest
@WithMockUser(value = "test", authorities = "sharing")
public class SearchServiceIT {
......@@ -75,10 +76,27 @@ public class SearchServiceIT {
@Autowired
private SearchService searchService;
@BeforeAll
public static void setUpESServer() throws IOException, NodeValidationException {
ElasticSearchTestServerConfiguration.getTestInstance().startTestNode();
@Autowired
ElasticSearchTestConfiguration elasticSearchTestConfiguration;
static ElasticSearchTestConfiguration staticElasticSearchTestConfiguration;
@BeforeEach // must be started as BeforeEach, in order to autowire the ElasticSearchTestConfiguration
@Timeout(value = 2, unit = TimeUnit.MINUTES)
public void setUpESServer() throws IOException, NodeValidationException {
if(staticElasticSearchTestConfiguration == null) {
elasticSearchTestConfiguration.startTestNode();
staticElasticSearchTestConfiguration = elasticSearchTestConfiguration;
}
}
@AfterAll
public static void shutDownESServer() {
if(staticElasticSearchTestConfiguration!=null) {
staticElasticSearchTestConfiguration.stopTestContainer();
staticElasticSearchTestConfiguration = null;
}
}
@BeforeEach
......
{
"idx_metadata_1": {
"aliases": {
"metadata": {
"is_write_index": true
}
},
"settings": {
"index.mapping.total_fields.limit": "2000",
"number_of_shards": "1"
}
},
"mappings": {
"_doc": {
"properties": {
"file": {
"properties": {
......@@ -225,6 +213,5 @@
}
}
}
}
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment