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/09/29 01:30:49 UTC
[incubator-servicecomb-java-chassis] 02/04: [SCB-944] test cases
switch to new mechanism
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 5496873bb1c7e05fb7b2955e36f2011c97c8481d
Author: wujimin <wu...@huawei.com>
AuthorDate: Fri Sep 28 17:04:27 2018 +0800
[SCB-944] test cases switch to new mechanism
---
.../it/testcase/TestAnnotatedAttribute.java | 16 ++-------------
.../it/testcase/TestChangeTransport.java | 24 ++++------------------
.../it/testcase/TestDataTypePrimitive.java | 23 +++++----------------
.../testcase/TestDefaultJsonValueJaxrsSchema.java | 16 +--------------
.../servicecomb/it/testcase/TestDefaultValue.java | 21 ++++---------------
.../servicecomb/it/testcase/TestParamCodec.java | 15 +-------------
.../it/testcase/TestParamCodecEdge.java | 15 +-------------
.../testcase/TestRequestBodySpringMvcSchema.java | 15 +-------------
.../it/testcase/TestRestServerConfig.java | 16 ++-------------
.../it/testcase/TestRestServerConfigEdge.java | 14 +------------
.../apache/servicecomb/it/testcase/TestTrace.java | 24 +++++++---------------
.../servicecomb/it/testcase/TestTraceEdge.java | 15 +-------------
.../thirdparty/Test3rdPartyInvocation.java | 2 +-
13 files changed, 31 insertions(+), 185 deletions(-)
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestAnnotatedAttribute.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestAnnotatedAttribute.java
index 37a5b1f..732f62c 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestAnnotatedAttribute.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestAnnotatedAttribute.java
@@ -22,8 +22,6 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.servicecomb.it.Consumers;
-import org.apache.servicecomb.it.junit.ITJUnitUtils;
-import org.junit.Before;
import org.junit.Test;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
@@ -37,18 +35,8 @@ public class TestAnnotatedAttribute {
String fromHeader(String inputs);
}
- private static Consumers<AnnotatedAttributeIntf> consumersSpringmvc;
-
- private static String producerName;
-
- @Before
- public void prepare() {
- if (!ITJUnitUtils.getProducerName().equals(producerName)) {
- producerName = ITJUnitUtils.getProducerName();
- consumersSpringmvc = new Consumers<>(producerName, "annotatedAttributeSpringmvc", AnnotatedAttributeIntf.class);
- consumersSpringmvc.init(ITJUnitUtils.getTransport());
- }
- }
+ private static Consumers<AnnotatedAttributeIntf> consumersSpringmvc =
+ new Consumers<>("annotatedAttributeSpringmvc", AnnotatedAttributeIntf.class);
@Test
public void fromHeader_springmvc_rt() {
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestChangeTransport.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestChangeTransport.java
index a7be7bc..633dad0 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestChangeTransport.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestChangeTransport.java
@@ -17,9 +17,7 @@
package org.apache.servicecomb.it.testcase;
import org.apache.servicecomb.it.Consumers;
-import org.apache.servicecomb.it.junit.ITJUnitUtils;
import org.junit.Assert;
-import org.junit.Before;
import org.junit.Test;
public class TestChangeTransport {
@@ -27,26 +25,12 @@ public class TestChangeTransport {
String checkTransport();
}
- private static Consumers<ChangeTranportIntf> consumersPojo;
+ static Consumers<ChangeTranportIntf> consumersPojo = new Consumers<>("transportPojo", ChangeTranportIntf.class);
- private static Consumers<ChangeTranportIntf> consumersJaxrs;
+ static Consumers<ChangeTranportIntf> consumersJaxrs = new Consumers<>("transportJaxrs", ChangeTranportIntf.class);
- private static Consumers<ChangeTranportIntf> consumersSpringmvc;
-
- private static String producerName;
-
- @Before
- public void prepare() {
- if (!ITJUnitUtils.getProducerName().equals(producerName)) {
- producerName = ITJUnitUtils.getProducerName();
- consumersPojo = new Consumers<>(producerName, "transportPojo", ChangeTranportIntf.class);
- consumersJaxrs = new Consumers<>(producerName, "transportJaxrs", ChangeTranportIntf.class);
- consumersSpringmvc = new Consumers<>(producerName, "transportSpringmvc", ChangeTranportIntf.class);
- consumersPojo.init(ITJUnitUtils.getTransport());
- consumersJaxrs.init(ITJUnitUtils.getTransport());
- consumersSpringmvc.init(ITJUnitUtils.getTransport());
- }
- }
+ static Consumers<ChangeTranportIntf> consumersSpringmvc = new Consumers<>("transportSpringmvc",
+ ChangeTranportIntf.class);
void checkTransport_intf(Consumers<ChangeTranportIntf> consumers) {
Assert.assertEquals(consumers.getTransport(), consumers.getIntf().checkTransport());
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestDataTypePrimitive.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestDataTypePrimitive.java
index 83423ce..82d505c 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestDataTypePrimitive.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestDataTypePrimitive.java
@@ -24,8 +24,6 @@ import java.util.Map;
import org.apache.servicecomb.it.Consumers;
import org.apache.servicecomb.it.extend.engine.ITSCBRestTemplate;
-import org.apache.servicecomb.it.junit.ITJUnitUtils;
-import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
@@ -94,24 +92,13 @@ public class TestDataTypePrimitive {
double doubleAdd(double num1, double num2);
}
- private static Consumers<DataTypePojoIntf> consumersPojo;
+ private static Consumers<DataTypePojoIntf> consumersPojo = new Consumers<>("dataTypePojo", DataTypePojoIntf.class);
- private static Consumers<DataTypeRestIntf> consumersJaxrs;
+ private static Consumers<DataTypeRestIntf> consumersJaxrs =
+ new Consumers<>("dataTypeJaxrs", DataTypeRestIntf.class);
- private static Consumers<DataTypeRestIntf> consumersSpringmvc;
-
- private static String producerName;
-
- @BeforeClass
- public static void beforeClass() {
- producerName = ITJUnitUtils.getProducerName();
- consumersPojo = new Consumers<>(producerName, "dataTypePojo", DataTypePojoIntf.class);
- consumersJaxrs = new Consumers<>(producerName, "dataTypeJaxrs", DataTypeRestIntf.class);
- consumersSpringmvc = new Consumers<>(producerName, "dataTypeSpringmvc", DataTypeRestIntf.class);
- consumersPojo.init(ITJUnitUtils.getTransport());
- consumersJaxrs.init(ITJUnitUtils.getTransport());
- consumersSpringmvc.init(ITJUnitUtils.getTransport());
- }
+ private static Consumers<DataTypeRestIntf> consumersSpringmvc = new Consumers<>("dataTypeSpringmvc",
+ DataTypeRestIntf.class);
@Test
public void int_pojo_intf() {
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestDefaultJsonValueJaxrsSchema.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestDefaultJsonValueJaxrsSchema.java
index 6594c9d..1e966a6 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestDefaultJsonValueJaxrsSchema.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestDefaultJsonValueJaxrsSchema.java
@@ -22,28 +22,14 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.servicecomb.it.extend.engine.GateRestTemplate;
-import org.apache.servicecomb.it.junit.ITJUnitUtils;
import org.junit.Assert;
-import org.junit.Before;
import org.junit.Test;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
-import org.springframework.web.client.RestTemplate;
public class TestDefaultJsonValueJaxrsSchema {
- private static RestTemplate client;
-
- private static String producerName;
-
- @Before
- public void prepare() {
- if (!ITJUnitUtils.getProducerName().equals(producerName)) {
- producerName = ITJUnitUtils.getProducerName();
- client = new GateRestTemplate("it-edge", producerName, "defaultJsonValueJaxrs");
- }
- }
-
+ static GateRestTemplate client = GateRestTemplate.createEdgeRestTemplate("defaultJsonValueJaxrs");
@Test
public void invokeFromEdgeWithQuery() {
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestDefaultValue.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestDefaultValue.java
index 60552bd..8d55dd3 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestDefaultValue.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestDefaultValue.java
@@ -19,8 +19,6 @@ package org.apache.servicecomb.it.testcase;
import static org.junit.Assert.assertEquals;
import org.apache.servicecomb.it.Consumers;
-import org.apache.servicecomb.it.junit.ITJUnitUtils;
-import org.junit.Before;
import org.junit.Test;
public class TestDefaultValue {
@@ -70,22 +68,11 @@ public class TestDefaultValue {
private double defaultDouble = 10.2;
- private static Consumers<DefaultValueIntf> consumersJaxrs;
+ private static Consumers<DefaultValueIntf> consumersJaxrs = new Consumers<>("defaultValueJaxrs",
+ DefaultValueIntf.class);
- private static Consumers<DefaultValueRequireIntf> consumersSpringmvc;
-
- private static String producerName;
-
- @Before
- public void prepare() {
- if (!ITJUnitUtils.getProducerName().equals(producerName)) {
- producerName = ITJUnitUtils.getProducerName();
- consumersJaxrs = new Consumers<>(producerName, "defaultValueJaxrs", DefaultValueIntf.class);
- consumersSpringmvc = new Consumers<>(producerName, "defaultValueSpringmvc", DefaultValueRequireIntf.class);
- consumersJaxrs.init(ITJUnitUtils.getTransport());
- consumersSpringmvc.init(ITJUnitUtils.getTransport());
- }
- }
+ private static Consumers<DefaultValueRequireIntf> consumersSpringmvc = new Consumers<>("defaultValueSpringmvc",
+ DefaultValueRequireIntf.class);
@Test
public void intQuery_jaxrs_intf() {
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestParamCodec.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestParamCodec.java
index d4a376e..8a2bc25 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestParamCodec.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestParamCodec.java
@@ -20,8 +20,6 @@ package org.apache.servicecomb.it.testcase;
import static org.junit.Assert.assertEquals;
import org.apache.servicecomb.it.Consumers;
-import org.apache.servicecomb.it.junit.ITJUnitUtils;
-import org.junit.Before;
import org.junit.Test;
public class TestParamCodec {
@@ -29,18 +27,7 @@ public class TestParamCodec {
String spaceCharCodec(String pathVal, String q);
}
- private static Consumers<ParamCodecSchemaIntf> consumers;
-
- private static String producerName;
-
- @Before
- public void prepare() {
- if (!ITJUnitUtils.getProducerName().equals(producerName)) {
- producerName = ITJUnitUtils.getProducerName();
- consumers = new Consumers<>(producerName, "paramCodec", ParamCodecSchemaIntf.class);
- consumers.init(ITJUnitUtils.getTransport());
- }
- }
+ static Consumers<ParamCodecSchemaIntf> consumers = new Consumers<>("paramCodec", ParamCodecSchemaIntf.class);
@Test
public void spaceCharEncode_intf() {
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestParamCodecEdge.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestParamCodecEdge.java
index 250b84e..408efe0 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestParamCodecEdge.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestParamCodecEdge.java
@@ -20,23 +20,10 @@ package org.apache.servicecomb.it.testcase;
import static org.junit.Assert.assertEquals;
import org.apache.servicecomb.it.extend.engine.GateRestTemplate;
-import org.apache.servicecomb.it.junit.ITJUnitUtils;
-import org.junit.Before;
import org.junit.Test;
-import org.springframework.web.client.RestTemplate;
public class TestParamCodecEdge {
- private static RestTemplate client;
-
- private static String producerName;
-
- @Before
- public void prepare() {
- if (!ITJUnitUtils.getProducerName().equals(producerName)) {
- producerName = ITJUnitUtils.getProducerName();
- client = new GateRestTemplate("it-edge", producerName, "paramCodec");
- }
- }
+ static GateRestTemplate client = GateRestTemplate.createEdgeRestTemplate("paramCodec");
@Test
public void spaceCharEncode() {
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestRequestBodySpringMvcSchema.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestRequestBodySpringMvcSchema.java
index f51322d..ac292b2 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestRequestBodySpringMvcSchema.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestRequestBodySpringMvcSchema.java
@@ -21,27 +21,14 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.servicecomb.it.extend.engine.GateRestTemplate;
-import org.apache.servicecomb.it.junit.ITJUnitUtils;
import org.junit.Assert;
-import org.junit.Before;
import org.junit.Test;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
-import org.springframework.web.client.RestTemplate;
public class TestRequestBodySpringMvcSchema {
- private static RestTemplate edgeClient;
-
- private static String producerName;
-
- @Before
- public void prepare() {
- if (!ITJUnitUtils.getProducerName().equals(producerName)) {
- producerName = ITJUnitUtils.getProducerName();
- edgeClient = new GateRestTemplate("it-edge", producerName, "requestBodySpringMvcSchema");
- }
- }
+ private static GateRestTemplate edgeClient = GateRestTemplate.createEdgeRestTemplate("requestBodySpringMvcSchema");
@Test
public void basicRequestResponse() {
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestRestServerConfig.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestRestServerConfig.java
index cdced0f..9adfb21 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestRestServerConfig.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestRestServerConfig.java
@@ -18,10 +18,8 @@
package org.apache.servicecomb.it.testcase;
import org.apache.servicecomb.it.Consumers;
-import org.apache.servicecomb.it.junit.ITJUnitUtils;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.junit.Assert;
-import org.junit.Before;
import org.junit.Test;
import com.google.common.base.Strings;
@@ -36,18 +34,8 @@ public class TestRestServerConfig {
String testMaxInitialLineLength(String q);
}
- private static String producerName;
-
- private static Consumers<RestServerConfigSchemaIntf> consumers;
-
- @Before
- public void prepare() {
- if (!ITJUnitUtils.getProducerName().equals(producerName)) {
- producerName = ITJUnitUtils.getProducerName();
- consumers = new Consumers<>(producerName, "restServerConfig", RestServerConfigSchemaIntf.class);
- consumers.init(ITJUnitUtils.getTransport());
- }
- }
+ static Consumers<RestServerConfigSchemaIntf> consumers = new Consumers<>("restServerConfig",
+ RestServerConfigSchemaIntf.class);
/**
* Max initial line length is set to 5000
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestRestServerConfigEdge.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestRestServerConfigEdge.java
index 1f0f30c..ac4c552 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestRestServerConfigEdge.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestRestServerConfigEdge.java
@@ -26,25 +26,13 @@ import java.net.URL;
import java.util.Scanner;
import org.apache.servicecomb.it.extend.engine.GateRestTemplate;
-import org.apache.servicecomb.it.junit.ITJUnitUtils;
import org.junit.Assert;
-import org.junit.Before;
import org.junit.Test;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestClientException;
public class TestRestServerConfigEdge {
- private static GateRestTemplate client;
-
- private static String producerName;
-
- @Before
- public void prepare() {
- if (!ITJUnitUtils.getProducerName().equals(producerName)) {
- producerName = ITJUnitUtils.getProducerName();
- client = new GateRestTemplate("it-edge", producerName, "dataTypeJaxrs");
- }
- }
+ static GateRestTemplate client = (GateRestTemplate) GateRestTemplate.createEdgeRestTemplate("dataTypeJaxrs");
@Test
public void testIllegalPathParam() throws IOException {
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestTrace.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestTrace.java
index 4e908f0..df4a6ad 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestTrace.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestTrace.java
@@ -21,12 +21,11 @@ import java.util.concurrent.ExecutionException;
import org.apache.servicecomb.core.Const;
import org.apache.servicecomb.it.Consumers;
-import org.apache.servicecomb.it.junit.ITJUnitUtils;
import org.apache.servicecomb.swagger.invocation.context.ContextUtils;
import org.apache.servicecomb.swagger.invocation.context.InvocationContext;
-import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Assert;
-import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
public class TestTrace {
@@ -34,26 +33,17 @@ public class TestTrace {
CompletableFuture<String> echoProxy();
}
- private static Consumers<TraceSchemaIntf> consumers;
-
-
- private static String producerName;
-
- @Before
- public void prepare() {
- if (!ITJUnitUtils.getProducerName().equals(producerName)) {
- producerName = ITJUnitUtils.getProducerName();
- consumers = new Consumers<>(producerName, "trace", TraceSchemaIntf.class);
- consumers.init(ITJUnitUtils.getTransport());
- }
+ static Consumers<TraceSchemaIntf> consumers = new Consumers<>("trace", TraceSchemaIntf.class);
+ @BeforeClass
+ public static void classSetup() {
InvocationContext context = new InvocationContext();
context.addContext(Const.TRACE_ID_NAME, "testId");
ContextUtils.setInvocationContext(context);
}
- @After
- public void teardown() {
+ @AfterClass
+ public static void classTeardown() {
ContextUtils.removeInvocationContext();
}
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestTraceEdge.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestTraceEdge.java
index 3244fb5..06b08bf 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestTraceEdge.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestTraceEdge.java
@@ -18,27 +18,14 @@ package org.apache.servicecomb.it.testcase;
import org.apache.servicecomb.core.Const;
import org.apache.servicecomb.it.extend.engine.GateRestTemplate;
-import org.apache.servicecomb.it.junit.ITJUnitUtils;
import org.junit.Assert;
-import org.junit.Before;
import org.junit.Test;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
-import org.springframework.web.client.RestTemplate;
public class TestTraceEdge {
- private static RestTemplate client;
-
- private static String producerName;
-
- @Before
- public void prepare() {
- if (!ITJUnitUtils.getProducerName().equals(producerName)) {
- producerName = ITJUnitUtils.getProducerName();
- client = new GateRestTemplate("it-edge", producerName, "trace");
- }
- }
+ static GateRestTemplate client = GateRestTemplate.createEdgeRestTemplate("trace");
@Test
public void echo() {
diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/thirdparty/Test3rdPartyInvocation.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/thirdparty/Test3rdPartyInvocation.java
index fec1f81..c0086c5 100644
--- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/thirdparty/Test3rdPartyInvocation.java
+++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/thirdparty/Test3rdPartyInvocation.java
@@ -53,7 +53,7 @@ public class Test3rdPartyInvocation {
private static final String ASYNC_THIRD_PARTY_MICROSERVICE_NAME = THIRD_PARTY_MICROSERVICE_NAME + "Async";
// to get endpoint from urlPrefix
- static GateRestTemplate rt = new GateRestTemplate("it-edge", "it-producer", "dataTypeJaxrs");
+ static GateRestTemplate rt = GateRestTemplate.createEdgeRestTemplate("dataTypeJaxrs");
private static DataTypeJaxrsSchemaIntf dataTypeJaxrsSchema;