HttpWebService extends ServletBase { protected Document getRoles() throws ServletException, IOException { IUserRoleListService service = PentahoSystem.get( IUserRoleListService.class ); Element rootElement = new DefaultElement( "roles" ); Document doc = DocumentHelper.createDocument( rootElement ); if ( service != null ) { List roles = service.getAllRoles(); for ( Iterator rolesIterator = roles.iterator(); rolesIterator.hasNext(); ) { String roleName = rolesIterator.next().toString(); if ( ( null != roleName ) && ( roleName.length() > 0 ) ) { rootElement.addElement( "role" ).addCDATA( roleName ); } } } return doc; } HttpWebService(); @Override Log getLogger(); String getPayloadAsString( final HttpServletRequest request ); void doGetFixMe( final HttpServletRequest request, final HttpServletResponse response ); @Override void doGet( final HttpServletRequest request, final HttpServletResponse response );  }
@Test public void testGetRoles() throws Exception { PentahoSystem.registerObject( userRoleListService ); List<String> roles = Arrays.asList( new String[] { "administrator", "power user" } ); when( userRoleListService.getAllRoles() ).thenReturn( roles ); Document doc = httpWebService.getRoles(); assertNotNull( doc ); assertEquals( roles.size(), doc.getRootElement().elements().size() ); }