use of io.servicecomb.core.definition.MicroserviceMeta in project java-chassis by ServiceComb.
the class MockUtil method mockRequestMeta.
public void mockRequestMeta() {
new MockUp<RequestMeta>() {
@Mock
public OperationMeta getOperationMeta() throws Exception {
OperationMeta om = new OperationMeta();
om.init(new SchemaMeta(null, new MicroserviceMeta("test"), null), this.getClass().getMethods()[0], "path", "get", null);
return om;
}
};
}
use of io.servicecomb.core.definition.MicroserviceMeta in project java-chassis by ServiceComb.
the class TestRestEngineSchemaListener method test.
@Test
public void test() {
BeanUtils.setContext(Mockito.mock(ApplicationContext.class));
MicroserviceMeta mm = new MicroserviceMeta("app:ms");
List<SchemaMeta> smList = new ArrayList<>();
SwaggerGenerator generator = new SwaggerGenerator(context, Impl.class);
Swagger swagger = generator.generate();
SchemaMeta sm1 = new SchemaMeta(swagger, mm, "sid1");
smList.add(sm1);
RestEngineSchemaListener listener = new RestEngineSchemaListener();
SchemaMeta[] smArr = smList.toArray(new SchemaMeta[smList.size()]);
listener.onSchemaLoaded(smArr);
// 重复调用,不应该出异常
listener.onSchemaLoaded(smArr);
ServicePathManager spm = ServicePathManager.getServicePathManager(mm);
Assert.assertEquals(mm, spm.getMicroserviceMeta());
Assert.assertNotNull(spm.getStaticPathOperationMap().get("Impl/add/"));
}
use of io.servicecomb.core.definition.MicroserviceMeta in project java-chassis by ServiceComb.
the class RestEngineSchemaListener method onSchemaLoaded.
@Override
public void onSchemaLoaded(SchemaMeta... schemaMetas) {
// 此时相应的ServicePathManager可能正在被使用,为避免太高的复杂度,使用copy on write逻辑
Map<String, ServicePathManager> mgrMap = new HashMap<>();
for (SchemaMeta schemaMeta : schemaMetas) {
MicroserviceMeta microserviceMeta = schemaMeta.getMicroserviceMeta();
ServicePathManager mgr = findPathManager(mgrMap, microserviceMeta);
if (mgr.isSchemaExists(schemaMeta.getSchemaId())) {
LOGGER.info("on schema loaded, exists schema. {}:{}", schemaMeta.getMicroserviceName(), schemaMeta.getSchemaId());
continue;
}
LOGGER.info("on schema loaded, new schema. {}:{}", schemaMeta.getMicroserviceName(), schemaMeta.getSchemaId());
mgr.addSchema(schemaMeta.getSchemaId());
for (OperationMeta operationMeta : schemaMeta.getOperations()) {
RestOperationMeta restOperationMeta = new RestOperationMeta();
restOperationMeta.init(operationMeta);
operationMeta.putExtData(RestConst.SWAGGER_REST_OPERATION, restOperationMeta);
mgr.addResource(restOperationMeta);
}
}
for (ServicePathManager mgr : mgrMap.values()) {
// 对具有动态path operation进行排序
mgr.sortPath();
mgr.printService();
mgr.saveToMicroserviceMeta();
}
}
use of io.servicecomb.core.definition.MicroserviceMeta in project java-chassis by ServiceComb.
the class TestLocator method testLocateDynamic.
@Test
public void testLocateDynamic() {
MicroserviceMeta msm = new MicroserviceMeta("app:ms");
ServicePathManager spm = new ServicePathManager(msm);
RestOperationMeta rom = createRestOperatonMeta("GET", "abc/{id}");
spm.addResource(rom);
try {
spm.locateOperation("abc/10", "PUT");
} catch (InvocationException e) {
Assert.assertEquals("Method Not Allowed", ((CommonExceptionData) e.getErrorData()).getMessage());
}
OperationLocator locator = spm.locateOperation("abc/10", "GET");
Assert.assertEquals("10", locator.getPathVarMap().get("id"));
}
use of io.servicecomb.core.definition.MicroserviceMeta in project java-chassis by ServiceComb.
the class TestLocator method testServicePathManager.
@Test
public void testServicePathManager() {
MicroserviceMeta msm = new MicroserviceMeta("app:ms");
ServicePathManager spm = new ServicePathManager(msm);
RestOperationMeta rom = createRestOperatonMeta("GET", "abc/{id}");
spm.addResource(rom);
rom = createRestOperatonMeta("GET", "abc/{id}/xxx");
spm.addResource(rom);
Assert.assertEquals("abc/{id}", spm.getDynamicPathOperationList().get(0).getAbsolutePath());
spm.sortPath();
Assert.assertEquals("abc/{id}/xxx", spm.getDynamicPathOperationList().get(0).getAbsolutePath());
spm.printService();
spm.doPrintService();
}
Aggregations