-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CAMEL-18201 Enhance CamelTestSupport to turn off context stopping
- Loading branch information
1 parent
3096762
commit 6dacb4f
Showing
3 changed files
with
131 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
...unit5/src/test/java/org/apache/camel/test/junit5/CamelTestSupporOneContextForAllTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* | ||
* 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.test.junit5; | ||
|
||
import org.apache.camel.CamelContext; | ||
import org.apache.camel.EndpointInject; | ||
import org.apache.camel.Produce; | ||
import org.apache.camel.ProducerTemplate; | ||
import org.apache.camel.RoutesBuilder; | ||
import org.apache.camel.Service; | ||
import org.apache.camel.builder.RouteBuilder; | ||
import org.apache.camel.component.mock.MockEndpoint; | ||
import org.apache.camel.impl.DefaultCamelContext; | ||
import org.apache.camel.spi.Registry; | ||
import org.apache.camel.support.DefaultRegistry; | ||
import org.apache.camel.test.junit5.patterns.CreateCamelContextPerTestTrueTest; | ||
import org.junit.jupiter.api.Order; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class CamelTestSupporOneContextForAllTest extends CamelTestSupport { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(CreateCamelContextPerTestTrueTest.class); | ||
|
||
private static final CamelContext CUSTOM_CONTEXT; | ||
|
||
static { | ||
CUSTOM_CONTEXT = new MockContext(); | ||
} | ||
|
||
@EndpointInject("mock:result") | ||
protected MockEndpoint resultEndpoint; | ||
|
||
@Produce("direct:start") | ||
protected ProducerTemplate template; | ||
|
||
@Override | ||
protected CamelContext createCamelContext() throws Exception { | ||
return CUSTOM_CONTEXT; | ||
} | ||
|
||
@Override | ||
protected void doStopCamelContext(CamelContext context, Service camelContextService) { | ||
//don't stop | ||
} | ||
|
||
@Override | ||
protected void doSetUp() throws Exception { | ||
if(context == null) { | ||
super.doSetUp(); | ||
} | ||
} | ||
|
||
@Test | ||
@Order(1) | ||
public void initContextTest() throws Exception { | ||
String expectedBody = "<matched/>"; | ||
|
||
resultEndpoint.expectedBodiesReceived(expectedBody); | ||
|
||
template.sendBodyAndHeader(expectedBody, "foo", "bar"); | ||
|
||
resultEndpoint.assertIsSatisfied(); | ||
resultEndpoint.reset(); | ||
|
||
} | ||
|
||
@Test | ||
@Order(2) | ||
public void stopNotEnabledTest() throws Exception { | ||
String expectedBody = "<matched/>"; | ||
|
||
resultEndpoint.expectedBodiesReceived(expectedBody); | ||
|
||
template.sendBodyAndHeader(expectedBody, "foo", "bar"); | ||
|
||
resultEndpoint.assertIsSatisfied(); | ||
resultEndpoint.reset(); | ||
|
||
} | ||
|
||
@Override | ||
protected RouteBuilder createRouteBuilder() { | ||
return new RouteBuilder() { | ||
public void configure() { | ||
from("direct:start").filter(header("foo").isEqualTo("bar")).to("mock:result"); | ||
} | ||
}; | ||
} | ||
|
||
private static class MockContext extends DefaultCamelContext { | ||
|
||
boolean initialized; | ||
|
||
@Override | ||
protected Registry createRegistry() { | ||
if (initialized) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
if (!initialized) { | ||
initialized = true; | ||
} | ||
return new DefaultRegistry(); | ||
} | ||
|
||
@Override | ||
public void addRoutes(RoutesBuilder builder) throws Exception { | ||
//if routes are already added, do not add them again | ||
if (getRoutes().isEmpty()) { | ||
super.addRoutes(builder); | ||
} | ||
} | ||
} | ||
} |
75 changes: 0 additions & 75 deletions
75
...st/camel-test-junit5/src/test/java/org/apache/camel/test/junit5/CamelTestSupportTest.java
This file was deleted.
Oops, something went wrong.