You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ni...@apache.org on 2018/01/02 10:44:49 UTC
[incubator-servicecomb-java-chassis] 01/03: JAV-575 create
ExceptionToResponseConverter
This is an automated email from the ASF dual-hosted git repository.
ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git
commit b4fd84110d096eeac40972df121757a91c9cbb8c
Author: wujimin <wu...@huawei.com>
AuthorDate: Wed Dec 27 15:19:27 2017 +0800
JAV-575 create ExceptionToResponseConverter
---
.../schema/TestProducerSchemaFactory.java | 9 ++-
.../swagger/invocation/SwaggerInvocation.java | 4 ++
.../DefaultExceptionToResponseConverter.java | 39 ++++++++++++
.../invocation/exception/ExceptionFactory.java | 8 +++
.../exception/ExceptionToResponseConverter.java | 26 ++++++++
.../exception/ExceptionToResponseConverters.java | 49 +++++++++++++++
.../InvocationExceptionToResponseConverter.java | 32 ++++++++++
...vocation.exception.ExceptionToResponseConverter | 19 ++++++
.../exception/ErrorToResponseConverter.java | 34 +++++++++++
.../TestDefaultExceptionToResponseConverter.java | 39 ++++++++++++
.../invocation/exception/TestExceptionFactory.java | 35 +++++++++++
.../TestExceptionToResponseConverters.java | 71 ++++++++++++++++++++++
...TestInvocationExceptionToResponseConverter.java | 39 ++++++++++++
...vocation.exception.ExceptionToResponseConverter | 1 +
14 files changed, 403 insertions(+), 2 deletions(-)
diff --git a/core/src/test/java/io/servicecomb/core/definition/schema/TestProducerSchemaFactory.java b/core/src/test/java/io/servicecomb/core/definition/schema/TestProducerSchemaFactory.java
index 84bf2e4..7a4a681 100644
--- a/core/src/test/java/io/servicecomb/core/definition/schema/TestProducerSchemaFactory.java
+++ b/core/src/test/java/io/servicecomb/core/definition/schema/TestProducerSchemaFactory.java
@@ -110,14 +110,19 @@ public class TestProducerSchemaFactory {
Object addBody = Class.forName("cse.gen.app.ms.schema.addBody").newInstance();
ReflectUtils.setField(addBody, "x", 1);
ReflectUtils.setField(addBody, "y", 2);
- Invocation invocation = new Invocation((Endpoint) null, operationMeta, new Object[] {addBody});
+ Invocation invocation = new Invocation((Endpoint) null, operationMeta, new Object[] {addBody}) {
+ @Override
+ public String getInvocationQualifiedName() {
+ return "";
+ }
+ };
Holder<Response> holder = new Holder<>();
producerOperation.invoke(invocation, resp -> {
holder.value = resp;
});
Assert.assertEquals(3, (int) holder.value.getResult());
- invocation = new Invocation((Endpoint) null, operationMeta, new Object[] {1, 2});
+ invocation.setSwaggerArguments(new Object[] {1, 2});
producerOperation.invoke(invocation, resp -> {
holder.value = resp;
});
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/SwaggerInvocation.java b/swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/SwaggerInvocation.java
index be102dd..277b896 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/SwaggerInvocation.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/SwaggerInvocation.java
@@ -53,4 +53,8 @@ public class SwaggerInvocation extends InvocationContext {
public void setSwaggerArgument(int idx, Object swaggerArgument) {
this.swaggerArguments[idx] = swaggerArgument;
}
+
+ public String getInvocationQualifiedName() {
+ return invocationType.name();
+ }
}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/exception/DefaultExceptionToResponseConverter.java b/swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/exception/DefaultExceptionToResponseConverter.java
new file mode 100644
index 0000000..b599ce8
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/exception/DefaultExceptionToResponseConverter.java
@@ -0,0 +1,39 @@
+/*
+ * 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 io.servicecomb.swagger.invocation.exception;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import io.servicecomb.swagger.invocation.Response;
+import io.servicecomb.swagger.invocation.SwaggerInvocation;
+
+public class DefaultExceptionToResponseConverter implements ExceptionToResponseConverter<Throwable> {
+ private static final Logger LOGGER = LoggerFactory.getLogger(DefaultExceptionToResponseConverter.class);
+
+ @Override
+ public Class<Throwable> getExceptionClass() {
+ // default logic, not bind to special class
+ return null;
+ }
+
+ @Override
+ public Response convert(SwaggerInvocation swaggerInvocation, Throwable e) {
+ LOGGER.error("invoke failed, invocation={}", swaggerInvocation.getInvocationQualifiedName(), e);
+ return Response.producerFailResp(e);
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/exception/ExceptionFactory.java b/swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/exception/ExceptionFactory.java
index 821e0a6..d4dc569 100644
--- a/swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/exception/ExceptionFactory.java
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/exception/ExceptionFactory.java
@@ -20,6 +20,8 @@ import java.lang.reflect.InvocationTargetException;
import javax.ws.rs.core.Response.StatusType;
+import io.servicecomb.swagger.invocation.Response;
+import io.servicecomb.swagger.invocation.SwaggerInvocation;
import io.servicecomb.swagger.invocation.context.HttpStatus;
public final class ExceptionFactory {
@@ -42,6 +44,8 @@ public final class ExceptionFactory {
public static final String CONSUMER_INNER_REASON_PHRASE = "Cse Internal Bad Request";
+ private static ExceptionToResponseConverters exceptionToResponseConverters = new ExceptionToResponseConverters();
+
public static final StatusType CONSUMER_INNER_STATUS =
new HttpStatus(CONSUMER_INNER_STATUS_CODE, CONSUMER_INNER_REASON_PHRASE);
@@ -119,4 +123,8 @@ public final class ExceptionFactory {
CommonExceptionData data = new CommonExceptionData(errorMsg);
return doCreate(statusCode, reasonPhrase, data, e);
}
+
+ public static Response convertExceptionToResponse(SwaggerInvocation swaggerInvocation, Throwable e) {
+ return exceptionToResponseConverters.convertExceptionToResponse(swaggerInvocation, e);
+ }
}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/exception/ExceptionToResponseConverter.java b/swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/exception/ExceptionToResponseConverter.java
new file mode 100644
index 0000000..3a3e9e0
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/exception/ExceptionToResponseConverter.java
@@ -0,0 +1,26 @@
+/*
+ * 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 io.servicecomb.swagger.invocation.exception;
+
+import io.servicecomb.swagger.invocation.Response;
+import io.servicecomb.swagger.invocation.SwaggerInvocation;
+
+public interface ExceptionToResponseConverter<T extends Throwable> {
+ Class<T> getExceptionClass();
+
+ Response convert(SwaggerInvocation swaggerInvocation, T e);
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/exception/ExceptionToResponseConverters.java b/swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/exception/ExceptionToResponseConverters.java
new file mode 100644
index 0000000..31a8a0c
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/exception/ExceptionToResponseConverters.java
@@ -0,0 +1,49 @@
+/*
+ * 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 io.servicecomb.swagger.invocation.exception;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import io.servicecomb.foundation.common.utils.SPIServiceUtils;
+import io.servicecomb.swagger.invocation.Response;
+import io.servicecomb.swagger.invocation.SwaggerInvocation;
+
+public class ExceptionToResponseConverters {
+ private Map<Class<?>, ExceptionToResponseConverter<Throwable>> exceptionToResponseConverters =
+ new HashMap<>();
+
+ private ExceptionToResponseConverter<Throwable> defaultConverter;
+
+ @SuppressWarnings("unchecked")
+ public ExceptionToResponseConverters() {
+ SPIServiceUtils.getAllService(ExceptionToResponseConverter.class).forEach(converter -> {
+ if (converter.getExceptionClass() == null) {
+ defaultConverter = converter;
+ return;
+ }
+
+ exceptionToResponseConverters.put(converter.getExceptionClass(), converter);
+ });
+ }
+
+ public Response convertExceptionToResponse(SwaggerInvocation swaggerInvocation, Throwable e) {
+ ExceptionToResponseConverter<Throwable> converter =
+ exceptionToResponseConverters.getOrDefault(e.getClass(), defaultConverter);
+ return converter.convert(swaggerInvocation, e);
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/exception/InvocationExceptionToResponseConverter.java b/swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/exception/InvocationExceptionToResponseConverter.java
new file mode 100644
index 0000000..43b1ee8
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/main/java/io/servicecomb/swagger/invocation/exception/InvocationExceptionToResponseConverter.java
@@ -0,0 +1,32 @@
+/*
+ * 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 io.servicecomb.swagger.invocation.exception;
+
+import io.servicecomb.swagger.invocation.Response;
+import io.servicecomb.swagger.invocation.SwaggerInvocation;
+
+public class InvocationExceptionToResponseConverter implements ExceptionToResponseConverter<InvocationException> {
+ @Override
+ public Class<InvocationException> getExceptionClass() {
+ return InvocationException.class;
+ }
+
+ @Override
+ public Response convert(SwaggerInvocation swaggerInvocation, InvocationException e) {
+ return Response.failResp(e);
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/main/resources/META-INF/services/io.servicecomb.swagger.invocation.exception.ExceptionToResponseConverter b/swagger/swagger-invocation/invocation-core/src/main/resources/META-INF/services/io.servicecomb.swagger.invocation.exception.ExceptionToResponseConverter
new file mode 100644
index 0000000..1314c53
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/main/resources/META-INF/services/io.servicecomb.swagger.invocation.exception.ExceptionToResponseConverter
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+
+io.servicecomb.swagger.invocation.exception.InvocationExceptionToResponseConverter
+io.servicecomb.swagger.invocation.exception.DefaultExceptionToResponseConverter
\ No newline at end of file
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/io/servicecomb/swagger/invocation/exception/ErrorToResponseConverter.java b/swagger/swagger-invocation/invocation-core/src/test/java/io/servicecomb/swagger/invocation/exception/ErrorToResponseConverter.java
new file mode 100644
index 0000000..92bb4ff
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/io/servicecomb/swagger/invocation/exception/ErrorToResponseConverter.java
@@ -0,0 +1,34 @@
+/*
+ * 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 io.servicecomb.swagger.invocation.exception;
+
+import javax.ws.rs.core.Response.Status;
+
+import io.servicecomb.swagger.invocation.Response;
+import io.servicecomb.swagger.invocation.SwaggerInvocation;
+
+public class ErrorToResponseConverter implements ExceptionToResponseConverter<Error> {
+ @Override
+ public Class<Error> getExceptionClass() {
+ return Error.class;
+ }
+
+ @Override
+ 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/io/servicecomb/swagger/invocation/exception/TestDefaultExceptionToResponseConverter.java b/swagger/swagger-invocation/invocation-core/src/test/java/io/servicecomb/swagger/invocation/exception/TestDefaultExceptionToResponseConverter.java
new file mode 100644
index 0000000..b759d2d
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/io/servicecomb/swagger/invocation/exception/TestDefaultExceptionToResponseConverter.java
@@ -0,0 +1,39 @@
+/*
+ * 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 io.servicecomb.swagger.invocation.exception;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import io.servicecomb.swagger.invocation.Response;
+import io.servicecomb.swagger.invocation.SwaggerInvocation;
+import mockit.Mocked;
+
+public class TestDefaultExceptionToResponseConverter {
+ DefaultExceptionToResponseConverter converter = new DefaultExceptionToResponseConverter();
+
+ @Test
+ public void getExceptionClass() {
+ Assert.assertNull(converter.getExceptionClass());
+ }
+
+ @Test
+ public void convert(@Mocked SwaggerInvocation swaggerInvocation, @Mocked Error e) {
+ Response response = converter.convert(swaggerInvocation, e);
+ Assert.assertSame(e, ((InvocationException) response.getResult()).getCause());
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/io/servicecomb/swagger/invocation/exception/TestExceptionFactory.java b/swagger/swagger-invocation/invocation-core/src/test/java/io/servicecomb/swagger/invocation/exception/TestExceptionFactory.java
new file mode 100644
index 0000000..73883c3
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/io/servicecomb/swagger/invocation/exception/TestExceptionFactory.java
@@ -0,0 +1,35 @@
+/*
+ * 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 io.servicecomb.swagger.invocation.exception;
+
+import javax.ws.rs.core.Response.Status;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import io.servicecomb.swagger.invocation.Response;
+
+public class TestExceptionFactory {
+ @Test
+ public void convertExceptionToResponse() {
+ Error error = new Error("test");
+ Response response = ExceptionFactory.convertExceptionToResponse(null, error);
+
+ Assert.assertSame(Status.OK, response.getStatus());
+ Assert.assertEquals("response from error: test", response.getResult());
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/io/servicecomb/swagger/invocation/exception/TestExceptionToResponseConverters.java b/swagger/swagger-invocation/invocation-core/src/test/java/io/servicecomb/swagger/invocation/exception/TestExceptionToResponseConverters.java
new file mode 100644
index 0000000..c4a7ce2
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/io/servicecomb/swagger/invocation/exception/TestExceptionToResponseConverters.java
@@ -0,0 +1,71 @@
+/*
+ * 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 io.servicecomb.swagger.invocation.exception;
+
+import java.util.Arrays;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import io.servicecomb.foundation.common.utils.SPIServiceUtils;
+import io.servicecomb.swagger.invocation.Response;
+import io.servicecomb.swagger.invocation.SwaggerInvocation;
+import mockit.Expectations;
+import mockit.Mocked;
+
+public class TestExceptionToResponseConverters {
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ @Test
+ public void convertExceptionToResponse(@Mocked ExceptionToResponseConverter c1,
+ @Mocked Response r1,
+ @Mocked ExceptionToResponseConverter c2,
+ @Mocked Response r2,
+ @Mocked ExceptionToResponseConverter cDef,
+ @Mocked Response rDef) {
+ new Expectations(SPIServiceUtils.class) {
+ {
+ SPIServiceUtils.getAllService(ExceptionToResponseConverter.class);
+ result = Arrays.asList(c1, c2, cDef);
+
+ c1.getExceptionClass();
+ result = Throwable.class;
+ c1.convert((SwaggerInvocation) any, (Throwable) any);
+ result = r1;
+
+ c2.getExceptionClass();
+ result = Exception.class;
+ c2.convert((SwaggerInvocation) any, (Throwable) any);
+ result = r2;
+
+ cDef.getExceptionClass();
+ result = null;
+ cDef.convert((SwaggerInvocation) any, (Throwable) any);
+ result = rDef;
+ }
+ };
+
+ ExceptionToResponseConverters exceptionToResponseConverters = new ExceptionToResponseConverters();
+
+ Assert.assertSame(r1,
+ exceptionToResponseConverters.convertExceptionToResponse((SwaggerInvocation) null, new Throwable()));
+ Assert.assertSame(r2,
+ exceptionToResponseConverters.convertExceptionToResponse((SwaggerInvocation) null, new Exception()));
+ Assert.assertSame(rDef,
+ exceptionToResponseConverters.convertExceptionToResponse((SwaggerInvocation) null,
+ new IllegalStateException()));
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/java/io/servicecomb/swagger/invocation/exception/TestInvocationExceptionToResponseConverter.java b/swagger/swagger-invocation/invocation-core/src/test/java/io/servicecomb/swagger/invocation/exception/TestInvocationExceptionToResponseConverter.java
new file mode 100644
index 0000000..a103604
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/java/io/servicecomb/swagger/invocation/exception/TestInvocationExceptionToResponseConverter.java
@@ -0,0 +1,39 @@
+/*
+ * 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 io.servicecomb.swagger.invocation.exception;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import io.servicecomb.swagger.invocation.Response;
+import io.servicecomb.swagger.invocation.SwaggerInvocation;
+import mockit.Mocked;
+
+public class TestInvocationExceptionToResponseConverter {
+ InvocationExceptionToResponseConverter converter = new InvocationExceptionToResponseConverter();
+
+ @Test
+ public void getExceptionClass() {
+ Assert.assertEquals(InvocationException.class, converter.getExceptionClass());
+ }
+
+ @Test
+ public void convert(@Mocked SwaggerInvocation swaggerInvocation, @Mocked InvocationException e) {
+ Response response = converter.convert(swaggerInvocation, e);
+ Assert.assertSame(e, response.getResult());
+ }
+}
diff --git a/swagger/swagger-invocation/invocation-core/src/test/resources/META-INF/services/io.servicecomb.swagger.invocation.exception.ExceptionToResponseConverter b/swagger/swagger-invocation/invocation-core/src/test/resources/META-INF/services/io.servicecomb.swagger.invocation.exception.ExceptionToResponseConverter
new file mode 100644
index 0000000..bb5a352
--- /dev/null
+++ b/swagger/swagger-invocation/invocation-core/src/test/resources/META-INF/services/io.servicecomb.swagger.invocation.exception.ExceptionToResponseConverter
@@ -0,0 +1 @@
+io.servicecomb.swagger.invocation.exception.ErrorToResponseConverter
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.