Skip to content

Commit

Permalink
Ref apache#318: Add camel netty http test (apache#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
f2par0 authored Jun 5, 2024
1 parent 131bc33 commit fbe47e8
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/features/camel-netty-http/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.karaf</groupId>
<artifactId>camel-karaf-features-test</artifactId>
<version>4.6.0-SNAPSHOT</version>
</parent>

<artifactId>camel-netty-http-test</artifactId>
<name>Apache Camel :: Karaf :: Tests :: Features :: Netty Http</name>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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.karaf.camel.test;

import java.util.function.Function;

import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.RouteDefinition;
import org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteSupplier;
import org.apache.karaf.camel.itests.CamelRouteSupplier;
import org.osgi.service.component.annotations.Component;


@Component(
name = "karaf-camel-netty-http-test",
immediate = true,
service = CamelRouteSupplier.class
)
public class CamelNettyHttpRouteSupplier extends AbstractCamelSingleFeatureResultMockBasedRouteSupplier {

private static final String HTTP_PROP = "http.port";

@Override
protected Function<RouteBuilder, RouteDefinition> consumerRoute() {
return builder ->
builder.fromF("netty-http:http://127.0.0.1:%s/testNetty", System.getProperty(HTTP_PROP))
.log("receiving http request")
.setBody(builder.constant("OK"));
}

@Override
protected void configureProducer(RouteBuilder builder, RouteDefinition producerRoute) {
producerRoute.log("calling http endpoint")
.setBody(builder.constant("OK"))
.log("sending http request")
.toF("netty-http:http://127.0.0.1:%s/testNetty", System.getProperty(HTTP_PROP));
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Licensed 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.karaf.camel.itest;

import java.util.List;

import org.apache.camel.component.mock.MockEndpoint;
import org.apache.karaf.camel.itests.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.ops4j.pax.exam.spi.reactors.PerClass;

@CamelKarafTestHint(externalResourceProvider = CamelNettyHttpITest.ExternalResourceProviders.class)
@RunWith(PaxExamWithExternalResource.class)
@ExamReactorStrategy(PerClass.class)
public class CamelNettyHttpITest extends AbstractCamelSingleFeatureResultMockBasedRouteITest {


@Override
public void configureMock(MockEndpoint mock) {
mock.expectedBodiesReceived("OK");
}

@Test
public void testResultMock() throws Exception {
assertMockEndpointsSatisfied();
}

public static final class ExternalResourceProviders {
public static AvailablePortProvider createAvailablePortProvider() {
return new AvailablePortProvider(List.of("http.port"));
}

}
}
1 change: 1 addition & 0 deletions tests/features/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<module>camel-core</module>
<module>camel-elasticsearch</module>
<module>camel-jetty</module>
<module>camel-netty-http</module>
<module>camel-mail</module>
</modules>

Expand Down

0 comments on commit fbe47e8

Please sign in to comment.