Search in sources :

Example 31 with SwaggerEnvironment

use of org.apache.servicecomb.swagger.engine.SwaggerEnvironment in project java-chassis by ServiceComb.

the class TestJaxrsV2V2 method addBody_add.

@Test
public void addBody_add() {
    SwaggerEnvironment environment = new SwaggerEnvironment();
    Swagger swagger = SwaggerGenerator.generate(JaxrsAddV2.class);
    SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddBodyV2.class, swagger);
    ArgumentsMapper mapper = swaggerConsumer.findOperation("add").getArgumentsMapper();
    Map<String, Object> arguments = new HashMap<>();
    arguments.put("addBody", new AddWrapperV2(1, 2, 3));
    SwaggerInvocation invocation = new SwaggerInvocation();
    Map<String, Object> result = mapper.invocationArgumentToSwaggerArguments(invocation, arguments);
    Assert.assertEquals(3, result.size());
    Assert.assertEquals(1, (int) result.get("x"));
    Assert.assertEquals(2, (int) result.get("y"));
    Assert.assertEquals(3, (int) result.get("x-z"));
}
Also used : SwaggerInvocation(org.apache.servicecomb.swagger.invocation.SwaggerInvocation) AddWrapperV2(org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV2) SwaggerConsumer(org.apache.servicecomb.swagger.engine.SwaggerConsumer) HashMap(java.util.HashMap) 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 32 with SwaggerEnvironment

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

Example 33 with SwaggerEnvironment

use of org.apache.servicecomb.swagger.engine.SwaggerEnvironment in project java-chassis by ServiceComb.

the class TestPojoV1V1 method add_addBody.

@Test
public void add_addBody() {
    SwaggerEnvironment environment = new SwaggerEnvironment();
    Swagger swagger = SwaggerGenerator.generate(PojoAddBodyV1.class);
    SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.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(1, result.size());
    result = (Map<String, Object>) result.get("addBody");
    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) 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 34 with SwaggerEnvironment

use of org.apache.servicecomb.swagger.engine.SwaggerEnvironment in project java-chassis by ServiceComb.

the class TestPojoV1V1 method add_add.

public void add_add(Class<?> clazz) {
    SwaggerEnvironment environment = new SwaggerEnvironment();
    Swagger swagger = SwaggerGenerator.generate(clazz);
    SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.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(1, result.size());
    result = (Map<String, Object>) result.get("addBody");
    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) Swagger(io.swagger.models.Swagger) SwaggerEnvironment(org.apache.servicecomb.swagger.engine.SwaggerEnvironment) ArgumentsMapper(org.apache.servicecomb.swagger.invocation.arguments.ArgumentsMapper)

Example 35 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.

@Test
public void should_mapper_consumer_multi_args_to_swagger_multi_args() {
    SwaggerEnvironment environment = new SwaggerEnvironment();
    Swagger swagger = SwaggerGenerator.generate(JaxrsAddV1.class);
    SwaggerConsumer swaggerConsumer = environment.createConsumer(ConsumerAddV1.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