@ -7,17 +7,40 @@
@@ -7,17 +7,40 @@
* /
package de.superx.qa.bin ;
import java.io.BufferedWriter ;
import java.io.ByteArrayOutputStream ;
import java.io.File ;
import java.io.FileInputStream ;
import java.io.FileWriter ;
import java.io.IOException ;
import java.io.PrintStream ;
import java.io.PrintWriter ;
import java.io.StringReader ;
import java.io.StringWriter ;
import java.net.URISyntaxException ;
import java.sql.Connection ;
import java.sql.PreparedStatement ;
import java.sql.SQLException ;
import java.sql.Statement ;
import java.text.SimpleDateFormat ;
import java.util.Date ;
import java.util.Enumeration ;
import java.util.Hashtable ;
import java.util.Iterator ;
import java.util.List ;
import java.util.Locale ;
import java.util.Properties ;
import java.util.StringTokenizer ;
import javax.xml.transform.TransformerConfigurationException ;
import javax.xml.transform.TransformerException ;
import javax.xml.transform.TransformerFactoryConfigurationError ;
import org.apache.log4j.Appender ;
import org.apache.log4j.Level ;
import org.apache.log4j.Logger ;
import org.apache.log4j.PropertyConfigurator ;
import org.slf4j.LoggerFactory ;
import org.jaxen.JaxenException ;
import org.jaxen.XPath ;
@ -30,8 +53,11 @@ import org.jdom.input.SAXBuilder;
@@ -30,8 +53,11 @@ import org.jdom.input.SAXBuilder;
import org.springframework.mock.web.MockHttpServletRequest ;
import org.springframework.mock.web.MockHttpServletResponse ;
import org.springframework.mock.web.MockServletConfig ;
import org.w3c.dom.NodeList ;
import de.memtext.baseobjects.coll.NamedIdObjectList ;
import de.memtext.util.LogUtils ;
import de.superx.bin.Dosql ;
import de.superx.bin.SxConnection ;
import de.superx.common.FieldContainer ;
import de.superx.common.Maske ;
@ -52,7 +78,7 @@ import net.sf.saxon.sxpath.XPathExpression;
@@ -52,7 +78,7 @@ import net.sf.saxon.sxpath.XPathExpression;
public class QaTestcaseExecutor {
private static String tcUniquename ;
private static String systeminfoId ;
private static int systeminfoId ;
private static String fieldSelCmdLine ;
private static int maskExecutionId ;
private static String maskeninfoId ;
@ -64,19 +90,35 @@ public class QaTestcaseExecutor {
@@ -64,19 +90,35 @@ public class QaTestcaseExecutor {
private static FieldContainer myFieldContainer ;
private static Hashtable < String , String > maskFields ;
private static String resultXml ;
private static String resultHtml ;
private static String resultLog ;
private static String pathToDbProperties ;
private static Connection myConnection ;
private static String logFile ;
public QaTestcaseExecutor ( ) {
this . maskFields = new Hashtable ( ) ;
initLogging ( ) ;
resultHtml = "" ;
}
private void init ( ) throws SQLException
private void init ( ) throws SQLException , IOException , SecurityException , URISyntaxException
{
/ * File f = new File ( logConf ) ;
if ( ! f . exists ( ) ) {
throw new IOException ( "Datei nicht gefunden: " + logConf ) ;
}
FileInputStream ins = new FileInputStream ( logConf ) ;
LogManager MyLogManager = java . util . logging . LogManager . getLogManager ( ) ;
MyLogManager . readConfiguration ( ins ) ;
String level = MyLogManager . getProperty ( ".level" ) ;
logger . info ( "Using Loggging-Level " + level ) ;
logger . info ( "Start Lauf" ) ; * /
//initLogging(true, Level.INFO);
//logger.info("START");
try {
myConnection = this . getConnection ( pathToDbProperties ) ;
} catch ( Exception e ) {
@ -89,7 +131,7 @@ public class QaTestcaseExecutor {
@@ -89,7 +131,7 @@ public class QaTestcaseExecutor {
//System.out.println("fieldSel:"+fieldSel);
System . out . println ( " inited") ;
writeToLog ( "QaTestcaseExecutor inited") ;
}
@ -110,39 +152,38 @@ public class QaTestcaseExecutor {
@@ -110,39 +152,38 @@ public class QaTestcaseExecutor {
}
public static void main ( String [ ] args ) {
String usage = "usage: java de.superx.qa.bin.QaTestcaseExecutor -dbproperties:$DB_PROPERTIES -tc:abc -systeminfo_id:9 -params:TID=16000 (optional) -outfile:Ausgabedatei (optional)" ;
String usage = "usage: java de.superx.qa.bin.QaTestcaseExecutor -userid:1(optional) -tc:abc(optional) -systeminfo_id:9 (optional)" ;
GetOpts . setOpts ( args ) ;
String isdrin = GetOpts . isAllRequiredOptionsPresent ( "-logger,-dbproperties" ) ;
if ( isdrin ! = null ) {
System . err . println ( usage ) ;
System . exit ( 1 ) ;
}
int returnCode = 0 ;
int nrOfTestcases = 0 ;
int nrOfSuccessfulTestcases = 0 ;
pathToDbProperties = GetOpts . getValue ( "-dbproperties" ) ;
String tcUniquename = "" ;
if ( GetOpts . isPresent ( "-userid" ) )
userId = Integer . valueOf ( GetOpts . getValue ( "-userid" ) ) ;
if ( GetOpts . isPresent ( "-tc" ) )
tcUniquename = GetOpts . getValue ( "-tc" ) ;
String systeminfoId = "" ;
if ( GetOpts . isPresent ( "-systeminfo_id" ) )
systeminfoId = GetOpts . getValue ( "-systeminfo_id" ) ;
String loggerArg = GetOpts . getValue ( "-logger" ) ;
systeminfoId = Integer . valueOf ( GetOpts . getValue ( "-systeminfo_id" ) ) ;
QaTestcaseExecutor myExec = new QaTestcaseExecutor ( ) ; //TODO:Mandantid
try {
myExec . init ( ) ;
int [ ] myTestcases = getTestcases ( tcUniquename , systeminfoId ) ;
int [ ] myTestcases = getTestcases ( ) ;
nrOfTestcases = myTestcases . length ;
if ( nrOfTestcases > 0 )
{
writeToLog ( "nrOfTestcases: " + nrOfTestcases ) ;
for ( int tcNr = 0 ; tcNr < nrOfTestcases ; tcNr + + )
{
returnCode = executeTestcase ( myTestcases [ tcNr ] ) ;
//reset static variables:
resultLog = "" ;
resultXml = "" ;
resultHtml = "" ;
tcUniquename = "" ;
if ( returnCode = = 0 )
nrOfSuccessfulTestcases + + ;
}
@ -163,7 +204,7 @@ public class QaTestcaseExecutor {
@@ -163,7 +204,7 @@ public class QaTestcaseExecutor {
}
private static int [ ] getTestcases ( String tcUniquename , String systeminfoId ) throws Exception
private static int [ ] getTestcases ( ) throws Exception
{
//TODO_ Umlaute erlauben:
//if(!SqlStringUtils.checkValidKeyEntry(tcUniquename) || !SqlStringUtils.checkValidKeyEntry(systeminfoId))
@ -175,10 +216,12 @@ public class QaTestcaseExecutor {
@@ -175,10 +216,12 @@ public class QaTestcaseExecutor {
+ "FROM qa_mask_execution E left outer join userinfo U\n"
+ " on (U.tid=E.userinfo_id)"
+ "where E.is_active=1" ;
if ( ! tcUniquename . equals ( "" ) )
if ( tcUniquename ! = null )
sql + = " and E.uniquename ='" + tcUniquename + "'" ;
if ( ! systeminfoId . equals ( "" ) )
if ( systeminfoId > 0 )
sql + = " and E.systeminfo_id=" + systeminfoId ;
if ( userId > 0 )
sql + = " and E.userinfo_id=" + userId ;
sql + = " order by 1;" ;
SuperX_el el = new SuperX_el ( ) ;
SxSqlHelper sh = new SxSqlHelper ( ) ;
@ -211,6 +254,7 @@ public class QaTestcaseExecutor {
@@ -211,6 +254,7 @@ public class QaTestcaseExecutor {
String fieldSel = "" ;
String felderinfoId = "" ;
String felderinfoName = "" ;
String tcName = "" ;
String fieldValue = "" ;
String sql = ""
+ "SELECT \n"
@ -221,7 +265,9 @@ public class QaTestcaseExecutor {
@@ -221,7 +265,9 @@ public class QaTestcaseExecutor {
+ "S.felderinfo_id,\n"
+ "trim(F.name) as felderinfo_name,"
+ "string_not_null(S.field_value) as field_value, \n"
+ "U.administration "
+ "U.administration, \n"
+ "E.name, \n"
+ "E.uniquename \n"
+ "FROM felderinfo F,qa_mask_field_sel S, qa_mask_execution E left outer join userinfo U\n"
+ " on (U.tid=E.userinfo_id)"
+ "where F.tid=S.felderinfo_id "
@ -248,19 +294,22 @@ public class QaTestcaseExecutor {
@@ -248,19 +294,22 @@ public class QaTestcaseExecutor {
felderinfoName = row . get ( 5 ) . toString ( ) . trim ( ) ;
fieldValue = row . get ( 6 ) . toString ( ) . trim ( ) ;
userAdmin = row . get ( 7 ) . toString ( ) . trim ( ) ;
tcName = row . get ( 8 ) . toString ( ) . trim ( ) ;
tcUniquename = row . get ( 9 ) . toString ( ) . trim ( ) ;
maskFields . put ( felderinfoName , fieldValue ) ;
}
System . out . println ( "Testcase "+ maskExecutionId + " initialized" ) ;
writeToLog ( "Testcase " + tcName + "(Schlüssel=" + tcUniquename + " ID= "+ maskExecutionId + ") initialized" ) ;
returnCode = executeMask ( ) ;
endtime = new java . util . Date ( ) . getTime ( ) ;
int maskExecutionResultId = saveExecutionResult ( returnCode , resultLog ) ;
writeToLog ( "Mask " + maskeninfoId + " executed in " + ( endtime - starttime ) / 1000 + " sec. with return Code " + returnCode ) ;
int maskExecutionResultId = saveExecutionResult ( maskExecutionId , returnCode , resultLog ) ;
if ( returnCode = = 0 )
{
returnCode = checkAssertions ( maskExecutionResultId ) ;
returnCode = checkAssertions ( maskExecutionId , maskExecution ResultId ) ;
}
else
throw new Exception ( "Testcase error in masc execution " + maskExecutionId ) ;
writeToLog ( "Testcase error in masc execution " + maskExecutionId ) ;
return returnCode ;
}
private static int executeMask ( )
@ -288,11 +337,11 @@ public class QaTestcaseExecutor {
@@ -288,11 +337,11 @@ public class QaTestcaseExecutor {
user = UserInitializer . initUser ( mandantenID , userName , userId , userAdmin ) ;
} catch ( Exception e ) {
System . err . println ( "Fehler beim Aufbau der Connection: " + e . toString ( ) ) ;
System . exit ( 1 ) ;
writeToLog ( "Fehler beim Aufbau der Connection: " + e . toString ( ) ) ;
return 1 ;
}
Locale desiredLocale = new Locale ( de . superx . util . SqlStringUtils . getEncoding ( ) ) ;
SuperXManager . maxRows = 1000000 ;
SuperXManager . maxRows = 10000 ;
Maske maske = null ;
InputCheckRegistry . registerDefaultChecks ( ) ;
try {
@ -302,29 +351,40 @@ public class QaTestcaseExecutor {
@@ -302,29 +351,40 @@ public class QaTestcaseExecutor {
myFieldContainer . addAll ( fields ) ; * /
maske . setFieldDefaults ( user , mock , true ) ;
resultXml = getResultXml ( mock , mockResponse , maske , user , desiredLocale ) ;
System . out . println ( "resultXml Länge " + resultXml . length ( ) + " für Maske " + maskeninfoId + " erzeugt" ) ;
if ( resultXml = = null )
{
writeToLog ( "resultXml für Maske " + maskeninfoId + " konnte nicht erzeugt werden" ) ;
}
else
{
writeToLog ( "resultXml Länge " + resultXml . length ( ) + " für Maske " + maskeninfoId + " erzeugt" ) ;
transformResultXmltoHtml ( ) ;
}
} catch ( Exception e ) {
e . printStackTrace ( ) ;
resultLog = "Fehler beim Ausführen der Maske " + maskeninfoId + ": " + e . toString ( ) ;
returnCode = 1 ;
}
user = null ;
return returnCode ;
}
private static int checkAssertions ( int maskExecutionResultId ) throws Exception
private static int checkAssertions ( int execId , int maskExecutionResultId ) throws Exception
{
int resultCode = 0 ;
int assertionId , assertionRownr , assertionColnr ;
Double minVal , maxVal , foundVal = null ;
String caption ;
String sql = "select "
+ "tid,"
+ "rownr,"
+ "colnr,"
+ "result_value_min,"
+ "result_value_max"
+ "result_value_max,"
+ "caption"
+ " from qa_mask_execution_assert"
+ " where is_active=1"
+ " and mask_execution_id=" + maskExecution Id+ ";" ;
+ " and mask_execution_id=" + exec Id+ ";" ;
/ * try {
@ -353,19 +413,22 @@ public class QaTestcaseExecutor {
@@ -353,19 +413,22 @@ public class QaTestcaseExecutor {
assertionColnr = ( Integer ) row . get ( 2 ) ;
minVal = ( Double ) row . get ( 3 ) ;
maxVal = ( Double ) row . get ( 4 ) ;
caption = ( String ) row . get ( 5 ) . toString ( ) ;
try {
foundVal = getValFromXml ( assertionRownr , assertionColnr ) ;
} catch ( Exception e ) {
System . err . println ( "Testfall ID " + maskExecutionId + " mit Maskennr. " + maskeninfoId + " Assertion-ID " + assertionId + " kein Ergebnis " ) ;
writeToLog ( "Testfall ID " + execId + " mit Maskennr. " + maskeninfoId + " Assertion-ID " + assertionId + " " + caption + " kein Ergebnis:\n" + e . toString ( ) ) ;
resultCode = 1 ;
return resultCode ;
}
if ( foundVal ! = null & & foundVal > = minVal & & foundVal < = maxVal )
{
System . out . println ( "Testfall ID " + maskExecutionId + " mit Maskennr. " + maskeninfoId + " Assertion-ID " + assertionId + " erfolgreich" ) ;
writeToLog ( "Testfall ID " + execId + " mit Maskennr. " + maskeninfoId + " Assertion-ID " + assertionId + " " + caption + " und Wert " + foundVal + " erfolgreich" ) ;
}
else
{
resultCode = 1 ;
System . out . println ( "Testfall ID " + maskExecutionId + " mit Maskennr. " + maskeninfoId + " Assertion-ID " + assertionId + " beendet mit Warnung/Fehler" ) ;
writeToLog ( "Testfall ID " + execId + " mit Maskennr. " + maskeninfoId + " Assertion-ID " + assertionId + " " + caption + " und Wert " + foundVal + " beendet mit Warnung/Fehler" ) ;
}
saveAssertResult ( assertionId , maskExecutionResultId , foundVal , resultCode , minVal , maxVal ) ;
}
@ -393,22 +456,22 @@ public class QaTestcaseExecutor {
@@ -393,22 +456,22 @@ public class QaTestcaseExecutor {
boolean executed = st . execute ( ) ;
}
private static int saveExecutionResult ( int maskExecutionResult , String log ) throws SQLException
private static int saveExecutionResult ( int execId , int maskExecutionResult , String log ) throws SQLException
{
int ret = 0 ;
java . sql . Timestamp startTimeDate = new java . sql . Timestamp ( starttime ) ;
java . sql . Timestamp endTimeDate = new java . sql . Timestamp ( endtime ) ;
String sql = "insert into qa_mask_execution_result(mask_execution_id, execution_start, execution_end, result_code,result_log,result_stream,result_stream_contenttype )" ;
String sql = "insert into qa_mask_execution_result(mask_execution_id, execution_start, execution_end, result_code,result_log,result_xml,result_html )" ;
sql + = "values(?,?,?,?,?,?,?);" ;
PreparedStatement st = myConnection . prepareStatement ( sql ) ;
st . setInt ( 1 , maskExecution Id) ;
st . setInt ( 1 , exec Id) ;
st . setTimestamp ( 2 , startTimeDate ) ;
st . setTimestamp ( 3 , endTimeDate ) ;
st . setInt ( 4 , maskExecutionResult ) ;
st . setString ( 5 , log ) ;
//im Fehler/Warnungsfall Ergebnis speichern:
st . setString ( 6 , resultXml ) ;
st . setString ( 7 , "text/xml" ) ;
st . setString ( 7 , resultHtml ) ;
boolean executed = st . execute ( ) ;
//get generated tid:
@ -465,6 +528,75 @@ public class QaTestcaseExecutor {
@@ -465,6 +528,75 @@ public class QaTestcaseExecutor {
return currentXml_local ;
}
public void initLogging ( ) {
File f ;
try {
logFile = PathAndFileUtils . getWebinfPath ( ) + File . separator + "logs" + File . separator + "superx_qa.log" ;
f = new File ( logFile ) ;
if ( f . exists ( ) )
f . delete ( ) ;
} catch ( Exception e ) {
// TODO Auto-generated catch block
e . printStackTrace ( ) ;
}
writeToLog ( "Start" ) ;
}
private static void writeToLog ( String msg )
{
FileWriter f ;
try {
f = new FileWriter ( logFile , true ) ;
long jetzt = new java . util . Date ( ) . getTime ( ) ;
Date date = new Date ( ) ;
date . setTime ( jetzt ) ;
SimpleDateFormat format = new SimpleDateFormat ( "yyyy-MM-dd hh:mm:ss" ) ;
f . write ( format . format ( date ) + ": " + msg + "\n" ) ;
f . close ( ) ;
} catch ( IOException e ) {
// TODO Auto-generated catch block
e . printStackTrace ( ) ;
System . err . println ( msg ) ;
}
}
private static void transformResultXmltoHtml ( )
{
String xslFile = "" ;
ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ;
PrintStream myStream = new PrintStream ( baos ) ;
try {
StringWriter myOutwriter = new StringWriter ( ) ;
xslFile = PathAndFileUtils . getWebinfDirectory ( ) + PathAndFileUtils . PATHSEP + ".." + PathAndFileUtils . PATHSEP + "xml" + PathAndFileUtils . PATHSEP + "tabelle_html_qa.xsl" ;
File f = new File ( xslFile ) ;
//in development mode the XSL is not available:
if ( ! f . exists ( ) )
xslFile = PathAndFileUtils . getWebinfDirectory ( ) + PathAndFileUtils . PATHSEP + ".." + PathAndFileUtils . PATHSEP + "xml" + PathAndFileUtils . PATHSEP + "tabelle_html2.xsl" ;
javax . xml . transform . TransformerFactory tFactory = javax . xml . transform . TransformerFactory . newInstance ( "net.sf.saxon.TransformerFactoryImpl" , null ) ;
javax . xml . transform . Transformer transformer = tFactory . newTransformer ( new javax . xml . transform . stream . StreamSource ( xslFile ) ) ;
StringReader s1 = new StringReader ( resultXml ) ;
transformer . setOutputProperty ( javax . xml . transform . OutputKeys . ENCODING , SqlStringUtils . getEncoding ( ) ) ;
transformer . setOutputProperty ( javax . xml . transform . OutputKeys . METHOD , "html" ) ;
/ * TODO : hier Parameter einzelne Zeile übergeben :
* String paramname = param . substring ( 0 , param . indexOf ( "=" ) ) ;
String paramvalue = param . substring ( param . indexOf ( "=" ) + 1 , param . length ( ) ) ;
transformer . setParameter ( paramname , paramvalue ) ;
* /
transformer . transform ( new javax . xml . transform . stream . StreamSource ( s1 ) , new javax . xml . transform . stream . StreamResult ( myOutwriter ) ) ;
resultHtml = myOutwriter . toString ( ) ;
myOutwriter . close ( ) ;
s1 . close ( ) ;
} catch ( Exception e ) {
writeToLog ( "resultXml konnte nicht zu HTML konvertiert werden:\n" + e . toString ( ) ) ;
resultLog + = ( "resultXml konnte nicht zu HTML konvertiert werden:\n" + e . toString ( ) ) ;
resultHtml = "resultXml konnte nicht zu HTML konvertiert werden:" + resultXml ;
}
}
}