/* * Copyright 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package jdave.wicket; import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.is; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import jdave.junit4.JDaveRunner; import org.apache.wicket.markup.html.WebMarkupContainer; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.list.ListItem; import org.apache.wicket.markup.html.list.ListView; import org.apache.wicket.markup.repeater.Item; import org.apache.wicket.markup.repeater.RefreshingView; import org.apache.wicket.model.IModel; import org.apache.wicket.model.util.ListModel; import org.junit.runner.RunWith; /** * @author Joni Freeman * @author Timo Rantalaiho */ @RunWith(JDaveRunner.class) public class PageWithItemsSpec extends ComponentSpecification> { public class WhenListHasItems { private final List list = Arrays.asList(0, 1, 2); public PageWithItems create() { return startComponent(new ListModel(list)); } public void theItemsCanBeReferencedEasilyInListView() { final ListItem item = itemAt(selectFirst(ListView.class, "listView") .> from(context), 1); specify(item.get("item").getDefaultModelObject(), does.equal("1")); } public void theItemsCanBeReferencedEasilyInRefreshingView() { final Item item = itemAt(selectFirst(RefreshingView.class, "refreshingView") .> from(context), 1); specify(item.get("item").getDefaultModelObject(), does.equal("1")); } public void theModelObjectsCanBeCollectedFromComponents() { final ListView listView = selectFirst(ListView.class, "listView") .> from(context); specify(modelObjects(listView.iterator()), containsInOrder(0, 1, 2)); } public void theModelObjectsCanBeUsedInContainmentExpectations() { final ListView listView = selectFirst(ListView.class, "listView") .> from(context); specify(listView, containsInOrder(0, 1, 2)); } public void theModelObjectsCanBeUsedInNegativeContainmentExpectations() { final ListView listView = selectFirst(ListView.class, "listView") .> from(context); specify(listView, does.not().containAll(0, 1, 2, 4)); } public void theFirstItemCanBePickedUsingHamcrestMatcher() { final Item item = selectFirst(Item.class).which(is(0)).from(context); specify(item.get("item").getDefaultModelObject(), does.equal("0")); } @SuppressWarnings("unchecked") public void allItemsCanBePickedUsingHamcrestMatcher() { final List> items = selectAll(Item.class).which(is(anyOf(is(0), is(1)))) .from(context); specify(modelObjects(items.iterator()), containsInOrder(0, 1)); } public void theFirstItemCanBePickedUsingItsId() { final Label item = selectFirst(Label.class, "item").from(context); specify(item.getDefaultModelObjectAsString(), is("0")); } public void allItemsWithSameIdCanBePickedUsingTheirId() { final List