|
22 | 22 |
|
23 | 23 | class MongoDb4ProviderTest { |
24 | 24 |
|
25 | | - private String validConnectionStringWithoutDatabase = "mongodb://localhost:27017"; |
26 | | - private String validConnectionStringWithDatabase = "mongodb://localhost:27017/logging"; |
27 | | - private String validConnectionStringWithDatabaseAndCollection = "mongodb://localhost:27017/logging.logs"; |
| 25 | + private static final String CON_STR_WO_DB = "mongodb://localhost:27017"; |
| 26 | + private static final String CON_STR_W_DB = "mongodb://localhost:27017/logging"; |
| 27 | + private static final String CON_STR_DB_COLL = "mongodb://localhost:27017/logging.logs"; |
28 | 28 |
|
29 | | - private String collectionName = "logsTest"; |
30 | | - private String databaseName = "loggingTest"; |
| 29 | + private static final String collectionName = "logsTest"; |
| 30 | + private static final String databaseName = "loggingTest"; |
31 | 31 |
|
32 | 32 | @Test |
33 | 33 | void createProviderWithDatabaseAndCollectionProvidedViaConfig() { |
34 | 34 |
|
35 | 35 | MongoDb4Provider provider = MongoDb4Provider.newBuilder() |
36 | | - .setConnectionStringSource(this.validConnectionStringWithoutDatabase) |
37 | | - .setDatabaseName(this.databaseName) |
38 | | - .setCollectionName(this.collectionName) |
| 36 | + .setConnectionStringSource(CON_STR_WO_DB) |
| 37 | + .setDatabaseName(databaseName) |
| 38 | + .setCollectionName(collectionName) |
39 | 39 | .build(); |
40 | 40 |
|
41 | | - assertNotNull(provider, "Returned provider is null"); |
| 41 | + assertNotNull(provider); |
42 | 42 | assertEquals( |
43 | | - this.collectionName, |
44 | | - provider.getConnection().getCollection().getNamespace().getCollectionName(), |
45 | | - "Collection names do not match"); |
| 43 | + collectionName, |
| 44 | + provider.getConnection().getCollection().getNamespace().getCollectionName()); |
46 | 45 | assertEquals( |
47 | | - this.databaseName, |
48 | | - provider.getConnection().getCollection().getNamespace().getDatabaseName(), |
49 | | - "Database names do not match"); |
| 46 | + databaseName, |
| 47 | + provider.getConnection().getCollection().getNamespace().getDatabaseName()); |
50 | 48 | } |
51 | 49 |
|
52 | 50 | @Test |
53 | 51 | void createProviderWithoutDatabaseName() { |
54 | 52 |
|
55 | 53 | MongoDb4Provider provider = MongoDb4Provider.newBuilder() |
56 | | - .setConnectionStringSource(this.validConnectionStringWithoutDatabase) |
| 54 | + .setConnectionStringSource(CON_STR_WO_DB) |
57 | 55 | .build(); |
58 | 56 |
|
59 | | - assertNull(provider, "Provider should be null but was not"); |
| 57 | + assertNull(provider); |
60 | 58 | } |
61 | 59 |
|
62 | 60 | @Test |
63 | 61 | void createProviderWithoutDatabaseNameWithCollectionName() { |
64 | 62 |
|
65 | 63 | MongoDb4Provider provider = MongoDb4Provider.newBuilder() |
66 | | - .setConnectionStringSource(this.validConnectionStringWithoutDatabase) |
67 | | - .setCollectionName(this.collectionName) |
| 64 | + .setConnectionStringSource(CON_STR_WO_DB) |
| 65 | + .setCollectionName(collectionName) |
68 | 66 | .build(); |
69 | 67 |
|
70 | | - assertNull(provider, "Provider should be null but was not"); |
| 68 | + assertNull(provider); |
71 | 69 | } |
72 | 70 |
|
73 | 71 | @Test |
74 | 72 | void createProviderWithoutCollectionName() { |
75 | 73 |
|
76 | 74 | MongoDb4Provider provider = MongoDb4Provider.newBuilder() |
77 | | - .setConnectionStringSource(this.validConnectionStringWithoutDatabase) |
78 | | - .setDatabaseName(this.databaseName) |
| 75 | + .setConnectionStringSource(CON_STR_WO_DB) |
| 76 | + .setDatabaseName(databaseName) |
79 | 77 | .build(); |
80 | 78 |
|
81 | | - assertNull(provider, "Provider should be null but was not"); |
| 79 | + assertNull(provider); |
82 | 80 | } |
83 | 81 |
|
84 | 82 | @Test |
85 | 83 | void createProviderWithDatabaseOnConnectionString() { |
86 | 84 | MongoDb4Provider provider = MongoDb4Provider.newBuilder() |
87 | | - .setConnectionStringSource(this.validConnectionStringWithDatabase) |
88 | | - .setCollectionName(this.collectionName) |
| 85 | + .setConnectionStringSource(CON_STR_W_DB) |
| 86 | + .setCollectionName(collectionName) |
89 | 87 | .build(); |
90 | 88 |
|
91 | | - assertNotNull(provider, "Provider should not be null"); |
| 89 | + assertNotNull(provider); |
92 | 90 | assertEquals( |
93 | | - this.collectionName, |
94 | | - provider.getConnection().getCollection().getNamespace().getCollectionName(), |
95 | | - "Provider should be null but was not"); |
| 91 | + collectionName, |
| 92 | + provider.getConnection().getCollection().getNamespace().getCollectionName()); |
96 | 93 | assertEquals( |
97 | 94 | "logging", |
98 | | - provider.getConnection().getCollection().getNamespace().getDatabaseName(), |
99 | | - "Database names do not match"); |
| 95 | + provider.getConnection().getCollection().getNamespace().getDatabaseName()); |
100 | 96 | } |
101 | 97 |
|
102 | 98 | @Test |
103 | 99 | void createProviderConfigOverridesConnectionString() { |
104 | 100 |
|
105 | 101 | MongoDb4Provider provider = MongoDb4Provider.newBuilder() |
106 | | - .setConnectionStringSource(this.validConnectionStringWithDatabaseAndCollection) |
107 | | - .setCollectionName(this.collectionName) |
108 | | - .setDatabaseName(this.databaseName) |
| 102 | + .setConnectionStringSource(CON_STR_DB_COLL) |
| 103 | + .setCollectionName(collectionName) |
| 104 | + .setDatabaseName(databaseName) |
109 | 105 | .build(); |
110 | 106 |
|
111 | | - assertNotNull(provider, "Provider should not be null"); |
| 107 | + assertNotNull(provider); |
112 | 108 | assertEquals( |
113 | | - this.collectionName, |
114 | | - provider.getConnection().getCollection().getNamespace().getCollectionName(), |
115 | | - "Collection name does not match provided configuration"); |
| 109 | + collectionName, |
| 110 | + provider.getConnection().getCollection().getNamespace().getCollectionName()); |
116 | 111 | assertEquals( |
117 | | - this.databaseName, |
118 | | - provider.getConnection().getCollection().getNamespace().getDatabaseName(), |
119 | | - "Database name does not match provided configuration"); |
| 112 | + databaseName, |
| 113 | + provider.getConnection().getCollection().getNamespace().getDatabaseName()); |
120 | 114 | } |
121 | 115 | } |
0 commit comments