<commit_before>/*
 * $Id: TestOaiHandler.java,v 1.1 2005-01-12 02:21:40 dcfok Exp $
 */

/*

Copyright (c) 2000-2002 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.oai;

import org.lockss.test.*;
import ORG.oclc.oai.harvester2.verb.ListRecords;
import org.lockss.util.Logger;

import org.lockss.util.XmlDomBuilder;
import org.lockss.util.XmlDomBuilder.XmlDomException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import javax.xml.transform.TransformerException;
import javax.xml.parsers.ParserConfigurationException;
import java.lang.NoSuchFieldException;
import java.io.IOException;
import org.xml.sax.SAXException;

/**
 * Test cases for OaiHandler.java
 */
public class TestOaiHandler extends LockssTestCase {

  private OaiRequestData oaiData;
  
  private String handler = "http://www.foo.com/handler";
  private String ns = "ns";
  private String tag = "tag";
  private String setSpec = "setSpec";
  private String prefix = "prefix";

  private String fromDate =  "2004-07-11";
  private String untilDate = "2004-12-26";

  private int retries = 3;

  private OaiHandler oaiHandler;
  
  public void setUp() throws Exception {
    super.setUp();
    oaiData = new OaiRequestData( handler, ns, tag, setSpec, prefix );
  }

  public void testNullParameter(){
    try {
      oaiHandler = new OaiHandler( (OaiRequestData) null, fromDate, untilDate, retries);
      fail("OaiHandler with null OaiRequestData should throw");
    } catch (NullPointerException e) { }
    try {
      oaiHandler = new OaiHandler( oaiData , (String) null , untilDate, retries);
      fail("OaiHandler with null fromDate should throw");
    } catch (NullPointerException e) { }
    try {
      oaiHandler = new OaiHandler( oaiData , fromDate , (String) null, retries);
      fail("OaiHandler with null untilDate should throw");
    } catch (NullPointerException e) { }    
  
  }

  public void testGetErrorMockListRecords(){
    oaiHandler =  new MyMockOaiHandler( oaiData, fromDate, untilDate, retries);
    
    
  }

  /**
   * there are 4 parts in the OaiHandler
   * 1. constructing and issuing an OAI request
   * 2. retriving the response and check for error
   * 3. parse the response for urls
   * 4. if there is any resumptionToken, go back to (1) 
   *    with resumptionToken in OAI request
   *
   * we need to check for the 4 part's error condition.
   * by comparing the hasError() and getUrlIterator()
   * 
   * we need to make a MockListRecords, which will return a
   * nodeList of url (String), and can throw TransformerException
   * <commit_msg>completed one testcase for OaiHandler.getErrors()<commit_after>/*
 * $Id: TestOaiHandler.java,v 1.2 2005-02-15 02:08:39 dcfok Exp $
 */

/*

Copyright (c) 2000-2002 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.oai;

import java.util.List;
import org.lockss.test.*;
import ORG.oclc.oai.harvester2.verb.ListRecords;
import org.lockss.util.Logger;

import org.lockss.util.XmlDomBuilder;
import org.lockss.util.XmlDomBuilder.XmlDomException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import javax.xml.transform.TransformerException;
import javax.xml.parsers.ParserConfigurationException;
import java.lang.NoSuchFieldException;
import java.io.IOException;
import org.xml.sax.SAXException;

import org.lockss.oai.OaiHandler.OaiResponseErrorException;

/**
 * Test cases for OaiHandler.java
 */
public class TestOaiHandler extends LockssTestCase {

  private OaiRequestData oaiData;
  
  private String handler = "http://www.foo.com/handler";
  private String ns = "ns";
  private String tag = "tag";
  private String setSpec = "setSpec";
  private String prefix = "prefix";

  private String fromDate =  "2004-07-11";
  private String untilDate = "2004-12-26";

  private int retries = 3;

  private OaiHandler oaiHandler;
  
  public void setUp() throws Exception {
    super.setUp();
    oaiData = new OaiRequestData( handler, ns, tag, setSpec, prefix );
  }

  public void testNullParameter(){
    try {
      oaiHandler = new OaiHandler( (OaiRequestData) null, fromDate, untilDate, retries);
      fail("OaiHandler with null OaiRequestData should throw");
    } catch (NullPointerException e) { }
    try {
      oaiHandler = new OaiHandler( oaiData , (String) null , untilDate, retries);
      fail("OaiHandler with null fromDate should throw");
    } catch (NullPointerException e) { }
    try {
      oaiHandler = new OaiHandler( oaiData , fromDate , (String) null, retries);
      fail("OaiHandler with null untilDate should throw");
    } catch (NullPointerException e) { }    
  
  }

  /** XXX 2 things particular need to test in OaiHandler 
   * getErrors()
   * getUpdatedUrls()
   *
   */


  public void testGetErrorMockListRecords(){
    oaiHandler =  new MyMockOaiHandler( oaiData, fromDate, untilDate, retries);
    List errList = oaiHandler.getErrors();
    String errMsg = ((OaiResponseErrorException) errList.get(0)).getMessage();
    String expectedErrMsg = "badArgument : This is an error statement";
    assertEquals(expectedErrMsg, errMsg);
    //    System.out.println(errMsg);
  }

  /**
   * there are 4 parts in the OaiHandler
   * 1. constructing and issuing an OAI request
   * 2. retriving the response and check for error
   * 3. parse the response for urls
   * 4. if there is any resumptionToken, go back to (1) 
   *    with resumptionToken in OAI request
   *
   * we need to check for the 4 part's error condition.
   * by comparing the hasError() and getUrlIterator()
   * 
   * we need to make a MockListRecords, which will return a
   * nodeList of url (String), and can throw TransformerException
   * 
{'fraction_non_alphanumeric': 0.07763446093940131, 'fraction_numerical': 0.012655147237770748, 'mean_word_length': 3.972171808832426, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3096398', 'n_tokens_mistral': 2447, 'n_tokens_neox': 2314, 'n_words': 935}