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 2020/01/11 10:02:57 UTC
[servicecomb-java-chassis] 05/08: [SCB-1704]change invocation
arguments from "swagger arguments" to "invocation arguments"
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/servicecomb-java-chassis.git
commit 85619e3be2b3a5d02d91d123439a472e10ae4cb1
Author: liubao <bi...@qq.com>
AuthorDate: Tue Jan 7 11:42:13 2020 +0800
[SCB-1704]change invocation arguments from "swagger arguments" to "invocation arguments"
---
.../servicecomb/common/rest/codec/RestCodec.java | 32 ++--
.../common/rest/definition/RestOperationMeta.java | 11 +-
.../common/rest/definition/RestParam.java | 9 +-
.../definition/path/AbstractUrlParamWriter.java | 6 +-
.../rest/definition/path/PathVarParamWriter.java | 4 +-
.../rest/definition/path/QueryVarParamWriter.java | 3 +-
.../rest/definition/path/StaticUrlParamWriter.java | 4 +-
.../rest/definition/path/URLPathBuilder.java | 8 +-
.../rest/definition/path/UrlParamWriter.java | 4 +-
.../rest/filter/inner/ClientRestArgsFilter.java | 2 +-
.../rest/filter/inner/ServerRestArgsFilter.java | 5 +-
.../common/rest/TestAbstractRestInvocation.java | 4 +-
.../common/rest/codec/TestRestCodec.java | 20 ++-
.../common/rest/definition/TestPath.java | 38 +++--
.../definition/path/PathVarParamWriterTest.java | 27 +++-
.../definition/path/QueryVarParamWriterTest.java | 120 ++++++++-------
.../rest/definition/path/URLPathBuilderTest.java | 62 ++++----
.../org/apache/servicecomb/core/Invocation.java | 55 ++++---
.../handler/impl/ProducerOperationHandler.java | 133 ++++++++++++++++-
.../core/invocation/InvocationFactory.java | 14 +-
.../core/provider/consumer/InvokerUtils.java | 7 +-
.../core => }/TestCseApplicationListener.java | 2 +-
.../apache/servicecomb/core/TestInvocation.java | 35 ++---
.../impl/ErrorToProducerResponseConverter.java | 17 ++-
.../handler/impl/TestProducerOperationHandler.java | 12 +-
.../core/invocation/TestInvocationStageTrace.java | 5 +-
....exception.ExceptionToProducerResponseConverter | 18 +++
.../servicecomb/demo/pojo/client/PojoClient.java | 13 +-
.../demo/pojo/client/PojoClientTest.java | 13 +-
.../loadbalance/TestLoadBalanceHandler2.java | 8 +-
.../apache/servicecomb/provider/pojo/Invoker.java | 14 +-
.../common/InvocationToHttpServletRequest.java | 4 +-
.../common/TestInvocationToHttpServletRequest.java | 17 ++-
.../springmvc/reference/CseClientHttpRequest.java | 14 +-
.../reference/async/CseAsyncClientHttpRequest.java | 5 +-
.../reference/TestCseClientHttpRequest.java | 4 +-
...WithProviderPrefixClientHttpRequestFactory.java | 4 +-
...UrlWithServiceNameClientHttpRequestFactory.java | 4 +-
.../async/CseAsyncClientHttpRequestTest.java | 2 +-
.../swagger/engine/SwaggerEnvironment.java | 12 --
.../swagger/engine/SwaggerProducerOperation.java | 147 +-----------------
.../swagger/invocation/SwaggerInvocation.java | 28 ----
.../arguments/consumer/ArgumentsMapperCommon.java | 46 ------
.../arguments/consumer/ConsumerArgumentSame.java | 41 ------
.../consumer/ConsumerArgumentToBodyField.java | 60 --------
.../consumer/ConsumerArgumentsMapperCreator.java | 114 --------------
.../consumer/ConsumerBeanParamMapper.java | 73 ---------
.../arguments/producer/ProducerArgumentSame.java | 38 -----
.../producer/ProducerArgumentsMapperCreator.java | 102 -------------
.../producer/ProducerBeanParamMapper.java | 68 ---------
.../SwaggerBodyFieldToProducerArgument.java | 56 -------
.../arguments/consumer/TestJaxrsV1V1.java | 164 ---------------------
.../arguments/consumer/TestJaxrsV1V2.java | 146 ------------------
.../arguments/consumer/TestJaxrsV2V1.java | 142 ------------------
.../arguments/consumer/TestJaxrsV2V2.java | 147 ------------------
.../arguments/consumer/TestPojoOneArg.java | 87 -----------
.../arguments/consumer/TestPojoV1V1.java | 139 -----------------
.../arguments/consumer/TestPojoV1V2.java | 105 -------------
.../arguments/consumer/TestPojoV2V1.java | 105 -------------
.../arguments/consumer/TestPojoV2V2.java | 107 --------------
.../arguments/consumer/TestSpringmvcV1V1.java | 143 ------------------
.../arguments/consumer/TestSpringmvcV1V2.java | 147 ------------------
.../arguments/consumer/TestSpringmvcV2V1.java | 143 ------------------
.../arguments/consumer/TestSpringmvcV2V2.java | 148 -------------------
.../invocation/arguments/producer/TestJaxrs.java | 76 ----------
.../invocation/arguments/producer/TestPojo.java | 83 -----------
.../arguments/producer/TestPojoOneArg.java | 48 ------
.../arguments/producer/TestSpringmvc.java | 75 ----------
.../rest/client/http/RestClientInvocation.java | 2 +-
69 files changed, 512 insertions(+), 3039 deletions(-)
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/RestCodec.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/RestCodec.java
index 9e5991e..3500463 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/RestCodec.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/RestCodec.java
@@ -17,7 +17,9 @@
package org.apache.servicecomb.common.rest.codec;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Response.Status;
@@ -37,42 +39,40 @@ public final class RestCodec {
private RestCodec() {
}
- public static void argsToRest(Object[] args, RestOperationMeta restOperation,
+ public static void argsToRest(Map<String, Object> args, RestOperationMeta restOperation,
RestClientRequest clientRequest) throws Exception {
int paramSize = restOperation.getParamList().size();
if (paramSize == 0) {
return;
}
- if (paramSize != args.length) {
- throw new Exception("wrong number of arguments");
- }
-
- for (int idx = 0; idx < paramSize; idx++) {
- RestParam param = restOperation.getParamList().get(idx);
- param.getParamProcessor().setValue(clientRequest, args[idx]);
+ for (String key : args.keySet()) {
+ RestParam param = restOperation.getParamByName(key);
+ param.getParamProcessor().setValue(clientRequest, args.get(key));
}
}
- public static Object[] restToArgs(HttpServletRequest request,
+ public static Map<String, Object> restToArgs(HttpServletRequest request,
RestOperationMeta restOperation) throws InvocationException {
List<RestParam> paramList = restOperation.getParamList();
- Object[] paramValues = new Object[paramList.size()];
+ Map<String, Object> paramValues = new HashMap<>();
for (int idx = 0; idx < paramList.size(); idx++) {
RestParam param = paramList.get(idx);
try {
- paramValues[idx] = param.getParamProcessor().getValue(request);
+ paramValues.put(param.getParamName(), param.getParamProcessor().getValue(request));
} catch (Exception e) {
// Avoid information leak of user input, and add option for debug use.
- String message = String.format("Parameter is not valid for operation [%s]. Parameter is [%s]. Processor is [%s].",
- restOperation.getOperationMeta().getMicroserviceQualifiedName(),
- param.getParamName(),
- param.getParamProcessor().getProcessorType());
+ String message = String
+ .format("Parameter is not valid for operation [%s]. Parameter is [%s]. Processor is [%s].",
+ restOperation.getOperationMeta().getMicroserviceQualifiedName(),
+ param.getParamName(),
+ param.getParamProcessor().getProcessorType());
if (DynamicPropertyFactory.getInstance().getBooleanProperty(
RestConst.PRINT_CODEC_ERROR_MESSGAGE, false).get()) {
LOG.error(message, e);
- throw new InvocationException(Status.BAD_REQUEST.getStatusCode(), Status.BAD_REQUEST.getReasonPhrase(), message, e);
+ throw new InvocationException(Status.BAD_REQUEST.getStatusCode(), Status.BAD_REQUEST.getReasonPhrase(),
+ message, e);
} else {
LOG.error("{} Add {}=true to print the details.", message, RestConst.PRINT_CODEC_ERROR_MESSGAGE);
throw new InvocationException(Status.BAD_REQUEST, message);
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/RestOperationMeta.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/RestOperationMeta.java
index a1d3ec0..af5fd9f 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/RestOperationMeta.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/RestOperationMeta.java
@@ -34,6 +34,7 @@ import org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor;
import org.apache.servicecomb.common.rest.codec.produce.ProduceProcessorManager;
import org.apache.servicecomb.common.rest.definition.path.PathRegExp;
import org.apache.servicecomb.common.rest.definition.path.URLPathBuilder;
+import org.apache.servicecomb.core.Const;
import org.apache.servicecomb.core.definition.CoreMetaUtils;
import org.apache.servicecomb.core.definition.OperationMeta;
import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
@@ -106,9 +107,13 @@ public class RestOperationMeta {
if ("formData".equals(parameter.getIn())) {
formData = true;
}
-
- Type type = producerOperation != null ? producerOperation.getSwaggerParameterTypes()[swaggerParameterIdx] : null;
- type = correctFormBodyType(parameter, type);
+ // TODO : WEAK handle BEAN query param and POJO wrapped arguments.
+ Type paramType = Object.class;
+ if (((SwaggerProducerOperation) operationMeta.getExtData(Const.PRODUCER_OPERATION)) != null) {
+ paramType = ((SwaggerProducerOperation) operationMeta.getExtData(Const.PRODUCER_OPERATION)).getProducerMethod()
+ .getGenericParameterTypes()[swaggerParameterIdx];
+ }
+ Type type = correctFormBodyType(parameter, paramType);
RestParam param = new RestParam(swaggerParameterIdx, parameter, type);
addParam(param);
}
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/RestParam.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/RestParam.java
index 4a71b0e..598a80e 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/RestParam.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/RestParam.java
@@ -19,6 +19,7 @@ package org.apache.servicecomb.common.rest.definition;
import java.lang.reflect.Type;
import java.util.Collection;
+import java.util.Map;
import org.apache.servicecomb.common.rest.codec.param.ParamValueProcessor;
import org.apache.servicecomb.common.rest.codec.param.ParamValueProcessorCreator;
@@ -67,12 +68,12 @@ public class RestParam {
}
@SuppressWarnings("unchecked")
- public <T> T getValue(Object[] args) {
- return (T) args[paramIndex];
+ public <T> T getValue(Map<String, Object> args) {
+ return (T) args.get(paramName);
}
- public String[] getValueAsStrings(Object[] args) {
- Object value = args[paramIndex];
+ public String[] getValueAsStrings(Map<String, Object> args) {
+ Object value = args.get(paramName);
if (value == null) {
return null;
}
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/path/AbstractUrlParamWriter.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/path/AbstractUrlParamWriter.java
index 7e65503..f25a42c 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/path/AbstractUrlParamWriter.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/path/AbstractUrlParamWriter.java
@@ -17,12 +17,14 @@
package org.apache.servicecomb.common.rest.definition.path;
+import java.util.Map;
+
import org.apache.servicecomb.common.rest.definition.RestParam;
public abstract class AbstractUrlParamWriter implements UrlParamWriter {
protected RestParam param;
- protected Object getParamValue(Object[] args) {
- return param.getValue(args);
+ protected Object getParamValue(Map<String, Object> args) {
+ return args.get(param.getParamName());
}
}
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/path/PathVarParamWriter.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/path/PathVarParamWriter.java
index a995073..fb753d9 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/path/PathVarParamWriter.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/path/PathVarParamWriter.java
@@ -17,6 +17,8 @@
package org.apache.servicecomb.common.rest.definition.path;
+import java.util.Map;
+
import org.apache.servicecomb.common.rest.definition.RestParam;
import org.apache.servicecomb.common.rest.definition.path.URLPathBuilder.URLPathStringBuilder;
import org.apache.servicecomb.foundation.common.http.HttpUtils;
@@ -30,7 +32,7 @@ public class PathVarParamWriter extends AbstractUrlParamWriter {
}
@Override
- public void write(URLPathStringBuilder builder, Object[] args) throws Exception {
+ public void write(URLPathStringBuilder builder, Map<String, Object> args) throws Exception {
String paramValue = getParamValue(args).toString();
String encodedPathParam = HttpUtils.encodePathParam(paramValue);
builder.appendPath(encodedPathParam);
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/path/QueryVarParamWriter.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/path/QueryVarParamWriter.java
index 133bbb7..409daa9 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/path/QueryVarParamWriter.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/path/QueryVarParamWriter.java
@@ -21,6 +21,7 @@ import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Map;
import org.apache.servicecomb.common.rest.codec.RestObjectMapperFactory;
import org.apache.servicecomb.common.rest.codec.param.QueryProcessorCreator.QueryProcessor;
@@ -37,7 +38,7 @@ public class QueryVarParamWriter extends AbstractUrlParamWriter {
}
@Override
- public void write(URLPathStringBuilder builder, Object[] args) throws Exception {
+ public void write(URLPathStringBuilder builder, Map<String, Object> args) throws Exception {
Object value = getParamValue(args);
if (value == null) {
// do not write query key to express "null"
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/path/StaticUrlParamWriter.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/path/StaticUrlParamWriter.java
index 315a677..42814eb 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/path/StaticUrlParamWriter.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/path/StaticUrlParamWriter.java
@@ -17,6 +17,8 @@
package org.apache.servicecomb.common.rest.definition.path;
+import java.util.Map;
+
import org.apache.servicecomb.common.rest.definition.path.URLPathBuilder.URLPathStringBuilder;
public class StaticUrlParamWriter implements UrlParamWriter {
@@ -28,7 +30,7 @@ public class StaticUrlParamWriter implements UrlParamWriter {
}
@Override
- public void write(URLPathStringBuilder builder, Object[] args) {
+ public void write(URLPathStringBuilder builder, Map<String, Object> args) {
builder.appendPath(staticPath);
}
}
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/path/URLPathBuilder.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/path/URLPathBuilder.java
index 1e8e2d8..94f9ba4 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/path/URLPathBuilder.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/path/URLPathBuilder.java
@@ -90,7 +90,7 @@ public class URLPathBuilder {
}
}
- public String createRequestPath(Object[] args) throws Exception {
+ public String createRequestPath(Map<String, Object> args) throws Exception {
URLPathStringBuilder builder = new URLPathStringBuilder();
genPathString(builder, args);
@@ -99,19 +99,19 @@ public class URLPathBuilder {
return builder.build();
}
- public String createPathString(Object[] args) throws Exception {
+ public String createPathString(Map<String, Object> args) throws Exception {
URLPathStringBuilder builder = new URLPathStringBuilder();
genPathString(builder, args);
return builder.build();
}
- private void genPathString(URLPathStringBuilder builder, Object[] args) throws Exception {
+ private void genPathString(URLPathStringBuilder builder, Map<String, Object> args) throws Exception {
for (UrlParamWriter writer : this.pathParamWriterList) {
writer.write(builder, args);
}
}
- private void genQueryString(URLPathStringBuilder builder, Object[] args) throws Exception {
+ private void genQueryString(URLPathStringBuilder builder, Map<String, Object> args) throws Exception {
for (UrlParamWriter writer : queryParamWriterList) {
writer.write(builder, args);
}
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/path/UrlParamWriter.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/path/UrlParamWriter.java
index a1a5fa6..21ed73a 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/path/UrlParamWriter.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/definition/path/UrlParamWriter.java
@@ -17,8 +17,10 @@
package org.apache.servicecomb.common.rest.definition.path;
+import java.util.Map;
+
import org.apache.servicecomb.common.rest.definition.path.URLPathBuilder.URLPathStringBuilder;
public interface UrlParamWriter {
- void write(URLPathStringBuilder builder, Object[] args) throws Exception;
+ void write(URLPathStringBuilder builder, Map<String, Object> args) throws Exception;
}
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/ClientRestArgsFilter.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/ClientRestArgsFilter.java
index d3a6195..97049a7 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/ClientRestArgsFilter.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/ClientRestArgsFilter.java
@@ -43,7 +43,7 @@ public class ClientRestArgsFilter implements HttpClientFilter {
OperationMeta operationMeta = invocation.getOperationMeta();
RestOperationMeta swaggerRestOperation = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
try {
- RestCodec.argsToRest(invocation.getArgs(), swaggerRestOperation, restClientRequest);
+ RestCodec.argsToRest(invocation.getArguments(), swaggerRestOperation, restClientRequest);
requestEx.setBodyBuffer(restClientRequest.getBodyBuffer());
} catch (Throwable e) {
throw ExceptionFactory.convertConsumerException(e);
diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/ServerRestArgsFilter.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/ServerRestArgsFilter.java
index 919280e..7935520 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/ServerRestArgsFilter.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/ServerRestArgsFilter.java
@@ -17,6 +17,7 @@
package org.apache.servicecomb.common.rest.filter.inner;
+import java.util.Map;
import java.util.concurrent.CompletableFuture;
import javax.servlet.http.Part;
@@ -58,8 +59,8 @@ public class ServerRestArgsFilter implements HttpServerFilter {
public Response afterReceiveRequest(Invocation invocation, HttpServletRequestEx requestEx) {
OperationMeta operationMeta = invocation.getOperationMeta();
RestOperationMeta restOperationMeta = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
- Object[] args = RestCodec.restToArgs(requestEx, restOperationMeta);
- invocation.setSwaggerArguments(args);
+ Map<String, Object> args = RestCodec.restToArgs(requestEx, restOperationMeta);
+ invocation.setArguments(args);
return null;
}
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestAbstractRestInvocation.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestAbstractRestInvocation.java
index 493d644..1ed6057 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestAbstractRestInvocation.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestAbstractRestInvocation.java
@@ -99,7 +99,7 @@ public class TestAbstractRestInvocation {
ReferenceConfig endpoint;
@Mocked
- Object[] swaggerArguments;
+ Map<String, Object> arguments;
Invocation invocation;
@@ -162,7 +162,7 @@ public class TestAbstractRestInvocation {
responseEx = new StandardHttpServletResponseEx(servletResponse);
}
- invocation = new Invocation(endpoint, operationMeta, swaggerArguments);
+ invocation = new Invocation(endpoint, operationMeta, arguments);
initRestInvocation();
List<HttpServerFilter> httpServerFilters = SPIServiceUtils.getSortedService(HttpServerFilter.class);
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/TestRestCodec.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/TestRestCodec.java
index b200acc..941bec3 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/TestRestCodec.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/TestRestCodec.java
@@ -60,14 +60,18 @@ public class TestRestCodec {
@BeforeClass
public static void beforeClass() {
+ Parameter hp = new HeaderParameter();
+ hp.setName("header");
+ RestParam restParam = new RestParam(0, hp, int.class);
+
restOperation = Mockito.mock(RestOperationMeta.class);
// clientRequest = Mockito.mock(RestClientRequest.class);
paramList = new ArrayList<>();
- Parameter hp = new HeaderParameter();
- hp.setName("header");
- paramList.add(new RestParam(0, hp, int.class));
+
+ paramList.add(restParam);
when(restOperation.getParamList()).thenReturn(paramList);
+ when(restOperation.getParamByName("test")).thenReturn(restParam);
}
@AfterClass
@@ -80,7 +84,9 @@ public class TestRestCodec {
@Test
public void testArgsToRest() {
try {
- RestCodec.argsToRest(new String[] {"abc"}, restOperation, clientRequest);
+ Map<String, Object> args = new HashMap<>();
+ args.put("test", "abc");
+ RestCodec.argsToRest(args, restOperation, clientRequest);
Assert.assertEquals("abc", header.get("header"));
} catch (Exception e) {
Assert.assertTrue(false);
@@ -103,11 +109,13 @@ public class TestRestCodec {
result = processer;
processer.getValue(request);
result = s;
+ restParam.getParamName();
+ result = "test";
}
};
- Object[] xx = RestCodec.restToArgs(request, restOperation);
- Assert.assertEquals(xx[0], s);
+ Map<String, Object> xx = RestCodec.restToArgs(request, restOperation);
+ Assert.assertEquals(xx.get("test"), s);
}
@Test
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/TestPath.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/TestPath.java
index bfac3fa..c9ca88d 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/TestPath.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/TestPath.java
@@ -111,9 +111,11 @@ public class TestPath {
paramMap.put(oRestParam.getParamName(), oRestParam);
URLPathBuilder oURLPathBuilder = new URLPathBuilder("/root/{id}", paramMap);
- Object[] args = new Object[] {100, "query"};
- Assert.assertEquals("/root/100?q=query", oURLPathBuilder.createRequestPath(args));
- Assert.assertEquals("/root/100", oURLPathBuilder.createPathString(args));
+ Map<String, Object> parameters = new HashMap<>();
+ parameters.put("id", 100);
+ parameters.put("q", "query");
+ Assert.assertEquals("/root/100?q=query", oURLPathBuilder.createRequestPath(parameters));
+ Assert.assertEquals("/root/100", oURLPathBuilder.createPathString(parameters));
}
@Test
@@ -135,24 +137,32 @@ public class TestPath {
Parameter parameter = new QueryParameter();
QueryVarParamWriter writer = new QueryVarParamWriter(new RestParam(0, parameter, String.class));
try {
- verify(writer, "T", "&queryVar=T");
- verify(writer, null, "&");
- verify(writer, new String[] {"a", "b"}, "&queryVar=a&queryVar=b");
- verify(writer, new String[] {"a", null, "b"}, "&queryVar=a&queryVar=&queryVar=b");
- verify(writer, Arrays.asList("Lars", "Simon"), "&queryVar=Lars&queryVar=Simon");
- verify(writer, "测试", "&queryVar=%E6%B5%8B%E8%AF%95");
- verify(writer, "a b", "&queryVar=a+b");
- verify(writer, "a+b", "&queryVar=a%2Bb");
+ Map<String, Object> parameters = new HashMap<>();
+ parameters.put("queryVar", "T");
+ verify(writer, parameters, "?queryVar=T");
+ parameters.put("queryVar", null);
+ verify(writer, parameters, "");
+ parameters.put("queryVar", new String[] {"a", "b"});
+ verify(writer, parameters, "?queryVar=a&queryVar=b");
+ parameters.put("queryVar", new String[] {"a", null, "b"});
+ verify(writer, parameters, "?queryVar=a&queryVar=b");
+ parameters.put("queryVar", Arrays.asList("Lars", "Simon"));
+ verify(writer, parameters, "?queryVar=Lars&queryVar=Simon");
+ parameters.put("queryVar", "测试");
+ verify(writer, parameters, "?queryVar=%E6%B5%8B%E8%AF%95");
+ parameters.put("queryVar", "a b");
+ verify(writer, parameters, "?queryVar=a+b");
+ parameters.put("queryVar", "a+b");
+ verify(writer, parameters, "?queryVar=a%2Bb");
} catch (Exception e) {
status = false;
}
Assert.assertTrue(status);
}
- // TODO expect not used?
- private void verify(QueryVarParamWriter writer, Object arg, String expect) throws Exception {
+ private void verify(QueryVarParamWriter writer, Map<String, Object> args, String expect) throws Exception {
URLPathStringBuilder sb = new URLPathStringBuilder();
- Object[] args = new Object[] {arg};
writer.write(sb, args);
+ Assert.assertEquals(expect, sb.build());
}
}
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/path/PathVarParamWriterTest.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/path/PathVarParamWriterTest.java
index fd24009..01978e8 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/path/PathVarParamWriterTest.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/path/PathVarParamWriterTest.java
@@ -17,6 +17,9 @@
package org.apache.servicecomb.common.rest.definition.path;
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.servicecomb.common.rest.definition.RestParam;
import org.apache.servicecomb.common.rest.definition.path.URLPathBuilder.URLPathStringBuilder;
import org.junit.Assert;
@@ -32,7 +35,9 @@ public class PathVarParamWriterTest {
PathVarParamWriter pathVarParamWriter = createPathVarParamWriter();
URLPathStringBuilder pathBuilder = new URLPathStringBuilder();
- pathVarParamWriter.write(pathBuilder, new Object[] {"abc"});
+ Map<String, Object> parameters = new HashMap<>();
+ parameters.put("test", "abc");
+ pathVarParamWriter.write(pathBuilder, parameters);
Assert.assertEquals("abc", pathBuilder.build());
}
@@ -41,7 +46,9 @@ public class PathVarParamWriterTest {
PathVarParamWriter pathVarParamWriter = createPathVarParamWriter();
URLPathStringBuilder pathBuilder = new URLPathStringBuilder();
- pathVarParamWriter.write(pathBuilder, new String[] {"a 20bc"});
+ Map<String, Object> parameters = new HashMap<>();
+ parameters.put("test", "a 20bc");
+ pathVarParamWriter.write(pathBuilder, parameters);
Assert.assertEquals("a%2020bc", pathBuilder.build());
}
@@ -50,7 +57,9 @@ public class PathVarParamWriterTest {
PathVarParamWriter pathVarParamWriter = createPathVarParamWriter();
URLPathStringBuilder pathBuilder = new URLPathStringBuilder();
pathBuilder.appendPath("/api/");
- pathVarParamWriter.write(pathBuilder, new String[] {"a%%bc"});
+ Map<String, Object> parameters = new HashMap<>();
+ parameters.put("test", "a%%bc");
+ pathVarParamWriter.write(pathBuilder, parameters);
Assert.assertEquals("/api/a%25%25bc", pathBuilder.build());
}
@@ -59,7 +68,9 @@ public class PathVarParamWriterTest {
PathVarParamWriter pathVarParamWriter = createPathVarParamWriter();
URLPathStringBuilder pathBuilder = new URLPathStringBuilder();
pathBuilder.appendPath("/api/");
- pathVarParamWriter.write(pathBuilder, new String[] {"a/bc"});
+ Map<String, Object> parameters = new HashMap<>();
+ parameters.put("test", "a/bc");
+ pathVarParamWriter.write(pathBuilder, parameters);
Assert.assertEquals("/api/a%2Fbc", pathBuilder.build());
}
@@ -67,15 +78,17 @@ public class PathVarParamWriterTest {
public void writeIntegerParam() throws Exception {
PathVarParamWriter pathVarParamWriter = createPathVarParamWriter();
URLPathStringBuilder pathBuilder = new URLPathStringBuilder();
- pathVarParamWriter.write(pathBuilder, new Integer[] {12});
+ Map<String, Object> parameters = new HashMap<>();
+ parameters.put("test", 12);
+ pathVarParamWriter.write(pathBuilder, parameters);
Assert.assertEquals("12", pathBuilder.build());
}
private PathVarParamWriter createPathVarParamWriter() {
RestParam restParam = new MockUp<RestParam>() {
@Mock
- Object getValue(Object[] args) {
- return args[0];
+ public String getParamName(){
+ return "test";
}
}.getMockInstance();
return new PathVarParamWriter(restParam);
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/path/QueryVarParamWriterTest.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/path/QueryVarParamWriterTest.java
index 33648a6..1e91cd6 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/path/QueryVarParamWriterTest.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/path/QueryVarParamWriterTest.java
@@ -20,7 +20,9 @@ package org.apache.servicecomb.common.rest.definition.path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.apache.servicecomb.common.rest.definition.RestParam;
import org.apache.servicecomb.common.rest.definition.path.URLPathBuilder.URLPathStringBuilder;
@@ -61,171 +63,177 @@ public class QueryVarParamWriterTest {
@Test
public void write() throws Exception {
URLPathStringBuilder stringBuilder = new URLPathStringBuilder();
- Object[] args = {"a"};
- queryVarParamWriterCsv.write(stringBuilder, args);
+ Map<String, Object> parameters = new HashMap<>();
+ parameters.put("q", "a");
+ queryVarParamWriterCsv.write(stringBuilder, parameters);
Assert.assertEquals("?q=a", stringBuilder.build());
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterMulti.write(stringBuilder, args);
+ queryVarParamWriterMulti.write(stringBuilder, parameters);
Assert.assertEquals("?q=a", stringBuilder.build());
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterDefault.write(stringBuilder, args);
+ queryVarParamWriterDefault.write(stringBuilder, parameters);
Assert.assertEquals("?q=a", stringBuilder.build());
}
@Test
public void writeNull() throws Exception {
URLPathStringBuilder stringBuilder = new URLPathStringBuilder();
- Object[] args = {null};
- queryVarParamWriterCsv.write(stringBuilder, args);
+ Map<String, Object> parameters = new HashMap<>();
+ parameters.put("test", null);
+ queryVarParamWriterCsv.write(stringBuilder, parameters);
Assert.assertEquals("", stringBuilder.build());
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterMulti.write(stringBuilder, args);
+ queryVarParamWriterMulti.write(stringBuilder, parameters);
Assert.assertEquals("", stringBuilder.build());
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterDefault.write(stringBuilder, args);
+ queryVarParamWriterDefault.write(stringBuilder, parameters);
Assert.assertEquals("", stringBuilder.build());
}
@Test
public void writeArray() throws Exception {
URLPathStringBuilder stringBuilder = new URLPathStringBuilder();
- Object[] args = new Object[] {new String[] {"ab", "cd", "ef"}};
- queryVarParamWriterCsv.write(stringBuilder, args);
+ Map<String, Object> parameters = new HashMap<>();
+ parameters.put("q", new String[] {"ab", "cd", "ef"});
+ queryVarParamWriterCsv.write(stringBuilder, parameters);
Assert.assertEquals("?q=ab%2Ccd%2Cef", stringBuilder.build());
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterMulti.write(stringBuilder, args);
+ queryVarParamWriterMulti.write(stringBuilder, parameters);
Assert.assertEquals("?q=ab&q=cd&q=ef", stringBuilder.build());
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterDefault.write(stringBuilder, args);
+ queryVarParamWriterDefault.write(stringBuilder, parameters);
Assert.assertEquals("?q=ab&q=cd&q=ef", stringBuilder.build());
// encode space char
stringBuilder = new URLPathStringBuilder();
- args[0] = new String[] {"a b", " ", "", "ef"};
- queryVarParamWriterCsv.write(stringBuilder, args);
+ parameters.put("q", new String[] {"a b", " ", "", "ef"});
+ queryVarParamWriterCsv.write(stringBuilder, parameters);
Assert.assertEquals("?q=a+b%2C+%2C%2Cef", stringBuilder.build());
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterMulti.write(stringBuilder, args);
+ queryVarParamWriterMulti.write(stringBuilder, parameters);
Assert.assertEquals("?q=a+b&q=+&q=&q=ef", stringBuilder.build());
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterDefault.write(stringBuilder, args);
+ queryVarParamWriterDefault.write(stringBuilder, parameters);
Assert.assertEquals("?q=a+b&q=+&q=&q=ef", stringBuilder.build());
// pass blank string
stringBuilder = new URLPathStringBuilder();
- args[0] = new String[] {""};
- queryVarParamWriterCsv.write(stringBuilder, args);
+ parameters.put("q", new String[] {""});
+ queryVarParamWriterCsv.write(stringBuilder, parameters);
Assert.assertEquals("?q=", stringBuilder.build());
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterMulti.write(stringBuilder, args);
+ queryVarParamWriterMulti.write(stringBuilder, parameters);
Assert.assertEquals("?q=", stringBuilder.build());
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterDefault.write(stringBuilder, args);
+ queryVarParamWriterDefault.write(stringBuilder, parameters);
Assert.assertEquals("?q=", stringBuilder.build());
// pass empty
stringBuilder = new URLPathStringBuilder();
- args[0] = new String[] {};
- queryVarParamWriterCsv.write(stringBuilder, args);
+ parameters.put("q", new String[] {});
+ queryVarParamWriterCsv.write(stringBuilder, parameters);
Assert.assertEquals("", stringBuilder.build());
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterMulti.write(stringBuilder, args);
+ queryVarParamWriterMulti.write(stringBuilder, parameters);
Assert.assertEquals("", stringBuilder.build());
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterDefault.write(stringBuilder, args);
+ queryVarParamWriterDefault.write(stringBuilder, parameters);
Assert.assertEquals("", stringBuilder.build());
// pass null
- args[0] = new String[] {null};
+ parameters.put("q", new String[] {null});
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterCsv.write(stringBuilder, args);
+ queryVarParamWriterCsv.write(stringBuilder, parameters);
Assert.assertEquals("", stringBuilder.build());
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterMulti.write(stringBuilder, args);
+ queryVarParamWriterMulti.write(stringBuilder, parameters);
Assert.assertEquals("", stringBuilder.build());
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterDefault.write(stringBuilder, args);
+ queryVarParamWriterDefault.write(stringBuilder, parameters);
Assert.assertEquals("", stringBuilder.build());
- args[0] = new String[] {null, "ab", null, "cd", null, null, "", null, "ef", null};
+
+ parameters.put("q", new String[] {null, "ab", null, "cd", null, null, "", null, "ef", null});
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterCsv.write(stringBuilder, args);
+ queryVarParamWriterCsv.write(stringBuilder, parameters);
Assert.assertEquals("?q=ab%2Ccd%2C%2Cef", stringBuilder.build());
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterMulti.write(stringBuilder, args);
+ queryVarParamWriterMulti.write(stringBuilder, parameters);
Assert.assertEquals("?q=ab&q=cd&q=&q=ef", stringBuilder.build());
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterDefault.write(stringBuilder, args);
+ queryVarParamWriterDefault.write(stringBuilder, parameters);
Assert.assertEquals("?q=ab&q=cd&q=&q=ef", stringBuilder.build());
}
@Test
public void writeList() throws Exception {
List<String> queryList = Arrays.asList("ab", "cd", "ef");
- Object[] args = {queryList};
+ Map<String, Object> parameters = new HashMap<>();
+ parameters.put("q", queryList);
URLPathStringBuilder stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterCsv.write(stringBuilder, args);
+ queryVarParamWriterCsv.write(stringBuilder, parameters);
Assert.assertEquals("?q=ab%2Ccd%2Cef", stringBuilder.build());
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterMulti.write(stringBuilder, args);
+ queryVarParamWriterMulti.write(stringBuilder, parameters);
Assert.assertEquals("?q=ab&q=cd&q=ef", stringBuilder.build());
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterDefault.write(stringBuilder, args);
+ queryVarParamWriterDefault.write(stringBuilder, parameters);
Assert.assertEquals("?q=ab&q=cd&q=ef", stringBuilder.build());
// encode space char
- args[0] = Arrays.asList("a b", " ", "", "ef");
+ parameters.put("q", Arrays.asList("a b", " ", "", "ef"));
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterCsv.write(stringBuilder, args);
+ queryVarParamWriterCsv.write(stringBuilder, parameters);
Assert.assertEquals("?q=a+b%2C+%2C%2Cef", stringBuilder.build());
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterMulti.write(stringBuilder, args);
+ queryVarParamWriterMulti.write(stringBuilder, parameters);
Assert.assertEquals("?q=a+b&q=+&q=&q=ef", stringBuilder.build());
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterDefault.write(stringBuilder, args);
+ queryVarParamWriterDefault.write(stringBuilder, parameters);
Assert.assertEquals("?q=a+b&q=+&q=&q=ef", stringBuilder.build());
// pass blank string
stringBuilder = new URLPathStringBuilder();
- args[0] = Collections.singletonList("");
- queryVarParamWriterCsv.write(stringBuilder, args);
+ parameters.put("q", Collections.singletonList(""));
+ queryVarParamWriterCsv.write(stringBuilder, parameters);
Assert.assertEquals("?q=", stringBuilder.build());
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterMulti.write(stringBuilder, args);
+ queryVarParamWriterMulti.write(stringBuilder, parameters);
Assert.assertEquals("?q=", stringBuilder.build());
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterDefault.write(stringBuilder, args);
+ queryVarParamWriterDefault.write(stringBuilder, parameters);
Assert.assertEquals("?q=", stringBuilder.build());
// pass empty
stringBuilder = new URLPathStringBuilder();
- args[0] = new ArrayList<>();
- queryVarParamWriterCsv.write(stringBuilder, args);
+ parameters.put("q", new ArrayList<>());
+ queryVarParamWriterCsv.write(stringBuilder, parameters);
Assert.assertEquals("", stringBuilder.build());
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterMulti.write(stringBuilder, args);
+ queryVarParamWriterMulti.write(stringBuilder, parameters);
Assert.assertEquals("", stringBuilder.build());
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterDefault.write(stringBuilder, args);
+ queryVarParamWriterDefault.write(stringBuilder, parameters);
Assert.assertEquals("", stringBuilder.build());
// pass null
- args[0] = Collections.singletonList(null);
+ parameters.put("q", Collections.singletonList(null));
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterCsv.write(stringBuilder, args);
+ queryVarParamWriterCsv.write(stringBuilder, parameters);
Assert.assertEquals("", stringBuilder.build());
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterMulti.write(stringBuilder, args);
+ queryVarParamWriterMulti.write(stringBuilder, parameters);
Assert.assertEquals("", stringBuilder.build());
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterDefault.write(stringBuilder, args);
+ queryVarParamWriterDefault.write(stringBuilder, parameters);
Assert.assertEquals("", stringBuilder.build());
- args[0] = Arrays.asList(null, "ab", null, "cd", null, null, "", null, "ef", null);
+
+ parameters.put("q", Arrays.asList(null, "ab", null, "cd", null, null, "", null, "ef", null));
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterCsv.write(stringBuilder, args);
+ queryVarParamWriterCsv.write(stringBuilder, parameters);
Assert.assertEquals("?q=ab%2Ccd%2C%2Cef", stringBuilder.build());
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterMulti.write(stringBuilder, args);
+ queryVarParamWriterMulti.write(stringBuilder, parameters);
Assert.assertEquals("?q=ab&q=cd&q=&q=ef", stringBuilder.build());
stringBuilder = new URLPathStringBuilder();
- queryVarParamWriterDefault.write(stringBuilder, args);
+ queryVarParamWriterDefault.write(stringBuilder, parameters);
Assert.assertEquals("?q=ab&q=cd&q=&q=ef", stringBuilder.build());
}
}
diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/path/URLPathBuilderTest.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/path/URLPathBuilderTest.java
index 8343d0d..f412f25 100644
--- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/path/URLPathBuilderTest.java
+++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/path/URLPathBuilderTest.java
@@ -18,6 +18,7 @@
package org.apache.servicecomb.common.rest.definition.path;
import java.lang.reflect.Type;
+import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -39,11 +40,15 @@ public class URLPathBuilderTest {
addParam("q1", String.class, QueryParameter::new, paramMap);
URLPathBuilder urlPathBuilder = new URLPathBuilder("/path/{p0}/and/{p1}", paramMap);
- Object[] args = {10, "abcPath", 11, "queryABC"};
+ Map<String, Object> parameters = new HashMap<>();
+ parameters.put("p0", 10);
+ parameters.put("p1", "abcPath");
+ parameters.put("q0", 11);
+ parameters.put("q1", "queryABC");
Assert.assertEquals("/path/10/and/abcPath?q0=11&q1=queryABC",
- urlPathBuilder.createRequestPath(args));
+ urlPathBuilder.createRequestPath(parameters));
Assert.assertEquals("/path/10/and/abcPath",
- urlPathBuilder.createPathString(args));
+ urlPathBuilder.createPathString(parameters));
}
@Test
@@ -53,11 +58,13 @@ public class URLPathBuilderTest {
addParam("q", String.class, QueryParameter::new, paramMap);
URLPathBuilder urlPathBuilder = new URLPathBuilder("/path/{p}", paramMap);
- Object[] args = {"ab%% %cd%", "ab%% %cd%"};
+ Map<String, Object> parameters = new HashMap<>();
+ parameters.put("p", "ab%% %cd%");
+ parameters.put("q", "ab%% %cd%");
Assert.assertEquals("/path/ab%25%25%20%25cd%25?q=ab%25%25+%25cd%25",
- urlPathBuilder.createRequestPath(args));
+ urlPathBuilder.createRequestPath(parameters));
Assert.assertEquals("/path/ab%25%25%20%25cd%25",
- urlPathBuilder.createPathString(args));
+ urlPathBuilder.createPathString(parameters));
}
@Test
@@ -67,30 +74,23 @@ public class URLPathBuilderTest {
addParam("intArr", int[].class, QueryParameter::new, paramMap);
URLPathBuilder urlPathBuilder = new URLPathBuilder("/path", paramMap);
- Object[] args = new Object[] {
- new Object[] {"a", "b", "c"},
- new Object[] {1, 2, 3}
- };
+ Map<String, Object> parameters = new HashMap<>();
+ parameters.put("strArr", new Object[] {"a", "b", "c"});
+ parameters.put("intArr", new Object[] {1, 2, 3});
Assert.assertEquals("/path?strArr=a&strArr=b&strArr=c&intArr=1&intArr=2&intArr=3",
- urlPathBuilder.createRequestPath(args));
- args = new Object[] {
- new Object[] {},
- new Object[] {1, 2, 3}
- };
+ urlPathBuilder.createRequestPath(parameters));
+ parameters.put("strArr", new Object[] {});
+ parameters.put("intArr", new Object[] {1, 2, 3});
Assert.assertEquals("/path?intArr=1&intArr=2&intArr=3",
- urlPathBuilder.createRequestPath(args));
- args = new Object[] {
- new Object[] {"a", "b", "c"},
- new Object[] {}
- };
+ urlPathBuilder.createRequestPath(parameters));
+ parameters.put("strArr", new Object[] {"a", "b", "c"});
+ parameters.put("intArr", new Object[] {});
Assert.assertEquals("/path?strArr=a&strArr=b&strArr=c",
- urlPathBuilder.createRequestPath(args));
- args = new Object[] {
- new Object[] {},
- new Object[] {}
- };
+ urlPathBuilder.createRequestPath(parameters));
+ parameters.put("strArr", new Object[] {});
+ parameters.put("intArr", new Object[] {});
Assert.assertEquals("/path",
- urlPathBuilder.createRequestPath(args));
+ urlPathBuilder.createRequestPath(parameters));
}
@Test
@@ -102,11 +102,15 @@ public class URLPathBuilderTest {
addParam("q1", String.class, QueryParameter::new, paramMap);
URLPathBuilder urlPathBuilder = new URLPathBuilder("/path/{p0 : .*}/and/{p1:.*}", paramMap);
- Object[] args = {10, "abcPath", 11, "queryABC"};
+ Map<String, Object> parameters = new HashMap<>();
+ parameters.put("p0", 10);
+ parameters.put("p1", "abcPath");
+ parameters.put("q0", 11);
+ parameters.put("q1", "queryABC");
Assert.assertEquals("/path/10/and/abcPath?q0=11&q1=queryABC",
- urlPathBuilder.createRequestPath(args));
+ urlPathBuilder.createRequestPath(parameters));
Assert.assertEquals("/path/10/and/abcPath",
- urlPathBuilder.createPathString(args));
+ urlPathBuilder.createPathString(parameters));
}
private void addParam(String paramName, Type paramType,
diff --git a/core/src/main/java/org/apache/servicecomb/core/Invocation.java b/core/src/main/java/org/apache/servicecomb/core/Invocation.java
index c4103f0..f164a41 100644
--- a/core/src/main/java/org/apache/servicecomb/core/Invocation.java
+++ b/core/src/main/java/org/apache/servicecomb/core/Invocation.java
@@ -17,11 +17,11 @@
package org.apache.servicecomb.core;
+import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicLong;
@@ -40,11 +40,11 @@ import org.apache.servicecomb.core.tracing.TraceIdGenerator;
import org.apache.servicecomb.foundation.common.event.EventManager;
import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
+import org.apache.servicecomb.swagger.engine.SwaggerProducerOperation;
import org.apache.servicecomb.swagger.invocation.AsyncResponse;
import org.apache.servicecomb.swagger.invocation.InvocationType;
import org.apache.servicecomb.swagger.invocation.Response;
import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.context.InvocationContext;
import org.apache.servicecomb.swagger.invocation.response.ResponsesMeta;
import com.fasterxml.jackson.databind.JavaType;
@@ -98,6 +98,8 @@ public class Invocation extends SwaggerInvocation {
private long invocationId;
+ private Map<String, Object> arguments;
+
public long getInvocationId() {
return invocationId;
}
@@ -132,24 +134,24 @@ public class Invocation extends SwaggerInvocation {
// An empty invocation, used to mock or some other scenario do not need operation information.
}
- public Invocation(ReferenceConfig referenceConfig, OperationMeta operationMeta, Object[] swaggerArguments) {
+ public Invocation(ReferenceConfig referenceConfig, OperationMeta operationMeta, Map<String, Object> arguments) {
this.invocationType = InvocationType.CONSUMER;
this.referenceConfig = referenceConfig;
this.responsesMeta = operationMeta.getResponsesMeta();
- init(operationMeta, swaggerArguments);
+ init(operationMeta, arguments);
}
- public Invocation(Endpoint endpoint, OperationMeta operationMeta, Object[] swaggerArguments) {
+ public Invocation(Endpoint endpoint, OperationMeta operationMeta, Map<String, Object> arguments) {
this.invocationType = InvocationType.PRODUCER;
this.endpoint = endpoint;
- init(operationMeta, swaggerArguments);
+ init(operationMeta, arguments);
}
- private void init(OperationMeta operationMeta, Object[] swaggerArguments) {
+ private void init(OperationMeta operationMeta, Map<String, Object> arguments) {
this.invocationId = INVOCATION_ID.getAndIncrement();
this.schemaMeta = operationMeta.getSchemaMeta();
this.operationMeta = operationMeta;
- this.swaggerArguments = swaggerArguments;
+ this.arguments = arguments;
this.handlerList = getHandlerChain();
handlerIndex = 0;
}
@@ -183,35 +185,28 @@ public class Invocation extends SwaggerInvocation {
return operationMeta;
}
- public Object[] getArgs() {
- return swaggerArguments;
- }
-
public Map<String, Object> getArguments() {
- if (swaggerArguments == null) {
- return new HashMap<>(0);
- }
- Map<String, Object> result = new HashMap<>(swaggerArguments.length);
- for (int i = 0; i < swaggerArguments.length; i++) {
- if (swaggerArguments[i] instanceof InvocationContext) {
- continue;
- }
- result.put(this.operationMeta.getParamName(i), swaggerArguments[i]);
- }
- return result;
+ return arguments;
}
- public void setArguments(Map<String, Object> swaggerArguments) {
- if (swaggerArguments == null) {
+ public void setArguments(Map<String, Object> arguments) {
+ if (arguments == null) {
// Empty arguments
- setSwaggerArguments(null);
+ this.arguments = new HashMap<>(0);
return;
}
- Object[] args = new Object[this.operationMeta.getParamSize()];
- for (Entry<String, Object> item : swaggerArguments.entrySet()) {
- args[this.operationMeta.getParameterIndex(item.getKey())] = item.getValue();
+ this.arguments = arguments;
+ }
+
+ // TODO: WEAK add release notes to tell this change in 2.0.0
+ public Object[] toProducerArguments() {
+ Method method = ((SwaggerProducerOperation) operationMeta.getExtData(Const.PRODUCER_OPERATION)).getProducerMethod();
+ Object[] args = new Object[method.getParameterCount()];
+ // TODO: WEAK parameter name maybe override by annotations.
+ for (int i = 0; i < method.getParameterCount(); i++) {
+ args[i] = this.arguments.get(method.getParameters()[i].getName());
}
- setSwaggerArguments(args);
+ return args;
}
public Endpoint getEndpoint() {
diff --git a/core/src/main/java/org/apache/servicecomb/core/handler/impl/ProducerOperationHandler.java b/core/src/main/java/org/apache/servicecomb/core/handler/impl/ProducerOperationHandler.java
index eec75f9..21893a3 100644
--- a/core/src/main/java/org/apache/servicecomb/core/handler/impl/ProducerOperationHandler.java
+++ b/core/src/main/java/org/apache/servicecomb/core/handler/impl/ProducerOperationHandler.java
@@ -17,14 +17,30 @@
package org.apache.servicecomb.core.handler.impl;
+import java.lang.reflect.InvocationTargetException;
+import java.util.concurrent.CompletableFuture;
+
+import javax.ws.rs.core.Response.Status;
+
import org.apache.servicecomb.core.Const;
import org.apache.servicecomb.core.Handler;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.exception.ExceptionUtils;
import org.apache.servicecomb.swagger.engine.SwaggerProducerOperation;
import org.apache.servicecomb.swagger.invocation.AsyncResponse;
+import org.apache.servicecomb.swagger.invocation.Response;
+import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+import org.apache.servicecomb.swagger.invocation.context.ContextUtils;
+import org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData;
+import org.apache.servicecomb.swagger.invocation.exception.ExceptionFactory;
+import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
+import org.apache.servicecomb.swagger.invocation.extension.ProducerInvokeExtension;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class ProducerOperationHandler implements Handler {
+ private static final Logger LOGGER = LoggerFactory.getLogger(ProducerOperationHandler.class);
+
public static final ProducerOperationHandler INSTANCE = new ProducerOperationHandler();
@Override
@@ -36,6 +52,121 @@ public class ProducerOperationHandler implements Handler {
invocation.getOperationName()));
return;
}
- producerOperation.invoke(invocation, asyncResp);
+ invoke(invocation, producerOperation, asyncResp);
+ }
+
+ private void invoke(Invocation invocation, SwaggerProducerOperation producerOperation, AsyncResponse asyncResp) {
+ if (CompletableFuture.class.equals(producerOperation.getProducerMethod().getReturnType())) {
+ completableFutureInvoke(invocation, producerOperation, asyncResp);
+ return;
+ }
+
+ syncInvoke(invocation, producerOperation, asyncResp);
+ }
+
+ public void completableFutureInvoke(Invocation invocation, SwaggerProducerOperation producerOperation,
+ AsyncResponse asyncResp) {
+ ContextUtils.setInvocationContext(invocation);
+ doCompletableFutureInvoke(invocation, producerOperation, asyncResp);
+ ContextUtils.removeInvocationContext();
+ }
+
+ @SuppressWarnings("unchecked")
+ public void doCompletableFutureInvoke(Invocation invocation, SwaggerProducerOperation producerOperation,
+ AsyncResponse asyncResp) {
+ try {
+ invocation.onBusinessMethodStart();
+
+ Object[] args = invocation.toProducerArguments();
+ for (ProducerInvokeExtension producerInvokeExtension : producerOperation.getProducerInvokeExtenstionList()) {
+ producerInvokeExtension.beforeMethodInvoke(invocation, producerOperation, args);
+ }
+
+ Object result = producerOperation.getProducerMethod().invoke(producerOperation.getProducerInstance(), args);
+ invocation.onBusinessMethodFinish();
+
+ ((CompletableFuture<Object>) result).whenComplete((realResult, ex) -> {
+ invocation.onBusinessFinish();
+ if (ex == null) {
+ asyncResp.handle(producerOperation.getResponseMapper().mapResponse(invocation.getStatus(), realResult));
+ return;
+ }
+
+ asyncResp.handle(processException(invocation, ex));
+ });
+ } catch (IllegalArgumentException ae) {
+ LOGGER.error("Parameters not valid or types not match {},",
+ invocation.getInvocationQualifiedName(), ae);
+ invocation.onBusinessMethodFinish();
+ invocation.onBusinessFinish();
+ asyncResp.handle(processException(invocation,
+ new InvocationException(Status.BAD_REQUEST.getStatusCode(), "",
+ new CommonExceptionData("Parameters not valid or types not match."), ae)));
+ } catch (Throwable e) {
+ LOGGER.error("unexpected error {},",
+ invocation.getInvocationQualifiedName(), e);
+ invocation.onBusinessMethodFinish();
+ invocation.onBusinessFinish();
+ asyncResp.handle(processException(invocation, e));
+ }
+ }
+
+ public void syncInvoke(Invocation invocation, SwaggerProducerOperation producerOperation, AsyncResponse asyncResp) {
+ ContextUtils.setInvocationContext(invocation);
+ Response response = doInvoke(invocation, producerOperation);
+ ContextUtils.removeInvocationContext();
+ asyncResp.handle(response);
+ }
+
+ public Response doInvoke(Invocation invocation, SwaggerProducerOperation producerOperation) {
+ Response response;
+ try {
+ invocation.onBusinessMethodStart();
+
+ Object[] args = invocation.toProducerArguments();
+ for (ProducerInvokeExtension producerInvokeExtension : producerOperation.getProducerInvokeExtenstionList()) {
+ producerInvokeExtension.beforeMethodInvoke(invocation, producerOperation, args);
+ }
+
+ Object result = producerOperation.getProducerMethod().invoke(producerOperation.getProducerInstance(), args);
+ response = producerOperation.getResponseMapper().mapResponse(invocation.getStatus(), result);
+
+ invocation.onBusinessMethodFinish();
+ invocation.onBusinessFinish();
+ } catch (IllegalArgumentException ae) {
+ LOGGER.error("Parameters not valid or types not match {},",
+ invocation.getInvocationQualifiedName(), ae);
+ invocation.onBusinessMethodFinish();
+ invocation.onBusinessFinish();
+ // ae.getMessage() is always null. Give a custom error message.
+ response = processException(invocation,
+ new InvocationException(Status.BAD_REQUEST.getStatusCode(), "",
+ new CommonExceptionData("Parameters not valid or types not match."), ae));
+ } catch (Throwable e) {
+ if (shouldPrintErrorLog(e)) {
+ LOGGER.error("unexpected error {},",
+ invocation.getInvocationQualifiedName(), e);
+ }
+ invocation.onBusinessMethodFinish();
+ invocation.onBusinessFinish();
+ response = processException(invocation, e);
+ }
+ return response;
+ }
+
+ protected boolean shouldPrintErrorLog(Throwable throwable) {
+ if (!(throwable instanceof InvocationTargetException)) {
+ return true;
+ }
+ Throwable targetException = ((InvocationTargetException) throwable).getTargetException();
+ return !(targetException instanceof InvocationException);
+ }
+
+ protected Response processException(SwaggerInvocation invocation, Throwable e) {
+ if (e instanceof InvocationTargetException) {
+ e = ((InvocationTargetException) e).getTargetException();
+ }
+
+ return ExceptionFactory.convertExceptionToResponse(invocation, e);
}
}
diff --git a/core/src/main/java/org/apache/servicecomb/core/invocation/InvocationFactory.java b/core/src/main/java/org/apache/servicecomb/core/invocation/InvocationFactory.java
index b70b11b..53229b0 100644
--- a/core/src/main/java/org/apache/servicecomb/core/invocation/InvocationFactory.java
+++ b/core/src/main/java/org/apache/servicecomb/core/invocation/InvocationFactory.java
@@ -17,6 +17,8 @@
package org.apache.servicecomb.core.invocation;
+import java.util.Map;
+
import org.apache.servicecomb.core.Const;
import org.apache.servicecomb.core.Endpoint;
import org.apache.servicecomb.core.Invocation;
@@ -35,10 +37,10 @@ public final class InvocationFactory {
}
public static Invocation forConsumer(ReferenceConfig referenceConfig, OperationMeta operationMeta,
- Object[] swaggerArguments) {
+ Map<String, Object> arguments) {
Invocation invocation = new Invocation(referenceConfig,
operationMeta,
- swaggerArguments);
+ arguments);
invocation.addContext(Const.SRC_MICROSERVICE, getMicroserviceName());
return invocation;
}
@@ -47,9 +49,9 @@ public final class InvocationFactory {
* consumer端使用,schemaMeta级别的缓存,每次调用根据operationName来执行
*/
public static Invocation forConsumer(ReferenceConfig referenceConfig, SchemaMeta schemaMeta, String operationId,
- Object[] swaggerArguments) {
+ Map<String, Object> arguments) {
OperationMeta operationMeta = schemaMeta.ensureFindOperation(operationId);
- return forConsumer(referenceConfig, operationMeta, swaggerArguments);
+ return forConsumer(referenceConfig, operationMeta, arguments);
}
/*
@@ -57,10 +59,10 @@ public final class InvocationFactory {
*/
public static Invocation forProvider(Endpoint endpoint,
OperationMeta operationMeta,
- Object[] swaggerArguments) {
+ Map<String, Object> arguments) {
SCBEngine.getInstance().ensureStatusUp();
return new Invocation(endpoint,
operationMeta,
- swaggerArguments);
+ arguments);
}
}
diff --git a/core/src/main/java/org/apache/servicecomb/core/provider/consumer/InvokerUtils.java b/core/src/main/java/org/apache/servicecomb/core/provider/consumer/InvokerUtils.java
index 117e751..dc2a895 100644
--- a/core/src/main/java/org/apache/servicecomb/core/provider/consumer/InvokerUtils.java
+++ b/core/src/main/java/org/apache/servicecomb/core/provider/consumer/InvokerUtils.java
@@ -17,6 +17,8 @@
package org.apache.servicecomb.core.provider.consumer;
+import java.util.Map;
+
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.SCBEngine;
import org.apache.servicecomb.core.definition.MicroserviceMeta;
@@ -34,12 +36,13 @@ import org.slf4j.LoggerFactory;
public final class InvokerUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(InvokerUtils.class);
- public static Object syncInvoke(String microserviceName, String schemaId, String operationId, Object[] args) {
+ public static Object syncInvoke(String microserviceName, String schemaId, String operationId,
+ Map<String, Object> args) {
return syncInvoke(microserviceName, null, null, schemaId, operationId, args);
}
public static Object syncInvoke(String microserviceName, String microserviceVersion, String transport,
- String schemaId, String operationId, Object[] args) {
+ String schemaId, String operationId, Map<String, Object> args) {
MicroserviceReferenceConfig microserviceReferenceConfig = SCBEngine.getInstance()
.createMicroserviceReferenceConfig(microserviceName, microserviceVersion);
MicroserviceMeta microserviceMeta = microserviceReferenceConfig.getLatestMicroserviceMeta();
diff --git a/core/src/test/java/org/apache/servicecomb/core/org/apache/servicecomb/core/TestCseApplicationListener.java b/core/src/test/java/org/apache/servicecomb/core/TestCseApplicationListener.java
similarity index 96%
rename from core/src/test/java/org/apache/servicecomb/core/org/apache/servicecomb/core/TestCseApplicationListener.java
rename to core/src/test/java/org/apache/servicecomb/core/TestCseApplicationListener.java
index de7b676..33b71af 100644
--- a/core/src/test/java/org/apache/servicecomb/core/org/apache/servicecomb/core/TestCseApplicationListener.java
+++ b/core/src/test/java/org/apache/servicecomb/core/TestCseApplicationListener.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.servicecomb.core.org.apache.servicecomb.core;
+package org.apache.servicecomb.core;
import org.apache.servicecomb.core.CseApplicationListener;
import org.apache.servicecomb.core.SCBEngine;
diff --git a/core/src/test/java/org/apache/servicecomb/core/TestInvocation.java b/core/src/test/java/org/apache/servicecomb/core/TestInvocation.java
index 256dfe1..f93adc7 100644
--- a/core/src/test/java/org/apache/servicecomb/core/TestInvocation.java
+++ b/core/src/test/java/org/apache/servicecomb/core/TestInvocation.java
@@ -17,6 +17,7 @@
package org.apache.servicecomb.core;
import java.util.Arrays;
+import java.util.Map;
import javax.xml.ws.Holder;
@@ -57,7 +58,7 @@ public class TestInvocation {
OperationMeta operationMeta;
@Mocked
- Object[] swaggerArguments;
+ Map<String, Object> arguments;
static long nanoTime = 123;
@@ -93,7 +94,7 @@ public class TestInvocation {
};
EventManager.register(subscriber);
- Invocation invocation = new Invocation(endpoint, operationMeta, swaggerArguments);
+ Invocation invocation = new Invocation(endpoint, operationMeta, arguments);
invocation.onStart(nanoTime);
Assert.assertSame(invocation, result.value);
@@ -106,7 +107,7 @@ public class TestInvocation {
public void onStartExecute() {
mockNonaTime();
- Invocation invocation = new Invocation(endpoint, operationMeta, swaggerArguments);
+ Invocation invocation = new Invocation(endpoint, operationMeta, arguments);
invocation.onExecuteStart();
Assert.assertEquals(nanoTime, invocation.getInvocationStageTrace().getStartExecution());
@@ -125,7 +126,7 @@ public class TestInvocation {
};
EventManager.register(subscriber);
- Invocation invocation = new Invocation(endpoint, operationMeta, swaggerArguments);
+ Invocation invocation = new Invocation(endpoint, operationMeta, arguments);
Assert.assertFalse(invocation.isFinished());
Response response = Response.succResp(null);
invocation.onFinish(response);
@@ -145,19 +146,19 @@ public class TestInvocation {
@Test
public void isConsumer_yes() {
- Invocation invocation = new Invocation(endpoint, operationMeta, swaggerArguments);
+ Invocation invocation = new Invocation(endpoint, operationMeta, arguments);
Assert.assertFalse(invocation.isConsumer());
}
@Test
public void isConsumer_no(@Mocked ReferenceConfig referenceConfig) {
- Invocation invocation = new Invocation(referenceConfig, operationMeta, swaggerArguments);
+ Invocation invocation = new Invocation(referenceConfig, operationMeta, arguments);
Assert.assertTrue(invocation.isConsumer());
}
@Test
public void localContext(@Mocked ReferenceConfig referenceConfig) {
- Invocation invocation = new Invocation(referenceConfig, operationMeta, swaggerArguments);
+ Invocation invocation = new Invocation(referenceConfig, operationMeta, arguments);
invocation.addLocalContext("k", 1);
Assert.assertSame(invocation.getHandlerContext(), invocation.getLocalContext());
@@ -166,7 +167,7 @@ public class TestInvocation {
@Test
public void traceId_fromContext(@Mocked ReferenceConfig referenceConfig) {
- Invocation invocation = new Invocation(referenceConfig, operationMeta, swaggerArguments);
+ Invocation invocation = new Invocation(referenceConfig, operationMeta, arguments);
invocation.addContext(Const.TRACE_ID_NAME, "abc");
invocation.onStart(0);
@@ -184,7 +185,7 @@ public class TestInvocation {
result = "abc";
}
};
- Invocation invocation = new Invocation(referenceConfig, operationMeta, swaggerArguments);
+ Invocation invocation = new Invocation(referenceConfig, operationMeta, arguments);
invocation.onStart(0);
@@ -200,7 +201,7 @@ public class TestInvocation {
result = "abc";
}
};
- Invocation invocation = new Invocation(endpoint, operationMeta, swaggerArguments);
+ Invocation invocation = new Invocation(endpoint, operationMeta, arguments);
invocation.onStart(requestEx, 0);
@@ -217,7 +218,7 @@ public class TestInvocation {
result = "abc";
}
};
- Invocation invocation = new Invocation(endpoint, operationMeta, swaggerArguments);
+ Invocation invocation = new Invocation(endpoint, operationMeta, arguments);
invocation.onStart(requestEx, 0);
@@ -261,7 +262,7 @@ public class TestInvocation {
}
};
EventManager.getEventBus().register(listener);
- Invocation invocation = new Invocation(endpoint, operationMeta, swaggerArguments);
+ Invocation invocation = new Invocation(endpoint, operationMeta, arguments);
mockNonaTime();
invocation.onBusinessMethodStart();
EventManager.getEventBus().unregister(listener);
@@ -279,7 +280,7 @@ public class TestInvocation {
}
};
EventManager.getEventBus().register(listener);
- Invocation invocation = new Invocation(endpoint, operationMeta, swaggerArguments);
+ Invocation invocation = new Invocation(endpoint, operationMeta, arguments);
invocation.onBusinessMethodFinish();
EventManager.getEventBus().unregister(listener);
@@ -288,7 +289,7 @@ public class TestInvocation {
@Test
public void onBusinessFinish() {
- Invocation invocation = new Invocation(endpoint, operationMeta, swaggerArguments);
+ Invocation invocation = new Invocation(endpoint, operationMeta, arguments);
mockNonaTime();
invocation.onBusinessFinish();
@@ -299,13 +300,13 @@ public class TestInvocation {
public void marker(@Mocked ReferenceConfig referenceConfig) {
Invocation.INVOCATION_ID.set(0);
- Invocation invocation = new Invocation(referenceConfig, operationMeta, swaggerArguments);
+ Invocation invocation = new Invocation(referenceConfig, operationMeta, arguments);
invocation.addContext(Const.TRACE_ID_NAME, "abc");
invocation.onStart(0);
Assert.assertEquals("abc-0", invocation.getMarker().toString());
Assert.assertEquals("abc-0", invocation.getMarker().getName());
- invocation = new Invocation(referenceConfig, operationMeta, swaggerArguments);
+ invocation = new Invocation(referenceConfig, operationMeta, arguments);
invocation.addContext(Const.TRACE_ID_NAME, "abc");
invocation.onStart(0);
Assert.assertEquals("abc-1", invocation.getMarker().toString());
@@ -314,7 +315,7 @@ public class TestInvocation {
@Test
public void isThirdPartyInvocation(@Mocked ReferenceConfig referenceConfig) {
- Invocation invocation = new Invocation(referenceConfig, operationMeta, swaggerArguments);
+ Invocation invocation = new Invocation(referenceConfig, operationMeta, arguments);
Assert.assertFalse(invocation.isThirdPartyInvocation());
new Expectations() {
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ArgumentsMapperDirectReuse.java b/core/src/test/java/org/apache/servicecomb/core/handler/impl/ErrorToProducerResponseConverter.java
similarity index 60%
rename from swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ArgumentsMapperDirectReuse.java
rename to core/src/test/java/org/apache/servicecomb/core/handler/impl/ErrorToProducerResponseConverter.java
index 704e297..373d7d8 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ArgumentsMapperDirectReuse.java
+++ b/core/src/test/java/org/apache/servicecomb/core/handler/impl/ErrorToProducerResponseConverter.java
@@ -14,13 +14,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.servicecomb.swagger.invocation.arguments.consumer;
+package org.apache.servicecomb.core.handler.impl;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.servicecomb.swagger.invocation.Response;
import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
+import org.apache.servicecomb.swagger.invocation.exception.ExceptionToProducerResponseConverter;
+
+public class ErrorToProducerResponseConverter implements ExceptionToProducerResponseConverter<Error> {
+ @Override
+ public Class<Error> getExceptionClass() {
+ return Error.class;
+ }
-public class ArgumentsMapperDirectReuse implements ConsumerArgumentsMapper {
@Override
- public void toInvocation(Object[] consumerArguments, SwaggerInvocation invocation) {
- invocation.setSwaggerArguments(consumerArguments);
+ public Response convert(SwaggerInvocation swaggerInvocation, Error e) {
+ return Response.create(Status.OK, "response from error: " + e.getMessage());
}
}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/engine/TestSwaggerProducerOperation.java b/core/src/test/java/org/apache/servicecomb/core/handler/impl/TestProducerOperationHandler.java
similarity index 81%
rename from swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/engine/TestSwaggerProducerOperation.java
rename to core/src/test/java/org/apache/servicecomb/core/handler/impl/TestProducerOperationHandler.java
index 3ea0bf1..104f57c 100644
--- a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/engine/TestSwaggerProducerOperation.java
+++ b/core/src/test/java/org/apache/servicecomb/core/handler/impl/TestProducerOperationHandler.java
@@ -14,7 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.servicecomb.swagger.engine;
+
+package org.apache.servicecomb.core.handler.impl;
import java.lang.reflect.InvocationTargetException;
@@ -27,14 +28,15 @@ import org.junit.Test;
import mockit.Mocked;
-public class TestSwaggerProducerOperation {
- SwaggerProducerOperation swaggerProducerOperation = new SwaggerProducerOperation();
+// test cases copied from delete class, this test case tests ExceptionToProducerResponseConverter
+public class TestProducerOperationHandler {
+ ProducerOperationHandler handler = new ProducerOperationHandler();
@Test
public void processException_normal(@Mocked SwaggerInvocation invocation) {
Error error = new Error("abc");
- Response response = swaggerProducerOperation.processException(invocation, error);
+ Response response = handler.processException(invocation, error);
Assert.assertSame(Status.OK, response.getStatus());
Assert.assertEquals("response from error: abc", response.getResult());
}
@@ -44,7 +46,7 @@ public class TestSwaggerProducerOperation {
Error error = new Error("abc");
InvocationTargetException targetException = new InvocationTargetException(error);
- Response response = swaggerProducerOperation.processException(invocation, targetException);
+ Response response = handler.processException(invocation, error);
Assert.assertSame(Status.OK, response.getStatus());
Assert.assertEquals("response from error: abc", response.getResult());
}
diff --git a/core/src/test/java/org/apache/servicecomb/core/invocation/TestInvocationStageTrace.java b/core/src/test/java/org/apache/servicecomb/core/invocation/TestInvocationStageTrace.java
index 64c468d..483a6ef 100644
--- a/core/src/test/java/org/apache/servicecomb/core/invocation/TestInvocationStageTrace.java
+++ b/core/src/test/java/org/apache/servicecomb/core/invocation/TestInvocationStageTrace.java
@@ -16,6 +16,9 @@
*/
package org.apache.servicecomb.core.invocation;
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.servicecomb.core.Endpoint;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.definition.OperationMeta;
@@ -42,7 +45,7 @@ public class TestInvocationStageTrace {
@Mocked
OperationMeta operationMeta;
- Object[] args = new Object[] {};
+ Map<String, Object> args = new HashMap<>();
static long nanoTime = 0;
diff --git a/core/src/test/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.exception.ExceptionToProducerResponseConverter b/core/src/test/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.exception.ExceptionToProducerResponseConverter
new file mode 100644
index 0000000..ff338ab
--- /dev/null
+++ b/core/src/test/resources/META-INF/services/org.apache.servicecomb.swagger.invocation.exception.ExceptionToProducerResponseConverter
@@ -0,0 +1,18 @@
+#
+# 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.
+# The ASF licenses this file to You 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.
+#
+
+org.apache.servicecomb.core.handler.impl.ErrorToProducerResponseConverter
\ No newline at end of file
diff --git a/demo/demo-pojo/pojo-client/src/main/java/org/apache/servicecomb/demo/pojo/client/PojoClient.java b/demo/demo-pojo/pojo-client/src/main/java/org/apache/servicecomb/demo/pojo/client/PojoClient.java
index b96d77a..c3f35b1 100644
--- a/demo/demo-pojo/pojo-client/src/main/java/org/apache/servicecomb/demo/pojo/client/PojoClient.java
+++ b/demo/demo-pojo/pojo-client/src/main/java/org/apache/servicecomb/demo/pojo/client/PojoClient.java
@@ -19,9 +19,10 @@ package org.apache.servicecomb.demo.pojo.client;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Set;
-import java.util.stream.IntStream;
import javax.inject.Inject;
@@ -224,16 +225,22 @@ public class PojoClient {
}
private static void testCommonInvoke(String transport) {
- Object result = InvokerUtils.syncInvoke("pojo", "server", "splitParam", new Object[] {2, new User()});
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("index", 2);
+ arguments.put("user", new User());
+ Object result = InvokerUtils.syncInvoke("pojo", "server", "splitParam", arguments);
TestMgr.check("User [name=nameA, users count:0, age=100, index=2]", result);
+ arguments = new HashMap<>();
+ arguments.put("index", 3);
+ arguments.put("user", new User());
result =
InvokerUtils.syncInvoke("pojo",
"0.0.4",
transport,
"server",
"splitParam",
- new Object[] {3, new User()});
+ arguments);
TestMgr.check("User [name=nameA, users count:0, age=100, index=3]", result);
}
diff --git a/demo/demo-spring-boot-transport/demo-spring-boot-pojo-client/src/main/java/org/apache/servicecomb/demo/pojo/client/PojoClientTest.java b/demo/demo-spring-boot-transport/demo-spring-boot-pojo-client/src/main/java/org/apache/servicecomb/demo/pojo/client/PojoClientTest.java
index 40f63a7..c9ec6a4 100644
--- a/demo/demo-spring-boot-transport/demo-spring-boot-pojo-client/src/main/java/org/apache/servicecomb/demo/pojo/client/PojoClientTest.java
+++ b/demo/demo-spring-boot-transport/demo-spring-boot-pojo-client/src/main/java/org/apache/servicecomb/demo/pojo/client/PojoClientTest.java
@@ -18,6 +18,8 @@
package org.apache.servicecomb.demo.pojo.client;
import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
import org.apache.servicecomb.core.provider.consumer.InvokerUtils;
import org.apache.servicecomb.demo.DemoConst;
@@ -90,17 +92,24 @@ public class PojoClientTest {
}
private static void testCommonInvoke(String transport) {
- Object result = InvokerUtils.syncInvoke("pojo", "server", "splitParam", new Object[] {2, new User()});
+ Map<String, Object> arguments = new HashMap<>();
+ arguments.put("index", 2);
+ arguments.put("user", new User());
+
+ Object result = InvokerUtils.syncInvoke("pojo", "server", "splitParam", arguments);
TestMgr.check("User [name=nameA, users count:0" + SPLITPARAM_RESPONSE_USER_SUFFIX
+ ", age=100, index=2]", result);
+ arguments = new HashMap<>();
+ arguments.put("index", 3);
+ arguments.put("user", new User());
result =
InvokerUtils.syncInvoke("pojo",
"0.0.1",
transport,
"server",
"splitParam",
- new Object[] {3, new User()});
+ arguments);
TestMgr.check("User [name=nameA, users count:0" + SPLITPARAM_RESPONSE_USER_SUFFIX
+ ", age=100, index=3]", result);
}
diff --git a/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadBalanceHandler2.java b/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadBalanceHandler2.java
index 77bcc8b..f7f3563 100644
--- a/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadBalanceHandler2.java
+++ b/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestLoadBalanceHandler2.java
@@ -118,7 +118,7 @@ public class TestLoadBalanceHandler2 {
when(microserviceMeta.getAppId()).thenReturn("testApp");
when(referenceConfig.getVersionRule()).thenReturn("0.0.0+");
when(referenceConfig.getTransport()).thenReturn("rest");
- Invocation invocation = new Invocation(referenceConfig, operationMeta, new Object[0]);
+ Invocation invocation = new Invocation(referenceConfig, operationMeta, new HashMap<>());
InstanceCacheManager instanceCacheManager = Mockito.mock(InstanceCacheManager.class);
ServiceRegistry serviceRegistry = Mockito.mock(ServiceRegistry.class);
@@ -253,7 +253,7 @@ public class TestLoadBalanceHandler2 {
when(microserviceMeta.getAppId()).thenReturn("testApp");
when(referenceConfig.getVersionRule()).thenReturn("0.0.0+");
when(referenceConfig.getTransport()).thenReturn("rest");
- Invocation invocation = new Invocation(referenceConfig, operationMeta, new Object[0]);
+ Invocation invocation = new Invocation(referenceConfig, operationMeta, new HashMap<>());
InstanceCacheManager instanceCacheManager = Mockito.mock(InstanceCacheManager.class);
ServiceRegistry serviceRegistry = Mockito.mock(ServiceRegistry.class);
@@ -348,7 +348,7 @@ public class TestLoadBalanceHandler2 {
when(microserviceMeta.getAppId()).thenReturn("testApp");
when(referenceConfig.getVersionRule()).thenReturn("0.0.0+");
when(referenceConfig.getTransport()).thenReturn("rest");
- Invocation invocation = new Invocation(referenceConfig, operationMeta, new Object[0]);
+ Invocation invocation = new Invocation(referenceConfig, operationMeta, new HashMap<>());
InstanceCacheManager instanceCacheManager = Mockito.mock(InstanceCacheManager.class);
ServiceRegistry serviceRegistry = Mockito.mock(ServiceRegistry.class);
@@ -768,7 +768,7 @@ public class TestLoadBalanceHandler2 {
when(microserviceMeta.getAppId()).thenReturn("testApp");
when(referenceConfig.getVersionRule()).thenReturn("0.0.0+");
when(referenceConfig.getTransport()).thenReturn("rest");
- Invocation invocation = new Invocation(referenceConfig, operationMeta, new Object[0]);
+ Invocation invocation = new Invocation(referenceConfig, operationMeta, new HashMap<>());
AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
InstanceCacheManager instanceCacheManager = Mockito.mock(InstanceCacheManager.class);
diff --git a/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/Invoker.java b/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/Invoker.java
index a9ddaaf..d7f8d9e 100644
--- a/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/Invoker.java
+++ b/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/Invoker.java
@@ -20,6 +20,8 @@ package org.apache.servicecomb.provider.pojo;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
+import java.util.HashMap;
+import java.util.Map;
import java.util.concurrent.CompletableFuture;
import javax.ws.rs.core.Response.Status;
@@ -165,7 +167,7 @@ public class Invoker implements InvocationHandler {
operationMeta,
null);
invocation.setResponsesMeta(pojoConsumerOperationMeta.getResponsesMeta());
- invocation.setSwaggerArguments(args);
+ invocation.setArguments(toArguments(method, args));
if (CompletableFuture.class.equals(method.getReturnType())) {
return completableFutureInvoke(invocation, consumerOperation);
@@ -174,6 +176,16 @@ public class Invoker implements InvocationHandler {
return syncInvoke(invocation, consumerOperation);
}
+
+ public Map<String, Object> toArguments(Method method, Object[] args) {
+ Map<String, Object> arguments = new HashMap<>();
+ // TODO: WEAK parameter name maybe override by annotations.
+ for (int i = 0; i < method.getParameterCount(); i++) {
+ arguments.put(method.getParameters()[i].getName(), args[i]);
+ }
+ return arguments;
+ }
+
protected ReferenceConfig findReferenceConfig(OperationMeta operationMeta) {
return consumerMeta.getMicroserviceReferenceConfig().createReferenceConfig(operationMeta);
}
diff --git a/providers/provider-rest-common/src/main/java/org/apache/servicecomb/provider/rest/common/InvocationToHttpServletRequest.java b/providers/provider-rest-common/src/main/java/org/apache/servicecomb/provider/rest/common/InvocationToHttpServletRequest.java
index 7bca4a8..c2f86d7 100644
--- a/providers/provider-rest-common/src/main/java/org/apache/servicecomb/provider/rest/common/InvocationToHttpServletRequest.java
+++ b/providers/provider-rest-common/src/main/java/org/apache/servicecomb/provider/rest/common/InvocationToHttpServletRequest.java
@@ -36,13 +36,13 @@ import io.vertx.core.net.SocketAddress;
public class InvocationToHttpServletRequest extends AbstractHttpServletRequest {
private RestOperationMeta swaggerOperation;
- private Object[] args;
+ private Map<String, Object> args;
private SocketAddress sockerAddress;
public InvocationToHttpServletRequest(Invocation invocation) {
this.swaggerOperation = invocation.getOperationMeta().getExtData(RestConst.SWAGGER_REST_OPERATION);
- this.args = invocation.getArgs();
+ this.args = invocation.getArguments();
this.sockerAddress = (SocketAddress) invocation.getHandlerContext().get(Const.REMOTE_ADDRESS);
}
diff --git a/providers/provider-rest-common/src/test/java/org/apache/servicecomb/provider/rest/common/TestInvocationToHttpServletRequest.java b/providers/provider-rest-common/src/test/java/org/apache/servicecomb/provider/rest/common/TestInvocationToHttpServletRequest.java
index 79c1c90..87daa70 100644
--- a/providers/provider-rest-common/src/test/java/org/apache/servicecomb/provider/rest/common/TestInvocationToHttpServletRequest.java
+++ b/providers/provider-rest-common/src/test/java/org/apache/servicecomb/provider/rest/common/TestInvocationToHttpServletRequest.java
@@ -32,6 +32,7 @@ import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.definition.OperationMeta;
import org.apache.servicecomb.foundation.common.exceptions.ServiceCombException;
import org.hamcrest.Matchers;
+import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -50,8 +51,7 @@ public class TestInvocationToHttpServletRequest {
@Mocked
RestOperationMeta swaggerOperation;
- @Mocked
- Object[] args;
+ Map<String, Object> args;
@Mocked
SocketAddress socketAddress;
@@ -63,22 +63,29 @@ public class TestInvocationToHttpServletRequest {
@Before
public void setup() {
handlerContext.put(Const.REMOTE_ADDRESS, socketAddress);
+ args = new HashMap<>();
+
new Expectations() {
{
invocation.getOperationMeta();
result = operationMeta;
operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
result = swaggerOperation;
- invocation.getArgs();
- result = args;
invocation.getHandlerContext();
result = handlerContext;
+ invocation.getArguments();
+ result = args;
}
};
request = new InvocationToHttpServletRequest(invocation);
}
+ @After
+ public void tearDown() {
+
+ }
+
@Test
public void testGetParameterNotFound() {
new Expectations() {
@@ -302,7 +309,7 @@ public class TestInvocationToHttpServletRequest {
result = operationMeta;
operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
result = swaggerOperation;
- invocation.getArgs();
+ invocation.getArguments();
result = args;
invocation.getHandlerContext();
result = handlerContext;
diff --git a/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/CseClientHttpRequest.java b/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/CseClientHttpRequest.java
index 2c9cd53..f0810a1 100644
--- a/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/CseClientHttpRequest.java
+++ b/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/CseClientHttpRequest.java
@@ -173,10 +173,10 @@ public class CseClientHttpRequest implements ClientHttpRequest {
QueryStringDecoder queryStringDecoder = new QueryStringDecoder(uri.getRawSchemeSpecificPart());
queryParams = queryStringDecoder.parameters();
- Object[] args = this.collectArguments();
+ Map<String, Object> arguments = this.collectArguments();
// 异常流程,直接抛异常出去
- return this.invoke(args);
+ return this.invoke(arguments);
}
protected RequestMeta createRequestMeta(String httpMethod, URI uri) {
@@ -207,11 +207,11 @@ public class CseClientHttpRequest implements ClientHttpRequest {
return uri.getRawPath();
}
- protected Invocation prepareInvocation(Object[] args) {
+ protected Invocation prepareInvocation(Map<String, Object> arguments) {
Invocation invocation =
InvocationFactory.forConsumer(requestMeta.getReferenceConfig(),
requestMeta.getOperationMeta(),
- args);
+ arguments);
invocation.getHandlerContext().put(RestConst.REST_CLIENT_REQUEST_PATH,
path + (this.uri.getRawQuery() == null ? "" : "?" + this.uri.getRawQuery()));
@@ -233,8 +233,8 @@ public class CseClientHttpRequest implements ClientHttpRequest {
return invocation;
}
- private CseClientHttpResponse invoke(Object[] args) {
- Invocation invocation = prepareInvocation(args);
+ private CseClientHttpResponse invoke(Map<String, Object> arguments) {
+ Invocation invocation = prepareInvocation(arguments);
Response response = doInvoke(invocation);
if (response.isSuccessed()) {
@@ -248,7 +248,7 @@ public class CseClientHttpRequest implements ClientHttpRequest {
return InvokerUtils.innerSyncInvoke(invocation);
}
- protected Object[] collectArguments() {
+ protected Map<String, Object> collectArguments() {
HttpServletRequest mockRequest = new CommonToHttpServletRequest(requestMeta.getPathParams(), queryParams,
httpHeaders, requestBody, requestMeta.getSwaggerRestOperation().isFormData(),
requestMeta.getSwaggerRestOperation().getFileKeys());
diff --git a/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/async/CseAsyncClientHttpRequest.java b/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/async/CseAsyncClientHttpRequest.java
index 489832e..fc8250b 100644
--- a/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/async/CseAsyncClientHttpRequest.java
+++ b/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/async/CseAsyncClientHttpRequest.java
@@ -19,6 +19,7 @@ package org.apache.servicecomb.provider.springmvc.reference.async;
import java.io.OutputStream;
import java.net.URI;
+import java.util.Map;
import java.util.concurrent.CompletableFuture;
import org.apache.servicecomb.common.rest.RestConst;
@@ -52,7 +53,7 @@ public class CseAsyncClientHttpRequest extends CseClientHttpRequest implements
return null;
}
- private ListenableFuture<ClientHttpResponse> invoke(Object[] args) {
+ private ListenableFuture<ClientHttpResponse> invoke(Map<String, Object> args) {
Invocation invocation = prepareInvocation(args);
invocation.getHandlerContext().put(RestConst.CONSUMER_HEADER, this.getHeaders());
CompletableFuture<ClientHttpResponse> clientHttpResponseCompletableFuture = doAsyncInvoke(invocation);
@@ -78,7 +79,7 @@ public class CseAsyncClientHttpRequest extends CseClientHttpRequest implements
this.setRequestMeta(createRequestMeta(this.getMethod().name(), this.getURI()));
QueryStringDecoder queryStringDecoder = new QueryStringDecoder(this.getURI().getRawSchemeSpecificPart());
this.setQueryParams(queryStringDecoder.parameters());
- Object[] args = this.collectArguments();
+ Map<String, Object> args = this.collectArguments();
return this.invoke(args);
}
}
diff --git a/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestCseClientHttpRequest.java b/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestCseClientHttpRequest.java
index 25602ac..a09e6d1 100644
--- a/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestCseClientHttpRequest.java
+++ b/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestCseClientHttpRequest.java
@@ -83,7 +83,7 @@ public class TestCseClientHttpRequest {
client.execute();
- Assert.assertArrayEquals(body, holder.value.getSwaggerArgument(0));
- Assert.assertEquals("123", holder.value.getSwaggerArgument(1));
+ Assert.assertArrayEquals(body, (byte[] )holder.value.getArguments().get("input"));
+ Assert.assertEquals("123", holder.value.getArguments().get("token"));
}
}
diff --git a/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestUrlWithProviderPrefixClientHttpRequestFactory.java b/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestUrlWithProviderPrefixClientHttpRequestFactory.java
index 4483540..035ea4b 100644
--- a/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestUrlWithProviderPrefixClientHttpRequestFactory.java
+++ b/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestUrlWithProviderPrefixClientHttpRequestFactory.java
@@ -65,7 +65,7 @@ public class TestUrlWithProviderPrefixClientHttpRequestFactory {
{
invocation.getHandlerContext();
result = handlerContext;
- InvocationFactory.forConsumer((ReferenceConfig) any, (OperationMeta) any, (Object[]) any);
+ InvocationFactory.forConsumer((ReferenceConfig) any, (OperationMeta) any, (Map<String, Object>) any);
result = invocation;
}
};
@@ -73,7 +73,7 @@ public class TestUrlWithProviderPrefixClientHttpRequestFactory {
Deencapsulation.setField(request, "requestMeta", requestMeta);
Deencapsulation.setField(request, "path", request.findUriPath(uri));
- Deencapsulation.invoke(request, "invoke", new Object[] {new Object[] {}});
+ Deencapsulation.invoke(request, "invoke", new HashMap<>());
Assert.assertEquals("/v1/path", handlerContext.get(RestConst.REST_CLIENT_REQUEST_PATH));
}
diff --git a/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestUrlWithServiceNameClientHttpRequestFactory.java b/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestUrlWithServiceNameClientHttpRequestFactory.java
index 2442945..7e98202 100644
--- a/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestUrlWithServiceNameClientHttpRequestFactory.java
+++ b/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestUrlWithServiceNameClientHttpRequestFactory.java
@@ -64,7 +64,7 @@ public class TestUrlWithServiceNameClientHttpRequestFactory {
{
invocation.getHandlerContext();
result = handlerContext;
- InvocationFactory.forConsumer((ReferenceConfig) any, (OperationMeta) any, (Object[]) any);
+ InvocationFactory.forConsumer((ReferenceConfig) any, (OperationMeta) any, (Map<String, Object>) any);
result = invocation;
}
};
@@ -72,7 +72,7 @@ public class TestUrlWithServiceNameClientHttpRequestFactory {
Deencapsulation.setField(request, "requestMeta", requestMeta);
Deencapsulation.setField(request, "path", request.findUriPath(uri));
- Deencapsulation.invoke(request, "invoke", new Object[] {new Object[] {}});
+ Deencapsulation.invoke(request, "invoke", new HashMap<>());
Assert.assertEquals("/ms/v1/path", handlerContext.get(RestConst.REST_CLIENT_REQUEST_PATH));
}
diff --git a/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/async/CseAsyncClientHttpRequestTest.java b/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/async/CseAsyncClientHttpRequestTest.java
index 2c27829..05e3ad3 100644
--- a/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/async/CseAsyncClientHttpRequestTest.java
+++ b/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/async/CseAsyncClientHttpRequestTest.java
@@ -82,7 +82,7 @@ public class CseAsyncClientHttpRequestTest {
byte[] body = "abc".getBytes();
client.setRequestBody(body);
client.executeAsync();
- Assert.assertArrayEquals(body, holder.value.getSwaggerArgument(0));
+ Assert.assertArrayEquals(body, ( byte[])holder.value.getArguments().get("input"));
}
@Test
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerEnvironment.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerEnvironment.java
index 953e76b..d04f2fa 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerEnvironment.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerEnvironment.java
@@ -29,11 +29,7 @@ import org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation;
import org.apache.servicecomb.swagger.generator.core.model.SwaggerOperations;
import org.apache.servicecomb.swagger.generator.core.utils.MethodUtils;
import org.apache.servicecomb.swagger.invocation.arguments.ContextArgumentMapperFactory;
-import org.apache.servicecomb.swagger.invocation.arguments.consumer.ConsumerArgumentsMapper;
-import org.apache.servicecomb.swagger.invocation.arguments.consumer.ConsumerArgumentsMapperCreator;
import org.apache.servicecomb.swagger.invocation.arguments.consumer.ConsumerContextArgumentMapperFactory;
-import org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerArgumentsMapper;
-import org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerArgumentsMapperCreator;
import org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerContextArgumentMapperFactory;
import org.apache.servicecomb.swagger.invocation.response.ResponseMapperFactorys;
import org.apache.servicecomb.swagger.invocation.response.consumer.ConsumerResponseMapper;
@@ -44,7 +40,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.swagger.models.Swagger;
-import io.swagger.util.Json;
public class SwaggerEnvironment {
private static final Logger LOGGER = LoggerFactory.getLogger(SwaggerEnvironment.class);
@@ -73,19 +68,12 @@ public class SwaggerEnvironment {
continue;
}
- ConsumerArgumentsMapperCreator creator = new ConsumerArgumentsMapperCreator(
- Json.mapper().getSerializationConfig(),
- contextFactorys,
- consumerMethod,
- swaggerOperation);
- ConsumerArgumentsMapper argsMapper = creator.createArgumentsMapper();
ConsumerResponseMapper responseMapper = consumerResponseMapperFactorys
.createResponseMapper(consumerMethod.getGenericReturnType());
SwaggerConsumerOperation op = new SwaggerConsumerOperation();
op.setConsumerMethod(consumerMethod);
op.setSwaggerOperation(swaggerOperation);
- op.setArgumentsMapper(argsMapper);
op.setResponseMapper(responseMapper);
consumer.addOperation(op);
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerProducerOperation.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerProducerOperation.java
index 3caf8fd..49bd095 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerProducerOperation.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/engine/SwaggerProducerOperation.java
@@ -16,24 +16,13 @@
*/
package org.apache.servicecomb.swagger.engine;
-import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.List;
-import java.util.concurrent.CompletableFuture;
-
-import javax.ws.rs.core.Response.Status;
import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
import org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation;
-import org.apache.servicecomb.swagger.invocation.AsyncResponse;
-import org.apache.servicecomb.swagger.invocation.Response;
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
import org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerArgumentsMapper;
-import org.apache.servicecomb.swagger.invocation.context.ContextUtils;
-import org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData;
-import org.apache.servicecomb.swagger.invocation.exception.ExceptionFactory;
-import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.apache.servicecomb.swagger.invocation.extension.ProducerInvokeExtension;
import org.apache.servicecomb.swagger.invocation.response.producer.ProducerResponseMapper;
import org.slf4j.Logger;
@@ -51,13 +40,6 @@ public class SwaggerProducerOperation {
private SwaggerOperation swaggerOperation;
- // swagger parameter types relate to producer
- // because features of @BeanParam/query wrapper/rpc mode parameter wrapper
- // types is not direct equals to producerMethod parameter types
- private Type[] swaggerParameterTypes;
-
- private ProducerArgumentsMapper argumentsMapper;
-
private ProducerResponseMapper responseMapper;
private List<ProducerInvokeExtension> producerInvokeExtenstionList =
@@ -99,22 +81,6 @@ public class SwaggerProducerOperation {
this.swaggerOperation = swaggerOperation;
}
- public Type[] getSwaggerParameterTypes() {
- return swaggerParameterTypes;
- }
-
- public void setSwaggerParameterTypes(Type[] swaggerParameterTypes) {
- this.swaggerParameterTypes = swaggerParameterTypes;
- }
-
- public ProducerArgumentsMapper getArgumentsMapper() {
- return argumentsMapper;
- }
-
- public void setArgumentsMapper(ProducerArgumentsMapper argumentsMapper) {
- this.argumentsMapper = argumentsMapper;
- }
-
public ProducerResponseMapper getResponseMapper() {
return responseMapper;
}
@@ -123,116 +89,7 @@ public class SwaggerProducerOperation {
this.responseMapper = responseMapper;
}
- public void invoke(SwaggerInvocation invocation, AsyncResponse asyncResp) {
- if (CompletableFuture.class.equals(producerMethod.getReturnType())) {
- completableFutureInvoke(invocation, asyncResp);
- return;
- }
-
- syncInvoke(invocation, asyncResp);
- }
-
- public void completableFutureInvoke(SwaggerInvocation invocation, AsyncResponse asyncResp) {
- ContextUtils.setInvocationContext(invocation);
- doCompletableFutureInvoke(invocation, asyncResp);
- ContextUtils.removeInvocationContext();
- }
-
- @SuppressWarnings("unchecked")
- public void doCompletableFutureInvoke(SwaggerInvocation invocation, AsyncResponse asyncResp) {
- try {
- invocation.onBusinessMethodStart();
-
- Object[] args = argumentsMapper.toProducerArgs(invocation);
- for (ProducerInvokeExtension producerInvokeExtension : producerInvokeExtenstionList) {
- producerInvokeExtension.beforeMethodInvoke(invocation, this, args);
- }
-
- Object result = producerMethod.invoke(producerInstance, args);
- invocation.onBusinessMethodFinish();
-
- ((CompletableFuture<Object>) result).whenComplete((realResult, ex) -> {
- invocation.onBusinessFinish();
- if (ex == null) {
- asyncResp.handle(responseMapper.mapResponse(invocation.getStatus(), realResult));
- return;
- }
-
- asyncResp.handle(processException(invocation, ex));
- });
- } catch (IllegalArgumentException ae) {
- LOGGER.error("Parameters not valid or types not match {},",
- invocation.getInvocationQualifiedName(), ae);
- invocation.onBusinessMethodFinish();
- invocation.onBusinessFinish();
- asyncResp.handle(processException(invocation,
- new InvocationException(Status.BAD_REQUEST.getStatusCode(), "",
- new CommonExceptionData("Parameters not valid or types not match."), ae)));
- } catch (Throwable e) {
- LOGGER.error("unexpected error {},",
- invocation.getInvocationQualifiedName(), e);
- invocation.onBusinessMethodFinish();
- invocation.onBusinessFinish();
- asyncResp.handle(processException(invocation, e));
- }
- }
-
- public void syncInvoke(SwaggerInvocation invocation, AsyncResponse asyncResp) {
- ContextUtils.setInvocationContext(invocation);
- Response response = doInvoke(invocation);
- ContextUtils.removeInvocationContext();
- asyncResp.handle(response);
- }
-
- public Response doInvoke(SwaggerInvocation invocation) {
- Response response;
- try {
- invocation.onBusinessMethodStart();
-
- Object[] args = invocation.getSwaggerArguments();
- for (ProducerInvokeExtension producerInvokeExtension : producerInvokeExtenstionList) {
- producerInvokeExtension.beforeMethodInvoke(invocation, this, args);
- }
-
- Object result = producerMethod.invoke(producerInstance, args);
- response = responseMapper.mapResponse(invocation.getStatus(), result);
-
- invocation.onBusinessMethodFinish();
- invocation.onBusinessFinish();
- } catch (IllegalArgumentException ae) {
- LOGGER.error("Parameters not valid or types not match {},",
- invocation.getInvocationQualifiedName(), ae);
- invocation.onBusinessMethodFinish();
- invocation.onBusinessFinish();
- // ae.getMessage() is always null. Give a custom error message.
- response = processException(invocation,
- new InvocationException(Status.BAD_REQUEST.getStatusCode(), "",
- new CommonExceptionData("Parameters not valid or types not match."), ae));
- } catch (Throwable e) {
- if (shouldPrintErrorLog(e)) {
- LOGGER.error("unexpected error {},",
- invocation.getInvocationQualifiedName(), e);
- }
- invocation.onBusinessMethodFinish();
- invocation.onBusinessFinish();
- response = processException(invocation, e);
- }
- return response;
- }
-
- protected boolean shouldPrintErrorLog(Throwable throwable) {
- if (!(throwable instanceof InvocationTargetException)) {
- return true;
- }
- Throwable targetException = ((InvocationTargetException) throwable).getTargetException();
- return !(targetException instanceof InvocationException);
- }
-
- protected Response processException(SwaggerInvocation invocation, Throwable e) {
- if (e instanceof InvocationTargetException) {
- e = ((InvocationTargetException) e).getTargetException();
- }
-
- return ExceptionFactory.convertExceptionToResponse(invocation, e);
+ public List<ProducerInvokeExtension> getProducerInvokeExtenstionList() {
+ return this.producerInvokeExtenstionList;
}
}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/SwaggerInvocation.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/SwaggerInvocation.java
index 47a5994..a6df86d 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/SwaggerInvocation.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/SwaggerInvocation.java
@@ -24,13 +24,6 @@ public class SwaggerInvocation extends InvocationContext {
// 本实例是在consumer端,还是在provider端
protected InvocationType invocationType;
- // highway consumer and all producer need arguments
- // only springmvc consumer no arguments
- //
- // so only adapt springmvc consumer to arguments mode
- // not adapt all to http mode
- protected Object[] swaggerArguments;
-
protected InvocationContext parentContext;
public SwaggerInvocation() {
@@ -49,27 +42,6 @@ public class SwaggerInvocation extends InvocationContext {
return invocationType;
}
- public Object[] getSwaggerArguments() {
- return swaggerArguments;
- }
-
- @SuppressWarnings("unchecked")
- public <T> T getSwaggerArgument(int idx) {
- return (T) swaggerArguments[idx];
- }
-
- public void setSwaggerArguments(Object[] swaggerArguments) {
- this.swaggerArguments = swaggerArguments;
- }
-
- public void setSwaggerArgument(int idx, Object swaggerArgument) {
- if(swaggerArguments == null) {
- // not request parameters. e.g. void test()
- return;
- }
- this.swaggerArguments[idx] = swaggerArgument;
- }
-
public String getInvocationQualifiedName() {
return invocationType.name();
}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ArgumentsMapperCommon.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ArgumentsMapperCommon.java
deleted file mode 100644
index 970c79f..0000000
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ArgumentsMapperCommon.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.
- * The ASF licenses this file to You 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.apache.servicecomb.swagger.invocation.arguments.consumer;
-
-import java.util.List;
-
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
-
-/**
- * map consumer arguments to swagger arguments
- */
-public class ArgumentsMapperCommon implements ConsumerArgumentsMapper {
- private List<ArgumentMapper> mappers;
-
- private int contractParameterCount;
-
- public ArgumentsMapperCommon(List<ArgumentMapper> mappers, int contractParameterCount) {
- this.mappers = mappers;
- this.contractParameterCount = contractParameterCount;
- }
-
- @Override
- public void toInvocation(Object[] consumerArguments, SwaggerInvocation invocation) {
- Object[] swaggerArguments = new Object[contractParameterCount];
- invocation.setSwaggerArguments(swaggerArguments);
-
- for (ArgumentMapper argMapper : mappers) {
- argMapper.mapArgument(invocation, consumerArguments);
- }
- }
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerArgumentSame.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerArgumentSame.java
deleted file mode 100644
index e6dea39..0000000
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerArgumentSame.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.
- * The ASF licenses this file to You 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.apache.servicecomb.swagger.invocation.arguments.consumer;
-
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
-
-public final class ConsumerArgumentSame implements ArgumentMapper {
- private int consumerIdx;
-
- private int swaggerIdx;
-
- public ConsumerArgumentSame(int consumerIdx, int swaggerIdx) {
- this.consumerIdx = consumerIdx;
- this.swaggerIdx = swaggerIdx;
- }
-
- public boolean isSameIndex() {
- return swaggerIdx == consumerIdx;
- }
-
- @Override
- public void mapArgument(SwaggerInvocation invocation, Object[] consumerArguments) {
- invocation.setSwaggerArgument(swaggerIdx, consumerArguments[consumerIdx]);
- }
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerArgumentToBodyField.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerArgumentToBodyField.java
deleted file mode 100644
index 1bcc939..0000000
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerArgumentToBodyField.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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.
- * The ASF licenses this file to You 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.apache.servicecomb.swagger.invocation.arguments.consumer;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
-
-/**
- * <pre>
- * Typical scene of transparent RPC
- * all parameters of consumer method wrapped to a bean in contract
- * </pre>
- */
-// TODO : WEAK this class can be deleted
-public final class ConsumerArgumentToBodyField implements ArgumentMapper {
- private int consumerIdx;
-
- private String parameterName;
-
- private final int swaggerIdx;
-
- public ConsumerArgumentToBodyField(int consumerIdx, String parameterName, int swaggerIdx) {
- this.consumerIdx = consumerIdx;
- this.parameterName = parameterName;
- this.swaggerIdx = swaggerIdx;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public void mapArgument(SwaggerInvocation invocation, Object[] consumerArguments) {
- Object consumerArgument = consumerArguments[consumerIdx];
-
- Object[] contractArguments = invocation.getSwaggerArguments();
- if (contractArguments[swaggerIdx] == null) {
- contractArguments[swaggerIdx] = new LinkedHashMap<>();
- }
-
- if (consumerArgument != null) {
- ((Map<String, Object>) contractArguments[swaggerIdx]).put(parameterName, consumerArgument);
- }
- }
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerArgumentsMapperCreator.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerArgumentsMapperCreator.java
deleted file mode 100644
index fddbfc4..0000000
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerArgumentsMapperCreator.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * 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.
- * The ASF licenses this file to You 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.apache.servicecomb.swagger.invocation.arguments.consumer;
-
-import static org.apache.servicecomb.swagger.generator.SwaggerGeneratorUtils.collectParameterName;
-
-import java.lang.reflect.Method;
-import java.util.Map;
-
-import org.apache.servicecomb.foundation.common.utils.LambdaMetafactoryUtils;
-import org.apache.servicecomb.foundation.common.utils.bean.Getter;
-import org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation;
-import org.apache.servicecomb.swagger.invocation.arguments.AbstractArgumentsMapperCreator;
-import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
-import org.apache.servicecomb.swagger.invocation.arguments.ContextArgumentMapperFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.fasterxml.jackson.databind.JavaType;
-import com.fasterxml.jackson.databind.SerializationConfig;
-import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition;
-import com.fasterxml.jackson.databind.type.TypeFactory;
-
-public class ConsumerArgumentsMapperCreator extends AbstractArgumentsMapperCreator {
- private static final Logger LOGGER = LoggerFactory.getLogger(ConsumerArgumentsMapperCreator.class);
-
- private int unknownConsumerParams = 0;
-
- public ConsumerArgumentsMapperCreator(SerializationConfig serializationConfig,
- Map<Class<?>, ContextArgumentMapperFactory> contextFactorys,
- Method consumerMethod, SwaggerOperation swaggerOperation) {
- super(serializationConfig, contextFactorys, consumerMethod, swaggerOperation);
- }
-
- private boolean isAllSameMapper() {
- for (ArgumentMapper mapper : mappers) {
- if (mapper instanceof ConsumerArgumentSame &&
- ((ConsumerArgumentSame) mapper).isSameIndex()) {
- continue;
- }
-
- return false;
- }
-
- return true;
- }
-
- public ConsumerArgumentsMapper createArgumentsMapper() {
- doCreateArgumentsMapper();
-
- // if all mappers are SameMapper, then no need any mapper
- if (unknownConsumerParams == 0
- && mappers.size() == swaggerOperation.getOperation().getParameters().size()
- && isAllSameMapper()) {
- return new ArgumentsMapperDirectReuse();
- }
-
- return new ArgumentsMapperCommon(mappers, swaggerParameters.size());
- }
-
- @Override
- protected void processUnknownParameter(String parameterName) {
- // real unknown parameter, new consumer invoke old producer, just ignore this parameter
- LOGGER.warn("new consumer invoke old version producer, parameter({}) is not exist in contract, method={}:{}.",
- parameterName, providerMethod.getDeclaringClass().getName(), providerMethod.getName());
- unknownConsumerParams++;
- }
-
- @Override
- protected ArgumentMapper createKnownParameterMapper(int consumerParamIdx, Integer swaggerIdx) {
- return new ConsumerArgumentSame(consumerParamIdx, swaggerIdx);
- }
-
- protected void processBeanParameter(int consumerParamIdx, java.lang.reflect.Parameter consumerParameter) {
- ConsumerBeanParamMapper mapper = new ConsumerBeanParamMapper(consumerParamIdx);
- JavaType consumerType = TypeFactory.defaultInstance().constructType(consumerParameter.getParameterizedType());
- for (BeanPropertyDefinition propertyDefinition : serializationConfig.introspect(consumerType).findProperties()) {
- String parameterName = collectParameterName(providerMethod, propertyDefinition);
- Integer swaggerIdx = findAndClearSwaggerParameterIndex(parameterName);
- if (swaggerIdx == null) {
- // unknown field, ignore it
- LOGGER.warn(
- "new consumer invoke old version producer, bean parameter({}) is not exist in contract, method={}:{}.",
- parameterName, providerMethod.getDeclaringClass().getName(), providerMethod.getName());
- continue;
- }
-
- Getter<Object, Object> getter;
- if (propertyDefinition.hasGetter()) {
- getter = LambdaMetafactoryUtils.createLambda(propertyDefinition.getGetter().getAnnotated(), Getter.class);
- } else {
- getter = LambdaMetafactoryUtils.createGetter(propertyDefinition.getField().getAnnotated());
- }
-
- mapper.addField(swaggerIdx, getter);
- }
- mappers.add(mapper);
- }
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerBeanParamMapper.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerBeanParamMapper.java
deleted file mode 100644
index b3759b5..0000000
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/ConsumerBeanParamMapper.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * 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.
- * The ASF licenses this file to You 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.apache.servicecomb.swagger.invocation.arguments.consumer;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.servicecomb.foundation.common.utils.bean.Getter;
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
-
-/**
- * <pre>
- * consumer: void add(QueryWrapper query)
- * class QueryWrapper {
- * int x;
- * int y;
- * }
- * contract; void add(int x, int y)
- * </pre>
- */
-public final class ConsumerBeanParamMapper implements ArgumentMapper {
- private class FieldMeta {
- int swaggerIdx;
-
- Getter<Object, Object> getter;
-
- public FieldMeta(int swaggerIdx, Getter<Object, Object> getter) {
- this.swaggerIdx = swaggerIdx;
- this.getter = getter;
- }
- }
-
- private int consumerIdx;
-
- private List<FieldMeta> fields = new ArrayList<>();
-
- public ConsumerBeanParamMapper(int consumerIdx) {
- this.consumerIdx = consumerIdx;
- }
-
- public void addField(int swaggerIdx, Getter<Object, Object> getter) {
- fields.add(new FieldMeta(swaggerIdx, getter));
- }
-
- @Override
- public void mapArgument(SwaggerInvocation invocation, Object[] consumerArguments) {
- Object consumerArgument = consumerArguments[consumerIdx];
- if (consumerArgument == null) {
- return;
- }
-
- Object[] contractArguments = invocation.getSwaggerArguments();
- for (FieldMeta fieldMeta : fields) {
- contractArguments[fieldMeta.swaggerIdx] = fieldMeta.getter.get(consumerArgument);
- }
- }
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentSame.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentSame.java
deleted file mode 100644
index 4d07b2e..0000000
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentSame.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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.
- * The ASF licenses this file to You 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.apache.servicecomb.swagger.invocation.arguments.producer;
-
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
-
-public class ProducerArgumentSame implements ArgumentMapper {
- private int swaggerIdx;
-
- private int producerIdx;
-
- public ProducerArgumentSame(int swaggerIdx, int producerIdx) {
- this.swaggerIdx = swaggerIdx;
- this.producerIdx = producerIdx;
- }
-
- @Override
- public void mapArgument(SwaggerInvocation invocation, Object[] producerArguments) {
- Object swaggerParam = invocation.getSwaggerArgument(swaggerIdx);
- producerArguments[producerIdx] = swaggerParam;
- }
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentsMapperCreator.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentsMapperCreator.java
deleted file mode 100644
index a6d8031..0000000
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerArgumentsMapperCreator.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * 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.
- * The ASF licenses this file to You 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.apache.servicecomb.swagger.invocation.arguments.producer;
-
-import static org.apache.servicecomb.swagger.generator.SwaggerGeneratorUtils.collectParameterName;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.Parameter;
-import java.lang.reflect.Type;
-import java.util.Map;
-
-import org.apache.servicecomb.foundation.common.utils.LambdaMetafactoryUtils;
-import org.apache.servicecomb.foundation.common.utils.bean.Setter;
-import org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation;
-import org.apache.servicecomb.swagger.invocation.arguments.AbstractArgumentsMapperCreator;
-import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
-import org.apache.servicecomb.swagger.invocation.arguments.ContextArgumentMapperFactory;
-
-import com.fasterxml.jackson.databind.JavaType;
-import com.fasterxml.jackson.databind.SerializationConfig;
-import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition;
-import com.fasterxml.jackson.databind.type.TypeFactory;
-
-public class ProducerArgumentsMapperCreator extends AbstractArgumentsMapperCreator {
- // swagger parameter types relate to producer
- // because features of @BeanParam/query, and rpc mode parameter wrapper
- // types is not always equals to producerMethod parameter types directly
- private Type[] swaggerParameterTypes;
-
- public ProducerArgumentsMapperCreator(SerializationConfig serializationConfig,
- Map<Class<?>, ContextArgumentMapperFactory> contextFactorys,
- Method producerMethod, SwaggerOperation swaggerOperation) {
- super(serializationConfig, contextFactorys, producerMethod, swaggerOperation);
-
- swaggerParameterTypes = new Type[swaggerOperation.getOperation().getParameters().size()];
- }
-
- public Type[] getSwaggerParameterTypes() {
- return swaggerParameterTypes;
- }
-
- public ProducerArgumentsMapper createArgumentsMapper() {
- doCreateArgumentsMapper();
- return new ProducerArgumentsMapper(mappers, providerMethod.getParameterCount());
- }
-
- @Override
- protected void processUnknownParameter(String parameterName) {
- throw new IllegalStateException(String
- .format("failed to find producer parameter in contract, method=%s:%s, parameter name=%s.",
- providerMethod.getDeclaringClass().getName(), providerMethod.getName(), parameterName));
- }
-
- @Override
- protected ArgumentMapper createKnownParameterMapper(int producerParamIdx, Integer swaggerIdx) {
- swaggerParameterTypes[swaggerIdx] = providerMethod.getGenericParameterTypes()[producerParamIdx];
- return new ProducerArgumentSame(swaggerIdx, producerParamIdx);
- }
-
-
- @Override
- protected void processBeanParameter(int producerParamIdx, Parameter producerParameter) {
- ProducerBeanParamMapper mapper = new ProducerBeanParamMapper(producerParamIdx, producerParameter.getType());
- JavaType producerType = TypeFactory.defaultInstance().constructType(producerParameter.getParameterizedType());
- for (BeanPropertyDefinition propertyDefinition : serializationConfig.introspect(producerType)
- .findProperties()) {
- String parameterName = collectParameterName(providerMethod, propertyDefinition);
- Integer swaggerIdx = findAndClearSwaggerParameterIndex(parameterName);
- if (swaggerIdx == null) {
- throw new IllegalStateException(String
- .format("failed to find producer parameter in contract, method=%s:%s, bean parameter name=%s.",
- providerMethod.getDeclaringClass().getName(), providerMethod.getName(), parameterName));
- }
-
- Setter<Object, Object> setter;
- if (propertyDefinition.hasSetter()) {
- setter = LambdaMetafactoryUtils.createLambda(propertyDefinition.getSetter().getAnnotated(), Setter.class);
- } else {
- setter = LambdaMetafactoryUtils.createSetter(propertyDefinition.getField().getAnnotated());
- }
-
- swaggerParameterTypes[swaggerIdx] = propertyDefinition.getPrimaryType();
- mapper.addField(swaggerIdx, setter);
- }
- mappers.add(mapper);
- }
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerBeanParamMapper.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerBeanParamMapper.java
deleted file mode 100644
index bf92549..0000000
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/ProducerBeanParamMapper.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * 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.
- * The ASF licenses this file to You 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.apache.servicecomb.swagger.invocation.arguments.producer;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.servicecomb.foundation.common.utils.bean.Setter;
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
-
-public class ProducerBeanParamMapper implements ArgumentMapper {
- private class FieldMeta {
- int swaggerIdx;
-
- Setter<Object, Object> setter;
-
- public FieldMeta(int swaggerIdx, Setter<Object, Object> setter) {
- this.swaggerIdx = swaggerIdx;
- this.setter = setter;
- }
- }
-
- private int producerIdx;
-
- private final Class<?> producerParamType;
-
- private List<FieldMeta> fields = new ArrayList<>();
-
- public ProducerBeanParamMapper(int producerIdx, Class<?> producerParamType) {
- this.producerIdx = producerIdx;
- this.producerParamType = producerParamType;
- }
-
- public void addField(int swaggerIdx, Setter<Object, Object> setter) {
- fields.add(new FieldMeta(swaggerIdx, setter));
- }
-
- @Override
- public void mapArgument(SwaggerInvocation invocation, Object[] producerArguments) {
- try {
- Object paramInstance = producerParamType.newInstance();
- producerArguments[producerIdx] = paramInstance;
-
- for (FieldMeta fieldMeta : fields) {
- Object value = invocation.getSwaggerArgument(fieldMeta.swaggerIdx);
- fieldMeta.setter.set(paramInstance, value);
- }
- } catch (Throwable e) {
- throw new IllegalStateException("failed to map bean param.", e);
- }
- }
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/SwaggerBodyFieldToProducerArgument.java b/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/SwaggerBodyFieldToProducerArgument.java
deleted file mode 100644
index 8c10b7e..0000000
--- a/swagger/swagger-invocation/invocation-core/src/main/java/org/apache/servicecomb/swagger/invocation/arguments/producer/SwaggerBodyFieldToProducerArgument.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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.
- * The ASF licenses this file to You 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.apache.servicecomb.swagger.invocation.arguments.producer;
-
-import java.lang.reflect.Type;
-import java.util.Map;
-
-import org.apache.servicecomb.foundation.common.utils.JsonUtils;
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.arguments.ArgumentMapper;
-
-import com.fasterxml.jackson.databind.JavaType;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.type.TypeFactory;
-
-// TODO : WEAK this class can be deleted
-public class SwaggerBodyFieldToProducerArgument implements ArgumentMapper {
- public static ObjectMapper mapper = JsonUtils.OBJ_MAPPER;
-
- private final int producerParamIdx;
-
- private final String parameterName;
-
- private final JavaType producerParamType;
-
- private final int swaggerBodyIdx;
-
- public SwaggerBodyFieldToProducerArgument(int producerParamIdx, String parameterName, Type producerParamType,
- int swaggerBodyIdx) {
- this.producerParamIdx = producerParamIdx;
- this.parameterName = parameterName;
- this.producerParamType = TypeFactory.defaultInstance().constructType(producerParamType);
- this.swaggerBodyIdx = swaggerBodyIdx;
- }
-
- @Override
- public void mapArgument(SwaggerInvocation invocation, Object[] producerArguments) {
- Map<String, Object> body = invocation.getSwaggerArgument(swaggerBodyIdx);
- producerArguments[producerParamIdx] = mapper.convertValue(body.get(parameterName), producerParamType);
- }
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestJaxrsV1V1.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestJaxrsV1V1.java
deleted file mode 100644
index 836a42a..0000000
--- a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestJaxrsV1V1.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * 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.
- * The ASF licenses this file to You 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.apache.servicecomb.swagger.invocation.arguments.consumer;
-
-import java.util.LinkedHashMap;
-
-import org.apache.servicecomb.swagger.engine.SwaggerConsumer;
-import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
-import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddBodyV1;
-import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddV1;
-import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddBeanParamV1;
-import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddBodyV1;
-import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddV1;
-import org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV1;
-import org.junit.Assert;
-import org.junit.Test;
-
-import io.swagger.models.Swagger;
-
-public class TestJaxrsV1V1 {
- @Test
- public void should_mapper_consumer_multi_args_to_swagger_multi_args() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(JaxrsAddV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(2, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- }
-
- interface ConsumerAddV1_diff_order {
- int add(int y, int x);
- }
-
- @Test
- public void should_mapper_consumer_multi_args_to_swagger_multi_args_with_diff_order() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(JaxrsAddV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1_diff_order.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {2, 1};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(2, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- }
-
- @Test
- public void should_mapper_consumer_multi_args_to_swagger_multi_args_gen_by_BeanParam() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(JaxrsAddBeanParamV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(2, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- }
-
- @Test
- public void should_mapper_consumer_multi_args_to_swagger_body() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(JaxrsAddBodyV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- LinkedHashMap<String, Object> map = invocation.getSwaggerArgument(0);
- Assert.assertEquals(2, map.size());
- Assert.assertEquals(1, map.get("x"));
- Assert.assertEquals(2, map.get("y"));
- }
-
- @Test
- public void should_mapper_consumer_wrapped_body_to_swagger_multi_args() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(JaxrsAddV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV1(1, 2)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(2, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- }
-
- @Test
- public void should_mapper_consumer_wrapped_body_to_swagger_multi_args_gen_by_BeanParam() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(JaxrsAddBeanParamV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV1(1, 2)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(2, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- }
-
- @Test
- public void should_mapper_consumer_body_to_swagger_body() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(JaxrsAddBodyV1.class);
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV1(1, 2)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertSame(arguments[0], invocation.getSwaggerArgument(0));
- }
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestJaxrsV1V2.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestJaxrsV1V2.java
deleted file mode 100644
index f12bf5b..0000000
--- a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestJaxrsV1V2.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * 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.
- * The ASF licenses this file to You 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.apache.servicecomb.swagger.invocation.arguments.consumer;
-
-import java.util.LinkedHashMap;
-
-import org.apache.servicecomb.swagger.engine.SwaggerConsumer;
-import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
-import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddBodyV1;
-import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddV1;
-import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddBeanParamV2;
-import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddBodyV2;
-import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddV2;
-import org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV1;
-import org.junit.Assert;
-import org.junit.Test;
-
-import io.swagger.models.Swagger;
-
-public class TestJaxrsV1V2 {
- @Test
- public void add_add() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(JaxrsAddV2.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(3, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- Assert.assertNull(invocation.getSwaggerArgument(2));
- }
-
- @Test
- public void add_addBeanParam() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(JaxrsAddBeanParamV2.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(3, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- Assert.assertNull(invocation.getSwaggerArgument(2));
- }
-
- @Test
- public void add_addBody() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(JaxrsAddBodyV2.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- LinkedHashMap<String, Object> map = invocation.getSwaggerArgument(0);
- Assert.assertEquals(2, map.size());
- Assert.assertEquals(1, map.get("x"));
- Assert.assertEquals(2, map.get("y"));
- }
-
- @Test
- public void addBody_add() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(JaxrsAddV2.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV1(1, 2)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(3, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- Assert.assertNull(invocation.getSwaggerArgument(2));
- }
-
- @Test
- public void addBody_addBeanParam() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(JaxrsAddBeanParamV2.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV1(1, 2)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(3, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- Assert.assertNull(invocation.getSwaggerArgument(2));
- }
-
- @Test
- public void addBody_addBody() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(JaxrsAddBodyV2.class);
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV1(1, 2)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertSame(arguments[0], invocation.getSwaggerArgument(0));
- }
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestJaxrsV2V1.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestJaxrsV2V1.java
deleted file mode 100644
index fef986a..0000000
--- a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestJaxrsV2V1.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * 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.
- * The ASF licenses this file to You 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.apache.servicecomb.swagger.invocation.arguments.consumer;
-
-import java.util.LinkedHashMap;
-
-import org.apache.servicecomb.swagger.engine.SwaggerConsumer;
-import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
-import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddBodyV2;
-import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddV2;
-import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddBeanParamV1;
-import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddBodyV1;
-import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddV1;
-import org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV2;
-import org.junit.Assert;
-import org.junit.Test;
-
-import io.swagger.models.Swagger;
-
-public class TestJaxrsV2V1 {
- @Test
- public void add_add() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(JaxrsAddV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2, 3};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(2, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- }
-
- @Test
- public void add_addBeanParam() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(JaxrsAddBeanParamV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2, 3};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(2, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- }
-
- @Test
- public void add_addBody() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(JaxrsAddBodyV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2, 3};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- LinkedHashMap<String, Object> map = invocation.getSwaggerArgument(0);
- Assert.assertEquals(2, map.size());
- Assert.assertEquals(1, map.get("x"));
- Assert.assertEquals(2, map.get("y"));
- }
-
- @Test
- public void addBody_add() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(JaxrsAddV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV2(1, 2, 3)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(2, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- }
-
- @Test
- public void addBody_addBeanParam() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(JaxrsAddBeanParamV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV2(1, 2, 3)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(2, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- }
-
- @Test
- public void addBody_addBody() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(JaxrsAddBodyV1.class);
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV2(1, 2, 3)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertSame(arguments[0], invocation.getSwaggerArgument(0));
- }
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestJaxrsV2V2.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestJaxrsV2V2.java
deleted file mode 100644
index a3a20b0..0000000
--- a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestJaxrsV2V2.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * 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.
- * The ASF licenses this file to You 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.apache.servicecomb.swagger.invocation.arguments.consumer;
-
-import java.util.LinkedHashMap;
-
-import org.apache.servicecomb.swagger.engine.SwaggerConsumer;
-import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
-import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddBodyV2;
-import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddV2;
-import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddBeanParamV2;
-import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddBodyV2;
-import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddV2;
-import org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV2;
-import org.junit.Assert;
-import org.junit.Test;
-
-import io.swagger.models.Swagger;
-
-public class TestJaxrsV2V2 {
- @Test
- public void add_add() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(JaxrsAddV2.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2, 3};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(3, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- Assert.assertEquals(3, (int) invocation.getSwaggerArgument(2));
- }
-
- @Test
- public void add_addBeanParam() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(JaxrsAddBeanParamV2.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2, 3};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(3, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- Assert.assertEquals(3, (int) invocation.getSwaggerArgument(2));
- }
-
- @Test
- public void add_addBody() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(JaxrsAddBodyV2.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2, 3};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- LinkedHashMap<String, Object> map = invocation.getSwaggerArgument(0);
- Assert.assertEquals(3, map.size());
- Assert.assertEquals(1, map.get("x"));
- Assert.assertEquals(2, map.get("y"));
- Assert.assertEquals(3, map.get("x-z"));
- }
-
- @Test
- public void addBody_add() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(JaxrsAddV2.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV2(1, 2, 3)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(3, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- Assert.assertEquals(3, (int) invocation.getSwaggerArgument(2));
- }
-
- @Test
- public void addBody_addBeanParam() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(JaxrsAddBeanParamV2.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV2(1, 2, 3)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(3, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- Assert.assertEquals(3, (int) invocation.getSwaggerArgument(2));
- }
-
- @Test
- public void addBody_addBody() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(JaxrsAddBodyV2.class);
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV2(1, 2, 3)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertSame(arguments[0], invocation.getSwaggerArgument(0));
- }
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestPojoOneArg.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestPojoOneArg.java
deleted file mode 100644
index 345017e..0000000
--- a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestPojoOneArg.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * 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.
- * The ASF licenses this file to You 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.apache.servicecomb.swagger.invocation.arguments.consumer;
-
-import java.util.LinkedHashMap;
-
-import org.apache.servicecomb.foundation.test.scaffolding.model.Color;
-import org.apache.servicecomb.foundation.test.scaffolding.model.User;
-import org.apache.servicecomb.swagger.engine.SwaggerConsumer;
-import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
-import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.schemas.ConsumerOneArg;
-import org.apache.servicecomb.swagger.invocation.schemas.PojoOneArg;
-import org.junit.Assert;
-import org.junit.Test;
-
-import io.swagger.models.Swagger;
-
-public class TestPojoOneArg {
- @Test
- public void should_mapper_consumer_simple_to_swagger_body() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(PojoOneArg.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerOneArg.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("simple").getArgumentsMapper();
-
- Object[] arguments = new Object[] {"name"};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- LinkedHashMap<String, Object> map = invocation.getSwaggerArgument(0);
- Assert.assertEquals(1, map.size());
- Assert.assertEquals("name", map.get("name"));
- }
-
- @Test
- public void should_mapper_consumer_bean_to_swagger_body() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(PojoOneArg.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerOneArg.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("bean").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new User()};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(1, invocation.getSwaggerArguments().length);
- Assert.assertSame(arguments[0], invocation.getSwaggerArgument(0));
- }
-
- @Test
- public void should_mapper_consumer_enum_to_swagger_body_field() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(PojoOneArg.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerOneArg.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("enumBody").getArgumentsMapper();
-
- Object[] arguments = new Object[] {Color.BLUE};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- LinkedHashMap<String, Object> map = invocation.getSwaggerArgument(0);
- Assert.assertEquals(1, map.size());
- Assert.assertEquals(Color.BLUE, map.get("color"));
- }
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestPojoV1V1.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestPojoV1V1.java
deleted file mode 100644
index 9dc6e36..0000000
--- a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestPojoV1V1.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * 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.
- * The ASF licenses this file to You 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.apache.servicecomb.swagger.invocation.arguments.consumer;
-
-import java.util.LinkedHashMap;
-
-import org.apache.servicecomb.swagger.engine.SwaggerConsumer;
-import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
-import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.context.InvocationContext;
-import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddBodyV1;
-import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddV1;
-import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddWithContext;
-import org.apache.servicecomb.swagger.invocation.schemas.PojoAddBodyV1;
-import org.apache.servicecomb.swagger.invocation.schemas.PojoAddV1;
-import org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV1;
-import org.junit.Assert;
-import org.junit.Test;
-
-import io.swagger.models.Swagger;
-
-public class TestPojoV1V1 {
- @Test
- public void add_add() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(PojoAddV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- LinkedHashMap<String, Object> map = invocation.getSwaggerArgument(0);
- Assert.assertEquals(2, map.size());
- Assert.assertEquals(1, map.get("x"));
- Assert.assertEquals(2, map.get("y"));
- }
-
- @Test
- public void add_addBody() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(PojoAddBodyV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- LinkedHashMap<String, Object> map = invocation.getSwaggerArgument(0);
- Assert.assertEquals(2, map.size());
- Assert.assertEquals(1, map.get("x"));
- Assert.assertEquals(2, map.get("y"));
- }
-
- @Test
- public void addBody_add() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(PojoAddV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV1(1, 2)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertSame(arguments[0], invocation.getSwaggerArgument(0));
- }
-
- @Test
- public void addBody_addBody() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(PojoAddBodyV1.class);
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV1(1, 2)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertSame(arguments[0], invocation.getSwaggerArgument(0));
- }
-
- @Test
- public void addWithContext_add() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(PojoAddV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddWithContext.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- InvocationContext invocationContext = new InvocationContext();
- invocationContext.addContext("k1", "v1");
- invocationContext.addContext("k2", "v2");
- invocationContext.addLocalContext("k3", "v3");
- invocationContext.addLocalContext("k4", "v4");
-
- Object[] arguments = new Object[] {invocationContext, 1, 2};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- LinkedHashMap<String, Object> map = invocation.getSwaggerArgument(0);
- Assert.assertEquals(2, map.size());
- Assert.assertEquals(1, map.get("x"));
- Assert.assertEquals(2, map.get("y"));
-
- Assert.assertEquals(2, invocation.getContext().size());
- Assert.assertEquals("v1", invocation.getContext().get("k1"));
- Assert.assertEquals("v2", invocation.getContext().get("k2"));
-
- Assert.assertEquals(2, invocation.getLocalContext().size());
- Assert.assertEquals("v3", invocation.getLocalContext().get("k3"));
- Assert.assertEquals("v4", invocation.getLocalContext().get("k4"));
- }
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestPojoV1V2.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestPojoV1V2.java
deleted file mode 100644
index e26355c..0000000
--- a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestPojoV1V2.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * 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.
- * The ASF licenses this file to You 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.apache.servicecomb.swagger.invocation.arguments.consumer;
-
-import java.util.LinkedHashMap;
-
-import org.apache.servicecomb.swagger.engine.SwaggerConsumer;
-import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
-import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddBodyV1;
-import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddV1;
-import org.apache.servicecomb.swagger.invocation.schemas.PojoAddBodyV2;
-import org.apache.servicecomb.swagger.invocation.schemas.PojoAddV2;
-import org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV1;
-import org.junit.Assert;
-import org.junit.Test;
-
-import io.swagger.models.Swagger;
-
-public class TestPojoV1V2 {
- @Test
- public void add_add() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(PojoAddV2.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- LinkedHashMap<String, Object> map = invocation.getSwaggerArgument(0);
- Assert.assertEquals(2, map.size());
- Assert.assertEquals(1, map.get("x"));
- Assert.assertEquals(2, map.get("y"));
- }
-
- @Test
- public void add_addBody() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(PojoAddBodyV2.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- LinkedHashMap<String, Object> map = invocation.getSwaggerArgument(0);
- Assert.assertEquals(2, map.size());
- Assert.assertEquals(1, map.get("x"));
- Assert.assertEquals(2, map.get("y"));
- }
-
- @Test
- public void addBody_add() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(PojoAddV2.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV1(1, 2)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertSame(arguments[0], invocation.getSwaggerArgument(0));
- }
-
- @Test
- public void addBody_addBody() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(PojoAddBodyV2.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV1(1, 2)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertSame(arguments[0], invocation.getSwaggerArgument(0));
- }
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestPojoV2V1.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestPojoV2V1.java
deleted file mode 100644
index be33303..0000000
--- a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestPojoV2V1.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * 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.
- * The ASF licenses this file to You 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.apache.servicecomb.swagger.invocation.arguments.consumer;
-
-import java.util.LinkedHashMap;
-
-import org.apache.servicecomb.swagger.engine.SwaggerConsumer;
-import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
-import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddBodyV2;
-import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddV2;
-import org.apache.servicecomb.swagger.invocation.schemas.PojoAddBodyV1;
-import org.apache.servicecomb.swagger.invocation.schemas.PojoAddV1;
-import org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV2;
-import org.junit.Assert;
-import org.junit.Test;
-
-import io.swagger.models.Swagger;
-
-public class TestPojoV2V1 {
- @Test
- public void add_add() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(PojoAddV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2, 3};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- LinkedHashMap<String, Object> map = invocation.getSwaggerArgument(0);
- Assert.assertEquals(2, map.size());
- Assert.assertEquals(1, map.get("x"));
- Assert.assertEquals(2, map.get("y"));
- }
-
- @Test
- public void add_addBody() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(PojoAddBodyV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2, 3};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- LinkedHashMap<String, Object> map = invocation.getSwaggerArgument(0);
- Assert.assertEquals(2, map.size());
- Assert.assertEquals(1, map.get("x"));
- Assert.assertEquals(2, map.get("y"));
- }
-
- @Test
- public void addBody_add() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(PojoAddV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV2(1, 2, 3)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertSame(arguments[0], invocation.getSwaggerArgument(0));
- }
-
- @Test
- public void addBody_addBody() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(PojoAddBodyV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV2(1, 2, 3)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertSame(arguments[0], invocation.getSwaggerArgument(0));
- }
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestPojoV2V2.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestPojoV2V2.java
deleted file mode 100644
index d13a8ca..0000000
--- a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestPojoV2V2.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * 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.
- * The ASF licenses this file to You 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.apache.servicecomb.swagger.invocation.arguments.consumer;
-
-import java.util.LinkedHashMap;
-
-import org.apache.servicecomb.swagger.engine.SwaggerConsumer;
-import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
-import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddBodyV2;
-import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddV2;
-import org.apache.servicecomb.swagger.invocation.schemas.PojoAddBodyV2;
-import org.apache.servicecomb.swagger.invocation.schemas.PojoAddV2;
-import org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV2;
-import org.junit.Assert;
-import org.junit.Test;
-
-import io.swagger.models.Swagger;
-
-public class TestPojoV2V2 {
- @Test
- public void add_add() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(PojoAddV2.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2, 3};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- LinkedHashMap<String, Object> map = invocation.getSwaggerArgument(0);
- Assert.assertEquals(3, map.size());
- Assert.assertEquals(1, map.get("x"));
- Assert.assertEquals(2, map.get("y"));
- Assert.assertEquals(3, map.get("x-z"));
- }
-
- @Test
- public void add_addBody() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(PojoAddBodyV2.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2, 3};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- LinkedHashMap<String, Object> map = invocation.getSwaggerArgument(0);
- Assert.assertEquals(3, map.size());
- Assert.assertEquals(1, map.get("x"));
- Assert.assertEquals(2, map.get("y"));
- Assert.assertEquals(3, map.get("x-z"));
- }
-
- @Test
- public void addBody_add() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(PojoAddV2.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV2(1, 2, 3)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertSame(arguments[0], invocation.getSwaggerArgument(0));
- }
-
- @Test
- public void addBody_addBody() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(PojoAddBodyV2.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV2(1, 2, 3)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertSame(arguments[0], invocation.getSwaggerArgument(0));
- }
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestSpringmvcV1V1.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestSpringmvcV1V1.java
deleted file mode 100644
index 5dcdc6a..0000000
--- a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestSpringmvcV1V1.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * 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.
- * The ASF licenses this file to You 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.apache.servicecomb.swagger.invocation.arguments.consumer;
-
-import java.util.LinkedHashMap;
-
-import org.apache.servicecomb.swagger.engine.SwaggerConsumer;
-import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
-import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddBodyV1;
-import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddV1;
-import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddBodyV1;
-import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddV1;
-import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddWrapperV1;
-import org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV1;
-import org.junit.Assert;
-import org.junit.Test;
-
-import io.swagger.models.Swagger;
-
-public class TestSpringmvcV1V1 {
- @Test
- public void add_add() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(SpringmvcAddV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(2, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- }
-
- @Test
- public void add_addWrapper() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(SpringmvcAddWrapperV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(2, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- }
-
- @Test
- public void add_addBody() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(SpringmvcAddBodyV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- LinkedHashMap<String, Object> map = invocation.getSwaggerArgument(0);
- Assert.assertEquals(2, map.size());
- Assert.assertEquals(1, map.get("x"));
- Assert.assertEquals(2, map.get("y"));
- }
-
- @Test
- public void addBody_add() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(SpringmvcAddV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV1(1, 2)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(2, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- }
-
- @Test
- public void addBody_addWrapper() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(SpringmvcAddWrapperV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV1(1, 2)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(2, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- }
-
- @Test
- public void addBody_addBody() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(SpringmvcAddBodyV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV1(1, 2)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertSame(arguments[0], invocation.getSwaggerArgument(0));
- }
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestSpringmvcV1V2.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestSpringmvcV1V2.java
deleted file mode 100644
index 22c10b6..0000000
--- a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestSpringmvcV1V2.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * 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.
- * The ASF licenses this file to You 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.apache.servicecomb.swagger.invocation.arguments.consumer;
-
-import java.util.LinkedHashMap;
-
-import org.apache.servicecomb.swagger.engine.SwaggerConsumer;
-import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
-import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddBodyV1;
-import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddV1;
-import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddBodyV2;
-import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddV2;
-import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddWrapperV2;
-import org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV1;
-import org.junit.Assert;
-import org.junit.Test;
-
-import io.swagger.models.Swagger;
-
-public class TestSpringmvcV1V2 {
- @Test
- public void add_add() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(SpringmvcAddV2.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(3, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- Assert.assertNull(invocation.getSwaggerArgument(2));
- }
-
- @Test
- public void add_addWrapper() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(SpringmvcAddWrapperV2.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(3, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- Assert.assertNull(invocation.getSwaggerArgument(2));
- }
-
- @Test
- public void add_addBody() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(SpringmvcAddBodyV2.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- LinkedHashMap<String, Object> map = invocation.getSwaggerArgument(0);
- Assert.assertEquals(2, map.size());
- Assert.assertEquals(1, map.get("x"));
- Assert.assertEquals(2, map.get("y"));
- }
-
- @Test
- public void addBody_add() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(SpringmvcAddV2.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV1(1, 2)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(3, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- Assert.assertNull(invocation.getSwaggerArgument(2));
- }
-
- @Test
- public void addBody_addWrapper() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(SpringmvcAddWrapperV2.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV1(1, 2)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(3, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- Assert.assertNull(invocation.getSwaggerArgument(2));
- }
-
- @Test
- public void addBody_addBody() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(SpringmvcAddBodyV2.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV1.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV1(1, 2)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertSame(arguments[0], invocation.getSwaggerArgument(0));
- }
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestSpringmvcV2V1.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestSpringmvcV2V1.java
deleted file mode 100644
index a1033e0..0000000
--- a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestSpringmvcV2V1.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * 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.
- * The ASF licenses this file to You 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.apache.servicecomb.swagger.invocation.arguments.consumer;
-
-import java.util.LinkedHashMap;
-
-import org.apache.servicecomb.swagger.engine.SwaggerConsumer;
-import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
-import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddBodyV2;
-import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddV2;
-import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddBodyV1;
-import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddV1;
-import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddWrapperV1;
-import org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV2;
-import org.junit.Assert;
-import org.junit.Test;
-
-import io.swagger.models.Swagger;
-
-public class TestSpringmvcV2V1 {
- @Test
- public void add_add() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(SpringmvcAddV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2, 3};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(2, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- }
-
- @Test
- public void add_addWrapper() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(SpringmvcAddWrapperV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2, 3};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(2, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- }
-
- @Test
- public void add_addBody() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(SpringmvcAddBodyV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2, 3};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- LinkedHashMap<String, Object> map = invocation.getSwaggerArgument(0);
- Assert.assertEquals(2, map.size());
- Assert.assertEquals(1, map.get("x"));
- Assert.assertEquals(2, map.get("y"));
- }
-
- @Test
- public void addBody_add() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(SpringmvcAddV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV2(1, 2, 3)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(2, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- }
-
- @Test
- public void addBody_addWrapper() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(SpringmvcAddWrapperV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV2(1, 2, 3)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(2, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- }
-
- @Test
- public void addBody_addBody() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(SpringmvcAddBodyV1.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV2(1, 2, 3)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertSame(arguments[0], invocation.getSwaggerArgument(0));
- }
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestSpringmvcV2V2.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestSpringmvcV2V2.java
deleted file mode 100644
index 9e35e8f..0000000
--- a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/consumer/TestSpringmvcV2V2.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * 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.
- * The ASF licenses this file to You 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.apache.servicecomb.swagger.invocation.arguments.consumer;
-
-import java.util.LinkedHashMap;
-
-import org.apache.servicecomb.swagger.engine.SwaggerConsumer;
-import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
-import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddBodyV2;
-import org.apache.servicecomb.swagger.invocation.schemas.ConsumerAddV2;
-import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddBodyV2;
-import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddV2;
-import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddWrapperV2;
-import org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV2;
-import org.junit.Assert;
-import org.junit.Test;
-
-import io.swagger.models.Swagger;
-
-public class TestSpringmvcV2V2 {
- @Test
- public void add_add() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(SpringmvcAddV2.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2, 3};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(3, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- Assert.assertEquals(3, (int) invocation.getSwaggerArgument(2));
- }
-
- @Test
- public void add_addWrapper() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(SpringmvcAddWrapperV2.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2, 3};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(3, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- Assert.assertEquals(3, (int) invocation.getSwaggerArgument(2));
- }
-
- @Test
- public void add_addBody() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(SpringmvcAddBodyV2.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {1, 2, 3};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- LinkedHashMap<String, Object> map = invocation.getSwaggerArgument(0);
- Assert.assertEquals(3, map.size());
- Assert.assertEquals(1, map.get("x"));
- Assert.assertEquals(2, map.get("y"));
- Assert.assertEquals(3, map.get("x-z"));
- }
-
- @Test
- public void addBody_add() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(SpringmvcAddV2.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV2(1, 2, 3)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(3, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- Assert.assertEquals(3, (int) invocation.getSwaggerArgument(2));
- }
-
- @Test
- public void addBody_addWrapper() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(SpringmvcAddWrapperV2.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV2(1, 2, 3)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertEquals(3, invocation.getSwaggerArguments().length);
- Assert.assertEquals(1, (int) invocation.getSwaggerArgument(0));
- Assert.assertEquals(2, (int) invocation.getSwaggerArgument(1));
- Assert.assertEquals(3, (int) invocation.getSwaggerArgument(2));
- }
-
- @Test
- public void addBody_addBody() {
- SwaggerEnvironment environment = new SwaggerEnvironment();
- Swagger swagger = SwaggerGenerator.generate(SpringmvcAddBodyV2.class);
-
- SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
- ConsumerArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
-
- Object[] arguments = new Object[] {new AddWrapperV2(1, 2, 3)};
- SwaggerInvocation invocation = new SwaggerInvocation();
-
- mapper.toInvocation(arguments, invocation);
-
- Assert.assertSame(arguments[0], invocation.getSwaggerArgument(0));
- }
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestJaxrs.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestJaxrs.java
deleted file mode 100644
index 0559101..0000000
--- a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestJaxrs.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * 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.
- * The ASF licenses this file to You 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.apache.servicecomb.swagger.invocation.arguments.producer;
-
-import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
-import org.apache.servicecomb.swagger.engine.SwaggerProducer;
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddBeanParamV1;
-import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddBodyV1;
-import org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddV1;
-import org.apache.servicecomb.swagger.invocation.schemas.models.AddBeanParamV1;
-import org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV1;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class TestJaxrs {
- @Test
- public void add() {
- SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new JaxrsAddV1(), null);
- ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
-
- SwaggerInvocation invocation = new SwaggerInvocation();
- invocation.setSwaggerArguments(new Object[] {1, 2});
-
- Object[] arguments = mapper.toProducerArgs(invocation);
-
- Assert.assertEquals(2, arguments.length);
- Assert.assertEquals(1, arguments[0]);
- Assert.assertEquals(2, arguments[1]);
- }
-
- @Test
- public void addBeanParam() {
- SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new JaxrsAddBeanParamV1(), null);
- ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
-
- SwaggerInvocation invocation = new SwaggerInvocation();
- invocation.setSwaggerArguments(new Object[] {1, 2});
-
- Object[] arguments = mapper.toProducerArgs(invocation);
-
- Assert.assertEquals(1, arguments.length);
- AddBeanParamV1 paramV1 = (AddBeanParamV1) arguments[0];
- Assert.assertEquals(1, paramV1.getX());
- Assert.assertEquals(2, paramV1.y);
- }
-
- @Test
- public void addBody() {
- SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new JaxrsAddBodyV1(), null);
- ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
-
- AddWrapperV1 addBody = new AddWrapperV1();
- SwaggerInvocation invocation = new SwaggerInvocation();
- invocation.setSwaggerArguments(new Object[] {addBody});
-
- Object[] arguments = mapper.toProducerArgs(invocation);
-
- Assert.assertEquals(1, arguments.length);
- Assert.assertSame(addBody, arguments[0]);
- }
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestPojo.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestPojo.java
deleted file mode 100644
index 6ec4af5..0000000
--- a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestPojo.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * 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.
- * The ASF licenses this file to You 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.apache.servicecomb.swagger.invocation.arguments.producer;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
-import org.apache.servicecomb.swagger.engine.SwaggerProducer;
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.schemas.PojoAddBodyV1;
-import org.apache.servicecomb.swagger.invocation.schemas.PojoAddV1;
-import org.apache.servicecomb.swagger.invocation.schemas.PojoAddWithContextV1;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class TestPojo {
- static Map<String, Object> addBody = new HashMap<>();
-
- static {
- addBody.put("x", 1);
- addBody.put("y", 2);
- }
-
- @Test
- public void add() {
- SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new PojoAddV1(), null);
- ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
-
- SwaggerInvocation invocation = new SwaggerInvocation();
- invocation.setSwaggerArguments(new Object[] {addBody});
-
- Object[] arguments = mapper.toProducerArgs(invocation);
-
- Assert.assertEquals(2, arguments.length);
- Assert.assertEquals(1, arguments[0]);
- Assert.assertEquals(2, arguments[1]);
- }
-
- @Test
- public void addBody() {
- SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new PojoAddBodyV1(), null);
- ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
-
- SwaggerInvocation invocation = new SwaggerInvocation();
- invocation.setSwaggerArguments(new Object[] {addBody});
-
- Object[] arguments = mapper.toProducerArgs(invocation);
-
- Assert.assertEquals(1, arguments.length);
- Assert.assertSame(addBody, arguments[0]);
- }
-
- @Test
- public void addWithContext_add() {
- SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new PojoAddWithContextV1(), null);
- ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
-
- SwaggerInvocation invocation = new SwaggerInvocation();
- invocation.setSwaggerArguments(new Object[] {addBody});
-
- Object[] arguments = mapper.toProducerArgs(invocation);
-
- Assert.assertEquals(3, arguments.length);
- Assert.assertSame(invocation, arguments[0]);
- Assert.assertEquals(1, arguments[1]);
- Assert.assertEquals(2, arguments[2]);
- }
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestPojoOneArg.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestPojoOneArg.java
deleted file mode 100644
index df8573d..0000000
--- a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestPojoOneArg.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.
- * The ASF licenses this file to You 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.apache.servicecomb.swagger.invocation.arguments.producer;
-
-import java.util.Collections;
-
-import org.apache.servicecomb.foundation.test.scaffolding.model.Color;
-import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
-import org.apache.servicecomb.swagger.engine.SwaggerProducer;
-import org.apache.servicecomb.swagger.engine.SwaggerProducerOperation;
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.schemas.PojoOneArg;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class TestPojoOneArg {
- @Test
- public void should_mapper_swagger_wrapped_body_field_to_producer_enum() {
- SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new PojoOneArg(), null);
- SwaggerProducerOperation swaggerProducerOperation = swaggerProducer.findOperation("enumBody");
- Assert.assertEquals("color",
- swaggerProducerOperation.getSwaggerOperation().getOperation().getParameters().get(0).getName());
-
- ProducerArgumentsMapper mapper = swaggerProducerOperation.getArgumentsMapper();
-
- SwaggerInvocation invocation = new SwaggerInvocation();
- invocation.setSwaggerArguments(new Object[] {Collections.singletonMap("color", "BLUE")});
-
- Object[] arguments = mapper.toProducerArgs(invocation);
-
- Assert.assertEquals(1, arguments.length);
- Assert.assertSame(Color.BLUE, arguments[0]);
- }
-}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestSpringmvc.java b/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestSpringmvc.java
deleted file mode 100644
index 3991da8..0000000
--- a/swagger/swagger-invocation/invocation-core/src/test/java/org/apache/servicecomb/swagger/invocation/arguments/producer/TestSpringmvc.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * 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.
- * The ASF licenses this file to You 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.apache.servicecomb.swagger.invocation.arguments.producer;
-
-import org.apache.servicecomb.swagger.engine.SwaggerEnvironment;
-import org.apache.servicecomb.swagger.engine.SwaggerProducer;
-import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
-import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddBodyV1;
-import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddV1;
-import org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddWrapperV1;
-import org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV1;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class TestSpringmvc {
- @Test
- public void add() {
- SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new SpringmvcAddV1(), null);
- ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
-
- SwaggerInvocation invocation = new SwaggerInvocation();
- invocation.setSwaggerArguments(new Object[] {1, 2});
-
- Object[] arguments = mapper.toProducerArgs(invocation);
-
- Assert.assertEquals(2, arguments.length);
- Assert.assertEquals(1, arguments[0]);
- Assert.assertEquals(2, arguments[1]);
- }
-
- @Test
- public void addWrapper() {
- SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new SpringmvcAddWrapperV1(), null);
- ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
-
- SwaggerInvocation invocation = new SwaggerInvocation();
- invocation.setSwaggerArguments(new Object[] {1, 2});
-
- Object[] arguments = mapper.toProducerArgs(invocation);
-
- Assert.assertEquals(1, arguments.length);
- AddWrapperV1 paramV1 = (AddWrapperV1) arguments[0];
- Assert.assertEquals(1, paramV1.getX());
- Assert.assertEquals(2, paramV1.y);
- }
-
- @Test
- public void addBody() {
- SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new SpringmvcAddBodyV1(), null);
- ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
-
- AddWrapperV1 addBody = new AddWrapperV1();
- SwaggerInvocation invocation = new SwaggerInvocation();
- invocation.setSwaggerArguments(new Object[] {addBody});
-
- Object[] arguments = mapper.toProducerArgs(invocation);
-
- Assert.assertEquals(1, arguments.length);
- Assert.assertSame(addBody, arguments[0]);
- }
-}
diff --git a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/http/RestClientInvocation.java b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/http/RestClientInvocation.java
index 41d66d7..995575a 100644
--- a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/http/RestClientInvocation.java
+++ b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/http/RestClientInvocation.java
@@ -295,7 +295,7 @@ public class RestClientInvocation {
String path = (String) invocation.getHandlerContext().get(RestConst.REST_CLIENT_REQUEST_PATH);
if (path == null) {
- path = swaggerRestOperation.getPathBuilder().createRequestPath(invocation.getArgs());
+ path = swaggerRestOperation.getPathBuilder().createRequestPath(invocation.getArguments());
}
if (StringUtils.isEmpty(urlPrefix) || path.startsWith(urlPrefix)) {