/*
 * 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.component.undertow.cloud;

import org.apache.camel.ResolveEndpointFailedException;
import org.apache.camel.RoutesBuilder;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class UndertowServiceCallRouteTest extends CamelTestSupport {

    @Test
    public void testCustomCall() throws Exception {
        assertEquals("8081", template.requestBody("direct:custom", "hello", String.class));
        assertEquals("8082", template.requestBody("direct:custom", "hello", String.class));
    }

    @Test
    public void testDefaultSchema() throws Exception {
        try {
            assertEquals("8081", template.requestBody("direct:default", "hello", String.class));
        } catch (RuntimeCamelException e) {
            assertTrue(e.getCause() instanceof ResolveEndpointFailedException);
        }
    }

    @Override
    protected RoutesBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("direct:custom")
                        .serviceCall()
                        .name("myService")
                        .component("undertow")
                        .staticServiceDiscovery()
                        .servers("myService@localhost:8081")
                        .servers("myService@localhost:8082")
                        .endParent();

                from("direct:default")
                        .serviceCall()
                        .name("myService")
                        .staticServiceDiscovery()
                        .servers("myService@localhost:8081")
                        .servers("myService@localhost:8082")
                        .endParent();

                from("undertow:http://localhost:8081")
                        .transform().constant("8081");
                from("undertow:http://localhost:8082")
                        .transform().constant("8082");
            }
        };
    }
}

@@ -848,16 +848,138 @@
 cloud;%0A%0A
+import org.apache.camel.CamelContext;%0Aimport org.apache.camel.ExtendedCamelContext;%0Aimport org.apache.camel.LoggingLevel;%0A
 import o
@@ -1150,32 +1150,79 @@
 r.RouteBuilder;%0A
+import org.apache.camel.spi.BeanIntrospection;%0A
 import org.apach
@@ -1495,320 +1495,985 @@
    @
-Test%0A    public void testCustomCall() throws Exception %7B%0A        assertEquals(%228081%22, template.requestBody(%22direct:custom%22, %22hello%22, String.class));%0A        assertEquals(%228082%22, template.requestBody(%22direct:custom%22, %22hello%22, String.class));%0A    %7D%0A%0A    @Test%0A    public void testDefaultSchema() throws Exception %7B
+Override%0A    protected CamelContext createCamelContext() throws Exception %7B%0A        CamelContext context = super.createCamelContext();%0A        context.adapt(ExtendedCamelContext.class).getBeanIntrospection().setExtendedStatistics(true);%0A        context.adapt(ExtendedCamelContext.class).getBeanIntrospection().setLoggingLevel(LoggingLevel.INFO);%0A        return context;%0A    %7D%0A%0A    @Test%0A    public void testCustomCall() throws Exception %7B%0A        BeanIntrospection bi = context.adapt(ExtendedCamelContext.class).getBeanIntrospection();%0A%0A        assertEquals(%228081%22, template.requestBody(%22direct:custom%22, %22hello%22, String.class));%0A        assertEquals(%228082%22, template.requestBody(%22direct:custom%22, %22hello%22, String.class));%0A%0A        // should not use reflection%0A        assertEquals(0, bi.getInvokedCounter());%0A    %7D%0A%0A    @Test%0A    public void testDefaultSchema() throws Exception %7B%0A        BeanIntrospection bi = context.adapt(ExtendedCamelContext.class).getBeanIntrospection();%0A
 %0A   
@@ -2709,24 +2709,111 @@
 );%0A        %7D
+%0A%0A        // should not use reflection%0A        assertEquals(0, bi.getInvokedCounter());
 %0A    %7D%0A%0A    

Add unit test to test serviceCall EIP does not use reflection.