|
22 | 22 |
|
23 | 23 | import java.net.UnknownHostException;
|
24 | 24 |
|
| 25 | +import org.junit.Rule; |
25 | 26 | import org.junit.Test;
|
| 27 | +import org.junit.rules.ExpectedException; |
26 | 28 | import org.junit.runner.RunWith;
|
27 | 29 | import org.mockito.Mock;
|
28 | 30 | import org.mockito.runners.MockitoJUnitRunner;
|
| 31 | +import org.springframework.dao.InvalidDataAccessApiUsageException; |
29 | 32 | import org.springframework.data.authentication.UserCredentials;
|
30 | 33 | import org.springframework.data.mongodb.MongoDbFactory;
|
31 | 34 |
|
|
43 | 46 | @RunWith(MockitoJUnitRunner.class)
|
44 | 47 | public class SimpleMongoDbFactoryUnitTests {
|
45 | 48 |
|
| 49 | + public @Rule ExpectedException expectedException = ExpectedException.none(); |
46 | 50 | @Mock Mongo mongo;
|
47 | 51 |
|
48 | 52 | /**
|
@@ -115,6 +119,46 @@ public void shouldDefaultAuthenticationDbNameToDbNameWhenUsingMongoClient() thro
|
115 | 119 | assertThat(getField(factory, "authenticationDatabaseName").toString(), is("FooBar"));
|
116 | 120 | }
|
117 | 121 |
|
| 122 | + /** |
| 123 | + * @see DATAMONGO-1260 |
| 124 | + */ |
| 125 | + @Test |
| 126 | + public void rejectsMongoClientWithUserCredentials() { |
| 127 | + |
| 128 | + expectedException.expect(InvalidDataAccessApiUsageException.class); |
| 129 | + expectedException.expectMessage("use 'MongoCredential' for 'MongoClient'"); |
| 130 | + |
| 131 | + new SimpleMongoDbFactory(mock(MongoClient.class), "cairhienin", new UserCredentials("moiraine", "sedai")); |
| 132 | + } |
| 133 | + |
| 134 | + /** |
| 135 | + * @see DATAMONGO-1260 |
| 136 | + */ |
| 137 | + @Test |
| 138 | + public void rejectsMongoClientWithUserCredentialsAndAuthDb() { |
| 139 | + |
| 140 | + expectedException.expect(InvalidDataAccessApiUsageException.class); |
| 141 | + expectedException.expectMessage("use 'MongoCredential' for 'MongoClient'"); |
| 142 | + |
| 143 | + new SimpleMongoDbFactory(mock(MongoClient.class), "malkieri", new UserCredentials("lan", "mandragoran"), "authdb"); |
| 144 | + } |
| 145 | + |
| 146 | + /** |
| 147 | + * @see DATAMONGO-1260 |
| 148 | + */ |
| 149 | + @Test |
| 150 | + public void shouldNotRejectMongoClientWithNoCredentials() { |
| 151 | + new SimpleMongoDbFactory(mock(MongoClient.class), "andoran", UserCredentials.NO_CREDENTIALS); |
| 152 | + } |
| 153 | + |
| 154 | + /** |
| 155 | + * @see DATAMONGO-1260 |
| 156 | + */ |
| 157 | + @Test |
| 158 | + public void shouldNotRejectMongoClientWithEmptyUserCredentials() { |
| 159 | + new SimpleMongoDbFactory(mock(MongoClient.class), "shangtai", new UserCredentials("", "")); |
| 160 | + } |
| 161 | + |
118 | 162 | @SuppressWarnings("deprecation")
|
119 | 163 | private void rejectsDatabaseName(String databaseName) {
|
120 | 164 |
|
|
0 commit comments