Project

General

Profile

« Previous | Next » 

Revision 9954

Added by Jing Tao about 8 years ago

Add the code to handle the exception which is throwed when the local schema can't be found for a given namespace or format id.

View differences:

test/edu/ucsb/nceas/metacattest/service/XMLSchemaServiceTest.java
1 1
package edu.ucsb.nceas.metacattest.service;
2 2

  
3 3
import org.apache.commons.io.FileUtils;
4

  
4 5
import edu.ucsb.nceas.MCTestCase;
6
import edu.ucsb.nceas.metacat.client.MetacatException;
5 7
import edu.ucsb.nceas.metacat.service.XMLSchemaParser;
6 8
import edu.ucsb.nceas.metacat.service.XMLSchemaService;
7 9

  
......
115 117
  public void testFindNamespaceAndSchemaLocalLocation() throws Exception {
116 118
      String formatId = null;
117 119
      String namespace = null;
118
      String location = XMLSchemaService.getInstance().findNamespaceAndSchemaLocalLocation(formatId, namespace);
119
      assertTrue(location == null);
120
      
120
      String location = null;
121
      try {
122
          location = XMLSchemaService.getInstance().findNamespaceAndSchemaLocalLocation(formatId, namespace);
123
          fail("we can't get here. The above line should throw an exception.");
124
      } catch (MetacatException e) {
125
          assertTrue(e.getMessage().contains("not registered in the Metacat"));
126
      }
127

  
121 128
      //registered formatid
122 129
      formatId = "http://www.isotc211.org/2005/gmd-noaa";
123 130
      namespace = null;
......
142 149
      location = XMLSchemaService.getInstance().findNamespaceAndSchemaLocalLocation(formatId, namespace);
143 150
      assertTrue(location.contains("/schema/isotc211/gco/gco.xsd"));
144 151
      
152
      formatId = "http://foo.com";
153
      namespace = "http://foo.com";
154
      try {
155
          location = XMLSchemaService.getInstance().findNamespaceAndSchemaLocalLocation(formatId, namespace);
156
          fail("we can't get here. The above line should throw an exception.");
157
      } catch (MetacatException e) {
158
          assertTrue(e.getMessage().contains("not registered in the Metacat"));
159
      }
145 160
  }
146 161
  
147 162
  public void testFindNoNamespaceSchemaLocalLocation() throws Exception {
148 163
      String formatId = null;
149 164
      String nonamespaceURI = null;
150
      String location = XMLSchemaService.getInstance().findNoNamespaceSchemaLocalLocation(formatId, nonamespaceURI);
165
      String location = null;
166
      try {
167
          location = XMLSchemaService.getInstance().findNoNamespaceSchemaLocalLocation(formatId, nonamespaceURI);
168
          fail("we can't get here. The above line should throw an exception.");
169
      } catch (MetacatException e) {
170
          assertTrue(e.getMessage().contains("not registered in the Metacat"));
171
      }
172
              
151 173
      assertTrue(location == null);
152 174
      
153 175
      formatId = "FGDC-STD-001-1998";
......
181 203
      location = XMLSchemaService.getInstance().findNoNamespaceSchemaLocalLocation(formatId, nonamespaceURI);
182 204
      assertTrue(location.contains("/schema/fgdc-std-001-1998/fgdc-std-001-1998.xsd"));
183 205
      
184
      formatId = "FGDC-STD-001";
185
      nonamespaceURI = "https://www.fgdc.gov/metadata-std-001-1998.xsd";
186
      location = XMLSchemaService.getInstance().findNoNamespaceSchemaLocalLocation(formatId, nonamespaceURI);
187
      assertTrue(location == null);
206
      formatId = "foo-001";
207
      nonamespaceURI = "https://www.fgdc.gov/foo";
208
      try {
209
          location = XMLSchemaService.getInstance().findNoNamespaceSchemaLocalLocation(formatId, nonamespaceURI);
210
          fail("we can't get here. The above line should throw an exception.");
211
      } catch (MetacatException e) {
212
          assertTrue(e.getMessage().contains("not registered in the Metacat"));
213
      }
188 214
  }
189 215
  
190 216
  public void testIsNamespaceRegistered() throws Exception {

Also available in: Unified diff