diff --git a/artemis/artemis-configuration/src/main/java/org/eclipse/jnosql/artemis/configuration/keyvalue/BucketManagerFactoryConverter.java b/artemis/artemis-configuration/src/main/java/org/eclipse/jnosql/artemis/configuration/keyvalue/BucketManagerFactoryConverter.java index aa756c6c2..815a23c1e 100644 --- a/artemis/artemis-configuration/src/main/java/org/eclipse/jnosql/artemis/configuration/keyvalue/BucketManagerFactoryConverter.java +++ b/artemis/artemis-configuration/src/main/java/org/eclipse/jnosql/artemis/configuration/keyvalue/BucketManagerFactoryConverter.java @@ -1,7 +1,20 @@ +/* + * Copyright (c) 2019 Otávio Santana and others + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Apache License v2.0 which accompanies this distribution. + * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html + * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. + * + * You may elect to redistribute this code under either of these licenses. + * + * Contributors: + * + * Otavio Santana + */ package org.eclipse.jnosql.artemis.configuration.keyvalue; import jakarta.nosql.Settings; -import jakarta.nosql.keyvalue.BucketManager; import jakarta.nosql.keyvalue.BucketManagerFactory; import jakarta.nosql.keyvalue.KeyValueConfiguration; import jakarta.nosql.mapping.reflection.Reflections; diff --git a/artemis/artemis-configuration/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.Converter b/artemis/artemis-configuration/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.Converter index cbbaa1529..d82efc8dd 100644 --- a/artemis/artemis-configuration/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.Converter +++ b/artemis/artemis-configuration/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.Converter @@ -1,2 +1,3 @@ org.eclipse.jnosql.artemis.configuration.SettingsConverter -org.eclipse.jnosql.artemis.configuration.keyvalue.BucketManagerConverter \ No newline at end of file +org.eclipse.jnosql.artemis.configuration.keyvalue.BucketManagerConverter +org.eclipse.jnosql.artemis.configuration.keyvalue.BucketManagerFactoryConverter diff --git a/artemis/artemis-configuration/src/test/java/org/eclipse/jnosql/artemis/configuration/keyvalue/BucketManagerFactoryConverterTest.java b/artemis/artemis-configuration/src/test/java/org/eclipse/jnosql/artemis/configuration/keyvalue/BucketManagerFactoryConverterTest.java new file mode 100644 index 000000000..e9a913bd1 --- /dev/null +++ b/artemis/artemis-configuration/src/test/java/org/eclipse/jnosql/artemis/configuration/keyvalue/BucketManagerFactoryConverterTest.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2019 Otávio Santana and others + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Apache License v2.0 which accompanies this distribution. + * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html + * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. + * + * You may elect to redistribute this code under either of these licenses. + * + * Contributors: + * + * Otavio Santana + */ +package org.eclipse.jnosql.artemis.configuration.keyvalue; + +import jakarta.nosql.keyvalue.BucketManagerFactory; +import org.eclipse.jnosql.artemis.configuration.CDIExtension; +import org.eclipse.jnosql.artemis.configuration.ConfigurationException; +import org.eclipse.microprofile.config.Config; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import javax.inject.Inject; +import java.util.NoSuchElementException; +import java.util.UUID; + +@ExtendWith(CDIExtension.class) +class BucketManagerFactoryConverterTest { + @Inject + private Config config; + + + @Test + public void shouldReturnErrorWhenThereIsNoProvider() { + final String prefix = UUID.randomUUID().toString(); + System.setProperty(prefix, prefix); + System.setProperty(prefix + ".settings.key", "value"); + System.setProperty(prefix + ".settings.key2", "value2"); + Assertions.assertThrows(NoSuchElementException.class, () -> config.getValue(prefix, BucketManagerFactory.class) ); + + System.clearProperty(prefix); + System.clearProperty(prefix + ".settings.key"); + System.clearProperty(prefix + ".settings.key2"); + } + + + @Test + public void shouldReturnErrorWhenThereIsInvalidProvider() { + final String prefix = UUID.randomUUID().toString(); + System.setProperty(prefix, prefix); + System.setProperty(prefix + ".settings.key", "value"); + System.setProperty(prefix + ".settings.key2", "value2"); + System.setProperty(prefix + ".provider", "java.lang.String"); + Assertions.assertThrows(ConfigurationException.class, () -> config.getValue(prefix, BucketManagerFactory.class) ); + + System.clearProperty(prefix); + System.clearProperty(prefix + ".settings.key"); + System.clearProperty(prefix + ".settings.key2"); + System.clearProperty(prefix + ".provider"); + } + + + @Test + public void shouldReturnBucketManagerFactory() { + final String prefix = UUID.randomUUID().toString(); + System.setProperty(prefix, prefix); + System.setProperty(prefix + ".settings.key", "value"); + System.setProperty(prefix + ".settings.key2", "value2"); + System.setProperty(prefix + ".provider", KeyValueConfigurationMock.class.getName()); + final BucketManagerFactory managerFactory = config.getValue(prefix, BucketManagerFactory.class); + + Assertions.assertNotNull(managerFactory); + System.clearProperty(prefix); + System.clearProperty(prefix + ".settings.key"); + System.clearProperty(prefix + ".settings.key2"); + System.clearProperty(prefix + ".provider"); + } +} \ No newline at end of file diff --git a/artemis/artemis-configuration/src/test/java/org/eclipse/jnosql/artemis/configuration/keyvalue/KeyValueConfigurationMock.java b/artemis/artemis-configuration/src/test/java/org/eclipse/jnosql/artemis/configuration/keyvalue/KeyValueConfigurationMock.java index 0725b6a45..c210fc2e0 100644 --- a/artemis/artemis-configuration/src/test/java/org/eclipse/jnosql/artemis/configuration/keyvalue/KeyValueConfigurationMock.java +++ b/artemis/artemis-configuration/src/test/java/org/eclipse/jnosql/artemis/configuration/keyvalue/KeyValueConfigurationMock.java @@ -1,3 +1,17 @@ +/* + * Copyright (c) 2019 Otávio Santana and others + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Apache License v2.0 which accompanies this distribution. + * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html + * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. + * + * You may elect to redistribute this code under either of these licenses. + * + * Contributors: + * + * Otavio Santana + */ package org.eclipse.jnosql.artemis.configuration.keyvalue; import jakarta.nosql.Settings; @@ -11,6 +25,7 @@ import java.util.Set; public class KeyValueConfigurationMock implements KeyValueConfiguration { + @Override public BucketManagerFactory get() { return new BucketManagerFactoryMock(Settings.builder().build());