简体   繁体   中英

Testing WCF with SoapUI

I need your help on one practical issue. I have created a WCF service with basic binding with two operation contact.

1- void StartRegistration - Anonymous member can fill the basic registration form and press submit. All the information will be stored into the database and one link with some random token will be send to user's email address. 2 - void CompleteRegistration - This method validates the token sent into the email address and if token is valid, user account will be activated.

Now I have issue here. Using SoapUI I can call StartRegistration method. Email is sent to destination but I want to pass the token to CompleteRegistration method.

Since it is a WCF service so can not do dependency injection to pass the SoapUI tests :).

Please help.

If I understand your question correctly, you have two WCF methods, one for creating a token and another for confirming it. What I would do in this case is have the first method, StartRegistration, return the token. Then you could use that token to pass into the CompleteRegistration method quite easily in Soap UI.

Another, quite messy solution, would be to have a groovy script test step in Soap UI that actually connected to the mail account, read the link and parsed the contents.

Edited:

Here is part of the script you'll need. Place it in a groovy step, that will then return the token from your mail.

Note: This code assumes that mail is plain text, not multipart. It also assumes that the mail box only has a single mail. The API for JavaMail is pretty extensive, so if you want to do any magic with it, Google is your friend :) At least, this is somewhere to start.

import javax.mail.*;
import javax.mail.internet.*;

// setup connection
Properties props = new Properties();
def host = "pop3.live.com";
def username = "mymailadress@live.com";
def password = "myPassword";
def provider = "pop3s"; 

// Connect to the POP3 server
Session session = Session.getDefaultInstance props, null
Store store = session.getStore provider
Folder inbox = null
String content
try
{
store.connect host, username, password

// Open the folder
inbox = store.getFolder 'INBOX'
if (!inbox) {
    println 'No INBOX'
    System.exit 1
}

inbox.open(Folder.READ_ONLY)

Message[] messages = inbox.getMessages()
content = messages[0].getContent()

//Do some parsing of the content here, to find your token. 
//Place the result in content   
}
finally
{
    inbox.close false
    store.close()
}

return content; //return the parsed token

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM