Skip to content

Commit 426279f

Browse files
author
michele
committed
Merge branch 'master' into kerberos
2 parents 8c11ab3 + 49d0def commit 426279f

File tree

11 files changed

+192
-50
lines changed

11 files changed

+192
-50
lines changed

src/main/java/com/arangodb/internal/http/HttpConnection.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private HttpConnection(final HostDescription host, final Integer timeout, final
139139

140140
client = builder.build();
141141
try {
142-
updateBearer();
142+
updateBearerToken();
143143
} catch (IOException e) {
144144
e.printStackTrace();
145145
}
@@ -180,30 +180,30 @@ private static void addHeader(final Request request, final HttpRequestBase httpR
180180
}
181181
}
182182

183-
private void updateBearer() throws IOException {
183+
private void updateBearerToken() throws IOException {
184+
// TODO: expose as config params
184185
final boolean stripPort = true;
185186
final boolean useCanonicalHostname = false;
187+
186188
final HttpClientBuilder builder = HttpClientBuilder.create();
187189
builder.setDefaultAuthSchemeRegistry((name) -> new SPNegoSchemeFactory(stripPort, useCanonicalHostname));
188190

189-
Credentials use_jaas_creds = new Credentials() {
190-
public String getPassword() {
191-
return null;
192-
}
193-
194-
public Principal getUserPrincipal() {
195-
return null;
196-
}
197-
};
198191

199192
BasicCredentialsProvider basicCredentialsProvider = new BasicCredentialsProvider();
200193
basicCredentialsProvider.setCredentials(
201194
new AuthScope(null, -1, null),
202-
use_jaas_creds);
195+
new Credentials() {
196+
public String getPassword() {
197+
return null;
198+
}
199+
200+
public Principal getUserPrincipal() {
201+
return null;
202+
}
203+
});
203204
builder.setDefaultCredentialsProvider(basicCredentialsProvider);
204205
CloseableHttpClient authClient = builder.build();
205206

206-
207207
HttpUriRequest request = new HttpGet("http://bruecklinux.arangodb.biz:8899/_db/_system/_open/auth");
208208
HttpResponse response = authClient.execute(request);
209209
HttpEntity entity = response.getEntity();
@@ -320,7 +320,7 @@ public Response execute(final Request request) throws ArangoDBException, IOExcep
320320
Response response;
321321

322322
httpRequest.addHeader("Authorization", "Bearer " + bearerToken);
323-
response = buildResponse(client.execute(httpRequest));
323+
response = buildResponse(client.execute(httpRequest));
324324
checkError(response);
325325
return response;
326326
}

src/test/java/com/arangodb/ArangoEdgeCollectionTest.java

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,7 @@
2020

2121
package com.arangodb;
2222

23-
import static org.hamcrest.Matchers.hasItem;
24-
import static org.hamcrest.Matchers.is;
25-
import static org.hamcrest.Matchers.not;
26-
import static org.hamcrest.Matchers.notNullValue;
27-
import static org.hamcrest.Matchers.nullValue;
28-
import static org.junit.Assert.assertThat;
29-
import static org.junit.Assert.fail;
30-
import static org.junit.Assume.assumeTrue;
31-
32-
import java.util.ArrayList;
33-
import java.util.Arrays;
34-
import java.util.Collection;
35-
23+
import com.arangodb.ArangoDB.Builder;
3624
import com.arangodb.entity.*;
3725
import com.arangodb.model.*;
3826
import org.junit.After;
@@ -41,7 +29,14 @@
4129
import org.junit.runner.RunWith;
4230
import org.junit.runners.Parameterized;
4331

44-
import com.arangodb.ArangoDB.Builder;
32+
import java.util.ArrayList;
33+
import java.util.Arrays;
34+
import java.util.Collection;
35+
36+
import static org.hamcrest.Matchers.*;
37+
import static org.junit.Assert.assertThat;
38+
import static org.junit.Assert.fail;
39+
import static org.junit.Assume.assumeTrue;
4540

4641
/**
4742
* @author Mark Vollmary
@@ -266,9 +261,14 @@ public void replaceEdgeIfMatchFail() {
266261
db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).replaceEdge(createResult.getKey(), doc, options);
267262
fail();
268263
} catch (final ArangoDBException e) {
269-
// FIXME: atm the server replies 409 for HTTP_JSON or HTTP_VPACK
270-
// assertThat(e.getResponseCode(), is(412));
271-
assertThat(e.getErrorNum(), is(1200));
264+
if (isAtLeastVersion(3, 4)) {
265+
// FIXME: atm the server replies 409 for HTTP_JSON or HTTP_VPACK
266+
// assertThat(e.getResponseCode(), is(412));
267+
assertThat(e.getErrorNum(), is(1200));
268+
} else {
269+
assertThat(e.getResponseCode(), is(412));
270+
assertThat(e.getErrorNum(), is(1903));
271+
}
272272
}
273273
}
274274

@@ -351,9 +351,14 @@ public void updateEdgeIfMatchFail() {
351351
db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).updateEdge(createResult.getKey(), doc, options);
352352
fail();
353353
} catch (final ArangoDBException e) {
354-
// FIXME: atm the server replies 409 for HTTP_JSON or HTTP_VPACK
355-
// assertThat(e.getResponseCode(), is(412));
356-
assertThat(e.getErrorNum(), is(1200));
354+
if (isAtLeastVersion(3, 4)) {
355+
// FIXME: atm the server replies 409 for HTTP_JSON or HTTP_VPACK
356+
// assertThat(e.getResponseCode(), is(412));
357+
assertThat(e.getErrorNum(), is(1200));
358+
} else {
359+
assertThat(e.getResponseCode(), is(412));
360+
assertThat(e.getErrorNum(), is(1903));
361+
}
357362
}
358363
}
359364

@@ -430,9 +435,14 @@ public void deleteEdgeIfMatchFail() {
430435
db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).deleteEdge(createResult.getKey(), options);
431436
fail();
432437
} catch (final ArangoDBException e) {
433-
// FIXME: atm the server replies 409 for HTTP_JSON or HTTP_VPACK
434-
// assertThat(e.getResponseCode(), is(412));
435-
assertThat(e.getErrorNum(), is(1200));
438+
if (isAtLeastVersion(3, 4)) {
439+
// FIXME: atm the server replies 409 for HTTP_JSON or HTTP_VPACK
440+
// assertThat(e.getResponseCode(), is(412));
441+
assertThat(e.getErrorNum(), is(1200));
442+
} else {
443+
assertThat(e.getResponseCode(), is(412));
444+
assertThat(e.getErrorNum(), is(1903));
445+
}
436446
}
437447
}
438448
}

src/test/java/com/arangodb/ArangoSearchTest.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public ArangoSearchTest(final Builder builder) {
5353

5454
@After
5555
public void teardown() {
56+
if (!isAtLeastVersion(3, 4))
57+
return;
5658
if (db.collection("view_update_prop_test_collection").exists())
5759
db.collection("view_update_prop_test_collection").drop();
5860
if (db.collection("view_replace_prop_test_collection").exists())
@@ -409,5 +411,46 @@ public void textAnalyzer() {
409411
createGetAndDeleteAnalyzer(options);
410412
}
411413

414+
@Test
415+
public void arangoSearchOptions() {
416+
assumeTrue(isAtLeastVersion(3, 4));
417+
418+
ArangoCollection collection = db.collection("entities");
419+
if (!collection.exists())
420+
collection.create();
421+
422+
ArangoSearchCreateOptions options = new ArangoSearchCreateOptions()
423+
.link(
424+
CollectionLink.on("entities")
425+
.analyzers("identity")
426+
.fields(
427+
FieldLink.on("id")
428+
.analyzers("identity")
429+
)
430+
.includeAllFields(true)
431+
.storeValues(StoreValuesType.ID)
432+
.trackListPositions(false)
433+
434+
);
435+
436+
final ArangoSearch view = db.arangoSearch("entities_view");
437+
if (view.exists())
438+
view.drop();
439+
440+
view.create(options);
441+
442+
final ArangoSearchPropertiesEntity properties = view.getProperties();
443+
assertThat(properties, is(not(nullValue())));
444+
assertThat(properties.getId(), is(not(nullValue())));
445+
assertThat(properties.getName(), is("entities_view"));
446+
assertThat(properties.getType(), is(ViewType.ARANGO_SEARCH));
447+
448+
CollectionLink link = properties.getLinks().iterator().next();
449+
assertThat(link.getAnalyzers(), contains("identity"));
450+
assertThat(link.getName(), is("entities"));
451+
assertThat(link.getIncludeAllFields(), is(true));
452+
assertThat(link.getStoreValues(), is(StoreValuesType.ID));
453+
assertThat(link.getTrackListPositions(), is(false));
454+
}
412455

413456
}

src/test/java/com/arangodb/ArangoVertexCollectionTest.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,14 @@ public void replaceVertexIfMatchFail() {
261261
db.graph(GRAPH_NAME).vertexCollection(COLLECTION_NAME).replaceVertex(createResult.getKey(), doc, options);
262262
fail();
263263
} catch (final ArangoDBException e) {
264-
// FIXME: atm the server replies 409 for HTTP_JSON or HTTP_VPACK
265-
// assertThat(e.getResponseCode(), is(412));
266-
assertThat(e.getErrorNum(), is(1200));
264+
if (isAtLeastVersion(3, 4)) {
265+
// FIXME: atm the server replies 409 for HTTP_JSON or HTTP_VPACK
266+
// assertThat(e.getResponseCode(), is(412));
267+
assertThat(e.getErrorNum(), is(1200));
268+
} else {
269+
assertThat(e.getResponseCode(), is(412));
270+
assertThat(e.getErrorNum(), is(1903));
271+
}
267272
}
268273
}
269274

@@ -350,9 +355,14 @@ public void updateVertexIfMatchFail() {
350355
db.graph(GRAPH_NAME).vertexCollection(COLLECTION_NAME).updateVertex(createResult.getKey(), doc, options);
351356
fail();
352357
} catch (final ArangoDBException e) {
353-
// FIXME: atm the server replies 409 for HTTP_JSON or HTTP_VPACK
354-
// assertThat(e.getResponseCode(), is(412));
355-
assertThat(e.getErrorNum(), is(1200));
358+
if (isAtLeastVersion(3, 4)) {
359+
// FIXME: atm the server replies 409 for HTTP_JSON or HTTP_VPACK
360+
// assertThat(e.getResponseCode(), is(412));
361+
assertThat(e.getErrorNum(), is(1200));
362+
} else {
363+
assertThat(e.getResponseCode(), is(412));
364+
assertThat(e.getErrorNum(), is(1903));
365+
}
356366
}
357367
}
358368

@@ -434,9 +444,14 @@ public void deleteVertexIfMatchFail() {
434444
db.graph(GRAPH_NAME).vertexCollection(COLLECTION_NAME).deleteVertex(createResult.getKey(), options);
435445
fail();
436446
} catch (final ArangoDBException e) {
437-
// FIXME: atm the server replies 409 for HTTP_JSON or HTTP_VPACK
438-
// assertThat(e.getResponseCode(), is(412));
439-
assertThat(e.getErrorNum(), is(1200));
447+
if (isAtLeastVersion(3, 4)) {
448+
// FIXME: atm the server replies 409 for HTTP_JSON or HTTP_VPACK
449+
// assertThat(e.getResponseCode(), is(412));
450+
assertThat(e.getErrorNum(), is(1200));
451+
} else {
452+
assertThat(e.getResponseCode(), is(412));
453+
assertThat(e.getErrorNum(), is(1903));
454+
}
440455
}
441456
}
442457
}

src/test/java/com/arangodb/ArangoViewTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public ArangoViewTest(final Builder builder) {
4646

4747
@After
4848
public void teardown() {
49+
if (!isAtLeastVersion(3, 4))
50+
return;
4951
if (db.view(VIEW_NAME).exists())
5052
db.view(VIEW_NAME).drop();
5153
}

src/test/java/com/arangodb/async/ArangoDBTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
import com.arangodb.velocypack.exception.VPackException;
3030
import com.arangodb.velocystream.Request;
3131
import com.arangodb.velocystream.RequestType;
32+
import org.junit.ClassRule;
3233
import org.junit.Test;
34+
import org.junit.rules.TestRule;
3335

3436
import java.util.Collection;
3537
import java.util.HashMap;
@@ -50,6 +52,9 @@ public class ArangoDBTest {
5052
private static final String USER = "mit dem mund";
5153
private static final String PW = "machts der hund";
5254

55+
@ClassRule
56+
public static TestRule acquireHostListRule = TestUtils.acquireHostListRule;
57+
5358
@Test
5459
public void getVersion() throws InterruptedException, ExecutionException {
5560
final ArangoDBAsync arangoDB = new ArangoDBAsync.Builder().build();

src/test/java/com/arangodb/async/ArangoSearchTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public class ArangoSearchTest extends BaseTest {
4848

4949
@BeforeClass
5050
public static void setup() throws InterruptedException, ExecutionException {
51+
if (!isAtLeastVersion(arangoDB, 3, 4))
52+
return;
5153
db.createArangoSearch(VIEW_NAME, new ArangoSearchCreateOptions()).get();
5254
}
5355

src/test/java/com/arangodb/async/ArangoViewTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public class ArangoViewTest extends BaseTest {
4141

4242
@BeforeClass
4343
public static void setup() throws InterruptedException, ExecutionException {
44+
if (!isAtLeastVersion(arangoDB, 3, 4))
45+
return;
4446
db.createView(VIEW_NAME, ViewType.ARANGO_SEARCH).get();
4547
}
4648

src/test/java/com/arangodb/async/BaseTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@
2525
import com.arangodb.entity.ServerRole;
2626
import org.junit.AfterClass;
2727
import org.junit.BeforeClass;
28+
import org.junit.ClassRule;
29+
import org.junit.rules.TestRule;
2830

2931
import java.util.concurrent.ExecutionException;
3032

33+
3134
/**
3235
* @author Mark Vollmary
3336
*/
@@ -37,6 +40,9 @@ public abstract class BaseTest {
3740
static ArangoDBAsync arangoDB;
3841
static ArangoDatabaseAsync db;
3942

43+
@ClassRule
44+
public static TestRule acquireHostListRule = TestUtils.acquireHostListRule;
45+
4046
@BeforeClass
4147
public static void init() throws InterruptedException, ExecutionException {
4248
if (arangoDB == null) {
@@ -58,13 +64,13 @@ public static void shutdown() throws InterruptedException, ExecutionException {
5864
arangoDB = null;
5965
}
6066

61-
private static boolean isAtLeastVersion(final ArangoDBAsync arangoDB, final int major, final int minor)
67+
protected static boolean isAtLeastVersion(final ArangoDBAsync arangoDB, final int major, final int minor)
6268
throws InterruptedException, ExecutionException {
6369
final String[] split = arangoDB.getVersion().get().getVersion().split("\\.");
6470
return Integer.parseInt(split[0]) >= major && Integer.parseInt(split[1]) >= minor;
6571
}
6672

67-
boolean isAtLeastVersion(final int major, final int minor) throws InterruptedException, ExecutionException {
73+
protected boolean isAtLeastVersion(final int major, final int minor) throws InterruptedException, ExecutionException {
6874
return isAtLeastVersion(arangoDB, major, minor);
6975
}
7076

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.arangodb.async;/*
2+
* DISCLAIMER
3+
*
4+
* Copyright 2016 ArangoDB GmbH, Cologne, Germany
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
*/
20+
21+
22+
import org.junit.rules.TestRule;
23+
24+
import java.io.IOException;
25+
import java.io.InputStream;
26+
import java.util.Properties;
27+
28+
import static org.junit.Assume.assumeTrue;
29+
30+
/**
31+
* @author Michele Rastelli
32+
*/
33+
public class TestUtils {
34+
public static TestRule acquireHostListRule = (base, description) -> {
35+
assumeTrue(!TestUtils.isAcquireHostList());
36+
return base;
37+
};
38+
39+
private static boolean isAcquireHostList() {
40+
InputStream in = TestUtils.class.getResourceAsStream("/arangodb.properties");
41+
final Properties properties = new Properties();
42+
try {
43+
properties.load(in);
44+
} catch (IOException e) {
45+
e.printStackTrace();
46+
return false;
47+
}
48+
return Boolean.parseBoolean(String.valueOf(properties.get("arangodb.acquireHostList")));
49+
}
50+
51+
}

0 commit comments

Comments
 (0)