Search in sources :

Example 11 with SwaggerEnvironment

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

the class TestPojo method add.

@Test
public void add() {
    SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new PojoAddV1(), null);
    ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
    SwaggerInvocation invocation = new SwaggerInvocation();
    Map<String, Object> arguments = new HashMap<>();
    arguments.put("addBody", addBody);
    Map<String, Object> result = mapper.swaggerArgumentToInvocationArguments(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) SwaggerProducer(org.apache.servicecomb.swagger.engine.SwaggerProducer) HashMap(java.util.HashMap) SwaggerEnvironment(org.apache.servicecomb.swagger.engine.SwaggerEnvironment) PojoAddV1(org.apache.servicecomb.swagger.invocation.schemas.PojoAddV1) Test(org.junit.Test)

Example 12 with SwaggerEnvironment

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

the class TestPojo method addBody.

@Test
public void addBody() {
    SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new PojoAddBodyV1(), null);
    ProducerArgumentsMapper mapper = swaggerProducer.findOperation("add").getArgumentsMapper();
    SwaggerInvocation invocation = new SwaggerInvocation();
    Map<String, Object> arguments = new HashMap<>();
    arguments.put("addBody", addBody);
    Map<String, Object> result = mapper.swaggerArgumentToInvocationArguments(invocation, arguments);
    Assert.assertEquals(1, result.size());
    Assert.assertSame(addBody, result.get("addBody"));
}
Also used : SwaggerInvocation(org.apache.servicecomb.swagger.invocation.SwaggerInvocation) SwaggerProducer(org.apache.servicecomb.swagger.engine.SwaggerProducer) HashMap(java.util.HashMap) PojoAddBodyV1(org.apache.servicecomb.swagger.invocation.schemas.PojoAddBodyV1) SwaggerEnvironment(org.apache.servicecomb.swagger.engine.SwaggerEnvironment) Test(org.junit.Test)

Example 13 with SwaggerEnvironment

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

the class TestJaxrs method add.

@Test
public void add() {
    SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new JaxrsAddV1(), 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(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) SwaggerProducer(org.apache.servicecomb.swagger.engine.SwaggerProducer) HashMap(java.util.HashMap) JaxrsAddV1(org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddV1) SwaggerEnvironment(org.apache.servicecomb.swagger.engine.SwaggerEnvironment) Test(org.junit.Test)

Example 14 with SwaggerEnvironment

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

the class TestPojoOneArg method should_mapper_swagger_wrapped_body_field_to_producer_enum.

@Test
public void should_mapper_swagger_wrapped_body_field_to_producer_enum() {
    SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new PojoOneArg(), null);
    SwaggerProducerOperation swaggerProducerOperation = swaggerProducer.findOperation("enumBody");
    Assert.assertEquals("color", swaggerProducerOperation.getSwaggerOperation().getOperation().getParameters().get(0).getName());
    ProducerArgumentsMapper mapper = swaggerProducerOperation.getArgumentsMapper();
    SwaggerInvocation invocation = new SwaggerInvocation();
    Map<String, Object> swaggerArguments = new HashMap<>();
    Map<String, Object> arguments = new HashMap<>();
    arguments.put("color", "BLUE");
    swaggerArguments.put("color", arguments);
    Map<String, Object> result = mapper.swaggerArgumentToInvocationArguments(invocation, swaggerArguments);
    Assert.assertEquals(1, result.size());
    Assert.assertSame(Color.BLUE, result.get("color"));
}
Also used : SwaggerInvocation(org.apache.servicecomb.swagger.invocation.SwaggerInvocation) SwaggerProducer(org.apache.servicecomb.swagger.engine.SwaggerProducer) HashMap(java.util.HashMap) SwaggerProducerOperation(org.apache.servicecomb.swagger.engine.SwaggerProducerOperation) SwaggerEnvironment(org.apache.servicecomb.swagger.engine.SwaggerEnvironment) PojoOneArg(org.apache.servicecomb.swagger.invocation.schemas.PojoOneArg) Test(org.junit.Test)

Example 15 with SwaggerEnvironment

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

the class TestSpringmvc method addWrapper.

@Test
public void addWrapper() {
    SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new SpringmvcAddWrapperV1(), 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());
    AddWrapperV1 paramV1 = (AddWrapperV1) result.get("wrapper");
    Assert.assertEquals(1, paramV1.getX());
    Assert.assertEquals(2, paramV1.y);
}
Also used : SwaggerInvocation(org.apache.servicecomb.swagger.invocation.SwaggerInvocation) SpringmvcAddWrapperV1(org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddWrapperV1) AddWrapperV1(org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV1) SpringmvcAddWrapperV1(org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddWrapperV1) SwaggerProducer(org.apache.servicecomb.swagger.engine.SwaggerProducer) HashMap(java.util.HashMap) SwaggerEnvironment(org.apache.servicecomb.swagger.engine.SwaggerEnvironment) 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