Skip to content
This repository has been archived by the owner on Apr 30, 2022. It is now read-only.

Commit

Permalink
#605 - Components for Docker database
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-edstrom committed Oct 28, 2021
1 parent 31db5cc commit 2686fe2
Show file tree
Hide file tree
Showing 12 changed files with 160 additions and 43 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
18 changes: 18 additions & 0 deletions Docker/MAQSSQLServer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: '2'

services:
mssql:
image: mcr.microsoft.com/mssql/server:latest
ports:
- 1433:1433
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=magenicMAQS2
- MSSQL_PID=Developer
expose:
- 1433
volumes:
# Mount the current directory onto /mnt/host on the image.
- ./:/mnt/host/
# Run a custom bash script that bootstraps the database after it is started.
command: ['/bin/bash', '/mnt/host/initialize_and_start_sqlserver.sh']
34 changes: 34 additions & 0 deletions Docker/MAQSSQLServer/initialize_and_start_sqlserver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
{
# Wait for SQL Server to start up
# Check if the server is ready
not_ready=1
while [ $not_ready != 0 ]
do
# Wait for the return code of the following statement to be zero
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P magenicMAQS2 -d master -Q "SELECT TOP 1 message_id FROM sys.messages"
not_ready=$?

if [ $not_ready != 0 ]
then
echo "Could not contact sql server, will try again in 5 seconds."
sleep 5s
fi
done

echo "Started initializing database"
# Set up the schema and stored procedures
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P magenicMAQS2 -d master -i `dirname $0`/schema.sql
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P magenicMAQS2 -d master -i `dirname $0`/stored_procedures.sql
# Use BCP to import test data
/opt/mssql-tools/bin/bcp MagenicAutomation.dbo.States in "`dirname $0`/SeedData/MagenicAutomation/States.bcp" \
-n -S localhost -U sa -P magenicMAQS2
/opt/mssql-tools/bin/bcp MagenicAutomation.dbo.Cities in "`dirname $0`/SeedData/MagenicAutomation/Cities.bcp" \
-n -S localhost -U sa -P magenicMAQS2
/opt/mssql-tools/bin/bcp MagenicAutomation.dbo.Datatype in "`dirname $0`/SeedData/MagenicAutomation/Datatype.bcp" \
-n -S localhost -U sa -P magenicMAQS2
echo "Finished initializing database"
}&

# Start SQL server
exec /opt/mssql/bin/sqlservr
31 changes: 31 additions & 0 deletions Docker/MAQSSQLServer/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
CREATE DATABASE MagenicAutomation;
GO
USE MagenicAutomation;
GO
CREATE TABLE [dbo].[States](
[StateID] [int] PRIMARY KEY IDENTITY(1,1) NOT NULL,
[StateName] [nvarchar](max) NOT NULL,
[StateAbbreviation] [nvarchar](2) NULL
);
GO
CREATE TABLE [dbo].[Cities](
[CityID] [int] PRIMARY KEY IDENTITY(1,1) NOT NULL,
[CityName] [nvarchar](max) NOT NULL,
[CityPopulation] [decimal](18, 2)
);
GO
CREATE TABLE [dbo].[Datatype](
[bitintType] [bigint] NULL,
[bitType] [bit] NULL,
[char10Type] [char](10) NULL,
[dateType] [date] NULL,
[dateTimeType] [datetime] NULL,
[floatType] [float] NULL,
[intType] [int] NULL,
[ncharType] [nchar](10) NULL,
[nvarcharType] [nvarchar](50) NULL,
[varcharType] [varchar](50) NULL,
[decimalType] [decimal](18, 2) NULL,
[xmlType] [xml] NULL
);
GO
17 changes: 17 additions & 0 deletions Docker/MAQSSQLServer/stored_procedures.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
USE MagenicAutomation;
GO
CREATE PROCEDURE [dbo].[getStateAbbrevMatch]
@StateAbbreviation VARCHAR(2)
AS BEGIN
SELECT StateAbbreviation FROM States
WHERE StateAbbreviation = @StateAbbreviation
END
GO
CREATE PROCEDURE [dbo].[setStateAbbrevToSelf]
@StateAbbreviation VARCHAR(2)
AS BEGIN
UPDATE States
SET StateAbbreviation = @StateAbbreviation
WHERE StateAbbreviation = @StateAbbreviation
END
GO
7 changes: 4 additions & 3 deletions jmaqs-database/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@
<DatabaseName>MagenicAutomation</DatabaseName>
<!--<DatabaseProviderType>SQL</DatabaseProviderType>
<DatabaseProviderType>MYSQL</DatabaseProviderType>-->
<!-- Data Source=localhost;Initial Catalog=MagenicAutomation;Persist Security Info=True;User ID=sa;Password=magenicMAQS2;Connection Timeout=30-->
<DatabaseProviderType>SQL</DatabaseProviderType>
<DatabaseUser>MagenicQA</DatabaseUser>
<DatabasePassword>1magenicMARQ</DatabasePassword>
<DatabaseConnectionString>jdbc:sqlserver://qasqlserver.database.windows.net</DatabaseConnectionString>
<DatabaseUser>sa</DatabaseUser>
<DatabasePassword>magenicMAQS2</DatabasePassword>
<DatabaseConnectionString>jdbc:sqlserver://localhost</DatabaseConnectionString>
<EntityDirectory>./src/test/java/com/magenic/jmaqs/database/entities/</EntityDirectory>
<EntityPackage>com.magenic.jmaqs.database.entities</EntityPackage>
</DatabaseMaqs>
Expand Down
33 changes: 31 additions & 2 deletions jmaqs-database/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
Expand Down Expand Up @@ -67,4 +67,33 @@
<version>${sqlite-jdbc.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.37.0</version>
<configuration>
<images>
<image>
<alias>mssql</alias>
<name>mcr.microsoft.com/mssql/server:latest</name>
<external>
<type>compose</type>
<basedir>../Docker/MAQSSQLServer/</basedir>
<composeFile>docker-compose.yml</composeFile>
</external>
</image>
</images>
<execution>
<id>setup-database</id>
<phase>process-test-resources</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class DatabaseConfigUnitTest extends BaseGenericTest {
@Test(groups = TestCategories.DATABASE)
public void testGetConnectionString() {
Assert.assertEquals(DatabaseConfig.getConnectionString(),
"jdbc:sqlserver://qasqlserver.database.windows.net");
"jdbc:sqlserver://localhost");
}

/**
Expand Down Expand Up @@ -68,11 +68,11 @@ public void testGetDatabaseName() {

@Test(groups = TestCategories.DATABASE)
public void testGetDatabaseUser() {
Assert.assertEquals(DatabaseConfig.getDatabaseUser(), "MagenicQA");
Assert.assertEquals(DatabaseConfig.getDatabaseUser(), "sa");
}

@Test(groups = TestCategories.DATABASE)
public void testGetDatabasePassword() {
Assert.assertEquals(DatabaseConfig.getDatabasePassword(), "1magenicMARQ");
Assert.assertEquals(DatabaseConfig.getDatabasePassword(), "magenicMAQS2");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
import com.magenic.jmaqs.selenium.constants.BrowserType;
import com.magenic.jmaqs.selenium.constants.OperatingSystem;
import com.magenic.jmaqs.selenium.constants.RemoteBrowserType;
import com.magenic.jmaqs.selenium.constants.WebDriverFile;
import com.magenic.jmaqs.selenium.exceptions.DriverNotFoundException;
import com.magenic.jmaqs.selenium.exceptions.WebDriverFactoryException;
import com.magenic.jmaqs.utilities.helper.Config;
import com.magenic.jmaqs.utilities.helper.ConfigSection;
import com.magenic.jmaqs.utilities.helper.StringProcessor;
import java.io.File;
import java.net.URL;
Expand Down
54 changes: 22 additions & 32 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -230,22 +230,41 @@
<profile>
<id>testing</id>
<activation>
<activeByDefault>true</activeByDefault>
<property>
<name>testing</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<goals>
<goal>properties</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.plugin.version}</version>
<version>3.0.0-M5</version>
<configuration>
<parallel>methods</parallel>
<threadCount>5</threadCount>
<!-- <argLine>${argLine}</argLine>-->
<!-- <argLine>-javaagent @{maven.dependency.io.github.bonigarcia:webdrivermanager:jar:path}</argLine>-->
<argLine>${argLine} -javaagent:@{io.github.bonigarcia:webdrivermanager:jar}</argLine>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>3.0.0-M5</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
Expand Down Expand Up @@ -421,35 +440,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<goals>
<goal>properties</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<parallel>methods</parallel>
<threadCount>5</threadCount>
<argLine>-javaagent:@{io.github.bonigarcia:webdrivermanager:jar}</argLine>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>3.0.0-M5</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
Expand Down

0 comments on commit 2686fe2

Please sign in to comment.