FixtureLoader

class FixtureLoader(classLoader: ClassLoader = Thread.currentThread().contextClassLoader ?: FixtureLoader::class.java.classLoader, val root: String = "fixtures")(source)

Loads Fixtures from the consumer's own classpath, under a resource directory (root, fixtures by default). A name ending in .http is parsed as a .http file (Fixture.parse); any other name is a body-only fixture: status 200, the whole resource as the body and a Content-Type chosen by the extension (json ->application/json, xml ->application/xml, rss ->application/rss+xml, atom ->application/atom+xml, txt ->text/plain; charset=utf-8, html/htm ->text/html; charset=utf-8, anything else or none ->application/octet-stream; compared ASCII-lower-cased). The fixtures jar ships no fixture file; a consumer marks its .http files -text in its .gitattributes (a pattern over every .http file below a fixtures directory) so a checkout cannot rewrite their line endings.

Stable Core, source compatibility only. Stateless after construction and safe to share between threads. Equality is identity. toString() prints the root only. It logs nothing.

Parameters

classLoader

the loader whose resources hold the fixtures; by default the thread's context class loader, or this class's own loader when the thread has none.

root

the resource directory the names are relative to; fixtures by default.

Throws

if root is blank, absolute, holds a backslash or an empty, . or .. segment.

Constructors

Link copied to clipboard
constructor(classLoader: ClassLoader = Thread.currentThread().contextClassLoader ?: FixtureLoader::class.java.classLoader, root: String = "fixtures")

Properties

Link copied to clipboard

The resource directory the names are relative to.

Functions

Link copied to clipboard
fun load(name: String): Fixture

Loads the fixture at <root>/<name>.

Link copied to clipboard
open override fun toString(): String

A diagnostic string for logs: the root only. Its format is not part of the API and may change.