Update EnvironmentController @GetMapping - Fixes gh-2083 (#2089)
Co-authored-by: Vincent Bostoen <vincent.bostoen@orange.com>
This commit is contained in:
@@ -104,13 +104,13 @@ public class EnvironmentController {
|
|||||||
this.acceptEmpty = acceptEmpty;
|
this.acceptEmpty = acceptEmpty;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(path = "/{name}/{profiles:(?!.*\\b(?:ya?ml|properties|json)\\b).*}",
|
@GetMapping(path = "/{name}/{profiles:(?!.*\\b\\.(?:ya?ml|properties|json)\\b).*}",
|
||||||
produces = MediaType.APPLICATION_JSON_VALUE)
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
public Environment defaultLabel(@PathVariable String name, @PathVariable String profiles) {
|
public Environment defaultLabel(@PathVariable String name, @PathVariable String profiles) {
|
||||||
return getEnvironment(name, profiles, null, false);
|
return getEnvironment(name, profiles, null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(path = "/{name}/{profiles:(?!.*\\b(?:ya?ml|properties|json)\\b).*}",
|
@GetMapping(path = "/{name}/{profiles:(?!.*\\b\\.(?:ya?ml|properties|json)\\b).*}",
|
||||||
produces = EnvironmentMediaType.V2_JSON)
|
produces = EnvironmentMediaType.V2_JSON)
|
||||||
public Environment defaultLabelIncludeOrigin(@PathVariable String name, @PathVariable String profiles) {
|
public Environment defaultLabelIncludeOrigin(@PathVariable String name, @PathVariable String profiles) {
|
||||||
return getEnvironment(name, profiles, null, true);
|
return getEnvironment(name, profiles, null, true);
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ import java.util.HashMap;
|
|||||||
import org.hamcrest.Matchers;
|
import org.hamcrest.Matchers;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.ValueSource;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -40,8 +42,10 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|||||||
import org.springframework.web.context.WebApplicationContext;
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
|
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.verifyNoInteractions;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
* @author Roy Clarkson
|
* @author Roy Clarkson
|
||||||
@@ -87,6 +91,29 @@ class EnvironmentControllerIntegrationTests {
|
|||||||
verify(this.repository).findOne("foo", "dev-db", null, false);
|
verify(this.repository).findOne("foo", "dev-db", null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@ValueSource(strings = {"yml", "yaml", "json", "properties"})
|
||||||
|
public void profileContainingExtensionKeyword(String extensionKeyword) throws Exception {
|
||||||
|
String profiles = "dev-" + extensionKeyword;
|
||||||
|
Environment dashEnvironment = new Environment("foo", profiles);
|
||||||
|
dashEnvironment.add(new PropertySource("foo", new HashMap<>()));
|
||||||
|
when(this.repository.findOne("foo", profiles, null, false)).thenReturn(dashEnvironment);
|
||||||
|
this.mvc.perform(MockMvcRequestBuilders.get("/foo/" + profiles))
|
||||||
|
.andExpect(MockMvcResultMatchers.status().isOk());
|
||||||
|
verify(this.repository).findOne("foo", profiles, null, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@ValueSource(strings = {"yml", "yaml", "json", "properties"})
|
||||||
|
public void profileHavingAnExtension(String extensionKeyword) throws Exception {
|
||||||
|
String profiles = "dev." + extensionKeyword;
|
||||||
|
Environment dashEnvironment = new Environment("foo", profiles);
|
||||||
|
dashEnvironment.add(new PropertySource("foo", new HashMap<>()));
|
||||||
|
this.mvc.perform(MockMvcRequestBuilders.get("/foo/" + profiles))
|
||||||
|
.andExpect(MockMvcResultMatchers.status().isNotFound());
|
||||||
|
verifyNoInteractions(this.repository);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void propertiesNoLabel() throws Exception {
|
public void propertiesNoLabel() throws Exception {
|
||||||
when(this.repository.findOne("foo", "default", null, false)).thenReturn(this.environment);
|
when(this.repository.findOne("foo", "default", null, false)).thenReturn(this.environment);
|
||||||
|
|||||||
Reference in New Issue
Block a user