YarProtocolUtil { public static Request convert(YarRequest yarRequest, Class<?> interfaceClass) { DefaultRequest request = new DefaultRequest(); request.setInterfaceName(interfaceClass.getName()); request.setMethodName(yarRequest.getMethodName()); request.setRequestId(yarRequest.getId()); addArguments(request, interfaceClass, yarRequest.getMethodName(), yarRequest.getParameters()); if (yarRequest instanceof AttachmentRequest) { request.setAttachments(((AttachmentRequest) yarRequest).getAttachments()); } return request; }  static String getYarPath(Class<?> interfaceClazz, URL url); static Request convert(YarRequest yarRequest, Class<?> interfaceClass); static YarRequest convert(Request request, String packagerName); static Response convert(YarResponse yarResponse); static YarResponse convert(Response response, String packagerName); static YarResponse buildDefaultErrorResponse(String errMsg, String packagerName);  }
@Test public void testConvertYarRequest() throws NoSuchMethodException, SecurityException { DefaultRequest request = new DefaultRequest(); request.setRequestId(123); request.setMethodName("hello"); request.setArguments(new Object[] {"param1"}); request.setInterfaceName(YarMessageRouterTest.AnnoService.class.getName()); request.setParamtersDesc(ReflectUtil.getMethodParamDesc(YarMessageRouterTest.AnnoService.class.getMethod("hello", String.class))); YarRequest yarRequest = YarProtocolUtil.convert(request, "JSON"); assertNotNull(yarRequest); Request newRequest = YarProtocolUtil.convert(yarRequest, YarMessageRouterTest.AnnoService.class); assertNotNull(newRequest); assertEquals(request.toString(), newRequest.toString()); }
@Test public void testConvertYarResponse() { DefaultResponse response = new DefaultResponse(); response.setRequestId(456); response.setValue("stringValue"); YarResponse yarResponse = YarProtocolUtil.convert(response, "JSON"); assertNotNull(yarResponse); Response newResponse = YarProtocolUtil.convert(yarResponse); assertEquals(response.getRequestId(), newResponse.getRequestId()); assertEquals(response.getValue(), newResponse.getValue()); response.setException(new RuntimeException("test exception")); yarResponse = YarProtocolUtil.convert(response, "JSON"); assertNotNull(yarResponse); newResponse = YarProtocolUtil.convert(yarResponse); assertEquals(response.getRequestId(), newResponse.getRequestId()); assertEquals(new MotanBizException(response.getException().getMessage()).getMessage(), newResponse.getException().getMessage()); }