Merge branch '3.1.x'

This commit is contained in:
Ryan Baxter
2022-05-12 10:48:00 -04:00
2 changed files with 29 additions and 2 deletions

View File

@@ -103,13 +103,13 @@ public class EnvironmentController {
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)
public Environment defaultLabel(@PathVariable String name, @PathVariable String profiles) {
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)
public Environment defaultLabelIncludeOrigin(@PathVariable String name, @PathVariable String profiles) {
return getEnvironment(name, profiles, null, true);

View File

@@ -21,6 +21,8 @@ import java.util.HashMap;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.BeforeEach;
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.springframework.beans.factory.annotation.Autowired;
@@ -40,8 +42,10 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
/**
* @author Dave Syer
* @author Roy Clarkson
@@ -87,6 +91,29 @@ class EnvironmentControllerIntegrationTests {
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
public void propertiesNoLabel() throws Exception {
when(this.repository.findOne("foo", "default", null, false)).thenReturn(this.environment);