Package eu.mosaic_cloud.drivers.filesystem

Source Code of eu.mosaic_cloud.drivers.filesystem.ExtendedTestLoggingHandler

package eu.mosaic_cloud.drivers.filesystem;
import org.slf4j.Logger;

import eu.mosaic_cloud.platform.core.tests.TestLoggingHandler;
import eu.mosaic_cloud.tools.transcript.core.Transcript;


public class ExtendedTestLoggingHandler<T extends Object> extends TestLoggingHandler<T>{

  protected String testName = "";
  protected final Logger logger;
  protected T result=null;
  protected T expectedValue=null;


  public ExtendedTestLoggingHandler(String testName, T expectedValue) {
    super(testName);
    this.testName = testName;
    this.expectedValue = expectedValue;
    final Transcript transcript = Transcript.create (this, true);
    logger = transcript.adaptAs(Logger.class);
  }

  @Override
  public void onFailure(Throwable error){
//    this.logger.trace("ExtendedTestLoggingHandler::" + testName + " failure:" +error.getMessage());
    super.onFailure(error);
  }

  @Override
  public void onSuccess(T result) {

    if(result instanceof byte[])
    {
      byte[] bytes = (byte[]) result;
      byte[] expected =  (byte[]) expectedValue;

      if(expected!=null)
        this.logger.trace("Test " + this.testName + " finished with byte[" + bytes.length +
            "] of expected " + expected.length);
      else
        this.logger.trace("Test " + this.testName + " finished with byte[" + bytes.length + "]");

    }
    else if (result instanceof String)
    {
      if(expectedValue!=null && expectedValue instanceof String && !result.equals(expectedValue))
        this.logger.trace("Test " + this.testName + " finished with result: " + result +
            "but the expected value was " + expectedValue);
      else
        this.logger.trace("Test " + this.testName + " finished with result: " + result);
    }
    else if (result instanceof Boolean)
    {
      if(expectedValue!=null && expectedValue instanceof Boolean && result!=expectedValue)
        this.logger.trace("Test " + this.testName + " finished with result: " + result +
            ", but the expected value was " + expectedValue);
      else
        this.logger.trace("Test " + this.testName + " finished with result: " + result);
    }

    this.result = result;
  }

  public T getResult()
  {
    return result;
  }

}
TOP

Related Classes of eu.mosaic_cloud.drivers.filesystem.ExtendedTestLoggingHandler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.