package de.ppi.samples.fuwesta.selophane.test;

import static org.assertj.core.api.Assertions.assertThat;

import org.dbunit.dataset.DataSetException;
import org.dbunit.dataset.IDataSet;
import org.junit.Test;

import de.ppi.samples.fuwesta.dbunit.dataset.TestData;
import de.ppi.samples.fuwesta.frontend.URL;
import de.ppi.samples.fuwesta.selophane.base.AuthRule.Auth;
import de.ppi.samples.fuwesta.selophane.widget.PaginatingBar;

/**
 * Test for the post-page.
 *
 */
public class PostIntegrationTest extends AbstractPostIntegrationTest {

    /**
     * {@inheritDoc}
     */
    @Override
    protected IDataSet getDataSet() throws DataSetException {
        return TestData.initWithSampleData();
    }

    /**
     * Test if the post-menu is active.
     */
    @Test
    public void testMenuPostActive() {
        browser.getRelativeUrl(URL.Post.LIST);
        assertThat(browser.getCurrentRelativeUrl()).isEqualTo(URL.Post.LIST);
        assertThat(postListPage.getMenu().getMenuItem("Post").isActive())
                .isTrue();
        assertThat(postListPage.getMenu().getMenuItem("User").isActive())
                .isFalse();
    }

    /**
     * Test if only the post menu exists and is active, if a user is
     * authenticated as post.
     */
    @Test
    @Auth(user = "post")
    public void testMenuPost() {
        browser.getRelativeUrl(URL.Post.LIST);
        assertThat(browser.getCurrentRelativeUrl()).isEqualTo(URL.Post.LIST);
        assertThat(postListPage.getMenu().getMenuItem("Post").isActive())
                .isTrue();
        assertThat(postListPage.getMenu().getMenuItems()).hasSize(2);
    }

    /**
     * Test if the table shows 2 entries.
     *
     *
     */
    @Test
    public void testPostList() {
        browser.getRelativeUrl(URL.Post.LIST);
        assertThat(browser.getCurrentRelativeUrl()).isEqualTo(URL.Post.LIST);
        softly.assertThat(postListPage.getTable().getNrOfDataRows()).isEqualTo(
                2);
        softly.assertThat(postListPage.getTable().getNrOfDataColumns())
                .isEqualTo(2);
        softly.assertThat(postListPage.getPaginatingBar().getNrOfButtons())
                .isEqualTo(5);
        softly.assertThat(postListPage.getPaginatingBar().getFirst()).hasClass(
                PaginatingBar.CLASS_DISABLED);
        softly.assertThat(postListPage.getPaginatingBar().getLast()).hasClass(
                PaginatingBar.CLASS_DISABLED);
        softly.assertThat(postListPage.getPaginatingBar().getPrevious())
                .hasClass(PaginatingBar.CLASS_DISABLED);
        softly.assertThat(postListPage.getPaginatingBar().getNext()).hasClass(
                PaginatingBar.CLASS_DISABLED);
        softly.assertThat(postListPage.getPaginatingBar().getButton("1"))
                .hasNotClass(PaginatingBar.CLASS_DISABLED);
    }
}

@@ -363,16 +363,76 @@
 e.Auth;%0A
+import de.ppi.samples.fuwesta.selophane.widget.ActionTable;%0A
 import d
@@ -1736,16 +1736,44 @@
  entries
+ and that the label are fine
 .%0A     *
@@ -1968,49 +1968,90 @@
     
-softly.assertThat(postListPage.getTable()
+final ActionTable table = postListPage.getTable();%0A        softly.assertThat(table
 .get
@@ -2076,16 +2076,19 @@
 EqualTo(
+2);
 %0A       
@@ -2092,180 +2092,732 @@
     
-        2);%0A        softly.assertThat(postListPage.getTable().getNrOfDataColumns())%0A                .isEqualTo(2);%0A        softly.assertThat(postListPage.getPaginatingBar()
+softly.assertThat(table.getNrOfDataColumns()).isEqualTo(2);%0A        final ActionTable.Row firstRow = table.getDataRows().get(0);%0A        softly.assertThat(firstRow.getActions()).hasSize(4);%0A        softly.assertThat(firstRow.getActions().get(0).getText()).isEqualTo(%0A                %22Show%22);%0A        softly.assertThat(firstRow.getActions().get(1).getText()).isEqualTo(%0A                %22Edit%22);%0A        softly.assertThat(firstRow.getActions().get(2).getText()).isEqualTo(%0A                %22Partialedit%22);%0A        softly.assertThat(firstRow.getActions().get(3).getText()).isEqualTo(%0A                %22Delete%22);%0A%0A        final PaginatingBar paginatingBar = postListPage.getPaginatingBar();%0A        softly.assertThat(paginatingBar
 .get
@@ -2830,33 +2830,16 @@
 ttons())
-%0A                
 .isEqual
@@ -2872,32 +2872,16 @@
 rtThat(p
-ostListPage.getP
 aginatin
@@ -2880,26 +2880,24 @@
 aginatingBar
-()
 .getFirst())
@@ -2981,32 +2981,16 @@
 rtThat(p
-ostListPage.getP
 aginatin
@@ -2989,26 +2989,24 @@
 aginatingBar
-()
 .getLast()).
@@ -3089,32 +3089,16 @@
 rtThat(p
-ostListPage.getP
 aginatin
@@ -3097,26 +3097,24 @@
 aginatingBar
-()
 .getPrevious
@@ -3116,16 +3116,26 @@
 vious())
+.hasClass(
 %0A       
@@ -3143,26 +3143,16 @@
         
-.hasClass(
 Paginati
@@ -3201,32 +3201,16 @@
 rtThat(p
-ostListPage.getP
 aginatin
@@ -3209,26 +3209,24 @@
 aginatingBar
-()
 .getNext()).
@@ -3309,32 +3309,16 @@
 rtThat(p
-ostListPage.getP
 aginatin
@@ -3321,18 +3321,16 @@
 atingBar
-()
 .getButt
@@ -3337,16 +3337,29 @@
 on(%221%22))
+.hasNotClass(
 %0A       
@@ -3367,29 +3367,16 @@
         
-.hasNotClass(
 Paginati

Check the actions of the table.