use of org.apache.servicecomb.core.unittest.UnitTestMeta in project incubator-servicecomb-java-chassis by apache.
the class TestConsumerSchemaFactory method init.
@BeforeClass
public static void init() {
ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
serviceRegistry.init();
RegistryUtils.setServiceRegistry(serviceRegistry);
SchemaListenerManager schemaListenerManager = new SchemaListenerManager();
schemaListenerManager.setSchemaListenerList(Arrays.asList(schemaListener));
MicroserviceMetaManager microserviceMetaManager = new MicroserviceMetaManager();
SchemaLoader schemaLoader = new SchemaLoader() {
@Override
public void putSelfBasePathIfAbsent(String microserviceName, String basePath) {
}
};
CompositeSwaggerGeneratorContext compositeSwaggerGeneratorContext = new CompositeSwaggerGeneratorContext();
ReflectUtils.setField(consumerSchemaFactory, "schemaListenerManager", schemaListenerManager);
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());
Microservice microservice = new Microservice();
microservice.setAppId("app");
microservice.setServiceId("0");
microservice.setServiceName("ms");
microservice.setVersion("1.0.0");
microservice.addSchema("schema", content);
serviceRegistry.getServiceRegistryClient().registerMicroservice(microservice);
MicroserviceInstance instance = new MicroserviceInstance();
instance.setServiceId("0");
instance.setInstanceId("0");
serviceRegistry.getServiceRegistryClient().registerMicroserviceInstance(instance);
}
use of org.apache.servicecomb.core.unittest.UnitTestMeta in project incubator-servicecomb-java-chassis by apache.
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 org.apache.servicecomb.core.unittest.UnitTestMeta in project incubator-servicecomb-java-chassis by apache.
the class TestCseClientHttpRequest method testNormal.
@Test
public void testNormal() throws IOException {
ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
serviceRegistry.init();
RegistryUtils.setServiceRegistry(serviceRegistry);
UnitTestMeta meta = new UnitTestMeta();
CseContext.getInstance().getSchemaListenerManager().setSchemaListenerList(Arrays.asList(new RestEngineSchemaListener()));
SchemaMeta schemaMeta = meta.getOrCreateSchemaMeta(SpringmvcImpl.class);
CseContext.getInstance().getSchemaListenerManager().notifySchemaListener(schemaMeta);
Holder<Invocation> holder = new Holder<>();
CseClientHttpRequest client = new CseClientHttpRequest(URI.create("cse://app:test/" + SpringmvcImpl.class.getSimpleName() + "/bytes"), HttpMethod.POST) {
/**
* {@inheritDoc}
*/
@Override
protected Response doInvoke(Invocation invocation) {
holder.value = invocation;
return Response.ok("result");
}
};
byte[] body = "abc".getBytes();
client.setRequestBody(body);
client.execute();
Assert.assertArrayEquals(body, holder.value.getSwaggerArgument(0));
}
use of org.apache.servicecomb.core.unittest.UnitTestMeta in project incubator-servicecomb-java-chassis by apache.
the class TestHighwayServerInvoke method setup.
@Before
public void setup() {
unitTestMeta = new UnitTestMeta();
socketAddress = new MockUp<SocketAddress>() {
@Mock
public String host() {
return "127.0.0.1";
}
@Mock
public int port() {
return 8080;
}
}.getMockInstance();
netSocket = new MockUp<NetSocket>() {
@Mock
public SocketAddress remoteAddress() {
return socketAddress;
}
}.getMockInstance();
connection = new MockUp<TcpConnection>() {
@Mock
public void write(ByteBuf data) {
netSocketBuffer = data;
}
@Mock
public NetSocket getNetSocket() {
return netSocket;
}
}.getMockInstance();
}
use of org.apache.servicecomb.core.unittest.UnitTestMeta in project incubator-servicecomb-java-chassis by apache.
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(Impl.class.getName() + ".test", operationMeta.getSchemaQualifiedName());
Assert.assertEquals("app:test." + Impl.class.getName() + ".test", operationMeta.getMicroserviceQualifiedName());
Assert.assertEquals("app:test", operationMeta.getMicroserviceName());
Assert.assertEquals("test", operationMeta.getOperationId());
Assert.assertEquals("x", operationMeta.getParamName(0));
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