Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestRestTemplate doesn't take spring.data.rest.base-path in application.properties into account [DATAREST-968] #1338

Closed
spring-projects-issues opened this issue Jan 3, 2017 · 3 comments

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Jan 3, 2017

Robert Rackl opened DATAREST-968 and commented

When you expose your Repositories via sprint-data-rest

AND

you change the REST base-path in application.properties

spring.data.rest.base-path=/base/path

WHEN you then use an autoinjected TestRestTemplate, then it is configured for localhost and the correct port, but not for that base path:

@RunWith(SpringRunner.class)
@ActiveProfiles("test")
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class RestEndpointTests {
  @Autowired
  TestRestTemplate client;

  @Test
  public void testUriMapping() {
    URI uri = client.getRestTemplate().getUriTemplateHandler().expand("/dummy");
    System.out.println("URI /dummy maps to "+uri);

    // will print  "http://localhost:<port>/dummy"  
    // INSTEAD OF  "http://localhost:<port>/base/path/dummy"   as configured in application.properties
  }
}

Expected behaviour

The autoinjected TestRestTemplate should automatically be configured with the base path from applicatin.properties

Workaround

For now, you must manually configure the base path of your TestRestClient, for example like this:

@Component
public class RepositoryRestConfigurer extends RepositoryRestConfigurerAdapter {
  @Override
  public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
    config.setBasePath("/base/path");
  }
}

Affects: 2.4.6 (Gosling SR6)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jan 3, 2017

Oliver Drotbohm commented

TestRestTemplate is not part of Spring Data REST but Spring Boot. Would you mind filing an issue there?

Loading

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jan 3, 2017

Robert Rackl commented

Ok I will move the issue. (Wow, that was a quick reply from you :-)
See spring-projects/spring-boot#7816

Loading

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jan 3, 2017

Oliver Drotbohm commented

You just caught me checking my inbox and it looked like a low hanging fruit to get off my desk 🙃

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants