/*
 * $Id: TestMathematicalSciencesPublishersPlugin.java,v 1.2 2013-10-04 01:44:45 etenbrink Exp $
 */

/*

Copyright (c) 2000-2012 Board of Trustees of Leland Stanford Jr. University,
all rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
STANFORD UNIVERSITY BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of Stanford University shall not
be used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from Stanford University.

*/

package org.lockss.plugin.mathematicalsciencespublishers;

import java.net.*;
import java.util.*;

import org.lockss.test.*;
import org.lockss.plugin.*;
import org.lockss.config.Configuration;
import org.lockss.daemon.*;
import org.lockss.extractor.*;
import org.lockss.plugin.ArchivalUnit.*;
import org.lockss.plugin.definable.*;
import org.lockss.plugin.wrapper.*;

public class TestMathematicalSciencesPublishersPlugin extends LockssTestCase {
  static final String BASE_URL_KEY = ConfigParamDescr.BASE_URL.getKey();
  static final String JOURNAL_ID_KEY = ConfigParamDescr.JOURNAL_ID.getKey();
  static final String YEAR_KEY = ConfigParamDescr.YEAR.getKey();

  private DefinablePlugin plugin;

  public TestMathematicalSciencesPublishersPlugin(String msg) {
    super(msg);
  }

  public void setUp() throws Exception {
    super.setUp();
    plugin = new DefinablePlugin();
    plugin.initPlugin(getMockLockssDaemon(),
                      "org.lockss.plugin.mathematicalsciencespublishers." +
                      "ClockssMathematicalSciencesPublishersPlugin");
  }

  public void testGetAuNullConfig()
      throws ArchivalUnit.ConfigurationException {
    try {
      plugin.configureAu(null, null);
      fail("Didn't throw ArchivalUnit.ConfigurationException");
    } catch (ArchivalUnit.ConfigurationException e) {
    }
  }
  public void testCreateAu() {
    Properties props = new Properties();
    props.setProperty(BASE_URL_KEY, "http://www.example.com/");
    props.setProperty(JOURNAL_ID_KEY, "j_id");
    props.setProperty(YEAR_KEY, "2004");
    DefinableArchivalUnit au = null;
    try {
      au = makeAuFromProps(props);
    }
    catch (ConfigurationException ex) {
    }
    au.getName();
  }

  private DefinableArchivalUnit makeAuFromProps(Properties props)
      throws ArchivalUnit.ConfigurationException {
    Configuration config = ConfigurationUtil.fromProps(props);
    return (DefinableArchivalUnit)plugin.configureAu(config, null);
  }

  public void testGetAuHandlesBadUrl()
      throws ArchivalUnit.ConfigurationException, MalformedURLException {
    Properties props = new Properties();
    props.setProperty(BASE_URL_KEY, "blah");
    props.setProperty(JOURNAL_ID_KEY, "322");
    props.setProperty(YEAR_KEY, "2001");

    try {
      DefinableArchivalUnit au = makeAuFromProps(props);
      fail ("Didn't throw InstantiationException when given a bad url");
    } catch (ArchivalUnit.ConfigurationException auie) {
      assertNotNull(auie.getCause());
    }
  }

  public void testGetAuConstructsProperAu()
      throws ArchivalUnit.ConfigurationException, MalformedURLException {
    Properties props = new Properties();
    props.setProperty(BASE_URL_KEY, "http://www.example.com/");
    props.setProperty(JOURNAL_ID_KEY, "j_id");
    props.setProperty(YEAR_KEY, "2004");

    DefinableArchivalUnit au = makeAuFromProps(props);
    assertEquals("Mathematical Sciences Publishers Plugin (CLOCKSS), " +
        "Base URL http://www.example.com/, " +
        "Journal ID j_id, Year 2004", au.getName());
  }

  public void testGetPluginId() {
    assertEquals("org.lockss.plugin.mathematicalsciencespublishers." +
        "ClockssMathematicalSciencesPublishersPlugin",
        plugin.getPluginId());
  }

  public void testGetAuConfigProperties() {
    // this assert fails due to the fact that the year param
    // in the LocalAuConfigDescrs is a string[20]
    
//    assertEquals(ListUtil.list(ConfigParamDescr.BASE_URL,
//                               ConfigParamDescr.JOURNAL_ID,
//                               ConfigParamDescr.YEAR),
//                 plugin.getLocalAuConfigDescrs());
  }

  public void testGetArticleMetadataExtractor() {
    Properties props = new Properties();
    props.setProperty(BASE_URL_KEY, "http://www.example.com/");
    props.setProperty(JOURNAL_ID_KEY, "asdf");
    props.setProperty(YEAR_KEY, "2004");
    DefinableArchivalUnit au = null;
    try {
      au = makeAuFromProps(props);
    }
    catch (ConfigurationException ex) {
    }
    assertTrue(""+plugin.getArticleMetadataExtractor(MetadataTarget.Any(), au),
        plugin.getArticleMetadataExtractor(null, au) instanceof ArticleMetadataExtractor);
    assertTrue(""+plugin.getFileMetadataExtractor(MetadataTarget.Any(), "text/html", au),
        plugin.getFileMetadataExtractor(MetadataTarget.Any(), "text/html", au) instanceof
        FileMetadataExtractor
        );
  }
  public void testGetHashFilterFactory() {
    assertNull(plugin.getHashFilterFactory("BogusFilterFactory"));
    assertNull(plugin.getHashFilterFactory("application/pdf"));
    assertNotNull(plugin.getHashFilterFactory("text/html"));
    assertTrue(WrapperUtil.unwrap(plugin.getHashFilterFactory("application/xhtml+xml"))
        instanceof org.lockss.plugin.mathematicalsciencespublishers.MathematicalSciencesPublishersHtmlFilterFactory);
  }
  public void testGetArticleIteratorFactory() {
    assertTrue(WrapperUtil.unwrap(plugin.getArticleIteratorFactory())
        instanceof org.lockss.plugin.mathematicalsciencespublishers.MathematicalSciencesPublishersArticleIteratorFactory);
  }

}

@@ -58,29 +58,29 @@
 v 1.
-2
+3
  201
-3-10-04 01:44:45
+4-03-07 00:09:13
  ete
@@ -1574,24 +1574,57 @@
 kss.test.*;%0A
+import org.lockss.util.ListUtil;%0A
 import org.l
@@ -4780,126 +4780,8 @@
 ) %7B%0A
-    // this assert fails due to the fact that the year param%0A    // in the LocalAuConfigDescrs is a string%5B20%5D%0A    %0A//
     
@@ -4834,18 +4834,16 @@
 SE_URL,%0A
-//
         
@@ -4894,18 +4894,16 @@
 NAL_ID,%0A
-//
         
@@ -4949,18 +4949,16 @@
 .YEAR),%0A
-//
         

Update test for year parameter (string with int)