Class AbstractManager

java.lang.Object
dev.galasa.framework.spi.AbstractManager
All Implemented Interfaces:
IManager
Direct Known Subclasses:
AbstractGherkinManager, OeconsolZosConsoleManagerImpl

public abstract class AbstractManager extends Object implements IManager
An abstract manager which attempts to provide all the boilerplate code necessary to write a Manager in Galasa.
  • Constructor Details

    • AbstractManager

      public AbstractManager()
  • Method Details

    • registerAnnotatedField

      protected void registerAnnotatedField(Field field, Object value)
      Register an Manager annotated field, for automatic filling during fillAnnotatedFields()
      Parameters:
      field - The field to fill
      value - The
    • getAnnotatedField

      protected Object getAnnotatedField(Field field)
      Retrieve the generated object for an annotated field
      Parameters:
      field - field to retrieve
      Returns:
      the generated object or null if it has not been generated yet
    • findAnnotatedFields

      protected List<AnnotatedField> findAnnotatedFields(Class<? extends Annotation> managerAnnotation)

      Helper method to obtain a list of annotated fields this manager is interested in.

      This method will return a list of fields that has an annotation that is in turn annotated with the managerAnnotation

      Parameters:
      managerAnnotation - - The annotation that other annotations are annotated with.
      Returns:
      A list of fields the manager should be interested in
    • generateAnnotatedFields

      protected void generateAnnotatedFields(Class<? extends Annotation> managerAnnotation) throws ResourceUnavailableException, ManagerException
      Will call GenerateAnnotatedField methods in the parent class to generate instances for each of the Test Class fields The annotated methods in the parent class must:
      • be public
      • return the interface of the field annotation
      • have 2 parameters of Field and List
      Parameters:
      managerAnnotation - The Annotation for those annotated fields we are interested in
      Throws:
      ManagerException
      ResourceUnavailableException
    • findProvisionDependentAnnotatedFieldTags

      @NotNull protected @NotNull Set<String> findProvisionDependentAnnotatedFieldTags(@NotNull @NotNull Class<? extends Annotation> managerAnnotation, @NotNull @NotNull String attributeName)
      Used to locate the TAG names used in Annotations that indicate a dependency on a Manager. See ZosImageDependencyField as an example. Where ZosImageDependencyField is annotated on a Manager field annotation, zOS Manager will ask for the imageTag attribute value. zOS Manager will then provision as appropriate for each of the returned tags, which means the means the tester does not need to code a ZosImage for every image the test wants. For example CICSRegion(imageTag="a") will cause the zOS Manager to provision an image for tag "a" without the ZosImage(imageTag="a")
      Parameters:
      managerAnnotation - the dependency annotation
      attributeName - the name of the attribute on the annotation that returns a String only
      Returns:
      the tags found from the dependency annotations and the attribute, uppercased
    • extraBundles

      public List<String> extraBundles(@NotNull @NotNull IFramework framework) throws ManagerException
      Description copied from interface: IManager

      Gives the ability for the Manager to request additional bundles to be loaded dependent of CPS Properties. This can be used to load OSGi fragment bundles for implements of the TPI/SPI this Manager provides.

      For example, the zOS Manager provides the zOS Batch Manager TPI. This TPI can be provided via various means, the default being zOS/MF, which is implemented by the zOS Batch zOSMF Manager. The zOS Manager can look at the CPS to determine which "fragment" should used to implement the the TPI

      This method is called only once during the lifecycle and should not be dependent on what is in the Test Class

      Specified by:
      extraBundles in interface IManager
      Parameters:
      framework - Full initialised Framework
      Returns:
      null for no extra bundles, or a List contain the symbolic names of the bundles to load
      Throws:
      ManagerException
    • initialise

      public void initialise(@NotNull @NotNull IFramework framework, @NotNull @NotNull List<IManager> allManagers, @NotNull @NotNull List<IManager> activeManagers, @NotNull @NotNull GalasaTest galasaTest) throws ManagerException
      Description copied from interface: IManager

      Initialise the Manager, if required. The Manager should examine the testClass and see if this manager should participate in the Test Run lifecycle. If the Manager needs to take part, it should add itself to the activeManager. A Manager add itself only to the activeManagers.

      If a Manager is dependent on another Manager, it should look for implementers in allManager and call the youAreRequired method of the other Manager. If the required Manager has not yet been initialised, it should flag the youAreRequired call for when the Manager is initialised

      This will be the only time the testClass is passed to the Manager, so should be preserved

      Specified by:
      initialise in interface IManager
      Parameters:
      framework - A fully initialised Framework - preserve it for later use
      allManagers - All Managers found in OSGi
      activeManagers - The Manager should add itself to this list if it is to be activated. Do not add other managers.
      galasaTest - The Test class the framework will be running
      Throws:
      ManagerException - If there is a problem initialising the Manager
    • getFramework

      public IFramework getFramework()
      Returns:
      The Framework
    • getTestClass

      public Class<?> getTestClass()
      Returns:
      The Test Class
    • youAreRequired

      public void youAreRequired(@NotNull @NotNull List<IManager> allManagers, @NotNull @NotNull List<IManager> activeManagers, @NotNull @NotNull GalasaTest galasaTest) throws ManagerException
      Description copied from interface: IManager

      Called if another Manager requires this one. If this Manager has not been initialised yet, this call should be flagged until it the initialise method is called

      If the Manager has previously been intialised, but believed it wasn't required, then it should drive the initialise routines now.

      Specified by:
      youAreRequired in interface IManager
      Parameters:
      allManagers - All Managers found in OSGi
      activeManagers - The Manager should add itself to this list if it is to be activated. Do not add other managers.
      galasaTest - The Test class the framework will be running
      Throws:
      ManagerException
    • areYouProvisionalDependentOn

      public boolean areYouProvisionalDependentOn(@NotNull @NotNull IManager otherManager)
      Description copied from interface: IManager
      Is this Manager dependent on the other Manager. Basically, return true if you require the other Manager at all during the provision* lifecycle methods.
      Specified by:
      areYouProvisionalDependentOn in interface IManager
      Parameters:
      otherManager - The other Manager
      Returns:
      true this Manager is provisionally dependent on the other Manager
    • anyReasonTestClassShouldBeIgnored

      public String anyReasonTestClassShouldBeIgnored() throws ManagerException
      Description copied from interface: IManager

      Should the test class be run at all? Used to set the Test Class to Ignored. Examples of use would be if the CICS TS Version is too low for the functionality this Test is testing

      Specified by:
      anyReasonTestClassShouldBeIgnored in interface IManager
      Returns:
      - Return a descriptive text string for the reason the Test should be ignored
      Throws:
      ManagerException - - Just in case something goes wrong, eg CPS
    • provisionGenerate

      public void provisionGenerate() throws ManagerException, ResourceUnavailableException
      Description copied from interface: IManager

      Provision resource names, resource pools, settings etc, ready for building.

      No building should occur during this process. Only resolution activities should occur so all managers indicate they have all the resources they require before attempting to build anything. If a manager is unable to acquire any resource, it should throw ResourceUnavailableException and the Test Run will be put into Waiting state for a later retry, if in Automation

      Specified by:
      provisionGenerate in interface IManager
      Throws:
      ManagerException - If anything goes wrong
      ResourceUnavailableException - IF resources are unavailable for this run
    • provisionBuild

      public void provisionBuild() throws ManagerException, ResourceUnavailableException
      Description copied from interface: IManager

      Build everything that is needed for this Test Run. The Managers will be called in the order resolved by the areYouProvisionalDependentOn method.

      If this method fails, the Test Run will fail with Environmental Failure, unless ResourceUnavailableException is thrown, where it is assumed it is a temporary condition and the run will be put into Waiting state if in Automation.

      Specified by:
      provisionBuild in interface IManager
      Throws:
      ManagerException - If unable to build the environment
      ResourceUnavailableException
    • provisionStart

      public void provisionStart() throws ManagerException, ResourceUnavailableException
      Description copied from interface: IManager

      Start the provisioned environment. The Managers will be called in the order resolved by the areYouProvisionalDependentOn method.

      If this method fails, the Test Run will fail with Environmental Failure, unless ResourceUnavailableException is thrown, where it is assumed it is a temporary condition and the run will be put into Waiting state if in Automation.

      Specified by:
      provisionStart in interface IManager
      Throws:
      ManagerException - If unable to start the environment
      ResourceUnavailableException
    • startOfTestClass

      public void startOfTestClass() throws ManagerException
      Description copied from interface: IManager

      Called when we have instantiated the Test Class and ready to start running it.

      Specified by:
      startOfTestClass in interface IManager
      Throws:
      ManagerException - On the off chance something when wrong
    • fillAnnotatedFields

      public void fillAnnotatedFields(Object instanstiatedTestClass) throws ManagerException
      Description copied from interface: IManager
      Fill/refill the annotated fields that belong to this Manager. This is called before the start of every Test Method just incase the tester decided to overwrite the field.
      Specified by:
      fillAnnotatedFields in interface IManager
      Parameters:
      instanstiatedTestClass - The Instantiated Test class to fill
      Throws:
      ManagerException - On the off chance something when wrong
    • anyReasonTestMethodShouldBeIgnored

      public String anyReasonTestMethodShouldBeIgnored(@NotNull @NotNull GalasaMethod galasaMethod) throws ManagerException
      Description copied from interface: IManager

      Should the Test Method be run at all? Used to set the Test Method to Ignored. Examples of use would be if the CICS TS version is too low for the functionality this Test Method is testing

      Specified by:
      anyReasonTestMethodShouldBeIgnored in interface IManager
      Returns:
      - Return a descriptive text string for the reason the Test Method should be ignored
      Throws:
      ManagerException - - Just in case something goes wrong, eg CPS
    • startOfTestMethod

      public void startOfTestMethod(@NotNull @NotNull GalasaMethod galasaMethod) throws ManagerException
      Description copied from interface: IManager
      Called when we are about to start the Test Method.
      Specified by:
      startOfTestMethod in interface IManager
      Parameters:
      galasaMethod - The current executing method
      Throws:
      ManagerException - On the off chance something when wrong
    • endOfTestMethod

      public Result endOfTestMethod(@NotNull @NotNull GalasaMethod galasaMethod, @NotNull @NotNull Result currentResult, Throwable currentException) throws ManagerException
      Description copied from interface: IManager

      Called when the Test Method has finished

      If the Manager would like to override the result, it can return the result it wishes to be used for the record

      Specified by:
      endOfTestMethod in interface IManager
      Parameters:
      galasaMethod - The current test method
      currentResult - What the current result is, will not include what the other Managers wish it to be.
      currentException - What the current Exception is
      Returns:
      Override the test result, or null if ok
      Throws:
      ManagerException - If something went wrong
    • testMethodResult

      public void testMethodResult(@NotNull @NotNull String finalResult, Throwable finalException) throws ManagerException
      Description copied from interface: IManager

      Called once the Test Method result is resolved, can be used to emit the result to another server, for example

      Specified by:
      testMethodResult in interface IManager
      Parameters:
      finalResult - The final resolved result
      finalException - The Exception
      Throws:
      ManagerException - If something went wrong with recording the result
    • endOfTestClass

      public Result endOfTestClass(@NotNull @NotNull Result currentResult, Throwable currentException) throws ManagerException
      Description copied from interface: IManager

      Called when the Test Class has finished

      If the Manager would like to override the result, it can return the result it wishes to be used for the record

      Specified by:
      endOfTestClass in interface IManager
      Parameters:
      currentResult - What the current result is, will not include what the other Managers wish it to be.
      currentException - What the current Exception is
      Returns:
      Override the test result, or null if ok
      Throws:
      ManagerException - If something went wrong
    • testClassResult

      public void testClassResult(@NotNull @NotNull String finalResult, Throwable finalException) throws ManagerException
      Description copied from interface: IManager

      Called once the Test Class result is resolved, can be used to emit the result to another server, for example

      Specified by:
      testClassResult in interface IManager
      Parameters:
      finalResult - The final resolved result
      finalException - The Exception
      Throws:
      ManagerException - If something went wrong with recording the result
    • provisionStop

      public void provisionStop()
      Description copied from interface: IManager

      Stop the provisioned environment. Called in reverse provide dependent order.

      Called after recording the Test Class result as failure here should not affect the Test result

      Specified by:
      provisionStop in interface IManager
    • provisionDiscard

      public void provisionDiscard()
      Description copied from interface: IManager

      Discard the provisioned environment. Called in reverse provide dependent order.

      The Manager is free to clean up resources at this point, if it is reasonably quick so that it doesn't slow the throughput of Tests through the automation system and can be executed under the Testers credentials if running locally.

      Specified by:
      provisionDiscard in interface IManager
    • performFailureAnalysis

      public void performFailureAnalysis()
      Description copied from interface: IManager

      Can be used to perform Failure Analysis at this point and record the results in the RAS.

      Specified by:
      performFailureAnalysis in interface IManager
    • endOfTestRun

      public void endOfTestRun()
      Description copied from interface: IManager

      About to shutdown everything

      Specified by:
      endOfTestRun in interface IManager
    • addDependentManager

      protected <T> T addDependentManager(@NotNull @NotNull List<IManager> allManagers, @NotNull @NotNull List<IManager> activeManagers, @NotNull @NotNull GalasaTest galasaTest, @NotNull @NotNull Class<T> dependentInterface) throws ManagerException
      Helper method to find managers that implement an interface and tell them they are required
      Parameters:
      allManagers - All available managers
      activeManagers - The currently active managers
      dependentInterface - The interface the manager needs to implement
      Returns:
      Throws:
      ManagerException - If the required manager can't be added to the active list
    • nulled

      public static String nulled(String value)
      null a String is if it is empty TODO Needs to be moved to a more appropriate place as non managers use this, a stringutils maybe
      Parameters:
      value -
      Returns:
      a trimmed String or a null if emtpy or null
    • split

      public static List<String> split(String value)
    • defaultString

      public static String defaultString(String value, String defaultValue)
    • trim

      public static List<String> trim(String[] array)
    • shutdown

      public void shutdown()
      Description copied from interface: IManager
      Gives the Managers the opportunity to close everything down like http clients etc. Managers must not call other Managers in this method as they may have shutdown already. Calls to the Framework, CPS, RAS etc will be safe.
      Specified by:
      shutdown in interface IManager
    • doYouSupportSharedEnvironments

      public boolean doYouSupportSharedEnvironments()
      Description copied from interface: IManager
      The framework will check each manager during Shared Environment Build to see if they support shared environments. Those Managers that don't provision resources should return true. Those Managers provision resources that can't be reused in a shared environment should return false. AbsrtactManager will return false by default
      Specified by:
      doYouSupportSharedEnvironments in interface IManager
      Returns:
      true if you support shared environments, or false if not