<commit_before>package org.sagebionetworks;

import static org.junit.Assert.*;
import static org.junit.Assert.assertNotNull;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.commons.codec.binary.Base64;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.web.client.ResponseErrorHandler;
import org.springframework.web.client.RestTemplate;

/**
 * Test that we can get profile data for a call.
 * @author jmhill
 *
 */
public class ITPerCallProfileTest {
	
	private static final String KEY_PROFILE_REQUEST = "profile_request";
	// The JSON object for the profile results
	public static final String KEY_PROFILE_RESPONSE_OBJECT = "profile_response_object";
	// The profile print string.
	public static final String KEY_PROFILE_RESPONSE_PRINT = "profile_response_print";
	
	// The template used for the tests
	private RestTemplate tempalte;
	String sessionToken;

	private Map<String, String> toDelete;
	/**
	 * @throws Exception
	 * 
	 */
	@Before
	public void before() throws Exception {
		tempalte = new RestTemplate();
		// Create a session token
		sessionToken = getNewSessionToken();
		toDelete = new HashMap<String, String>();
	}
	
	@After
	public void after(){
		if(tempalte != null && sessionToken != null && toDelete!= null){
			Iterator<String> it = toDelete.keySet().iterator();
			while(it.hasNext()){
				String id = it.next();
				String suffix = toDelete.get(id);
				deleteEntity(id, suffix);
			}
		}
	}
	
	@Test
	public void testPerCallProfileOn() throws JSONException, UnsupportedEncodingException{
		assertNotNull(sessionToken);
		// First get a token
		ResponseEntity<String> response = createProject("ITPerCallProfileTest.testPerCallProfileOn", true);
		// Now get the frame from the header
		System.out.println(response.getHeaders());
		List<String> list = response.getHeaders().get(KEY_PROFILE_RESPONSE_OBJECT);
		assertNotNull(list);
		assertEquals(1, list.size());
		String encoded = list.get(0);
		String decoded = new String(Base64.decodeBase64(encoded.getBytes("UTF-8")), "UTF-8");
		System.out.println("Results: "+decoded);
		JSONObject frame = new JSONObject(decoded);
		assertNotNull(frame.getLong("startTime"));
		assertNotNull(frame.getString("name"));
		assertNotNull(frame.getLong("elapse"));
		
	}

	@Test
	public void testPerCallProfileOff() throws JSONException, UnsupportedEncodingException{
		assertNotNull(sessionToken);
		ResponseEntity<String> response = createProject("ITPerCallProfileTest.testPerCallProfileOff", false);
		// Now get the frame from the header
		System.out.println(response.getHeaders());
		// The profile data should not be in the header when profiling if off.
		List<String> list = response.getHeaders().get(KEY_PROFILE_RESPONSE_OBJECT);
		assertTrue(list == null);
		
	}<commit_msg>Removing this test for now.<commit_after>package org.sagebionetworks;

import static org.junit.Assert.*;
import static org.junit.Assert.assertNotNull;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.commons.codec.binary.Base64;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.web.client.ResponseErrorHandler;
import org.springframework.web.client.RestTemplate;

/**
 * Test that we can get profile data for a call.
 * @author jmhill
 *
 */
public class ITPerCallProfileTest {
	
	private static final String KEY_PROFILE_REQUEST = "profile_request";
	// The JSON object for the profile results
	public static final String KEY_PROFILE_RESPONSE_OBJECT = "profile_response_object";
	// The profile print string.
	public static final String KEY_PROFILE_RESPONSE_PRINT = "profile_response_print";
	
	// The template used for the tests
	private RestTemplate tempalte;
	String sessionToken;

	private Map<String, String> toDelete;
	/**
	 * @throws Exception
	 * 
	 */
	@Before
	public void before() throws Exception {
		tempalte = new RestTemplate();
		// Create a session token
		sessionToken = getNewSessionToken();
		toDelete = new HashMap<String, String>();
	}
	
	@After
	public void after(){
		if(tempalte != null && sessionToken != null && toDelete!= null){
			Iterator<String> it = toDelete.keySet().iterator();
			while(it.hasNext()){
				String id = it.next();
				String suffix = toDelete.get(id);
				deleteEntity(id, suffix);
			}
		}
	}
	
	@Ignore
	@Test
	public void testPerCallProfileOn() throws JSONException, UnsupportedEncodingException{
		assertNotNull(sessionToken);
		// First get a token
		ResponseEntity<String> response = createProject("ITPerCallProfileTest.testPerCallProfileOn", true);
		// Now get the frame from the header
		System.out.println(response.getHeaders());
		List<String> list = response.getHeaders().get(KEY_PROFILE_RESPONSE_OBJECT);
		assertNotNull(list);
		assertEquals(1, list.size());
		String encoded = list.get(0);
		String decoded = new String(Base64.decodeBase64(encoded.getBytes("UTF-8")), "UTF-8");
		System.out.println("Results: "+decoded);
		JSONObject frame = new JSONObject(decoded);
		assertNotNull(frame.getLong("startTime"));
		assertNotNull(frame.getString("name"));
		assertNotNull(frame.getLong("elapse"));
		
	}

	@Ignore
	@Test
	public void testPerCallProfileOff() throws JSONException, UnsupportedEncodingException{
		assertNotNull(sessionToken);
		ResponseEntity<String> response = createProject("ITPerCallProfileTest.testPerCallProfileOff", false);
		// Now get the frame from the header
		System.out.println(response.getHeaders());
		// The profile data should not be in the header when profiling if off.
		List<String> list = response.getHeaders().get(KEY_PROFILE_RESPONSE_OBJECT);
		assertTrue(list == null);
		
	}
{'fraction_non_alphanumeric': 0.10986714434990297, 'fraction_numerical': 0.002985520226899537, 'mean_word_length': 5.273408239700374, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '3837826', 'n_tokens_mistral': 2060, 'n_tokens_neox': 1932, 'n_words': 482}