Skip to content

Commit

Permalink
Merge pull request #35370 from dreis2211
Browse files Browse the repository at this point in the history
* pr/35370:
  Fix configuring replica set via PropertiesMongoConnectionDetails

Closes gh-35370
  • Loading branch information
mhalbritter committed May 10, 2023
2 parents 9f78705 + 6086e81 commit 19b81c2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ else if (this.properties.getAuthenticationDatabase() != null) {
}
if (this.properties.getReplicaSetName() != null) {
builder.append("?");
builder.append("repliceSet=");
builder.append("replicaSet=");
builder.append(this.properties.getReplicaSetName());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2012-2023 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.
* You may obtain a copy of the License at
*
* https://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.springframework.boot.autoconfigure.mongo;

import com.mongodb.ConnectionString;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

/**
* Tests for {@link PropertiesMongoConnectionDetails}.
*
* @author Christoph Dreis
*/
class PropertiesMongoConnectionDetailsTests {

private final MongoProperties properties = new MongoProperties();

@Test
void replicaSetCanBeConfigured() {
this.properties.setReplicaSetName("test");
ConnectionString connectionString = getConnectionString();
assertThat(connectionString.getRequiredReplicaSetName()).isEqualTo("test");
}

private PropertiesMongoConnectionDetails createConnectionDetails() {
return new PropertiesMongoConnectionDetails(this.properties);
}

private ConnectionString getConnectionString() {
PropertiesMongoConnectionDetails connectionDetails = createConnectionDetails();
return connectionDetails.getConnectionString();
}

}

0 comments on commit 19b81c2

Please sign in to comment.