InMemoryProtocolResolver class final
A ProtocolResolver that serves prefix:path locations from a map of
paths to text held in memory.
It is for tests that need config files or templates without touching
the disk, and for content an app builds in code. Paths are normalized
(./, .., a leading /), so memory:config/a and
memory:/config/./a are the same file. An unknown path gives a
resource that does not exist.
// Config files for a test, without files on disk.
final loader = DefaultResourceLoader(
protocolResolvers: [
InMemoryProtocolResolver('memory:', {
'config/application.properties': 'app.name=demo',
}),
],
);
final environment = StandardEnvironment();
ConfigDataEnvironment(
environment,
resourceLoader: loader,
defaultLocations: const ['optional:memory:config/'],
).processAndApplySync();
Spring has no direct equivalent; tests usually use ByteArrayResource,
MockPropertySource or @TestPropertySource instead.
- Implemented types
Constructors
-
InMemoryProtocolResolver(String prefix, Map<
String, String> files) -
Creates a resolver serving
files(path to content, copied) underprefix.
Properties
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
put(
String path, String content) → void -
Adds the file
pathwithcontent, or replaces its content. -
resolve(
String location, ResourceLoader resourceLoader) → Resource? -
The resource for
location, ornullwhen this resolver does not handle it, so the next resolver (or the built-in rules) is tried.resourceLoaderis the loader asking, for resolvers that delegate.override -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited