Skip to content

#DATAMONGO-1561 #442

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

Closed
wants to merge 100 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
5bd0e21
DATAMONGO-1527 - Updated changelog.
odrotbohm Nov 23, 2016
36838ff
DATAMONGO-1327 - Added support for $stdDevSamp and $stdDevPop to aggr…
gustavodegeus Apr 9, 2016
578441e
DATAMONGO-1327 - Polishing.
christophstrobl Nov 23, 2016
2985b4c
DATAMONGO-1491 - Add support for $filter (aggregation).
christophstrobl Oct 25, 2016
3dc1e93
DATAMONGO-1491 - Polishing.
mp911de Nov 24, 2016
e631e2d
DATAMONGO-784 - Add support for comparison aggregation operators to g…
christophstrobl Nov 23, 2016
710770e
DATAMONGO-784 - Polishing.
mp911de Nov 24, 2016
b786b82
DATAMONGO-1530 - Add support for missing MongoDB 3.2 aggregation pipe…
sebge2emasphere Nov 16, 2016
a741400
DATAMONGO-1530 - Polishing.
christophstrobl Nov 21, 2016
9059a77
DATAMONGO-1534 - Fix bulk operations missing to write type info.
christophstrobl Nov 24, 2016
a799301
DATAMONGO-1525 - Improved creation of empty collections, esp. EnumSet.
odrotbohm Nov 7, 2016
8c838e8
DATAMONGO-1539 - Introduce @CountQuery and @DeleteQuery.
firatkucuk Nov 24, 2016
9ff86fe
DATAMONGO-1539 - Polishing.
odrotbohm Dec 2, 2016
63d6234
DATAMONGO-1536 - Add aggregation operators for array, arithmetic, dat…
christophstrobl Nov 28, 2016
bbfa0f7
DATAMONGO-1536 - Polishing.
mp911de Dec 2, 2016
3ae6aeb
DATAMONGO-1454 - Add support for exists projection in repository quer…
mp911de Jun 28, 2016
40da470
DATAMONGO-1454 - Polishing.
odrotbohm Dec 2, 2016
7f39c42
DATAMONGO-1141 - Add support for $push $sort in Update.
pavelvodrazka Nov 2, 2016
c6a4e71
DATAMONGO-1141 - Polishing.
mp911de Dec 2, 2016
407affb
DATAMONGO-1141 - Polishing.
odrotbohm Dec 2, 2016
438dbc4
DATAMONGO-1546 - Register GeoJsonConfiguration via spring.factories.
odrotbohm Dec 5, 2016
a0be890
DATAMONGO-1547 - Register MongoRepositoryFactory in spring.factories.
odrotbohm Dec 5, 2016
1923994
DATAMONGO-1540 - Add support for $map (aggregation).
christophstrobl Dec 2, 2016
a0ac351
DATAMONGO-1540 - Polishing.
mp911de Dec 5, 2016
ea4782c
DATAMONGO-1520 - Add overload for aggregation $match accepting Criter…
christophstrobl Nov 18, 2016
1a11877
DATAMONGO-1542 - Refactor CondOperator and IfNullOperator to children…
mp911de Dec 5, 2016
c9dfeea
DATAMONGO-1542 - Polishing.
christophstrobl Dec 6, 2016
68db0d4
DATAMONGO-1538 - Add support for $let to aggregation.
christophstrobl Nov 24, 2016
3d8b686
DATAMONGO-1538 - Polishing.
mp911de Dec 6, 2016
0449719
DATAMONGO-1548 - Add support for MongoDB 3.4 aggregation operators.
christophstrobl Dec 6, 2016
dc57b66
DATAMONGO-1548 - Polishing.
mp911de Dec 12, 2016
7b49b12
DATAMONGO-1558 - Upgrade MongoDB server version to, and add build pro…
christophstrobl Dec 12, 2016
cab3575
DATAMONGO-1549 - Add $count aggregation stage.
mp911de Dec 7, 2016
4e56d9c
DATAMONGO-1549 - Polishing $count (aggregation stage).
christophstrobl Dec 12, 2016
14678ce
DATAMONGO-1550 - Add $replaceRoot aggregation stage.
mp911de Dec 7, 2016
c1c7daf
DATAMONGO-1550 - Polishing $replaceRoot (aggregation stage).
christophstrobl Dec 12, 2016
c6dae3c
DATAMONGO-1551 - Add $graphLookup aggregation stage.
mp911de Dec 8, 2016
204a051
DATAMONGO-1551 - Polishing.
christophstrobl Dec 13, 2016
9737464
DATAMONGO-442 - Support username/password authentication with MongoLo…
Dec 1, 2016
aa1e91c
DATAMONGO-442 - Polishing.
mp911de Dec 13, 2016
e992d81
DATAMONGO-1552 - Add $bucket aggregation stage.
mp911de Dec 9, 2016
2c4377c
DATAMONGO-1552 - Add $bucketAuto aggregation stage.
mp911de Dec 9, 2016
bcb63b2
DATAMONGO-1552 - Add $facet aggregation stage.
mp911de Dec 9, 2016
d250f88
DATAMONGO-1552 - Update Documentation.
mp911de Dec 9, 2016
c9c5fe6
DATAMONGO-1552 - Polishing.
christophstrobl Dec 14, 2016
89a02bb
DATAMONGO-1566 - Adapt API in MongoRepositoryFactoryBean.
odrotbohm Dec 15, 2016
35bfb92
DATAMONGO-1533 - Add AggregationExpression derived from SpEL AST.
christophstrobl Dec 14, 2016
6993054
DATAMONGO-1533 - Polishing.
mp911de Dec 16, 2016
6236384
DATAMONGO-1567 - Use newer Java 8 on Travis CI.
mp911de Dec 16, 2016
7513904
DATAMONGO-1564 - Split up AggregationExpressions.
christophstrobl Dec 15, 2016
f026ab4
DATAMONGO-1564 - Polishing.
mp911de Dec 16, 2016
14e326d
DATAMONGO-1565 - Ignore placeholder pattern in replacement values for…
christophstrobl Dec 15, 2016
1a10533
DATAMONGO-1565 - Polishing.
mp911de Dec 16, 2016
29e405b
DATAMONGO-1565 - Polishing.
odrotbohm Dec 19, 2016
dc4a30a
DATAMONGO-1467 - Add support for MongoDB 3.2 partialFilterExpression …
christophstrobl Dec 19, 2016
7914e8a
DATAMONGO-1467 - Polishing.
odrotbohm Dec 19, 2016
982adf3
DATAMONGO-1469 - Updated changelog.
odrotbohm Dec 21, 2016
408c5d8
DATAMONGO-1469 - Prepare 1.10 RC1 (Ingalls).
odrotbohm Dec 21, 2016
737f7b4
DATAMONGO-1469 - Release version 1.10 RC1 (Ingalls).
odrotbohm Dec 21, 2016
e55e748
DATAMONGO-1469 - Prepare next development iteration.
odrotbohm Dec 21, 2016
320a287
DATAMONGO-1469 - After release cleanups.
odrotbohm Dec 21, 2016
a96752d
DATAMONGO-1522 - Updated changelog.
odrotbohm Dec 21, 2016
fda72d6
DATAMONGO-1508 - Document authentication-dbname attribute in db-factory.
Oct 10, 2016
e784e58
DATAMONGO-1508 - Polishing.
mp911de Jan 2, 2017
e838662
DATAMONGO-1577 - Fix Reference and JavaDoc spelling issues.
kdombeck Dec 8, 2016
8149273
DATAMONGO-1577 - Fix wording repetition in MongoRepository JavaDoc.
kryger Nov 15, 2016
97a03d8
DATAMONGO-1508 - Improve reference documentation.
mp911de Jan 2, 2017
9f33199
DATAMONGO-1578 - Add missing @Test annotation to ProjectionOperationU…
LinkedList Oct 9, 2016
3c6db34
DATAMONGO-1578 - Polishing.
mp911de Jan 2, 2017
8340c02
DATAMONGO-1576 - Update lifecycle event documentation.
christophstrobl Jan 10, 2017
c3e5fca
DATAMONGO-1585 - Expose synthetic fields in $project aggregation stage.
mp911de Jan 9, 2017
437bf89
DATAMONGO-1585 - Polishing.
christophstrobl Jan 10, 2017
174f7f0
DATAMONGO-1586 - Consider field name in TypeBasedAggregationOperation…
mp911de Jan 9, 2017
27651ef
DATAMONGO-1587 - Migrate ticket references in test code to Spring Fra…
mp911de Jan 12, 2017
7ab7212
DATAMONGO-1587 - Polishing.
mp911de Jan 12, 2017
8f7ea3a
DATAMONGO-1589 - Update project documentation with the CLA tool integ…
mp911de Jan 13, 2017
35fa922
DATAMONGO-1588 - Fix derived finder not accepting subclass of paramet…
christophstrobl Jan 13, 2017
3476c63
DATAMONGO-1588 - Polishing.
mp911de Jan 16, 2017
822e295
DATAMONGO-1590 - EntityInformation selected now correctly considers P…
christophstrobl Jan 16, 2017
45818f2
DATAMONGO-1590 - Polishing.
odrotbohm Jan 18, 2017
98b3c16
DATAMONGO-1592 - Adapt AuditingEventListenerUnitTests to changes in c…
odrotbohm Jan 20, 2017
3ed72a9
DATAMONGO-1594 - Update "what’s new" section in reference documentation.
christophstrobl Jan 20, 2017
6f278ce
DATAMONGO-1575 - Escape Strings correctly.
christophstrobl Dec 22, 2016
b9aa410
DATAMONGO-1575 - Polishing.
mp911de Jan 2, 2017
d2d162d
DATAMONGO-1596 - Fix typo in JavaDoc.
mp911de Jan 25, 2017
8e3d7f9
DATAMONGO-1517 - Add support for Decimal128 BSON type.
mp911de Jan 3, 2017
7413a03
DATAMONGO-1517 - Polishing.
christophstrobl Jan 12, 2017
d046f30
DATAMONGO-1574 - Updated changelog.
odrotbohm Jan 26, 2017
52b52db
DATAMONGO-1574 - Prepare 1.10 GA (Ingalls).
odrotbohm Jan 26, 2017
d5fec09
DATAMONGO-1574 - Release version 1.10 GA (Ingalls).
odrotbohm Jan 26, 2017
3e4ce05
DATAMONGO-1574 - Prepare next development iteration.
odrotbohm Jan 26, 2017
b79474c
DATAMONGO-1574 - After release cleanups.
odrotbohm Jan 26, 2017
18e00a9
DATAMONGO-1602 - Remove references to Assert single-arg methods.
mp911de Jan 31, 2017
7b5233c
DATAMONGO-1607 - Fix ClassCastException in Circle, Point and Sphere w…
thiagodsti Feb 3, 2017
f6efd69
DATAMONGO-1607 - Polishing.
christophstrobl Feb 10, 2017
fb3789b
DATAMONGO-1608 - Add guard against NPE in MongoQueryCreator when usin…
EdwardPrentice Feb 7, 2017
71fbb91
DATAMONGO-1608 - Polishing.
christophstrobl Feb 10, 2017
fe1dd25
#DATAMONGO-1561 :
yacota Feb 18, 2017
a1a87c0
#DATAMONGO-1561 :
yacota Feb 18, 2017
7ff24a5
Merge origin/master
yacota Feb 18, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 4 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<!--

Thank you for proposing a pull request. This template will guide you through the essential steps necessary for a pull request.
Make sure that:

-->

- [ ] You have read the [Spring Data contribution guidelines](https://github.com/spring-projects/spring-data-build/blob/master/CONTRIBUTING.adoc).
- [ ] There is a ticket in the bug tracker for the project in our [JIRA](https://jira.spring.io/browse/DATAMONGO).
- [ ] You use the code formatters provided [here](https://github.com/spring-projects/spring-data-build/tree/master/etc/ide) and have them applied to your changes. Don’t submit any formatting related changes.
- [ ] You submit test cases (unit or integration tests) that back your changes.
- [ ] You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).
- [ ] You provide your full name and an email address registered with your GitHub account. If you’re a first-time submitter, make sure you have completed the [Contributor’s License Agreement form](https://support.springsource.com/spring_committer_signup).
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ env:
- PROFILE=mongo31
- PROFILE=mongo32
- PROFILE=mongo33
- PROFILE=mongo34
- PROFILE=mongo34-next

# Current MongoDB version is 2.4.2 as of 2016-04, see https://github.com/travis-ci/travis-ci/issues/3694
# apt-get starts a MongoDB instance so it's not started using before_script
addons:
apt:
sources:
- mongodb-3.2-precise
- mongodb-3.4-precise
packages:
- mongodb-org-server
- mongodb-org-shell
- oracle-java8-installer

sudo: false

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ public class MyService {
Here are some ways for you to get involved in the community:

* Get involved with the Spring community on Stackoverflow and help out on the [spring-data-mongodb](http://stackoverflow.com/questions/tagged/spring-data-mongodb) tag by responding to questions and joining the debate.
* Create [JIRA](https://jira.springframework.org/browse/DATADOC) tickets for bugs and new features and comment and vote on the ones that you are interested in.
* Create [JIRA](https://jira.spring.io/browse/DATAMONGO) tickets for bugs and new features and comment and vote on the ones that you are interested in.
* Github is for social coding: if you want to write code, we encourage contributions through pull requests from [forks of this repository](http://help.github.com/forking/). If you want to contribute code this way, please reference a JIRA ticket as well covering the specific issue you are addressing.
* Watch for upcoming articles on Spring by [subscribing](http://spring.io/blog) to spring.io.

Before we accept a non-trivial patch or pull request we will need you to sign the [contributor's agreement](https://support.springsource.com/spring_committer_signup). Signing the contributor's agreement does not grant anyone commit rights to the main repository, but it does mean that we can accept your contributions, and you will get an author credit if we do. Active contributors might be asked to join the core team, and given the ability to merge pull requests.
Before we accept a non-trivial patch or pull request we will need you to [sign the Contributor License Agreement](https://cla.pivotal.io/sign/spring). Signing the contributors agreement does not grant anyone commit rights to the main repository, but it does mean that we can accept your contributions, and you will get an author credit if we do. If you forget to do so, you'll be reminded when you submit a pull request. Active contributors might be asked to join the core team, and given the ability to merge pull requests.
17 changes: 13 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>1.10.0.BUILD-SNAPSHOT</version>
<version>1.11.0.BUILD-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data MongoDB</name>
Expand All @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data.build</groupId>
<artifactId>spring-data-parent</artifactId>
<version>1.9.0.BUILD-SNAPSHOT</version>
<version>1.10.0.BUILD-SNAPSHOT</version>
</parent>

<modules>
Expand All @@ -28,7 +28,7 @@
<properties>
<project.type>multi</project.type>
<dist.id>spring-data-mongodb</dist.id>
<springdata.commons>1.13.0.BUILD-SNAPSHOT</springdata.commons>
<springdata.commons>1.14.0.BUILD-SNAPSHOT</springdata.commons>
<mongo>2.14.3</mongo>
<mongo.osgi>2.13.0</mongo.osgi>
</properties>
Expand Down Expand Up @@ -178,11 +178,20 @@

</profile>

<profile>

<id>mongo34</id>
<properties>
<mongo>3.4.0</mongo>
</properties>

</profile>

<profile>

<id>mongo34-next</id>
<properties>
<mongo>3.4.0-SNAPSHOT</mongo>
<mongo>3.4.1-SNAPSHOT</mongo>
</properties>

<repositories>
Expand Down
4 changes: 2 additions & 2 deletions spring-data-mongodb-cross-store/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>1.10.0.BUILD-SNAPSHOT</version>
<version>1.11.0.BUILD-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -48,7 +48,7 @@
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.10.0.BUILD-SNAPSHOT</version>
<version>1.11.0.BUILD-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
2 changes: 1 addition & 1 deletion spring-data-mongodb-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>1.10.0.BUILD-SNAPSHOT</version>
<version>1.11.0.BUILD-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-mongodb-log4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>1.10.0.BUILD-SNAPSHOT</version>
<version>1.11.0.BUILD-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.apache.log4j.AppenderSkeleton;
Expand All @@ -31,14 +33,17 @@
import com.mongodb.DB;
import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
import com.mongodb.WriteConcern;

/**
* Log4j appender writing log entries into a MongoDB instance.
*
*
* @author Jon Brisbin
* @author Oliver Gierke
* @auhtor Christoph Strobl
* @author Christoph Strobl
* @author Ricardo Espirito Santo
*/
public class MongoLog4jAppender extends AppenderSkeleton {

Expand All @@ -56,6 +61,9 @@ public class MongoLog4jAppender extends AppenderSkeleton {

protected String host = "localhost";
protected int port = 27017;
protected String username;
protected String password;
protected String authenticationDatabase;
protected String database = "logs";
protected String collectionPattern = "%c";
protected PatternLayout collectionLayout = new PatternLayout(collectionPattern);
Expand All @@ -65,8 +73,7 @@ public class MongoLog4jAppender extends AppenderSkeleton {
protected Mongo mongo;
protected DB db;

public MongoLog4jAppender() {
}
public MongoLog4jAppender() {}

public MongoLog4jAppender(boolean isActive) {
super(isActive);
Expand All @@ -88,6 +95,53 @@ public void setPort(int port) {
this.port = port;
}

/**
* @return
* @since 1.10
*/
public String getUsername() {
return username;
}

/**
* @param username may be {@literal null} for unauthenticated access.
* @since 1.10
*/
public void setUsername(String username) {
this.username = username;
}

/**
* @return
* @since 1.10
*/
public String getPassword() {
return password;
}

/**
* @param password may be {@literal null} for unauthenticated access.
* @since 1.10
*/
public void setPassword(String password) {
this.password = password;
}

/**
* @return
*/
public String getAuthenticationDatabase() {
return authenticationDatabase;
}

/**
* @param authenticationDatabase may be {@literal null} to use {@link #getDatabase()} as authentication database.
* @since 1.10
*/
public void setAuthenticationDatabase(String authenticationDatabase) {
this.authenticationDatabase = authenticationDatabase;
}

public String getDatabase() {
return database;
}
Expand All @@ -113,14 +167,14 @@ public void setApplicationId(String applicationId) {
this.applicationId = applicationId;
}

public void setWarnOrHigherWriteConcern(String wc) {
this.warnOrHigherWriteConcern = WriteConcern.valueOf(wc);
}

public String getWarnOrHigherWriteConcern() {
return warnOrHigherWriteConcern.toString();
}

public void setWarnOrHigherWriteConcern(String wc) {
this.warnOrHigherWriteConcern = WriteConcern.valueOf(wc);
}

public String getInfoOrLowerWriteConcern() {
return infoOrLowerWriteConcern.toString();
}
Expand All @@ -130,10 +184,26 @@ public void setInfoOrLowerWriteConcern(String wc) {
}

protected void connectToMongo() throws UnknownHostException {
this.mongo = new MongoClient(host, port);

this.mongo = createMongoClient();
this.db = mongo.getDB(database);
}

private MongoClient createMongoClient() throws UnknownHostException {

ServerAddress serverAddress = new ServerAddress(host, port);

if (null == password || null == username) {
return new MongoClient(serverAddress);
}

String authenticationDatabaseToUse = authenticationDatabase == null ? this.database : authenticationDatabase;
MongoCredential mongoCredential = MongoCredential.createCredential(username,
authenticationDatabaseToUse, password.toCharArray());
List<MongoCredential> credentials = Collections.singletonList(mongoCredential);
return new MongoClient(serverAddress, credentials);
}

/*
* (non-Javadoc)
* @see org.apache.log4j.AppenderSkeleton#append(org.apache.log4j.spi.LoggingEvent)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* Copyright 2016 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
*
* 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.springframework.data.mongodb.log4j;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;

import java.util.Calendar;
import java.util.Collections;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.log4j.MDC;
import org.apache.log4j.PropertyConfigurator;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject;
import com.mongodb.BasicDBObjectBuilder;
import com.mongodb.DB;
import com.mongodb.DBCursor;
import com.mongodb.MongoClient;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;

/**
* Integration tests for {@link MongoLog4jAppender} using authentication.
*
* @author Mark Paluch
*/
public class MongoLog4jAppenderAuthenticationIntegrationTests {

private final static String username = "admin";
private final static String password = "test";
private final static String authenticationDatabase = "logs";

MongoClient mongo;
DB db;
String collection;
ServerAddress serverLocation;

Logger log;

@Before
public void setUp() throws Exception {

serverLocation = new ServerAddress("localhost", 27017);

mongo = new MongoClient(serverLocation);
db = mongo.getDB("logs");

BasicDBList roles = new BasicDBList();
roles.add("dbOwner");
db.command(new BasicDBObjectBuilder().add("createUser", username).add("pwd", password).add("roles", roles).get());
mongo.close();

mongo = new MongoClient(serverLocation, Collections
.singletonList(MongoCredential.createCredential(username, authenticationDatabase, password.toCharArray())));
db = mongo.getDB("logs");

Calendar now = Calendar.getInstance();
collection = String.valueOf(now.get(Calendar.YEAR)) + String.format("%1$02d", now.get(Calendar.MONTH) + 1);

LogManager.resetConfiguration();
PropertyConfigurator.configure(getClass().getResource("/log4j-with-authentication.properties"));

log = Logger.getLogger(MongoLog4jAppenderIntegrationTests.class.getName());
}

@After
public void tearDown() {

if (db != null) {
db.getCollection(collection).remove(new BasicDBObject());
db.command(new BasicDBObject("dropUser", username));
}

LogManager.resetConfiguration();
PropertyConfigurator.configure(getClass().getResource("/log4j.properties"));
}

@Test
public void testLogging() {

log.debug("DEBUG message");
log.info("INFO message");
log.warn("WARN message");
log.error("ERROR message");

DBCursor msgs = db.getCollection(collection).find();
assertThat(msgs.count(), is(4));
}

@Test
public void testProperties() {
MDC.put("property", "one");
log.debug("DEBUG message");
}
}
Loading