/*
 * Copyright 2008-2019 by Emeric Vernat
 *
 *     This file is part of Java Melody.
 *
 * 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 net.bull.javamelody;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.Ordered;
import org.springframework.data.mongodb.MongoDbFactory;

import net.bull.javamelody.internal.model.Counter;

/**
 * Test unitaire de la classe SpringMongoDbFactoryBeanPostProcessor.
 * @author Emeric Vernat
 */
public class TestSpringMongoDbFactoryBeanPostProcessor {
	private static final String TEST_CONTEXT_FILENAME = "spring-context.xml";
	private static final String MONITORING_CONTEXT_FILENAME = "net/bull/javamelody/monitoring-spring.xml";

	/** Check. */
	@Before
	public void setUp() {
		Utils.initialize();
	}

	/** Test. */
	@Test
	public void testSpringAOP() {
		final Counter servicesCounter = MonitoringProxy.getServicesCounter();
		servicesCounter.clear();
		final ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
				MONITORING_CONTEXT_FILENAME, TEST_CONTEXT_FILENAME);
		try {
			final MongoDbFactory mongoDbFactory = context.getBean(MongoDbFactory.class);
			assertNotNull("toString", mongoDbFactory.toString());
			assertNotNull("getDb", mongoDbFactory.getDb());

			final SpringMongoDbFactoryBeanPostProcessor springMongoDbFactoryBeanPostProcessor = context
					.getBean(SpringMongoDbFactoryBeanPostProcessor.class);
			assertEquals("order", Ordered.LOWEST_PRECEDENCE,
					springMongoDbFactoryBeanPostProcessor.getOrder());
			springMongoDbFactoryBeanPostProcessor.setOrder(1);
			assertEquals("order", 1, springMongoDbFactoryBeanPostProcessor.getOrder());
		} finally {
			context.close();
		}
	}
}

@@ -995,16 +995,78 @@
 rdered;%0A
+import org.springframework.data.mongodb.MongoDatabaseFactory;%0A
 import o
@@ -1113,16 +1113,16 @@
 actory;%0A
-
 %0Aimport 
@@ -1268,16 +1268,49 @@
 nat%0A */%0A
+@SuppressWarnings(%22deprecation%22)%0A
 public c
@@ -2049,16 +2049,16 @@
 ing());%0A
-
 %09%09%09asser
@@ -2101,16 +2101,992 @@
 Db());%0A%0A
+%09%09%09final SpringMongoDbFactoryBeanPostProcessor springMongoDbFactoryBeanPostProcessor = context%0A%09%09%09%09%09.getBean(SpringMongoDbFactoryBeanPostProcessor.class);%0A%09%09%09assertEquals(%22order%22, Ordered.LOWEST_PRECEDENCE,%0A%09%09%09%09%09springMongoDbFactoryBeanPostProcessor.getOrder());%0A%09%09%09springMongoDbFactoryBeanPostProcessor.setOrder(1);%0A%09%09%09assertEquals(%22order%22, 1, springMongoDbFactoryBeanPostProcessor.getOrder());%0A%09%09%7D finally %7B%0A%09%09%09context.close();%0A%09%09%7D%0A%09%7D%0A%0A%09/** Test. */%0A%09@Test%0A%09public void testSpringAOP2() %7B%0A%09%09final Counter servicesCounter = MonitoringProxy.getServicesCounter();%0A%09%09servicesCounter.clear();%0A%09%09final ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(%0A%09%09%09%09MONITORING_CONTEXT_FILENAME, TEST_CONTEXT_FILENAME);%0A%09%09try %7B%0A%09%09%09final MongoDatabaseFactory mongoDatabaseFactory = context%0A%09%09%09%09%09.getBean(MongoDatabaseFactory.class);%0A%09%09%09assertNotNull(%22toString%22, mongoDatabaseFactory.toString());%0A%09%09%09assertNotNull(%22getDb%22, mongoDatabaseFactory.getMongoDatabase());%0A%0A
 %09%09%09final

upgrade test for mongodb