Search in sources :

Example 1 with UnitTestMeta

use of io.servicecomb.core.unittest.UnitTestMeta in project java-chassis by ServiceComb.

the class TestOperationProtobuf method testOperationProtobuf.

@Test
public void testOperationProtobuf() throws Exception {
    UnitTestMeta meta = new UnitTestMeta();
    SchemaMeta schemaMeta = meta.getOrCreateSchemaMeta(Impl.class);
    OperationMeta operationMeta = schemaMeta.findOperation("test");
    OperationProtobuf operationProtobuf = ProtobufManager.getOrCreateOperation(operationMeta);
    Assert.assertEquals(operationMeta, operationProtobuf.getOperationMeta());
    Assert.assertEquals(ArgsNotWrapSchema.class, operationProtobuf.getRequestSchema().getClass());
    Assert.assertEquals(NormalWrapSchema.class, operationProtobuf.getResponseSchema().getClass());
    WrapSchema responseSchema = operationProtobuf.findResponseSchema(200);
    Assert.assertEquals(operationProtobuf.getResponseSchema(), responseSchema);
    responseSchema = operationProtobuf.findResponseSchema(300);
    Assert.assertNotNull(responseSchema);
    Assert.assertNotEquals(operationProtobuf.getResponseSchema(), responseSchema);
}
Also used : UnitTestMeta(io.servicecomb.core.unittest.UnitTestMeta) SchemaMeta(io.servicecomb.core.definition.SchemaMeta) OperationMeta(io.servicecomb.core.definition.OperationMeta) ArgsNotWrapSchema(io.servicecomb.codec.protobuf.utils.schema.ArgsNotWrapSchema) WrapSchema(io.servicecomb.codec.protobuf.utils.WrapSchema) NormalWrapSchema(io.servicecomb.codec.protobuf.utils.schema.NormalWrapSchema) Test(org.junit.Test)

Example 2 with UnitTestMeta

use of io.servicecomb.core.unittest.UnitTestMeta in project java-chassis by ServiceComb.

the class TestConsumerSchemaFactory method init.

@BeforeClass
public static void init() {
    ReflectUtils.setField(RegistryClientFactory.class, null, "registryClient", registryClient);
    SchemaListenerManager schemaListenerManager = new SchemaListenerManager();
    schemaListenerManager.setSchemaListenerList(Arrays.asList(schemaListener));
    ConsumerResponseMapperFactory responseMapperFactory = new ConsumerResponseMapperFactory();
    responseMapperFactory.setMapperList(Arrays.asList(new ConsumerResponseSame()));
    ConsumerArgumentsMapperFactory consumerArgsMapperFactory = new ConsumerArgumentsMapperFactory();
    MicroserviceMetaManager microserviceMetaManager = new MicroserviceMetaManager();
    SchemaLoader schemaLoader = new SchemaLoader();
    CompositeSwaggerGeneratorContext compositeSwaggerGeneratorContext = new CompositeSwaggerGeneratorContext();
    ReflectUtils.setField(consumerSchemaFactory, "schemaListenerManager", schemaListenerManager);
    ReflectUtils.setField(consumerSchemaFactory, "consumerArgsMapperFactory", consumerArgsMapperFactory);
    ReflectUtils.setField(consumerSchemaFactory, "responseMapperFactory", responseMapperFactory);
    ReflectUtils.setField(consumerSchemaFactory, "microserviceMetaManager", microserviceMetaManager);
    ReflectUtils.setField(consumerSchemaFactory, "schemaLoader", schemaLoader);
    ReflectUtils.setField(consumerSchemaFactory, "compositeSwaggerGeneratorContext", compositeSwaggerGeneratorContext);
    SchemaMeta schemaMeta = new UnitTestMeta().getOrCreateSchemaMeta(TestConsumerSchemaFactoryImpl.class);
    String content = UnitTestSwaggerUtils.pretty(schemaMeta.getSwagger());
    Mockito.when(registryClient.getMicroserviceId("app", "ms", "latest")).thenReturn("0");
    Mockito.when(registryClient.getSchema("0", "schema")).thenReturn(content);
    Microservice microservice = new Microservice();
    microservice.setAppId("app");
    microservice.setServiceId("0");
    microservice.addSchema("schema", content);
    Mockito.when(registryClient.getMicroservice("0")).thenReturn(microservice);
}
Also used : ConsumerResponseSame(io.servicecomb.swagger.invocation.response.consumer.ConsumerResponseSame) MicroserviceMetaManager(io.servicecomb.core.definition.MicroserviceMetaManager) SchemaLoader(io.servicecomb.core.definition.loader.SchemaLoader) Microservice(io.servicecomb.serviceregistry.api.registry.Microservice) UnitTestMeta(io.servicecomb.core.unittest.UnitTestMeta) CompositeSwaggerGeneratorContext(io.servicecomb.swagger.generator.core.CompositeSwaggerGeneratorContext) SchemaMeta(io.servicecomb.core.definition.SchemaMeta) SchemaListenerManager(io.servicecomb.core.definition.loader.SchemaListenerManager) ConsumerResponseMapperFactory(io.servicecomb.swagger.invocation.response.consumer.ConsumerResponseMapperFactory) ConsumerArgumentsMapperFactory(io.servicecomb.swagger.invocation.arguments.consumer.ConsumerArgumentsMapperFactory) BeforeClass(org.junit.BeforeClass)

Example 3 with UnitTestMeta

use of io.servicecomb.core.unittest.UnitTestMeta in project java-chassis by ServiceComb.

the class TestHighwayServerInvoke method setup.

@Before
public void setup() {
    unitTestMeta = new UnitTestMeta();
    netSocket = new MockUp<NetSocket>() {

        @Mock
        public NetSocket write(Buffer data) {
            netSocketBuffer = data;
            return netSocket;
        }
    }.getMockInstance();
}
Also used : Buffer(io.vertx.core.buffer.Buffer) UnitTestMeta(io.servicecomb.core.unittest.UnitTestMeta) MockUp(mockit.MockUp) Before(org.junit.Before)

Example 4 with UnitTestMeta

use of io.servicecomb.core.unittest.UnitTestMeta in project java-chassis by ServiceComb.

the class TestOperationMeta method testOperationMeta.

@Test
public void testOperationMeta() {
    UnitTestMeta meta = new UnitTestMeta();
    SchemaMeta schemaMeta = meta.getOrCreateSchemaMeta(Impl.class);
    OperationMeta operationMeta = schemaMeta.findOperation("test");
    Assert.assertEquals("POST", operationMeta.getHttpMethod());
    Assert.assertEquals("/test", operationMeta.getOperationPath());
    Assert.assertEquals(schemaMeta, operationMeta.getSchemaMeta());
    Assert.assertEquals("io.servicecomb.core.definition.TestOperationMeta$Impl.test", operationMeta.getSchemaQualifiedName());
    Assert.assertEquals("app:test.io.servicecomb.core.definition.TestOperationMeta$Impl.test", operationMeta.getMicroserviceQualifiedName());
    Assert.assertEquals("app:test", operationMeta.getMicroserviceName());
    Assert.assertEquals("test", operationMeta.getOperationId());
    Assert.assertEquals("x", operationMeta.getParamName(0));
    Assert.assertEquals(true, operationMeta.isSync());
    operationMeta.putExtData("ext", 1);
    Assert.assertEquals(1, (int) operationMeta.getExtData("ext"));
    ResponseMeta responseMeta = operationMeta.findResponseMeta(200);
    Assert.assertEquals("Ljava/lang/Integer;", responseMeta.getJavaType().getGenericSignature());
    Assert.assertEquals("Ljava/lang/Integer;", responseMeta.getHeaders().get("h1").getGenericSignature());
    Assert.assertEquals("Ljava/util/List<Ljava/lang/String;>;", responseMeta.getHeaders().get("h2").getGenericSignature());
    Assert.assertEquals(null, responseMeta.getHeaders().get("h3"));
    responseMeta = operationMeta.findResponseMeta(300);
    Assert.assertEquals("Ljava/lang/String;", responseMeta.getJavaType().getGenericSignature());
    Assert.assertEquals("Ljava/lang/Integer;", responseMeta.getHeaders().get("h1").getGenericSignature());
    Assert.assertEquals("Ljava/util/List<Ljava/lang/String;>;", responseMeta.getHeaders().get("h2").getGenericSignature());
    Assert.assertEquals("Ljava/lang/Integer;", responseMeta.getHeaders().get("h3").getGenericSignature());
}
Also used : UnitTestMeta(io.servicecomb.core.unittest.UnitTestMeta) ResponseMeta(io.servicecomb.swagger.invocation.response.ResponseMeta) Test(org.junit.Test)

Aggregations

UnitTestMeta (io.servicecomb.core.unittest.UnitTestMeta)4 SchemaMeta (io.servicecomb.core.definition.SchemaMeta)2 Test (org.junit.Test)2 WrapSchema (io.servicecomb.codec.protobuf.utils.WrapSchema)1 ArgsNotWrapSchema (io.servicecomb.codec.protobuf.utils.schema.ArgsNotWrapSchema)1 NormalWrapSchema (io.servicecomb.codec.protobuf.utils.schema.NormalWrapSchema)1 MicroserviceMetaManager (io.servicecomb.core.definition.MicroserviceMetaManager)1 OperationMeta (io.servicecomb.core.definition.OperationMeta)1 SchemaListenerManager (io.servicecomb.core.definition.loader.SchemaListenerManager)1 SchemaLoader (io.servicecomb.core.definition.loader.SchemaLoader)1 Microservice (io.servicecomb.serviceregistry.api.registry.Microservice)1 CompositeSwaggerGeneratorContext (io.servicecomb.swagger.generator.core.CompositeSwaggerGeneratorContext)1 ConsumerArgumentsMapperFactory (io.servicecomb.swagger.invocation.arguments.consumer.ConsumerArgumentsMapperFactory)1 ResponseMeta (io.servicecomb.swagger.invocation.response.ResponseMeta)1 ConsumerResponseMapperFactory (io.servicecomb.swagger.invocation.response.consumer.ConsumerResponseMapperFactory)1 ConsumerResponseSame (io.servicecomb.swagger.invocation.response.consumer.ConsumerResponseSame)1 Buffer (io.vertx.core.buffer.Buffer)1 MockUp (mockit.MockUp)1 Before (org.junit.Before)1 BeforeClass (org.junit.BeforeClass)1