INTSAMPLES-52 - All Samples should use Log4J

INTSAMPLES-52 - Standardize Log4j PatternLayout
Standardize Log4j PatternLayout to **%d{HH:mm:ss.SSS} %-5p [%t][%c] %m%n**.
This commit is contained in:
Gunnar Hillert
2012-05-14 15:38:35 -04:00
committed by Gary Russell
parent 218668cb9c
commit fc2e5890a9
73 changed files with 1208 additions and 1105 deletions

View File

@@ -19,48 +19,46 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.io.File;
import org.apache.log4j.Logger;
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.Message;
import org.springframework.integration.core.PollableChannel;
/**
*
*
* @author Oleg Zhurakousky
* @author Gunnar Hillert
*
*/
public class FtpInboundChannelAdapterSample {
private static final Logger LOGGER = LoggerFactory.getLogger(FtpInboundChannelAdapterSample.class);
private static final Logger LOGGER = Logger.getLogger(FtpInboundChannelAdapterSample.class);
@Test
public void runDemo() throws Exception{
ConfigurableApplicationContext ctx =
ConfigurableApplicationContext ctx =
new ClassPathXmlApplicationContext("META-INF/spring/integration/FtpInboundChannelAdapterSample-context.xml");
PollableChannel ftpChannel = ctx.getBean("ftpChannel", PollableChannel.class);
Message<?> message1 = ftpChannel.receive(2000);
Message<?> message2 = ftpChannel.receive(2000);
Message<?> message3 = ftpChannel.receive(1000);
LOGGER.info("Received first file message: {}.", message1);
LOGGER.info("Received second file message: {}.", message2);
LOGGER.info("Received nothing else: {}.", message3);
LOGGER.info(String.format("Received first file message: %s.", message1));
LOGGER.info(String.format("Received second file message: %s.", message2));
LOGGER.info(String.format("Received nothing else: %s.", message3));
assertNotNull(message1);
assertNotNull(message2);
assertNull("Was NOT expecting a third message.", message3);
}
@After
public void cleanup() {
FileUtils.deleteQuietly(new File(TestSuite.LOCAL_FTP_TEMP_DIR));

View File

@@ -19,12 +19,10 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.InputStream;
import org.apache.log4j.Logger;
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.Message;
@@ -32,57 +30,57 @@ import org.springframework.integration.MessageChannel;
import org.springframework.integration.support.MessageBuilder;
/**
*
*
* @author Oleg Zhurakousky
* @author Gunnar Hillert
*
*/
public class FtpOutboundChannelAdapterSample {
private static final Logger LOGGER = LoggerFactory.getLogger(FtpOutboundChannelAdapterSample.class);
private static final Logger LOGGER = Logger.getLogger(FtpOutboundChannelAdapterSample.class);
private final File baseFolder = new File("target" + File.separator + "toSend");
@Test
public void runDemo() throws Exception{
ConfigurableApplicationContext ctx =
ConfigurableApplicationContext ctx =
new ClassPathXmlApplicationContext("META-INF/spring/integration/FtpOutboundChannelAdapterSample-context.xml");
MessageChannel ftpChannel = ctx.getBean("ftpChannel", MessageChannel.class);
baseFolder.mkdirs();
final File fileToSendA = new File(baseFolder, "a.txt");
final File fileToSendB = new File(baseFolder, "b.txt");
final File fileToSendB = new File(baseFolder, "b.txt");
final InputStream inputStreamA = FtpOutboundChannelAdapterSample.class.getResourceAsStream("/test-files/a.txt");
final InputStream inputStreamB = FtpOutboundChannelAdapterSample.class.getResourceAsStream("/test-files/b.txt");
FileUtils.copyInputStreamToFile(inputStreamA, fileToSendA);
FileUtils.copyInputStreamToFile(inputStreamB, fileToSendB);
assertTrue(fileToSendA.exists());
assertTrue(fileToSendB.exists());
final Message<File> messageA = MessageBuilder.withPayload(fileToSendA).build();
final Message<File> messageB = MessageBuilder.withPayload(fileToSendB).build();
ftpChannel.send(messageA);
ftpChannel.send(messageB);
Thread.sleep(2000);
assertTrue(new File(TestSuite.FTP_ROOT_DIR + File.separator + "a.txt").exists());
assertTrue(new File(TestSuite.FTP_ROOT_DIR + File.separator + "b.txt").exists());
LOGGER.info("Successfully transfered file 'a.txt' and 'b.txt' to a remote FTP location.");
}
@After
public void cleanup() {
FileUtils.deleteQuietly(baseFolder);
}
}

View File

@@ -29,50 +29,50 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* Demonstrates use of the outbound gateway to use ls, get and rm.
*
*
* The previous Test {@link FtpOutboundChannelAdapterSample} was uploading 2 test
* files:
*
*
* <ul>
* <li>a.txt</li>
* <li>b.txt</li>
* </ul>
*
* This test will now retrieves those 2 files and removes them. Instead of just
* polling the file, the files are instead retrieved and deleted using explicit
* This test will now retrieves those 2 files and removes them. Instead of just
* polling the file, the files are instead retrieved and deleted using explicit
* FTP commands (LS and RM)
*
*
* @author Gary Russell
* @since 2.1
*
*/
public class FtpOutboundGatewaySample {
@Test
public void testLsGetRm() throws Exception {
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(
"classpath:/META-INF/spring/integration/FtpOutboundGatewaySample-context.xml");
final ToFtpFlowGateway toFtpFlow = ctx.getBean(ToFtpFlowGateway.class);
// execute the flow (ls, get, rm, aggregate results)
List<Boolean> rmResults = toFtpFlow.lsGetAndRmFiles("/");
//Check everything went as expected, and clean up
assertEquals("Was expecting the collection 'rmResults' to contain 2 elements.", 2, rmResults.size());
for (Boolean result : rmResults) {
assertTrue(result);
}
assertTrue("Expected FTP remote directory to be empty", new File(TestSuite.FTP_ROOT_DIR).delete());
}
@After
public void cleanup() {
FileUtils.deleteQuietly(new File(TestSuite.LOCAL_FTP_TEMP_DIR));
}
}

View File

@@ -34,15 +34,15 @@ import org.springframework.integration.samples.ftp.support.TestUserManager;
/**
* Test Suite that will bootstrap an embedded Apache FTP Server. Additionally some
* test files will be send to the FTP Server.
*
*
* test files will be send to the FTP Server.
*
*
* @author Gunnar Hillert
*
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({
FtpOutboundChannelAdapterSample.class,
FtpOutboundChannelAdapterSample.class,
FtpInboundChannelAdapterSample.class,
FtpOutboundGatewaySample.class
})
@@ -50,20 +50,20 @@ public class TestSuite {
public static final String FTP_ROOT_DIR = "target" + File.separator + "ftproot";
public static final String LOCAL_FTP_TEMP_DIR = "target" + File.separator + "local-ftp-temp";
@ClassRule
public static final TemporaryFolder temporaryFolder = new TemporaryFolder();
public static FtpServer server;
@BeforeClass
public static void setupFtpServer() throws FtpException, SocketException, IOException {
File ftpRoot = new File (FTP_ROOT_DIR);
ftpRoot.mkdirs();
TestUserManager userManager = new TestUserManager(ftpRoot.getAbsolutePath());
FtpServerFactory serverFactory = new FtpServerFactory();
serverFactory.setUserManager(userManager);
ListenerFactory factory = new ListenerFactory();
@@ -71,13 +71,13 @@ public class TestSuite {
factory.setPort(3333);
serverFactory.addListener("default", factory.createListener());
server = serverFactory.createServer();
server = serverFactory.createServer();
server.start();
}
@AfterClass
public static void shutDown() {
server.stop();

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- Appenders -->
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{HH:mm:ss.SSS} %-5p [%t][%c] %m%n" />
</layout>
</appender>
<!-- Loggers -->
<logger name="org.springframework.integration">
<level value="warn" />
</logger>
<logger name="org.springframework.integration.samples">
<level value="info" />
</logger>
<!-- Root Logger -->
<root>
<priority value="warn" />
<appender-ref ref="console" />
</root>
</log4j:configuration>

View File

@@ -1,27 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d %5p | %t | %-55logger{55} | %m %n</pattern>
</encoder>
</appender>
<logger name="org.springframework.integration">
<level value="INFO" />
</logger>
<logger name="org.springframework">
<level value="INFO" />
</logger>
<logger name="org.apache.ftpserver">
<level value="WARN" />
</logger>
<root>
<level value="INFO" />
<appender-ref ref="CONSOLE" />
</root>
</configuration>