Test extension with configuration

This commit is contained in:
Bossanyi Tibor 2020-05-10 11:00:42 +02:00
parent 9fd319e8be
commit 49afafd008
4 changed files with 200 additions and 11 deletions

View File

@ -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

87
docker.development.yml Normal file
View File

@ -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:

View File

@ -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()
//}
}
}

View File

@ -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
}