Package org.jboss.arquillian.test.spi

Examples of org.jboss.arquillian.test.spi.TestResult


         if (testInstance != null)
         {
            try
            {
               TestResult result = null;
               try
               {
                  try
                  {
                     testInstance = ClassLoaderAdapterCallback.enhance(getClass().getClassLoader(),
                              testInstance.getClass().getClassLoader(), testInstance, testClass);
                     testInstance.getClass();
                  }
                  catch (Exception e)
                  {
                     System.out.println("Could not enhance test class. Falling back to un-proxied invocation.");
                  }

                  Method method = testInstance.getClass().getMethod(testMethodExecutor.getMethod().getName());
                  Annotation[] annotations = method.getAnnotations();

                  for (Annotation annotation : annotations)
                  {
                     if ("org.junit.Ignore".equals(annotation.getClass().getName()))
                     {
                        result = new TestResult(Status.SKIPPED);
                     }
                  }

                  if (result == null)
                  {
                     try
                     {
                        System.out.println("Executing test method: "
                                 + testMethodExecutor.getInstance().getClass().getName() + "."
                                 + testMethodExecutor.getMethod().getName() + "()");

                        try
                        {
                           invokeBefore(testInstance.getClass(), testInstance);
                           method.invoke(testInstance);
                        }
                        catch (Exception e)
                        {
                           throw e;
                        }
                        finally
                        {
                           invokeAfter(testInstance.getClass(), testInstance);
                        }

                        result = new TestResult(Status.PASSED);
                     }
                     catch (InvocationTargetException e)
                     {
                        if (e.getCause() != null && e.getCause() instanceof Exception)
                           throw (Exception) e.getCause();
                        else
                           throw e;
                     }
                  }
               }
               catch (AssertionError e)
               {
                  result = new TestResult(Status.FAILED, e);
               }
               catch (Exception e)
               {
                  result = new TestResult(Status.FAILED, e);

                  Throwable cause = e.getCause();
                  while (cause != null)
                  {
                     if (cause instanceof AssertionError)
                     {
                        result = new TestResult(Status.FAILED, cause);
                        break;
                     }
                     cause = cause.getCause();
                  }
               }
View Full Code Here


      return new Statement()
      {
         @Override
         public void evaluate() throws Throwable
         {
            TestResult result = adaptor.test(new TestMethodExecutor()
            {
               @Override
               public void invoke(Object... parameters) throws Throwable
               {
                  try
                  {
                     method.invokeExplosively(test, parameters);
                  }
                  catch (Throwable e)
                  {
                     // Force a way to return the thrown Exception from the Container the client.
                     State.caughtTestException(e);
                     throw e;
                  }
               }
              
               public Method getMethod()
               {
                  return method.getMethod();
               }
              
               public Object getInstance()
               {
                  return test;
               }
            });
            if(result.getThrowable() != null)
            {
               throw result.getThrowable();
            }
         }
      };
   }
View Full Code Here

   {
      doAnswer(new ExecuteLifecycle()).when(adaptor).beforeClass(any(Class.class), any(LifecycleMethodExecutor.class));
      doAnswer(new ExecuteLifecycle()).when(adaptor).afterClass(any(Class.class), any(LifecycleMethodExecutor.class));
      doAnswer(new ExecuteLifecycle()).when(adaptor).before(any(Object.class), any(Method.class), any(LifecycleMethodExecutor.class));
      doAnswer(new ExecuteLifecycle()).when(adaptor).after(any(Object.class), any(Method.class), any(LifecycleMethodExecutor.class));
      doAnswer(new TestExecuteLifecycle(new TestResult(Status.PASSED))).when(adaptor).test(any(TestMethodExecutor.class));
   }
View Full Code Here

   }

   public void run(final IHookCallBack callback, final ITestResult testResult)
   {
      verifyTestRunnerAdaptorHasBeenSet();
      TestResult result;
      try
      {
         result = deployableTest.get().test(new TestMethodExecutor()
         {
            public void invoke(Object... parameters) throws Throwable
            {
               /*
                *  The parameters are stored in the InvocationHandler, so we can't set them on the test result directly.
                *  Copy the Arquillian found parameters to the InvocationHandlers parameters
                */
               copyParameters(parameters, callback.getParameters());
               callback.runTestMethod(testResult);
              
               // Parameters can be contextual, so extract information
               swapWithClassNames(callback.getParameters());
               testResult.setParameters(callback.getParameters());
               if (testResult.getThrowable() != null) {
                   throw testResult.getThrowable();
               }
            }
           
            private void copyParameters(Object[] source, Object[] target)
            {
               for(int i = 0; i < source.length; i++)
               {
                  if(source[i] != null)
                  {
                     target[i] = source[i];
                  }
               }
            }
           
            private void swapWithClassNames(Object[] source)
            {
               // clear parameters. they can be contextual and might fail TestNG during the report writing.
               for(int i = 0; source != null && i < source.length; i++)
               {
                  Object parameter = source[i];
                  if(parameter != null)
                  {
                     source[i] = parameter.toString();
                  }
                  else
                  {
                     source[i] = "null";
                  }
               }
            }
           
            public Method getMethod()
            {
               return testResult.getMethod().getMethod();
            }
           
            public Object getInstance()
            {
               return Arquillian.this;
            }
         });
         if(result.getThrowable() != null)
         {
            testResult.setThrowable(result.getThrowable());
         }

         // calculate test end time. this is overwritten in the testng invoker..
         testResult.setEndMillis( (result.getStart() - result.getEnd()) + testResult.getStartMillis());
      }
      catch (Exception e)
      {
         testResult.setThrowable(e);
      }
View Full Code Here

        String testMethod = testMethodExecutor.getMethod().getName();
        String testCanonicalName = testClass + "." + testMethod;

        NotificationListener commandListener = null;
        ObjectName objectName = null;
        TestResult result = null;
        try {
            objectName = new ObjectName(JMXTestRunnerMBean.OBJECT_NAME);
            commandListener = new CallbackNotificationListener(objectName);
            mbeanServer.addNotificationListener(objectName, commandListener, null, null);

            JMXTestRunnerMBean testRunner = getMBeanProxy(objectName, JMXTestRunnerMBean.class);
            log.fine("Invoke " + testCanonicalName);
            result = Serializer.toObject(TestResult.class, testRunner.runTestMethod(testClass, testMethod));

        } catch (final Throwable th) {
            result = new TestResult(Status.FAILED);
            result.setThrowable(th);
        } finally {
            result.setEnd(System.currentTimeMillis());
            if (objectName != null && commandListener != null) {
                try {
                    mbeanServer.removeNotificationListener(objectName, commandListener);
                } catch (Throwable th) {
                    log.log(Level.SEVERE, "Cannot remove notification listener", th);
                }
            }
        }
        log.fine("Result: " + result);
        if (result.getStatus() == Status.FAILED)
            log.log(Level.SEVERE, "Failed: " + testCanonicalName, result.getThrowable());
        return result;
    }
View Full Code Here

      localMBeanServer = null;
   }

   public byte[] runTestMethod(String className, String methodName)
   {
      TestResult result = runTestMethodInternal(className, methodName);
      return Serializer.toByteArray(result);
   }
View Full Code Here

   }

   private TestResult runTestMethodInternal(String className, String methodName)
   {
      currentCall.set(className + methodName);
      TestResult result = new TestResult();
      try
      {
         TestRunner runner = mockTestRunner;
         if (runner == null)
         {
            runner = TestRunners.getTestRunner(getClass().getClassLoader());
         }

         log.fine("Load test class: " + className);
         Class<?> testClass = testClassLoader.loadTestClass(className);
         log.fine("Test class loaded from: " + testClass.getClassLoader());

         log.fine("Execute: " + className + "." + methodName);
         result = runner.execute(testClass, methodName);
      }
      catch (Throwable th)
      {
         result.setStatus(Status.FAILED);
         result.setEnd(System.currentTimeMillis());
         result.setThrowable(th);
      }
      finally
      {
         log.fine("Result: " + result);
         if (result.getStatus() == Status.FAILED)
            log.log(Level.SEVERE, "Failed: " + className + "." + methodName, result.getThrowable());
      }
      return result;
   }
View Full Code Here

   public void executeTest(HttpServletResponse response, String outputMode, String className, String methodName)
         throws ClassNotFoundException, IOException
   {
      Class<?> testClass = SecurityActions.getThreadContextClassLoader().loadClass(className);
      TestRunner runner = TestRunners.getTestRunner();
      TestResult testResult = runner.execute(testClass, methodName);
      if(OUTPUT_MODE_SERIALIZED.equalsIgnoreCase(outputMode))
      {
         writeObject(testResult, response);
      }
      else
View Full Code Here

      return Collections.emptyList();
   }

   public TestResult execute(Class<?> testClass, String methodName)
   {
      TestResult testResult = new TestResult(Status.PASSED);
      ExpectedExceptionHolder exceptionHolder = new ExpectedExceptionHolder();
      try
      {
          JUnitCore runner = new JUnitCore();

          runner.addListener(exceptionHolder);

          for (RunListener listener : getRunListeners())
             runner.addListener(listener);

          Result result = runner.run(Request.method(testClass, methodName));
          testResult.setThrowable(exceptionHolder.getException());

          if (result.getFailureCount() > 0)
          {
             testResult.setStatus(Status.FAILED);
             testResult.setThrowable(result.getFailures().get(0).getException());
          }
          if (result.getIgnoreCount() > 0)
          {
              testResult.setStatus(Status.SKIPPED);
          }
      }
      catch (Throwable th) {
          testResult.setStatus(Status.FAILED);
          testResult.setThrowable(th);
      }
      finally
      {
          testResult.setEnd(System.currentTimeMillis());
      }
      return testResult;
   }
View Full Code Here

      if (testInstance != null)
      {
         try
         {
            TestResult result = null;
            try
            {
               Method method = testInstance.getClass().getMethod(testMethodExecutor.getMethod().getName());
               Annotation[] annotations = method.getAnnotations();

               for (Annotation annotation : annotations)
               {
                  if ("org.junit.Ignore".equals(annotation.getClass().getName()))
                  {
                     result = new TestResult(Status.SKIPPED);
                  }
               }

               if (result == null)
               {
                  try
                  {
                     try
                     {
                        System.out.println("Executing test method: "
                                 + testMethodExecutor.getInstance().getClass().getName() + "."
                                 + testMethodExecutor.getMethod().getName() + "()");

                        invokeBefore(testClass, testInstance);
                        method.invoke(testInstance);
                        invokeAfter(testClass, testInstance);

                        result = new TestResult(Status.PASSED);
                     }
                     finally
                     {
                     }
                  }
                  catch (InvocationTargetException e)
                  {
                     if (e.getCause() != null && e.getCause() instanceof Exception)
                        throw (Exception) e.getCause();
                     else
                        throw e;
                  }
               }
            }
            catch (AssertionError e)
            {
               result = new TestResult(Status.FAILED, e);
            }
            catch (Exception e)
            {
               result = new TestResult(Status.FAILED, e);

               Throwable cause = e.getCause();
               while (cause != null)
               {
                  if (cause instanceof AssertionError)
                  {
                     result = new TestResult(Status.FAILED, cause);
                     break;
                  }
                  cause = cause.getCause();
               }
            }
View Full Code Here

TOP

Related Classes of org.jboss.arquillian.test.spi.TestResult

Copyright © 2018 www.massapicom. 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.