Search in sources :

Example 11 with SwaggerProducer

use of org.apache.servicecomb.swagger.engine.SwaggerProducer 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 12 with SwaggerProducer

use of org.apache.servicecomb.swagger.engine.SwaggerProducer 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 13 with SwaggerProducer

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

the class TestPojo method addWithContext_add.

@Test
public void addWithContext_add() {
    SwaggerProducer swaggerProducer = new SwaggerEnvironment().createProducer(new PojoAddWithContextV1(), 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(3, result.size());
    Assert.assertSame(invocation, result.get("context"));
    Assert.assertEquals(1, result.get("x"));
    Assert.assertEquals(2, result.get("y"));
}
Also used : SwaggerInvocation(org.apache.servicecomb.swagger.invocation.SwaggerInvocation) SwaggerProducer(org.apache.servicecomb.swagger.engine.SwaggerProducer) HashMap(java.util.HashMap) PojoAddWithContextV1(org.apache.servicecomb.swagger.invocation.schemas.PojoAddWithContextV1) SwaggerEnvironment(org.apache.servicecomb.swagger.engine.SwaggerEnvironment) Test(org.junit.Test)

Example 14 with SwaggerProducer

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

the class TestSchemaMetaCodecRestTemplate method setUp.

@Before
public void setUp() {
    ProtobufManager.clear();
    new Expectations() {

        {
            providerMicroserviceMeta.getMicroserviceName();
            result = "test";
            providerMicroserviceMeta.getExtData(ProtobufManager.EXT_ID);
            result = null;
            consumerMicroserviceMeta.getMicroserviceName();
            result = "test";
            consumerMicroserviceMeta.getExtData(ProtobufManager.EXT_ID);
            result = null;
        }
    };
    SpringmvcSwaggerGenerator swaggerGenerator = new SpringmvcSwaggerGenerator(ProtoSchema.class);
    Swagger swagger = swaggerGenerator.generate();
    SwaggerEnvironment swaggerEnvironment = new SwaggerEnvironment();
    providerSchemaMeta = new SchemaMeta(providerMicroserviceMeta, "ProtoSchema", swagger);
    SwaggerProducer swaggerProducer = swaggerEnvironment.createProducer(new ProtoSchema(), swagger);
    for (SwaggerProducerOperation producerOperation : swaggerProducer.getAllOperations()) {
        OperationMeta operationMeta = providerSchemaMeta.ensureFindOperation(producerOperation.getOperationId());
        operationMeta.setSwaggerProducerOperation(producerOperation);
    }
    consumerSchemaMeta = new SchemaMeta(consumerMicroserviceMeta, "ProtoSchema", swagger);
}
Also used : Expectations(mockit.Expectations) ProtoSchema(org.apache.servicecomb.codec.protobuf.internal.converter.model.ProtoSchema) SwaggerProducer(org.apache.servicecomb.swagger.engine.SwaggerProducer) Swagger(io.swagger.models.Swagger) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) SwaggerProducerOperation(org.apache.servicecomb.swagger.engine.SwaggerProducerOperation) SwaggerEnvironment(org.apache.servicecomb.swagger.engine.SwaggerEnvironment) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) SpringmvcSwaggerGenerator(org.apache.servicecomb.swagger.generator.springmvc.SpringmvcSwaggerGenerator) Before(org.junit.Before)

Aggregations

SwaggerProducer (org.apache.servicecomb.swagger.engine.SwaggerProducer)14 SwaggerEnvironment (org.apache.servicecomb.swagger.engine.SwaggerEnvironment)12 HashMap (java.util.HashMap)10 SwaggerInvocation (org.apache.servicecomb.swagger.invocation.SwaggerInvocation)10 Test (org.junit.Test)10 SwaggerProducerOperation (org.apache.servicecomb.swagger.engine.SwaggerProducerOperation)5 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)4 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)4 Swagger (io.swagger.models.Swagger)3 AddWrapperV1 (org.apache.servicecomb.swagger.invocation.schemas.models.AddWrapperV1)3 Executor (java.util.concurrent.Executor)2 Expectations (mockit.Expectations)2 MicroserviceMeta (org.apache.servicecomb.core.definition.MicroserviceMeta)2 SpringmvcAddWrapperV1 (org.apache.servicecomb.swagger.invocation.schemas.SpringmvcAddWrapperV1)2 ProtoSchema (org.apache.servicecomb.codec.protobuf.internal.converter.model.ProtoSchema)1 SpringmvcSwaggerGenerator (org.apache.servicecomb.swagger.generator.springmvc.SpringmvcSwaggerGenerator)1 JaxrsAddBeanParamV1 (org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddBeanParamV1)1 JaxrsAddBodyV1 (org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddBodyV1)1 JaxrsAddV1 (org.apache.servicecomb.swagger.invocation.schemas.JaxrsAddV1)1 PojoAddBodyV1 (org.apache.servicecomb.swagger.invocation.schemas.PojoAddBodyV1)1