}
@Test
public void testBuildResourceWithMock() throws Exception {
WADLGenerator generator = new WADLGenerator();
Mockery mockContext = new Mockery() {
{
setImposteriser(ClassImposteriser.INSTANCE);
}
};
final ClassMetadata metadata = mockContext.mock(ClassMetadata.class);
final MethodMetadata methodMeta = mockContext.mock(MethodMetadata.class);
final java.lang.reflect.Method method =
BasicResourceWithVoidReturn.class.getMethod("basicReturn");
mockContext.checking(new Expectations() {
{
oneOf(metadata).getResourceClass();
will(returnValue(BasicResourceWithVoidReturn.class));
oneOf(metadata).getPath();
will(returnValue("myResourcePath"));
oneOf(metadata).getResourceMethods();
will(returnValue(Collections.singletonList(methodMeta)));
oneOf(methodMeta).getHttpMethod();
will(returnValue(HttpMethod.GET));
oneOf(methodMeta).getFormalParameters();
will(returnValue(Collections.emptyList()));
oneOf(methodMeta).getProduces();
will(returnValue(Collections.emptySet()));
exactly(2).of(methodMeta).getReflectionMethod();
will(returnValue(method));
oneOf(methodMeta).getFormalParameters();
will(returnValue(null));
oneOf(metadata).getInjectableFields();
will(returnValue(null));
oneOf(metadata).getSubResourceMethods();
will(returnValue(null));
oneOf(metadata).getSubResourceLocators();
will(returnValue(null));
}
});
Resource actualRes = generator.buildResource(metadata);
assertNull(actualRes.getId());
assertEquals(MediaType.APPLICATION_FORM_URLENCODED, actualRes.getQueryType());
assertEquals(0, actualRes.getType().size());
assertEquals(0, actualRes.getDoc().size());
assertEquals("myResourcePath", actualRes.getPath());
assertEquals(0, actualRes.getParam().size());
/* method */
assertEquals(1, actualRes.getMethodOrResource().size());
Method m = ((Method)actualRes.getMethodOrResource().get(0));
assertEquals(HttpMethod.GET, m.getName());
assertNull(m.getId());
assertEquals(0, m.getDoc().size());
assertNull(m.getHref());
assertNull(m.getRequest());
assertEquals(1, m.getResponse().size());
List<Response> resps = m.getResponse();
assertEquals(Collections.singletonList(Long.valueOf(204)), resps.get(0).getStatus());
assertEquals(0, resps.get(0).getAny().size());
assertEquals(0, resps.get(0).getDoc().size());
assertEquals(0, resps.get(0).getOtherAttributes().size());
assertEquals(0, resps.get(0).getParam().size());
mockContext.assertIsSatisfied();
}