Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

testcontainers setup #42

Merged
merged 13 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
restore-keys: |
maven-
- run: |
mvn clean install
mvn clean install -DskipITs
- uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
30 changes: 26 additions & 4 deletions .github/workflows/mvn.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: mvn
name: maven
on:
push:
branches:
Expand All @@ -8,7 +8,7 @@ on:
- master
jobs:
test:
name: Tests
name: Build
strategy:
matrix:
os: [ ubuntu-20.04, macos-12, windows-2022 ]
Expand All @@ -26,5 +26,27 @@ jobs:
key: ${{ runner.os }}-jdk-${{ matrix.java }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-jdk-${{ matrix.java }}-maven-
- run: |
mvn clean install --errors --batch-mode
- run: mvn clean install -DskipITs --errors --batch-mode

it-test:
name: Build Integrations
strategy:
matrix:
os-integration: [ubuntu-20.04]
java: [17]
runs-on: ${{ matrix.os-integration }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: ${{ matrix.java }}
- uses: docker-practice/actions-setup-docker@master
timeout-minutes: 12
- uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-jdk-${{ matrix.java }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-jdk-${{ matrix.java }}-maven-
- run: mvn clean install --errors --batch-mode
2 changes: 1 addition & 1 deletion .rultor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ assets:
pubring.gpg: eo-cqrs/eo-cqrs-secrets#assets/pubring.gpg
merge:
script:
- "mvn clean install --errors --batch-mode"
- "mvn clean install -DskipITs --errors --batch-mode"
release:
pre: false
sensetive:
Expand Down
25 changes: 25 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ SOFTWARE.
<mockito-junit-jupiter.version>5.4.0</mockito-junit-jupiter.version>
<hamcrest-all.version>1.3</hamcrest-all.version>
<guava.version>19.0</guava.version>
<test-cassandra.version>1.18.3</test-cassandra.version>
<failsafe.version>3.1.0</failsafe.version>
<unixized.version>1.0.0</unixized.version>
</properties>
<dependencies>
Expand Down Expand Up @@ -161,6 +163,7 @@ SOFTWARE.
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>${hamcrest-all.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ru.l3r8y</groupId>
Expand All @@ -185,6 +188,12 @@ SOFTWARE.
<version>${mockito-junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>cassandra</artifactId>
<version>${test-cassandra.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down Expand Up @@ -215,6 +224,22 @@ SOFTWARE.
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${failsafe.version}</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
Expand Down
6 changes: 4 additions & 2 deletions src/test/java/io/github/eocqrs/cmig/MasterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
*/
final class MasterTest {

/*
* @todo #36:30m/DEV Tests for master
*/
@Test
@Disabled
void readsShaInRightFormat() throws Exception {
Expand All @@ -46,15 +49,14 @@ void readsShaInRightFormat() throws Exception {
"master.xml",
new Simple("localhost", 9042)
).value(),
// @todo #11:90m/DEV generate SHA based on commit result
new IsEqual<>(
"c8be525311cfd5f5ac7bf1c7d41a61fd82ae5e384b9b7b490358c1cb038c46c9"
)
);
}

/*
* @todo #11:60m/DEV cassandra instance in tests
* @todo #36:60m/DEV Master Cassandra Test
*/
@Test
@Disabled
Expand Down
27 changes: 11 additions & 16 deletions src/test/java/io/github/eocqrs/cmig/session/InFileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,26 @@

package io.github.eocqrs.cmig.session;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

/**
* Test suite for {@link InFile}.
*
* @author Aliaksei Bialiauski ([email protected])
* @since 0.0.0
*/
@ExtendWith(MockitoExtension.class)
final class InFileTest {

@Test
@Disabled
void appliesInRightFormat() throws Exception {
Assertions.assertDoesNotThrow(
() ->
new InFile(
new Simple(
"localhost",
9042
),
"cmig/002-queries-table.cql"
).apply(),
"Applies does not throw exception"
void createsWithMockCassandra(@Mock final Cassandra mock) {
MatcherAssert.assertThat(
"Creates cql in file",
new InFile(mock, "cmig/001-initial-keyspace.cql"),
Matchers.notNullValue()
);
}
}
70 changes: 70 additions & 0 deletions src/test/java/io/github/eocqrs/cmig/session/SimpleTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2023 Aliaksei Bialiauski, EO-CQRS
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package io.github.eocqrs.cmig.session;

import com.datastax.driver.core.Cluster;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

/**
* Test suite for {@link Simple}.
*
* @author Aliaksei Bialiauski ([email protected])
* @since 0.0.0
*/
@ExtendWith(MockitoExtension.class)
final class SimpleTest {

@Test
void createsCassandra(@Mock final Cluster mock) {
final Cassandra cassandra = new Simple(mock);
MatcherAssert.assertThat(
"Creates Cassandra",
cassandra,
Matchers.notNullValue()
);
}

@Test
void closesWithoutException(@Mock final Cluster mock) {
final Cassandra cassandra = new Simple(mock);
Assertions.assertDoesNotThrow(
cassandra::close,
"Closes without exception"
);
}

@Test
void connectsToMockWithoutException(@Mock final Cluster mock) {
final Cassandra cassandra = new Simple(mock);
Assertions.assertDoesNotThrow(
cassandra::value,
"Connect to mocked cluster doesnt throw exception"
);
}
}
56 changes: 56 additions & 0 deletions src/test/java/it/CassandraIntegration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2023 Aliaksei Bialiauski, EO-CQRS
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package it;

import org.junit.AfterClass;
import org.junit.jupiter.api.BeforeAll;
import org.testcontainers.containers.CassandraContainer;
import org.testcontainers.utility.DockerImageName;

/**
* Cassandra for Integration Testing.
*
* @author Aliaksei Bialiauski ([email protected])
* @since 0.0.0
*/
@SuppressWarnings("JTCOP.RuleCorrectTestName")
public abstract class CassandraIntegration {

protected static final CassandraContainer<?> CASSANDRA =
new CassandraContainer<>(
DockerImageName.parse("cassandra:3.11.15")
).withExposedPorts(9042);
protected static String host;

@BeforeAll
static void beforeAll() {
CassandraIntegration.CASSANDRA.start();
CassandraIntegration.host =
CassandraIntegration.CASSANDRA.getHost();
}

@AfterClass
public static void tearDown() {
CassandraIntegration.CASSANDRA.stop();
}
}
46 changes: 46 additions & 0 deletions src/test/java/it/CassandraRunsIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2023 Aliaksei Bialiauski, EO-CQRS
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package it;

import org.hamcrest.MatcherAssert;
import org.hamcrest.core.IsEqual;
import org.junit.jupiter.api.Test;

/**
* Cassandra Runs Integration test.
*
* @author Aliaksei Bialiauski ([email protected])
* @since 0.0.0
*/
@SuppressWarnings("JTCOP.RuleCorrectTestName")
final class CassandraRunsIT extends CassandraIntegration {

@Test
void runs() {
MatcherAssert.assertThat(
"Cassandra runs",
CASSANDRA.isRunning(),
new IsEqual<>(true)
);
}
}
Loading