public void testGet() {
final InMemoryTempTargetRepository underlying = new InMemoryTempTargetRepository();
final UniqueId uid = underlying.locateOrStore(new MockTempTarget("Test"));
assertEquals(uid, UniqueId.of("TmpMem", "1"));
final DataTempTargetRepositoryResource server = new DataTempTargetRepositoryResource(underlying);
final TempTargetRepository client = new RemoteTempTargetRepository(URI.create("http://localhost/")) {
@Override
protected UniformInterface accessRemote(final URI uri) {
assertTrue(uri.getPath().startsWith("/target/"));
final UniformInterface builder = Mockito.mock(UniformInterface.class);
Mockito.when(builder.get(FudgeMsg.class)).thenAnswer(new Answer<FudgeMsg>() {
@Override
public FudgeMsg answer(final InvocationOnMock invocation) throws Throwable {
try {
return (FudgeMsg) server.get(uri.getPath().substring(8)).getEntity();
} catch (final WebApplicationException e) {
assertEquals(e.getResponse().getStatus(), 404);
throw new UniformInterfaceException404NotFound(new ClientResponse(404, null, null, null), false);
}
}
});
return builder;
}
};
assertNull(client.get(UniqueId.of("Invalid", "Foo")));
assertEquals(client.get(uid), new MockTempTarget("Test"));
}