use of org.apache.servicecomb.core.definition.SchemaMeta in project incubator-servicecomb-java-chassis by apache.
the class SchemaLoader method registerSchema.
/*
* resource的路径格式,至少是以这个形式结尾:schemaId.yaml
*/
public SchemaMeta registerSchema(String microserviceName, Resource resource) {
try {
String schemaId = FilenameUtils.getBaseName(resource.getFilename());
String swaggerContent = IOUtils.toString(resource.getURL());
SchemaMeta schemaMeta = registerSchema(microserviceName, schemaId, swaggerContent);
return schemaMeta;
} catch (Throwable e) {
throw new Error(e);
}
}
use of org.apache.servicecomb.core.definition.SchemaMeta in project incubator-servicecomb-java-chassis by apache.
the class UnitTestMeta method getOrCreateSchemaMeta.
public SchemaMeta getOrCreateSchemaMeta(String appId, String microserviceName, String schemaId, Class<?> impl) {
String longName = appId + ":" + microserviceName;
MicroserviceMeta microserviceMeta = microserviceMetaManager.getOrCreateMicroserviceMeta(longName);
SchemaMeta schemaMeta = microserviceMeta.findSchemaMeta(schemaId);
if (schemaMeta != null) {
return schemaMeta;
}
Swagger swagger = UnitTestSwaggerUtils.generateSwagger(impl).getSwagger();
return schemaLoader.registerSchema(microserviceMeta, schemaId, swagger);
}
use of org.apache.servicecomb.core.definition.SchemaMeta in project incubator-servicecomb-java-chassis by apache.
the class TestConsumer method testInvocation.
@Test
public void testInvocation() {
OperationMeta oOperationMeta = Mockito.mock(OperationMeta.class);
SchemaMeta oSchemaMeta = Mockito.mock(SchemaMeta.class);
AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
List<Handler> oHandlerList = new ArrayList<>();
Mockito.when(oSchemaMeta.getProviderHandlerChain()).thenReturn(oHandlerList);
Mockito.when(oSchemaMeta.getMicroserviceName()).thenReturn("TMK");
Mockito.when(oOperationMeta.getSchemaMeta()).thenReturn(oSchemaMeta);
Endpoint oEndpoint = Mockito.mock(Endpoint.class);
Transport oTransport = Mockito.mock(Transport.class);
Mockito.when(oEndpoint.getTransport()).thenReturn(oTransport);
Mockito.when(oOperationMeta.getOperationId()).thenReturn("TMK");
Invocation oInvocation = new Invocation(oEndpoint, oOperationMeta, null);
Assert.assertNotNull(oInvocation.getTransport());
Assert.assertNotNull(oInvocation.getInvocationType());
oInvocation.setResponseExecutor(Mockito.mock(Executor.class));
Assert.assertNotNull(oInvocation.getResponseExecutor());
Assert.assertNotNull(oInvocation.getSchemaMeta());
Assert.assertNotNull(oInvocation.getOperationMeta());
Assert.assertNull(oInvocation.getArgs());
Assert.assertNotNull(oInvocation.getEndpoint());
oInvocation.setEndpoint(null);
Map<String, String> map = oInvocation.getContext();
Assert.assertNotNull(map);
String str = oInvocation.getSchemaId();
Assert.assertEquals(null, str);
String str1 = oInvocation.getMicroserviceName();
Assert.assertEquals("TMK", str1);
Map<String, Object> mapp = oInvocation.getHandlerContext();
Assert.assertNotNull(mapp);
Assert.assertEquals(true, oInvocation.getHandlerIndex() >= 0);
oInvocation.setHandlerIndex(8);
Assert.assertEquals("TMK", oInvocation.getOperationName());
Assert.assertEquals("TMK", oInvocation.getMicroserviceName());
boolean validAssert;
try {
validAssert = true;
oInvocation.next(asyncResp);
} catch (Exception e) {
validAssert = false;
}
Assert.assertFalse(validAssert);
}
use of org.apache.servicecomb.core.definition.SchemaMeta in project incubator-servicecomb-java-chassis by apache.
the class TestDynamicSchemaLoader method testRegisterShemasAcrossApp.
@SuppressWarnings("deprecation")
@Test
public void testRegisterShemasAcrossApp() {
DynamicSchemaLoader.INSTANCE.registerSchemas("CSE:as", "classpath*:test/test/schema.yaml");
SchemaMeta schemaMeta = microserviceMetaManager.ensureFindSchemaMeta("CSE:as", "schema");
Assert.assertEquals("cse.gen.CSE.as.schema", schemaMeta.getPackageName());
}
use of org.apache.servicecomb.core.definition.SchemaMeta 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);
}
Aggregations