use of org.apache.servicecomb.swagger.invocation.context.InvocationContext in project java-chassis by ServiceComb.
the class TestPojoV1V1 method addWithContext_add.
@Test
public void addWithContext_add() {
SwaggerEnvironment environment = new SwaggerEnvironment();
Swagger swagger = SwaggerGenerator.generate(PojoAddV1.class);
SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddWithContext.class, swagger);
ArgumentsMapper 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");
Map<String, Object> arguments = new HashMap<>();
arguments.put("context", invocationContext);
arguments.put("x", 1);
arguments.put("y", 2);
SwaggerInvocation invocation = new SwaggerInvocation();
Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
Assert.assertEquals(1, result.size());
result = (Map<String, Object>) result.get("addBody");
Assert.assertEquals(2, result.size());
Assert.assertEquals(1, result.get("x"));
Assert.assertEquals(2, result.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"));
}
use of org.apache.servicecomb.swagger.invocation.context.InvocationContext in project java-chassis by ServiceComb.
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 java-chassis by ServiceComb.
the class CodeFirstSpringmvcBase method cseResponse.
public Response cseResponse(InvocationContext c1) {
Response response = Response.createSuccess(Status.ACCEPTED, new User());
response.addHeader("h1", "h1v " + c1.getContext().toString());
InvocationContext c2 = ContextUtils.getInvocationContext();
response.addHeader("h2", "h2v " + c2.getContext().toString());
return response;
}
use of org.apache.servicecomb.swagger.invocation.context.InvocationContext in project java-chassis by ServiceComb.
the class CodeFirstSpringmvcBase method responseEntity.
public ResponseEntity<Date> responseEntity(InvocationContext c1, Date date) {
HttpHeaders headers = new HttpHeaders();
headers.add("h1", "h1v " + c1.getContext().toString());
InvocationContext c2 = ContextUtils.getInvocationContext();
headers.add("h2", "h2v " + c2.getContext().toString());
return new ResponseEntity<>(date, headers, HttpStatus.ACCEPTED);
}
use of org.apache.servicecomb.swagger.invocation.context.InvocationContext in project incubator-servicecomb-java-chassis by apache.
the class CodeFirstSpringmvc method responseEntityPATCH.
@ResponseHeaders({ @ResponseHeader(name = "h1", response = String.class), @ResponseHeader(name = "h2", response = String.class) })
@RequestMapping(path = "/responseEntity", method = RequestMethod.PATCH)
public ResponseEntity<Date> responseEntityPATCH(InvocationContext c1, @RequestAttribute("date") Date date) {
HttpHeaders headers = new HttpHeaders();
headers.add("h1", "h1v " + c1.getContext().get(Const.SRC_MICROSERVICE).toString());
InvocationContext c2 = ContextUtils.getInvocationContext();
headers.add("h2", "h2v " + c2.getContext().get(Const.SRC_MICROSERVICE).toString());
return new ResponseEntity<>(date, headers, HttpStatus.ACCEPTED);
}
Aggregations