bundle = client.getConventionBundle(ExternalId.of("Test", "Bar"));
assertNull(bundle);
}
public void testGetByBundle() {
ConventionBundle bundle = createBundle();
final ConventionBundleSource underlying = Mockito.mock(ConventionBundleSource.class);
Mockito.when(underlying.getConventionBundle(ExternalId.of("Test", "Foo").toBundle())).thenReturn(bundle);
Mockito.when(underlying.getConventionBundle(ExternalId.of("Test", "Bar").toBundle())).thenReturn(null);
final DataConventionBundleSourceResource server = new DataConventionBundleSourceResource(underlying);
final ConventionBundleSource client = new RemoteConventionBundleSource(URI.create("http://localhost/")) {
@Override
protected UniformInterface accessRemote(final URI uri) {
assertTrue(uri.getPath().startsWith("/bundle"));
assertTrue(uri.getQuery().startsWith("id="));
final UniformInterface builder = Mockito.mock(UniformInterface.class);
Mockito.when(builder.get(ConventionBundle.class)).thenAnswer(new Answer<ConventionBundle>() {
@Override
public ConventionBundle answer(final InvocationOnMock invocation) throws Throwable {
try {
return OpenGammaFudgeContext.getInstance().fromFudgeMsg(ConventionBundle.class, (FudgeMsg) server.getByBundle(Arrays.asList(uri.getQuery().substring(3))).getEntity());
} catch (final WebApplicationException e) {
assertEquals(e.getResponse().getStatus(), 404);
throw new UniformInterfaceException404NotFound(new ClientResponse(404, null, null, null), false);
}
}
});
return builder;
}
};
bundle = client.getConventionBundle(ExternalId.of("Test", "Foo").toBundle());
assertNotNull(bundle);
assertEquals(bundle.getUniqueId(), UniqueId.of("Mock", "0"));
bundle = client.getConventionBundle(ExternalId.of("Test", "Bar").toBundle());
assertNull(bundle);
}