use of jakarta.nosql.Settings in project jnosql-diana by eclipse.
the class SettingsConverterTest method shouldLoadEmptySettings.
@Test
public void shouldLoadEmptySettings() {
System.setProperty("database", "prefix");
final Settings settings = config.getValue("database", Settings.class);
Assertions.assertNotNull(settings);
assertEquals(0, settings.size());
System.clearProperty("database");
}
use of jakarta.nosql.Settings in project jnosql-diana by eclipse.
the class SettingsConverterTest method shouldSettings.
@Test
public void shouldSettings() {
final String prefix = UUID.randomUUID().toString();
System.setProperty(prefix, prefix);
System.setProperty(prefix + ".settings.key", "value");
System.setProperty(prefix + ".settings.key2", "value2");
final Settings settings = config.getValue(prefix, Settings.class);
Assertions.assertNotNull(settings);
assertEquals(2, settings.size());
assertEquals(settings.get("key").get(), "value");
assertEquals(settings.get("key2").get(), "value2");
System.clearProperty(prefix);
System.clearProperty(prefix + ".settings.key");
System.clearProperty(prefix + ".settings.key2");
}
use of jakarta.nosql.Settings in project jnosql-diana-driver by eclipse.
the class MongoDBDocumentConfiguration method get.
@Override
public MongoDBDocumentCollectionManagerFactory get(Settings settings) throws NullPointerException {
requireNonNull(settings, "settings is required");
List<ServerAddress> servers = settings.prefix(Arrays.asList(OldMongoDBDocumentConfigurations.HOST.get(), MongoDBDocumentConfigurations.HOST.get(), Configurations.HOST.get())).stream().map(Object::toString).map(HostPortConfiguration::new).map(HostPortConfiguration::toServerAddress).collect(Collectors.toList());
if (servers.isEmpty()) {
Optional<ConnectionString> connectionString = settings.get(MongoDBDocumentConfigurations.URL.get(), String.class).map(ConnectionString::new);
return connectionString.map(c -> MongoClientSettings.builder().applyConnectionString(c).build()).map(MongoClients::create).map(MongoDBDocumentCollectionManagerFactory::new).orElseGet(() -> new MongoDBDocumentCollectionManagerFactory(MongoClients.create()));
}
Optional<MongoCredential> credential = MongoAuthentication.of(settings);
final MongoClientSettings mongoClientSettings = credential.map(c -> MongoClientSettings.builder().credential(c).applyToClusterSettings(builder -> builder.hosts(servers))).orElseGet(() -> MongoClientSettings.builder().applyToClusterSettings(builder -> builder.hosts(servers))).build();
return new MongoDBDocumentCollectionManagerFactory(MongoClients.create(mongoClientSettings));
}
use of jakarta.nosql.Settings in project jnosql-diana-driver by eclipse.
the class MongoAuthenticationTest method shouldReturnOneAuthenticationWithGSSAPI.
@Test
public void shouldReturnOneAuthenticationWithGSSAPI() {
Settings settings = Settings.builder().put(AUTHENTICATION_SOURCE.get(), "database").put(PASSWORD.get(), "password").put(USER.get(), "user").put(AUTHENTICATION_MECHANISM.get(), "GSSAPI").build();
MongoCredential credential = MongoAuthentication.of(settings).get();
assertEquals("$external", credential.getSource());
assertEquals("user", credential.getUserName());
assertEquals(GSSAPI.getMechanismName(), credential.getMechanism());
}
use of jakarta.nosql.Settings in project jnosql-diana-driver by eclipse.
the class CassandraProperties method of.
public static CassandraProperties of(Map<String, String> configurations) {
SettingsBuilder builder = Settings.builder();
configurations.entrySet().forEach(e -> builder.put(e.getKey(), e.getValue()));
Settings settings = builder.build();
CassandraProperties cp = new CassandraProperties();
settings.prefix(Arrays.asList(OldCassandraConfigurations.HOST.get(), CassandraConfigurations.HOST.get(), Configurations.HOST.get())).stream().map(Object::toString).forEach(cp::addNodes);
settings.prefix(Arrays.asList(OldCassandraConfigurations.QUERY.get(), CassandraConfigurations.QUERY.get())).stream().map(Object::toString).forEach(cp::addQuery);
cp.port = settings.get(Arrays.asList(OldCassandraConfigurations.PORT.get(), CassandraConfigurations.PORT.get())).map(Object::toString).map(Integer::parseInt).orElse(DEFAULT_PORT);
cp.name = settings.get(Arrays.asList(OldCassandraConfigurations.NAME.get(), CassandraConfigurations.NAME.get())).map(Object::toString);
cp.dataCenter = settings.get(CassandraConfigurations.DATA_CENTER.get()).map(Object::toString).orElse(DEFAULT_DATA_CENTER);
cp.user = settings.get(Configurations.USER.get()).map(Object::toString);
cp.password = settings.get(Configurations.PASSWORD.get()).map(Object::toString);
return cp;
}
Aggregations