Search in sources :

Example 46 with SwaggerEnvironment

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);
}
Also used : Endpoint(org.apache.servicecomb.core.Endpoint) Invocation(org.apache.servicecomb.core.Invocation) SwaggerConsumer(org.apache.servicecomb.swagger.engine.SwaggerConsumer) SwaggerConsumerOperation(org.apache.servicecomb.swagger.engine.SwaggerConsumerOperation) Holder(org.apache.servicecomb.foundation.common.Holder) SwaggerEnvironment(org.apache.servicecomb.swagger.engine.SwaggerEnvironment) Transport(org.apache.servicecomb.core.Transport) Test(org.junit.jupiter.api.Test)

Example 47 with SwaggerEnvironment

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);
}
Also used : SwaggerInvocation(org.apache.servicecomb.swagger.invocation.SwaggerInvocation) JaxrsAddBeanParamV1(org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddBeanParamV1) SwaggerProducer(org.apache.servicecomb.swagger.engine.SwaggerProducer) HashMap(java.util.HashMap) JaxrsAddBeanParamV1(org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddBeanParamV1) AddBeanParamV1(org.apache.servicecomb.swagger.invocation.schemas.models.AddBeanParamV1) SwaggerEnvironment(org.apache.servicecomb.swagger.engine.SwaggerEnvironment) Test(org.junit.Test)

Example 48 with SwaggerEnvironment

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"));
}
Also used : JaxrsAddBodyV1(org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddBodyV1) AddWrapperV1(org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV1) SwaggerInvocation(org.apache.servicecomb.swagger.invocation.SwaggerInvocation) SwaggerProducer(org.apache.servicecomb.swagger.engine.SwaggerProducer) HashMap(java.util.HashMap) SwaggerEnvironment(org.apache.servicecomb.swagger.engine.SwaggerEnvironment) Test(org.junit.Test)

Example 49 with SwaggerEnvironment

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"));
}
Also used : AddWrapperV1(org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV1) SwaggerInvocation(org.apache.servicecomb.swagger.invocation.SwaggerInvocation) SwaggerConsumer(org.apache.servicecomb.swagger.engine.SwaggerConsumer) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Swagger(io.swagger.models.Swagger) SwaggerEnvironment(org.apache.servicecomb.swagger.engine.SwaggerEnvironment) ArgumentsMapper(org.apache.servicecomb.swagger.invocation.arguments.ArgumentsMapper) Test(org.junit.Test)

Example 50 with SwaggerEnvironment

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"));
}
Also used : SwaggerInvocation(org.apache.servicecomb.swagger.invocation.SwaggerInvocation) SwaggerConsumer(org.apache.servicecomb.swagger.engine.SwaggerConsumer) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Swagger(io.swagger.models.Swagger) SwaggerEnvironment(org.apache.servicecomb.swagger.engine.SwaggerEnvironment) ArgumentsMapper(org.apache.servicecomb.swagger.invocation.arguments.ArgumentsMapper) Test(org.junit.Test)

Aggregations

SwaggerEnvironment (org.apache.servicecomb.swagger.engine.SwaggerEnvironment)83 HashMap (java.util.HashMap)79 SwaggerInvocation (org.apache.servicecomb.swagger.invocation.SwaggerInvocation)79 Test (org.junit.Test)78 Swagger (io.swagger.models.Swagger)71 SwaggerConsumer (org.apache.servicecomb.swagger.engine.SwaggerConsumer)70 ArgumentsMapper (org.apache.servicecomb.swagger.invocation.arguments.ArgumentsMapper)69 LinkedHashMap (java.util.LinkedHashMap)27 AddWrapperV1 (org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV1)19 AddWrapperV2 (org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV2)16 SwaggerProducer (org.apache.servicecomb.swagger.engine.SwaggerProducer)12 SpringmvcAddWrapperV1 (org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddWrapperV1)5 SwaggerProducerOperation (org.apache.servicecomb.swagger.engine.SwaggerProducerOperation)3 SpringmvcAddWrapperV2 (org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddWrapperV2)3 Expectations (mockit.Expectations)2 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)2 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)2 ProtoSchema (org.apache.servicecomb.codec.protobuf.internal.converter.model.ProtoSchema)1 Endpoint (org.apache.servicecomb.core.Endpoint)1 Invocation (org.apache.servicecomb.core.Invocation)1