use of org.icij.datashare.PropertiesProvider in project datashare by ICIJ.
the class BatchSearchRunnerIntTest method test_search_with_phraseMatches_with_ner.
@Test
public void test_search_with_phraseMatches_with_ner() throws Exception {
Document mydoc = createDoc("docId").with("anne's doc to find").build();
indexer.add(TEST_INDEX, mydoc);
indexer.add(TEST_INDEX, NamedEntity.create(NamedEntity.Category.PERSON, "anne", asList(12L), mydoc.getId(), mydoc.getRootDocument(), Pipeline.Type.CORENLP, Language.FRENCH));
BatchSearch searchKo = new BatchSearch(project(TEST_INDEX), "name", "desc", asSet("anne doc"), User.local(), false, null, null, true);
BatchSearch searchOk = new BatchSearch(project(TEST_INDEX), "name", "desc", asSet("anne's doc"), User.local(), false, null, null, true);
new BatchSearchRunner(indexer, new PropertiesProvider(), searchKo, resultConsumer).call();
new BatchSearchRunner(indexer, new PropertiesProvider(), searchOk, resultConsumer).call();
verify(resultConsumer, never()).apply(eq(searchKo.uuid), eq("anne doc"), anyList());
verify(resultConsumer).apply(searchOk.uuid, "anne's doc", singletonList(mydoc));
}
use of org.icij.datashare.PropertiesProvider in project datashare by ICIJ.
the class IndexTaskTest method test_index_task_null_user_uses_options_for_index_name.
@Test
public void test_index_task_null_user_uses_options_for_index_name() {
ElasticsearchSpewer spewer = mock(ElasticsearchSpewer.class);
new IndexTask(spewer, mock(Publisher.class), mock(DocumentCollectionFactory.class), nullUser(), "queueName", new PropertiesProvider(new HashMap<String, String>() {
{
put("redisAddress", "redis://redis:6379");
put("defaultProject", "foo");
}
}).getProperties());
Mockito.verify(spewer).withIndex("foo");
}
use of org.icij.datashare.PropertiesProvider in project datashare by ICIJ.
the class LocalUserFilterTest method test_adds_cookie.
@Test
public void test_adds_cookie() throws Exception {
LocalUserFilter localUserFilter = new LocalUserFilter(new PropertiesProvider());
Payload payload = localUserFilter.apply("url", context, nextFilter);
assertThat(payload.cookies().size()).isEqualTo(1);
assertThat(payload.cookies().get(0).name()).isEqualTo("_ds_session_id");
assertThat(payload.cookies().get(0).value()).contains("\"login\":\"local\"");
}
use of org.icij.datashare.PropertiesProvider in project datashare by ICIJ.
the class LocalUserFilterTest method test_matches.
@Test
public void test_matches() {
LocalUserFilter localUserFilter = new LocalUserFilter(new PropertiesProvider(new HashMap<String, String>() {
{
put("protectedUrPrefix", "test");
}
}));
assertThat(localUserFilter.matches("foo", null)).isFalse();
assertThat(localUserFilter.matches("/foo", null)).isFalse();
assertThat(localUserFilter.matches("test", null)).isTrue();
assertThat(localUserFilter.matches("/test", null)).isFalse();
assertThat(localUserFilter.matches("test_bar", null)).isTrue();
}
use of org.icij.datashare.PropertiesProvider in project datashare by ICIJ.
the class ElasticsearchConfiguration method createESClient.
public static RestHighLevelClient createESClient(final PropertiesProvider propertiesProvider) {
System.setProperty("es.set.netty.runtime.available.processors", "false");
try {
URL indexUrl = new URL(propertiesProvider.get(INDEX_ADDRESS_PROP).orElse(DEFAULT_ADDRESS));
HttpHost httpHost = create(format("%s://%s:%d", indexUrl.getProtocol(), indexUrl.getHost(), indexUrl.getPort()));
RestClientBuilder.HttpClientConfigCallback httpClientConfigCallback = httpClientBuilder -> httpClientBuilder;
if (indexUrl.getUserInfo() != null) {
String[] userInfo = indexUrl.getUserInfo().split(":");
LOGGER.info("using credentials from url (user={})", userInfo[0]);
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userInfo[0], userInfo[1]));
httpClientConfigCallback = httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
}
RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(httpHost).setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder.setConnectTimeout(5000).setSocketTimeout(60000)).setHttpClientConfigCallback(httpClientConfigCallback));
String clusterName = propertiesProvider.get(CLUSTER_PROP).orElse(ES_CLUSTER_NAME);
return client;
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
Aggregations