mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-31 12:51:35 +02:00
Large refactor of parts into distinct components / interfaces
This commit is contained in:
committed by
Michael Mazour
parent
5b810b64ba
commit
692b979098
@@ -0,0 +1,58 @@
|
||||
package uk.ac.ic.wlgitbridge.bridge;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import uk.ac.ic.wlgitbridge.bridge.db.DBStore;
|
||||
import uk.ac.ic.wlgitbridge.bridge.lock.ProjectLock;
|
||||
import uk.ac.ic.wlgitbridge.bridge.repo.RepoStore;
|
||||
import uk.ac.ic.wlgitbridge.bridge.resource.ResourceCache;
|
||||
import uk.ac.ic.wlgitbridge.bridge.snapshot.SnapshotAPI;
|
||||
import uk.ac.ic.wlgitbridge.bridge.swap.SwapJob;
|
||||
import uk.ac.ic.wlgitbridge.bridge.swap.SwapStore;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Created by winston on 20/08/2016.
|
||||
*/
|
||||
public class BridgeTest {
|
||||
|
||||
private Bridge bridge;
|
||||
|
||||
private ProjectLock lock;
|
||||
private RepoStore repoStore;
|
||||
private DBStore dbStore;
|
||||
private SwapStore swapStore;
|
||||
private SnapshotAPI snapshotAPI;
|
||||
private ResourceCache resourceCache;
|
||||
private SwapJob swapJob;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
lock = mock(ProjectLock.class);
|
||||
repoStore = mock(RepoStore.class);
|
||||
dbStore = mock(DBStore.class);
|
||||
swapStore = mock(SwapStore.class);
|
||||
snapshotAPI = mock(SnapshotAPI.class);
|
||||
swapJob = mock(SwapJob.class);
|
||||
bridge = new Bridge(
|
||||
lock,
|
||||
repoStore,
|
||||
dbStore,
|
||||
swapStore,
|
||||
snapshotAPI,
|
||||
resourceCache,
|
||||
swapJob
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shutdownStopsSwapJob() {
|
||||
bridge.startSwapJob(1000);
|
||||
bridge.doShutdown();
|
||||
verify(swapJob).start(1000);
|
||||
verify(swapJob).stop();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,8 +9,10 @@ import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.mockserver.client.server.MockServerClient;
|
||||
import org.mockserver.junit.MockServerRule;
|
||||
import uk.ac.ic.wlgitbridge.bridge.db.DBStore;
|
||||
import uk.ac.ic.wlgitbridge.bridge.resource.ResourceCache;
|
||||
import uk.ac.ic.wlgitbridge.bridge.resource.UrlResourceCache;
|
||||
import uk.ac.ic.wlgitbridge.data.filestore.RawFile;
|
||||
import uk.ac.ic.wlgitbridge.data.model.db.PersistentStore;
|
||||
import uk.ac.ic.wlgitbridge.git.exception.GitUserException;
|
||||
import uk.ac.ic.wlgitbridge.git.util.RepositoryObjectTreeWalker;
|
||||
|
||||
@@ -50,23 +52,23 @@ public class ResourceFetcherTest {
|
||||
);
|
||||
|
||||
final Mockery context = new Mockery();
|
||||
final PersistentStore persistentStore = context.mock(PersistentStore.class);
|
||||
final DBStore dbStore = context.mock(DBStore.class);
|
||||
context.checking(new Expectations() {{
|
||||
// It should fetch the file once it finds it is missing.
|
||||
oneOf(persistentStore).getPathForURLInProject(testProjectName, testUrl);
|
||||
oneOf(dbStore).getPathForURLInProject(testProjectName, testUrl);
|
||||
will(returnValue(oldTestPath));
|
||||
|
||||
// It should update the URL index store once it has fetched; at present, it does not actually change the stored path.
|
||||
oneOf(persistentStore).addURLIndexForProject(testProjectName, testUrl, oldTestPath);
|
||||
oneOf(dbStore).addURLIndexForProject(testProjectName, testUrl, oldTestPath);
|
||||
}});
|
||||
|
||||
ResourceFetcher resourceFetcher = new ResourceFetcher(persistentStore);
|
||||
ResourceCache resources = new UrlResourceCache(dbStore);
|
||||
TemporaryFolder repositoryFolder = new TemporaryFolder();
|
||||
repositoryFolder.create();
|
||||
Repository repository = new FileRepositoryBuilder().setWorkTree(repositoryFolder.getRoot()).build();
|
||||
Map<String, RawFile> fileTable = new RepositoryObjectTreeWalker(repository).getDirectoryContents().getFileTable();
|
||||
Map<String, byte[]> fetchedUrls = new HashMap<String, byte[]>();
|
||||
resourceFetcher.get(testProjectName, testUrl, newTestPath, fileTable, fetchedUrls);
|
||||
resources.get(testProjectName, testUrl, newTestPath, fileTable, fetchedUrls);
|
||||
|
||||
// We don't bother caching in this case, at present.
|
||||
assertEquals(0, fetchedUrls.size());
|
||||
|
||||
Reference in New Issue
Block a user