/* * Copyright 2004-2006 Geert Bevin * Licensed under the Apache License, Version 2.0 (the "License"); * * $Id: TestElements.java 2923 2006-02-06 11:36:43Z gbevin $ */ package org.foo.petstore.tests; import org.mortbay.util.TestCase; import com.uwyn.rife.engine.Site; import com.uwyn.rife.test.MockConversation; import com.uwyn.rife.test.MockForm; import com.uwyn.rife.test.MockLink; import com.uwyn.rife.test.MockResponse; import com.uwyn.rife.test.ParsedHtml; public class TestElements extends TestCase { public TestElements(String name) { super(name); } public void testHome() throws Throwable { MockConversation conversation = new MockConversation(Site.getRepInstance()); MockResponse response = conversation.doRequest("/"); ParsedHtml parsed = response.getParsedHtml(); // check that the home page is present at the root URL assertEquals("RIFE/Jumpstart - Home", parsed.getTitle()); } public void testAdmin() throws Throwable { MockConversation conversation = new MockConversation(Site.getRepInstance()); MockResponse response; ParsedHtml parsed; // go to the homepage response = conversation.doRequest("/"); parsed = response.getParsedHtml(); // get the link to the admin PETSTORE_SITE and click on it MockLink link_admin = parsed.getLinkWithText("here"); response = link_admin.click(); parsed = response.getParsedHtml(); // check that the authentication page is shown assertEquals("RIFE/Jumpstart - Admin - Authentication", parsed.getTitle()); // fill in the form on the authentication page and submit it with wrong credentials MockForm form_credentials = parsed.getFormWithName("credentials"); response = form_credentials .parameter("login", "wronglogin") .parameter("password", "wrongpassword") .submit(); parsed = response.getParsedHtml(); // check that the authentication page is still shown assertEquals("RIFE/Jumpstart - Admin - Authentication", parsed.getTitle()); assertEquals("The login and the password that you provided are not valid.", response.xpathString("//*[@id='error_area']/text()")); // fill in the form on the authentication page and submit it with correct credentials form_credentials = parsed.getFormWithName("credentials"); response = form_credentials .parameter("login", "admin") .parameter("password", "password") .submit(); parsed = response.getParsedHtml(); // check that the administration homepage is shown assertEquals("RIFE/Jumpstart - Admin - Home", parsed.getTitle()); // check that the authentication cookie has been added assertEquals(1, response.getNewCookieNames().size()); assertEquals("authid", response.getNewCookieNames().get(0)); } }