Skip to content

Commit

Permalink
Merge branch '3.2.x' into 3.3.x
Browse files Browse the repository at this point in the history
Closes gh-42059
  • Loading branch information
philwebb committed Aug 29, 2024
2 parents 71f509c + 1085505 commit a09af7e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,6 +23,8 @@

import com.mongodb.ConnectionString;

import org.springframework.util.StringUtils;

/**
* Adapts {@link MongoProperties} to {@link MongoConnectionDetails}.
*
Expand Down Expand Up @@ -90,7 +92,7 @@ public GridFs getGridFs() {

private List<String> getOptions() {
List<String> options = new ArrayList<>();
if (this.properties.getReplicaSetName() != null) {
if (StringUtils.hasText(this.properties.getReplicaSetName())) {
options.add("replicaSet=" + this.properties.getReplicaSetName());
}
if (this.properties.getUsername() != null && this.properties.getAuthenticationDatabase() != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -104,6 +104,20 @@ void replicaSetCanBeConfiguredWithDatabase() {
assertThat(connectionString.getRequiredReplicaSetName()).isEqualTo("test");
}

@Test
void replicaSetCanBeNull() {
this.properties.setReplicaSetName(null);
ConnectionString connectionString = getConnectionString();
assertThat(connectionString.getRequiredReplicaSetName()).isNull();
}

@Test
void replicaSetCanBeBlank() {
this.properties.setReplicaSetName("");
ConnectionString connectionString = getConnectionString();
assertThat(connectionString.getRequiredReplicaSetName()).isNull();
}

@Test
void whenAdditionalHostsAreConfiguredThenTheyAreIncludedInHostsOfConnectionString() {
this.properties.setHost("mongo1.example.com");
Expand Down

0 comments on commit a09af7e

Please sign in to comment.