Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2011 JBoss Inc
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.drools.simulation.impl;
 
 import java.util.List;
 import java.util.Map;
 
 import org.junit.Test;
 
 public class JUnitSimulationRunner extends Runner {
 
     private Description              descr;
     private Map<StringDescriptiontestGroups  = new HashMap<StringDescription>();
 
     private List<Simulation>         simulations = new ArrayList<Simulation>();
 
     public JUnitSimulationRunner(Class cls) {
         this. = Description.createSuiteDescriptioncls );
 
         Object object = null;
         try {
             object = cls.newInstance();
         } catch ( Exception e ) {
 
         }
 
         List<Methodmethods = new ArrayList<Method>();
         for ( Method method : cls.getDeclaredMethods() ) {
             if ( method.getReturnType().equalsSimulation.class ) && method.getAnnotationTest.class ) != null ) {
                 methods.addmethod );
             }
         }
 
         try {
             for ( Method method : methods ) {
 
                 Simulation simulation = (Simulationmethod.invokeobject,
                                                                     null );
 
                 for ( SimulationPath path : simulation.getPaths().values() ) {
                     for ( SimulationStep step : path.getSteps() ) {
                         for ( Command command : step.getCommands() ) {
                             if ( command instanceof TestGroupCommand ) {
                                 String testName = ((TestGroupCommandcommand).getName();
                                 Description testGroupDescr = Description.createTestDescriptioncls,
                                                                                                 testName );
                                 this..addChildtestGroupDescr );
                                 this..puttestName,
                                                      testGroupDescr );
                             }
                         }
                     }
                 }
 
                 .addsimulation );
             }
         } catch ( Exception e ) {
         }
 
         //        
         //        System.out.println( "class:" + cls );
         //        this.descr = Description.createSuiteDescription( cls );
         //        this.descr1 = Description.createTestDescription( cls, "test1" );
         //        this.descr2 = Description.createTestDescription( cls, "test2" );
         //        
         //        this.descr.addChild( descr1 );
         //        this.descr.addChild( descr2 );
 
     }
 
     @Override
    public Description getDescription() {
        return this.;
    }
    @Override
    public void run(RunNotifier notifier) {
        JunitCommandExecutionHandler executionHandler = new JunitCommandExecutionHandlernotifier,
                                                                                          this. );
        for ( Simulation simulation :  ) {
            Simulator simulator = new Simulatorsimulation,
                                                 System.currentTimeMillis() );
            simulator.setCommandExecutionHandlerexecutionHandler );
            simulator.run();
        }
    }
    public static class JunitCommandExecutionHandler
            implements CommandExecutionHandler {
        private RunNotifier              notifier;
        private Map<StringDescriptiontestGroups;
        public JunitCommandExecutionHandler(RunNotifier notifier,
                                            Map<StringDescriptiontestGroups) {
            super();
            this. = notifier;
            this. = testGroups;
        }
        public Object execute(GenericCommand command,
                              Context context) {
            if ( command instanceof TestGroupCommand ) {
                TestGroupCommand testGroupCmd = (TestGroupCommandcommand;
                Description descr = this..gettestGroupCmd.getName() );
                this..fireTestStarteddescr );
                try {
                    command.executecontext );
                    this..fireTestFinisheddescr );
                    return null;
                } catch ( Exception e ) {
                    this..fireTestFailurenew Failuredescr,
                                                                e ) );
                    return null;
                }
            } else {
                return command.executecontext );
            }
        }
    }
New to GrepCode? Check out our FAQ X