Uploaded image for project: 'Spring Data REST'
  1. Spring Data REST
  2. DATAREST-968

TestRestTemplate doesn't take spring.data.rest.base-path in application.properties into account

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Invalid
    • Affects Version/s: 2.4.6 (Gosling SR6)
    • Fix Version/s: None
    • Component/s: Repositories
    • Labels:
    • Environment:
      any

      Description

      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");
        }
      }
      

        Attachments

          Activity

            People

            Assignee:
            olivergierke Oliver Drotbohm
            Reporter:
            Doogie Robert Rackl
            Last updater:
            Spring Issues Spring Issues
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: