Closed ghost closed 7 years ago
Please use debugComponentTrees() from the wicket tester to inspect the current components of the page.. You havn't provided the code of the CustomerListPage/CustomerListPageTest classes. Its hard to tell whats the problem...
Here both classes:
package braunimmobilien.web.pages.customers;
import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify;
import java.util.ArrayList; import java.util.List;
import org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable; import org.apache.wicket.markup.repeater.Item; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; import org.springframework.boot.test.mock.mockito.MockBean;
import braunimmobilien.model.Customer; import braunimmobilien.repository.services.customer.CustomerRepositoryService; import braunimmobilien.repository.services.customer.filter.CustomerSort; import braunimmobilien.web.WicketBaseTest; import braunimmobilien.web.html.modal.YesNoModal; import braunimmobilien.web.pages.customers.CustomerListPage; import braunimmobilien.web.pages.customers.create.CustomerCreatePage;
public class CustomerListPageTest extends WicketBaseTest {
private static final long CUSTOMERS_COUNT = 5;
@MockBean
private CustomerRepositoryService repository;
@Override
@Before
public void setUp(){
super.setUp();
Mockito.when(repository.findAll(Mockito.anyLong(), Mockito.anyLong(),
Mockito.any())).thenReturn(createCustomers(CUSTOMERS_COUNT));
Mockito.when(repository.count(Mockito.any())).thenReturn(CUSTOMERS_COUNT);
for (long i=1; i <= CUSTOMERS_COUNT; i++) {
Mockito.when(repository.findById(i)).thenReturn(createCustomer(i));
}
}
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void assert_start_customer_list_page(){
getTester().startPage(CustomerListPage.class);
getTester().assertRenderedPage(CustomerListPage.class);
getTester().assertComponent("filterForm:table", DataTable.class);
DataTable<Customer, CustomerSort> dataTable = (DataTable)
getTester().getComponentFromLastRenderedPage("filterForm:table");
assertThat(dataTable.getItemCount(), equalTo(CUSTOMERS_COUNT));
//id, username, firstname, lastname, active, actions
assertThat(dataTable.getColumns().size(), equalTo(6));
//get third row
Item
public static Customer createCustomer(long i) { Customer customer = new Customer(); customer.setId(Long.valueOf(i)); customer.setUsername("username" + i); customer.setFirstname("firstname" + i); customer.setLastname("lastname" + i); customer.setPassword("password" + i); return customer; } }
package braunimmobilien.web.pages.customers;
import java.util.ArrayList; import java.util.List;
import org.apache.wicket.Component; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation; import org.apache.wicket.extensions.ajax.markup.html.repeater.data.table.AjaxFallbackDefaultDataTable; import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator; import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn; import org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable; import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn; import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn; import org.apache.wicket.extensions.markup.html.repeater.data.table.filter.FilterForm; import org.apache.wicket.extensions.markup.html.repeater.data.table.filter.FilterToolbar; import org.apache.wicket.extensions.markup.html.repeater.data.table.filter.FilteredPropertyColumn; import org.apache.wicket.markup.html.form.Button; import org.apache.wicket.markup.html.form.CheckBox; import org.apache.wicket.markup.html.form.TextField; import org.apache.wicket.markup.html.link.BookmarkablePageLink; import org.apache.wicket.markup.repeater.Item; import org.apache.wicket.model.CompoundPropertyModel; import org.apache.wicket.model.IModel; import org.apache.wicket.model.Model; import org.apache.wicket.model.PropertyModel; import org.apache.wicket.model.ResourceModel; import org.apache.wicket.protocol.ws.api.WebSocketBehavior; import org.apache.wicket.protocol.ws.api.WebSocketRequestHandler; import org.apache.wicket.protocol.ws.api.message.IWebSocketPushMessage; import org.apache.wicket.request.mapper.parameter.PageParameters; import org.apache.wicket.spring.injection.annot.SpringBean; import org.apache.wicket.validation.validator.StringValidator; import org.wicketstuff.annotation.mount.MountPath;
import braunimmobilien.model.Customer; import braunimmobilien.repository.services.customer.CustomerRepositoryService; import braunimmobilien.repository.services.customer.filter.CustomerFilter; import braunimmobilien.repository.services.customer.filter.CustomerSort; import braunimmobilien.web.general.action.panel.ActionPanel; import braunimmobilien.web.general.action.panel.items.AbstrractActionItem; import braunimmobilien.web.general.action.panel.items.links.ActionItemLink; import braunimmobilien.web.general.action.panel.items.yesno.YesNoLink; import braunimmobilien.web.general.icons.IconType; import braunimmobilien.web.html.basic.YesNoLabel; import braunimmobilien.web.html.border.LabeledFormBorder; import braunimmobilien.web.html.form.ValidationForm; import braunimmobilien.web.html.panel.FeedbackPanel; import braunimmobilien.web.html.repeater.data.table.filter.AbstractCheckBoxFilter; import braunimmobilien.web.html.repeater.data.table.filter.AbstractTextFieldFilter; import braunimmobilien.web.pages.BasePage; import braunimmobilien.web.pages.customers.create.CustomerCreatePage; import braunimmobilien.web.pages.customers.edit.CustomerEditPage; import braunimmobilien.web.pages.customers.events.CustomerChangedEvent; import braunimmobilien.web.pages.customers.model.CustomerDataProvider; import braunimmobilien.web.pages.customers.model.UsernameSearchTextField;
@MountPath("customers") @AuthorizeInstantiation("USER") public class CustomerListPage extends BasePage {
@SpringBean
private CustomerRepositoryService customerRepositoryService;
private IModel
private FilterForm
@Override protected void onPush(WebSocketRequestHandler handler, IWebSocketPushMessage message) { if (message instanceof CustomerChangedEvent) { CustomerChangedEvent event = (CustomerChangedEvent)message; info("changed/created " + event.getCustomer().getFirstname() + " " + event.getCustomer().getLastname()); handler.add(feedbackPanel); } }
});
customerFilterModel = new CompoundPropertyModel<>(new CustomerFilter());
CustomerDataProvider customerDataProvider = new
CustomerDataProvider(customerFilterModel);
queue(new BookmarkablePageLink
}
private Button cancelButton() { Button cancelButton = new Button("cancel") {
@Override public void onSubmit() { customerFilterModel.setObject(new CustomerFilter()); getForm().clearInput(); filterForm.clearInput(); }
}; cancelButton.setDefaultFormProcessing(false); return cancelButton; }
private void customerDataTable(CustomerDataProvider customerDataProvider) {
filterForm = new FilterForm
List<IColumn<Customer, CustomerSort>> columns = new ArrayList<>(); columns.add(idColumn()); columns.add(usernameColumn()); columns.add(firstnameColumn()); columns.add(lastnameColumn()); columns.add(activeColumn()); columns.add(actionColumn());
DataTable<Customer, CustomerSort> dataTable = new AjaxFallbackDefaultDataTable<Customer, CustomerSort>("table", columns, customerDataProvider, 10); FilterToolbar filterToolbar = new FilterToolbar(dataTable, filterForm);
dataTable.addTopToolbar(filterToolbar); queue(dataTable); }
private PropertyColumn<Customer, CustomerSort> idColumn() { return new PropertyColumn<>(Model.of("Id"), CustomerSort.ID, CustomerSort.ID.getFieldName()); } private FilteredPropertyColumn<Customer, CustomerSort> usernameColumn() { return new FilteredPropertyColumn<Customer, CustomerSort>(new ResourceModel("username"), CustomerSort.USERNAME, CustomerSort.USERNAME.getFieldName()) {
@Override
public Component getFilter(String componentId, FilterForm<?> form) {
return new AbstractTextFieldFilter
@Override
public TextField
}; }
}; } private FilteredPropertyColumn<Customer, CustomerSort> firstnameColumn() { return new FilteredPropertyColumn<Customer, CustomerSort>(new ResourceModel("firstname"), CustomerSort.FIRSTNAME, CustomerSort.FIRSTNAME.getFieldName()) {
@Override
public Component getFilter(String componentId, FilterForm<?> form) {
return new AbstractTextFieldFilter
@Override
public TextField
}; }
}; } private FilteredPropertyColumn<Customer, CustomerSort> lastnameColumn() { return new FilteredPropertyColumn<Customer, CustomerSort>(new ResourceModel("lastname"), CustomerSort.LASTNAME, CustomerSort.LASTNAME.getFieldName()) {
@Override
public Component getFilter(String componentId, FilterForm<?> form) {
return new AbstractTextFieldFilter
@Override
public TextField
}; }
}; }
private FilteredPropertyColumn<Customer, CustomerSort> activeColumn() { return new FilteredPropertyColumn<Customer, CustomerSort>(new ResourceModel("active"), CustomerSort.ACTIVE, CustomerSort.ACTIVE.getFieldName()) {
@Override public Component getFilter(String componentId, FilterForm<?> form) { return new AbstractCheckBoxFilter(componentId, new PropertyModel<>(form.getModel(), "active"), form); }
@Override
public void populateItem(Item<ICellPopulator
}; } private AbstractColumn<Customer, CustomerSort> actionColumn() { return new AbstractColumn<Customer, CustomerSort>(Model.of("Action")) {
@Override
public void populateItem(Item<ICellPopulator
@Override protected void yesClicked(AjaxRequestTarget target) { customerRepositoryService.delete(rowModel.getObject().getId()); setResponsePage(CustomerListPage.this); } }); ActionPanel actionPanel = new ActionPanel(componentId, abstractItems); cellItem.add(actionPanel);
} }; }
}
2017-06-16 20:54 GMT+02:00 MarcGiffing notifications@github.com:
Please use debugComponentTrees() from the wicket tester to inspect the current components of the page.. You havn't provided the code of the CustomerListPage/CustomerListPageTest classes. Its hard to tell whats the problem...
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/MarcGiffing/wicket-spring-boot/issues/114#issuecomment-309107040, or mute the thread https://github.com/notifications/unsubscribe-auth/AKZkZ7pkZhyKw9Glkr_d9Wm_jv6C1E0Rks5sEs95gaJpZM4N8XgA .
I reduced the tests now and i think i found the change which causes the different behaviour of the tests. To use the agilecoders artifacts i made the following change in the BasePage : private void initPage(){ add(new HtmlTag("html")); add(new Label("title", new ResourceModel("page.title"))); add(new MobileViewportMetaTag("viewport")); add(new IeEdgeMetaTag("ie-edge")); add(newNavbar("navbar"));
defaultModal = new EmptyPanel("defaultModal");
defaultModal.setOutputMarkupId(true);
add(defaultModal);
}
and just at this HTMLTag i have an error:
Tests run: 4, Failures: 0, Errors: 4, Skipped: 0, Time elapsed: 3.933 sec <<< FAILURE! - in braunimmobilien.web.pages.customers.CustomerListPageTest assert_delete_customer_method_called_once(braunimmobilien.web.pages.customers.CustomerListPageTest) Time elapsed: 0.273 sec <<< ERROR! java.lang.NullPointerException: null at de.agilecoders.wicket.core.markup.html.bootstrap.html.HtmlTag.onComponentTag(HtmlTag.java:135) at org.apache.wicket.Component.internalRenderComponent(Component.java:2542) at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1657) at org.apache.wicket.Component.internalRender(Component.java:2401) at org.apache.wicket.Component.render(Component.java:2329) at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1515) at org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1718) at org.apache.wicket.Page.onRender(Page.java:879) at org.apache.wicket.markup.html.WebPage.onRender(WebPage.java:141) at org.apache.wicket.Component.internalRender(Component.java:2401) at org.apache.wicket.Component.render(Component.java:2329) at org.apache.wicket.Page.renderPage(Page.java:1018) at org.apache.wicket.request.handler.render.WebPageRenderer.renderPage(WebPageRenderer.java:124) at org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:236) at org.apache.wicket.util.tester.BaseWicketTester$LastPageRecordingPageRendererProvider$1.respond(BaseWicketTester.java:2802) at org.apache.wicket.core.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:175) at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:895) at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64) at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:265) at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:222) at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:293) at org.apache.wicket.util.tester.BaseWicketTester.processRequest(BaseWicketTester.java:722) at org.apache.wicket.util.tester.BaseWicketTester.processRequest(BaseWicketTester.java:661) at org.apache.wicket.util.tester.BaseWicketTester.processRequest(BaseWicketTester.java:633) at org.apache.wicket.util.tester.BaseWicketTester.startPage(BaseWicketTester.java:1290) at org.apache.wicket.util.tester.BaseWicketTester.startPage(BaseWicketTester.java:1263) at braunimmobilien.web.WicketBaseTest.login(WicketBaseTest.java:75) at braunimmobilien.web.WicketBaseTest.setUp(WicketBaseTest.java:60) at braunimmobilien.web.pages.customers.CustomerListPageTest.setUp(CustomerListPageTest.java:36)
still here the markup of the LoginPage:
<!DOCTYPE html>
I check what happens when i extinct the html Tag in the makup
THe application is running but the test error prevails. I don't know for what this HtmlTag change is good for i copied it from another application which uses more of the agilecoders artifacts maybe i erase this change and look if the application still works
I need this Tag because without i get the error org.apache.wicket.WicketRuntimeException: No BootstrapSettings associated with this Application. Did you call Bootstrap.install()?
What a pity the Application from which i copied has no tests and there is another difference OptimizedMobileViewportMetaTag doesn't exist any more i used MobileViewportMetaTag and the other applicatiuon doesn't use spring authentication. The only idea i have now is to add tests to the other application and see if i get the same error
It is always the HtmlTag which causes the problem in the test java.lang.NullPointerException: null at de.agilecoders.wicket.core.markup.html.bootstrap.html.HtmlTag.onComponentTag(HtmlTag.java:135) at org.apache.wicket.Component.internalRenderComponent(Component.java:2542) when i remove it the test passes but then i cannot use the agilecoders artifacts
2017-06-16 20:54 GMT+02:00 MarcGiffing notifications@github.com:
Please use debugComponentTrees() from the wicket tester to inspect the current components of the page.. You havn't provided the code of the CustomerListPage/CustomerListPageTest classes. Its hard to tell whats the problem...
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/MarcGiffing/wicket-spring-boot/issues/114#issuecomment-309107040, or mute the thread https://github.com/notifications/unsubscribe-auth/AKZkZ7pkZhyKw9Glkr_d9Wm_jv6C1E0Rks5sEs95gaJpZM4N8XgA .
I think i have it. there is no active theme provider
But now it is a question for you: in the main stream i have the configuration class
ApplicationInitExtension public class BraunimmobilienExtensionConfig implements WicketApplicationInitConfiguration{ @Override public void init(WebApplication webApplication) { configureBootstrap(webApplication); } private void configureBootstrap(WebApplication webApplication) { // System.exit(5); Bootstrap.install(webApplication, new BootstrapSettings().setThemeProvider(new SingleThemeProvider(new BootstrapTheme()))); }
} in the test there is the configuration class @SpringBootApplication @EnableAutoConfiguration(exclude={ DataSourceAutoConfiguration.class, JpaRepositoriesAutoConfiguration.class, HibernateJpaAutoConfiguration.class, }) @ComponentScan(basePackageClasses=SpringBootWebPackageIdentifier.class) public class WicketWebApplicationConfig extends WicketBootSecuredWebApplication {
@Override
protected Class<? extends WebPage> getSignInPageClass() {
return LoginPage.class;
}
@Override
public Class<? extends Page> getHomePage() {
return CustomerListPage.class;
}
@Override
protected Class<? extends AbstractAuthenticatedWebSession> getWebSessionClass() {
return SecureWebSession.class;
}
} How can i bring the themeproviderinformation in the test classes
I have it :: I put BraunimmobilienExtensionConfig in the same package as SpringBootWebPackageIdentifier and then started all paths with "html:"
But the application does its job. So let me describe what i did. I use
and