Skip to content

Commit

Permalink
Set up tests and GitHub action (RPB-3)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsteeg committed Jan 27, 2022
1 parent 199a053 commit fbbca24
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 3 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/build.yml
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

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ bin
.settings
/conf/output/*
!/conf/output/.empty
/data/*
!/data/.empty
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@

https://service-wiki.hbz-nrw.de/pages/viewpage.action?pageId=712998955

[![Build](https://github.com/hbz/rpb/workflows/Build/badge.svg)](https://github.com/hbz/rpb/actions?query=workflow%3ABuild)

## metafix

```
git clone git@github.com:metafacture/metafacture-fix.git -b rpb
git clone https://github.com/metafacture/metafacture-fix.git -b rpb
cd metafacture-fix
./gradlew publishToMavenLocal
```

## etl

```
git clone git@github.com:hbz/rpb.git
git clone https://github.com/hbz/rpb.git
cd rpb
sbt "runMain rpb.ETL conf/rpb-test.flux"
```
Expand Down
2 changes: 2 additions & 0 deletions app/rpb/Decode.java
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;
Expand Down
2 changes: 2 additions & 0 deletions app/rpb/ETL.java
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;
Expand Down
5 changes: 4 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ libraryDependencies ++= Seq(
"org.metafacture" % "metafacture-json" % "5.3.1",
"org.metafacture" % "metafacture-flux" % "5.3.1",
"org.metafacture" % "metafacture-triples" % "5.3.1",
"org.metafacture" % "metafix" % "0.2.0-SNAPSHOT"
"org.metafacture" % "metafix" % "0.2.0-SNAPSHOT",
"org.easytesting" % "fest-assert" % "1.4" % "test",
"org.mockito" % "mockito-core" % "2.27.0" % "test",
"org.mockito" % "mockito-junit-jupiter" % "2.27.0" % "test"
)

lazy val root = (project in file(".")).enablePlugins(PlayJava)
Expand Down
Empty file added data/.empty
Empty file.
81 changes: 81 additions & 0 deletions test/rpb/DecodeTest.java
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;
}
}
}
37 changes: 37 additions & 0 deletions test/rpb/EtlTest.java
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();
}

}

0 comments on commit fbbca24

Please sign in to comment.