use of org.apache.servicecomb.swagger.invocation.context.InvocationContext in project incubator-servicecomb-java-chassis by apache.
the class TestConfig method testContextUtils.
@Test
public void testContextUtils() {
ThreadLocal<InvocationContext> contextMgr = new ThreadLocal<>();
Assert.assertEquals(contextMgr.get(), ContextUtils.getInvocationContext());
SwaggerInvocation invocation = new SwaggerInvocation();
invocation.addContext("test1", "testObject");
Assert.assertEquals("testObject", invocation.getContext("test1"));
Map<String, String> context = new HashMap<>();
context.put("test2", new String("testObject"));
invocation.setContext(context);
Assert.assertEquals(context, invocation.getContext());
invocation.setStatus(Status.OK);
Assert.assertEquals(200, invocation.getStatus().getStatusCode());
invocation.setStatus(204);
Assert.assertEquals(204, invocation.getStatus().getStatusCode());
invocation.setStatus(Status.OK);
Assert.assertEquals((Status.OK).getStatusCode(), invocation.getStatus().getStatusCode());
invocation.setStatus(203, "Done");
Assert.assertEquals(203, invocation.getStatus().getStatusCode());
ContextUtils.setInvocationContext(invocation);
Assert.assertEquals(invocation, ContextUtils.getInvocationContext());
ContextUtils.removeInvocationContext();
Assert.assertEquals(null, ContextUtils.getInvocationContext());
}
use of org.apache.servicecomb.swagger.invocation.context.InvocationContext in project incubator-servicecomb-java-chassis by apache.
the class CodeFirstJaxrs method response.
@ApiResponse(code = 200, response = User.class, message = "")
@ResponseHeaders({ @ResponseHeader(name = "h1", response = String.class), @ResponseHeader(name = "h2", response = String.class) })
@Path("/response")
@GET
public Response response(InvocationContext c1) {
Response response = Response.createSuccess(Status.ACCEPTED, new User());
Headers headers = response.getHeaders();
headers.addHeader("h1", "h1v " + c1.getContext().toString());
InvocationContext c2 = ContextUtils.getInvocationContext();
headers.addHeader("h2", "h2v " + c2.getContext().toString());
return response;
}
use of org.apache.servicecomb.swagger.invocation.context.InvocationContext in project incubator-servicecomb-java-chassis by apache.
the class TestPojoConsumerEqualProducer method testContext.
@Test
public void testContext() throws Exception {
InvocationContext threadContext = new InvocationContext();
threadContext.addContext("ta", "tvalue");
ContextUtils.setInvocationContext(threadContext);
InvocationContext context = new InvocationContext();
context.addContext("a", "value");
String result = proxy.testContext(context, "name");
Object body = invoker.getSwaggerArgument(0);
Assert.assertEquals(3, invoker.getInvocation().getContext().size());
Assert.assertEquals("tvalue", invoker.getContext("ta"));
Assert.assertEquals("value", invoker.getContext("a"));
Assert.assertEquals("name", invoker.getContext("name"));
Assert.assertEquals("name", Utils.getFieldValue(body, "name"));
Assert.assertEquals("name sayhi", result);
}
use of org.apache.servicecomb.swagger.invocation.context.InvocationContext in project incubator-servicecomb-java-chassis by apache.
the class ConsumerInvocationContextMapper method mapArgument.
@Override
public void mapArgument(SwaggerInvocation invocation, Object[] consumerArguments) {
InvocationContext context = (InvocationContext) consumerArguments[consumerIdx];
invocation.addContext(context.getContext());
}
use of org.apache.servicecomb.swagger.invocation.context.InvocationContext in project incubator-servicecomb-java-chassis by apache.
the class PojoClient method testTraceIdOnContextContainsTraceId.
private static void testTraceIdOnContextContainsTraceId() {
InvocationContext context = new InvocationContext();
context.addContext(Const.TRACE_ID_NAME, String.valueOf(Long.MIN_VALUE));
ContextUtils.setInvocationContext(context);
String traceId = test.testTraceId();
TestMgr.check(String.valueOf(Long.MIN_VALUE), traceId);
ContextUtils.removeInvocationContext();
}
Aggregations