Project

General

Profile

« Previous | Next » 

Revision 1104

Added by Jing Tao over 22 years ago

Add the test case to insert invalidate xml and non well-formed xml documents.

View differences:

junittests/edu/ucsb/nceas/metacatjunittests/MetaCatServletTest.java
86 86
   */
87 87
  public static Test suite()
88 88
  {
89
  
89
    double number = 0;
90
    String serial = null;
90 91
    
91 92
    
92 93
    TestSuite suite = new TestSuite();
93
    suite.addTest(new MetaCatServletTest("initialize"));
94
    /*suite.addTest(new MetaCatServletTest("initialize"));
94 95
    suite.addTest(new MetaCatServletTest("testLterReferralLogin"));
95 96
    suite.addTest(new MetaCatServletTest("testLterReferralLoginFail"));
96 97
    suite.addTest(new MetaCatServletTest("testPiscoReferralLogin"));
97 98
    suite.addTest(new MetaCatServletTest("testPiscoReferralLoginFail"));
98
    suite.addTest(new MetaCatServletTest("testNCEASLoginFail"));
99
    suite.addTest(new MetaCatServletTest("testNCEASLoginFail"));*/
99 100
    //Should put a login successfully at the end of login test
100 101
    //So insert or update can have cookie.
101 102
    suite.addTest(new MetaCatServletTest("testNCEASLogin"));
102 103
    
103 104
    //create random number for docid, so it can void repeat
104
    double number = Math.random()*10000;
105
    String serial = Integer.toString(((new Double(number)).intValue()));
105
    number = Math.random()*10000;
106
    serial = Integer.toString(((new Double(number)).intValue()));
106 107
    MetaCatUtil.debugMessage("serial: "+serial, 1);
107 108
    suite.addTest(new MetaCatServletTest("testInsertXMLDocument", serial));
108 109
    suite.addTest(new MetaCatServletTest("testReadXMLDocumentXMLFormat", 
......
115 116
    suite.addTest(new MetaCatServletTest("testUpdateXMLDocument",serial));
116 117
    suite.addTest(new MetaCatServletTest("testDeleteXMLDocument",serial));
117 118
    
118
    suite.addTest(new MetaCatServletTest("testLogOut"));
119
                                                        
120
                         
119
    //insert invalid xml document
120
    number = Math.random()*10000;
121
    serial = Integer.toString(((new Double(number)).intValue()));
122
    suite.addTest(new MetaCatServletTest("testInsertInvalidateXMLDocument",
123
                                                                  serial));    
124
    //insert non well formed document
125
    number = Math.random()*10000;
126
    serial = Integer.toString(((new Double(number)).intValue())); 
127
    suite.addTest(new MetaCatServletTest("testInsertNonWellFormedXMLDocument",
128
                                                            serial));                                               
129
    suite.addTest(new MetaCatServletTest("testLogOut"));                   
121 130
                              
122 131
    return suite;
123 132
  }
......
227 236
   
228 237
  }
229 238
  
239
  /**
240
   * Test insert a invalidate xml document successfully
241
   * In the String, there is no <!Doctype ... Public/System/>
242
   */
243
  public void testInsertInvalidateXMLDocument()
244
  {
245
    String name = "john"+MetaCatUtil.getOption("accNumSeparator")
246
                     +serialNumber+MetaCatUtil.getOption("accNumSeparator")+"1";
247
    MetaCatUtil.debugMessage("docid: "+name, 20);
248
    String content="<?xml version=\"1.0\"?>"
249
                   +"<acl authSystem=\"knb\" order=\"allowFirst\">"
250
                   +"<identifier>"+name+"</identifier>"
251
                   +"<allow>"
252
             +"<principal>uid=john,o=NCEAS,dc=ecoinformatics,dc=org</principal>"
253
                   +"<permission>all</permission>"
254
                   +"</allow>"
255
                   +"<allow>"
256
                   +"<principal>public</principal>"
257
                   +"<permission>read</permission>"
258
                   +"</allow>"
259
                   +"</acl>";
260
     MetaCatUtil.debugMessage("xml document: "+content, 55);
261
     assert(handleXMLDocument(content, name, "insert"));
262
  }
263
  
264
   /**
265
   * Test insert a non well-formed xml document successfully
266
   * There is no </acl> in this string
267
   */
268
  public void testInsertNonWellFormedXMLDocument()
269
  {
270
    String name = "john"+MetaCatUtil.getOption("accNumSeparator")
271
                     +serialNumber+MetaCatUtil.getOption("accNumSeparator")+"1";
272
    MetaCatUtil.debugMessage("docid: "+name, 20);
273
    String content="<?xml version=\"1.0\"?>"
274
                   +"<acl authSystem=\"knb\" order=\"allowFirst\">"
275
                   +"<identifier>"+name+"</identifier>"
276
                   +"<allow>"
277
             +"<principal>uid=john,o=NCEAS,dc=ecoinformatics,dc=org</principal>"
278
                   +"<permission>all</permission>"
279
                   +"</allow>"
280
                   +"<allow>"
281
                   +"<principal>public</principal>"
282
                   +"<permission>read</permission>"
283
                   +"</allow>";
284
  
285
     MetaCatUtil.debugMessage("xml document: "+content, 55);
286
     assert(!handleXMLDocument(content, name, "insert"));
287
  } 
230 288

  
231

  
232 289
  /**
233 290
   * Test read a xml document  in xml format successfully
234 291
   */
......
387 444
    
388 445
    message = getMetacatString(prop);
389 446
    message = message.trim();
390
    MetaCatUtil.debugMessage("Read Message: "+message, 30);
447
    //MetaCatUtil.debugMessage("Read Message: "+message, 30);
391 448
    if (message==null || message.equals("")||message.indexOf("<error>") != -1 )
392 449
    {//there was an error
393 450
      
......
469 526
    } 
470 527
  }
471 528
  
529
  
530
 
531
  
472 532
   public String getMetacatString(Properties prop)
473 533
  {
474 534
    String response = null;

Also available in: Unified diff