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.
/*
Copyright 2014-2019 Nationale-Nederlanden, 2020-2022 WeAreFrank!
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package nl.nn.adapterframework.testtool;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicLong;
import java.util.regex.Pattern;
import java.util.zip.ZipInputStream;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Logger;
import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.XMLUnit;
import nl.nn.adapterframework.configuration.ConfigurationException;
import nl.nn.adapterframework.configuration.IbisContext;
import nl.nn.adapterframework.core.ISender;
import nl.nn.adapterframework.core.ListenerException;
import nl.nn.adapterframework.core.PipeLineSession;
import nl.nn.adapterframework.core.SenderException;
import nl.nn.adapterframework.core.TimeoutException;
import nl.nn.adapterframework.jdbc.FixedQuerySender;
import nl.nn.adapterframework.jms.JmsSender;
import nl.nn.adapterframework.jms.PullingJmsListener;
import nl.nn.adapterframework.lifecycle.IbisApplicationServlet;
import nl.nn.adapterframework.parameters.Parameter;
import nl.nn.adapterframework.senders.DelaySender;
import nl.nn.adapterframework.stream.FileMessage;
import nl.nn.adapterframework.stream.Message;
import nl.nn.adapterframework.testtool.queues.QueueCreator;
import nl.nn.adapterframework.testtool.queues.QueueWrapper;
import nl.nn.adapterframework.util.AppConstants;
import nl.nn.adapterframework.util.CaseInsensitiveComparator;
import nl.nn.adapterframework.util.DomBuilderException;
import nl.nn.adapterframework.util.FileUtils;
import nl.nn.adapterframework.util.LogUtil;
import nl.nn.adapterframework.util.Misc;
import nl.nn.adapterframework.util.ProcessUtil;
import nl.nn.adapterframework.util.StreamUtil;
import nl.nn.adapterframework.util.StringResolver;
import nl.nn.adapterframework.util.XmlUtils;
/**
* @author Jaco de Groot
*/
public class TestTool {
private static Logger logger = LogUtil.getLogger(TestTool.class);
public static final String LOG_LEVEL_ORDER = "[debug], [pipeline messages prepared for diff], [pipeline messages], [wrong pipeline messages prepared for diff], [wrong pipeline messages], [step passed/failed], [scenario passed/failed], [scenario failed], [totals], [error]";
private static final String STEP_SYNCHRONIZER = "Step synchronizer";
protected static final String TESTTOOL_CORRELATIONID = "Test Tool correlation id";
protected static final int DEFAULT_TIMEOUT = AppConstants.getInstance().getInt("larva.timeout", 30000);
protected static final String TESTTOOL_BIFNAME = "Test Tool bif name";
public static final nl.nn.adapterframework.stream.Message TESTTOOL_DUMMY_MESSAGE = new nl.nn.adapterframework.stream.Message("Dummy message");
protected static final String TESTTOOL_CLEAN_UP_REPLY = "Clean up reply";
private static final int RESULT_ERROR = 0;
private static final int RESULT_OK = 1;
private static final int RESULT_AUTOSAVED = 2;
// dirty solution by Marco de Reus:
private static String zeefVijlNeem = "";
private static Writer silentOut = null;
private static boolean autoSaveDiffs = false;
private static AtomicLong correlationIdSuffixCounter = new AtomicLong(1);
/*
* if allowReadlineSteps is set to true, actual results can be compared in line by using .readline steps.
* Those results cannot be saved to the inline expected value, however.
*/
private static final boolean allowReadlineSteps = false;
protected static int globalTimeout=DEFAULT_TIMEOUT;
private static final String TR_STARTING_TAG="
";
private static final String TR_CLOSING_TAG="
";
private static final String TD_STARTING_TAG="
";
private static final String TD_CLOSING_TAG="
";
private static final String TABLE_CLOSING_TAG="";
public static void setTimeout(int newTimeout) {
globalTimeout=newTimeout;
}
private static IbisContext getIbisContext(ServletContext application) {
return IbisApplicationServlet.getIbisContext(application);
}
public static void runScenarios(ServletContext application, HttpServletRequest request, Writer out) {
runScenarios(application, request, out, false);
}
public static void runScenarios(ServletContext application, HttpServletRequest request, Writer out, boolean silent) {
String paramLogLevel = request.getParameter("loglevel");
String paramAutoScroll = request.getParameter("autoscroll");
String paramExecute = request.getParameter("execute");
String paramWaitBeforeCleanUp = request.getParameter("waitbeforecleanup");
String paramGlobalTimeout = request.getParameter("timeout");
int timeout=globalTimeout;
if(paramGlobalTimeout != null) {
try {
timeout = Integer.parseInt(paramGlobalTimeout);
} catch(NumberFormatException e) {
}
}
String servletPath = request.getServletPath();
int i = servletPath.lastIndexOf('/');
String realPath = application.getRealPath(servletPath.substring(0, i));
String paramScenariosRootDirectory = request.getParameter("scenariosrootdirectory");
IbisContext ibisContext = getIbisContext(application);
runScenarios(ibisContext, paramLogLevel,
paramAutoScroll, paramExecute, paramWaitBeforeCleanUp, timeout,
realPath, paramScenariosRootDirectory, out, silent);
}
public static final int ERROR_NO_SCENARIO_DIRECTORIES_FOUND=-1;
/**
*
* @return negative: error condition
* 0: all scenarios passed
* positive: number of scenarios that failed
*/
public static int runScenarios(IbisContext ibisContext, String paramLogLevel,
String paramAutoScroll, String paramExecute, String paramWaitBeforeCleanUp,
int timeout, String realPath, String paramScenariosRootDirectory,
Writer out, boolean silent) {
AppConstants appConstants = AppConstants.getInstance();
String logLevel = "wrong pipeline messages";
String autoScroll = "true";
if (paramLogLevel != null && LOG_LEVEL_ORDER.indexOf("[" + paramLogLevel + "]") > -1) {
logLevel = paramLogLevel;
}
if (paramAutoScroll == null && paramLogLevel != null) {
autoScroll = "false";
}
Map writers = null;
if (!silent) {
writers = new HashMap();
writers.put("out", out);
writers.put("htmlbuffer", new StringWriter());
writers.put("logbuffer", new StringWriter());
writers.put("loglevel", logLevel);
writers.put("autoscroll", autoScroll);
writers.put("usehtmlbuffer", "false");
writers.put("uselogbuffer", "true");
writers.put("messagecounter", new Integer(0));
writers.put("scenariocounter", new Integer(1));
} else {
silentOut = out;
}
TestTool.debugMessage("Start logging to logbuffer until form is written", writers);
String asd = appConstants.getResolvedProperty("larva.diffs.autosave");
if (asd!=null) {
autoSaveDiffs = Boolean.parseBoolean(asd);
}
debugMessage("Initialize scenarios root directories", writers);
List scenariosRootDirectories = new ArrayList();
List scenariosRootDescriptions = new ArrayList();
String currentScenariosRootDirectory = initScenariosRootDirectories(
realPath,
paramScenariosRootDirectory, scenariosRootDirectories,
scenariosRootDescriptions, writers);
if (scenariosRootDirectories.size() == 0) {
debugMessage("Stop logging to logbuffer", writers);
writers.put("uselogbuffer", "stop");
errorMessage("No scenarios root directories found", writers);
return ERROR_NO_SCENARIO_DIRECTORIES_FOUND;
}
debugMessage("Read scenarios from directory '" + currentScenariosRootDirectory + "'", writers);
List allScenarioFiles = readScenarioFiles(appConstants, currentScenariosRootDirectory, writers);
debugMessage("Initialize 'wait before cleanup' variable", writers);
int waitBeforeCleanUp = 100;
if (paramWaitBeforeCleanUp != null) {
try {
waitBeforeCleanUp = Integer.parseInt(paramWaitBeforeCleanUp);
} catch(NumberFormatException e) {
}
}
debugMessage("Write html form", writers);
printHtmlForm(scenariosRootDirectories, scenariosRootDescriptions, currentScenariosRootDirectory, appConstants, allScenarioFiles, waitBeforeCleanUp, timeout, paramExecute, autoScroll, writers);
debugMessage("Stop logging to logbuffer", writers);
if (writers!=null) {
writers.put("uselogbuffer", "stop");
}
debugMessage("Start debugging to out", writers);
debugMessage("Execute scenario(s) if execute parameter present and scenarios root directory did not change", writers);
int scenariosFailed = 0;
if (paramExecute != null) {
String paramExecuteCanonicalPath;
String scenariosRootDirectoryCanonicalPath;
try {
paramExecuteCanonicalPath = new File(paramExecute).getCanonicalPath();
scenariosRootDirectoryCanonicalPath = new File(currentScenariosRootDirectory).getCanonicalPath();
} catch(IOException e) {
paramExecuteCanonicalPath = paramExecute;
scenariosRootDirectoryCanonicalPath = currentScenariosRootDirectory;
errorMessage("Could not get canonical path: " + e.getMessage(), e, writers);
}
if (paramExecuteCanonicalPath.startsWith(scenariosRootDirectoryCanonicalPath)) {
debugMessage("Initialize XMLUnit", writers);
XMLUnit.setIgnoreWhitespace(true);
debugMessage("Initialize 'scenario files' variable", writers);
debugMessage("Param execute: " + paramExecute, writers);
List scenarioFiles;
if (paramExecute.endsWith(".properties")) {
debugMessage("Read one scenario", writers);
scenarioFiles = new ArrayList();
scenarioFiles.add(new File(paramExecute));
} else {
debugMessage("Read all scenarios from directory '" + paramExecute + "'", writers);
scenarioFiles = readScenarioFiles(appConstants, paramExecute, writers);
}
boolean evenStep = false;
debugMessage("Initialize statistics variables", writers);
int scenariosPassed = 0;
int scenariosAutosaved = 0;
long startTime = System.currentTimeMillis();
debugMessage("Execute scenario('s)", writers);
Iterator scenarioFilesIterator = scenarioFiles.iterator();
while (scenarioFilesIterator.hasNext()) {
// increment suffix for each scenario
String correlationId = TESTTOOL_CORRELATIONID + "("+ correlationIdSuffixCounter.getAndIncrement() +")";
int scenarioPassed = RESULT_ERROR;
File scenarioFile = scenarioFilesIterator.next();
String scenarioDirectory = scenarioFile.getParentFile().getAbsolutePath() + File.separator;
String longName = scenarioFile.getAbsolutePath();
String shortName = longName.substring(currentScenariosRootDirectory.length() - 1, longName.length() - ".properties".length());
if (writers!=null) {
if (LOG_LEVEL_ORDER.indexOf("[" + (String)writers.get("loglevel") + "]") < LOG_LEVEL_ORDER.indexOf("[scenario passed/failed]")) {
writeHtml(" ", writers, false);
writeHtml(" ", writers, false);
writeHtml("