Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to junit5 #158

Merged
merged 5 commits into from
Aug 6, 2020
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
28 changes: 26 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* - server: A java executable runnable container similar to Tomcat that can run consumers
* - consumers: Examples written to show how you to build your own forklift ESB
*/

allprojects {
repositories {
mavenCentral()
Expand All @@ -36,7 +35,16 @@ subprojects {
}

dependencies {
testImplementation 'junit:junit:4.12'
testImplementation 'org.junit.jupiter:junit-jupiter:5.6.2'
}

test {
useJUnitPlatform()
reports.html.enabled = false
// ignoreFailures true
testLogging {
events "passed", "skipped", "failed"
}
}

jar {
Expand Down Expand Up @@ -112,3 +120,19 @@ subprojects {
sign publishing.publications.mavenJava
}
}

// Setup the test report to put together into one report for all subprojects.
task testReport(type: TestReport) {
destinationDir = file("$buildDir/reports/allTests")
// Include the results from the `test` task in all subprojects
reportOn getTasksByName("test", true)
}

rootProject.getTasksByName('test', true).each {
it.finalizedBy(testReport)
}

task cleanTestDir (type: Delete) {
file("$buildDir").deleteDir()
}

Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package forklift.activemq.test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import forklift.consumer.ProcessStep;
import forklift.message.ActiveMQHeaders;
import forklift.message.Header;

import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQMessage;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.Date;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
import forklift.producers.ProducerException;
import forklift.source.decorators.Queue;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -43,13 +44,13 @@ public class MessagingTest {
@forklift.decorators.Message
private Map<String, String> keyvalMsg;

@Before
public void before() {
@BeforeAll
public static void before() {
TestServiceManager.start();
}

@After
public void after() {
@AfterAll
public static void after() {
TestServiceManager.stop();
}

Expand Down Expand Up @@ -102,13 +103,13 @@ public void test() throws JMSException, ConnectorException, ProducerException {
// Shutdown the consumer after all the messages have been processed.
c.setOutOfMessages((listener) -> {
listener.shutdown();
Assert.assertTrue(ordered);
Assert.assertTrue("called was not == " + msgCount + " -- " + called.get(), called.get() == msgCount);
assertTrue(ordered);
assertTrue(called.get() == msgCount, "called was not == " + msgCount + " -- " + called.get());
});

// Start the consumer.
c.listen();

Assert.assertTrue(called.get() > 0);
assertTrue(called.get() > 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@
import forklift.producers.ProducerException;
import forklift.source.decorators.Queue;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

import javax.jms.JMSException;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

@Queue("q2")
public class ProducerTest {
private static AtomicInteger called = new AtomicInteger(0);
Expand All @@ -35,7 +36,7 @@ public class ProducerTest {
@forklift.decorators.Producer(queue="q2")
private ForkliftProducerI injectedProducer;

@Before
@BeforeEach
public void before() {
TestServiceManager.start();
called.set(0);
Expand All @@ -46,7 +47,7 @@ public void before() {
isPropOverwritten = true;
}

@After
@AfterEach
public void after() {
TestServiceManager.stop();
}
Expand Down Expand Up @@ -92,13 +93,13 @@ public void testSendStringMessage() throws ProducerException, ConnectorException
// Shutdown the consumer after all the messages have been processed.
c.setOutOfMessages((listener) -> {
listener.shutdown();
Assert.assertTrue("called was not == " + msgCount, called.get() == msgCount);
assertTrue(called.get() == msgCount, "called was not == " + msgCount);
});

// Start the consumer.
c.listen();

Assert.assertTrue(called.get() > 0);
assertTrue(called.get() > 0);
}

@Test
Expand All @@ -114,13 +115,13 @@ public void testSendObjectMessage() throws JMSException, ConnectorException, Pro
// Shutdown the consumer after all the messages have been processed.
c.setOutOfMessages((listener) -> {
listener.shutdown();
Assert.assertTrue("called was not == " + msgCount, called.get() == msgCount);
assertTrue(called.get() == msgCount, "called was not == " + msgCount);
});

// Start the consumer.
c.listen();

Assert.assertTrue(called.get() > 0);
assertTrue(called.get() > 0);
}

@Test
Expand All @@ -137,13 +138,13 @@ public void testSendKeyValueMessage() throws JMSException, ConnectorException, P
// Shutdown the consumer after all the messages have been processed.
c.setOutOfMessages((listener) -> {
listener.shutdown();
Assert.assertTrue("called was not == " + msgCount, called.get() == msgCount);
assertTrue(called.get() == msgCount, "called was not == " + msgCount);
});

// Start the consumer.
c.listen();

Assert.assertTrue(called.get() > 0);
assertTrue(called.get() > 0);
}

@Test
Expand All @@ -168,15 +169,15 @@ public void testSendTripleThreat() throws ConnectorException, ProducerException
// Shutdown the consumer after all the messages have been processed.
c.setOutOfMessages((listener) -> {
listener.shutdown();
Assert.assertTrue(ordered);
Assert.assertTrue("called was not == " + msgCount, called.get() == msgCount);
Assert.assertTrue("injectedProducer is null", isInjectNull == false);
assertTrue(ordered);
assertTrue(called.get() == msgCount, "called was not == " + msgCount);
assertTrue(isInjectNull == false, "injectedProducer is null");
});

// Start the consumer.
c.listen();

Assert.assertTrue(called.get() > 0);
assertTrue(called.get() > 0);
}

@Test
Expand Down Expand Up @@ -212,17 +213,17 @@ public void testPresets() throws JMSException, ConnectorException, ProducerExcep
// Shutdown the consumer after all the messages have been processed.
c.setOutOfMessages((listener) -> {
listener.shutdown();
Assert.assertTrue(ordered);
Assert.assertTrue("called was not == " + msgCount, called.get() == msgCount);
Assert.assertTrue("Message properties were overwritten", !isPropOverwritten);
Assert.assertTrue("Message properties were not set", isPropsSet);
Assert.assertTrue("Message headers were not set", isHeadersSet);
assertTrue(ordered);
assertTrue(called.get() == msgCount, "called was not == " + msgCount);
assertTrue(!isPropOverwritten, "Message properties were overwritten");
assertTrue(isPropsSet, "Message properties were not set");
assertTrue(isHeadersSet, "Message headers were not set");
});

// Start the consumer.
c.listen();

Assert.assertTrue(called.get() > 0);
assertTrue(called.get() > 0);
}

public class TestMessage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,27 @@
import forklift.producers.ForkliftSyncProducerI;
import forklift.source.decorators.Queue;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Future;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

public class ResponseTest {
@Before
public void before() {
@BeforeAll
public static void before() {
TestServiceManager.start();
}

@After
public void after() {
@AfterAll
public static void after() {
TestServiceManager.stop();
}

Expand Down Expand Up @@ -58,11 +61,11 @@ public void testStringResp() throws Exception {

// Verify that each future has been completed and has a valid data item.
futures.forEach((f) -> {
Assert.assertTrue(f.isDone());
assertTrue(f.isDone());
try {
Assert.assertEquals("test", f.get());
assertEquals("test", f.get());
} catch (Exception e) {
Assert.fail(e.getMessage());
fail(e.getMessage());
}
});
}
Expand Down Expand Up @@ -98,13 +101,13 @@ public void testMapResp() throws Exception {

// Verify that each future has been completed and has a valid data item.
futures.forEach((f) -> {
Assert.assertTrue(f.isDone());
assertTrue(f.isDone());
try {
Map<String, String> map = f.get();
Assert.assertTrue(map.containsKey("x"));
Assert.assertEquals("x", map.get("x"));
assertTrue(map.containsKey("x"));
assertEquals("x", map.get("x"));
} catch (Exception e) {
Assert.fail(e.getMessage());
fail(e.getMessage());
}
});
}
Expand Down Expand Up @@ -140,13 +143,13 @@ public void testObjResp() throws Exception {

// Verify that each future has been completed and has a valid data item.
futures.forEach((f) -> {
Assert.assertTrue(f.isDone());
assertTrue(f.isDone());
try {
ResponseObj o = f.get();
Assert.assertEquals("Dude", o.getName());
Assert.assertEquals(Integer.valueOf(22), o.getAge());
assertEquals("Dude", o.getName());
assertEquals(Integer.valueOf(22), o.getAge());
} catch (Exception e) {
Assert.fail(e.getMessage());
fail(e.getMessage());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package forklift.connectors;

import static org.junit.Assert.assertEquals;
import forklift.controller.AcknowledgedRecordHandler;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.OffsetAndMetadata;
import org.apache.kafka.common.TopicPartition;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
Expand All @@ -20,7 +22,7 @@ public class AcknowledgedRecordHandlerTests {
private AcknowledgedRecordHandler handler;
private Supplier<Boolean> predicate;

@Before
@BeforeEach
public void setup() {
this.handler = new AcknowledgedRecordHandler();
this.predicate = () -> true;
Expand Down
Loading