From 34e558ab63941b11bb67a44fe2724f435306b67f Mon Sep 17 00:00:00 2001 From: Winston Li Date: Tue, 8 Aug 2017 23:55:03 +0100 Subject: [PATCH] Create noop db store and test file --- .../bridge/db/noop/NoopDbStore.java | 66 +++++++++++++++++++ .../bridge/resource/UrlResourceCacheTest.java | 42 ++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/db/noop/NoopDbStore.java create mode 100644 services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/bridge/resource/UrlResourceCacheTest.java diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/db/noop/NoopDbStore.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/db/noop/NoopDbStore.java new file mode 100644 index 0000000000..9519bf0fe4 --- /dev/null +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/db/noop/NoopDbStore.java @@ -0,0 +1,66 @@ +package uk.ac.ic.wlgitbridge.bridge.db.noop; + +import uk.ac.ic.wlgitbridge.bridge.db.DBStore; +import uk.ac.ic.wlgitbridge.bridge.db.ProjectState; + +import java.sql.Timestamp; +import java.util.List; + +public class NoopDbStore implements DBStore { + + @Override + public int getNumProjects() { + return 0; + } + + @Override + public List getProjectNames() { + return null; + } + + @Override + public void setLatestVersionForProject(String project, int versionID) { + + } + + @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) { + return null; + } + + @Override + public String getOldestUnswappedProject() { + return null; + } + + @Override + public int getNumUnswappedProjects() { + return 0; + } + + @Override + public ProjectState getProjectState(String projectName) { + return null; + } + + @Override + public void setLastAccessedTime(String projectName, Timestamp time) { + + } + +} diff --git a/services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/bridge/resource/UrlResourceCacheTest.java b/services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/bridge/resource/UrlResourceCacheTest.java new file mode 100644 index 0000000000..e180a07731 --- /dev/null +++ b/services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/bridge/resource/UrlResourceCacheTest.java @@ -0,0 +1,42 @@ +package uk.ac.ic.wlgitbridge.bridge.resource; + +import org.junit.Test; +import uk.ac.ic.wlgitbridge.bridge.db.noop.NoopDbStore; +import uk.ac.ic.wlgitbridge.io.http.ning.NingHttpClientFacade; + +import java.util.Collections; +import java.util.Optional; + +import static org.mockito.Mockito.mock; + +public class UrlResourceCacheTest { + + private static String PROJ = "proj"; + + private static String URL = "http://localhost/file.jpg"; + + private static String NEW_PATH = "file1.jpg"; + + private final NingHttpClientFacade http = mock(NingHttpClientFacade.class); + + private final UrlResourceCache cache + = new UrlResourceCache(new NoopDbStore(), http); + + @Test + public void getThrowsSizeLimitWhenContentLengthTooBig() throws Exception { + when(http.get(any(), any())).thenAnswer(invoc -> { + Object[] args = invoc.getArguments(); + //noinspection unchecked + ((FunctionT< + HttpResponseHeaders, Boolean, SizeLimitExceededException + >) args[1]).apply(withContentLength(2)); + return new byte[0]; + }); + + cache.get( + PROJ, URL, NEW_PATH, + Collections.emptyMap(), Collections.emptyMap(), + Optional.of(2L) + ); + } +}