1   package org.paneris.jammyjoes.functional;
2   
3   import net.sourceforge.jwebunit.WebTestCase;
4   
5   import org.melati.LogicalDatabase;
6   import org.melati.poem.AccessToken;
7   import org.melati.poem.PoemTask;
8   import org.paneris.jammyjoes.model.AffiliateTransaction;
9   import org.paneris.jammyjoes.model.JammyjoesDatabase;
10  
11  public class TestCaseFunctionalReferrer extends WebTestCase {
12  
13     public TestCaseFunctionalReferrer(String name) {
14        super(name);
15     }
16  
17     public void setUp() {
18        getTestContext().setBaseUrl("http://localhost");
19     }
20  
21     public void testReferrer() throws Exception {
22       getTestContext().getWebClient().setHeaderField("Referer","http://testReferringSite?search=toys");
23       beginAt("/index.html?affiliate=0");
24       
25       final JammyjoesDatabase database = (JammyjoesDatabase) LogicalDatabase.getDatabase("jammyjoes");
26       database.inSession(AccessToken.root, new PoemTask() {
27  
28         public void run() {
29           AffiliateTransaction transaction = (AffiliateTransaction)database.getAffiliateTransactionTable().selection().nextElement();
30           assertEquals("127.0.0.1", transaction.getUserIpAddress());
31           assertEquals("http://testReferringSite?search=toys", transaction.getReferrerURL());
32           assertEquals("http://localhost/index.html", transaction.getLandingPage());
33         }
34       });
35     }
36  
37  }