final Resource.Builder resourceBuilder = Resource.builder();
resourceBuilder.addMethod("GET").handledBy(MyInflector.class);
resourceBuilder.addMethod("POST").handledBy(MyInflector.class);
final Resource res = resourceBuilder.build();
ResourceMethod getMethod;
ResourceMethod postMethod;
if (res.getResourceMethods().get(0).getHttpMethod().equals("GET")) {
getMethod = res.getResourceMethods().get(0);
postMethod = res.getResourceMethods().get(1);
} else {
getMethod = res.getResourceMethods().get(1);
postMethod = res.getResourceMethods().get(0);
}
statBuilder.addExecution("/new/elefant", getMethod, 10, 5, 8, 8);
statBuilder.addExecution("/new/elefant", getMethod, 20, 12, 18, 10);
statBuilder.addExecution("/new/elefant", postMethod, 30, 2, 28, 4);
final MonitoringStatisticsImpl stat = statBuilder.build();
final Iterator<Map.Entry<String, ResourceStatistics>> it = stat.getUriStatistics().entrySet().iterator();
check(it, "/hello", 2);
check(it, "/hello/world", 1);
check(it, "/new/elefant", 2);
check(it, "/prog", 1);
check(it, "/test-resource", 1);
check(it, "/test-resource/child", 3);
check(it, "/test-resource/prog-child", 1);
final Map<ResourceMethod, ResourceMethodStatistics> resourceMethodStatistics
= stat.getUriStatistics().get("/new/elefant").getResourceMethodStatistics();
for (ResourceMethodStatistics methodStatistics : resourceMethodStatistics.values()) {
final ResourceMethod method = methodStatistics.getResourceMethod();
final ExecutionStatistics st = methodStatistics.getMethodStatistics();
if (method.getHttpMethod().equals("GET")) {
Assert.assertEquals(20, st.getLastStartTime().getTime());
} else if (method.getHttpMethod().equals("POST")) {
Assert.assertEquals(30, st.getLastStartTime().getTime());
} else {
Assert.fail();
}
}