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

import java.sql.SQLException;
import org.datadryad.api.DryadDataPackage;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.WorkspaceItem;
import org.dspace.core.Context;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author Dan Leehr <dan.leehr@nescent.org>
 */
public class DataPackageCountTest {

    private Context context;
    public DataPackageCountTest() {
    }

    @BeforeClass
    public static void setUpClass() {
    }

    @AfterClass
    public static void tearDownClass() {
    }

    @Before
    public void setUp() {
        try {
            this.context = new Context();
            context.turnOffAuthorisationSystem();
        } catch (SQLException ex) {
            fail("Unable to instantiate Context " + ex);
        }
    }

    @After
    public void tearDown() {
    }

    /**
     * Test of extract method, of class DataPackageCount.
     * Data packages are items in collection identified by 'stats.datapkgs.coll'
     * having prism.publicationName as provided
     */
    @Test
    public void testExtract() throws SQLException {
        // There should be one package in the database with journal name "Test Journal"
        // Create a data package
        DryadDataPackage dataPackage = DryadDataPackage.create(context);
        // set its journal
        String journalName = "Test Journal";
        dataPackage.setPublicationName(journalName);
        context.commit();

        DataPackageCount instance = new DataPackageCount(this.context);
        Integer expResult = 1;
        Integer result = instance.extract(journalName);
        assertEquals(expResult, result);
    }
}

@@ -1241,15 +1241,25 @@
 test
-Extract
+CountDataPackages
 () t
@@ -1294,35 +1294,48 @@
  // 
-There should 
+Count the initial num
 be
+r
  o
-ne
+f data
  package
  in 
@@ -1334,37 +1334,32 @@
 kage
- in the database with
+s%0A        String
  journal
  nam
@@ -1358,13 +1358,14 @@
 rnal
- n
+N
 ame
+ =
  %22Te
@@ -1375,16 +1375,17 @@
 Journal%22
+;
 %0A       
@@ -1389,257 +1389,207 @@
     
-// Create a data package%0A        DryadDataPackage dataPackage = DryadDataPackage.create(context);%0A        // set its journal%0A        String journalName = %22Test Journal%22;%0A       
+DataPackageCount instance = new DataPackageCount(this.context);%0A        Integer initialCount = instance.extract(journalName);%0A        // Create a new
  data
-P
+ p
 ackage
-.setPublicationName(journalName);%0A        context.commit();%0A
+, and assert the count goes up by one
 %0A   
@@ -1585,32 +1585,37 @@
  by one%0A        
+Dryad
 DataPackageCount
@@ -1613,58 +1613,107 @@
 kage
-Count instance = new DataPackageCount(this.context
+ dataPackage = DryadDataPackage.create(context);%0A        dataPackage.setPublicationName(journalName
 );%0A 
@@ -1738,16 +1738,31 @@
 Result =
+ initialCount +
  1;%0A    

Update test to check for count+1