public static class Logget {
ByteArrayOutputStream bytes = new ByteArrayOutputStream ( ) ;
PrintStream console;
public List< String> loglist = new ArrayList < > ( ) ;
public void listenSTD ( ) {
console = System. out;
System. setOut ( new PrintStream ( bytes) ) ;
}
public void listenSTDAndClear ( ) {
listenSTD ( ) ;
loglist. clear ( ) ;
bytes. reset ( ) ;
}
public List< String> close ( ) {
resetSTD ( ) ;
for ( String s : bytes. toString ( ) . split ( "\r\n" )
) {
loglist. add ( s) ;
}
return this . loglist;
}
private void resetSTD ( ) {
System. setOut ( console) ;
}
public List< String> closeandprintSTD ( ) {
resetSTD ( ) ;
System. out. print ( bytes) ;
return close ( ) ;
}
}
logget= new Logget ( ) ;
logger. listenSTDAndClear ( ) ;
日志打印
日志打印1
logtext = logget. closeandprintSTD ( ) ;
public < T> List< T> loadYAML ( String content, Class cls ) {
ObjectMapper mapper = new ObjectMapper ( new YAMLFactory ( ) ) ;
mapper. configure ( DeserializationFeature. FAIL_ON_UNKNOWN_PROPERTIES, false ) ;
try {
return mapper. readValue ( content, mapper. getTypeFactory ( ) . constructParametricType ( ArrayList. class , cls) ) ;
} catch ( JsonProcessingException e) {
e. printStackTrace ( ) ;
}
return null;
}
public < T> List< T> loadYAML ( URL src, Class cls ) {
ObjectMapper mapper = new ObjectMapper ( new YAMLFactory ( ) ) ;
mapper. configure ( DeserializationFeature. FAIL_ON_UNKNOWN_PROPERTIES, false ) ;
try {
return mapper. readValue ( src, mapper. getTypeFactory ( ) . constructParametricType ( ArrayList. class , cls) ) ;
} catch ( JsonProcessingException e) {
e. printStackTrace ( ) ;
} catch ( IOException e) {
e. printStackTrace ( ) ;
}
return null;
}
protected void title ( String s) {
String out = String. format ( "==[step%d].[%s]=" , step++ , s) ;
try {
while ( new String ( out. getBytes ( "GB2312" ) , "ISO-8859-1" ) . length ( ) < 50 ) {
out += "=" ;
}
} catch ( UnsupportedEncodingException u) {
u. printStackTrace ( ) ;
}
StackTraceElement stackTraceElement = Thread. currentThread ( ) . getStackTrace ( ) [ 2 ] ;
System. out. println ( out + "(" + stackTraceElement. getFileName ( ) + ":" + stackTraceElement. getLineNumber ( ) + ")" ) ;
}
@Autowired
protected FlowReq baseTestNameSpace;
protected void initOnce ( String uniqueName, Executor executor) {
Objects. requireNonNull ( executor) ;
if ( ! baseTestNameSpace. b ( uniqueName) ) {
executor. runAction ( this ) ;
baseTestNameSpace. append ( uniqueName, true ) ;
log. info ( uniqueName+ " initOnce() Done" ) ;
}
}
protected interface Executor {
void runAction ( BaseFlowTest a) ;
}
initOnce ( "init" , ( base) - > {
do ( ) ;
} ) ;