/*
 * $Id: PTestPlugin.java,v 1.2 2002-08-13 02:20:48 tal Exp $
 */

/*

Copyright (c) 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.proxy;

import java.io.*;
import java.util.*;
import java.net.*;
import java.security.MessageDigest;
import org.lockss.daemon.*;
import org.lockss.plugin.*;
import org.lockss.test.*;

/**
 * Stub plugin for testing proxy.
 * Results are completely canned.
 */
class PTestPlugin {

  static class PCachedUrl implements CachedUrl {
    private String url;
    private String contents = null;
    private Properties props = new Properties();

    public PCachedUrl(String url) {
      this.url = url;
    }
    public PCachedUrl(String url, String type, String contents) {
      this.url = url;
      setContents(contents);
      props.setProperty("Content-Type", type);
    }

    public void setContents(String s) {
      contents = s;
      props.setProperty("Content-Length", ""+s.length());
    }

    public String toString() {
      return url;
    }

    public boolean exists() {
      return contents != null;
    }

    public boolean shouldBeCached() {
      return false;;
    }

    public InputStream openForReading() {
      return new StringInputStream(contents);
    }

    public Properties getProperties() {
      return props;
    }

    public void storeContent(InputStream input,
			     Properties headers) throws IOException{
    }

    public InputStream getUncachedInputStream() {
      return null;
    }
  
    public Properties getUncachedProperties() {
      return null;
    }
  }

  static class PCachedUrlSet implements CachedUrlSet {
    private Hashtable map = new Hashtable();

    public String toString() {
      return "[cus: " + map + "]";
    }

    void storeCachedUrl(CachedUrl cu) {
      map.put(cu.toString(), cu);
    }

    public void addToList(CachedUrlSetSpec spec) {
    }

    public boolean removeFromList(CachedUrlSetSpec spec) {
      return false;
    }

    public boolean memberOfList(CachedUrlSetSpec spec) {
      return false;
    }

    public Enumeration listEnumeration() {
      return null;
    }

    public boolean memberOfSet(String url) {
      return map.containsKey(url);
    }

    public CachedUrlSetHasher getContentHasher(MessageDigest hasher) {
      return null;
    }

    public CachedUrlSetHasher getNameHasher(MessageDigest hasher) {
      return null;
    }

    public Enumeration flatEnumeration() {
      return null;
    }

    public Enumeration treeEnumeration() {
      return null;
    }

    public long hashDuration() {
      return 0;
    }

    public long duration(long elapsed, boolean success) {
      return 0;
    }

    public CachedUrl makeCachedUrl(String url) {
      return (CachedUrl)map.get(url);
    }

    public UrlCacher makeUrlCacher(String url) {
      return (UrlCacher)map.get(url);
    }
  }

  public static CachedUrlSet makeTest() {
    PCachedUrlSet cus = new PCachedUrlSet();
    cus.storeCachedUrl(new PCachedUrl("http://foo.bar/one", "text/plain",
				      "this is one text\n"));
    cus.storeCachedUrl(new PCachedUrl("http://foo.bar/two", "text/html",
				      "<html><h3>this is two html</h3></html>"));
    org.lockss.plugin.Plugin.registerCachedUrlSet(cus);
    return cus;
  }


}

@@ -29,29 +29,29 @@
 v 1.
-2
+3
  2002-0
-8-13 02:20:48
+9-19 20:56:06
  tal
@@ -1728,26 +1728,18 @@
 c class 
-PCachedUrl
+CU
  impleme
@@ -1871,34 +1871,26 @@
 %0A    public 
-PCachedUrl
+CU
 (String url)
@@ -1931,26 +1931,18 @@
  public 
-PCachedUrl
+CU
 (String 
@@ -2084,29 +2084,30 @@
     %7D%0A%0A    p
-ublic
+rivate
  void setCon
@@ -2337,74 +2337,8 @@
  %7D%0A%0A
-    public boolean shouldBeCached() %7B%0A      return false;;%0A    %7D%0A%0A
     
@@ -2498,308 +2498,51 @@
   %7D%0A
-%0A
   
-  public void storeContent(InputStream input,%0A%09%09%09     Properties headers) throws IOException%7B%0A    %7D%0A%0A    public InputStream getUncachedInputStream() %7B%0A      return null;%0A    %7D%0A  %0A    public Properties getUncachedProperties() %7B%0A      return null;%0A    %7D%0A  %7D%0A%0A  static class PCachedUrlSet implements 
+%7D%0A%0A  static class CUS extends NullPlugin.
 Cach
@@ -2675,16 +2675,24 @@
  %7D%0A%0A    
+private 
 void sto
@@ -2775,838 +2775,75 @@
 lic 
-void addToList(CachedUrlSetSpec spec) %7B%0A    %7D%0A%0A    public boolean removeFromList(CachedUrlSetSpec spec) %7B%0A      return false;%0A    %7D%0A%0A    public boolean memberOfList(CachedUrlSetSpec spec) %7B%0A      return false;%0A    %7D%0A%0A    public Enumeration listEnumeration() %7B%0A      return null;%0A    %7D%0A%0A    public boolean memberOfSet(String url) %7B%0A      return map.containsKey(url);%0A    %7D%0A%0A    public CachedUrlSetHasher getContentHasher(MessageDigest hasher) %7B%0A      return null;%0A    %7D%0A%0A    public CachedUrlSetHasher getNameHasher(MessageDigest hasher) %7B%0A      return null;%0A    %7D%0A%0A    public Enumeration flatEnumeration() %7B%0A      return null;%0A    %7D%0A%0A    public Enumeration treeEnumeration() %7B%0A      return null;%0A    %7D%0A%0A    public long hashDuration() %7B%0A      return 0;%0A    %7D%0A%0A    public long duration(long elapsed, boolean success) %7B%0A      return 0
+boolean memberOfSet(String url) %7B%0A      return map.containsKey(url)
 ;%0A  
@@ -3089,45 +3089,25 @@
     
-PCachedUrlSet cus = new PCachedUrlSet
+CUS cus = new CUS
 ();%0A
@@ -3129,34 +3129,26 @@
 chedUrl(new 
-PCachedUrl
+CU
 (%22http://foo
@@ -3237,18 +3237,10 @@
 new 
-PCachedUrl
+CU
 (%22ht
@@ -3401,12 +3401,10 @@
 us;%0A  %7D%0A
-%0A%0A
 %7D%0A

Use NullPlugin