diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/EnvironmentController.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/EnvironmentController.java index ac520218..318b63d5 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/EnvironmentController.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/EnvironmentController.java @@ -56,7 +56,7 @@ public class EnvironmentController { return labelled(name, profiles, defaultLabel); } - @RequestMapping("/{name}/{profiles}/{label}") + @RequestMapping("/{name}/{profiles}/{label:.*}") public Environment labelled(@PathVariable String name, @PathVariable String profiles, @PathVariable String label) { Environment environment = encryption.decrypt(repository.findOne(name, profiles, diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/EnvironmentControllerIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/EnvironmentControllerIntegrationTests.java new file mode 100644 index 00000000..02295c83 --- /dev/null +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/EnvironmentControllerIntegrationTests.java @@ -0,0 +1,67 @@ +/* + * Copyright 2014-2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.config.server; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.springframework.cloud.config.environment.Environment; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; + +/** + * @author Dave Syer + * + */ +public class EnvironmentControllerIntegrationTests { + + private MockMvc mvc; + private EnvironmentRepository repository = Mockito.mock(EnvironmentRepository.class);; + + @Before + public void init() { + mvc = MockMvcBuilders.standaloneSetup( + new EnvironmentController(repository, new EncryptionController())) + .build(); + } + + @Test + public void environmentNoLabel() throws Exception { + Mockito.when(repository.findOne("foo", "default", "master")).thenReturn( + new Environment("foo", "default")); + mvc.perform(MockMvcRequestBuilders.get("/foo/default")).andExpect( + MockMvcResultMatchers.status().isOk()); + } + + @Test + public void environmentWithLabel() throws Exception { + Mockito.when(repository.findOne("foo", "default", "awesome")).thenReturn( + new Environment("foo", "default")); + mvc.perform(MockMvcRequestBuilders.get("/foo/default/awesome")).andExpect( + MockMvcResultMatchers.status().isOk()); + } + @Test + public void environmentWithLabelContainingPeriod() throws Exception { + Mockito.when(repository.findOne("foo", "default", "1.0.0")).thenReturn( + new Environment("foo", "default")); + mvc.perform(MockMvcRequestBuilders.get("/foo/default/1.0.0")).andExpect( + MockMvcResultMatchers.status().isOk()); + } + +}