Skip to content

Commit

Permalink
Split out log related tests apache#2362
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga committed May 14, 2021
1 parent 1fb3169 commit 65eaeb8
Show file tree
Hide file tree
Showing 15 changed files with 446 additions and 56 deletions.
21 changes: 0 additions & 21 deletions integration-test-groups/foundation/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,10 @@
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-direct</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-log</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-timer</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-integration-tests-support-custom-log-component</artifactId>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
Expand Down Expand Up @@ -95,19 +87,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-log-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-timer-deployment</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.json.Json;
import javax.json.JsonObject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
Expand All @@ -43,12 +43,10 @@
import org.apache.camel.builder.LambdaRouteBuilder;
import org.apache.camel.builder.TemplatedRouteBuilder;
import org.apache.camel.catalog.RuntimeCamelCatalog;
import org.apache.camel.component.log.LogComponent;
import org.apache.camel.impl.engine.DefaultHeadersMapFactory;
import org.apache.camel.model.ModelCamelContext;
import org.apache.camel.spi.Registry;
import org.apache.camel.support.LRUCacheFactory;
import org.apache.camel.support.processor.DefaultExchangeFormatter;
import org.apache.camel.support.startup.DefaultStartupStepRecorder;
import org.apache.commons.io.IOUtils;

Expand All @@ -60,24 +58,12 @@ public class CoreResource {
@Inject
CamelContext context;

@Path("/registry/log/exchange-formatter")
@GET
@Produces(MediaType.APPLICATION_JSON)
public JsonObject exchangeFormatterConfig() {
LogComponent component = registry.lookupByNameAndType("log", LogComponent.class);
DefaultExchangeFormatter def = (DefaultExchangeFormatter) component.getExchangeFormatter();

JsonObject result = Json.createObjectBuilder()
.add("show-all", def.isShowAll())
.add("multi-line", def.isMultiline())
.build();

return result;
}
private final List<String> lambdaRouteResult = new CopyOnWriteArrayList<>();

@javax.enterprise.inject.Produces
public LambdaRouteBuilder myOtherRoute() {
return rb -> rb.from("timer:bar").routeId("bar").to("log:bar");
public LambdaRouteBuilder lambdaRoute() {
return rb -> rb.from("timer:bar").routeId("bar")
.process(e -> lambdaRouteResult.add(e.getMessage().getBody(String.class)));
}

@Path("/routes/lookup-routes")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@
package org.apache.camel.quarkus.core;

import org.apache.camel.builder.RouteBuilder;
import org.jboss.logging.Logger;

public class CoreRoutes extends RouteBuilder {

private static final Logger LOG = Logger.getLogger(CoreRoutes.class);

@Override
public void configure() {
from("timer:keep-alive")
.routeId("timer")
.setBody().constant("I'm alive !")
.to("log:keep-alive");

.process(e -> LOG.infof("keep-alive: %s", e.getMessage().getBody(String.class)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,14 @@
package org.apache.camel.quarkus.core;

import java.io.IOException;
import java.net.HttpURLConnection;

import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.apache.camel.support.DefaultLRUCacheFactory;
import org.junit.jupiter.api.Test;

import static org.hamcrest.Matchers.*;
import static org.hamcrest.core.IsNot.not;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

@QuarkusTest
public class CoreTest {
Expand All @@ -55,15 +51,6 @@ public void testCamelContextAwareRegistryBeansInitialized() {
RestAssured.when().get("/core/registry/camel-context-aware/initialized").then().body(is("true"));
}

@Test
public void testCamelBeanBuildItem() {
Response response = RestAssured.get("/core/registry/log/exchange-formatter").andReturn();

assertEquals(HttpURLConnection.HTTP_OK, response.getStatusCode());
assertTrue(response.jsonPath().getBoolean("show-all"));
assertTrue(response.jsonPath().getBoolean("multi-line"));
}

@Test
public void testCamelContextVersion() {
RestAssured.when().get("/core/context/version").then().body(not(""));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-integration-tests-foundation</artifactId>
<version>1.9.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>camel-quarkus-integration-test-customized-log-component</artifactId>
<name>Camel Quarkus :: Integration Tests :: Customize Log component :: Tests</name>

<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-integration-tests-support-custom-log-component</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>

<!-- test dependencies -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<properties>
<quarkus.package.type>native</quarkus.package.type>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.component.customized.log.it;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.log.LogComponent;
import org.apache.camel.spi.Registry;
import org.apache.camel.support.processor.DefaultExchangeFormatter;

@Path("/customized-log-component")
@ApplicationScoped
public class CustomizedLogComponentResource {
@Inject
Registry registry;

@Inject
ProducerTemplate producerTemplate;

@Path("/exchange-formatter/{key}")
@GET
@Produces(MediaType.TEXT_PLAIN)
public String exchangeFormatterConfig(@PathParam("key") String key) {
LogComponent component = registry.lookupByNameAndType("log", LogComponent.class);
DefaultExchangeFormatter def = (DefaultExchangeFormatter) component.getExchangeFormatter();

switch (key) {
case "show-all":
return String.valueOf(def.isShowAll());
case "multi-line":
return String.valueOf(def.isMultiline());
default:
throw new IllegalStateException("Unexpected key " + key);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.component.log.it;

import io.quarkus.test.junit.NativeImageTest;

@NativeImageTest
public class CustomizedLogComponentIT extends CustomizedLogComponentTest {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.component.log.it;

import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;

@QuarkusTest
public class CustomizedLogComponentTest {

@Test
public void customLogComponent() {
RestAssured
.get("/customized-log-component/exchange-formatter/show-all")
.then()
.statusCode(200)
.body(Matchers.is("true"));
RestAssured
.get("/customized-log-component/exchange-formatter/multi-line")
.then()
.statusCode(200)
.body(Matchers.is("true"));

}

}

0 comments on commit 65eaeb8

Please sign in to comment.