jdave.wicket
Class ComponentSpecification<C extends org.apache.wicket.Component,M>

java.lang.Object
  extended by jdave.ContainmentSupport
      extended by jdave.mock.MockSupport
          extended by jdave.Specification<C>
              extended by jdave.wicket.ComponentSpecification<C,M>

public abstract class ComponentSpecification<C extends org.apache.wicket.Component,M>
extends jdave.Specification<C>

A base class for Wicket's Component specifications.

Author:
Joni Freeman, Timo Rantalaiho

Field Summary
protected  C specifiedComponent
           
protected  org.apache.wicket.util.tester.BaseWicketTester wicket
           
 
Fields inherited from class jdave.Specification
be, context, does, must, should
 
Constructor Summary
ComponentSpecification()
           
 
Method Summary
protected
<X> org.apache.wicket.model.IModel<X>
cast(org.apache.wicket.model.IModel<?> model)
           
 void create()
           
<T> org.apache.wicket.markup.html.list.ListItem<T>
itemAt(org.apache.wicket.markup.html.list.ListView<T> view, int index)
          Select an item from a ListView.
<T> org.apache.wicket.markup.repeater.Item<T>
itemAt(org.apache.wicket.markup.repeater.RepeatingView view, int index)
          Select an item from a RepeatingView.
 java.util.List<?> modelObjects(java.util.Iterator<?> components)
          Collect model objects from given components.
protected  org.apache.wicket.protocol.http.WebApplication newApplication()
          Create the application for the specification.
protected abstract  C newComponent(java.lang.String id, org.apache.wicket.model.IModel<M> model)
          Create a new instance of a Wicket component to be specified.
protected  org.apache.wicket.util.tester.BaseWicketTester newWicketTester()
          Create a WicketTester for the specification.
protected  void onCreate()
          Called after create().
<S extends org.apache.wicket.Component>
MultiSelection<S>
selectAll(java.lang.Class<S> type)
          Select all components whose model objects match given Hamcrest matcher:
<S extends org.apache.wicket.Component>
MultiSelection<S>
selectAll(java.lang.Class<S> type, java.lang.String wicketId)
          Select all components whose ids are given Wicket id:
<S extends org.apache.wicket.Component>
Selection<S>
selectFirst(java.lang.Class<S> type)
          Select first component whose model object matches given Hamcrest matcher:
<S extends org.apache.wicket.Component>
Selection<S>
selectFirst(java.lang.Class<S> type, java.lang.String wicketId)
          Select first component whose Wicket id is given String:
<T> void
specify(org.apache.wicket.MarkupContainer actual, jdave.IContainment<T> containment)
          Specify that given container contains given model objects.
protected  void startBorder(org.apache.wicket.model.IModel<M> model)
           
 C startComponent()
          Start component for context.
 C startComponent(org.apache.wicket.model.IModel<M> model)
          Start component for context.
 C startComponent(org.apache.wicket.model.IModel<M> model, java.lang.CharSequence pageMarkup, java.lang.String rootComponentId)
          Start component for context, using page with given markup.
 C startComponent(org.apache.wicket.model.IModel<M> model, org.apache.wicket.util.resource.IResourceStream pageMarkup, java.lang.String rootComponentId)
          Start component for context, using page with given markup.
 C startComponentWithoutMarkup(org.apache.wicket.model.IModel<M> model)
          Start component for context.
<F> org.apache.wicket.markup.html.form.Form<F>
startForm(org.apache.wicket.model.IModel<M> model, java.lang.CharSequence formMarkup)
          Start form for context, using given markup as form markup.
protected  void startPage(org.apache.wicket.model.IModel<M> model)
           
protected  void startPanel(org.apache.wicket.model.IModel<M> model)
           
 
Methods inherited from class jdave.Specification
addListener, destroy, equal, equal, equal, equal, fail, fireAfterContextCreation, fireAfterContextDestroy, fireAfterContextInstantiation, getContextObjectFactory, isNotNull, maps, needsThreadLocalIsolation, not, raise, raise, raiseExactly, raiseExactly, satisfies, setContextObjectFactory, setStringComparisonFailure, specify, specify, specify, specify, specify, specify, specify, specify, specify, specify, specify, specify, specify, specify, specify, specify, specify, specify, specify, specify, specify, specify, specify, specify, specify, where
 
Methods inherited from class jdave.mock.MockSupport
checking, dummy, dummy, mock, mock, mockery, sequence, setDefaultResultForType, states, verifyMocks
 
Methods inherited from class jdave.ContainmentSupport
contain, containAll, containAll, containAll, containAll, containAll, containAll, containAll, containAll, containAll, containAll, containAny, containAny, containAny, containAny, containAny, containAny, containAny, containAny, containAny, containAny, containExactly, containExactly, containExactly, containExactly, containExactly, containExactly, containExactly, containExactly, containExactly, containExactly, containInOrder, containInOrder, containInOrder, containInOrder, containInOrder, containInOrder, containInOrder, containInOrder, containInOrder, containInOrder, containInPartialOrder, containInPartialOrder, containInPartialOrder, containInPartialOrder, containInPartialOrder, containInPartialOrder, containInPartialOrder, containInPartialOrder, containInPartialOrder, containInPartialOrder, contains, containsAll, containsAll, containsAll, containsAll, containsAll, containsAll, containsAll, containsAll, containsAll, containsAll, containsAny, containsAny, containsAny, containsAny, containsAny, containsAny, containsAny, containsAny, containsAny, containsAny, containsExactly, containsExactly, containsExactly, containsExactly, containsExactly, containsExactly, containsExactly, containsExactly, containsExactly, containsExactly, containsInOrder, containsInOrder, containsInOrder, containsInOrder, containsInOrder, containsInOrder, containsInOrder, containsInOrder, containsInOrder, containsInOrder, containsInPartialOrder, containsInPartialOrder, containsInPartialOrder, containsInPartialOrder, containsInPartialOrder, containsInPartialOrder, containsInPartialOrder, containsInPartialOrder, containsInPartialOrder, containsInPartialOrder, newAllContainment, newAllContainment, newAllContainment, newAnyContainment, newAnyContainment, newAnyContainment, newExactContainment, newExactContainment, newExactContainment, newInOrderContainment, newInOrderContainment, newInOrderContainment, newInPartialOrderContainment, newInPartialOrderContainment, newInPartialOrderContainment, newObjectContainment
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

wicket

protected org.apache.wicket.util.tester.BaseWicketTester wicket

specifiedComponent

protected C extends org.apache.wicket.Component specifiedComponent
Constructor Detail

ComponentSpecification

public ComponentSpecification()
Method Detail

create

public final void create()
Overrides:
create in class jdave.Specification<C extends org.apache.wicket.Component>

onCreate

protected void onCreate()
Called after create(). No need to call super.onCreate().


startComponent

public C startComponent()
Start component for context.


startComponent

public C startComponent(org.apache.wicket.model.IModel<M> model)
Start component for context.

Parameters:
model - The model passed to component that is used for context.

startComponent

public C startComponent(org.apache.wicket.model.IModel<M> model,
                        java.lang.CharSequence pageMarkup,
                        java.lang.String rootComponentId)
Start component for context, using page with given markup.

Parameters:
model - The model passed to component that is used for context.
pageMarkup - Markup (as java.lang.CharSequence) of the page created to host the specified component.
rootComponentId - Wicket id of the root component in the component markup hierarchy given by the pageMarkup parameter. This is the id of the component returned from newComponent method and used as context, often a MarkupContainer or Form.

startComponent

public C startComponent(org.apache.wicket.model.IModel<M> model,
                        org.apache.wicket.util.resource.IResourceStream pageMarkup,
                        java.lang.String rootComponentId)
Start component for context, using page with given markup.

Parameters:
model - The model passed to component that is used for context.
pageMarkup - Markup (as org.apache.wicket.util.resource.IResourceStream ) of the page created to host the specified component.
rootComponentId - Wicket id of the root component in the component markup hierarchy given by the pageMarkup parameter. This is the id of the component returned from newComponent method and used as context, often a MarkupContainer or Form.

startForm

public <F> org.apache.wicket.markup.html.form.Form<F> startForm(org.apache.wicket.model.IModel<M> model,
                                                                java.lang.CharSequence formMarkup)
Start form for context, using given markup as form markup.

Parameters:
model - The model passed to newComponent method.
formMarkup - Markup (as java.lang.CharSequence) of the form returned from newComponent method, excluding the <form> tag.

startComponentWithoutMarkup

public C startComponentWithoutMarkup(org.apache.wicket.model.IModel<M> model)
Start component for context.

The markup file of a component is not needed.

Parameters:
model - The model passed to component that is used for context.

startBorder

protected void startBorder(org.apache.wicket.model.IModel<M> model)

startPanel

protected void startPanel(org.apache.wicket.model.IModel<M> model)

startPage

protected void startPage(org.apache.wicket.model.IModel<M> model)

cast

protected <X> org.apache.wicket.model.IModel<X> cast(org.apache.wicket.model.IModel<?> model)

specify

public <T> void specify(org.apache.wicket.MarkupContainer actual,
                        jdave.IContainment<T> containment)
Specify that given container contains given model objects.

This is most often used with RefreshingViews and ListViews.

 <blockquote><code>
 ListView list = new ListView("stooges", Arrays.asList("Larry", "Moe", "Curly")) { ... };
 specify(list, containsInOrder("Larry", "Moe", "Curly");
 <code></blockquote>
 

Parameters:
actual - the container of Wicket components
containment - any containment, see: http://www.jdave.org/documentation.html#containments

itemAt

public <T> org.apache.wicket.markup.repeater.Item<T> itemAt(org.apache.wicket.markup.repeater.RepeatingView view,
                                                            int index)
Select an item from a RepeatingView.


itemAt

public <T> org.apache.wicket.markup.html.list.ListItem<T> itemAt(org.apache.wicket.markup.html.list.ListView<T> view,
                                                                 int index)
Select an item from a ListView.


modelObjects

public java.util.List<?> modelObjects(java.util.Iterator<?> components)
Collect model objects from given components.


newWicketTester

protected org.apache.wicket.util.tester.BaseWicketTester newWicketTester()
Create a WicketTester for the specification.

By default, WicketTester is created as:

 <blockquote><code>
 return new BaseWicketTester(newApplication());
 </code></blockquote>
 
So, it is possible to overwrite newApplication if you just need a different Application for a specification.

See Also:
newApplication()

newApplication

protected org.apache.wicket.protocol.http.WebApplication newApplication()
Create the application for the specification.


selectFirst

public <S extends org.apache.wicket.Component> Selection<S> selectFirst(java.lang.Class<S> type)
Select first component whose model object matches given Hamcrest matcher:
 <blockquote><code>
 Item item = selectFirst(Item.class).which(is(0)).from(context);
 </code></blockquote>
 


selectAll

public <S extends org.apache.wicket.Component> MultiSelection<S> selectAll(java.lang.Class<S> type)
Select all components whose model objects match given Hamcrest matcher:
 <blockquote><code>
 List<Label> labels = selectAll(Label.class).which(is(Person.class)).from(context);
 </code></blockquote>
 


selectFirst

public <S extends org.apache.wicket.Component> Selection<S> selectFirst(java.lang.Class<S> type,
                                                                        java.lang.String wicketId)
Select first component whose Wicket id is given String:
 <blockquote><code>
 Label itemName = selectFirst(Label.class, "name").from(context);
 </code></blockquote>
 


selectAll

public <S extends org.apache.wicket.Component> MultiSelection<S> selectAll(java.lang.Class<S> type,
                                                                           java.lang.String wicketId)
Select all components whose ids are given Wicket id:
 <blockquote><code>
 List<Label> prices = selectAll(Label.class, "price").from(context);
 </code></blockquote>
 


newComponent

protected abstract C newComponent(java.lang.String id,
                                  org.apache.wicket.model.IModel<M> model)
Create a new instance of a Wicket component to be specified.

Page, the id is null.

Parameters:
id - The id of a component, null if the component is a Page,
model - A model for the component which was passed in startComponent method.
See Also:
startComponent(IModel)


Copyright ? 2009. All Rights Reserved.