package org.collectionspace.chain.csp.persistence.services.vocab;

import static org.junit.Assert.*;

import org.collectionspace.chain.csp.persistence.TestBase;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.AfterClass;
import org.junit.Test;
import org.mortbay.jetty.testing.HttpTester;
import org.mortbay.jetty.testing.ServletTester;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TestGenerateAuthorities {
	private static final Logger log = LoggerFactory
	.getLogger(TestGenerateAuthorities.class);
	private static TestBase tester = new TestBase();
	static ServletTester jetty;
	static {
		try{
			jetty=tester.setupJetty();
			}
		catch(Exception ex){
			
		}
	}
	
	@AfterClass public static  void testStop() throws Exception {
		tester.stopJetty(jetty);
	}
	

	
	@Test
	public void testSetUp() throws Exception {
		HttpTester out;
		log.info("initialize authorities");

		//String urltest = "/vocabularies/currency/refresh?datapath=/Users/csm22/Documents/collectionspace/test.txt";
		//out = tester.GETData(urltest, jetty);

		
		// repopulate the authorities with dummy data
		//DONOT RUN THIS TEST LOCALLY 
		out = tester.GETData("/reset/", jetty);
		

		//do we have any records
		out = tester.GETData("/authorities/organization/?pageSize=1", jetty);
		JSONArray results = new JSONObject(out.getContent()).getJSONArray("items");
		assertTrue(results.length() > 0);
		

		//do we have any records
		out = tester.GETData("/authorities/person/?pageSize=1", jetty);
		JSONArray results2 = new JSONObject(out.getContent()).getJSONArray("items");
		assertTrue(results2.length() > 0);

		//make sure all the vocabs are initialized
		out = tester.GETData("/authorities/vocab/initialize", jetty);
		// update and remove fields not in each list within an authority
		// /chain/vocabularies/person/initialize?datapath=/Users/csm22/Documents/collectionspace/svcapp/cspi-webui/src/main/resources/org/collectionspace/chain/csp/webui/misc/names.txt

	}
	
	
	
}

@@ -1625,24 +1625,235 @@
 th() %3E 0);%0A%0A
+%09%09//do we have any records%0A%09%09out = tester.GETData(%22/authorities/concept/?pageSize=1%22, jetty);%0A%09%09JSONArray results3 = new JSONObject(out.getContent()).getJSONArray(%22items%22);%0A%09%09assertTrue(results3.length() %3E 0);%0A%0A
 %09%09//make sur

Add authorities generate test.