INT-2621: make tests verifying file paths OS independent

INT-2621 Polishing

Move file separator replacement code to TestUtils in
s-i-test.
This commit is contained in:
Artem Bilan
2012-06-18 11:10:45 +03:00
committed by Gary Russell
parent a6049bc51c
commit 81579f7491
2 changed files with 23 additions and 5 deletions

View File

@@ -30,12 +30,14 @@ import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel; import org.springframework.integration.MessageChannel;
import org.springframework.integration.MessageHandlingException; import org.springframework.integration.MessageHandlingException;
import org.springframework.integration.support.MessageBuilder; import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.FileCopyUtils; import org.springframework.util.FileCopyUtils;
/** /**
* @author Gunnar Hillert * @author Gunnar Hillert
* @author Artem Bilan
*/ */
@ContextConfiguration @ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@@ -43,7 +45,7 @@ public class FileOutboundChannelAdapterIntegrationTests {
static final String DEFAULT_ENCODING = "UTF-8"; static final String DEFAULT_ENCODING = "UTF-8";
static final String SAMPLE_CONTENT = "HelloWorld\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"; static final String SAMPLE_CONTENT = "HelloWorld";
static File workDir; static File workDir;
@@ -118,7 +120,9 @@ public class FileOutboundChannelAdapterIntegrationTests {
try { try {
this.inputChannelSaveToSubDirWrongExpression.send(message); this.inputChannelSaveToSubDirWrongExpression.send(message);
} catch (MessageHandlingException e) { } catch (MessageHandlingException e) {
Assert.assertEquals("Destination path [target/base-directory/sub-directory/foo.txt] does not point to a directory.", e.getCause().getMessage()); Assert.assertEquals(
TestUtils.applySystemFileSeparator("Destination path [target/base-directory/sub-directory/foo.txt] does not point to a directory."),
e.getCause().getMessage());
return; return;
} }
@@ -155,7 +159,9 @@ public class FileOutboundChannelAdapterIntegrationTests {
try { try {
this.inputChannelSaveToSubDirAutoCreateOff.send(message); this.inputChannelSaveToSubDirAutoCreateOff.send(message);
} catch (MessageHandlingException e) { } catch (MessageHandlingException e) {
Assert.assertEquals("Destination directory [target/base-directory2/sub-directory2] does not exist.", e.getCause().getMessage()); Assert.assertEquals(
TestUtils.applySystemFileSeparator("Destination directory [target/base-directory2/sub-directory2] does not exist."),
e.getCause().getMessage());
return; return;
} }
@@ -215,4 +221,5 @@ public class FileOutboundChannelAdapterIntegrationTests {
Assert.fail("Was expecting a MessageHandlingException to be thrown"); Assert.fail("Was expecting a MessageHandlingException to be thrown");
} }
}
}

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2010 the original author or authors. * Copyright 2002-2012 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@ package org.springframework.integration.test.util;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import java.io.File;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy; import java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy;
@@ -52,6 +53,7 @@ import org.springframework.util.StringUtils;
* @author Mark Fisher * @author Mark Fisher
* @author Iwein Fuld * @author Iwein Fuld
* @author Oleg Zhurakousky * @author Oleg Zhurakousky
* @author Artem Bilan
*/ */
public abstract class TestUtils { public abstract class TestUtils {
@@ -169,4 +171,13 @@ public abstract class TestUtils {
} }
return component; return component;
} }
/**
* Update file path by replacing any '/' with the system's file separator.
* @param s The file path containing '/'.
* @return The updated file path (if necessary).
*/
public static String applySystemFileSeparator(String s) {
return s.replaceAll("/", java.util.regex.Matcher.quoteReplacement(File.separator));
}
} }