/*
 * 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.infra.arangodb.services;

import org.apache.camel.test.infra.common.services.SimpleTestServiceBuilder;
import org.apache.camel.test.infra.common.services.SingletonService;
import org.junit.jupiter.api.extension.ExtensionContext;

public final class ArangoDBServiceFactory {
    private static class SingletonArangoDBService extends SingletonService<ArangoDBService> implements ArangoDBService {
        public SingletonArangoDBService(ArangoDBService service, String name) {
            super(service, name);
        }

        @Override
        public void beforeAll(ExtensionContext extensionContext) {
            addToStore(extensionContext);
        }

        @Override
        public void afterAll(ExtensionContext extensionContext) {
            // NO-OP
        }

        @Override
        public int getPort() {
            return getService().getPort();
        }

        @Override
        public String getHost() {
            return getService().getHost();
        }
    }

    private ArangoDBServiceFactory() {

    }

    public static SimpleTestServiceBuilder<ArangoDBService> builder() {
        return new SimpleTestServiceBuilder<>("arangodb");
    }

    public static ArangoDBService createService() {
        return builder()
                .addLocalMapping(ArangoDBLocalContainerService::new)
                .addRemoteMapping(ArangoDBRemoteService::new)
                .build();
    }

    public static ArangoDBService createSingletonService() {
        return builder()
                .addLocalMapping(() -> new SingletonArangoDBService(new ArangoDBLocalContainerService(), "arangoDB"))
                .addRemoteMapping(ArangoDBRemoteService::new)
                .build();
    }
}

@@ -1811,24 +1811,148 @@
    %7D%0A    %7D%0A%0A
+    private static SimpleTestServiceBuilder%3CArangoDBService%3E instance;%0A    private static ArangoDBService arangoDBService;%0A%0A
     private 
@@ -1978,16 +1978,16 @@
 ory() %7B%0A
-
 %0A    %7D%0A%0A
@@ -2426,38 +2426,126 @@
 ice() %7B%0A        
-return
+if (arangoDBService == null) %7B%0A%0A            if (instance == null) %7B%0A                instance =
  builder()%0A     
@@ -2530,32 +2530,34 @@
 ance = builder()
+;%0A
 %0A               
@@ -2549,32 +2549,40 @@
                 
+instance
 .addLocalMapping
@@ -2675,32 +2675,40 @@
                 
+        
 .addRemoteMappin
@@ -2745,32 +2745,40 @@
                 
+   
+     
 .build();%0A    %7D%0A
@@ -2767,20 +2767,126 @@
   .build();%0A
+            %7D%0A%0A            arangoDBService = instance.build();%0A        %7D%0A%0A        return arangoDBService;%0A
     %7D%0A%7D%0A

fix ArangoDB services in test infra not being singleton