@Test public void fromMethodCallWithPathVariableAndMultiValueRequestParams() { UriComponents uriComponents = fromMethodCall( on(ControllerWithMethods.class).methodWithMultiValueRequestParams("1", Arrays.asList(3, 7), 5)).build(); assertThat(uriComponents.getPath(), is("/something/1/foo")); MultiValueMap<String, String> queryParams = uriComponents.getQueryParams(); assertThat(queryParams.get("limit"), contains("5")); assertThat(queryParams.get("items"), containsInAnyOrder("3", "7")); }
@Test // SPR-16710 public void fromMethodCallWithModelAndViewReturnType() { UriComponents uriComponents = fromMethodCall( on(BookingControllerWithModelAndView.class).getBooking(21L)).buildAndExpand(42); assertEquals("http://localhost/hotels/42/bookings/21", uriComponents.encode().toUri().toString()); }
@Test(expected = IllegalStateException.class) // SPR-16710 public void fromMethodCallWithStringReturnType() { UriComponents uriComponents = fromMethodCall( on(BookingControllerWithString.class).getBooking(21L)).buildAndExpand(42); assertEquals("http://localhost/hotels/42/bookings/21", uriComponents.encode().toUri().toString()); }
@Test // SPR-16710 public void fromMethodCallWithObjectReturnType() { UriComponents uriComponents = fromMethodCall( on(BookingControllerWithObject.class).getBooking(21L)).buildAndExpand(42); assertEquals("http://localhost/hotels/42/bookings/21", uriComponents.encode().toUri().toString()); }
@Test public void fromMethodCallWithPathVariableAndRequestParams() { UriComponents uriComponents = fromMethodCall( on(ControllerWithMethods.class).methodForNextPage("1", 10, 5)).build(); assertThat(uriComponents.getPath(), is("/something/1/foo")); MultiValueMap<String, String> queryParams = uriComponents.getQueryParams(); assertThat(queryParams.get("limit"), contains("5")); assertThat(queryParams.get("offset"), contains("10")); }
@Test public void fromMethodCallWithCustomBaseUrlViaStaticCall() { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("http://example.org:9090/base"); UriComponents uriComponents = fromMethodCall(builder, on(ControllerWithMethods.class).myMethod(null)).build(); assertEquals("http://example.org:9090/base/something/else", uriComponents.toString()); assertEquals("http://example.org:9090/base", builder.toUriString()); }
@Test public void fromMethodCallPlain() { UriComponents uriComponents = fromMethodCall(on(ControllerWithMethods.class).myMethod(null)).build(); assertThat(uriComponents.toUriString(), startsWith("http://localhost")); assertThat(uriComponents.toUriString(), endsWith("/something/else")); }
@Test public void fromMethodCallWithCustomBaseUrlViaInstance() { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("http://example.org:9090/base"); MvcUriComponentsBuilder mvcBuilder = relativeTo(builder); UriComponents result = mvcBuilder.withMethodCall(on(ControllerWithMethods.class).myMethod(null)).build(); assertEquals("http://example.org:9090/base/something/else", result.toString()); assertEquals("http://example.org:9090/base", builder.toUriString()); }
@Test public void fromMethodCallOnSubclass() { UriComponents uriComponents = fromMethodCall(on(ExtendedController.class).myMethod(null)).build(); assertThat(uriComponents.toUriString(), startsWith("http://localhost")); assertThat(uriComponents.toUriString(), endsWith("/extended/else")); }
@Test public void fromMethodCallWithPathVariable() { UriComponents uriComponents = fromMethodCall( on(ControllerWithMethods.class).methodWithPathVariable("1")).build(); assertThat(uriComponents.toUriString(), startsWith("http://localhost")); assertThat(uriComponents.toUriString(), endsWith("/something/1/foo")); }
@Test public void fromMethodCallWithTypeLevelUriVars() { UriComponents uriComponents = fromMethodCall( on(PersonsAddressesController.class).getAddressesForCountry("DE")).buildAndExpand(15); assertThat(uriComponents.toUriString(), endsWith("/people/15/addresses/DE")); }
@Test public void methodCall() throws Exception { this.mockMvc.perform(get("/")).andExpect(handler().methodCall(on(SimpleController.class).handle())); }
@Test public void fromMethodWithPrefix() { initWebApplicationContext(PathPrefixWebConfig.class); this.request.setServerName("example.org"); this.request.setServerPort(9999); this.request.setContextPath("/base"); assertEquals("http://example.org:9999/base/api/people/123/addresses/DE", fromMethodCall(on(PersonsAddressesController.class).getAddressesForCountry("DE")) .buildAndExpand("123").toString()); }
/** * Gets the summary for an issue in a repository */ @RequestMapping(value = "configuration/{configuration:.*}/issue/{key}", method = RequestMethod.GET) public Resource<OntrackSVNIssueInfo> issueInfo(@PathVariable String configuration, @PathVariable String key) { return Resource.of( svnInfoService.getIssueInfo(configuration, key), uri(on(getClass()).issueInfo(configuration, key)) ).withView(Build.class); }
/** * Gets the configuration descriptors */ @RequestMapping(value = "configurations/descriptors", method = RequestMethod.GET) public Resources<ConfigurationDescriptor> getConfigurationsDescriptors() { return Resources.of( configurationService.getConfigurationDescriptors(), uri(on(getClass()).getConfigurationsDescriptors()) ); }
@Override @RequestMapping(value = "", method = RequestMethod.GET) public Resource<ExtensionFeatureDescription> getDescription() { return Resource.of( feature.getFeatureDescription(), uri(MvcUriComponentsBuilder.on(getClass()).getDescription()) ) .with("configurations", uri(on(getClass()).getConfigurations()), securityService.isGlobalFunctionGranted(GlobalSettings.class)) ; }
@Override @RequestMapping(value = "", method = RequestMethod.GET) public Resource<ExtensionFeatureDescription> getDescription() { return Resource.of( feature.getFeatureDescription(), uri(MvcUriComponentsBuilder.on(getClass()).getDescription()) ) .with("configurations", uri(on(getClass()).getConfigurationList()), securityService.isGlobalFunctionGranted(GlobalSettings.class)) ; }
@Override @RequestMapping(value = "", method = RequestMethod.GET) public Resource<ExtensionFeatureDescription> getDescription() { return Resource.of( feature.getFeatureDescription(), uri(MvcUriComponentsBuilder.on(getClass()).getDescription()) ) .with("configurations", uri(on(getClass()).getConfigurations()), securityService.isGlobalFunctionGranted(GlobalSettings.class)) ; }
@Override @RequestMapping(value = "", method = RequestMethod.GET) public Resource<ExtensionFeatureDescription> getDescription() { return Resource.of( feature.getFeatureDescription(), uri(MvcUriComponentsBuilder.on(getClass()).getDescription()) ) .with("configurations", uri(on(getClass()).getConfigurations()), securityService.isGlobalFunctionGranted(GlobalSettings.class)) ; }
@Override public List<Link> links(GitLabConfiguration configuration, ResourceContext resourceContext) { boolean globalSettingsGranted = securityService.isGlobalFunctionGranted(GlobalSettings.class); return resourceContext.links() .self(on(GitLabController.class).getConfiguration(configuration.getName())) .link(Link.UPDATE, on(GitLabController.class).updateConfigurationForm(configuration.getName()), globalSettingsGranted) .link(Link.DELETE, on(GitLabController.class).deleteConfiguration(configuration.getName()), globalSettingsGranted) // OK .build(); } }