use of org.apache.servicecomb.swagger.engine.SwaggerEnvironment in project java-chassis by ServiceComb.
the class EndpointTest method should_set_endpoint_to_invocation_when_map_arguments.
@Test
void should_set_endpoint_to_invocation_when_map_arguments() {
SwaggerEnvironment environment = new SwaggerEnvironment();
SwaggerConsumer consumer = environment.createConsumer(TestSchema.class, SwaggerGenerator.generate(TestSchema.class));
SwaggerConsumerOperation operation = consumer.findOperation("say");
Endpoint endpoint = new Endpoint(Mockito.mock(Transport.class), null);
Invocation invocation = Mockito.mock(Invocation.class);
Holder<Object> holder = new Holder<>();
Mockito.doAnswer(invocationOnMock -> {
holder.value = invocationOnMock.getArguments()[0];
return null;
}).when(invocation).setEndpoint(Mockito.any());
Map<String, Object> argsMap = of("endpoint", endpoint);
operation.getArgumentsMapper().invocationArgumentToSwaggerArguments(invocation, argsMap);
assertThat(holder.value).isSameAs(endpoint);
}
use of org.apache.servicecomb.swagger.engine.SwaggerEnvironment in project java-chassis by ServiceComb.
the class TestJaxrs method addBeanParam.
@Test
public void addBeanParam() {
SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new JaxrsAddBeanParamV1(), null);
ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
Map<String, Object> arguments = new HashMap<>();
arguments.put("x", 1);
arguments.put("y", 2);
SwaggerInvocation invocation = new SwaggerInvocation();
Map<String, Object> result = mapper.swaggerArgumentToInvocationArguments(invocation, arguments);
Assert.assertEquals(1, result.size());
AddBeanParamV1 paramV1 = (AddBeanParamV1) result.get("wrapper");
Assert.assertEquals(1, paramV1.getX());
Assert.assertEquals(2, paramV1.y);
}
use of org.apache.servicecomb.swagger.engine.SwaggerEnvironment in project java-chassis by ServiceComb.
the class TestJaxrs method addBody.
@Test
public void addBody() {
SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new JaxrsAddBodyV1(), null);
ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
AddWrapperV1 addBody = new AddWrapperV1();
Map<String, Object> arguments = new HashMap<>();
arguments.put("addBody", addBody);
SwaggerInvocation invocation = new SwaggerInvocation();
Map<String, Object> result = mapper.swaggerArgumentToInvocationArguments(invocation, arguments);
Assert.assertEquals(1, result.size());
Assert.assertSame(addBody, result.get("addBody"));
}
use of org.apache.servicecomb.swagger.engine.SwaggerEnvironment in project java-chassis by ServiceComb.
the class TestJaxrsV1V1 method should_mapper_consumer_body_to_swagger_body.
@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);
ArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
Map<String, Object> arguments = new HashMap<>();
arguments.put("addBody", new AddWrapperV1(1, 2));
SwaggerInvocation invocation = new SwaggerInvocation();
Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
Assert.assertSame(result.get("addBody"), arguments.get("addBody"));
}
use of org.apache.servicecomb.swagger.engine.SwaggerEnvironment in project java-chassis by ServiceComb.
the class TestJaxrsV1V1 method should_mapper_consumer_multi_args_to_swagger_multi_args_with_diff_order.
@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);
ArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
Map<String, Object> arguments = new HashMap<>();
arguments.put("x", 1);
arguments.put("y", 2);
SwaggerInvocation invocation = new SwaggerInvocation();
Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
Assert.assertEquals(2, result.size());
Assert.assertEquals(1, (int) result.get("x"));
Assert.assertEquals(2, (int) result.get("y"));
}
Aggregations