001    package org.hackystat.projectbrowser.page.dailyprojectdata;
002    
003    import static org.junit.Assert.assertEquals;
004    import static org.junit.Assert.assertTrue;
005    import static org.junit.Assert.fail;
006    import java.util.Properties;
007    
008    import javax.xml.datatype.XMLGregorianCalendar;
009    
010    import org.apache.wicket.Component;
011    import org.apache.wicket.markup.html.form.ListMultipleChoice;
012    import org.apache.wicket.util.tester.FormTester;
013    import org.apache.wicket.util.tester.WicketTester;
014    import org.hackystat.projectbrowser.ProjectBrowserApplication;
015    import org.hackystat.projectbrowser.ProjectBrowserProperties;
016    import org.hackystat.projectbrowser.authentication.SigninPage;
017    import org.hackystat.projectbrowser.test.ProjectBrowserTestHelper;
018    import org.hackystat.sensorbase.resource.projects.jaxb.Project;
019    import org.hackystat.utilities.tstamp.Tstamp;
020    import org.junit.Test;
021    
022    /**
023     * Test class for DailyProjectDataPage.
024     * @author Shaoxuan Zhang
025     *
026     */
027    public class TestDailyProjectDataPage extends ProjectBrowserTestHelper {
028    
029      /**
030       * Test the daily project data page.
031       */
032      @Test 
033      public void testDailyProjectDataPage() {  //NOPMD WicketTester has its own assert classes.
034        Properties testProperties = getTestProperties();
035        testProperties.put(ProjectBrowserProperties.AVAILABLEPAGE_KEY + ".dailyprojectdata", "true");
036        WicketTester tester = new WicketTester(new ProjectBrowserApplication(testProperties));
037        tester.startPage(SigninPage.class); 
038        // Let's sign in.
039        String testUser = "TestUser@hackystat.org";
040        FormTester signinForm = tester.newFormTester("signinForm");
041        signinForm.setValue("user", testUser);
042        signinForm.setValue("password", testUser);
043        signinForm.submit("Signin");
044        //first, go to daily project data page.
045        tester.clickLink("DailyProjectDataPageLink");
046        tester.assertRenderedPage(DailyProjectDataPage.class);
047        FormTester projectForm = tester.newFormTester("dpdInputPanel:dpdInputForm");
048        //checkt the date field.
049        assertEquals("The date field should be set to yesterday.", getDateYesterdayAsString(), 
050            projectForm.getTextComponentValue("dateTextField"));
051        //check the project list content.
052        Component component = projectForm.getForm().get("projectMenu");
053        assertTrue("Check project select field", component instanceof ListMultipleChoice);
054        ListMultipleChoice projectChoice = (ListMultipleChoice) component;
055        boolean pass = false;
056        int index = 0;
057        for (int i = 0; i < projectChoice.getChoices().size(); i++) {
058          Project project = (Project)projectChoice.getChoices().get(i);
059          if ("Default".equals(project.getName())) {
060            index = i;
061            pass = true;
062          }
063        }
064        if (!pass) {
065          fail("Default project not found in project list.");
066        }
067        //select that choice.
068        projectForm.select("projectMenu", index);
069        projectForm.select("analysisMenu", 1);
070        projectForm.submit();
071        //check the result.
072        tester.assertRenderedPage(
073            org.hackystat.projectbrowser.page.dailyprojectdata.DailyProjectDataPage.class);
074        //tester.assertLabel("dpdDataPanel:valuesType", "Count");
075      }
076      
077      /**
078       * return a String that represent the date of today.
079       * @return a String represent today.
080       */
081      public String getDateYesterdayAsString() {
082        XMLGregorianCalendar time = Tstamp.incrementDays(Tstamp.makeTimestamp(), -1);
083        String timeString = time.getYear() + "-";
084        timeString += (time.getMonth() >= 10) ? time.getMonth() : "0" + time.getMonth();
085        timeString += "-";
086        timeString += (time.getDay() >= 10) ? time.getDay() : "0" + time.getDay();
087        return timeString;
088      }
089    }