Create noop db store and test file

This commit is contained in:
Winston Li 2017-08-08 23:55:03 +01:00 committed by Michael Walker
parent 4e7636c94a
commit 34e558ab63
2 changed files with 108 additions and 0 deletions

View file

@ -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<String> 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) {
}
}

View file

@ -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)
);
}
}