Project

General

Profile

« Previous | Next » 

Revision 3172

Added by Jing Tao about 17 years ago

Add new method to keep inserting spatial data.

View differences:

MetacatClientTest.java
36 36
import java.util.SimpleTimeZone;
37 37
import java.util.TimeZone;
38 38

  
39
import edu.ucsb.nceas.metacat.DocumentImpl;
40
import edu.ucsb.nceas.metacat.client.DocumentNotFoundException;
39 41
import edu.ucsb.nceas.metacat.client.InsufficientKarmaException;
40 42
import edu.ucsb.nceas.metacat.client.Metacat;
41 43
import edu.ucsb.nceas.metacat.client.MetacatAuthException;
......
48 50
import junit.framework.TestSuite;
49 51
import java.io.FileInputStream;
50 52

  
53
import org.apache.log4j.Logger;
54

  
51 55
/**
52 56
 * A JUnit test for testing Step class processing
53 57
 */
......
68 72
    private String queryFile = "test/query.xml";
69 73
    private String testdocument = "";
70 74
    private Metacat m;
71

  
75
    private String spatialTestFile = "test/spatialEml.xml";
76
    private static final int TIME = 30;
77
    
72 78
    /**
73 79
     * Constructor to build the test
74 80
     *
......
133 139
      suite.addTest(new MetacatClientTest("inaccessibleMetacat"));
134 140
      suite.addTest(new MetacatClientTest("reuseSession"));
135 141
      suite.addTest(new MetacatClientTest("reuseInvalidSession"));
142
      //suite.addTest(new MetacatClientTest("insertSpatialDocs"));
136 143
      return suite;
137 144
  }
138 145

  
......
253 260
            assertTrue(1 == 1);
254 261
        } catch (MetacatException e) {
255 262
            fail("Metacat exception:\n" + e.getMessage());
256
        } catch (Exception ioe) {
257
            fail("Exception:\n" + ioe.getMessage());
263
        } catch (IOException ioe) {
264
            fail("IO exception:\n" + ioe.getMessage());
265
        } catch (DocumentNotFoundException ne) {
266
            fail("DocumentNotFound exception:\n" + ne.getMessage());
267

  
258 268
        }
259 269
    }
260 270

  
......
640 650
           fail("General exception:\n" + e.getMessage());
641 651
       }
642 652
   }
653
   
654
   /**
655
    * Try to insert a bunch of eml documents which contain spatial information
656
    * This test is used to try to find a bug in spatial part of metacat
657
    */
658
    public void insertSpatialDocs() throws IOException
659
    {
660
    	FileReader fr = new FileReader(spatialTestFile);
661
        String spatialtestdocument = IOUtil.getAsString(fr, true);
662
        System.out.println("the eml is "+spatialtestdocument);
663
    	for (int i=0; i<TIME; i++)
664
    	{
665
	    	try {
666
	    		newdocid = generateDocid();
667
	            String identifier = newdocid + ".1";
668
	            System.out.println("the docid is "+identifier);
669
	            m.login(username, password);
670
	            String response = m.insert(identifier,
671
	                    new StringReader(spatialtestdocument), null);
672
	            assertTrue(response.indexOf("<success>") != -1);
673
	            assertTrue(response.indexOf(identifier) != -1);
674
	            Thread.sleep(8000);
675
	            identifier = newdocid +".2";
676
	            response = m.update(identifier,
677
	                    new StringReader(spatialtestdocument), null);
678
	            assertTrue(response.indexOf("<success>") != -1);
679
	            //System.err.println(response);
680
	
681
	        } catch (MetacatAuthException mae) {
682
	            fail("Authorization failed:\n" + mae.getMessage());
683
	        } catch (MetacatInaccessibleException mie) {
684
	            fail("Metacat Inaccessible:\n" + mie.getMessage());
685
	        } catch (InsufficientKarmaException ike) {
686
	            assertTrue(1 == 1);
687
	            fail("Insufficient karma:\n" + ike.getMessage());
688
	        } catch (MetacatException me) {
689
	            fail("Metacat Error:\n" + me.getMessage());
690
	        } catch (Exception e) {
691
	            fail("General exception:\n" + e.getMessage());
692
	        }
693
    	}
694
    }
643 695
    
644 696
    /**
645 697
     * Create a hopefully unique docid for testing insert and update. Does

Also available in: Unified diff