DefaultUriFactory implements UriFactory { @Override public String buildUrl(RestAction<?> action) { String prefix = buildPrefix(action); String path = buildPath(action); String matrixString = buildMatrixString(action); String queryString = buildQueryString(action, Type.QUERY); StringBuilder url = new StringBuilder(prefix).append(path).append(matrixString); if (!queryString.isEmpty()) { url.append('?').append(queryString); } return url.toString(); } @Inject  DefaultUriFactory(
            @GlobalQueryParams RestParameterBindings globalQueryParams,
            @RestApplicationPath Provider<String> applicationPathProvider); @Override String buildUrl(RestAction<?> action); @Override String buildQueryString(RestAction<?> action, Type type);  }
@Test public void absoluteUrlShouldNotChange() { RestAction<Void> action = new UnsecuredRestAction(GET, ABSOLUTE_PATH); String url = factory.buildUrl(action); assertThat(url).startsWith(ABSOLUTE_PATH); }
@Test public void relativeUrlShouldBePrependedByApplicationPath() { RestAction<Void> action = new UnsecuredRestAction(GET, RELATIVE_PATH); String url = factory.buildUrl(action); assertThat(url).startsWith(APPLICATION_PATH + RELATIVE_PATH); }
@Test public void globalQueryParamsShouldBeSetForCorrespondingHttpMethod() { RestAction<Void> action = new SecuredRestAction(GET, RELATIVE_PATH); String url = factory.buildUrl(action); String expectedUrl = String.format("?%s=%s&%s=%s", KEY_1, VALUE_1, KEY_2, VALUE_2); assertThat(url).endsWith(expectedUrl); }
@Test public void allActionQueryParamsShouldBeSet() { ExposedRestAction<Void> action = new SecuredRestAction(GET, RELATIVE_PATH); action.addParam(new QueryParameter(ACTION_KEY_1, VALUE_1, null, urlUtils)); action.addParam(new QueryParameter(ACTION_KEY_2, VALUE_2, null, urlUtils)); String url = factory.buildUrl(action); String expectedUrl = String.format("?%s=%s&%s=%s&%s=%s&%s=%s", KEY_1, VALUE_1, KEY_2, VALUE_2, ACTION_KEY_1, VALUE_1, ACTION_KEY_2, VALUE_2); assertThat(url).endsWith(expectedUrl); }
@Test public void allMatrixParamsShouldBeSet() { ExposedRestAction<Void> action = new SecuredRestAction(GET, RELATIVE_PATH); action.addParam(new MatrixParameter(ACTION_KEY_1, VALUE_1, null, urlUtils)); action.addParam(new MatrixParameter(ACTION_KEY_2, VALUE_2, null, urlUtils)); String url = factory.buildUrl(action); String expectedUrl = String.format(";%s=%s;%s=%s?%s=%s&%s=%s", ACTION_KEY_1, VALUE_1, ACTION_KEY_2, VALUE_2, KEY_1, VALUE_1, KEY_2, VALUE_2); assertThat(url).endsWith(expectedUrl); }