Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
nablarch.test.core.reader.BasicTestDataParser Maven / Gradle / Ivy
package nablarch.test.core.reader;
import nablarch.core.log.Logger;
import nablarch.core.log.LoggerManager;
import nablarch.core.util.StringUtil;
import nablarch.test.core.db.BasicDefaultValues;
import nablarch.test.core.db.DbInfo;
import nablarch.test.core.db.DefaultValues;
import nablarch.test.core.db.TableData;
import nablarch.test.core.file.DataFile;
import nablarch.test.core.file.FixedLengthFile;
import nablarch.test.core.file.VariableLengthFile;
import nablarch.test.core.messaging.MessagePool;
import nablarch.test.core.messaging.RequestTestingMessagePool;
import nablarch.test.core.util.interpreter.BinaryFileInterpreter;
import nablarch.test.core.util.interpreter.TestDataInterpreter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import static nablarch.core.util.Builder.concat;
public class BasicTestDataParser implements TestDataParser {
private static final Logger LOGGER = LoggerManager.get(BasicTestDataParser.class);
private TestDataReader testDataReader;
private DbInfo dbInfo;
private DefaultValues defaultValues = new BasicDefaultValues();
private List interpreters;
public List getSetupTableData (String path, String resourceName, String... groupId) {
if (!testDataReader.isDataExisting(path, resourceName)) {
LOGGER.logDebug("Skipping table data initialization because preparation data is not found. resource=[" + resourceName + "]" );
return Collections.emptyList();
}
return getTableData(path, resourceName, DataType.SETUP_TABLE_DATA, formatGroupId(groupId));
}
public List> getListMap(String path, String resourceName, String id) {
ListMapParser agent = new ListMapParser(testDataReader, addBinaryFileInterpreter(path));
agent.parse(path, resourceName, id);
return agent.getResult();
}
public List getSetupFile (String path, String resourceName, String... groupId) {
List result = new ArrayList();
result.addAll(getFixedLengthFile(DataType.SETUP_FIXED, path, resourceName, groupId));
result.addAll(getVariableLengthFile(DataType.SETUP_VARIABLE, path, resourceName, groupId));
return result;
}
public List getExpectedFile (String path, String resourceName, String... groupId) {
List result = new ArrayList();
result.addAll(getFixedLengthFile(DataType.EXPECTED_FIXED, path, resourceName, groupId));
result.addAll(getVariableLengthFile(DataType.EXPECTED_VARIABLE, path, resourceName, groupId));
return result;
}
public MessagePool getMessage (String path, String resourceName, String id) {
MessageParser agent = new MessageParser(testDataReader, addBinaryFileInterpreter(path), DataType.MESSAGE);
agent.parse(path, resourceName, id);
return agent.getResult();
}
public MessagePool getMessageWithoutCache (String path, String resourceName, DataType dataType, String id) {
SendSyncMessageParser agent = new SendSyncMessageParser(testDataReader, addBinaryFileInterpreter(path), dataType);
agent.parse(path, resourceName, id, false );
return agent.getResult();
}
public List getSendSyncMessage (String path, String resourceName, String id, DataType dataType) {
GroupMessageParser agent = new GroupMessageParser(testDataReader, addBinaryFileInterpreter(path), dataType);
agent.parse(path, resourceName, id);
return agent.getResult();
}
private List getFixedLengthFile (
DataType type, String path, String resourceName, String... groupId) {
FixedLengthFileParser agent = new FixedLengthFileParser(testDataReader, addBinaryFileInterpreter(path), type);
return getFile(agent, path, resourceName, groupId);
}
private List getVariableLengthFile (
DataType type, String path, String resourceName, String... groupId) {
VariableLengthFileParser agent = new VariableLengthFileParser(testDataReader, addBinaryFileInterpreter(path), type);
return getFile(agent, path, resourceName, groupId);
}
private List getFile (DataFileParser agent, String path, String resourceName,
String... groupId) {
String id = formatGroupId(groupId);
agent.parse(path, resourceName, id);
return agent.getResult();
}
public List getExpectedTableData (String path, String resourceName, String... groupId) {
String gid = formatGroupId(groupId);
List expectedTable = getTableData(path, resourceName, DataType.EXPECTED_TABLE_DATA, gid);
List expectedCompleted = getTableData(path, resourceName, DataType.EXPECTED_COMPLETED, gid);
for (TableData e : expectedCompleted) {
e.fillDefaultValues();
}
expectedTable.addAll(expectedCompleted);
return expectedTable;
}
private List getTableData (String path, String resourceName, DataType targetType,
String groupId) {
TableDataParser agent = new TableDataParser(testDataReader, addBinaryFileInterpreter(path), dbInfo,
defaultValues, targetType);
agent.parse(path, resourceName, groupId);
return agent.getResult();
}
private List addBinaryFileInterpreter (String path) {
BinaryFileInterpreter fileInterpreter = new BinaryFileInterpreter(path);
List newInterpreters = new ArrayList(
interpreters.size() + 1 );
newInterpreters.add(fileInterpreter);
newInterpreters.addAll(interpreters);
return newInterpreters;
}
public void setTestDataReader (TestDataReader testDataReader) {
this .testDataReader = testDataReader;
}
public void setDbInfo (DbInfo dbInfo) {
this .dbInfo = dbInfo;
}
public void setInterpreters (List interpretersPrototype) {
this .interpreters = interpretersPrototype;
}
public void setDefaultValues (DefaultValues defaultValues) {
this .defaultValues = defaultValues;
}
String formatGroupId (String[] groupIdVarargs) {
if (groupIdVarargs == null ) {
return "" ;
}
switch (groupIdVarargs.length) {
case 0 :
return "" ;
case 1 :
String groupId = groupIdVarargs[0 ];
return StringUtil.isNullOrEmpty(groupId) ? "" : concat("[" , groupId, "]" );
default :
throw new IllegalArgumentException("argument groupId must be one or zero." );
}
}
@Override
public boolean isResourceExisting (String basePath, String resourceName) {
return testDataReader.isResourceExisting(basePath, resourceName);
}
}