mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-29 10:23:46 -05:00
mock the persistent store with jmock
This commit is contained in:
parent
e2574ab163
commit
318e11deeb
1 changed files with 17 additions and 34 deletions
|
@ -7,6 +7,9 @@ import static org.mockserver.model.HttpResponse.response;
|
||||||
|
|
||||||
import org.eclipse.jgit.lib.*;
|
import org.eclipse.jgit.lib.*;
|
||||||
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
|
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
|
||||||
|
import org.jmock.Expectations;
|
||||||
|
import org.jmock.Mockery;
|
||||||
|
import org.hamcrest.TypeSafeMatcher;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.TemporaryFolder;
|
import org.junit.rules.TemporaryFolder;
|
||||||
|
@ -33,6 +36,8 @@ public class ResourceFetcherTest {
|
||||||
public void fetchesFilesThatAreMissingFromUrlStoreCache() throws IOException {
|
public void fetchesFilesThatAreMissingFromUrlStoreCache() throws IOException {
|
||||||
final String testProjectName = "123abc";
|
final String testProjectName = "123abc";
|
||||||
final String testUrl = "http://localhost:" + mockServerRule.getHttpPort() + "/123abc";
|
final String testUrl = "http://localhost:" + mockServerRule.getHttpPort() + "/123abc";
|
||||||
|
final String oldTestPath = "testPath";
|
||||||
|
final String newTestPath = "missingPath";
|
||||||
|
|
||||||
mockServerClient.when(
|
mockServerClient.when(
|
||||||
request()
|
request()
|
||||||
|
@ -45,47 +50,25 @@ public class ResourceFetcherTest {
|
||||||
.withBody("content")
|
.withBody("content")
|
||||||
);
|
);
|
||||||
|
|
||||||
final PersistentStore persistentStore = new PersistentStore() {
|
final Mockery context = new Mockery();
|
||||||
@Override
|
final PersistentStore persistentStore = context.mock(PersistentStore.class);
|
||||||
public List<String> getProjectNames() {
|
context.checking(new Expectations() {{
|
||||||
return null;
|
// It should fetch the file once it finds it is missing.
|
||||||
}
|
oneOf(persistentStore).getPathForURLInProject(testProjectName, testUrl);
|
||||||
|
will(returnValue(oldTestPath));
|
||||||
|
|
||||||
@Override
|
// It should update the URL index store once it has fetched; at present, it does not actually change the stored path.
|
||||||
public void setLatestVersionForProject(String project, int versionID) {
|
oneOf(persistentStore).addURLIndexForProject(testProjectName, testUrl, oldTestPath);
|
||||||
|
}});
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getLatestVersionForProject(String project) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addURLIndexForProject(String projectName, String url, String path) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void deleteFilesForProject(String project, String... files) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPathForURLInProject(String projectName, String url) {
|
|
||||||
assertEquals(testProjectName, projectName);
|
|
||||||
assertEquals(testUrl, url);
|
|
||||||
return "missingPath";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ResourceFetcher resourceFetcher = new ResourceFetcher(persistentStore);
|
ResourceFetcher resourceFetcher = new ResourceFetcher(persistentStore);
|
||||||
TemporaryFolder repositoryFolder = new TemporaryFolder();
|
TemporaryFolder repositoryFolder = new TemporaryFolder();
|
||||||
repositoryFolder.create();
|
repositoryFolder.create();
|
||||||
Repository repository = new FileRepositoryBuilder().setWorkTree(repositoryFolder.getRoot()).build();
|
Repository repository = new FileRepositoryBuilder().setWorkTree(repositoryFolder.getRoot()).build();
|
||||||
Map<String, byte[]> fetchedUrls = new HashMap<String, byte[]>();
|
Map<String, byte[]> fetchedUrls = new HashMap<String, byte[]>();
|
||||||
resourceFetcher.get(testProjectName, testUrl, "testPath", repository, fetchedUrls);
|
resourceFetcher.get(testProjectName, testUrl, newTestPath, repository, fetchedUrls);
|
||||||
// public RawFile get(String projectName, String url, String newPath, Repository repository, Map<String, byte[]> fetchedUrls) throws IOException {
|
|
||||||
|
|
||||||
|
// We don't bother caching in this case, at present.
|
||||||
|
assertEquals(0, fetchedUrls.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue