From 49afafd00801ac91355ad29f7da82d39a9c87eb0 Mon Sep 17 00:00:00 2001 From: Bossanyi Tibor Date: Sun, 10 May 2020 11:00:42 +0200 Subject: [PATCH] Test extension with configuration --- .gitlab-ci.yml | 22 ++--- docker.development.yml | 87 ++++++++++++++++++ .../com/aitrainer/api/test/AitrainerDBTest.kt | 90 +++++++++++++++++++ .../api/test/ApplicationConfiguration.kt | 12 +++ 4 files changed, 200 insertions(+), 11 deletions(-) create mode 100644 docker.development.yml create mode 100644 src/test/kotlin/com/aitrainer/api/test/AitrainerDBTest.kt create mode 100644 src/test/kotlin/com/aitrainer/api/test/ApplicationConfiguration.kt diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3983d35..539e5f4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -24,17 +24,17 @@ cache: - .gradle/wrapper - .gradle/caches -build: - stage: build - image: openjdk:latest - script: - - ./gradlew assemble - artifacts: - paths: - - build/libs/*.jar - expire_in: 1 week - only: - - master +#build: +# stage: build +# image: openjdk:latest +# script: +# - ./gradlew assemble +# artifacts: +# paths: +# - build/libs/*.jar +# expire_in: 1 week +# only: +# - master connect: stage: prepare diff --git a/docker.development.yml b/docker.development.yml new file mode 100644 index 0000000..77d6753 --- /dev/null +++ b/docker.development.yml @@ -0,0 +1,87 @@ +version: '3.8' +services: + jira: + image: 'atlassian/jira-software:latest' + container_name: 'jira' + restart: 'always' + volumes: + - jiraVolume:/var/atlassian/application-data/jira + - db_data:/var/lib/mysql + ports: + - 8082:80 + gitlab: + image: 'gitlab/gitlab-ce:latest' + container_name: 'gitlab' + restart: always + hostname: 'localhost' + environment: + GITLAB_OMNIBUS_CONFIG: | + external_url 'https://andio.club:443' + gitlab_rails['smtp_enable'] = true + gitlab_rails['smtp_address'] = "email-smtp.eu-west-1.amazonaws.com" + gitlab_rails['smtp_port'] = 587 + gitlab_rails['smtp_user_name'] = "AKIAIWHHQDMPADT7ETHQ" + gitlab_rails['smtp_password'] = "AjCB8NA+61i/URp09gik0HHtbEuy48e4JXhuPaqGacFs" + gitlab_rails['smtp_domain'] = "andio.club" + gitlab_rails['smtp_authentication'] = "login" + gitlab_rails['smtp_enable_starttls_auto'] = true + gitlab_rails['smtp_openssl_verify_mode'] = 'peer' + # Add any other gitlab.rb configuration here, each on its own line + gitlab_rails['gitlab_shell_ssh_port'] = 6622 + ports: + - '80:80' + - '443:443' + - '6622:22' + - '587:587' + volumes: + - '/srv/gitlab/config:/etc/gitlab' + - '/srv/gitlab/logs:/var/log/gitlab' + - '/srv/gitlab/data:/var/opt/gitlab' + mysql: + image: mysql:latest + volumes: + - db_data:/var/lib/mysql + restart: always + ports: + - 33061:33061 + environment: + MYSQL_ROOT_PASSWORD: andio2009 + MYSQL_DATABASE: aitrainer + MYSQL_USER: aitrainer + MYSQL_PASSWORD: andio2009 + networks: + - bosi_default + phpmyadmin: + depends_on: + - mysql + image: phpmyadmin/phpmyadmin + restart: always + ports: + - '8081:80' + environment: + PMA_HOST: mysql + MYSQL_ROOT_PASSWORD: andio2009 + networks: + - bosi_default + php: + image: php:7.2-fpm + volumes: + - php:/var/www/html + - ./php/php.ini:/usr/local/etc/php/php.ini + depends_on: + - mysql + gitlab-runner: + image: gitlab/gitlab-runner:latest + container_name: gitlab-runner + restart: always + networks: + - bosi_default + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - /srv/gitlab-runner/config:/etc/gitlab-runner +networks: + bosi_default: +volumes: + db_data: + php: + jiraVolume: \ No newline at end of file diff --git a/src/test/kotlin/com/aitrainer/api/test/AitrainerDBTest.kt b/src/test/kotlin/com/aitrainer/api/test/AitrainerDBTest.kt new file mode 100644 index 0000000..253d387 --- /dev/null +++ b/src/test/kotlin/com/aitrainer/api/test/AitrainerDBTest.kt @@ -0,0 +1,90 @@ +package com.aitrainer.api.test + +import org.springframework.beans.factory.annotation.Autowired + +import java.sql.* +import kotlin.test.assertFails + +import java.util.* +import kotlin.test.assertNotNull +import kotlin.test.assertTrue + + +class AitrainerDBTest(configuration: ApplicationConfiguration) { + + + @Autowired + private lateinit var username: String; + private lateinit var password: String; + private lateinit var datasourceUrl: String; + private lateinit var conn: Connection + private val conf: ApplicationConfiguration = configuration + + fun initDB() { + this.username = this.conf.username.orEmpty() + this.password = this.conf.password.orEmpty() + this.datasourceUrl = this.conf.url.orEmpty() + assertTrue ("username should not be empty", { this.username.isNotEmpty() }) + assertTrue ("password should not be empty", { this.password.isNotEmpty() }) + assertTrue ("url should not be empty", { this.datasourceUrl.isNotEmpty() }) + + this.getConnection() + + assertNotNull({this.conn}, "MySQL connection should not be null") + } + + + private fun executeDBQueries() { + var stmt: Statement? = null + var resultset: ResultSet? = null + try { + stmt = conn.createStatement() + val sql: String = "CREATE DATABASE aitrainer_test;" + if ( stmt.execute( sql ) ) { + + } + //while (resultset!!.next()) { + // println(resultset.getString("Database")) + //} + } catch (ex: SQLException) { + throw Exception(ex) + } finally { + // release resources + if (resultset != null) { + try { + resultset.close() + } catch (sqlEx: SQLException) { + } + } + if (stmt != null) { + try { + stmt.close() + } catch (sqlEx: SQLException) { + throw Exception(sqlEx) + } + } + conn.close() + } + } + /** + * This method makes a connection to MySQL Server + * In this example, MySQL Server is running in the local host (so 127.0.0.1) + * at the standard port 3306 + */ + private fun getConnection() { + val connectionProps = Properties() + connectionProps["user"] = this.username + connectionProps["password"] = this.password + //try { + Class.forName("com.mysql.cj.jdbc.Driver").getDeclaredConstructor().newInstance() + this.conn = DriverManager.getConnection(this.datasourceUrl, connectionProps) + //} catch (ex: SQLException) { + // handle any errors + // ex.printStackTrace() + //} catch (ex: Exception) { + // handle any errors + // ex.printStackTrace() + //} + } + +} \ No newline at end of file diff --git a/src/test/kotlin/com/aitrainer/api/test/ApplicationConfiguration.kt b/src/test/kotlin/com/aitrainer/api/test/ApplicationConfiguration.kt new file mode 100644 index 0000000..2d4438e --- /dev/null +++ b/src/test/kotlin/com/aitrainer/api/test/ApplicationConfiguration.kt @@ -0,0 +1,12 @@ +package com.aitrainer.api.test + +import org.springframework.boot.context.properties.ConfigurationProperties +import org.springframework.stereotype.Component + +@Component +@ConfigurationProperties(prefix = "spring.datasource") +class ApplicationConfiguration { + open var username: String? = null + open var password: String? = null + open var url: String? = null +} \ No newline at end of file