<commit_before>package org.collectionspace.chain.csp.persistence.services.vocab;

import static org.junit.Assert.*;

import java.io.InputStream;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.collectionspace.bconfigutils.bootstrap.BootstrapConfigLoadFailedException;
import org.collectionspace.chain.csp.persistence.services.ServicesBaseClass;
import org.collectionspace.chain.csp.persistence.services.connection.ConnectionException;
import org.collectionspace.csp.api.persistence.ExistException;
import org.collectionspace.csp.api.persistence.Storage;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TestVocab extends ServicesBaseClass {
	private static final Logger log=LoggerFactory.getLogger(TestVocab.class);
	private static Pattern vocab_urn=Pattern.compile("urn:cspace:org.collectionspace.demo:vocabulary\\((.*?)\\):item\\((.*?)\\)'(.*?)'");
		
	private InputStream getRootSource(String file) {
		return Thread.currentThread().getContextClassLoader().getResourceAsStream(file);
	}
	
	@Before public void checkServicesRunning() throws BootstrapConfigLoadFailedException, ConnectionException {
		setup();
	}
	
	@Test public void testAuthorities() throws Exception {
		Storage ss=makeServicesStorage(base+"/cspace-services/");
		testAllAuthorities(ss,"/person/person","displayName");
		testAllAuthorities(ss,"/vocab/xxx","name");
		testAllAuthorities(ss,"/organization/organization","displayName");
		//testAllAuthorities(ss,"/place/place","displayName");
	}
	
	private void testAllAuthorities(Storage ss, String path, String testField) throws Exception {
		// Create
		JSONObject data=new JSONObject();
		data.put(testField,"TEST");
		//XXX why has staus disappeared?
		//data.put("status","Provisional");
		String id=ss.autocreateJSON(path,data);
		// Read
		JSONObject out=ss.retrieveJSON(path+"/"+id);
		log.info(out.toString());
		assertEquals("TEST",out.getString(testField));
		//assertEquals("Provisional",out.getString("status"));
		// Update
		data.remove(testField);
		data.put(testField,"TEST2");
		//data.put("status","Provisional2");
		ss.updateJSON(path + "/"+id,data);
		out=ss.retrieveJSON(path + "/"+id);
		assertEquals("TEST2",out.getString(testField));
		//assertEquals("Provisional2",out.getString("status"));
		String id3=out.getString("csid");
		// List
		data.remove(testField);
		data.put(testField,"TEST3");
		String id2=ss.autocreateJSON(path,data);
		out=ss.retrieveJSON(path + "/"+id2);
		assertEquals("TEST3",out.getString(testField));		
		boolean found1=false,found2=false;
		JSONObject myjs = new JSONObject();
		myjs.put("pageSize", "100");
		myjs.put("pageNum", "0");
		int resultsize=1;
		int check = 0;
		String checkpagination = "";
		while(resultsize >0){
			myjs.put("pageNum", check);
			check++;
			JSONObject items = ss.getPathsJSON(path,myjs);

			String[] rest = ss.getPaths(path,myjs);
			log.info("WWW");
			log.info(items.toString());
			//log.info(rest.);
			String[] res = (String[])items.get("listItems");

			if(res.length==0 || checkpagination.equals(res[0])){
				resultsize=0;
				//testing whether we have actually returned the same page or the next page - all csid returned should be unique
			}
			else{
				checkpagination = res[0];
			}
			resultsize=res.length;<commit_msg>nojira - test fixes<commit_after>package org.collectionspace.chain.csp.persistence.services.vocab;

import static org.junit.Assert.*;

import java.io.InputStream;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.collectionspace.bconfigutils.bootstrap.BootstrapConfigLoadFailedException;
import org.collectionspace.chain.csp.persistence.services.ServicesBaseClass;
import org.collectionspace.chain.csp.persistence.services.connection.ConnectionException;
import org.collectionspace.csp.api.persistence.ExistException;
import org.collectionspace.csp.api.persistence.Storage;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TestVocab extends ServicesBaseClass {
	private static final Logger log=LoggerFactory.getLogger(TestVocab.class);
	private static Pattern vocab_urn=Pattern.compile("urn:cspace:org.collectionspace.demo:vocabulary\\((.*?)\\):item\\((.*?)\\)'(.*?)'");
		
	private InputStream getRootSource(String file) {
		return Thread.currentThread().getContextClassLoader().getResourceAsStream(file);
	}
	
	@Before public void checkServicesRunning() throws BootstrapConfigLoadFailedException, ConnectionException {
		setup();
	}
	
	@Test public void testAuthorities() throws Exception {
		Storage ss=makeServicesStorage(base+"/cspace-services/");
		testAllAuthorities(ss,"/person/person","displayName");
		testAllAuthorities(ss,"/vocab/xxx","name");
		testAllAuthorities(ss,"/organization/organization","displayName");
		//testAllAuthorities(ss,"/place/place","displayName");
	}
	
	private void testAllAuthorities(Storage ss, String path, String testField) throws Exception {
		// Create
		JSONObject data=new JSONObject();
		data.put(testField,"TEST");
		//XXX why has staus disappeared?
		//data.put("status","Provisional");
		String id=ss.autocreateJSON(path,data);
		// Read
		JSONObject out=ss.retrieveJSON(path+"/"+id);
		log.info(out.toString());
		assertEquals("TEST",out.getString(testField));
		//assertEquals("Provisional",out.getString("status"));
		// Update
		data.remove(testField);
		data.put(testField,"TEST2");
		//data.put("status","Provisional2");
		ss.updateJSON(path + "/"+id,data);
		out=ss.retrieveJSON(path + "/"+id);
		assertEquals("TEST2",out.getString(testField));
		//assertEquals("Provisional2",out.getString("status"));
		String id3=out.getString("csid");
		// List
		data.remove(testField);
		data.put(testField,"TEST3");
		String id2=ss.autocreateJSON(path,data);
		out=ss.retrieveJSON(path + "/"+id2);
		assertEquals("TEST3",out.getString(testField));		
		boolean found1=false,found2=false;
		JSONObject myjs = new JSONObject();
		myjs.put("pageSize", "100");
		myjs.put("pageNum", "0");
		int resultsize=1;
		int check = 0;
		String checkpagination = "";
		while(resultsize >0){
			myjs.put("pageNum", check);
			check++;
			JSONObject items = ss.getPathsJSON(path,myjs);

			String[] res = (String[])items.get("listItems");

			if(res.length==0 || checkpagination.equals(res[0])){
				resultsize=0;
				//testing whether we have actually returned the same page or the next page - all csid returned should be unique
			}
			else{
				checkpagination = res[0];
			}
			resultsize=res.length;
{'fraction_non_alphanumeric': 0.1527190332326284, 'fraction_numerical': 0.0072507552870090634, 'mean_word_length': 5.594621513944223, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3442087', 'n_tokens_mistral': 2238, 'n_tokens_neox': 2080, 'n_words': 355}