Class TestModel


  • public class TestModel
    extends java.lang.Object
    The test model. There's not much more to say ;-)
    Author:
    Rene Schneider - initial API and implementation
    • Field Detail

      • models

        protected java.util.List<Model> models
        All models. Every file is a model of itself (though they are all linked, of course).
      • suiteMap

        protected java.util.Map<java.lang.String,​SuiteDefinition> suiteMap
        Suite names -> Suites.
      • variantMap

        protected java.util.Map<java.lang.String,​VariantDefinition> variantMap
        Variant names -> Variants.
      • forkMap

        protected java.util.Map<java.lang.String,​ForkDefinition> forkMap
        Fork names -> Forks.
      • callMap

        protected java.util.Map<java.lang.String,​CallDefinition> callMap
        Call names -> Calls.
      • testMap

        protected java.util.Map<java.lang.String,​TestDefinition> testMap
        Test names -> Tests.
      • variableAndConstantMap

        protected java.util.Map<java.lang.String,​VariableOrConstantEntity> variableAndConstantMap
        Variable/constant names -> Entities.
      • ambiguousDefinitions

        protected java.util.Set<AmbiguousDefinition> ambiguousDefinitions
        Ambiguous definitions which are found during variable/suite/etc. indexing are collected here.
      • constantDefinitionsInPackages

        protected java.util.TreeSet<ConstantDefinition> constantDefinitionsInPackages
        Stores an ordered list of global constant definitions. This is intended as a cache - if it's null, it must be recreated.
      • variableDefinitionsInPackages

        protected java.util.TreeSet<VariableDefinition> variableDefinitionsInPackages
        Stores an ordered list of global variable definitions. This is intended as a cache - if it's null, it must be recreated.
      • injector

        @Inject
        protected com.google.inject.Injector injector
        The Google Guice Injector.
      • modelSourceExplorer

        @Inject
        protected ModelSourceExplorer modelSourceExplorer
        The model source explorer.
      • loadedResources

        protected java.util.Queue<TestResource> loadedResources
        All successfully loaded resources, in the order in which they were loaded.
      • loadedResourceProviders

        protected java.util.List<TestResourceProvider> loadedResourceProviders
        All resource providers that this model has been filled from.
      • inMemoryResourceProviders

        protected java.util.List<InMemoryTestResourceProvider> inMemoryResourceProviders
        This list stores copies of the loadedResourceProviders which refer to resources which have been fully loaded in memory. It is intended as a cache to avoid repeated duplication of the same TestResourceProviders. If it is null, the cache is empty and must be recreated. If not, it can be used.
      • PRINT_ALL_LOADED_SCRIPTS_PROPERTY

        public static final java.lang.String PRINT_ALL_LOADED_SCRIPTS_PROPERTY
        Set this system property to turn on verbose script loading. This makes Integrity list all scripts that it loads, regardless of the number of scripts being loaded. If this is turned off, only a summary is printed if more than MAX_SCRIPT_COUNT_AUTO_VERBOSE_LOADING scripts are being loaded.
        See Also:
        Constant Field Values
      • MAX_SCRIPT_COUNT_AUTO_VERBOSE_LOADING

        protected static final int MAX_SCRIPT_COUNT_AUTO_VERBOSE_LOADING
        The maximum number of scripts which are always loaded in "verbose" mode.
        See Also:
        Constant Field Values
      • verboseScriptLoading

        protected final boolean verboseScriptLoading
        Whether to load scripts in a verbose fashion (=printing every load).
      • MULTITHREADED_SECTIONS_THREAD_COUNT_PROPERTY

        protected static final java.lang.String MULTITHREADED_SECTIONS_THREAD_COUNT_PROPERTY
        The system property that allows to override the number of threads used to do some time-critical sections in the test runner, such as defining constants and variables.
        See Also:
        Constant Field Values
      • MULTITHREADED_SECTIONS_THREAD_COUNT_DEFAULT_MAX

        protected static final int MULTITHREADED_SECTIONS_THREAD_COUNT_DEFAULT_MAX
        The maximum of multithreaded threads if default determination is used. This is not taken into account if a custom number of threads is set via MULTITHREADED_SECTIONS_THREAD_COUNT_PROPERTY.
        See Also:
        Constant Field Values
      • resourceLoadingSyncObject

        protected java.lang.Object resourceLoadingSyncObject
        This sync object is used to synchronize access to XtextResourceFactory, XtextResource and XtextResourceSet. I'm not sure if those are parallelizable, so better be safe than sorry.
      • statusOutputSyncObject

        protected java.lang.Object statusOutputSyncObject
        Used to synchronize potential printouts - printing to stdout with multiple threads can quickly lead to chaos.
    • Constructor Detail

      • TestModel

        public TestModel()
    • Method Detail

      • getMultithreadedSectionsThreadCount

        public int getMultithreadedSectionsThreadCount()
        Returns the number of threads to use during multithreaded sections, such as defining constants and variables. This public method is located here for practical reasons - the test model and test runner both need this information, but the model needs it first, so I've placed it here.
      • getMultithreadedSectionsThreadCountDefault

        protected int getMultithreadedSectionsThreadCountDefault()
        Returns the default number of threads to use during multithreaded sections, such as defining constants and variables.
      • addIntegrityScriptModels

        public void addIntegrityScriptModels​(java.util.List<Model> someModels)
        Adds all given Integrity script files to the test model.
        Parameters:
        someModels - the models to add
      • addIntegrityScriptModel

        public void addIntegrityScriptModel​(Model aModel)
        Adds a given Integrity script file to the test model.
        Parameters:
        aModel - the model to add
      • readIntegrityScriptFiles

        public java.util.List<Diagnostic> readIntegrityScriptFiles​(TestResourceProvider aResourceProvider,
                                                                   boolean aPerformModelValidationFlag)
                                                            throws ModelLoadException
        Reads all Integrity scripts from the provided resource provider and initializes this test model with them. This is an "additive" operation, meaning that it is possible to call this method on a model multiple times and inject more and more scripts.

        For each successfully loaded resource provider, a reference to the provider is stored in the model as well. The same is done for each successfully loaded resource (see TestResource). These references may later be retrieved by getLoadedResourceProviders() and getLoadedResources().
        Parameters:
        aResourceProvider - the resource provider to use for loading
        aPerformModelValidationFlag - whether model validation is to be done
        Returns:
        any errors that happened while loading or validating
        Throws:
        ModelLoadException
      • loadSingleResource

        protected java.util.List<Diagnostic> loadSingleResource​(TestResourceProvider aResourceProvider,
                                                                TestResource aResourceName,
                                                                org.eclipse.xtext.resource.XtextResourceSet aResourceSet,
                                                                org.eclipse.xtext.resource.IResourceFactory aResourceFactory,
                                                                boolean aVerboseFlag)
                                                         throws ModelLoadException
        Loads a single TestResource from the given TestResourceProvider. This method is deliberately designed to be thread-safe and shall be invoked in parallel for parallelized script loading.
        Parameters:
        aResourceProvider - the resource provider to load from
        aResourceName - the resource to load
        aResourceSet - the resource set to add the resource to
        aResourceFactory - the resource factory to use
        aVerboseFlag - whether to make verbose output
        Returns:
        a list of errors
        Throws:
        ModelLoadException
      • customValidateSingleModel

        protected java.util.List<Diagnostic> customValidateSingleModel​(Model aModel)
        Performs validation of a single model. THIS IS NOT THREAD-SAFE, as the model is being lazy-resolved during validation, which may trigger modifications to other models' internal structures.
        Parameters:
        aModel - the model to validate
        Returns:
        a list of validation errors (only errors are reported)
      • getInjector

        public com.google.inject.Injector getInjector()
      • getModels

        public java.util.List<Model> getModels()
      • getLoadedResources

        public java.util.List<TestResource> getLoadedResources()
      • getLoadedResourceProviders

        public java.util.List<TestResourceProvider> getLoadedResourceProviders()
      • getDuplicateDefinitions

        public java.util.Set<AmbiguousDefinition> getDuplicateDefinitions()
      • getSuiteByName

        public SuiteDefinition getSuiteByName​(java.lang.String aFullyQualifiedSuiteName)
        Resolves a fully qualified suite name to the actual suite definition.
        Parameters:
        aFullyQualifiedSuiteName - the suite name
        Returns:
        the suite, or null if none was found
      • getAllSuites

        public java.util.Collection<SuiteDefinition> getAllSuites()
        Returns all suites in the test model.
        Returns:
        all suites
      • getVariantByName

        public VariantDefinition getVariantByName​(java.lang.String aFullyQualifiedVariantName)
        Resolves a fully qualified variant name to the actual variant definition.
        Parameters:
        aFullyQualifiedVariantName - the variant name
        Returns:
        the variant, or null if none was found
      • getForkByName

        public ForkDefinition getForkByName​(java.lang.String aFullyQualifiedForkName)
        Resolves a fully qualified fork name to the actual fork definition.
        Parameters:
        aFullyQualifiedForkName - the fork name
        Returns:
        the fork, or null if none was found
      • getAllForks

        public java.util.Collection<ForkDefinition> getAllForks()
        Returns all forks in the test model.
        Returns:
        all forks
      • getCallByName

        public CallDefinition getCallByName​(java.lang.String aFullyQualifiedCallName)
        Resolves a fully qualified call name to the actual call definition.
        Parameters:
        aFullyQualifiedCallName - the call name
        Returns:
        the call definition, or null if none was found
      • getAllCalls

        public java.util.Collection<CallDefinition> getAllCalls()
        Returns all calls in the test model.
        Returns:
        all calls
      • getTestByName

        public TestDefinition getTestByName​(java.lang.String aFullyQualifiedTestName)
        Resolves a fully qualified test name to the actual test definition.
        Parameters:
        aFullyQualifiedTestName - the call name
        Returns:
        the test definition, or null if none was found
      • getAllTests

        public java.util.Collection<TestDefinition> getAllTests()
        Returns all tests in the test model.
        Returns:
        all tests
      • getVariableOrConstantByName

        public VariableOrConstantEntity getVariableOrConstantByName​(java.lang.String aFullyQualifiedName)
        Resolves a fully qualified variable/constant name to the actual entity.
        Parameters:
        aFullyQualifiedName - the name to resolve
        Returns:
        the entity, or null if none was found
      • getVariableDefinitionsInPackages

        public java.util.TreeSet<VariableDefinition> getVariableDefinitionsInPackages()
        Iterates through the whole model and searches for variable definitions hosted in packages (global variables).
        Returns:
        a set of variable definitions (sorted by fully qualified name)
      • getConstantDefinitionsInPackages

        public java.util.TreeSet<ConstantDefinition> getConstantDefinitionsInPackages()
        Iterates through the whole model and searches for constant definitions.
        Returns:
        a set of constant definitions (sorted by fully qualified name)
      • loadTestModel

        public static TestModel loadTestModel​(TestResourceProvider aResourceProvider,
                                              boolean aSkipModelChecksFlag,
                                              boolean aPerformModelValidationFlag,
                                              java.lang.Class<? extends IntegrityDSLSetup> aSetupClass)
                                       throws ModelLoadException
        Loads a TestModel from a given TestResourceProvider. During this process, the files provided by the resource provider are parsed, the resulting models are linked and stored in the TestModel container.

        Errors, like unresolved symbols, will cause an exception. If a model is returned by this method, you can be sure that everything was linked fine and the model can be executed by the TestRunner.
        Parameters:
        aResourceProvider - The resource provider to use for loading the test scripts for the model.
        aSkipModelChecksFlag - if true, the test runner will skip the model consistency checks it would otherwise perform during the dry run
        aPerformModelValidationFlag - if true, the test runner will perform extensive model validation
        aSetupClass - the setup class to use for EMF setup and Guice initialization (if null, the default class is used)
        Returns:
        the test model ready for execution
        Throws:
        ModelLoadException - if any errors occur during loading (syntax errors or unresolvable references)
      • instantiateTestModel

        public static TestModel instantiateTestModel​(java.lang.ClassLoader aClassLoader,
                                                     java.lang.Class<? extends IntegrityDSLSetup> aSetupClass,
                                                     boolean aSkipModelChecksFlag)
        Instantiates a TestModel using the provided setup class.
        Parameters:
        aClassLoader - the class loader to use for Integrity stuff
        aSetupClass - the setup class to use for EMF setup and Guice initialization (if null, the default class is used)
        aSkipModelChecksFlag - if true, the test runner will skip the model consistency checks it would otherwise perform during the dry run
        Returns:
        the new (but still empty) test model
      • initializeTestRunner

        public TestRunner initializeTestRunner​(TestRunnerCallback aCallback,
                                               java.util.Map<java.lang.String,​java.lang.String> someParameterizedConstants,
                                               java.lang.String aResultLocale,
                                               java.lang.Integer aRemotingPort,
                                               java.lang.String aRemotingBindHost,
                                               java.lang.Long aRandomSeed,
                                               java.lang.String[] someCommandLineArguments)
                                        throws java.io.IOException
        Initializes a fresh test runner instance, based on this test model.
        Parameters:
        aCallback - the callback to use to report test results
        someParameterizedConstants - Maps fully qualified constant names (must be those with the "parameterized" keyword) to their desired value. This way, test execution can be parameterized from outside.
        aRemotingPort - the port on which the remoting server should listen, or null if remoting should be disabled
        aRemotingBindHost - the host name (or IP) to which the remoting server should bind
        aRandomSeed - the seed for the RandomNumberOperation (optional; randomly determined if not given).
        someCommandLineArguments - all command line arguments as given to the original Java programs' main routine (required for forking!)
        Returns:
        the initialized test runner instance
        Throws:
        java.io.IOException - if the remoting server startup fails
      • getInMemoryResourceProviders

        public java.util.List<InMemoryTestResourceProvider> getInMemoryResourceProviders()
                                                                                  throws java.io.IOException
        Returns a list of duplicates of all resource providers ever used to load test scripts into this TestModel. These duplicates are instances of InMemoryTestResourceProvider, meaning they contain the whole script data inside their instances, so nothing has to be loaded from the file system or other sources anymore. They also are transferable via Serialization, so they can be used to initialize Forks, which is their primary use!
        Returns:
        duplicates of the used resource providers
        Throws:
        java.io.IOException - in case of errors during duplication