Skip to content
Snippets Groups Projects
Commit 9bb2b0ab authored by René Schöne's avatar René Schöne
Browse files

Update remaining tests to jUnit 5.

parent c7cc9682
Branches
No related tags found
1 merge request!19dev to master
Pipeline #8409 passed
Showing
with 100 additions and 218 deletions
...@@ -20,7 +20,8 @@ dependencies { ...@@ -20,7 +20,8 @@ dependencies {
api group: 'org.fusesource.mqtt-client', name: 'mqtt-client', version: '1.16' api group: 'org.fusesource.mqtt-client', name: 'mqtt-client', version: '1.16'
implementation group: 'org.influxdb', name: 'influxdb-java', version: '2.20' implementation group: 'org.influxdb', name: 'influxdb-java', version: '2.20'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: "${jupiter_version}" testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: "${jupiter_version}"
testImplementation group: 'org.testcontainers', name: 'testcontainers', version: '1.15.0' // testImplementation group: 'org.testcontainers', name: 'testcontainers', version: '1.15.0'
testImplementation group: 'org.testcontainers', name: 'junit-jupiter', version: '1.15.0'
testImplementation group: 'org.testcontainers', name: 'influxdb', version: '1.15.0' testImplementation group: 'org.testcontainers', name: 'influxdb', version: '1.15.0'
testImplementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: "${log4j_version}" testImplementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: "${log4j_version}"
} }
......
package de.tudresden.inf.st.eraser; package de.tudresden.inf.st.eraser;
import de.tudresden.inf.st.eraser.jastadd.model.*;
import de.tudresden.inf.st.eraser.util.TestUtils; import de.tudresden.inf.st.eraser.util.TestUtils;
import de.tudresden.inf.st.eraser.util.TestUtils.ModelAndItem; import de.tudresden.inf.st.eraser.util.TestUtils.ModelAndItem;
import de.tudresden.inf.st.eraser.jastadd.model.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.function.Consumer; import java.util.function.Consumer;
......
...@@ -30,7 +30,7 @@ public class ExpressionEvalTest { ...@@ -30,7 +30,7 @@ public class ExpressionEvalTest {
} }
@Test @Test
public void multExpression() throws IOException, Parser.Exception { public void mulExpression() throws IOException, Parser.Exception {
NumberExpression sut = ParserUtils.parseNumberExpression("(3 * 4)"); NumberExpression sut = ParserUtils.parseNumberExpression("(3 * 4)");
assertEquals(12.0, sut.eval()); assertEquals(12.0, sut.eval());
} }
......
...@@ -3,10 +3,16 @@ package de.tudresden.inf.st.eraser; ...@@ -3,10 +3,16 @@ package de.tudresden.inf.st.eraser;
import de.tudresden.inf.st.eraser.jastadd.model.*; import de.tudresden.inf.st.eraser.jastadd.model.*;
import de.tudresden.inf.st.eraser.util.TestUtils; import de.tudresden.inf.st.eraser.util.TestUtils;
import de.tudresden.inf.st.eraser.util.TestUtils.ModelAndItem; import de.tudresden.inf.st.eraser.util.TestUtils.ModelAndItem;
import org.junit.jupiter.api.*; import org.junit.ClassRule;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource; import org.junit.jupiter.params.provider.ValueSource;
import org.testcontainers.containers.InfluxDBContainer; import org.testcontainers.containers.InfluxDBContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;
import java.time.Instant; import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -23,20 +29,23 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue; ...@@ -23,20 +29,23 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue;
* *
* @author rschoene - Initial contribution * @author rschoene - Initial contribution
*/ */
//@RunWith(Parameterized.class) @Testcontainers
@Disabled("Parameterized test still to be ported to junit5")
public class InfluxTest { public class InfluxTest {
private static final double DELTA = 0.001; private static final double DELTA = 0.001;
private List<DoubleStatePoint> points = new ArrayList<>(); private final List<DoubleStatePoint> points = new ArrayList<>();
private static final double firstState = 2.0; private static final double firstState = 2.0;
private static final double secondState = 4.0; private static final double secondState = 4.0;
private static final double thirdState = 3.0; private static final double thirdState = 3.0;
private ModelAndItem mai; private ModelAndItem mai;
// @ClassRule @Container
public static InfluxDBContainer influxDbContainer = new InfluxDBContainer() private static final InfluxDBContainer<?> influxDbContainer =
new InfluxDBContainer<>(
DockerImageName
.parse("influxdb")
.withTag("1.8.3"))
.withDatabase(InfluxRoot.createDefault().getDbName()) .withDatabase(InfluxRoot.createDefault().getDbName())
.withAdmin(InfluxRoot.createDefault().getUser()) .withAdmin(InfluxRoot.createDefault().getUser())
.withAdminPassword(InfluxRoot.createDefault().getPassword()); .withAdminPassword(InfluxRoot.createDefault().getPassword());
...@@ -44,6 +53,7 @@ public class InfluxTest { ...@@ -44,6 +53,7 @@ public class InfluxTest {
@ParameterizedTest @ParameterizedTest
@ValueSource(booleans = {true, false}) @ValueSource(booleans = {true, false})
public void oneItem(boolean useStub) { public void oneItem(boolean useStub) {
setNewModel(useStub);
NumberItem item = mai.item; NumberItem item = mai.item;
// set state once // set state once
item.setState(firstState); item.setState(firstState);
...@@ -67,6 +77,7 @@ public class InfluxTest { ...@@ -67,6 +77,7 @@ public class InfluxTest {
@ParameterizedTest @ParameterizedTest
@ValueSource(booleans = {true, false}) @ValueSource(booleans = {true, false})
public void twoItems(boolean useStub) { public void twoItems(boolean useStub) {
setNewModel(useStub);
NumberItem item1 = mai.item; NumberItem item1 = mai.item;
NumberItem item2 = TestUtils.addItemTo(mai.model, 1.0, true); NumberItem item2 = TestUtils.addItemTo(mai.model, 1.0, true);
// set state once for first item // set state once for first item
...@@ -110,6 +121,7 @@ public class InfluxTest { ...@@ -110,6 +121,7 @@ public class InfluxTest {
@ParameterizedTest @ParameterizedTest
@ValueSource(booleans = {true, false}) @ValueSource(booleans = {true, false})
public void justAdapter(boolean useStub) { public void justAdapter(boolean useStub) {
setNewModel(useStub);
InfluxAdapter influxAdapter = getInfluxRoot().influxAdapter(); InfluxAdapter influxAdapter = getInfluxRoot().influxAdapter();
assertTrue(influxAdapter.isConnected(), "Adapter not connected"); assertTrue(influxAdapter.isConnected(), "Adapter not connected");
influxAdapter.deleteDatabase(); influxAdapter.deleteDatabase();
...@@ -189,8 +201,8 @@ public class InfluxTest { ...@@ -189,8 +201,8 @@ public class InfluxTest {
} }
} }
@BeforeEach private void setNewModel(boolean useStub) {
public void setNewModel(boolean useStub) { // BeforeEach does not work with parameterized tests :(
mai = createModel(useStub); mai = createModel(useStub);
getInfluxRoot().influxAdapter().disableAsyncQuery(); getInfluxRoot().influxAdapter().disableAsyncQuery();
} }
...@@ -201,18 +213,4 @@ public class InfluxTest { ...@@ -201,18 +213,4 @@ public class InfluxTest {
getInfluxRoot().influxAdapter().close(); getInfluxRoot().influxAdapter().close();
} }
} }
// @Parameterized.Parameter
// public String name;
//
// @Parameterized.Parameter(1)
// public boolean useStub;
// @Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> getTests() {
return Arrays.asList(new Object[][] {
{"Impl", false},
{"Stub", true}
});
}
} }
...@@ -3,7 +3,6 @@ package de.tudresden.inf.st.eraser; ...@@ -3,7 +3,6 @@ package de.tudresden.inf.st.eraser;
import de.tudresden.inf.st.eraser.jastadd.model.*; import de.tudresden.inf.st.eraser.jastadd.model.*;
import de.tudresden.inf.st.eraser.util.TestUtils; import de.tudresden.inf.st.eraser.util.TestUtils;
import de.tudresden.inf.st.eraser.util.TestUtils.ModelAndItem; import de.tudresden.inf.st.eraser.util.TestUtils.ModelAndItem;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.time.Instant; import java.time.Instant;
......
package de.tudresden.inf.st.eraser; package de.tudresden.inf.st.eraser;
import de.tudresden.inf.st.eraser.jastadd_test.core.*; import de.tudresden.inf.st.eraser.jastadd_test.core.TestConfiguration;
import de.tudresden.inf.st.eraser.jastadd_test.core.TestProperties;
import de.tudresden.inf.st.eraser.jastadd_test.core.TestRunner;
import de.tudresden.inf.st.eraser.jastadd_test.core.Util;
import de.tudresden.inf.st.eraser.parser.EraserParserHelper; import de.tudresden.inf.st.eraser.parser.EraserParserHelper;
import de.tudresden.inf.st.eraser.util.ParserUtils; import de.tudresden.inf.st.eraser.util.ParserUtils;
import org.junit.BeforeClass; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.Test; import org.junit.jupiter.params.provider.MethodSource;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized; import java.util.List;
/** /**
* Testing round-trip parsing-printing-comparing. * Testing round-trip parsing-printing-comparing.
* *
* @author rschoene - Initial contribution * @author rschoene - Initial contribution
*/ */
//@RunWith(ParallelParameterized.class)
@RunWith(Parameterized.class)
public class MarshallingTests { public class MarshallingTests {
private static final TestProperties properties = new TestProperties();
static {
properties.put("jastadd3", "false");
properties.put("options", "indent=tab");
properties.setTestRoot("src/test/resources/tests");
// properties.exclude(Tests.FAILING);
// properties.exclude(Tests.UNSTABLE);
}
private final TestConfiguration unitTest;
@BeforeClass
public static void setupParser() {
EraserParserHelper.setCheckUnusedElements(false);
ParserUtils.setVerboseLoading(false);
}
/**
* Construct a new JastAdd test
* @param unitTest The test to run.
*/
public MarshallingTests(TestConfiguration unitTest) {
this.unitTest = unitTest;
}
/** /**
* Run the JastAdd test * Run the JastAdd test
* @param unitTest The test to run.
*/ */
@Test @ParameterizedTest
public void runTest() throws Exception { @MethodSource("getTests")
TestRunner.runTest(unitTest, properties); public void runTest(TestConfiguration unitTest) throws Exception {
EraserParserHelper.setCheckUnusedElements(false);
ParserUtils.setVerboseLoading(false);
TestRunner.runTest(unitTest);
} }
@Parameterized.Parameters(name = "{0}") public static List<TestConfiguration> getTests() {
public static Iterable<Object[]> getTests() { TestProperties properties = new TestProperties();
properties.put("jastadd3", "false");
properties.put("options", "indent=tab");
properties.setTestRoot("src/test/resources/tests");
// properties.exclude(Tests.FAILING);
// properties.exclude(Tests.UNSTABLE);
return Util.getTests(properties); return Util.getTests(properties);
} }
......
...@@ -5,13 +5,12 @@ import de.tudresden.inf.st.eraser.util.MqttReceiver; ...@@ -5,13 +5,12 @@ import de.tudresden.inf.st.eraser.util.MqttReceiver;
import de.tudresden.inf.st.eraser.util.TestUtils; import de.tudresden.inf.st.eraser.util.TestUtils;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource; import org.junit.jupiter.params.provider.ValueSource;
import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait; import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -21,7 +20,6 @@ import java.util.concurrent.TimeUnit; ...@@ -21,7 +20,6 @@ import java.util.concurrent.TimeUnit;
import java.util.function.Supplier; import java.util.function.Supplier;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.core.IsCollectionContaining.hasItem;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue; import static org.junit.jupiter.api.Assumptions.assumeTrue;
...@@ -31,8 +29,7 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue; ...@@ -31,8 +29,7 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue;
* *
* @author rschoene - Initial contribution * @author rschoene - Initial contribution
*/ */
//@RunWith(Parameterized.class) @Testcontainers
@Disabled("Parameterized test still to be ported to junit5")
public class MqttTests { public class MqttTests {
private static final String outgoingPrefix = "out"; private static final String outgoingPrefix = "out";
...@@ -43,11 +40,11 @@ public class MqttTests { ...@@ -43,11 +40,11 @@ public class MqttTests {
private static final double secondState = 2.0; private static final double secondState = 2.0;
private static final double thirdState = 3.0; private static final double thirdState = 3.0;
private List<String> messages = new ArrayList<>(); private final List<String> messages = new ArrayList<>();
private static Logger logger = LogManager.getLogger(MqttTests.class); private static final Logger logger = LogManager.getLogger(MqttTests.class);
// @ClassRule @Container
public static GenericContainer mqttBroker = new GenericContainer<>("eclipse-mosquitto:1.5") public static GenericContainer<?> mqttBroker = new GenericContainer<>("eclipse-mosquitto:1.5")
.withExposedPorts(1883); .withExposedPorts(1883);
@ParameterizedTest @ParameterizedTest
...@@ -154,6 +151,7 @@ public class MqttTests { ...@@ -154,6 +151,7 @@ public class MqttTests {
private void createMqttReceiver(boolean useStub, String... expectedTopics) throws IOException { private void createMqttReceiver(boolean useStub, String... expectedTopics) throws IOException {
if (useStub) { if (useStub) {
// do not need receiver, as messages are directly written by MqttSenderStub and callback // do not need receiver, as messages are directly written by MqttSenderStub and callback
messages.clear();
return; return;
} }
MqttReceiver receiver = new MqttReceiver(); MqttReceiver receiver = new MqttReceiver();
...@@ -219,6 +217,8 @@ public class MqttTests { ...@@ -219,6 +217,8 @@ public class MqttTests {
} }
long targetEndTime = System.nanoTime() + TimeUnit.SECONDS.toNanos(seconds); long targetEndTime = System.nanoTime() + TimeUnit.SECONDS.toNanos(seconds);
while (System.nanoTime() < targetEndTime) { while (System.nanoTime() < targetEndTime) {
// this is indeed busy waiting in favour of new dependencies handling it
//noinspection BusyWait
Thread.sleep(100); Thread.sleep(100);
if (expected == actualProvider.get()) { if (expected == actualProvider.get()) {
break; break;
......
...@@ -3,7 +3,6 @@ package de.tudresden.inf.st.eraser; ...@@ -3,7 +3,6 @@ package de.tudresden.inf.st.eraser;
import de.tudresden.inf.st.eraser.jastadd.model.*; import de.tudresden.inf.st.eraser.jastadd.model.*;
import de.tudresden.inf.st.eraser.util.TestUtils; import de.tudresden.inf.st.eraser.util.TestUtils;
import de.tudresden.inf.st.eraser.util.TestUtils.ModelAndItem; import de.tudresden.inf.st.eraser.util.TestUtils.ModelAndItem;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
......
package de.tudresden.inf.st.eraser; package de.tudresden.inf.st.eraser;
import de.tudresden.inf.st.eraser.jastadd.model.SmartHomeEntityModel; import de.tudresden.inf.st.eraser.jastadd.model.SmartHomeEntityModel;
import de.tudresden.inf.st.eraser.jastadd.model.Root;
import de.tudresden.inf.st.eraser.jastadd_test.core.*; import de.tudresden.inf.st.eraser.jastadd_test.core.*;
import de.tudresden.inf.st.eraser.openhab2.OpenHab2Importer; import de.tudresden.inf.st.eraser.openhab2.OpenHab2Importer;
import org.junit.Test; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.runner.RunWith; import org.junit.jupiter.params.provider.MethodSource;
import org.junit.runners.Parameterized;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Properties; import java.util.List;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
...@@ -23,13 +19,12 @@ import static org.junit.Assert.fail; ...@@ -23,13 +19,12 @@ import static org.junit.Assert.fail;
* *
* @author rschoene - Initial contribution * @author rschoene - Initial contribution
*/ */
@RunWith(ParallelParameterized.class)
public class OpenHabImporterTest { public class OpenHabImporterTest {
private static final String HOST = "localhost"; private static final String HOST = "localhost";
static class OpenHab2ImporterFromFile extends OpenHab2Importer { static class OpenHab2ImporterFromFile extends OpenHab2Importer {
private String directory; private final String directory;
OpenHab2ImporterFromFile(String directory) { OpenHab2ImporterFromFile(String directory) {
this.directory = directory; this.directory = directory;
...@@ -63,7 +58,7 @@ public class OpenHabImporterTest { ...@@ -63,7 +58,7 @@ public class OpenHabImporterTest {
} }
static class OpenHabImportRunner extends TestRunner { static class OpenHabImportRunner extends TestRunner {
public static void runTest(TestConfiguration config, Properties jastaddProperties) { public static void runTest(TestConfiguration config) {
Result expected = config.getExpected(); Result expected = config.getExpected();
...@@ -93,34 +88,22 @@ public class OpenHabImporterTest { ...@@ -93,34 +88,22 @@ public class OpenHabImporterTest {
} }
} }
private static final TestProperties properties = new TestProperties();
static {
properties.put("jastadd3", "false");
properties.setTestRoot("src/test/resources/openhabtest");
// properties.exclude(Tests.FAILING);
// properties.exclude(Tests.UNSTABLE);
}
private final TestConfiguration unitTest;
/**
* Construct a new OpenHabImporterTest
* @param unitTest The test to run.
*/
public OpenHabImporterTest(TestConfiguration unitTest) {
this.unitTest = unitTest;
}
/** /**
* Run the OpenHabImporterTest * Run the OpenHabImporterTest
* @param unitTest The test to run.
*/ */
@Test @ParameterizedTest
public void runTest() { @MethodSource("getTests")
OpenHabImportRunner.runTest(unitTest, properties); public void runTest(TestConfiguration unitTest) {
OpenHabImportRunner.runTest(unitTest);
} }
@Parameterized.Parameters(name = "{0}") public static List<TestConfiguration> getTests() {
public static Iterable<Object[]> getTests() { TestProperties properties = new TestProperties();
properties.put("jastadd3", "false");
properties.setTestRoot("src/test/resources/openhabtest");
// properties.exclude(Tests.FAILING);
// properties.exclude(Tests.UNSTABLE);
return Util.getTests(properties); return Util.getTests(properties);
} }
} }
...@@ -27,7 +27,7 @@ public class RulesTest { ...@@ -27,7 +27,7 @@ public class RulesTest {
private static final double DELTA = 0.01d; private static final double DELTA = 0.01d;
class CountingAction extends NoopAction { static class CountingAction extends NoopAction {
final Map<Item, AtomicInteger> counters = new HashMap<>(); final Map<Item, AtomicInteger> counters = new HashMap<>();
CountingAction() { CountingAction() {
...@@ -334,7 +334,7 @@ public class RulesTest { ...@@ -334,7 +334,7 @@ public class RulesTest {
assertEquals(5, item2.asItemWithDoubleState().getState(), DELTA, "Change of item state should set the state of the affected item"); assertEquals(5, item2.asItemWithDoubleState().getState(), DELTA, "Change of item state should set the state of the affected item");
} }
class ValuedStateProvider implements NewStateProvider { static class ValuedStateProvider implements NewStateProvider {
int value; int value;
@Override @Override
public String get() { public String get() {
......
/* Copyright (c) 2005-2015, The JastAdd Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.tudresden.inf.st.eraser.jastadd_test.core;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.junit.runners.Parameterized;
import org.junit.runners.model.RunnerScheduler;
/**
* Runs parameterized tests in parallel
*/
public class ParallelParameterized extends Parameterized {
private static final int NUM_THREADS = 16;
/**
* Constructor
* @param klass
* @throws Throwable
*/
public ParallelParameterized(Class<?> klass) throws Throwable {
super(klass);
setScheduler(new ThreadPoolScheduler());
}
private static class ThreadPoolScheduler implements RunnerScheduler {
private final ExecutorService executor;
public ThreadPoolScheduler() {
executor = Executors.newFixedThreadPool(NUM_THREADS);
}
@Override
public void finished() {
executor.shutdown();
try {
executor.awaitTermination(10, TimeUnit.MINUTES);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
@Override
public void schedule(Runnable test) {
executor.submit(test);
}
}
}
...@@ -30,18 +30,16 @@ ...@@ -30,18 +30,16 @@
package de.tudresden.inf.st.eraser.jastadd_test.core; package de.tudresden.inf.st.eraser.jastadd_test.core;
import beaver.Parser; import beaver.Parser;
import de.tudresden.inf.st.eraser.jastadd.model.SmartHomeEntityModel;
import de.tudresden.inf.st.eraser.jastadd.model.Root; import de.tudresden.inf.st.eraser.jastadd.model.Root;
import de.tudresden.inf.st.eraser.util.ParserUtils; import de.tudresden.inf.st.eraser.util.ParserUtils;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.Properties;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.fail;
/** /**
* Utility methods for running JastAdd unit tests. * Utility methods for running JastAdd unit tests.
...@@ -50,7 +48,7 @@ import static org.junit.Assert.assertEquals; ...@@ -50,7 +48,7 @@ import static org.junit.Assert.assertEquals;
public class TestRunner { public class TestRunner {
private static int TEST_TIMEOUT = 5000; private static int TEST_TIMEOUT = 5000;
private static String SYS_LINE_SEP = System.getProperty("line.separator"); private static final String SYS_LINE_SEP = System.getProperty("line.separator");
static { static {
// Set up test timeout. // Set up test timeout.
...@@ -60,9 +58,8 @@ public class TestRunner { ...@@ -60,9 +58,8 @@ public class TestRunner {
/** /**
* Run test with given JastAdd configuration. * Run test with given JastAdd configuration.
* @param config test case specific configuration * @param config test case specific configuration
* @param jastaddProperties global test configuration
*/ */
public static void runTest(TestConfiguration config, Properties jastaddProperties) public static void runTest(TestConfiguration config)
throws Exception { throws Exception {
Result expected = config.expected; Result expected = config.expected;
...@@ -129,9 +126,10 @@ public class TestRunner { ...@@ -129,9 +126,10 @@ public class TestRunner {
try { try {
File expected = expectedJastAddErrorOutput(testDir); File expected = expectedJastAddErrorOutput(testDir);
File actual = new File(tmpDir, "jastadd.err"); File actual = new File(tmpDir, "jastadd.err");
assertEquals("Error output files differ", assertEquals(
readFileToString(expected), readFileToString(expected),
readFileToString(actual)); readFileToString(actual),
"Error output files differ");
} catch (IOException e) { } catch (IOException e) {
fail("IOException occurred while comparing JastAdd error output: " + e.getMessage()); fail("IOException occurred while comparing JastAdd error output: " + e.getMessage());
} }
...@@ -167,7 +165,7 @@ public class TestRunner { ...@@ -167,7 +165,7 @@ public class TestRunner {
fail("Missing file: " + expectedFileLocation); fail("Missing file: " + expectedFileLocation);
} }
String expected = readFileToString(expectedOutput); String expected = readFileToString(expectedOutput);
assertEquals("Output differs!", expected, actual); assertEquals(expected, actual, "Output differs!");
} catch (IOException e) { } catch (IOException e) {
fail("IOException occurred while comparing output: " + e.getMessage()); fail("IOException occurred while comparing output: " + e.getMessage());
} }
...@@ -189,7 +187,7 @@ public class TestRunner { ...@@ -189,7 +187,7 @@ public class TestRunner {
if (!file.isFile()) { if (!file.isFile()) {
return ""; return "";
} }
String content = new String(Files.readAllBytes(file.toPath()), Charset.forName("UTF-8")); String content = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);
return normalizeText(content); return normalizeText(content);
} }
...@@ -197,7 +195,7 @@ public class TestRunner { ...@@ -197,7 +195,7 @@ public class TestRunner {
* Normalize line endings and replace back-slashes with slashes. * Normalize line endings and replace back-slashes with slashes.
* This is used to avoid insignificant platform differences from * This is used to avoid insignificant platform differences from
* altering test results. * altering test results.
* @param text * @param text text to normalize
* @return normalized text string * @return normalized text string
*/ */
private static String normalizeText(String text) { private static String normalizeText(String text) {
......
...@@ -47,7 +47,7 @@ public class Util { ...@@ -47,7 +47,7 @@ public class Util {
* @param tests * @param tests
* @param excludes * @param excludes
*/ */
private static void addChildTestDirs(File testRoot, Collection<Object[]> tests, private static void addChildTestDirs(File testRoot, List<TestConfiguration> tests,
Collection<String> excludes) { Collection<String> excludes) {
if (testRoot == null) { if (testRoot == null) {
return; return;
...@@ -63,7 +63,7 @@ public class Util { ...@@ -63,7 +63,7 @@ public class Util {
} }
private static void addTestDir(String testRoot, File dir, private static void addTestDir(String testRoot, File dir,
Collection<Object[]> tests, Collection<String> excludes) { List<TestConfiguration> tests, Collection<String> excludes) {
if (dir.isDirectory()) { if (dir.isDirectory()) {
String path = dir.getPath().replace(File.separatorChar, '/'); String path = dir.getPath().replace(File.separatorChar, '/');
...@@ -89,23 +89,23 @@ public class Util { ...@@ -89,23 +89,23 @@ public class Util {
/** /**
* Add separate test for each option set. * Add separate test for each option set.
*/ */
private static void addUnitTests(String testRoot, Collection<Object[]> tests, String path, File dir) { private static void addUnitTests(String testRoot, List<TestConfiguration> tests, String path, File dir) {
Properties testProperties = Util.getTestProperties(dir); Properties testProperties = Util.getTestProperties(dir);
String optionsProperty = testProperties.getProperty("options", ""); String optionsProperty = testProperties.getProperty("options", "");
String extraOptions = testProperties.getProperty("extraoptions", ""); String extraOptions = testProperties.getProperty("extraoptions", "");
String options[] = optionsProperty.split("\\|", -1); String[] options = optionsProperty.split("\\|", -1);
int index = 1; int index = 1;
for (String option : options) { for (String option : options) {
TestOptions u = new TestOptions((option + " " + extraOptions).trim(), TestOptions u = new TestOptions((option + " " + extraOptions).trim(),
options.length > 1, index); options.length > 1, index);
TestConfiguration config = new TestConfiguration(testRoot, path, u); TestConfiguration config = new TestConfiguration(testRoot, path, u);
tests.add(new Object[] { config }); tests.add(config);
index++; index++;
} }
} }
private static void addByPattern(File root, String pattern, private static void addByPattern(File root, String pattern,
Collection<Object[]> tests, Collection<String> excludes) { List<TestConfiguration> tests, Collection<String> excludes) {
if (pattern.isEmpty()) { if (pattern.isEmpty()) {
addTestDir(root.getPath(), root, tests, excludes); addTestDir(root.getPath(), root, tests, excludes);
} else { } else {
...@@ -116,7 +116,7 @@ public class Util { ...@@ -116,7 +116,7 @@ public class Util {
rest = ""; rest = "";
} else { } else {
part = pattern.substring(0, index); part = pattern.substring(0, index);
rest = pattern.substring(index+1, pattern.length()); rest = pattern.substring(index + 1);
} }
if (part.indexOf('*') == -1) { if (part.indexOf('*') == -1) {
addByPattern(new File(root, part), rest, tests, excludes); addByPattern(new File(root, part), rest, tests, excludes);
...@@ -168,8 +168,8 @@ public class Util { ...@@ -168,8 +168,8 @@ public class Util {
* @param properties * @param properties
* @return A collection of String arrays containing the test directories * @return A collection of String arrays containing the test directories
*/ */
public static Iterable<Object[]> getTests(TestProperties properties) { public static List<TestConfiguration> getTests(TestProperties properties) {
List<Object[]> tests = new LinkedList<>(); List<TestConfiguration> tests = new ArrayList<>();
Collection<String> includes = properties.includes(); Collection<String> includes = properties.includes();
Collection<String> excludes = properties.excludes(); Collection<String> excludes = properties.excludes();
...@@ -182,12 +182,12 @@ public class Util { ...@@ -182,12 +182,12 @@ public class Util {
} }
} }
for (Object[] test : tests) { for (TestConfiguration test : tests) {
((TestConfiguration) test[0]).addOptions(properties.getProperty("extraoptions", "")); test.addOptions(properties.getProperty("extraoptions", ""));
} }
// Sort the tests lexicographically. // Sort the tests lexicographically.
tests.sort(Comparator.comparing(a -> a[0].toString())); tests.sort(Comparator.comparing(TestConfiguration::toString));
return tests; return tests;
} }
...@@ -201,7 +201,6 @@ public class Util { ...@@ -201,7 +201,6 @@ public class Util {
FileInputStream in = new FileInputStream(propertiesFile); FileInputStream in = new FileInputStream(propertiesFile);
properties.load(in); properties.load(in);
in.close(); in.close();
} catch (FileNotFoundException e) {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -231,7 +230,6 @@ public class Util { ...@@ -231,7 +230,6 @@ public class Util {
break; break;
} }
} }
} catch (FileNotFoundException e) {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment