You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2018/04/20 02:44:59 UTC
[incubator-servicecomb-java-chassis] 02/02: SCB-453 add IT to test
reading config from application.yml/application.properties
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git
commit 737870a125af6178041dbc76548269e90c1781c7
Author: yaohaishi <ya...@huawei.com>
AuthorDate: Thu Apr 19 21:51:41 2018 +0800
SCB-453 add IT to test reading config from application.yml/application.properties
---
.../jaxrs/tests/JaxrsSpringIntegrationTest.java | 31 +++++++++++++++++
.../src/test/resources/application-dev.yaml} | 9 ++---
.../src/test/resources/application-prod.yaml} | 9 ++---
.../src/test/resources/application.properties | 4 ++-
.../src/test/resources/application.yaml} | 5 ++-
.../src/test/resources/application.yml} | 14 +++++---
.../src/test/resources/microservice.yaml} | 10 +++---
.../zuul/tracing/SpringCloudZuulTracingTest.java | 39 +++++++++++++++++++++-
.../cloud/zuul/tracing/TracedController.java | 31 +++++++++++++++++
...application.properties => application-dev.yaml} | 9 ++---
...pplication.properties => application-prod.yaml} | 9 ++---
.../src/test/resources/application.properties | 4 +++
.../src/test/resources/application.yaml | 5 +++
.../{application.properties => application.yml} | 14 +++++---
.../src/test/resources/microservice.yaml | 4 +++
15 files changed, 166 insertions(+), 31 deletions(-)
diff --git a/integration-tests/spring-jaxrs-tests/src/test/java/org/apache/servicecomb/demo/jaxrs/tests/JaxrsSpringIntegrationTest.java b/integration-tests/spring-jaxrs-tests/src/test/java/org/apache/servicecomb/demo/jaxrs/tests/JaxrsSpringIntegrationTest.java
index f38df6c..8bb37bd 100644
--- a/integration-tests/spring-jaxrs-tests/src/test/java/org/apache/servicecomb/demo/jaxrs/tests/JaxrsSpringIntegrationTest.java
+++ b/integration-tests/spring-jaxrs-tests/src/test/java/org/apache/servicecomb/demo/jaxrs/tests/JaxrsSpringIntegrationTest.java
@@ -17,12 +17,43 @@
package org.apache.servicecomb.demo.jaxrs.tests;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
+import com.netflix.config.DynamicProperty;
+
@RunWith(SpringRunner.class)
@SpringBootTest(classes = JaxrsSpringMain.class)
public class JaxrsSpringIntegrationTest extends JaxrsIntegrationTestBase {
+ @BeforeClass
+ public static void setUp() {
+ System.setProperty("property.test5", "from_system_property");
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ System.clearProperty("property.test5");
+ }
+ @Test
+ public void testGetConfigFromSpringBoot() {
+ DynamicProperty dynamicProperty = DynamicProperty.getInstance("property.test0");
+ assertEquals("from_properties", dynamicProperty.getString());
+ dynamicProperty = DynamicProperty.getInstance("property.test1");
+ assertEquals("from_yml", dynamicProperty.getString());
+ dynamicProperty = DynamicProperty.getInstance("property.test2");
+ assertEquals("from_yaml_from_yml", dynamicProperty.getString());
+ dynamicProperty = DynamicProperty.getInstance("property.test3");
+ assertEquals("from_yaml_dev_from_properties", dynamicProperty.getString());
+ dynamicProperty = DynamicProperty.getInstance("property.test4");
+ assertEquals("from_microservice_yaml", dynamicProperty.getString());
+ dynamicProperty = DynamicProperty.getInstance("property.test5");
+ assertEquals("from_system_property", dynamicProperty.getString());
+ }
}
diff --git a/integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties b/integration-tests/spring-jaxrs-tests/src/test/resources/application-dev.yaml
similarity index 74%
copy from integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties
copy to integration-tests/spring-jaxrs-tests/src/test/resources/application-dev.yaml
index 4289b89..5a6e140 100644
--- a/integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties
+++ b/integration-tests/spring-jaxrs-tests/src/test/resources/application-dev.yaml
@@ -1,4 +1,4 @@
-#
+# ---------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
@@ -6,13 +6,14 @@
# (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
+# 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.
-#
+# ---------------------------------------------------------------------------
-spring.main.web-environment=true
+property:
+ test3: from_yaml_dev_${property.test0}
diff --git a/integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties b/integration-tests/spring-jaxrs-tests/src/test/resources/application-prod.yaml
similarity index 73%
copy from integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties
copy to integration-tests/spring-jaxrs-tests/src/test/resources/application-prod.yaml
index 4289b89..2fcc199 100644
--- a/integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties
+++ b/integration-tests/spring-jaxrs-tests/src/test/resources/application-prod.yaml
@@ -1,4 +1,4 @@
-#
+# ---------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
@@ -6,13 +6,14 @@
# (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
+# 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.
-#
+# ---------------------------------------------------------------------------
-spring.main.web-environment=true
+property:
+ test3: from_yaml_prod_${property.test0}
diff --git a/integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties b/integration-tests/spring-jaxrs-tests/src/test/resources/application.properties
similarity index 89%
copy from integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties
copy to integration-tests/spring-jaxrs-tests/src/test/resources/application.properties
index 4289b89..39d0201 100644
--- a/integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties
+++ b/integration-tests/spring-jaxrs-tests/src/test/resources/application.properties
@@ -15,4 +15,6 @@
# limitations under the License.
#
-spring.main.web-environment=true
+property.test0=from_properties
+property.test4=from_properties
+property.test5=from_properties
diff --git a/integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties b/integration-tests/spring-jaxrs-tests/src/test/resources/application.yaml
similarity index 90%
copy from integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties
copy to integration-tests/spring-jaxrs-tests/src/test/resources/application.yaml
index 4289b89..ebe87f6 100644
--- a/integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties
+++ b/integration-tests/spring-jaxrs-tests/src/test/resources/application.yaml
@@ -15,4 +15,7 @@
# limitations under the License.
#
-spring.main.web-environment=true
+property:
+ test0: from_yaml
+ test1: from_yaml
+ test2: from_yaml_${property.test1}
diff --git a/integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties b/integration-tests/spring-jaxrs-tests/src/test/resources/application.yml
similarity index 71%
copy from integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties
copy to integration-tests/spring-jaxrs-tests/src/test/resources/application.yml
index 4289b89..a350c10 100644
--- a/integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties
+++ b/integration-tests/spring-jaxrs-tests/src/test/resources/application.yml
@@ -1,4 +1,4 @@
-#
+# ---------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
@@ -6,13 +6,19 @@
# (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
+# 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.
-#
+# ---------------------------------------------------------------------------
+
+property:
+ test0: from_yml
+ test1: from_yml
-spring.main.web-environment=true
+spring:
+ profiles:
+ active: dev
diff --git a/integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties b/integration-tests/spring-jaxrs-tests/src/test/resources/microservice.yaml
similarity index 72%
copy from integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties
copy to integration-tests/spring-jaxrs-tests/src/test/resources/microservice.yaml
index 4289b89..49937a2 100644
--- a/integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties
+++ b/integration-tests/spring-jaxrs-tests/src/test/resources/microservice.yaml
@@ -1,4 +1,4 @@
-#
+# ---------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
@@ -6,13 +6,15 @@
# (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
+# 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.
-#
+# ---------------------------------------------------------------------------
-spring.main.web-environment=true
+property:
+ test4: from_microservice_yaml
+ test5: from_microservice_yaml
diff --git a/integration-tests/spring-zuul-tracing-tests/src/test/java/org/apache/servicecomb/spring/cloud/zuul/tracing/SpringCloudZuulTracingTest.java b/integration-tests/spring-zuul-tracing-tests/src/test/java/org/apache/servicecomb/spring/cloud/zuul/tracing/SpringCloudZuulTracingTest.java
index 3859e12..06dabf5 100644
--- a/integration-tests/spring-zuul-tracing-tests/src/test/java/org/apache/servicecomb/spring/cloud/zuul/tracing/SpringCloudZuulTracingTest.java
+++ b/integration-tests/spring-zuul-tracing-tests/src/test/java/org/apache/servicecomb/spring/cloud/zuul/tracing/SpringCloudZuulTracingTest.java
@@ -19,6 +19,7 @@ package org.apache.servicecomb.spring.cloud.zuul.tracing;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
@@ -29,6 +30,8 @@ import java.util.concurrent.TimeUnit;
import org.apache.servicecomb.tests.tracing.TracingTestBase;
import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -37,6 +40,8 @@ import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
+import com.netflix.config.DynamicProperty;
+
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TracedZuulMain.class, webEnvironment = RANDOM_PORT)
public class SpringCloudZuulTracingTest extends TracingTestBase {
@@ -44,8 +49,18 @@ public class SpringCloudZuulTracingTest extends TracingTestBase {
@Autowired
private TestRestTemplate testRestTemplate;
+ @BeforeClass
+ public static void beforeClass() {
+ System.setProperty("property.test5", "from_system_property");
+ }
+
+ @AfterClass
+ public static void afterClass() {
+ System.clearProperty("property.test5");
+ }
+
@After
- public void tearDown() throws Exception {
+ public void tearDown() {
appender.clear();
}
@@ -77,4 +92,26 @@ public class SpringCloudZuulTracingTest extends TracingTestBase {
assertThatSpansReceivedByZipkin(tracingMessages, "/dummy/rest/oops", "500", "/oops", "590");
}
+
+ @Test
+ public void testGetConfigFromSpringBoot() {
+ DynamicProperty dynamicProperty = DynamicProperty.getInstance("property.test0");
+ assertEquals("from_properties", dynamicProperty.getString());
+ dynamicProperty = DynamicProperty.getInstance("property.test1");
+ assertEquals("from_yml", dynamicProperty.getString());
+ dynamicProperty = DynamicProperty.getInstance("property.test2");
+ assertEquals("from_yaml_from_yml", dynamicProperty.getString());
+ dynamicProperty = DynamicProperty.getInstance("property.test3");
+ assertEquals("from_yaml_dev_from_properties", dynamicProperty.getString());
+ dynamicProperty = DynamicProperty.getInstance("property.test4");
+ assertEquals("from_microservice_yaml", dynamicProperty.getString());
+ dynamicProperty = DynamicProperty.getInstance("property.test5");
+ assertEquals("from_system_property", dynamicProperty.getString());
+
+ ResponseEntity<String> responseEntity = testRestTemplate.getForEntity("/dummy/rest/testProperty", String.class);
+
+ assertThat(responseEntity.getStatusCode(), is(OK));
+ assertThat(responseEntity.getBody(),
+ is("from_properties-from_yml-from_yaml_from_yml-from_yaml_dev_from_properties-from_microservice_yaml-from_system_property"));
+ }
}
diff --git a/integration-tests/spring-zuul-tracing-tests/src/test/java/org/apache/servicecomb/spring/cloud/zuul/tracing/TracedController.java b/integration-tests/spring-zuul-tracing-tests/src/test/java/org/apache/servicecomb/spring/cloud/zuul/tracing/TracedController.java
index d1c2ed9..0463594 100644
--- a/integration-tests/spring-zuul-tracing-tests/src/test/java/org/apache/servicecomb/spring/cloud/zuul/tracing/TracedController.java
+++ b/integration-tests/spring-zuul-tracing-tests/src/test/java/org/apache/servicecomb/spring/cloud/zuul/tracing/TracedController.java
@@ -25,6 +25,7 @@ import java.lang.invoke.MethodHandles;
import org.apache.servicecomb.provider.rest.common.RestSchema;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
@RestSchema(schemaId = "tracedController")
@@ -32,6 +33,24 @@ import org.springframework.web.bind.annotation.RequestMapping;
public class TracedController {
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+ @Value("${property.test0}")
+ private String propertyTest0;
+
+ @Value("${property.test1}")
+ private String propertyTest1;
+
+ @Value("${property.test2}")
+ private String propertyTest2;
+
+ @Value("${property.test3}")
+ private String propertyTest3;
+
+ @Value("${property.test4}")
+ private String propertyTest4;
+
+ @Value("${property.test5}")
+ private String propertyTest5;
+
@RequestMapping(value = "/blah", method = GET, produces = TEXT_PLAIN_VALUE)
public String blah() {
logger.info("in /blah");
@@ -45,4 +64,16 @@ public class TracedController {
throw new IllegalStateException("oops");
}
+
+ @RequestMapping(value = "/testProperty", method = GET, produces = TEXT_PLAIN_VALUE)
+ public String testProperty() {
+ logger.info("in /testProperty");
+
+ return propertyTest0
+ + "-" + propertyTest1
+ + "-" + propertyTest2
+ + "-" + propertyTest3
+ + "-" + propertyTest4
+ + "-" + propertyTest5;
+ }
}
diff --git a/integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties b/integration-tests/spring-zuul-tracing-tests/src/test/resources/application-dev.yaml
similarity index 74%
copy from integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties
copy to integration-tests/spring-zuul-tracing-tests/src/test/resources/application-dev.yaml
index 4289b89..5a6e140 100644
--- a/integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties
+++ b/integration-tests/spring-zuul-tracing-tests/src/test/resources/application-dev.yaml
@@ -1,4 +1,4 @@
-#
+# ---------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
@@ -6,13 +6,14 @@
# (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
+# 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.
-#
+# ---------------------------------------------------------------------------
-spring.main.web-environment=true
+property:
+ test3: from_yaml_dev_${property.test0}
diff --git a/integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties b/integration-tests/spring-zuul-tracing-tests/src/test/resources/application-prod.yaml
similarity index 73%
copy from integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties
copy to integration-tests/spring-zuul-tracing-tests/src/test/resources/application-prod.yaml
index 4289b89..2fcc199 100644
--- a/integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties
+++ b/integration-tests/spring-zuul-tracing-tests/src/test/resources/application-prod.yaml
@@ -1,4 +1,4 @@
-#
+# ---------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
@@ -6,13 +6,14 @@
# (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
+# 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.
-#
+# ---------------------------------------------------------------------------
-spring.main.web-environment=true
+property:
+ test3: from_yaml_prod_${property.test0}
diff --git a/integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties b/integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties
index 4289b89..9c2440b 100644
--- a/integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties
+++ b/integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties
@@ -16,3 +16,7 @@
#
spring.main.web-environment=true
+
+property.test0=from_properties
+property.test4=from_properties
+property.test5=from_properties
\ No newline at end of file
diff --git a/integration-tests/spring-zuul-tracing-tests/src/test/resources/application.yaml b/integration-tests/spring-zuul-tracing-tests/src/test/resources/application.yaml
index 3bd3923..1d4dc74 100644
--- a/integration-tests/spring-zuul-tracing-tests/src/test/resources/application.yaml
+++ b/integration-tests/spring-zuul-tracing-tests/src/test/resources/application.yaml
@@ -27,3 +27,8 @@ ribbon:
server:
port: 0
+
+property:
+ test0: from_yaml
+ test1: from_yaml
+ test2: from_yaml_${property.test1}
\ No newline at end of file
diff --git a/integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties b/integration-tests/spring-zuul-tracing-tests/src/test/resources/application.yml
similarity index 71%
copy from integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties
copy to integration-tests/spring-zuul-tracing-tests/src/test/resources/application.yml
index 4289b89..a350c10 100644
--- a/integration-tests/spring-zuul-tracing-tests/src/test/resources/application.properties
+++ b/integration-tests/spring-zuul-tracing-tests/src/test/resources/application.yml
@@ -1,4 +1,4 @@
-#
+# ---------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
@@ -6,13 +6,19 @@
# (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
+# 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.
-#
+# ---------------------------------------------------------------------------
+
+property:
+ test0: from_yml
+ test1: from_yml
-spring.main.web-environment=true
+spring:
+ profiles:
+ active: dev
diff --git a/integration-tests/spring-zuul-tracing-tests/src/test/resources/microservice.yaml b/integration-tests/spring-zuul-tracing-tests/src/test/resources/microservice.yaml
index 6de98d9..ca417ce 100644
--- a/integration-tests/spring-zuul-tracing-tests/src/test/resources/microservice.yaml
+++ b/integration-tests/spring-zuul-tracing-tests/src/test/resources/microservice.yaml
@@ -36,3 +36,7 @@ servicecomb:
tracing:
collector:
address: http://localhost:9411/
+
+property:
+ test4: from_microservice_yaml
+ test5: from_microservice_yaml
--
To stop receiving notification emails like this one, please contact
liubao@apache.org.