-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add collectionName
and databaseName
attributes to MongoDbProvider
#3322
base: main
Are you sure you want to change the base?
Changes from all commits
91a0db4
1836809
9d9608d
aa4c0bc
b746300
3bd99b7
73b96f2
c1dd909
a6dcb4f
bd66bc7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to you 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 | ||
* | ||
* http://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.apache.logging.log4j.mongodb; | ||
|
||
import com.mongodb.client.MongoClient; | ||
import org.apache.logging.log4j.core.LoggerContext; | ||
import org.apache.logging.log4j.core.test.junit.LoggerContextSource; | ||
import org.apache.logging.log4j.test.junit.UsingStatusListener; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@UsingMongoDb | ||
@LoggerContextSource("MongoDbCollectionNameIT.xml") | ||
// Print debug status logger output upon failure | ||
@UsingStatusListener | ||
class MongoDbCollectionNameIT extends AbstractMongoDbCappedIT { | ||
ppkarwasz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@Test | ||
@Override | ||
protected void test(LoggerContext ctx, MongoClient mongoClient) { | ||
super.test(ctx, mongoClient); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to you 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 | ||
* | ||
* http://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.apache.logging.log4j.mongodb; | ||
|
||
import com.mongodb.client.MongoClient; | ||
import org.apache.logging.log4j.core.LoggerContext; | ||
import org.apache.logging.log4j.core.test.junit.LoggerContextSource; | ||
import org.apache.logging.log4j.test.junit.UsingStatusListener; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@UsingMongoDb | ||
@LoggerContextSource("MongoDbDatabaseAndCollectionNameIT.xml") | ||
// Print debug status logger output upon failure | ||
@UsingStatusListener | ||
class MongoDbDatabaseAndCollectionNameIT extends AbstractMongoDbCappedIT { | ||
|
||
@Test | ||
@Override | ||
protected void test(LoggerContext ctx, MongoClient mongoClient) { | ||
super.test(ctx, mongoClient); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to you 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 | ||
* | ||
* http://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.apache.logging.log4j.mongodb; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class MongoDbProviderTest { | ||
|
||
private String validConnectionStringWithoutDatabase = "mongodb://localhost:27017"; | ||
private String validConnectionStringWithDatabase = "mongodb://localhost:27017/logging"; | ||
private String validConnectionStringWithDatabaseAndCollection = "mongodb://localhost:27017/logging.logs"; | ||
|
||
private String collectionName = "logsTest"; | ||
private String databaseName = "loggingTest"; | ||
Comment on lines
+27
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Could you make all these |
||
|
||
@Test | ||
void createProviderWithDatabaseAndCollectionProvidedViaConfig() { | ||
|
||
MongoDbProvider provider = MongoDbProvider.newBuilder() | ||
.setConnectionStringSource(this.validConnectionStringWithoutDatabase) | ||
.setDatabaseName(this.databaseName) | ||
.setCollectionName(this.collectionName) | ||
.build(); | ||
|
||
assertNotNull(provider, "Returned provider is null"); | ||
assertEquals( | ||
this.collectionName, | ||
provider.getConnection().getCollection().getNamespace().getCollectionName(), | ||
"Collection names do not match"); | ||
assertEquals( | ||
this.databaseName, | ||
provider.getConnection().getCollection().getNamespace().getDatabaseName(), | ||
"Database names do not match"); | ||
Comment on lines
+43
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All checks are pretty self-explanatory. Could you remove all messages ( |
||
} | ||
|
||
@Test | ||
void createProviderWithoutDatabaseName() { | ||
|
||
MongoDbProvider provider = MongoDbProvider.newBuilder() | ||
.setConnectionStringSource(this.validConnectionStringWithoutDatabase) | ||
.build(); | ||
|
||
assertNull(provider, "Provider should be null but was not"); | ||
} | ||
|
||
@Test | ||
void createProviderWithoutDatabaseNameWithCollectionName() { | ||
|
||
MongoDbProvider provider = MongoDbProvider.newBuilder() | ||
.setConnectionStringSource(this.validConnectionStringWithoutDatabase) | ||
.setCollectionName(this.collectionName) | ||
.build(); | ||
|
||
assertNull(provider, "Provider should be null but was not"); | ||
} | ||
|
||
@Test | ||
void createProviderWithoutCollectionName() { | ||
|
||
MongoDbProvider provider = MongoDbProvider.newBuilder() | ||
.setConnectionStringSource(this.validConnectionStringWithoutDatabase) | ||
.setDatabaseName(this.databaseName) | ||
.build(); | ||
|
||
assertNull(provider, "Provider should be null but was not"); | ||
} | ||
|
||
@Test | ||
void createProviderWithDatabaseOnConnectionString() { | ||
MongoDbProvider provider = MongoDbProvider.newBuilder() | ||
.setConnectionStringSource(this.validConnectionStringWithDatabase) | ||
.setCollectionName(this.collectionName) | ||
.build(); | ||
|
||
assertNotNull(provider, "Provider should not be null"); | ||
assertEquals( | ||
this.collectionName, | ||
provider.getConnection().getCollection().getNamespace().getCollectionName(), | ||
"Provider should be null but was not"); | ||
assertEquals( | ||
"logging", | ||
provider.getConnection().getCollection().getNamespace().getDatabaseName(), | ||
"Database names do not match"); | ||
} | ||
|
||
@Test | ||
void createProviderConfigOverridesConnectionString() { | ||
|
||
MongoDbProvider provider = MongoDbProvider.newBuilder() | ||
.setConnectionStringSource(this.validConnectionStringWithDatabaseAndCollection) | ||
.setCollectionName(this.collectionName) | ||
.setDatabaseName(this.databaseName) | ||
.build(); | ||
|
||
assertNotNull(provider, "Provider should not be null"); | ||
assertEquals( | ||
this.collectionName, | ||
provider.getConnection().getCollection().getNamespace().getCollectionName(), | ||
"Collection name does not match provided configuration"); | ||
assertEquals( | ||
this.databaseName, | ||
provider.getConnection().getCollection().getNamespace().getDatabaseName(), | ||
"Database name does not match provided configuration"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove the entire
<configuration>
, since<skip>false
is the default.