Project

General

Profile

« Previous | Next » 

Revision 5946

Added by Jing Tao almost 14 years ago

Add a method to test download a schema with included schemas.

View differences:

test/edu/ucsb/nceas/metacattest/SchemaRegistryTest.java
80 80
	private static String goodSchemaXMLFile = "good-schema.xml";
81 81
	private static String goodSchemaFile1 = "chapter05ord.xsd";
82 82
	private static String goodSchemaFile2 = "chapter05prod.xsd";
83
	private static String includedSchemaXMLFile = "company.xml";
84
	private static String includedSchemaFile1="company.xsd";
85
	private static String includedSchemaFile2="worker.xsd";
86
	private static String includedSchemaFile3="item.xsd";
87
	private static String includedSchemaFile4="product.xsd";
83 88
	
89
	
84 90
	private static String getRegisteredTestSchemaSql =
85 91
		"SELECT * FROM xml_catalog " + 
86 92
		"WHERE entry_type = 'Schema' " + 
......
90 96
		"DELETE FROM xml_catalog " + 
91 97
		"WHERE entry_type = 'Schema' " + 
92 98
		"AND system_id LIKE '%chapter05%'";	
99
	
100
	private static String getRegisteredIncludedTestSchemaSql =
101
    "SELECT * FROM xml_catalog " + 
102
    "WHERE entry_type = 'Schema' " + 
103
    "AND system_id LIKE '%company%'";
104
  
105
  private static String deleteRegisteredIncludedTestSchemaSql =
106
    "DELETE FROM xml_catalog " + 
107
    "WHERE entry_type = 'Schema' " + 
108
    "AND system_id LIKE '%company%'"; 
93 109

  
94 110
	private Metacat m;
95 111

  
......
139 155
		suite.addTest(new SchemaRegistryTest("newGoodSchemaBadXmlRegisterTest"));
140 156
		suite.addTest(new SchemaRegistryTest("existingGoodSchemaBadXmlRegisterTest"));
141 157
		suite.addTest(new SchemaRegistryTest("schemaInDbNotOnFileSystemTest"));
142

  
158
		suite.addTest(new SchemaRegistryTest("includedSchemaRegisterTest"));
143 159
		return suite;
144 160
	}
145 161

  
......
633 649
	}
634 650
	
635 651
	/**
652
   * Tests adding a document that has a new valid schema and the xml conforms to the 
653
   * schema. The schema has included schemas. We expect one entry will be added to
654
   * the db. But four schema files will be downloaded (four schemas share the same 
655
   * target namespace).
656
   */
657
  public void includedSchemaRegisterTest() {
658
    try {
659
      debug("\nRunning: newGoodSchemaRegisterTest");
660

  
661
      String newdocid = generateDocid();
662
      
663
      debug("Refreshing the XMLSchemaService");
664
      httpPost(metacatUrl + "?action=refreshServices",
665
          new HashMap<String, String>());
666

  
667
      String testDocument = getTestDocument(testFileLocation + includedSchemaXMLFile);
668
      
669
      // login
670
      debug("logging in as: username=" + username + " password=" + password);
671
      m.login(username, password);
672
      
673
      // insert document.  We expect to succeed.
674
      insertDocid(newdocid + ".1", testDocument, SUCCESS, false);
675
      
676
      debug("Checking db for registered schemas");
677
      Vector<Hashtable<String,Object>> sqlResults = 
678
        dbSelect(getRegisteredIncludedTestSchemaSql, 
679
            "SchemaRegistryTest.includedSchemaRegisterTest");
680
      if (sqlResults.size() != 1) {
681
        fail("Expected number of test schemas in the database is 1." +
682
            " The number found was: " + sqlResults.size());
683
      }
684
      deleteDocid(newdocid + ".1", SUCCESS, false);
685
      debug("Checking server for registered schema file: " + serverSchemaLocation + includedSchemaFile1);
686
      if( FileUtil.getFileStatus(serverSchemaLocation + includedSchemaFile1) < 
687
          FileUtil.EXISTS_READABLE) {
688
        fail("Could not find expected schema file on server: " + 
689
            serverSchemaLocation + includedSchemaFile1);
690
      }
691

  
692
      debug("Checking server for registered schema file: " + serverSchemaLocation + includedSchemaFile2);
693
      if( FileUtil.getFileStatus(serverSchemaLocation + includedSchemaFile2) < 
694
          FileUtil.EXISTS_READABLE) {
695
        fail("Could not find expected schema file on server: " + 
696
            serverSchemaLocation + includedSchemaFile2);
697
      }
698
      
699
      debug("Checking server for registered schema file: " + serverSchemaLocation + includedSchemaFile3);
700
      if( FileUtil.getFileStatus(serverSchemaLocation + includedSchemaFile3) < 
701
          FileUtil.EXISTS_READABLE) {
702
        fail("Could not find expected schema file on server: " + 
703
            serverSchemaLocation + includedSchemaFile3);
704
      }
705
      
706
      debug("Checking server for registered schema file: " + serverSchemaLocation + includedSchemaFile4);
707
      if( FileUtil.getFileStatus(serverSchemaLocation + includedSchemaFile4) < 
708
          FileUtil.EXISTS_READABLE) {
709
        fail("Could not find expected schema file on server: " + 
710
            serverSchemaLocation + includedSchemaFile4);
711
      }
712
      
713
      String newdocid2 = generateDocid();
714
      //insert document.  We expect to succeed.
715
      insertDocid(newdocid2 + ".1", testDocument, SUCCESS, false);
716
      String newdocid3 = generateDocid();
717
      // insert document.  We expect to succeed.
718
      insertDocid(newdocid3 + ".1", testDocument, SUCCESS, false);
719
      
720
      
721
      deleteDocid(newdocid2 + ".1", SUCCESS, false);
722
      deleteDocid(newdocid3 + ".1", SUCCESS, false);
723
      m.logout();
724
      
725
      // Clean the system up
726
      debug("Deleting test schemas from db");
727
      dbUpdate(deleteRegisteredIncludedTestSchemaSql,
728
          "SchemaRegistryTest.includedSchemaRegisterTest");
729
      
730
      debug("Deleting test schema files from server file system");
731
      FileUtil.deleteFile(serverSchemaLocation + includedSchemaFile1);
732
      FileUtil.deleteFile(serverSchemaLocation + includedSchemaFile2);
733
      FileUtil.deleteFile(serverSchemaLocation + includedSchemaFile3);
734
      FileUtil.deleteFile(serverSchemaLocation + includedSchemaFile4);
735
      
736
      debug("Refreshing the XMLSchemaService");
737
      httpPost(metacatUrl + "?action=refreshServices",
738
          new HashMap<String, String>());
739
      
740
    
741

  
742
    } catch (MetacatAuthException mae) {
743
      fail("Authorization failed: " + mae.getMessage());
744
    } catch (MetacatInaccessibleException mie) {
745
      fail("Metacat Inaccessible: " + mie.getMessage());
746
    } catch (IOException ioe) {
747
      fail("I/O Exception: " + ioe.getMessage());
748
    } catch (SQLException sqle) {
749
      fail("SQL Exception: " + sqle.getMessage());
750
    } catch (Exception e) {
751
      fail("General exception: " + e.getMessage());
752
    }
753
  }
754
	
755
	/**
636 756
	 * @param documentLocation
637 757
	 *            the path of the document to read.
638 758
	 * @return a string holding the contents of the document with the contextUrl

Also available in: Unified diff