Skip to content

Commit

Permalink
Fixed arangodb + generated pomns
Browse files Browse the repository at this point in the history
  • Loading branch information
JiriOndrusek committed Jul 20, 2023
1 parent 1dfaedc commit efc58d8
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
package org.apache.camel.quarkus.component.arangodb.it;

import java.net.URI;
import java.util.Collection;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.arangodb.entity.BaseDocument;
import com.arangodb.entity.DocumentCreateEntity;
import com.arangodb.entity.DocumentDeleteEntity;
import jakarta.enterprise.context.ApplicationScoped;
Expand All @@ -36,6 +39,7 @@
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.apache.camel.ProducerTemplate;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.jboss.logging.Logger;

import static org.apache.camel.component.arangodb.ArangoDbConstants.AQL_QUERY;
Expand All @@ -44,7 +48,7 @@
import static org.apache.camel.component.arangodb.ArangoDbConstants.ARANGO_KEY;
import static org.apache.camel.component.arangodb.ArangoDbConstants.RESULT_CLASS_TYPE;

@Path("/arangodb/camel")
@Path("/arangodb")
@ApplicationScoped
public class ArangodbResource {

Expand All @@ -53,14 +57,20 @@ public class ArangodbResource {
@Inject
ProducerTemplate producerTemplate;

@ConfigProperty(name = "camel.arangodb.host")
String host;

@ConfigProperty(name = "camel.arangodb.port")
String port;

@PUT
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
public Response put(String message) throws Exception {
LOG.infof("Saving to arangodb: %s", message);
final DocumentCreateEntity<?> response = producerTemplate.requestBody(
"arangodb:test?host={{camel.arangodb.host}}&port={{camel.arangodb.port}}&documentCollection=camel&operation=SAVE_DOCUMENT",
message, DocumentCreateEntity.class);
String.format("arangodb:test?host=%s&port=%s&documentCollection=camel&operation=SAVE_DOCUMENT", host, port),
toDocument(message), DocumentCreateEntity.class);
LOG.infof("Got response from arangodb: %s", response);
return Response
.created(new URI("https://camel.apache.org/"))
Expand All @@ -73,13 +83,13 @@ public Response put(String message) throws Exception {
@Produces(MediaType.TEXT_PLAIN)
public Response get(@PathParam("key") String key) throws Exception {
LOG.infof("Retrieve document from arangodb with key: %s", key);
final String response = producerTemplate.requestBodyAndHeader(
final BaseDocument response = producerTemplate.requestBodyAndHeader(
"arangodb:test?host={{camel.arangodb.host}}&port={{camel.arangodb.port}}&documentCollection=camel&operation=FIND_DOCUMENT_BY_KEY",
key, RESULT_CLASS_TYPE, String.class, String.class);
key, RESULT_CLASS_TYPE, BaseDocument.class, BaseDocument.class);
LOG.infof("Got response from arangodb: %s", response);
return Response
.ok()
.entity(response)
.entity(toString(response))
.build();
}

Expand Down Expand Up @@ -107,7 +117,7 @@ public Response post(@PathParam("key") String key, String msg) throws Exception

producerTemplate.requestBodyAndHeaders(
"arangodb:test?host={{camel.arangodb.host}}&port={{camel.arangodb.port}}&documentCollection=camel&operation=UPDATE_DOCUMENT",
msg, headers, String.class);
toDocument(msg), headers, String.class);
return Response
.ok()
.build();
Expand All @@ -126,15 +136,39 @@ public Response getByFooName(@PathParam("fooName") String fooName) throws Except
headers.put(AQL_QUERY, query);
headers.put(AQL_QUERY_BIND_PARAMETERS, bindVars);
headers.put(AQL_QUERY_OPTIONS, null);
headers.put(RESULT_CLASS_TYPE, String.class);
headers.put(RESULT_CLASS_TYPE, Map.class);

final Collection<?> responseList = producerTemplate.requestBodyAndHeaders(
final List o = producerTemplate.requestBodyAndHeaders(
"arangodb:test?host={{camel.arangodb.host}}&port={{camel.arangodb.port}}&operation=AQL_QUERY",
fooName, headers, Collection.class);
fooName, headers, List.class);

return Response
.ok()
.entity(responseList.toString())
.entity(toString(o))
.build();
}

private BaseDocument toDocument(String msg) {
BaseDocument myObject = new BaseDocument();
Arrays.stream(msg.split(",")).map(pair -> pair.split(":"))
.forEach(strings -> myObject.addAttribute(strings[0], strings[1]));
return myObject;
}

private String toString(Object o) {
if (o instanceof List && ((List) o).size() == 1 && ((List) o).get(0) instanceof Map) {
return toString(((List) o).get(0));
}

if (o instanceof Map) {
return (String) ((Map) o).entrySet().stream()
.map(e -> ((Map.Entry) e).getKey() + ":" + ((Map.Entry) e).getValue())
.collect(Collectors.joining(","));
}

if (o instanceof BaseDocument) {
return toString(((BaseDocument) o).getProperties());
}
return o.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,14 @@
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
import org.eclipse.microprofile.config.ConfigProvider;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.hamcrest.Matchers.both;
import static org.hamcrest.Matchers.containsString;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

@QuarkusTest
@QuarkusTestResource(ArangodbTestResource.class)
Expand All @@ -46,29 +44,23 @@ class ArangodbTest {
@Test
public void testCreateGetDeleteDocument() {
// create a new document
RequestSpecification request = RestAssured.given()
String key = RestAssured.given()
.contentType(ContentType.TEXT)
.body("{\"foo\":\"bar\"}");
Response response = request.put("/arangodb/camel");

int statusCode = response.getStatusCode();
assertEquals(201, statusCode);
// getting key of the document inserted
String key = response.body().asString().trim();

// get the document by key
request = RestAssured.given()
.contentType(ContentType.TEXT);
response = request.get("/arangodb/camel/" + key);
statusCode = response.getStatusCode();
assertEquals(200, statusCode);
String document = response.body().asString().trim();
assertTrue(document.contains("\"foo\":\"bar\""));
.body("foo:bar")
.put("/arangodb")
.then()
.statusCode(201)
.extract().body().asString();

RestAssured.get("/arangodb/" + key)
.then()
.statusCode(200)
.body(containsString("foo:bar"));

// delete document
RestAssured.given()
.contentType(ContentType.TEXT)
.delete("/arangodb/camel/" + key)
.delete("/arangodb/" + key)
.then()
.statusCode(200);

Expand All @@ -88,19 +80,16 @@ public void testUpdateDocument() {
// udpate document
RestAssured.given()
.contentType(ContentType.TEXT)
.body("{\"key\":\"myKey\",\"foo\":\"hello\", \"gg\":\"42\"}")
.post("/arangodb/camel/myKey")
.body("key:myKey,foo:hello,gg:42")
.post("/arangodb/myKey")
.then()
.statusCode(200);

// get document by key
RequestSpecification request = RestAssured.given()
.contentType(ContentType.TEXT);
Response response = request.get("/arangodb/camel/myKey");
assertEquals(200, response.getStatusCode());
String document = response.body().asString().trim();
assertTrue(document.contains("\"foo\":\"hello\""));
assertTrue(document.contains("\"gg\":\"42\""));
RestAssured.get("/arangodb/myKey")
.then()
.statusCode(200)
.body(both(containsString("foo:hello")).and(containsString("gg:42")));
}

@Test
Expand All @@ -117,21 +106,15 @@ public void testAQLQuery() {
myObject2.addAttribute("foo", "bar2");
collection.insertDocument(myObject2);

// get document with foo = bar1
RequestSpecification request = RestAssured.given()
.contentType(ContentType.TEXT);
Response response = request.get("/arangodb/camel/foo/bar1");
assertEquals(200, response.getStatusCode());
String result = response.body().asString();
assertTrue(result.contains("\"_key\":\"keyBar1\""));

//get document with foo = bar2
request = RestAssured.given()
.contentType(ContentType.TEXT);
response = request.get("/arangodb/camel/foo/bar2");
assertEquals(200, response.getStatusCode());
result = response.body().asString().trim();
assertTrue(result.contains("\"_key\":\"keyBar2\""));
RestAssured.get("/arangodb/foo/bar1")
.then()
.statusCode(200)
.body(containsString("_key:keyBar1"));

RestAssured.get("/arangodb/foo/bar2")
.then()
.statusCode(200)
.body(containsString("_key:keyBar2"));
}

@BeforeAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class ArangodbTestResource implements QuarkusTestResourceLifecycleManager
private static final Logger LOGGER = LoggerFactory.getLogger(ArangodbTestResource.class);
private GenericContainer<?> container;
private static final String CONTAINER_NAME = "arango";
private static final String ARANGO_IMAGE = "arangodb:latest";
private static final String ARANGO_IMAGE = "arangodb:3.10.9";
private static final String ARANGO_NO_AUTH = "ARANGO_NO_AUTH";
private static final Integer PORT_DEFAULT = 8529;

Expand Down
10 changes: 5 additions & 5 deletions poms/bom/src/main/generated/flattened-full-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6115,7 +6115,7 @@
<dependency>
<groupId>com.squareup.okio</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<artifactId>okio</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<version>1.17.2</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<version>1.17.5</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
</dependency>
<dependency>
<groupId>com.squareup.retrofit2</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
Expand Down Expand Up @@ -6691,22 +6691,22 @@
<dependency>
<groupId>org.web3j</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<artifactId>core</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<version>3.6.0</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<version>5.0.0</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
</dependency>
<dependency>
<groupId>org.web3j</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<artifactId>geth</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<version>3.6.0</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<version>5.0.0</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
</dependency>
<dependency>
<groupId>org.web3j</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<artifactId>parity</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<version>3.6.0</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<version>5.0.0</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
</dependency>
<dependency>
<groupId>org.web3j</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<artifactId>quorum</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<version>0.8.0</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<version>4.10.0</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
</dependency>
<dependency>
<groupId>software.amazon.awssdk.crt</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
Expand Down
10 changes: 5 additions & 5 deletions poms/bom/src/main/generated/flattened-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6115,7 +6115,7 @@
<dependency>
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
<version>1.17.2</version>
<version>1.17.5</version>
</dependency>
<dependency>
<groupId>com.squareup.retrofit2</groupId>
Expand Down Expand Up @@ -6656,22 +6656,22 @@
<dependency>
<groupId>org.web3j</groupId>
<artifactId>core</artifactId>
<version>3.6.0</version>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>org.web3j</groupId>
<artifactId>geth</artifactId>
<version>3.6.0</version>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>org.web3j</groupId>
<artifactId>parity</artifactId>
<version>3.6.0</version>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>org.web3j</groupId>
<artifactId>quorum</artifactId>
<version>0.8.0</version>
<version>4.10.0</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk.crt</groupId>
Expand Down
10 changes: 5 additions & 5 deletions poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6115,7 +6115,7 @@
<dependency>
<groupId>com.squareup.okio</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<artifactId>okio</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<version>1.17.2</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<version>1.17.5</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
</dependency>
<dependency>
<groupId>com.squareup.retrofit2</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
Expand Down Expand Up @@ -6656,22 +6656,22 @@
<dependency>
<groupId>org.web3j</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<artifactId>core</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<version>3.6.0</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<version>5.0.0</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
</dependency>
<dependency>
<groupId>org.web3j</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<artifactId>geth</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<version>3.6.0</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<version>5.0.0</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
</dependency>
<dependency>
<groupId>org.web3j</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<artifactId>parity</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<version>3.6.0</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<version>5.0.0</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
</dependency>
<dependency>
<groupId>org.web3j</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<artifactId>quorum</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<version>0.8.0</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<version>4.10.0</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
</dependency>
<dependency>
<groupId>software.amazon.awssdk.crt</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
Expand Down

0 comments on commit efc58d8

Please sign in to comment.