Project

General

Profile

« Previous | Next » 

Revision 8709

include code to generate random annotations for UI testing. Effective, but can be confusing to see so many unrelated concepts on duplicate EML packages.

View differences:

test/edu/ucsb/nceas/metacat/annotation/DatapackageSummarizerTest.java
64 64
	public static Test suite() {
65 65
		TestSuite suite = new TestSuite();
66 66
		suite.addTest(new DatapackageSummarizerTest("testGenerateAnnotation"));
67
//		suite.addTest(new DatapackageSummarizerTest("testGenerateRandomAnnotation"));
67 68
		return suite;
68 69
	}
70
	
71
	/**
72
	 * Generate a single annotation based exclusively on the metadata
73
	 * @throws Exception
74
	 */
75
	public void testGenerateAnnotation() throws Exception {
76
		this.testGenerateAnnotation_base(false);
77
	}
78
	
79
	/**
80
	 * Generate a bunch of random annotations
81
	 * @throws Exception
82
	 */
83
	public void testGenerateRandomAnnotation() throws Exception {
84
		for (int i = 0; i < 5; i++) {
85
			this.testGenerateAnnotation_base(true);
86
		}
87
	}
69 88

  
70
	public void testGenerateAnnotation() throws Exception {
89
	private void testGenerateAnnotation_base(boolean randomize) throws Exception {
71 90
		Identifier metadataPid = new Identifier();
72 91
		metadataPid.setValue("testAnnotation.eml." + System.currentTimeMillis());
73 92
		Session session = getTestSession();
......
86 105

  
87 106
		// generate the annotation for the metadata
88 107
		DatapackageSummarizer ds = new DatapackageSummarizer();
108
		ds.randomize = randomize;
89 109
		String rdfContent = ds.generateAnnotation(metadataPid);
90 110
		
91 111
		// save the annotation
src/edu/ucsb/nceas/metacat/annotation/DatapackageSummarizer.java
63 63
    public static String prov = "http://www.w3.org/ns/prov#";
64 64
    public static String prov_source = "http://www.w3.org/ns/prov.owl";
65 65
    public static String cito =  "http://purl.org/spar/cito/";
66
    
67
    // package visibility for testing only
68
    boolean randomize = false;
66 69

  
67 70
    /**
68 71
     * Generate annotation for given metadata identifier
......
194 197
		String unit = attribute.getUnit().toLowerCase();
195 198
		boolean found = false;
196 199
		ExtendedIterator iter = standardClass.listSubClasses(false);
200
		if (randomize) {
201
			List subclasses = iter.toList();
202
			int size = subclasses.size();
203
			Long index = new Long(Math.round(Math.floor((Math.random() * (size-1)))));
204
			OntClass subclass = (OntClass) subclasses.get( index.intValue() );
205
			return subclass;
206
		}
197 207
		while (iter.hasNext()) {
198 208
			OntClass subclass = (OntClass) iter.next();
199 209
			String subclassName = subclass.getLocalName().toLowerCase();
......
217 227
		boolean found = false;
218 228
		// find something that matches
219 229
		ExtendedIterator iter = characteristicClass.listSubClasses();
230
		if (randomize) {
231
			List subclasses = iter.toList();
232
			int size = subclasses.size();
233
			Long index = new Long(Math.round(Math.floor((Math.random() * (size-1)))));
234
			OntClass subclass = (OntClass) subclasses.get( index.intValue() );
235
			return subclass;
236
		}
220 237
		while (iter.hasNext()) {
221 238
			OntClass subclass = (OntClass) iter.next();
222 239
			String subclassName = subclass.getLocalName().toLowerCase();

Also available in: Unified diff