Zip: Some deep cleanup and polishing

* Upgrade to Gradle-2.5, SI-4.2.4
* Remove redundant dependencies
* Add `slf4j-log4j12` to avoid log noise during testing
* Add `settings.gradle` to allow Artifactory Release Management
* Move XSD stuff to the proper place - `org\springframework\integration\zip\config`
* Get rid of manual `enum` transformation in the `Parser`:
  - we can't do that there because `property-placeholder` and SpEL are processed later
  - no reason to do that at all - `enum`s are properly converted by the SF during bean population phase
* Fix `UnZipTransformer` to `delete()` file in the `finally` block after closing the `InputStream` on file
This commit is contained in:
Artem Bilan
2016-01-07 21:43:15 -05:00
parent f7b31228c2
commit 0a5fedcd7a
21 changed files with 170 additions and 240 deletions

View File

@@ -12,9 +12,11 @@
*/
package org.springframework.integration.zip.config.xml;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -24,7 +26,8 @@ import java.util.zip.Deflater;
import org.junit.After;
import org.junit.Test;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.channel.AbstractMessageChannel;
@@ -38,10 +41,8 @@ import org.springframework.integration.zip.transformer.ZipTransformer;
import org.springframework.util.Assert;
/**
*
* @author Gunnar Hillert
* @since 1.0
*
*/
public class ZipTransformerParserTests {
@@ -52,7 +53,7 @@ public class ZipTransformerParserTests {
setUp("ZipTransformerParserTests.xml", getClass());
EventDrivenConsumer consumer = this.context.getBean("zipTransformerWithDefaults", EventDrivenConsumer.class);
EventDrivenConsumer consumer = this.context.getBean("zipTransformerWithDefaults", EventDrivenConsumer.class);
final AbstractMessageChannel inputChannel = TestUtils.getPropertyValue(consumer, "inputChannel", AbstractMessageChannel.class);
assertEquals("input", inputChannel.getComponentName());
@@ -93,7 +94,7 @@ public class ZipTransformerParserTests {
setUp("ZipTransformerParserTests.xml", getClass());
EventDrivenConsumer consumer = this.context.getBean("zipTransformer", EventDrivenConsumer.class);
EventDrivenConsumer consumer = this.context.getBean("zipTransformer", EventDrivenConsumer.class);
final AbstractMessageChannel inputChannel = TestUtils.getPropertyValue(consumer, "inputChannel", AbstractMessageChannel.class);
assertEquals("input", inputChannel.getComponentName());
@@ -130,30 +131,27 @@ public class ZipTransformerParserTests {
}
@Test
public void testZiptransformerParserWithIncorrectResultType() {
public void testZipTransformerParserWithIncorrectResultType() {
try {
setUp("ZipTransformerParserTestsWithIncorrectResultType.xml", getClass());
setUp("ZipTransformerParserTestsWithIncorrectResultType.xml", getClass());
fail("Expected a BeanDefinitionParsingException to be thrown.");
}
catch (BeanDefinitionParsingException e) {
String expectedErrorMessage = "Unable to convert the provided result-type 'INCORRECT' " +
"to the respective ZipResultType enum.";
assertTrue(String.format("Expected exception message to contain '%s' but got '%s'", expectedErrorMessage, e.getMessage()),
e.getMessage().contains(expectedErrorMessage));
return;
catch (BeanCreationException e) {
assertThat(e.getMessage(), containsString("Failed to convert property value of type [java.lang.String] " +
"to required type [org.springframework.integration.zip.transformer.ZipResultType] "));
}
fail("Expected a BeanDefinitionParsingException to be thrown.");
}
@After
public void tearDown(){
if(context != null){
public void tearDown() {
if (context != null) {
context.close();
}
}
public void setUp(String name, Class<?> cls){
context = new ClassPathXmlApplicationContext(name, cls);
public void setUp(String name, Class<?> cls) {
context = new ClassPathXmlApplicationContext(name, cls);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
package org.springframework.integration.zip.transformer;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -31,6 +30,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
@@ -43,11 +43,12 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
*
* @author Gunnar Hillert
* @author Artem Bilan
* @since 1.0
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath:org/springframework/integration/zip/transformer/UnZipTransformerTests.xml"})
@ContextConfiguration
public class UnZipTransformerTests {
@Rule
@@ -70,7 +71,7 @@ public class UnZipTransformerTests {
* @throws IOException
*/
@Test
public void unzipSingleFileAsInputstreamToByteArray() throws IOException {
public void unzipSingleFileAsInputStreamToByteArray() throws IOException {
final Resource resource = resourceLoader.getResource("classpath:testzipdata/single.zip");
final InputStream is = resource.getInputStream();
@@ -142,7 +143,9 @@ public class UnZipTransformerTests {
final File inputFile = new File(this.workDir, "unzipSingleFileToByteArray");
IOUtils.copy(is, new FileOutputStream(inputFile));
FileOutputStream output = new FileOutputStream(inputFile);
IOUtils.copy(is, output);
output.close();
final Message<File> message = MessageBuilder.withPayload(inputFile).build();
@@ -172,7 +175,7 @@ public class UnZipTransformerTests {
* @throws IOException
*/
@Test
public void unzipMultipleFilesAsInputstreamToByteArray() throws IOException {
public void unzipMultipleFilesAsInputStreamToByteArray() throws IOException {
final Resource resource = resourceLoader.getResource("classpath:testzipdata/countries.zip");
final InputStream is = resource.getInputStream();
@@ -228,26 +231,26 @@ public class UnZipTransformerTests {
}
@Test
public void unzipInvalidZipFile() throws FileNotFoundException, IOException, InterruptedException {
public void unzipInvalidZipFile() throws IOException, InterruptedException {
final File fileToUnzip = testFolder.newFile();
File fileToUnzip = testFolder.newFile();
FileUtils.writeStringToFile(fileToUnzip, "hello world");
final UnZipTransformer unZipTransformer = new UnZipTransformer();
UnZipTransformer unZipTransformer = new UnZipTransformer();
unZipTransformer.setZipResultType(ZipResultType.BYTE_ARRAY);
unZipTransformer.setExpectSingleResult(true);
unZipTransformer.afterPropertiesSet();
final Message<File> message = MessageBuilder.withPayload(fileToUnzip).build();
Message<File> message = MessageBuilder.withPayload(fileToUnzip).build();
try {
unZipTransformer.transform(message);
Assert.fail("Expected a MessagingException to be thrown.");
}
catch (MessagingException e) {
Assert.assertTrue(e.getMessage().contains(String.format("Not a zip file: '%s'.", fileToUnzip.getAbsolutePath())));
return;
Assert.assertTrue(e.getMessage().contains(String.format("Not a zip file: '%s'.",
fileToUnzip.getAbsolutePath())));
}
Assert.fail("Expected a MessagingException to be thrown.");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,15 +35,17 @@ import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.springframework.messaging.Message;
import org.zeroturnaround.zip.ZipUtil;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.zip.ZipHeaders;
import org.zeroturnaround.zip.ZipUtil;
import org.springframework.messaging.Message;
/**
*
* @author Gunnar Hillert
* @author Artem Bilan
* @since 1.0
*
*/
@@ -59,7 +61,7 @@ public class ZipTransformerTests {
* @throws IOException
*/
@Test
public void zipString() throws FileNotFoundException, IOException {
public void zipString() throws IOException {
final ZipTransformer zipTransformer = new ZipTransformer();
zipTransformer.setBeanFactory(mock(BeanFactory.class));
zipTransformer.setZipResultType(ZipResultType.BYTE_ARRAY);
@@ -95,7 +97,7 @@ public class ZipTransformerTests {
}
@Test
public void zipStringCollection() throws FileNotFoundException, IOException {
public void zipStringCollection() throws IOException {
final ZipTransformer zipTransformer = new ZipTransformer();
zipTransformer.setBeanFactory(mock(BeanFactory.class));
zipTransformer.setZipResultType(ZipResultType.BYTE_ARRAY);
@@ -161,10 +163,9 @@ public class ZipTransformerTests {
}
@Test
public void zipStringToFile() throws FileNotFoundException, IOException {
public void zipStringToFile() throws IOException {
final ZipTransformer zipTransformer = new ZipTransformer();
zipTransformer.setBeanFactory(mock(BeanFactory.class));
zipTransformer.setZipResultType(ZipResultType.FILE);
zipTransformer.afterPropertiesSet();
final String stringToCompress = "Hello World";