require "rubygems" gem "soap4r" ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../../config/environment") require 'test_help' #------------------------------------------------------------------------ # Test SOAP client #------------------------------------------------------------------------ File.unlink *%w{Mailservice.rb MailserviceServiceClient.rb MailserviceDriver.rb} rescue nil system "wsdl2ruby.rb --wsdl http://localhost:3001/wsdl --type client" system "rake db:fixtures:load" require "MailserviceDriver" require "test/unit" require "soap/soap" require "soap/mapping" require "soap/wsdlDriver" require "pp" class SOAPConnection < Test::Unit::TestCase def setup @server = MailserviceMailservicePort.new end def test_0_nil # Everyone gets to run the nil test! assert true, "Test to see if the class sets up properly" end def test_1_connection # Make sure the connection is still there assert_equal true, @server.ping, "Test to see if SOAP pings" end end =begin def getConfirmationCode(mailinglist_name, address) server = MailserviceMailservicePort.new server.domainLogin "test.domain", "foobar" server.userLogin "root", "foobar" code = server.getConfirmationCode(mailinglist_name, address) server.userLogout server.domainLogout return code end =end class SOAPDomainLogin < SOAPConnection def setup super @server.domainLogin "test.domain", "foobar" end def teardown @server.domainLogout end def test_0_domain_logged_in assert_equal true, @server.domainLoggedIn, "Domain still logged in" assert_equal "test.domain", @server.domainName, "Still the right domain" end end class SOAPUserLogin < SOAPDomainLogin def setup super @server.userLogin "testuser", "foobar" end def teardown @server.userLogout super end def test_0_user_logged_in assert_equal true, @server.userLoggedIn, "User still logged in" assert_equal "testuser", @server.userName, "Still the right user" end end class SOAPDomainAdmin < SOAPDomainLogin def setup super @server.userLogin "root", "foobar" end def teardown @server.userLogout super end def test_0_user_still_admin assert_equal true, @server.userLoggedIn, "User still loggedin" assert_equal "root", @server.userName, "User is still root" assert_equal true, @server.isAdmin, "User is still administrator" end end class TC_SOAPClient_DomainLogin < SOAPConnection def test_baddomain # bad username, bad password assert_equal(false, @server.domainLogin("junkdomain", "blort")) # good username, bad password assert_equal(false, @server.domainLogin("test.domain", "blort")) end def test_loggedout # now once again assert_equal(false, @server.domainLogout); end def test_good_domain # good username, good password assert_equal(true, @server.domainLogin("test.domain", "foobar")) # now log out assert_equal(true, @server.domainLogout); end def test_permissions assert_raises RuntimeError do @server.userLogin "testuser", "foobar" end end end class TC_SOAPClient_UserLogin < SOAPDomainLogin def test_baduser assert_equal false, @server.userLogin("huaglhuagl", "blort") assert_equal false, @server.userLogin("testuser", "blort") end def test_gooduser assert_equal true, @server.userLogin("testuser", "foobar") assert_equal false, @server.isAdmin end end class TC_SOAPClient_TroublesomeAdminTask < SOAPDomainAdmin def teardown @server.userDelete("newuser", "newuser") super end def test_userlogin assert_nothing_raised do assert_equal true, @server.isAdmin end assert_nothing_raised do assert @server.userSignup("newuser", "password", "password") end # user exists, login succeeds assert @server.userLogin("newuser", "password") assert_equal false, @server.isAdmin # let's get our session back assert @server.userLogin("root", "foobar") assert_equal true, @server.isAdmin assert_equal true, @server.userDelete("newuser", "newuser") end end class TC_SOAPClient_AdminTasks < SOAPDomainAdmin def teardown @server.userDelete("newuser", "newuser") super end def test_passwordmismatch assert_equal true, @server.isAdmin # password doesn't match assert_raises RuntimeError do @server.userSignup("flibbleuser", "password", "drowssap") end end def test_usercreate # user doesn't exist; gets created assert_equal true, @server.isAdmin assert @server.userSignup("newuser", "password", "password") assert_equal true, @server.userDelete("newuser", "newuser") end def test_usercollision assert_nothing_raised do assert_equal true, @server.isAdmin end assert @server.userSignup("newuser", "password", "password") # user already exists; creation fails assert_raises RuntimeError do @server.userSignup("newuser", "password", "password") end assert_equal true, @server.userDelete("newuser", "newuser") end def test_usernolongerexists assert_nothing_raised do assert @server.isAdmin end # create the user assert_nothing_raised do assert @server.userSignup("newuser", "password", "password") end # user exists; deletion succeeds assert_nothing_raised do assert @server.userDelete("newuser", "newuser") end # user doesn't exist; login fails assert_nothing_raised do assert_equal false, @server.userLogin("newuser", "password") end # okay, our session's just been trashed again. Get it back. assert_nothing_raised do assert @server.userLogin("root", "foobar") end # user doesn't exist; deletion fails assert_nothing_raised do assert_equal false, @server.userDelete("testuser", "testuser") end end def test_aaa_userlist # force it to go first, see what happens assert_equal true, @server.isAdmin list=nil assert_nothing_raised do list=@server.userList end assert list assert_equal [ [ "root", "Admin" ], [ "testuser", "Test User" ] ], list.sort end end =begin class TC_SOAPClient_EmailAddresses < SOAPUserLogin def test_emailaddress assert_equal "dagbrown@test.domain", @server.userEmailAddress end def test_emailaddresses assert_equal [ "dagbrown@lart.ca", "dagbrown@rwp.jp", "hide@rwp.jp", "kaboom@lart.ca", "ookblat@foo.test" ], @server.userEmailAddresses.sort assert_equal [ "dagbrown@rwp.jp", "hide@rwp.jp", "kaboom@lart.ca" ], @server.userEmailAddressesConfirmed.sort end def test_addremove assert_nothing_raised do assert @server.userEmailAddressesAdd("dagbrown@lart.ca") end assert_nothing_raised do assert_equal [ "dagbrown@lart.ca", "dagbrown@rwp.jp", "hide@rwp.jp", "kaboom@lart.ca", "ookblat@foo.test" ], @server.userEmailAddresses.sort end assert_nothing_raised do assert_equal [ "dagbrown@rwp.jp", "hide@rwp.jp", "kaboom@lart.ca" ], @server.userEmailAddressesConfirmed.sort end assert_nothing_raised do assert_equal [ "dagbrown@lart.ca", "ookblat@foo.test" ], @server.UserEmailAddressesUnconfirmed.sort end confirmation_code=nil assert_nothing_raised do confirmation_code=getConfirmationCode("dagbrown", "dagbrown@lart.ca") end assert_nothing_raised do assert_equal true, @server.userEmailAddressConfirm("dagbrown@lart.ca", confirmation_code) end assert_nothing_raised do assert_equal [ "ookblat@foo.test" ], @server.UserEmailAddressesUnconfirmed.sort end assert_nothing_raised do assert_equal [ "dagbrown@lart.ca" ], @server.userEmailAddressesRemove("dagbrown@lart.ca").sort end assert_nothing_raised do assert_equal [ nil ], @server.userEmailAddressesRemove("dagbrown@lart.ca").sort end assert_nothing_raised do assert_equal [ "dagbrown@rwp.jp", "hide@rwp.jp", "kaboom@lart.ca" ], @server.userEmailAddresses.sort end end end class TC_SOAPClient_UserMailingLists < SOAPUserLogin def test_mailinglists assert_equal [ 2 ], @server.userMailinglists assert_equal "snorglebloot", @server.mailinglistName(2) end end class TC_SOAPClient_CreateMailinglist < SOAPUserLogin def test_create_mailinglist assert_equal "testmailinglist@test.domain", @server.mailinglistCreate("testmailinglist",true) assert id = @server.mailinglistFindByName("testmailinglist") assert @server.mailinglistDelete(id) end end class SOAPUserMailinglist < SOAPUserLogin def setup super @server.mailinglistCreate("testmailinglist", true) @id = @server.mailinglistFindByName("testmailinglist") end def teardown @server.mailinglistDelete(@id) super end end class TC_SOAPClient_MailingListSubscribe < SOAPUserMailinglist def test_mailinglist_subscribe assert @id assert_nothing_raised do assert_equal [ ], @server.mailinglistSubscribers(@id).sort end assert_nothing_raised do assert @server.mailinglistSubscribe(@id,"test@foo.test") end assert_nothing_raised do assert_equal [ ], @server.mailinglistSubscribers(@id).sort end assert_nothing_raised do assert_equal [ "test@foo.test" ], @server.mailinglistPending(@id) end assert_nothing_raised do confirmation=getConfirmationCode("testmailinglist","test@foo.test") end assert_nothing_raised do assert_equal false, @server.mailinglistConfirm("testmailinglist", "test@foo.test", "@@@@@@@@@@@@@@@@") end assert_nothing_raised do assert_equal true, @server.mailinglistConfirm("testmailinglist", "test@foo.test", confirmation) end assert_nothing_raised do assert_equal [ "test@foo.test" ], @server.mailinglistSubscribers(@id).sort end assert_nothing_raised do assert @server.mailinglistUnsubscribe(@id,"test@foo.test") end assert_nothing_raised do assert_equal [ ], @server.mailinglistSubscribers(@id).sort end end def test_mailinglist_message @server.mailinglistMessages(@id) end end =end