@Test public void testComputeId() throws Exception { String id = "getStudentsByIdForApi"; Method mockMethod = mock(Method.class); when(mockMethod.getVerb()).thenReturn(Method.NAME_HTTP_GET); Resource mockResource = mock(Resource.class); when(mockResource.getPath()).thenReturn("students/{id}"); Resource mockAncestorResource = mock(Resource.class); when(mockAncestorResource.getPath()).thenReturn("api/v1"); Stack<Resource> resources = new Stack<Resource>(); resources.push(mockAncestorResource); String computedId = WadlHelper.computeId(mockMethod, mockResource, null, null, resources); assertEquals(id, computedId); }
public static final String computeId(final Method method, final Resource resource, final Resources resources, final Application app, final Stack<Resource> ancestors) { final List<String> steps = reverse(toSteps(resource, ancestors)); final StringBuilder sb = new StringBuilder(); sb.append(method.getVerb().toLowerCase()); boolean first = true; boolean seenParam = false; String paramName = null; for (final String step : steps) { if (isTemplateParam(step)) { seenParam = true; paramName = parseTemplateParam(step); } else if (!isVersion(step)) { if (first) { first = false; } else { sb.append("For"); } sb.append(titleCase(step)); if (seenParam) { sb.append("By" + titleCase(paramName)); seenParam = false; } } } return sb.toString(); }
WadlHelper { public static final String computeId(final Method method, final Resource resource, final Resources resources, final Application app, final Stack<Resource> ancestors) { final List<String> steps = reverse(toSteps(resource, ancestors)); final StringBuilder sb = new StringBuilder(); sb.append(method.getVerb().toLowerCase()); boolean first = true; boolean seenParam = false; String paramName = null; for (final String step : steps) { if (isTemplateParam(step)) { seenParam = true; paramName = parseTemplateParam(step); } else if (!isVersion(step)) { if (first) { first = false; } else { sb.append("For"); } sb.append(titleCase(step)); if (seenParam) { sb.append("By" + titleCase(paramName)); seenParam = false; } } } return sb.toString(); } }
WadlHelper { public static final String computeId(final Method method, final Resource resource, final Resources resources, final Application app, final Stack<Resource> ancestors) { final List<String> steps = reverse(toSteps(resource, ancestors)); final StringBuilder sb = new StringBuilder(); sb.append(method.getVerb().toLowerCase()); boolean first = true; boolean seenParam = false; String paramName = null; for (final String step : steps) { if (isTemplateParam(step)) { seenParam = true; paramName = parseTemplateParam(step); } else if (!isVersion(step)) { if (first) { first = false; } else { sb.append("For"); } sb.append(titleCase(step)); if (seenParam) { sb.append("By" + titleCase(paramName)); seenParam = false; } } } return sb.toString(); } private  WadlHelper(); }
WadlHelper { public static final String computeId(final Method method, final Resource resource, final Resources resources, final Application app, final Stack<Resource> ancestors) { final List<String> steps = reverse(toSteps(resource, ancestors)); final StringBuilder sb = new StringBuilder(); sb.append(method.getVerb().toLowerCase()); boolean first = true; boolean seenParam = false; String paramName = null; for (final String step : steps) { if (isTemplateParam(step)) { seenParam = true; paramName = parseTemplateParam(step); } else if (!isVersion(step)) { if (first) { first = false; } else { sb.append("For"); } sb.append(titleCase(step)); if (seenParam) { sb.append("By" + titleCase(paramName)); seenParam = false; } } } return sb.toString(); } private  WadlHelper(); static List<Param> getRequestParams(final Method method); static final String computeId(final Method method, final Resource resource, final Resources resources,
            final Application app, final Stack<Resource> ancestors); static final String titleCase(final String text); static final List<T> reverse(final List<T> strings); static final boolean isVersion(final String step); static final String parseTemplateParam(final String step); static final List<String> toSteps(final Resource resource, final Stack<Resource> ancestors); static final boolean isTemplateParam(final String step); }
WadlHelper { public static final String computeId(final Method method, final Resource resource, final Resources resources, final Application app, final Stack<Resource> ancestors) { final List<String> steps = reverse(toSteps(resource, ancestors)); final StringBuilder sb = new StringBuilder(); sb.append(method.getVerb().toLowerCase()); boolean first = true; boolean seenParam = false; String paramName = null; for (final String step : steps) { if (isTemplateParam(step)) { seenParam = true; paramName = parseTemplateParam(step); } else if (!isVersion(step)) { if (first) { first = false; } else { sb.append("For"); } sb.append(titleCase(step)); if (seenParam) { sb.append("By" + titleCase(paramName)); seenParam = false; } } } return sb.toString(); } private  WadlHelper(); static List<Param> getRequestParams(final Method method); static final String computeId(final Method method, final Resource resource, final Resources resources,
            final Application app, final Stack<Resource> ancestors); static final String titleCase(final String text); static final List<T> reverse(final List<T> strings); static final boolean isVersion(final String step); static final String parseTemplateParam(final String step); static final List<String> toSteps(final Resource resource, final Stack<Resource> ancestors); static final boolean isTemplateParam(final String step);  }