liquibase.sdk.resource.MockResourceAccessor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of liquibase-core Show documentation
Show all versions of liquibase-core Show documentation
Liquibase is a tool for managing and executing database changes.
The newest version!
package liquibase.sdk.resource;
import liquibase.resource.AbstractResourceAccessor;
import liquibase.resource.Resource;
import java.io.IOException;
import java.util.*;
public class MockResourceAccessor extends AbstractResourceAccessor {
private final SortedMap contentByFileName;
public MockResourceAccessor() {
this(new HashMap<>());
}
public MockResourceAccessor(Map contentByFileName) {
this.contentByFileName = new TreeMap<>(contentByFileName);
}
@Override
public void close() throws Exception {
}
@Override
public List getAll(String path) throws IOException {
path = path.replace("\\", "/");
String content = contentByFileName.get(path);
List returnSet = new ArrayList<>();
if (content != null) {
returnSet.add(new MockResource(path, content));
}
if (returnSet.isEmpty()) {
return null;
}
return returnSet;
}
@Override
public List search(String path, boolean recursive) throws IOException {
path = path.replace("\\", "/");
List returnList = new ArrayList<>();
for (String file : contentByFileName.keySet()) {
if (file.startsWith(path)) {
if (!recursive && (file.split("/").length) - (path.split("/").length) > 2) {
continue;
}
returnList.add(new MockResource(file, contentByFileName.get(file)));
}
}
return returnList;
}
@Override
public List describeLocations() {
return Collections.singletonList("MockResouceAccessor.java");
}
public void setContent(String fileName, String content) {
this.contentByFileName.put(fileName, content);
}
}