1 package org.appfuse.service; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 5 6 import org.apache.commons.logging.Log; 7 import org.apache.commons.logging.LogFactory; 8 import org.appfuse.dao.UserDao; 9 import org.appfuse.model.User; 10 import org.codehaus.xfire.client.XFireProxyFactory; 11 import org.codehaus.xfire.service.Service; 12 import org.codehaus.xfire.spring.AbstractXFireSpringTest; 13 import org.jdom.Document; 14 import org.jmock.Mock; 15 import org.jmock.core.constraint.IsEqual; 16 import org.jmock.core.matcher.InvokeOnceMatcher; 17 import org.jmock.core.stub.ReturnStub; 18 import org.springframework.context.ApplicationContext; 19 import org.springframework.context.support.ClassPathXmlApplicationContext; 20 21 public class UserWebServiceTest extends AbstractXFireSpringTest { 22 23 protected final Log log = LogFactory.getLog(getClass()); 24 25 public void setUp() throws Exception { 26 super.setUp(); 27 } 28 29 public void testGetWsdl() throws Exception { 30 Document doc = getWSDLDocument("UserWebService"); 31 printNode(doc); 32 33 assertValid("//xsd:complexType[@name=\"User\"]", doc); 34 assertValid("//xsd:complexType[@name=\"Role\"]", doc); 35 } 36 37 public void testGetUser() throws Exception { 38 User testData = new User("tomcat"); 40 testData.setEnabled(true); 41 Mock userDao = new Mock(UserDao.class); 42 43 InvokeOnceMatcher once = new InvokeOnceMatcher(); 45 IsEqual eq = new IsEqual(new Long (1)); 46 ReturnStub returnValue = new ReturnStub(testData); 47 userDao.expects(once).method("getUser").with(eq).will(returnValue); 48 49 UserManager service = (UserManager) getContext().getBean("userManager"); 50 service.setUserDao((UserDao)userDao.proxy()); 51 52 Document response = 54 invokeService("UserWebService", "/org/appfuse/service/getUser.xml"); 55 56 userDao.verify(); 59 addNamespace("service","http://service.appfuse.org"); 60 addNamespace("model","http://model.appfuse.org"); 61 assertValid("//service:getUserResponse/service:out[model:username=\"tomcat\"]",response); 62 assertValid("//service:getUserResponse/service:out[model:enabled=\"true\"]",response); 63 } 64 65 public void testGetUsers() throws Exception { 66 Service service = getServiceRegistry().getService("UserWebService"); 67 UserWebService client = (UserWebService) 68 new XFireProxyFactory(getXFire()).create(service, "xfire.local://UserWebService"); 69 70 final User testUser = new User("tomcat"); 71 User user = new User(); 72 73 List testData = new ArrayList (){{ add(testUser); }}; 74 testUser.setEnabled(true); 75 Mock userDao = new Mock(UserDao.class); 76 77 InvokeOnceMatcher once = new InvokeOnceMatcher(); 79 ReturnStub returnValue = new ReturnStub(testData); 80 IsEqual eq = new IsEqual(user); 81 userDao.expects(once).method("getUsers").with(eq).will(returnValue); 82 83 UserManager userService = (UserManager) getContext().getBean("userManager"); 84 userService.setUserDao((UserDao)userDao.proxy()); 85 86 List userList = (List )client.getUsers(user); 87 assertNotNull(userList); 88 userDao.verify(); 89 } 90 91 protected ApplicationContext createContext() { 92 return new ClassPathXmlApplicationContext(new String []{ 93 "org/appfuse/service/applicationContext-test.xml", 94 "org/appfuse/service/applicationContext-webservice.xml"}); 95 } 96 97 98 } 99 | Popular Tags |