Skip to content

Commit

Permalink
Remove deprecated doPreSetup/doPostSetup methods and some cosmetic edits
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Gantenbein committed Sep 26, 2024
1 parent 68374f7 commit b3c9b67
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.camel.builder.NotifyBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.spring.junit5.CamelSpringTestSupport;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

Expand All @@ -40,11 +41,11 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class SpringTarFileDataFormatTest extends CamelSpringTestSupport {
class SpringTarFileDataFormatTest extends CamelSpringTestSupport {
private static final File TEST_DIR = new File("target/springtar");

@Test
public void testTarWithoutFileName() throws Exception {
void testTarWithoutFileName() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:tar");
mock.expectedMessageCount(1);

Expand All @@ -65,7 +66,7 @@ public void testTarWithoutFileName() throws Exception {
}

@Test
public void testTarWithFileName() throws Exception {
void testTarWithFileName() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:tar");
mock.expectedMessageCount(1);
mock.expectedHeaderReceived(FILE_NAME, "poem.txt.tar");
Expand All @@ -87,7 +88,7 @@ public void testTarWithFileName() throws Exception {
}

@Test
public void testUntar() throws Exception {
void testUntar() throws Exception {
getMockEndpoint("mock:untar").expectedBodiesReceived(TEXT);
getMockEndpoint("mock:untar").expectedHeaderReceived(FILE_NAME, "file");

Expand All @@ -97,7 +98,7 @@ public void testUntar() throws Exception {
}

@Test
public void testTarAndUntar() throws Exception {
void testTarAndUntar() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:tarAndUntar");
mock.expectedMessageCount(1);

Expand All @@ -111,7 +112,7 @@ public void testTarAndUntar() throws Exception {
}

@Test
public void testTarToFileWithoutFileName() throws Exception {
void testTarToFileWithoutFileName() throws Exception {
NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();

String[] files = TEST_DIR.list();
Expand Down Expand Up @@ -142,7 +143,7 @@ public void testTarToFileWithoutFileName() throws Exception {
}

@Test
public void testTarToFileWithFileName() throws Exception {
void testTarToFileWithFileName() throws Exception {
NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();

MockEndpoint mock = getMockEndpoint("mock:tarToFile");
Expand Down Expand Up @@ -172,7 +173,7 @@ public void testTarToFileWithFileName() throws Exception {
}

@Test
public void testDslTar() throws Exception {
void testDslTar() throws Exception {
getMockEndpoint("mock:dslTar").expectedHeaderReceived(FILE_NAME, "poem.txt.tar");

template.sendBodyAndHeader("direct:dslTar", TEXT, FILE_NAME, "poem.txt");
Expand All @@ -181,7 +182,7 @@ public void testDslTar() throws Exception {
}

@Test
public void testDslUntar() throws Exception {
void testDslUntar() throws Exception {
getMockEndpoint("mock:dslUntar").expectedBodiesReceived(TEXT);
getMockEndpoint("mock:dslUntar").expectedHeaderReceived(FILE_NAME, "test.txt");

Expand All @@ -190,8 +191,8 @@ public void testDslUntar() throws Exception {
MockEndpoint.assertIsSatisfied(context);
}

@Override
public void doPostSetup() {
@AfterEach
public void cleanOutputDirectory() {
deleteDirectory(TEST_DIR);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import org.junit.jupiter.api.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringTarSplitterRouteTest extends CamelSpringTestSupport {
class SpringTarSplitterRouteTest extends CamelSpringTestSupport {

@Test
public void testSplitter() throws InterruptedException {
void testSplitter() throws InterruptedException {
MockEndpoint processTarEntry = getMockEndpoint("mock:processTarEntry");

processTarEntry.expectedBodiesReceivedInAnyOrder("chau", "hi", "hola", "hello", "greetings");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.apache.commons.compress.archivers.ArchiveStreamFactory;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;

import static org.apache.camel.Exchange.FILE_NAME;
Expand All @@ -56,13 +57,13 @@
/**
* Unit tests for {@link TarFileDataFormat}.
*/
public class TarFileDataFormatTest extends CamelTestSupport {
class TarFileDataFormatTest extends CamelTestSupport {

private static final File TEST_DIR = new File("target/tar");
private TarFileDataFormat tar;

@Test
public void testTarWithoutFileName() throws Exception {
void testTarWithoutFileName() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:tar");
mock.expectedMessageCount(1);

Expand All @@ -84,7 +85,7 @@ public void testTarWithoutFileName() throws Exception {
}

@Test
public void testTarWithFileName() throws Exception {
void testTarWithFileName() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:tar");
mock.expectedMessageCount(1);
mock.expectedHeaderReceived(FILE_NAME, "poem.txt.tar");
Expand All @@ -106,7 +107,7 @@ public void testTarWithFileName() throws Exception {
}

@Test
public void testTarWithPathElements() throws Exception {
void testTarWithPathElements() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:tar");
mock.expectedMessageCount(1);
mock.expectedHeaderReceived(FILE_NAME, "poem.txt.tar");
Expand All @@ -127,7 +128,7 @@ public void testTarWithPathElements() throws Exception {
}

@Test
public void testTarWithPreservedPathElements() throws Exception {
void testTarWithPreservedPathElements() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:tar");
mock.expectedMessageCount(1);
mock.expectedHeaderReceived(FILE_NAME, "poem.txt.tar");
Expand Down Expand Up @@ -155,7 +156,7 @@ public void testTarWithPreservedPathElements() throws Exception {
}

@Test
public void testUntar() throws Exception {
void testUntar() throws Exception {
getMockEndpoint("mock:untar").expectedBodiesReceived(TEXT);
getMockEndpoint("mock:untar").expectedHeaderReceived(FILE_NAME, "file");

Expand All @@ -165,15 +166,15 @@ public void testUntar() throws Exception {
}

@Test
public void testUntarWithCorruptedTarFile() {
void testUntarWithCorruptedTarFile() {
final File body = new File("src/test/resources/data/corrupt.tar");

assertThrows(CamelExecutionException.class,
() -> template.sendBody("direct:corruptUntar", body));
}

@Test
public void testTarAndUntar() throws Exception {
void testTarAndUntar() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:tarAndUntar");
mock.expectedMessageCount(1);

Expand All @@ -187,7 +188,7 @@ public void testTarAndUntar() throws Exception {
}

@Test
public void testTarToFileWithoutFileName() throws Exception {
void testTarToFileWithoutFileName() throws Exception {
NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();

String[] files = TEST_DIR.list();
Expand Down Expand Up @@ -218,7 +219,7 @@ public void testTarToFileWithoutFileName() throws Exception {
}

@Test
public void testTarToFileWithFileName() throws Exception {
void testTarToFileWithFileName() throws Exception {
NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();

MockEndpoint mock = getMockEndpoint("mock:tarToFile");
Expand Down Expand Up @@ -249,7 +250,7 @@ public void testTarToFileWithFileName() throws Exception {
}

@Test
public void testDslTar() throws Exception {
void testDslTar() throws Exception {
getMockEndpoint("mock:dslTar").expectedHeaderReceived(FILE_NAME, "poem.txt.tar");

template.sendBodyAndHeader("direct:dslTar", TEXT, FILE_NAME, "poem.txt");
Expand All @@ -258,7 +259,7 @@ public void testDslTar() throws Exception {
}

@Test
public void testDslUntar() throws Exception {
void testDslUntar() throws Exception {
getMockEndpoint("mock:dslUntar").expectedBodiesReceived(TEXT);
getMockEndpoint("mock:dslUntar").expectedHeaderReceived(FILE_NAME, "test.txt");

Expand All @@ -268,7 +269,7 @@ public void testDslUntar() throws Exception {
}

@Test
public void testUntarWithEmptyDirectorySupported() {
void testUntarWithEmptyDirectorySupported() {
deleteDirectory(new File("hello_out"));
tar.setUsingIterator(true);
tar.setAllowEmptyDirectory(true);
Expand All @@ -278,7 +279,7 @@ public void testUntarWithEmptyDirectorySupported() {
}

@Test
public void testUntarWithEmptyDirectoryUnsupported() {
void testUntarWithEmptyDirectoryUnsupported() {
deleteDirectory(new File("hello_out"));
tar.setUsingIterator(true);
tar.setAllowEmptyDirectory(false);
Expand All @@ -288,16 +289,16 @@ public void testUntarWithEmptyDirectoryUnsupported() {
}

@Test
public void testUnzipMaxDecompressedSize() throws Exception {
void testUnzipMaxDecompressedSize() throws Exception {
final byte[] files = getTaredText("file");

// We are only allowing 10 bytes to be decompressed, so we expect an error
assertThrows(CamelExecutionException.class,
() -> template.sendBody("direct:untarMaxDecompressedSize", files));
}

@Override
public void doPostSetup() {
@AfterEach
public void cleanOutputDirectory() {
deleteDirectory(TEST_DIR);
}

Expand Down Expand Up @@ -352,7 +353,7 @@ public void process(Exchange exchange) throws Exception {
} else {
outputFile.getParentFile().mkdirs();
try (TarArchiveInputStream debInputStream
= (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream("tar",
= new ArchiveStreamFactory().createArchiveInputStream("tar",
is)) {
copy(debInputStream, outputFile);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,22 @@
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.apache.camel.test.junit5.TestSupport.deleteDirectory;
import static org.junit.jupiter.api.Assertions.assertFalse;

public class TarFileSplitAndDeleteTest extends CamelTestSupport {
class TarFileSplitAndDeleteTest extends CamelTestSupport {

@Override
public void doPreSetup() {
@BeforeEach
public void cleanOutputDirectories() {
deleteDirectory("target/testDeleteTarFileWhenUnmarshalWithDataFormat");
deleteDirectory("target/testDeleteTarFileWhenUnmarshalWithSplitter");
}

@Test
public void testDeleteTarFileWhenUnmarshalWithDataFormat() throws Exception {
void testDeleteTarFileWhenUnmarshalWithDataFormat() throws Exception {
NotifyBuilder notify = new NotifyBuilder(context)
.from("file://target/" + "testDeleteTarFileWhenUnmarshalWithDataFormat").whenDone(1).create();
getMockEndpoint("mock:end").expectedMessageCount(3);
Expand All @@ -58,7 +59,7 @@ public void testDeleteTarFileWhenUnmarshalWithDataFormat() throws Exception {
}

@Test
public void testDeleteTarFileWhenUnmarshalWithSplitter() throws Exception {
void testDeleteTarFileWhenUnmarshalWithSplitter() throws Exception {
NotifyBuilder notify = new NotifyBuilder(context).from("file://target/" + "testDeleteTarFileWhenUnmarshalWithSplitter")
.whenDone(1).create();
getMockEndpoint("mock:end").expectedMessageCount(3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.Test;

public class TarFileSplitIteratorCorruptTest extends CamelTestSupport {
class TarFileSplitIteratorCorruptTest extends CamelTestSupport {

@Test
public void testTarFileUnmarshal() throws Exception {
void testTarFileUnmarshal() throws Exception {
getMockEndpoint("mock:dead").expectedMessageCount(1);
getMockEndpoint("mock:dead").message(0).exchangeProperty(Exchange.EXCEPTION_CAUGHT)
.isInstanceOf(IllegalStateException.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,20 @@
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.apache.camel.test.junit5.TestSupport.deleteDirectory;

public class TarSplitterRouteIssueTest extends CamelTestSupport {
class TarSplitterRouteIssueTest extends CamelTestSupport {

@Override
public void doPreSetup() {
@BeforeEach
public void cleanOutputDirectory() {
deleteDirectory("target/tar");
}

@Test
public void testSplitter() throws Exception {
void testSplitter() throws Exception {
getMockEndpoint("mock:entry").expectedMessageCount(3);

template.sendBody("direct:decompressFiles", new File("src/test/resources/data/tarfile3.tar"));
Expand All @@ -42,7 +43,7 @@ public void testSplitter() throws Exception {
}

@Test
public void testSplitterWithWrongFile() throws Exception {
void testSplitterWithWrongFile() throws Exception {
getMockEndpoint("mock:entry").expectedMessageCount(0);
getMockEndpoint("mock:errors").expectedMessageCount(1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,29 @@
import org.apache.commons.compress.archivers.ArchiveStreamFactory;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.apache.camel.test.junit5.TestSupport.deleteDirectory;
import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class AggregationStrategyWithFilenameHeaderTest extends CamelTestSupport {
class AggregationStrategyWithFilenameHeaderTest extends CamelTestSupport {

private static final List<String> FILE_NAMES = Arrays.asList("foo", "bar");

private TarAggregationStrategy tar = new TarAggregationStrategy(false, true);

@Override
public void doPreSetup() {
@BeforeEach
public void cleanOutputDirectories() {
tar.setParentDir("target/temp");
deleteDirectory("target/temp");
deleteDirectory("target/out");
}

@Test
public void testSplitter() throws Exception {
void testSplitter() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:aggregateToTarEntry");
mock.expectedMessageCount(1);

Expand All @@ -69,7 +70,7 @@ public void testSplitter() throws Exception {
File resultFile = files[0];

final TarArchiveInputStream tis
= (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.TAR,
= new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.TAR,
new BufferedInputStream(new FileInputStream(resultFile)));
try {
int fileCount = 0;
Expand Down
Loading

0 comments on commit b3c9b67

Please sign in to comment.