Package nexj.core.meta.testing.unit

Examples of nexj.core.meta.testing.unit.UnitTest


   /**
    * @see nexj.core.meta.EnterpriseMetadata#getUnitTest(java.lang.String)
    */
   public UnitTest getUnitTest(String sName)
   {
      UnitTest utest = null;

      synchronized (m_unitTestMap)
      {
         utest = (UnitTest)m_unitTestMap.get(sName);
      }
View Full Code Here


      Collections.sort(m_unitTestList, new Comparator()
      {
         public int compare(Object left, Object right)
         {
            UnitTest leftUnitTest = (UnitTest)left;
            UnitTest rightUnitTest = (UnitTest)right;
            URL leftDumpURL = getDumpURL(leftUnitTest);
            URL rightDumpURL = getDumpURL(rightUnitTest);
           
            if (leftDumpURL == null)
            {
               return (rightDumpURL == null) ? 0 : -1;
            }
           
            int n = leftDumpURL.toString().compareTo(rightDumpURL.toString());

            if (n != 0)
            {
               return n;
            }

            return leftUnitTest.getName().compareToIgnoreCase(rightUnitTest.getName());
         }
      });

      run();
   }
View Full Code Here

                  IOUtil.close(reader);
                  IOUtil.close(istream);
               }
            }

            UnitTest utest = (UnitTest)m_unitTestList.get(nUnitTest);

            for (Iterator argItr = new ArgumentIterator(context, utest); argItr.hasNext(); )
            {
               Object[] variableArray = (Object[])argItr.next();
               String sTestArguments = formatLoopVariables(variableArray, utest.getLoopCount());
               DataLoader dataLoader = new DataLoader(context);
               URL dumpURL = getDumpURL(utest);
               boolean bResetDB = dumpURL != null;

               m_unitTestLogger.begin(utest, sTestArguments);

               if (bResetDB && !bReady)
               {
                  if (m_container != null)
                  {
                     m_container.suspend();
                  }

                  bReady = true;

                  if (nUnitTest == 0)
                  {
                     try
                     {
                        dataLoader.recreateSchema((Set)null);
                     }
                     catch (Throwable e)
                     {
                        m_unitTestLogger.err(utest, e);

                        return;
                     }
                  }
                  else
                  {
                     bFirstRun = false;
                  }
               }

               byte nMode = utest.getMode();
               int nTestCase = 0;

               if (utest.hasInitializer())
               {
                  ++nTestCase;
               }

               if (utest.hasFinalizer())
               {
                  ++nTestCase;
               }

               Object[] functionObjArray = null;

               if (utest.getFunction() != null)
               {
                  functionObjArray = (Object[])context.getMachine().invoke(utest.getFunction(), variableArray);
               }

               boolean bFirstTestCase = true;

               for (Iterator itr = utest.getUnitTestCaseIterator(); itr.hasNext();
                  bFirstRun = false, bFirstTestCase = false, bResetDB = dumpURL != null && nMode != UnitTest.MODE_DIRTY)
               {
                  UnitTestCase testCase = (UnitTestCase)itr.next();

                  if (!isEnabled(utest, testCase))
                  {
                     nTestCase++;
                     continue;
                  }

                  if (bResetDB)
                  {
                     if (!bFirstTestCase && m_container != null)
                     {
                        m_container.suspend();
                     }

                     if (!bFirstRun)
                     {
                        try
                        {
                           dataLoader.deleteData((Set)null);
                        }
                        catch (Throwable e)
                        {
                           m_unitTestLogger.err(utest, e);

                           return;
                        }
                     }

                     InputStream in = null;

                     try
                     {
                        in = new BufferedInputStream(URLUtil.openStream(dumpURL));
                        dataLoader.importData(in, true);
                     }
                     catch (Throwable e)
                     {
                        m_unitTestLogger.err(utest, e);

                        return;
                     }
                     finally
                     {
                        IOUtil.close(in);
                        in = null;
                     }
                  }

                  context.complete(true);
                  context.getMachine().cleanup();
                  context.initUnitOfWork();

                  final InvocationContext testContext = (InvocationContext)metadata
                     .getComponent("System.InvocationContext").getInstance(null);

                  try
                  {
                     testContext.setAudited(false);
                     testContext.getGlobalCache().clear();
                     testContext.initialize((m_sSystemUser == null) ? null : new SimplePrincipal(m_sSystemUser),
                        new GlobalEnvironment(m_globalEnv));

                     if (m_container != null && m_sSystemUser != null)
                     {
                        Event grantDebugEvent = testContext.getUserClass().findEvent(GRANT_DEBUG, 0);

                        if (grantDebugEvent != null)
                        {
                           boolean bSecure = testContext.isSecure();

                           try
                           {
                              testContext.setSecure(false);
                              grantDebugEvent.invoke(testContext.getUser(), (Pair)null, testContext.getMachine());
                           }
                           finally
                           {
                              testContext.setSecure(bSecure);
                           }
                        }
                     }

                     if (bResetDB && m_container != null)
                     {
                        m_container.resume();

                        // Suspend the thread if in script debugging mode
                        if (m_bDebug)
                        {
                           PCodeFunction nextFunction = (PCodeFunction)((utest.hasInitializer()) ? functionObjArray[0]
                              : functionObjArray[nTestCase]);

                           s_logger.debug("Waiting for script debugger to connect");

                           try
                           {
                              Class clazz = Class.forName("nexj.core.scripting.debugger.server.GenericDebugSessionManager");
                             
                              Object debugSessionManager = clazz.getMethod("getInstance", null).invoke(null, null);
                             
                              clazz.getMethod("suspendOnStartup", new Class[]{PCodeLocation.class})
                                 .invoke(debugSessionManager, new Object[]{new PCodeLocation(nextFunction, 0)});
                           }
                           catch(Throwable t)
                           {
                              ObjUtil.rethrow(t);
                           }
                        }

                        ThreadContextHolder.setContext(testContext);
                     }

                     if (utest.hasInitializer())
                     {
                        try
                        {
                           testContext.getMachine().invoke((Function)functionObjArray[0], (Object[])null);
                        }
                        catch (Throwable e)
                        {
                           m_unitTestLogger.err(testCase, e);
                           ++nErrorCount;

                           continue;
                        }
                     }

                     m_unitTestLogger.begin(testCase);

                     try
                     {
                        nTestCaseCount++;
                        testContext.getMachine().invoke((Function)functionObjArray[nTestCase++], (Object[])null);
                        m_unitTestLogger.end(testCase);
                     }
                     catch (UnitTestAssertionException e)
                     {
                        m_unitTestLogger.fail(testCase, e);
                        ++nFailureCount;
                     }
                     catch (Throwable e)
                     {
                        m_unitTestLogger.err(testCase, e);
                        ++nErrorCount;
                     }

                     if (utest.hasFinalizer())
                     {
                        try
                        {
                           testContext.getMachine().invoke(
                              (Function)functionObjArray[(!utest.hasInitializer()) ? 0 : 1],
                              (Object[])null);
                        }
                        catch (Throwable e)
                        {
                           m_unitTestLogger.err(testCase, e);
View Full Code Here

TOP

Related Classes of nexj.core.meta.testing.unit.UnitTest

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.