[jboss-svn-commits] JBL Code SVN: r24412 - in labs/jbossesb/workspace/skeagh/routing/file/src/test/java/org/jboss/esb/file: eval and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Dec 18 06:31:35 EST 2008
Author: beve
Date: 2008-12-18 06:31:35 -0500 (Thu, 18 Dec 2008)
New Revision: 24412
Added:
labs/jbossesb/workspace/skeagh/routing/file/src/test/java/org/jboss/esb/file/eval/
labs/jbossesb/workspace/skeagh/routing/file/src/test/java/org/jboss/esb/file/eval/PatternEvaluatorImplTest.java
labs/jbossesb/workspace/skeagh/routing/file/src/test/java/org/jboss/esb/file/eval/ServerInfo.java
Log:
Added test
Added: labs/jbossesb/workspace/skeagh/routing/file/src/test/java/org/jboss/esb/file/eval/PatternEvaluatorImplTest.java
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/file/src/test/java/org/jboss/esb/file/eval/PatternEvaluatorImplTest.java (rev 0)
+++ labs/jbossesb/workspace/skeagh/routing/file/src/test/java/org/jboss/esb/file/eval/PatternEvaluatorImplTest.java 2008-12-18 11:31:35 UTC (rev 24412)
@@ -0,0 +1,135 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2008, Red Hat Middleware
+ * LLC, and individual contributors by the @authors tag. See the copyright.txt
+ * in the distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.esb.file.eval;
+
+import static org.jboss.esb.file.FileRoutingConstants.IN_FILE_NAME;
+import static org.jboss.esb.file.FileRoutingConstants.IN_FILE_LENGTH;
+import static org.junit.Assert.*;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.esb.api.context.InvocationContext;
+import org.jboss.esb.api.message.Message;
+import org.junit.Test;
+
+/**
+ * Test for {@link PatternEvaluatorImpl}.
+ *
+ * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
+ *
+ */
+public class PatternEvaluatorImplTest
+{
+ private PatternEvaluatorImpl evaluator = new PatternEvaluatorImpl();
+
+ @Test
+ public void evalFileNameSubstitution()
+ {
+ final String expectedFileName = "fileNumberOne";
+ final String filePattern = "/path/to\\some\\file\\${name}";
+ final InvocationContext invocationContext = createInvocationContext(IN_FILE_NAME, expectedFileName);
+
+ final String result = evaluator.evalFileName(filePattern, null, invocationContext);
+ assertEquals(expectedFileName, result);
+ }
+
+ @Test
+ public void evalTimestampSubstitution()
+ {
+ final String filePattern = "/path/to\\some\\file\\${timestamp}";
+ final InvocationContext invocationContext = new InvocationContext();
+
+ final String result = evaluator.evalFileName(filePattern, null, invocationContext);
+ Long valueOf = Long.valueOf(result);
+ assertNotNull(valueOf);
+ }
+
+ @Test
+ public void evalFileNameUsingFreeMarkerTemplate()
+ {
+ final String filePattern = "/path/${serverName}-${serverId}";
+ final ServerInfo serverInfo = createServerInfo("mother", 13);
+
+ final Message message = new Message(serverInfo);
+
+ final InvocationContext invocationContext = new InvocationContext();
+ final String result = evaluator.evalFileName(filePattern, message, invocationContext);
+
+ final String expected = serverInfo.getServerName() + "-" + serverInfo.getServerId();
+ assertEquals(expected, result);
+ }
+
+ @Test
+ public void evalFileNameUsingFreeMarkerTemplateNonExistingData()
+ {
+ final String filePattern = "/path/${serverName}-${serverId}";
+ final Message message = new Message("some other payload");
+
+ final InvocationContext invocationContext = new InvocationContext();
+ final String result = evaluator.evalFileName(filePattern, message, invocationContext);
+
+ assertEquals("${serverName}-${serverId}", result);
+ }
+
+ @Test
+ public void evalFileNameUsingFreeMarkerTemplateContext()
+ {
+ final String filePattern = "/path/${serverInfo.serverName}-${serverInfo.serverId}";
+ final ServerInfo serverInfo = createServerInfo("mother", 13);
+ final InvocationContext invocationContext = new InvocationContext();
+ invocationContext.setContextObject("serverInfo", serverInfo);
+ final Message message = new Message();
+
+ final String result = evaluator.evalFileName(filePattern, message, invocationContext);
+
+ final String expected = serverInfo.getServerName() + "-" + serverInfo.getServerId();
+ assertEquals(expected, result);
+ }
+
+ @Test
+ public void evalFileNameUsingFreeMarkerTemplateInvocationParameter()
+ {
+ final String filePattern = "/path/${in_file_length}";
+ final InvocationContext invocationContext = createInvocationContext(IN_FILE_LENGTH, "88");
+ final Message message = new Message();
+
+ final String result = evaluator.evalFileName(filePattern, message, invocationContext);
+
+ assertEquals("88", result);
+ }
+
+ private ServerInfo createServerInfo(final String serverName, final int serverId)
+ {
+ final ServerInfo serverInfo = new ServerInfo();
+ serverInfo.setServerName(serverName);
+ serverInfo.setServerId(serverId);
+ return serverInfo;
+ }
+
+ private InvocationContext createInvocationContext(final String key, final String value)
+ {
+ Map<String, String> invocationParams = new HashMap<String,String>();
+ invocationParams.put(key, value);
+ return new InvocationContext(invocationParams);
+ }
+
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/skeagh/routing/file/src/test/java/org/jboss/esb/file/eval/ServerInfo.java
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/file/src/test/java/org/jboss/esb/file/eval/ServerInfo.java (rev 0)
+++ labs/jbossesb/workspace/skeagh/routing/file/src/test/java/org/jboss/esb/file/eval/ServerInfo.java 2008-12-18 11:31:35 UTC (rev 24412)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2008, Red Hat Middleware
+ * LLC, and individual contributors by the @authors tag. See the copyright.txt
+ * in the distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.esb.file.eval;
+
+/**
+ * Simple object used for testing templates.
+ *
+ * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
+ *
+ */
+public class ServerInfo
+{
+ private String serverName;
+ private int serverId;
+
+ public ServerInfo()
+ {
+ }
+
+ public String getServerName()
+ {
+ return serverName;
+ }
+
+ public void setServerName(String serverName)
+ {
+ this.serverName = serverName;
+ }
+
+ public int getServerId()
+ {
+ return serverId;
+ }
+
+ public void setServerId(int serverId)
+ {
+ this.serverId = serverId;
+ }
+
+}
\ No newline at end of file
More information about the jboss-svn-commits
mailing list