orpiske commented on code in PR #13447: URL: https://github.com/apache/camel/pull/13447#discussion_r1521141356
########## core/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java: ########## @@ -338,53 +919,86 @@ protected void assertPredicate(String languageName, String expressionText, Excha Predicate predicate = language.createPredicate(expressionText); assertNotNull(predicate, "No Predicate could be created for text: " + expressionText + " language: " + language); - assertPredicate(predicate, exchange, expected); + TestSupport.assertPredicate(predicate, exchange, expected); } /** * Asserts that the language name can be resolved */ protected Language assertResolveLanguage(String languageName) { Language language = context.resolveLanguage(languageName); - assertNotNull(language, "No language found for name: " + languageName); + assertNotNull(language, "Nog language found for name: " + languageName); Review Comment: Typo here. ########## components/camel-qdrant/src/test/java/org/apache/camel/component/qdrant/QdrantUpsertManualIT.java: ########## @@ -31,7 +31,7 @@ import static io.qdrant.client.ValueFactory.value; import static org.assertj.core.api.Assertions.assertThat; -public class QdrantUpsertTest extends QdrantTestSupport { +public class QdrantUpsertManualIT extends QdrantTestSupport { Review Comment: These are other changes in components (`camel-qdrant` and `camel-lucene`) are outside the context of this PR. ########## core/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java: ########## @@ -258,7 +773,55 @@ protected <T extends Endpoint> T resolveMandatoryEndpoint(String uri, Class<T> e * @return the mandatory mock endpoint or an exception is thrown if it could not be resolved */ protected MockEndpoint getMockEndpoint(String uri) { - return resolveMandatoryEndpoint(uri, MockEndpoint.class); + return getMockEndpoint(uri, true); + } + + /** + * Resolves the {@link MockEndpoint} using a URI of the form <code>mock:someName</code>, optionally creating it if + * it does not exist. This implementation will lookup existing mock endpoints and match on the mock queue name, eg + * mock:foo and mock:foo?retainFirst=5 would match as the queue name is foo. + * + * @param uri the URI which typically starts with "mock:" and has some name + * @param create whether or not to allow the endpoint to be created if it doesn't exist + * @return the mock endpoint or an {@link NoSuchEndpointException} is thrown if it could not + * be resolved + * @throws NoSuchEndpointException is the mock endpoint does not exist + */ + protected MockEndpoint getMockEndpoint(String uri, boolean create) throws NoSuchEndpointException { + // look for existing mock endpoints that have the same queue name, and + // to + // do that we need to normalize uri and strip out query parameters and + // whatnot + String n; + try { + n = URISupport.normalizeUri(uri); + } catch (URISyntaxException e) { + throw RuntimeCamelException.wrapRuntimeException(e); + } + // strip query + final String target = StringHelper.before(n, "?", n); + + // lookup endpoints in registry and try to find it + MockEndpoint found = (MockEndpoint) context.getEndpointRegistry().values().stream() + .filter(e -> e instanceof MockEndpoint).filter(e -> { + String t = e.getEndpointUri(); + // strip query + int idx2 = t.indexOf('?'); + if (idx2 != -1) { + t = t.substring(0, idx2); + } + return t.equals(target); + }).findFirst().orElse(null); + + if (found != null) { + return found; + } + + if (create) { + return resolveMandatoryEndpoint(uri, MockEndpoint.class); + } else { + throw new NoSuchEndpointException(String.format("MockEndpoint %s does not exist.", uri)); + } Review Comment: This one seems similar enough to what we have in the `CamelTestSupport` that I wonder if it should be de-duplicated in this PR. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org