|
| 1 | +/* |
| 2 | + * Copyright 2024 openGemini Authors |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package io.opengemini.client.spring.data.core; |
| 18 | + |
| 19 | +import io.github.openfacade.http.HttpClientConfig; |
| 20 | +import io.github.openfacade.http.HttpClientEngine; |
| 21 | +import io.opengemini.client.api.Configuration; |
| 22 | +import org.junit.jupiter.api.Assertions; |
| 23 | +import org.junit.jupiter.api.Test; |
| 24 | +import org.springframework.beans.factory.ObjectProvider; |
| 25 | +import org.springframework.beans.factory.support.StaticListableBeanFactory; |
| 26 | + |
| 27 | +import java.time.Duration; |
| 28 | + |
| 29 | +class OpenGeminiPropertiesConverterTest { |
| 30 | + |
| 31 | + @Test |
| 32 | + void toConfiguration_should_right_for_convert_http_config() { |
| 33 | + OpenGeminiProperties.Http http = new OpenGeminiProperties.Http(); |
| 34 | + http.setEngine(HttpClientEngine.OkHttp); |
| 35 | + http.setTimeout(Duration.ofSeconds(30)); |
| 36 | + http.setConnectTimeout(Duration.ofSeconds(10)); |
| 37 | + |
| 38 | + OpenGeminiProperties properties = new OpenGeminiProperties(); |
| 39 | + properties.setHttp(http); |
| 40 | + |
| 41 | + ObjectProvider<ClientConfigurationBuilderCustomizer> provider = |
| 42 | + new StaticListableBeanFactory().getBeanProvider(ClientConfigurationBuilderCustomizer.class); |
| 43 | + OpenGeminiPropertiesConverter converter = new OpenGeminiPropertiesConverter(properties, provider); |
| 44 | + |
| 45 | + Configuration configuration = converter.toConfiguration(); |
| 46 | + HttpClientConfig httpConfig = configuration.getHttpConfig(); |
| 47 | + |
| 48 | + Assertions.assertEquals(http.getEngine(), httpConfig.engine()); |
| 49 | + Assertions.assertEquals(http.getTimeout(), httpConfig.timeout()); |
| 50 | + Assertions.assertEquals(http.getConnectTimeout(), httpConfig.connectTimeout()); |
| 51 | + } |
| 52 | +} |
0 commit comments