Package com.atlassian.bamboo.utils
Class BambooTestUtils
- java.lang.Object
-
- com.atlassian.bamboo.utils.BambooTestUtils
-
public class BambooTestUtils extends Object
This class provides a collection of utility methods for use in the unit tests
-
-
Field Summary
Fields Modifier and Type Field Description static StringNLConvenience constant for new linestatic StringSEPConvenice constant for file separatorsstatic booleanUSE_FAST_LOGINWhether fast login via URL parameters should be used by tests.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static voidassertFormError(ErrorCollection errorCollection, String field, String errorMessage)static voidcreateActionContext()static <T> Set<T>createSet(T... items)Varargs to set.static PathcreateTempDirectory(String prefix)static voiddestroyActionContext()static FilegetFileFromResourceDirectory(Class<?> ref, String fileName)static FilegetFileFromResourceDirectory(Object object, String fileName)static InputStreamgetInputStream(@NotNull String resourceName, @NotNull Object object)Obtains the given fileName as an input stream.static InputStreamgetInputStream(String resourceName)Obtains the given fileName as an input stream.static InputStreamgetInputStream(String resourceName, Class<?> clazz)Obtains the given fileName as an input stream.static org.codehaus.jackson.JsonNodegetJsonResource(String resourceName, Class<?> clazz)static ReadergetReader(String resourceName)static PathgetShortTempDir()static StringgetSubstitutedResource(@NotNull String resourceName, @NotNull Object object, @NotNull Properties subs)static FilegetTestDataFile(String fileName)Get file from test data directory.static StringreadFileFromResource(Class<?> clazz, String fileName)static StringreadFileFromResource(Object object, String fileName)Deprecated.since 6.3 usereadFileFromResource(Class, String)insteadstatic <T extends Serializable>
TserializeAndDeserialize(T object)static @NotNull StringtoVariableUsage(@NotNull String variableName)Converts variable name to a variable usage string using the default namespace "bamboo".static StringtoVariableUsage(@NotNull String variableNamespace, @NotNull String variableName)Converts variable name to a variable usage string using the provided namespace.
-
-
-
Field Detail
-
NL
public static final String NL
Convenience constant for new line
-
SEP
public static final String SEP
Convenice constant for file separators
-
USE_FAST_LOGIN
public static final boolean USE_FAST_LOGIN
Whether fast login via URL parameters should be used by tests. If this isfalse, tests should fall back to standard login.The value is
falseby default, unless a system property is specified.
-
-
Method Detail
-
getShortTempDir
public static Path getShortTempDir()
-
createTempDirectory
public static Path createTempDirectory(String prefix) throws IOException
- Throws:
IOException
-
getSubstitutedResource
public static String getSubstitutedResource(@NotNull @NotNull String resourceName, @NotNull @NotNull Object object, @NotNull @NotNull Properties subs)
-
getInputStream
public static InputStream getInputStream(String resourceName)
Obtains the given fileName as an input stream. Assumes the file is located in the test source tree,- Parameters:
resourceName- The file to read as a stream- Returns:
- The stream
-
getInputStream
public static InputStream getInputStream(@NotNull @NotNull String resourceName, @NotNull @NotNull Object object)
Obtains the given fileName as an input stream. Assumes the file is located in the test source tree,- Parameters:
resourceName- The file to read as a streamobject- This object's class is used to load resource- Returns:
- The stream
-
getInputStream
public static InputStream getInputStream(String resourceName, Class<?> clazz)
Obtains the given fileName as an input stream. Assumes the file is located in the test source tree,- Parameters:
resourceName- The resource nameclazz- The class to be used to load resource- Returns:
- The stream
-
getJsonResource
public static org.codehaus.jackson.JsonNode getJsonResource(String resourceName, Class<?> clazz) throws IOException
- Throws:
IOException
-
assertFormError
public static void assertFormError(ErrorCollection errorCollection, String field, String errorMessage)
-
getFileFromResourceDirectory
public static File getFileFromResourceDirectory(Object object, String fileName)
-
getFileFromResourceDirectory
public static File getFileFromResourceDirectory(Class<?> ref, String fileName)
-
getTestDataFile
public static File getTestDataFile(String fileName)
Get file from test data directory. Test data directory is an external resource (separate source repository), its location is provided to test by system property.
-
readFileFromResource
@Deprecated public static String readFileFromResource(Object object, String fileName) throws IOException
Deprecated.since 6.3 usereadFileFromResource(Class, String)instead- Throws:
IOException
-
readFileFromResource
public static String readFileFromResource(Class<?> clazz, String fileName) throws IOException
- Throws:
IOException
-
createActionContext
public static void createActionContext()
-
destroyActionContext
public static void destroyActionContext()
-
serializeAndDeserialize
public static <T extends Serializable> T serializeAndDeserialize(@NotNull T object) throws IOException, ClassNotFoundException
- Throws:
IOExceptionClassNotFoundException
-
toVariableUsage
@NotNull public static @NotNull String toVariableUsage(@NotNull @NotNull String variableName)
Converts variable name to a variable usage string using the default namespace "bamboo". For example, variable 'docker.image' will be converted to '${bamboo.docker.image}'.- Parameters:
variableName- variable name- Returns:
- variable usage string
-
toVariableUsage
public static String toVariableUsage(@NotNull @NotNull String variableNamespace, @NotNull @NotNull String variableName)
Converts variable name to a variable usage string using the provided namespace. For example, variable 'docker.image' in namespace 'bamboo' will be converted to '${bamboo.docker.image}'.- Parameters:
variableNamespace- variable namespacevariableName- variable name- Returns:
- variable usage string
-
createSet
public static <T> Set<T> createSet(T... items)
Varargs to set.
-
-