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) under prefix.

Properties

hashCode → int
The hash code for this object.
no setterinherited
prefix → String
The prefix it handles, colon included, such as memory:.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
put(String path, String content) → void
Adds the file path with content, or replaces its content.
resolve(String location, ResourceLoader resourceLoader) → Resource?
The resource for location, or null when this resolver does not handle it, so the next resolver (or the built-in rules) is tried. resourceLoader is 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