/*
 */
package org.datadryad.journalstatistics.extractor;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Map;
import org.datadryad.api.DryadDataPackage;
import org.datadryad.test.ContextUnitTest;
import org.dspace.content.DCDate;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author Dan Leehr <dan.leehr@nescent.org>
 */
public class DataPackageUnpublishedCountTest extends ContextUnitTest {
    private Date date_2014_06_07;
    private static final String STRING_2014_06 = "2014-06";
    private static final String BURIED_DATE_STRING = "2014-03-05T18:11:29Z";
    private static final String PROVENANCE_MESSAGE = "Submitted by First Last (f.last@university.edu) on " + BURIED_DATE_STRING + " workflow start=Step: requiresReviewStep - action:noUserSelectionAction\nNo. of bitstreams: 0";
    
    @Before
    @Override
    public void setUp() {
        super.setUp();
        Calendar calendar = new GregorianCalendar();
        calendar.set(Calendar.YEAR, 2014);
        calendar.set(Calendar.MONTH, Calendar.JUNE);
        calendar.set(Calendar.DAY_OF_MONTH, 7);
        date_2014_06_07 = calendar.getTime();
    }
    /**
     * Test of bucketForDate method, of class DataPackageUnpublishedCount.
     */
    @Test
    public void testBucketForDate() {
        System.out.println("bucketForDate");
        String expResult = STRING_2014_06;
        String result = DataPackageUnpublishedCount.bucketForDate(date_2014_06_07);
        assertEquals(expResult, result);
    }

    /**
     * Test of extractDateStringFromProvenance method, of class DataPackageUnpublishedCount.
     */
    @Test
    public void testExtractDateStringFromProvenance() throws Exception {
        System.out.println("extractDateStringFromProvenance");
        String provenance = PROVENANCE_MESSAGE;
        String expResult = BURIED_DATE_STRING;
        String result = DataPackageUnpublishedCount.extractDateStringFromProvenance(provenance);
        assertEquals(expResult, result);
    }

    @Test
    public void testCountUnpublishedDataPackages() throws Exception {
        System.out.println("countUnpublishedDataPackages");
        // Make sure there is exactly one unpublished data package for JUN 2014
        DryadDataPackage dataPackage = DryadDataPackage.createInWorkflow(context);
        DCDate submittedDate = new DCDate(date_2014_06_07);
        String submitterName = "Cornelius Tester";
        String submitterEmail = "test@example.com";
        String provenanceStartId = "TEST START ID";
        String bitstreamProvenanceMessage = "Number of Bitstreams: 0";
        String journalName = "Test Journal";
        dataPackage.setPublicationName(journalName);
        dataPackage.addSubmittedProvenance(submittedDate, submitterName, submitterEmail, provenanceStartId, bitstreamProvenanceMessage);
        DataPackageUnpublishedCount instance = new DataPackageUnpublishedCount(this.context);
        Map<String, Integer> results = instance.extract(journalName);
        assertNotNull(results);
        assertTrue(results.containsKey(STRING_2014_06));
        Integer expectedCount = 1;
        Integer resultCount = results.get(STRING_2014_06);
        assertEquals(expectedCount, resultCount);
    }
}

@@ -2223,79 +2223,450 @@
     
-// Make sure there is exactly one unpublished data package for JUN 2014
+String journalName = %22Test Journal%22;%0A        // Get the count prior to adding a data package to the workflow.%0A        DataPackageUnpublishedCount instance = new DataPackageUnpublishedCount(this.context);%0A        Map%3CString, Integer%3E results = instance.extract(journalName);%0A        Integer initialCount = 0;%0A        if(results != null && results.containsKey(STRING_2014_06)) %7B%0A            initialCount = results.get(STRING_2014_06);%0A        %7D
 %0A   
@@ -3035,53 +3035,8 @@
 0%22;%0A
-        String journalName = %22Test Journal%22;%0A
     
@@ -3233,215 +3233,948 @@
     
-DataPackageUnpublishedCount instance = new DataPackageUnpublishedCount(this.context);%0A        Map%3CString, Integer%3E results = instance.extract(journalName);%0A        assertNotNull(results);%0A        assertTrue(
+results = instance.extract(journalName);%0A        assertNotNull(%22Result map should be non-null%22, results);%0A        assertTrue(%22Results should contain a count for %22 + STRING_2014_06, results.containsKey(STRING_2014_06));%0A        Integer expectedCount = initialCount + 1;%0A        Integer resultCount = results.get(STRING_2014_06);%0A        assertEquals(%22Count mismatch%22, expectedCount, resultCount);%0A%0A        // Add a package to the archive with submission metadata%0A        // and make sure it is not counted%0A        dataPackage = DryadDataPackage.create(context);%0A        dataPackage.setPublicationName(journalName);%0A        dataPackage.addSubmittedProvenance(submittedDate, submitterName, submitterEmail, provenanceStartId, bitstreamProvenanceMessage);%0A        results = instance.extract(journalName);%0A        assertNotNull(%22Result map should be non-null%22, results);%0A        assertTrue(%22Results should contain a count for %22 + STRING_2014_06, 
 resu
@@ -4219,51 +4219,8 @@
     
-Integer expectedCount = 1;%0A        Integer 
 resu
@@ -4279,16 +4279,34 @@
 tEquals(
+%22Count mismatch%22, 
 expected

Fix tests for DataPackageUnpublishedCount