DefaultRopContext implements RopContext { public ServiceMethodHandler getServiceMethodHandler(String methodName, String version) { return serviceHandlerMap.get(ServiceMethodHandler.methodWithVersion(methodName, version)); } DefaultRopContext(ApplicationContext context); void addServiceMethod(String methodName, String version, ServiceMethodHandler serviceMethodHandler); ServiceMethodHandler getServiceMethodHandler(String methodName, String version); boolean isValidMethod(String methodName); boolean isValidVersion(String methodName, String version); boolean isVersionObsoleted(String methodName, String version); Map<String, ServiceMethodHandler> getAllServiceMethodHandlers(); boolean isSignEnable(); SessionManager getSessionManager(); void setSessionManager(SessionManager sessionManager); void setSignEnable(boolean signEnable); static List<String> getIgnoreSignFieldNames(Class<? extends RopRequest> requestType);  }
@Test public void testWithoutGroupService() { ApplicationContext context = mock(ApplicationContext.class); when(context.getBeanNamesForType(Object.class)).thenReturn(new String[]{"service1"}); Class withoutGroupServiceClass = WithoutGroupService.class; when(context.getType("service1")).thenReturn(withoutGroupServiceClass); RopContext registryMethod = new DefaultRopContext(context); ServiceMethodHandler handler = registryMethod.getServiceMethodHandler("service.method1", "1.0"); ServiceMethodDefinition definition = handler.getServiceMethodDefinition(); assertNotNull(definition); assertEquals(definition.getMethod(), "service.method1"); assertEquals(definition.getMethodTitle(), "测试方法1"); assertEquals(definition.getMethodGroup(), "GROUP1"); assertEquals(definition.getMethodGroupTitle(), "分组1"); assertEquals(definition.getTags(), new String[]{"TAG1", "TAG2"}); assertEquals(definition.isIgnoreSign(), true); assertEquals(definition.isNeedInSession(), false); assertEquals(definition.getTimeout(), 100); assertEquals(definition.getVersion(), "1.0"); }
@Test public void testWithGroupService() { ApplicationContext context = mock(ApplicationContext.class); when(context.getBeanNamesForType(Object.class)).thenReturn(new String[]{"service1"}); Class withGroupServiceClass = WithGroupService.class; when(context.getType("service1")).thenReturn(withGroupServiceClass); RopContext ropContext = new DefaultRopContext(context); ServiceMethodHandler handler = ropContext.getServiceMethodHandler("service.method1", "1.0"); ServiceMethodDefinition definition = handler.getServiceMethodDefinition(); assertNotNull(definition); assertEquals(definition.getMethod(), "service.method1"); assertEquals(definition.getMethodTitle(), "测试方法1"); assertEquals(definition.getMethodGroup(), "GROUP1"); assertEquals(definition.getMethodGroupTitle(), "分组1"); assertEquals(definition.getTags(), new String[]{"TAG1", "TAG2"}); assertEquals(definition.isIgnoreSign(), true); assertEquals(definition.isNeedInSession(), false); assertEquals(definition.getTimeout(), 100); assertEquals(definition.getVersion(), "1.0"); ServiceMethodHandler handler2 = ropContext.getServiceMethodHandler("service.method2", "2.0"); ServiceMethodDefinition definition2 = handler2.getServiceMethodDefinition(); assertNotNull(definition2); assertEquals(definition2.getMethod(), "service.method2"); assertEquals(definition2.getMethodTitle(), "测试方法2"); assertEquals(definition2.getMethodGroup(), "GROUP2"); assertEquals(definition2.getMethodGroupTitle(), "分组2"); assertEquals(definition2.getTags(), new String[]{"TAG11", "TAG21"}); assertEquals(definition2.isIgnoreSign(), false); assertEquals(definition2.isNeedInSession(), true); assertEquals(definition2.getTimeout(), 200); assertEquals(definition2.getVersion(), "2.0"); }