<commit_before>package ca.intelliware.ihtsdo.mlds.security.ihtsdo;

import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;

import java.util.List;

import org.apache.http.HttpStatus;
import org.apache.http.HttpVersion;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.message.BasicHttpResponse;
import org.apache.http.message.BasicStatusLine;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;

import ca.intelliware.ihtsdo.mlds.domain.json.ObjectMapperTestBuilder;

@RunWith(MockitoJUnitRunner.class)
public class HttpAuthAdaptorTest {
	HttpAuthAdaptor httpAuthAdaptor = new HttpAuthAdaptor();
	
	@Mock HttpClient httpClient;
	BasicHttpResponse response200 = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK"));
	BasicHttpResponse response401 = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "OK"));
	

	@Before
	public void setUp() {
		httpAuthAdaptor.httpClient = httpClient;
		httpAuthAdaptor.objectMapper = new ObjectMapperTestBuilder().buildObjectMapper();
	}
	
	@Test
	public void userPermsUnmarshalsOKResponse() throws Exception {
		response200.setEntity(new StringEntity("{\"perms\":[{\"app\":\"Release\",\"role\":\"Manager\",\"member\":\"UK\"}]}", ContentType.APPLICATION_JSON));
		Mockito.stub(httpClient.execute(Mockito.any(HttpUriRequest.class))).toReturn(response200);
		
		List<CentralAuthUserPermission> userPermissions = httpAuthAdaptor.getUserPermissions("username");<commit_msg>MLDS-170 Update test to survive no default config<commit_after>package ca.intelliware.ihtsdo.mlds.security.ihtsdo;

import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;

import java.util.List;

import org.apache.http.HttpStatus;
import org.apache.http.HttpVersion;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.message.BasicHttpResponse;
import org.apache.http.message.BasicStatusLine;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;

import ca.intelliware.ihtsdo.mlds.domain.json.ObjectMapperTestBuilder;

@RunWith(MockitoJUnitRunner.class)
public class HttpAuthAdaptorTest {
	HttpAuthAdaptor httpAuthAdaptor = new HttpAuthAdaptor();
	
	@Mock HttpClient httpClient;
	BasicHttpResponse response200 = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK"));
	BasicHttpResponse response401 = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "OK"));
	

	@Before
	public void setUp() {
		httpAuthAdaptor.httpClient = httpClient;
		httpAuthAdaptor.objectMapper = new ObjectMapperTestBuilder().buildObjectMapper();
		httpAuthAdaptor.setApplicationName("MLDS");
		httpAuthAdaptor.setQueryUrl("http://example.com/");
	}
	
	@Test
	public void userPermsUnmarshalsOKResponse() throws Exception {
		response200.setEntity(new StringEntity("{\"perms\":[{\"app\":\"Release\",\"role\":\"Manager\",\"member\":\"UK\"}]}", ContentType.APPLICATION_JSON));
		Mockito.stub(httpClient.execute(Mockito.any(HttpUriRequest.class))).toReturn(response200);
		
		List<CentralAuthUserPermission> userPermissions = httpAuthAdaptor.getUserPermissions("username");
{'fraction_non_alphanumeric': 0.11715686274509804, 'fraction_numerical': 0.00857843137254902, 'mean_word_length': 6.8936170212765955, 'pattern_counts': {'":': 8, '<': 5, '<?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': '7663755', 'n_tokens_mistral': 1327, 'n_tokens_neox': 1280, 'n_words': 206}