01 - Dealing with resources and converters

The Resource type

When is a resource used?

A Resource is the data that will be used as input for engine components, and are produced by it. The resources loaded are of course of the type "Resource", but also are the targets, the result, the configuration files, and the intermediate created file, such as the temporary files created by the CONVERT instruction.

Let's have a look at the following instructions:

LOAD test.sah AS sahi-script.file

CONVERT sahi-script.file TO script.sahi(script) AS test.script

  • sahi-script.file is a resource of the type FileResource (the LOAD and the DEFINE instructions always create FileResources).

  • test.bundle is a resource of the type SahiSuiteResource, after the use of the converter's category "script".

How to define a resource?

  • All resources need to be annotated @TAResource("NAME")

    • NAME is the name given to the resource in the TA instruction.

  • All resources must implement the interface Resource<RESOURCE>

    • RESOURCE is the concerned resource itself.

For example, the resource SahiSuiteResource which was spoken of above is defined as:

@TAResource("script.sahi")

public class SahiSuiteResource implements Resource<SahiSuiteResource>

Note: Several useful generic resources can be found in org.squashtest.ta.plugin.commons.resources.

The Converter type

When is a converter used?

A ResourceConverter accepts a Resource of some type and returns the same Resource casted in another type. If needed, it can also rate its relevance regarding the input.

Let's have a look at the following instruction:

CONVERT sahi-script.file TO script.sahi(script) AS test.script

How to define a converter?

  • All the converters need to be annotated @TAResourceConverter("NAME")

    • NAME is the name given to the converter in the TA instruction.

    • All converters must implement the interface ResourceConverter<INPUT, OUTPUT>

    • INPUT is the resource the converter takes,

    • OUTPUT is the resource the converter returns.

For example, the converter FileToSahiConverter which was spoken of above is defined as:

@TAResourceConverter("script")

public class FileToSahiConverter implements ResourceConverter<FileResource, SahiSuiteResource>