Project

General

Profile

« Previous | Next » 

Revision 6790

query for deleted metadata when testing that replication communicated the deletion. to check data, we try to update the data object on the target node (which should fail)

View differences:

test/edu/ucsb/nceas/MCTestCase.java
181 181
			+ "  </instrument>                                                    "
182 182
			+ "</inline>                                                          ";
183 183

  
184
    
185
    /**
186
     * Returns an xml squery that searches for the doc id in the
187
     * title of documents. This function is for eml-2.0.1+ only. For 
188
     * other eml versions, this function might have to modified.
189
     */
190
    protected String getTestEmlQuery(String titlePart, String emlVersion) {
191

  
192
    	String docType;
193
    	if (emlVersion.equals(EML2_0_1)) {
194
    		docType = "eml://ecoinformatics.org/eml-2.0.1";
195
    	} else if (emlVersion.equals(EML2_1_0)) {
196
    		docType = "eml://ecoinformatics.org/eml-2.1.0";
197
    	} else { //if (emlVersion.equals(EML2_1_1)) {
198
    		docType = "eml://ecoinformatics.org/eml-2.1.1";
199
    	}
200
    	
201
        String sQuery = "";
202
        sQuery = 
203
        	"<pathquery version=\"1.0\">" +
204
        		"<meta_file_id>unspecified</meta_file_id>" +
205
        		"<querytitle>unspecified</querytitle>" + 
206
        		"<returnfield>dataset/title</returnfield>" +
207
        		"<returndoctype>" + docType + "</returndoctype>" +
208
        		"<querygroup operator=\"UNION\">" +
209
        			"<queryterm casesensitive=\"false\" searchmode=\"contains\">" +
210
        				"<value>" + titlePart + "</value>" +
211
        				"<pathexpr>dataset/title</pathexpr>" +
212
        			"</queryterm>" +
213
        		"</querygroup>" +
214
        	"</pathquery>";
215

  
216
        return sQuery;
217
    }
218
	
219
	/**
220
     * Query a document by looking for a part of the title in the title element.
221
     * Then check if the testTitle exists in the doc.
222
     * @param titlePart the part of the title of the doc to look for
223
     * @param testTitle the title containing special characters
224
     * @param result are we expecting SUCCESS or FAILURE
225
     * @param expextedKarmaFailure
226
     */
227
    protected void queryDocWhichHasTitle(String titlePart, String testTitle,
228
                                         String emlVersion, boolean result) {
229
        try {
230
            String sQuery = getTestEmlQuery(titlePart, emlVersion);
231
        	Reader queryReader = new StringReader(sQuery);
232
            Reader resultReader = m.query(queryReader);
233
            String queryResult = IOUtil.getAsString(resultReader, true);
234
            if (result) {
235
                if (!queryResult.contains(testTitle)) {
236
                    debug("queryResult: " + queryResult);
237
                    debug("does not contain title: " + testTitle);
238
                }
239

  
240
                assertTrue(queryResult.contains(testTitle));
241
            }
242
            else {
243
                assertTrue(queryResult.indexOf("<error>") != -1);
244
            }
245
        }
246
        catch (MetacatInaccessibleException mie) {
247
            fail("Metacat Inaccessible:\n" + mie.getMessage());
248
        }
249
        catch (Exception e) {
250
            fail("General exception:\n" + e.getMessage());
251
        }
252

  
253
    }
254
	
184 255
	/*
185 256
	 * Retrus an access block base on params passed and the defaul perm order -
186 257
	 * allow first
test/edu/ucsb/nceas/metacat/replication/ReplicationTest.java
26 26
package edu.ucsb.nceas.metacat.replication;
27 27

  
28 28
import java.io.InputStream;
29
import java.io.Reader;
29 30
import java.io.StringReader;
30 31
import java.net.URL;
31 32

  
......
185 186
    		// wait for replication (forced)
186 187
    		Thread.sleep(forceReplicationSleep);
187 188
    		
188
    		// check that it is missing
189
			replicatedObject = null;
189
    		// TODO: check that it is missing
190
    		// update should fail since it is "archived"
191
    		docid = baseDocid + "." + 3;
192
    		object = "test3";
190 193
    		try {
191
        		is = targetMetacat.read(docid);
192
    			replicatedObject = IOUtils.toString(is, MetaCatServlet.DEFAULT_ENCODING);
193
    		} catch (DocumentNotFoundException dnfe) {
194
    			// expect this
194
    			targetMetacat.upload(docid, "testObject", IOUtils.toInputStream(object, MetaCatServlet.DEFAULT_ENCODING), object.getBytes(MetaCatServlet.DEFAULT_ENCODING).length);
195
    		} catch (Exception e) {
196
				// should fail
195 197
    			assertTrue(true);
196
    		}
197
    		assertNull(replicatedObject);
198
    			return;
199
			}
200
    		// if we get here, he have failed
201
    		fail("Should not have been able to update archived data");
198 202
    		
199 203
			
200 204
    	} catch (Exception e) {
......
293 297
    		// wait for replication (forced)
294 298
    		Thread.sleep(forceReplicationSleep);
295 299
    		
296
    		// check that it is missing
297
			replicatedObject = null;
298
    		try {
299
        		is = targetMetacat.read(docid);
300
    			replicatedObject = IOUtils.toString(is, MetaCatServlet.DEFAULT_ENCODING);
301
    		} catch (DocumentNotFoundException dnfe) {
302
    			// expect this
303
    			assertTrue(true);
304
    		}
305
    		assertNull(replicatedObject);
300
			// query for the docid -- should not be returned since it is archived
301
			String queryString = getTestEmlQuery(docid, EML2_1_0);
302
			Reader xmlQuery = new StringReader(queryString);
303
			Reader resultReader = targetMetacat.query(xmlQuery);
304
			String results = IOUtils.toString(resultReader);
305
			assertFalse(results.contains(docid));
306 306
			
307 307
    	} catch (Exception e) {
308 308
    		e.printStackTrace();
test/edu/ucsb/nceas/metacattest/NonAsciiCharacterTest.java
161 161
        return accessBlock;
162 162

  
163 163
    }
164
    
165
    /**
166
     * Returns an xml squery that searches for the doc id in the
167
     * title of documents. This function is for eml-2.0.1+ only. For 
168
     * other eml versions, this function might have to modified.
169
     */
170
    private String getTestEmlQuery(String titlePart, String emlVersion) {
171 164

  
172
    	String docType;
173
    	if (emlVersion.equals(EML2_0_1)) {
174
    		docType = "eml://ecoinformatics.org/eml-2.0.1";
175
    	} else if (emlVersion.equals(EML2_1_0)) {
176
    		docType = "eml://ecoinformatics.org/eml-2.1.0";
177
    	} else { //if (emlVersion.equals(EML2_1_1)) {
178
    		docType = "eml://ecoinformatics.org/eml-2.1.1";
179
    	}
180
    	
181
        String sQuery = "";
182
        sQuery = 
183
        	"<pathquery version=\"1.0\">" +
184
        		"<meta_file_id>unspecified</meta_file_id>" +
185
        		"<querytitle>unspecified</querytitle>" + 
186
        		"<returnfield>dataset/title</returnfield>" +
187
        		"<returndoctype>" + docType + "</returndoctype>" +
188
        		"<querygroup operator=\"UNION\">" +
189
        			"<queryterm casesensitive=\"false\" searchmode=\"contains\">" +
190
        				"<value>" + titlePart + "</value>" +
191
        				"<pathexpr>dataset/title</pathexpr>" +
192
        			"</queryterm>" +
193
        		"</querygroup>" +
194
        	"</pathquery>";
195

  
196
        return sQuery;
197
    }
198

  
199 165
    /**
200 166
     * Constructor to build the test
201 167
     *
......
847 813
        }
848 814

  
849 815
    }
850
    
851
    /**
852
     * Query a document by looking for a part of the title in the title element.
853
     * Then check if the testTitle exists in the doc.
854
     * @param titlePart the part of the title of the doc to look for
855
     * @param testTitle the title containing special characters
856
     * @param result are we expecting SUCCESS or FAILURE
857
     * @param expextedKarmaFailure
858
     */
859
    private void queryDocWhichHasTitle(String titlePart, String testTitle,
860
                                         String emlVersion, boolean result) {
861
        try {
862
            String sQuery = getTestEmlQuery(titlePart, emlVersion);
863
        	Reader queryReader = new StringReader(sQuery);
864
            Reader resultReader = m.query(queryReader);
865
            String queryResult = IOUtil.getAsString(resultReader, true);
866
            if (result) {
867
                if (!queryResult.contains(testTitle)) {
868
                    debug("queryResult: " + queryResult);
869
                    debug("does not contain title: " + testTitle);
870
                }
871 816

  
872
                assertTrue(queryResult.contains(testTitle));
873
            }
874
            else {
875
                assertTrue(queryResult.indexOf("<error>") != -1);
876
            }
877
        }
878
        catch (MetacatInaccessibleException mie) {
879
            fail("Metacat Inaccessible:\n" + mie.getMessage());
880
        }
881
        catch (Exception e) {
882
            fail("General exception:\n" + e.getMessage());
883
        }
884

  
885
    }
886

  
887 817
    /**
888 818
     * Create a hopefully unique docid for testing insert and update. Does
889 819
     * not include the 'revision' part of the id.

Also available in: Unified diff