use of io.servicecomb.common.rest.definition.RestOperationMeta in project java-chassis by ServiceComb.
the class TestLocator method createRestOperatonMeta.
protected RestOperationMeta createRestOperatonMeta(String httpMethod, String path) {
OperationMeta om = new OperationMeta();
om.setHttpMethod(httpMethod);
RestOperationMeta rom = new RestOperationMeta();
rom.setOperationMeta(om);
rom.setAbsolutePath(path);
return rom;
}
use of io.servicecomb.common.rest.definition.RestOperationMeta in project java-chassis by ServiceComb.
the class TestLocator method testLocateStatic.
@Test
public void testLocateStatic() {
MicroserviceMeta msm = new MicroserviceMeta("app:ms");
ServicePathManager spm = new ServicePathManager(msm);
RestOperationMeta rom = createRestOperatonMeta("GET", "abc/");
spm.addResource(rom);
rom = createRestOperatonMeta("POST", "abc/");
spm.addResource(rom);
try {
spm.addResource(rom);
} catch (Throwable e) {
Assert.assertEquals("operation with url abc/, method POST is duplicated", e.getMessage());
}
Assert.assertEquals(1, spm.getStaticPathOperationMap().size());
Assert.assertEquals(2, spm.getStaticPathOperationMap().get("abc/").values().size());
try {
spm.locateOperation("abcd", "GET");
} catch (InvocationException e) {
Assert.assertEquals("Not Found", ((CommonExceptionData) e.getErrorData()).getMessage());
}
try {
spm.locateOperation("abc/", "PUT");
} catch (InvocationException e) {
Assert.assertEquals("Method Not Allowed", ((CommonExceptionData) e.getErrorData()).getMessage());
}
OperationLocator locator = spm.locateOperation("abc/", "GET");
Assert.assertEquals(Collections.emptyMap(), locator.getPathVarMap());
locator.locate(spm, "abc/", "POST");
Assert.assertEquals(Collections.emptyMap(), locator.getPathVarMap());
}
use of io.servicecomb.common.rest.definition.RestOperationMeta in project java-chassis by ServiceComb.
the class MockUtil method mockAbstactRestServer.
public void mockAbstactRestServer() {
new MockUp<AbstractRestServer<HttpServletResponse>>() {
@Mock
protected RestOperationMeta findRestOperation(RestServerRequestInternal restRequest) {
RestOperationMeta restOperationMeta = Mockito.mock(RestOperationMeta.class);
OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
Executor executor = Mockito.mock(Executor.class);
operationMeta.setExecutor(executor);
return restOperationMeta;
}
};
}
use of io.servicecomb.common.rest.definition.RestOperationMeta in project java-chassis by ServiceComb.
the class AbstractRestServer method handleRequest.
protected void handleRequest(RestServerRequestInternal restRequest, HTTP_RESPONSE httpResponse) {
try {
RestOperationMeta restOperation = findRestOperation(restRequest);
OperationMeta operationMeta = restOperation.getOperationMeta();
operationMeta.getExecutor().execute(() -> {
try {
runOnExecutor(restRequest, restOperation, httpResponse);
} catch (Exception e) {
LOGGER.error("rest server onRequest error", e);
sendFailResponse(restRequest, httpResponse, e);
}
});
} catch (Exception e) {
LOGGER.error("rest server onRequest error", e);
sendFailResponse(restRequest, httpResponse, e);
}
}
use of io.servicecomb.common.rest.definition.RestOperationMeta in project java-chassis by ServiceComb.
the class MockUtil method mockOperationLocator.
public void mockOperationLocator() {
new MockUp<OperationLocator>() {
@Mock
public RestOperationMeta getOperation() {
RestOperationMeta rom = new RestOperationMeta();
rom.init(Mockito.mock(OperationMeta.class));
return rom;
}
};
}
Aggregations