/*
* $Id: IdempotencyTestCase.java 21732 2011-04-26 19:00:13Z dzapata $
* --------------------------------------------------------------------------------------
* Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
*
* The software in this package is published under the terms of the CPAL v1.0
* license, a copy of which has been included with this distribution in the
* LICENSE.txt file.
*/
package org.mule.transport.jdbc.functional;
import java.util.Calendar;
import org.apache.commons.dbutils.QueryRunner;
import org.mule.DefaultMuleMessage;
import org.mule.api.MuleMessage;
import org.mule.api.client.MuleClient;
import org.mule.api.transport.PropertyScope;
import org.mule.tck.FunctionalTestCase;
import org.mule.util.DateUtils;
public class IdempotencyTestCase extends AbstractJdbcFunctionalTestCase
{
public void testIdempotencySequential() throws Exception
{
MuleClient client = muleContext.getClient();
int id = Integer.valueOf(DateUtils.formatTimeStamp(Calendar.getInstance().getTime(), "hhmmss"));
String valueExpression = DateUtils.formatTimeStamp(Calendar.getInstance().getTime(), "ssmmhh");
MuleMessage message = new DefaultMuleMessage("hi", muleContext);
message.setProperty("originalId", id, PropertyScope.OUTBOUND);
message.setProperty("valueId", valueExpression, PropertyScope.OUTBOUND);
client.dispatch("vm://in", message);
MuleMessage requestMessage = client.request("vm://forProcessing", FunctionalTestCase.RECEIVE_TIMEOUT);
assertNotNull(requestMessage);
message = new DefaultMuleMessage("hi", muleContext);
message.setProperty("originalId", id, PropertyScope.OUTBOUND);
message.setProperty("valueId", valueExpression, PropertyScope.OUTBOUND);
client.send("vm://in", message);
requestMessage = client.request("vm://duplicated", FunctionalTestCase.RECEIVE_TIMEOUT);
assertNotNull(requestMessage);
}
@Override
protected String getConfigResources()
{
return super.getConfigResources() + ",jdbc-store.xml";
}
@Override
protected void createTable() throws Exception
{
super.createTable();
QueryRunner qr = jdbcConnector.getQueryRunner();
qr.update(jdbcConnector.getConnection(), "CREATE TABLE IDS(K VARCHAR(255) NOT NULL PRIMARY KEY, VALUE VARCHAR(255))");
}
@Override
protected void deleteTable() throws Exception
{
super.deleteTable();
QueryRunner qr = jdbcConnector.getQueryRunner();
qr.update(jdbcConnector.getConnection(), "DELETE FROM IDS");
}
}