/**
 * The contents of this file are subject to the license and copyright
 * detailed in the LICENSE and NOTICE files at the root of the source
 * tree and available online at
 *
 * http://www.dspace.org/license/
 */
package org.datadryad.api;

import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import org.apache.log4j.Logger;
import org.dspace.content.Item;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import org.datadryad.test.ContextUnitTest;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;

/**
 *
 * @author Nathan Day
 */
public class DryadJournalTest extends ContextUnitTest {
    private static Logger log = Logger.getLogger(DryadJournalTest.class);
    private static final String testJournalName = "Evolution";
    private DryadJournal dryadJournal;
    
    @Before
    public void setUp() {
        super.setUp();
        dryadJournal = new DryadJournal(this.context, testJournalName);
    }
    @After
    public void tearDown() {
        super.tearDown();
    }
    
    // override beforeClass, afterClass to avoid kernel setup
    @BeforeClass
    public static void setupClass() {}
    @AfterClass
    public static void tearDownClass() {}
    
    /**
     * Test of getArchivedDataFiles method, of class DryadJournal.
     */
    @Test
    public void testGetArchivedDataFiles() throws Exception {
        log.debug("getArchivedDataFiles");        
        List<Integer> expResult = Arrays.asList(107333);
        List<Integer> result = dryadJournal.getArchivedDataFiles();
        assertEquals(expResult, result);
    }

    /**
     * Test of getArchivedPackagesCount method, of class DryadJournal.
     */
    @Test
    public void testGetArchivedPackagesCount() {
        log.debug("getArchivedPackagesCount");
        int expResult = 1;
        int result = dryadJournal.getArchivedPackagesCount();
        assertEquals(expResult, result);
    }

    /**
     * Test of getArchivedPackagesSortedRecent method, of class DryadJournal.
     */
    @Test
    public void testGetArchivedPackagesSortedRecent() throws Exception {
        log.debug("getArchivedPackagesSortedRecent");
        int max = 10;
        Item item = Item.find(this.context, 107332);
        List<Item> expResult = Arrays.asList(item);
        List<Item> result = dryadJournal.getArchivedPackagesSortedRecent(max);
        assertEquals(expResult, result);
    }

    /**
     * Test of getRequestsPerJournal method, of class DryadJournal.
     */
    @Ignore("No Solr service running on test system")
    @Test
    public void testGetRequestsPerJournal() {
        /*
        log.debug("getRequestsPerJournal");
        String facetQueryField = "";
        String time = "";
        int max = 0;
        LinkedHashMap<Item, String> expResult = null;
        LinkedHashMap<Item, String> result = dryadJournal.getRequestsPerJournal(facetQueryField, time, max);
        assertEquals(expResult, result);
        */
    }
    
}

@@ -320,40 +320,8 @@
 st;%0A
-import org.apache.log4j.Logger;%0A
 impo
@@ -446,36 +446,25 @@
 rg.d
-atadryad.test.ContextUnitTes
+space.core.Contex
 t;%0Ai
@@ -490,67 +490,8 @@
 er;%0A
-import org.junit.AfterClass;%0Aimport org.junit.BeforeClass;%0A
 impo
@@ -579,107 +579,9 @@
 est 
-extends ContextUnitTest %7B%0A    private static Logger log = Logger.getLogger(DryadJournalTest.class);
+%7B
 %0A   
@@ -640,16 +640,17 @@
 ution%22;%0A
+%0A
     priv
@@ -680,24 +680,49 @@
 ournal;%0A    
+private Context context;%0A
 %0A    @Before
@@ -760,23 +760,55 @@
     
-super.setUp();%0A
+try %7B%0A            context = new Context();%0A    
     
@@ -843,21 +843,16 @@
 Journal(
-this.
 context,
@@ -870,16 +870,53 @@
 lName);%0A
+        %7D catch (SQLException ex) %7B%7D%0A
     %7D%0A  
@@ -965,208 +965,78 @@
     
-super.tearDown();
+try %7B
 %0A    
-%7D%0A
     
-%0A
     
-// override beforeClass, afterClass to avoid kernel setup%0A    @BeforeClass%0A    public static void setupClass() %7B%7D%0A    @AfterClass%0A    public static void tearDownClass(
+context.complete();%0A        %7D catch (SQLException ex
 ) %7B%7D
@@ -1036,24 +1036,26 @@
  ex) %7B%7D%0A    
+%7D%0A
 %0A    /**%0A   
@@ -1202,59 +1202,8 @@
 n %7B%0A
-        log.debug(%22getArchivedDataFiles%22);        %0A
     
@@ -1521,55 +1521,8 @@
 ) %7B%0A
-        log.debug(%22getArchivedPackagesCount%22);%0A
     
@@ -1835,62 +1835,8 @@
 n %7B%0A
-        log.debug(%22getArchivedPackagesSortedRecent%22);%0A
     
@@ -1887,13 +1887,8 @@
 ind(
-this.
 cont
@@ -2289,52 +2289,8 @@
  /*%0A
-        log.debug(%22getRequestsPerJournal%22);%0A
     
@@ -2594,11 +2594,6 @@
   %7D%0A
-    %0A
 %7D%0A

remove log4j logging from journal-landing test case and dependence on ContextUnitTest