Skip to content

Commit

Permalink
2nd round of updates for conversion to junit5.
Browse files Browse the repository at this point in the history
  • Loading branch information
dthompsn committed Aug 5, 2020
1 parent 968531c commit 21e30de
Show file tree
Hide file tree
Showing 21 changed files with 92 additions and 92 deletions.
18 changes: 18 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ subprojects {

test {
useJUnitPlatform()
reports.html.enabled = false
// ignoreFailures true
testLogging {
events "passed", "skipped", "failed"
}
Expand Down Expand Up @@ -116,3 +118,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)
}

clean {
delete "$buildDir"
}

Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public class MessagingTest {
private Map<String, String> keyvalMsg;

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import javax.jms.JMSException;

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

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

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

@AfterAll
@AfterEach
public void after() {
TestServiceManager.stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.OffsetAndMetadata;
import org.apache.kafka.common.TopicPartition;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -22,7 +22,7 @@ public class AcknowledgedRecordHandlerTests {
private AcknowledgedRecordHandler handler;
private Supplier<Boolean> predicate;

@BeforeAll
@BeforeEach
public void setup() {
this.handler = new AcknowledgedRecordHandler();
this.predicate = () -> true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
Expand All @@ -42,13 +42,13 @@ public class KafkaControllerTests {
@Captor
private ArgumentCaptor<Collection<String>> subscribeCaptor;

@BeforeAll
@BeforeEach
public void setup() {
MockitoAnnotations.initMocks(this);
this.controller = new KafkaController(kafkaConsumer, messageStream, topic1);
}

@AfterAll
@AfterEach
public void teardown() throws InterruptedException {
this.controller.stop(500, TimeUnit.MILLISECONDS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import forklift.message.MessageStream;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.common.TopicPartition;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
Expand All @@ -21,7 +21,7 @@ public class MessageStreamTests {
private KafkaController controller;
private MessageStream stream;

@BeforeAll
@BeforeEach
public void setup() {
stream = new MessageStream();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

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

import forklift.connectors.ConnectorException;
Expand All @@ -21,7 +21,7 @@ public class KafkaTopicConsumerTests {
private MessageStream messageStream;
private KafkaTopicConsumer consumer;

@BeforeAll
@BeforeEach
public void setup() {
this.topic = "testTopic";
this.controller = mock(KafkaController.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.apache.avro.generic.GenericRecord;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.common.TopicPartition;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
Expand Down Expand Up @@ -54,7 +54,7 @@ public class KafkaControllerRebalanceTests {
private ForkliftConnectorI mockConnector;
private Forklift forklift;

@BeforeAll
@BeforeEach
public void setup() throws Exception {
donePolling = new AtomicBoolean(false);
processedRecords = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import forklift.consumer.Consumer;
import forklift.decorators.OnMessage;
import forklift.exception.StartupException;
import forklift.integration.server.TestServiceManager;
import forklift.producers.ForkliftProducerI;
import forklift.producers.ProducerException;
import forklift.schemas.StateCode;
Expand All @@ -16,22 +15,9 @@
import java.util.HashMap;
import java.util.Map;

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

public class AvroMessageTests extends BaseIntegrationTest {
@AfterAll
public void after() {
serviceManager.stop();
}

@BeforeAll
public void setup() {
serviceManager = new TestServiceManager();
serviceManager.start();
}

@Test
public void testComplexAvroMessageWithProperty() throws ProducerException, ConnectorException, InterruptedException, StartupException {
Forklift forklift = serviceManager.newManagedForkliftInstance("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -37,21 +38,25 @@ public abstract class BaseIntegrationTest {
protected static final Logger log = LoggerFactory.getLogger(BaseIntegrationTest.class);
protected static Set<String> sentMessageIds = ConcurrentHashMap.newKeySet();
protected static Set<String> consumedMessageIds = ConcurrentHashMap.newKeySet();
protected TestServiceManager serviceManager;
protected static TestServiceManager serviceManager;
protected final int maxTimeouts = 5;
protected int timeouts = 0;

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

@BeforeEach
public void setupMaps() {
sentMessageIds = ConcurrentHashMap.newKeySet();
consumedMessageIds = ConcurrentHashMap.newKeySet();
}

@BeforeAll
public void setup() {
public static void setup() {
serviceManager = new TestServiceManager();
serviceManager.start();
sentMessageIds = ConcurrentHashMap.newKeySet();
consumedMessageIds = ConcurrentHashMap.newKeySet();
}

protected void messageAsserts(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import forklift.decorators.OnMessage;
import forklift.decorators.Producer;
import forklift.exception.StartupException;
import forklift.integration.server.TestServiceManager;
import forklift.producers.ForkliftProducerI;
import forklift.producers.ProducerException;
import forklift.source.decorators.Queue;
Expand All @@ -17,26 +16,13 @@
import java.util.HashMap;
import java.util.Map;

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

public class ForkliftMessageTests extends BaseIntegrationTest {

private static boolean isPropsSet = false;
private static boolean isPropOverwritten = true;

@AfterAll
public void after() {
serviceManager.stop();
}

@BeforeAll
public void setup() {
serviceManager = new TestServiceManager();
serviceManager.start();
}

@Test
public void testForkliftMessageWithProperties()
throws ProducerException, ConnectorException, InterruptedException, StartupException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
import forklift.controller.KafkaController;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class KafkaMessageTests {

private KafkaController controller;
private KafkaMessage message;
private ConsumerRecord<?, ?> record;
private static KafkaController controller;
private static KafkaMessage message;
private static ConsumerRecord<?, ?> record;

@BeforeAll
@BeforeEach
public void setup() {
controller = mock(KafkaController.class);
record = new ConsumerRecord<>("testTopic", 0, 1L, "key", "value");
Expand Down
6 changes: 3 additions & 3 deletions core/src/test/java/forklift/ForkliftTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
import java.net.URL;

public class ForkliftTest {
protected Forklift forklift;
protected static Forklift forklift;

@BeforeAll
public void start()
public static void start()
throws StartupException {
forklift = new Forklift();
forklift.start(Mockito.mock(ForkliftConnectorI.class));
}

@AfterAll
public void stop() {
public static void stop() {
forklift.shutdown();
}

Expand Down
8 changes: 5 additions & 3 deletions core/src/test/java/forklift/Startup.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import forklift.connectors.ForkliftConnectorI;
import forklift.exception.StartupException;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

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

import java.io.IOException;

/**
Expand All @@ -25,12 +27,12 @@ public void start()
int count = 20;
while (!forklift.isRunning() && count-- > 0)
Thread.sleep(250);
Assertions.assertTrue(forklift.isRunning());
assertTrue(forklift.isRunning());

forklift.shutdown();
count = 20;
while (forklift.isRunning() && count-- > 0)
Thread.sleep(250);
Assertions.assertFalse(forklift.isRunning());
assertFalse(forklift.isRunning());
}
}
Loading

0 comments on commit 21e30de

Please sign in to comment.