-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up tests and GitHub action (RPB-3)
- Loading branch information
Showing
9 changed files
with
157 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Build | ||
|
||
on: | ||
push | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up JDK 1.8 | ||
uses: actions/setup-java@v1 | ||
with: | ||
java-version: 1.8 | ||
- name: Install metafacture-fix | ||
run: | | ||
git clone https://github.com/metafacture/metafacture-fix.git -b rpb | ||
cd metafacture-fix | ||
./gradlew publishToMavenLocal | ||
cd .. | ||
- name: Run tests | ||
run: sbt test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ bin | |
.settings | ||
/conf/output/* | ||
!/conf/output/.empty | ||
/data/* | ||
!/data/.empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
/* Copyright 2022 Fabian Steeg, hbz. Licensed under the GPLv2 */ | ||
|
||
package rpb; | ||
|
||
import org.apache.log4j.Logger; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
/* Copyright 2022 Fabian Steeg, hbz. Licensed under the GPLv2 */ | ||
|
||
package rpb; | ||
|
||
import java.io.File; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* Copyright 2022 Fabian Steeg, hbz. Licensed under the GPLv2 */ | ||
|
||
package rpb; | ||
|
||
import static org.mockito.Mockito.inOrder; | ||
import static org.mockito.Mockito.verifyZeroInteractions; | ||
|
||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
import org.metafacture.framework.StreamReceiver; | ||
import org.mockito.InOrder; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.exceptions.base.MockitoAssertionError; | ||
import org.mockito.junit.MockitoJUnit; | ||
import org.mockito.junit.MockitoRule; | ||
|
||
/** | ||
* Tests for class {@link Decode}. | ||
* | ||
* @author Fabian Steeg | ||
* | ||
*/ | ||
public final class DecodeTest { | ||
|
||
@Rule | ||
public MockitoRule mockitoRule = MockitoJUnit.rule(); | ||
|
||
@Rule | ||
public ExpectedException exception = ExpectedException.none(); | ||
|
||
@Mock | ||
private StreamReceiver receiver; | ||
|
||
private Decode decode; | ||
|
||
@Before | ||
public void init() { | ||
decode = new Decode(); | ||
decode.setReceiver(receiver); | ||
} | ||
|
||
public void processEmptyStrings() { | ||
decode.process(""); | ||
verifyZeroInteractions(receiver); | ||
} | ||
|
||
@Test | ||
public void processRecord() { | ||
test("[/]#00 123[/]#20 abc[/]", () -> { | ||
final InOrder ordered = inOrder(receiver); | ||
ordered.verify(receiver).startRecord("123"); | ||
ordered.verify(receiver).literal("#00", "123"); | ||
ordered.verify(receiver).literal("#20", " abc"); | ||
ordered.verify(receiver).endRecord(); | ||
ordered.verifyNoMoreInteractions(); | ||
}); | ||
} | ||
|
||
@Test | ||
public void processError() { | ||
exception.expect(ArrayIndexOutOfBoundsException.class); | ||
exception.expectMessage("1"); | ||
decode.process("[/]#01something[/]"); | ||
} | ||
|
||
private void test(final String in, final Runnable r) throws MockitoAssertionError { | ||
try { | ||
decode.process(in); | ||
r.run(); | ||
Mockito.verifyNoMoreInteractions(receiver); | ||
} | ||
catch (final MockitoAssertionError e) { | ||
System.out.println("\nDecoding string: " + in); | ||
System.out.println(Mockito.mockingDetails(receiver).printInvocations()); | ||
throw e; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* Copyright 2014, 2022 Fabian Steeg, hbz. Licensed under the GPLv2 */ | ||
|
||
package rpb; | ||
|
||
import static org.fest.assertions.Assertions.assertThat; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
|
||
import org.antlr.runtime.RecognitionException; | ||
import org.junit.Test; | ||
import org.metafacture.framework.StreamReceiver; | ||
import org.mockito.Mock; | ||
|
||
/** | ||
* Tests for class {@link ETL}. | ||
* | ||
* @author Fabian Steeg | ||
* | ||
*/ | ||
@SuppressWarnings("javadoc") | ||
public class EtlTest { | ||
|
||
@Mock | ||
private StreamReceiver streamReceiver; | ||
|
||
@Test | ||
public void runMain() throws FileNotFoundException, RecognitionException, IOException { | ||
File output = new File("conf/output/test-output.json"); | ||
output.delete(); | ||
assertThat(output).as("test output").doesNotExist(); | ||
ETL.main(new String[] { "conf/rpb-test.flux" }); | ||
assertThat(output).as("test output").exists(); | ||
} | ||
|
||
} |