ZIP: More Polishing

This commit is contained in:
Artem Bilan
2016-01-08 12:15:31 -05:00
parent 0a5fedcd7a
commit cd37ecae9a
12 changed files with 71 additions and 75 deletions

View File

@@ -15,8 +15,8 @@
<int:chain input-channel="input" output-channel="out">
<int-zip:unzip-transformer result-type="BYTE_ARRAY"/>
<int:splitter method="splitUnzippedMap">
<bean class="org.springframework.integration.zip.transformer.splitter.UnZipResultSplitter"/>
<int:splitter>
<bean class="org.springframework.integration.zip.splitter.UnZipResultSplitter"/>
</int:splitter>
</int:chain>

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.
@@ -25,10 +25,10 @@ import org.apache.commons.io.IOUtils;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -60,29 +60,28 @@ public class UnZip2FileTests {
@Before
public void setup() throws IOException {
this.workDir = testFolder.newFolder();
properties.put("workDir", workDir);
this.workDir = this.testFolder.newFolder();
properties.put("workDir", this.workDir);
System.out.print(this.workDir.getAbsolutePath());
context = new AnnotationConfigApplicationContext();
context.register(ContextConfiguration.class);
context.refresh();
input = context.getBean("input", MessageChannel.class);
resourceLoader = context;
this.context = new AnnotationConfigApplicationContext();
this.context.register(ContextConfiguration.class);
this.context.refresh();
this.input = this.context.getBean("input", MessageChannel.class);
this.resourceLoader = this.context;
}
@After
public void cleanup() {
if (context != null) {
context.close();
if (this.context != null) {
this.context.close();
}
}
@Test
@Ignore
public void unZipWithOneEntry() throws Exception {
final Resource resource = resourceLoader.getResource("classpath:testzipdata/single.zip");
final Resource resource = this.resourceLoader.getResource("classpath:testzipdata/single.zip");
final InputStream is = resource.getInputStream();
byte[] zipdata = IOUtils.toByteArray(is);
@@ -157,4 +156,5 @@ public class UnZip2FileTests {
}
}
}

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. You may obtain a copy of the License at
@@ -10,6 +10,7 @@
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package org.springframework.integration.zip.config.xml;
import static org.junit.Assert.assertEquals;
@@ -45,7 +46,7 @@ public class UnZipTransformerParserTests {
private ConfigurableApplicationContext context;
@Test
public void testUnZiptransformerParserWithDefaults() {
public void testUnZipTransformerParserWithDefaults() {
setUp("UnZipTransformerParserTests.xml", getClass());
@@ -86,7 +87,7 @@ public class UnZipTransformerParserTests {
}
@Test
public void testUnZiptransformerParserWithExplicitSettings() {
public void testUnZipTransformerParserWithExplicitSettings() {
setUp("UnZipTransformerParserTests.xml", getClass());

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. You may obtain a copy of the License at
@@ -10,6 +10,7 @@
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package org.springframework.integration.zip.config.xml;
import static org.hamcrest.Matchers.containsString;
@@ -49,7 +50,7 @@ public class ZipTransformerParserTests {
private ConfigurableApplicationContext context;
@Test
public void testZiptransformerParserWithDefaults() {
public void testZipTransformerParserWithDefaults() {
setUp("ZipTransformerParserTests.xml", getClass());
@@ -90,7 +91,7 @@ public class ZipTransformerParserTests {
}
@Test
public void testZiptransformerParserWithExplicitSettings() {
public void testZipTransformerParserWithExplicitSettings() {
setUp("ZipTransformerParserTests.xml", getClass());

View File

@@ -73,7 +73,7 @@ public class UnZipTransformerTests {
@Test
public void unzipSingleFileAsInputStreamToByteArray() throws IOException {
final Resource resource = resourceLoader.getResource("classpath:testzipdata/single.zip");
final Resource resource = this.resourceLoader.getResource("classpath:testzipdata/single.zip");
final InputStream is = resource.getInputStream();
final Message<InputStream> message = MessageBuilder.withPayload(is).build();
@@ -103,7 +103,7 @@ public class UnZipTransformerTests {
@Test
public void unzipSingleFileToByteArray() throws IOException {
final Resource resource = resourceLoader.getResource("classpath:testzipdata/single.zip");
final Resource resource = this.resourceLoader.getResource("classpath:testzipdata/single.zip");
final InputStream is = resource.getInputStream();
final File inputFile = new File(this.workDir, "unzipSingleFileToByteArray");
@@ -138,7 +138,7 @@ public class UnZipTransformerTests {
@Test
public void unzipSingleFileToByteArrayWithDeleteFilesTrue() throws IOException {
final Resource resource = resourceLoader.getResource("classpath:testzipdata/single.zip");
final Resource resource = this.resourceLoader.getResource("classpath:testzipdata/single.zip");
final InputStream is = resource.getInputStream();
final File inputFile = new File(this.workDir, "unzipSingleFileToByteArray");
@@ -177,7 +177,7 @@ public class UnZipTransformerTests {
@Test
public void unzipMultipleFilesAsInputStreamToByteArray() throws IOException {
final Resource resource = resourceLoader.getResource("classpath:testzipdata/countries.zip");
final Resource resource = this.resourceLoader.getResource("classpath:testzipdata/countries.zip");
final InputStream is = resource.getInputStream();
final Message<InputStream> message = MessageBuilder.withPayload(is).build();
@@ -205,9 +205,9 @@ public class UnZipTransformerTests {
* @throws IOException
*/
@Test
public void unzipMultipleFilesAsInputstreamWithExpectSingleResultTrue() throws IOException {
public void unzipMultipleFilesAsInputStreamWithExpectSingleResultTrue() throws IOException {
final Resource resource = resourceLoader.getResource("classpath:testzipdata/countries.zip");
final Resource resource = this.resourceLoader.getResource("classpath:testzipdata/countries.zip");
final InputStream is = resource.getInputStream();
final Message<InputStream> message = MessageBuilder.withPayload(is).build();
@@ -233,7 +233,7 @@ public class UnZipTransformerTests {
@Test
public void unzipInvalidZipFile() throws IOException, InterruptedException {
File fileToUnzip = testFolder.newFile();
File fileToUnzip = this.testFolder.newFile();
FileUtils.writeStringToFile(fileToUnzip, "hello world");
UnZipTransformer unZipTransformer = new UnZipTransformer();

View File

@@ -148,7 +148,8 @@ public class ZipTransformerTests {
Assert.assertTrue(file.isFile());
//See http://stackoverflow.com/questions/3725662/what-is-the-earliest-timestamp-value-that-is-supported-in-zip-file-format
Assert.assertTrue(String.format("%s : %s", fileDate.getTime() - 4000, file.lastModified()), (fileDate.getTime() - 4000) < file.lastModified());
Assert.assertTrue(String.format("%s : %s", fileDate.getTime() - 4000, file.lastModified()),
(fileDate.getTime() - 4000) < file.lastModified());
Assert.assertTrue((fileDate.getTime() + 4000) > file.lastModified());
Assert.assertTrue(
@@ -241,8 +242,7 @@ public class ZipTransformerTests {
zipTransformer.setBeanFactory(mock(BeanFactory.class));
zipTransformer.afterPropertiesSet();
final Message<Collection<File>> message = MessageBuilder.withPayload(files)
.build();
final Message<Collection<File>> message = MessageBuilder.withPayload(files).build();
final Message<?> result = zipTransformer.transform(message);
@@ -259,7 +259,7 @@ public class ZipTransformerTests {
private File createTestFile(int size) throws IOException {
final File temporaryTestDirectory = testFolder.newFolder();
final File temporaryTestDirectory = this.testFolder.newFolder();
final File testFile = new File(temporaryTestDirectory, "testdata" + UUID.randomUUID().toString() + ".data");