Skip to content

Commit

Permalink
added demonstration of Faces Messages API
Browse files Browse the repository at this point in the history
  • Loading branch information
tremes authored and bleathem committed Jul 29, 2011
1 parent 887c51f commit 5c47508
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Expand Up @@ -22,13 +22,16 @@

import javax.ejb.Stateful;
import javax.enterprise.context.ConversationScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.jboss.seam.faces.context.conversation.Begin;
import org.jboss.seam.faces.context.conversation.End;
import org.jboss.seam.international.status.Messages;
import org.jboss.seam.international.status.builder.BundleKey;

/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
Expand All @@ -41,12 +44,16 @@ public class LinkBean implements Serializable {

@PersistenceContext
private EntityManager em;

@Inject
private Messages messages;

private TinyLink link = new TinyLink();

@Begin
@End
public String createLink() throws SQLException {
messages.info("Created link {0}",link.getName());
System.out.println("Created link: [ " + link.getName() + " => " + link.getTarget() + " ]");
em.persist(link);
return "pretty:create";
Expand Down Expand Up @@ -75,6 +82,7 @@ public String format(final String link) {
}

public String deleteAll() {
messages.info(new BundleKey("shortly", "linksDeleted"));
em.createQuery("delete from TinyLink").executeUpdate();
return "pretty:";
}
Expand Down
@@ -0,0 +1 @@
linksDeleted=All links deleted
Expand Up @@ -43,7 +43,7 @@ public class ShortlyTest extends AbstractTestCase {
protected final XpathLocator DELETEALL_BUTTON = xp("//input[contains(@value,'deleteAll')]");

protected final XpathLocator ROOT_LINK = xp("//a[text()=\"root\"]");
protected final AttributeLocator ROOT_LINK_HREF = ROOT_LINK.getAttribute(HREF);
protected final AttributeLocator<XpathLocator> ROOT_LINK_HREF = ROOT_LINK.getAttribute(HREF);

protected final XpathLocator BAR_LINK = xp("//a[text()=\"bar\"]");

Expand All @@ -65,14 +65,15 @@ public void testCreate() throws MalformedURLException {
waitHttp(selenium).click(CREATE_BUTTON);

assertEquals(selenium.getAttribute(ROOT_LINK_HREF), "/faces-shortly/root");

assertEquals(selenium.isTextPresent("Created link root"), true);
waitHttp(selenium).click(ROOT_LINK);
assertEquals(selenium.getLocation().toString(), contextRoot.toString());
}

@Test(dependsOnMethods = {"testCreate"})
public void testDeleteAll() {
waitHttp(selenium).click(DELETEALL_BUTTON);
assertEquals(selenium.isTextPresent("All links deleted"), true);
assertEquals(selenium.isElementPresent(DELETEALL_BUTTON), false);
assertEquals(selenium.isElementPresent(ROOT_LINK), false);
}
Expand Down

0 comments on commit 5c47508

Please sign in to comment.