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);
}
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);
}
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();
}
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());
}
Aggregations