/*
 * Copyright 2012-2019 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
 *
 *      https://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 smoketest.data.mongo;

import java.util.concurrent.TimeUnit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.mongo.MongoClientSettingsBuilderCustomizer;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class SampleMongoApplication implements CommandLineRunner {

	@Autowired
	private CustomerRepository repository;

	@Override
	public void run(String... args) throws Exception {
		this.repository.deleteAll();

		// save a couple of customers
		this.repository.save(new Customer("Alice", "Smith"));
		this.repository.save(new Customer("Bob", "Smith"));

		// fetch all customers
		System.out.println("Customers found with findAll():");
		System.out.println("-------------------------------");
		for (Customer customer : this.repository.findAll()) {
			System.out.println(customer);
		}
		System.out.println();

		// fetch an individual customer
		System.out.println("Customer found with findByFirstName('Alice'):");
		System.out.println("--------------------------------");
		System.out.println(this.repository.findByFirstName("Alice"));

		System.out.println("Customers found with findByLastName('Smith'):");
		System.out.println("--------------------------------");
		for (Customer customer : this.repository.findByLastName("Smith")) {
			System.out.println(customer);
		}
	}

	@Bean
	public MongoClientSettingsBuilderCustomizer customizer() {
		return (builder) -> builder.applyToConnectionPoolSettings(
				(connectionPool) -> connectionPool.maxConnectionIdleTime(5, TimeUnit.MINUTES));
	}

	public static void main(String[] args) {
		SpringApplication.run(SampleMongoApplication.class, args);
	}

}

@@ -20,10 +20,10 @@
 2-20
+2
 1
-9
  the
@@ -690,71 +690,8 @@
 t;%0A%0A
-import org.springframework.beans.factory.annotation.Autowired;%0A
 impo
@@ -1063,18 +1063,25 @@
 ion 
-implements
+%7B%0A%0A%09@Bean%0A%09public
  Com
@@ -1099,32 +1099,22 @@
 ner 
-%7B%0A%0A%09@Autowired%0A%09private 
+exampleRunner(
 Cust
@@ -1142,81 +1142,36 @@
 tory
-;%0A%0A%09@Override%0A%09public void run(String... args) throws Exception %7B%0A%09%09this.
+) %7B%0A%09%09return (args) -%3E %7B%0A%09%09%09
 repo
@@ -1187,24 +1187,25 @@
 leteAll();%0A%0A
+%09
 %09%09// save a 
@@ -1226,21 +1226,17 @@
 omers%0A%09%09
-this.
+%09
 reposito
@@ -1278,21 +1278,17 @@
 h%22));%0A%09%09
+%09
-this.
 reposito
@@ -1323,24 +1323,25 @@
 %22Smith%22));%0A%0A
+%09
 %09%09// fetch a
@@ -1355,16 +1355,17 @@
 omers%0A%09%09
+%09
 System.o
@@ -1407,24 +1407,25 @@
 ndAll():%22);%0A
+%09
 %09%09System.out
@@ -1461,32 +1461,33 @@
 ------------%22);%0A
+%09
 %09%09for (Customer 
@@ -1489,37 +1489,32 @@
 omer customer : 
-this.
 repository.findA
@@ -1517,24 +1517,25 @@
 indAll()) %7B%0A
+%09
 %09%09%09System.ou
@@ -1559,14 +1559,16 @@
 r);%0A
+%09
 %09%09%7D%0A%09%09
+%09
 Syst
@@ -1586,16 +1586,17 @@
 tln();%0A%0A
+%09
 %09%09// fet
@@ -1621,16 +1621,17 @@
 ustomer%0A
+%09
 %09%09System
@@ -1687,32 +1687,33 @@
 ('Alice'):%22);%0A%09%09
+%09
 System.out.print
@@ -1748,24 +1748,25 @@
 --------%22);%0A
+%09
 %09%09System.out
@@ -1774,21 +1774,16 @@
 println(
-this.
 reposito
@@ -1815,16 +1815,17 @@
 %22));%0A%0A%09%09
+%09
 System.o
@@ -1887,16 +1887,17 @@
 ):%22);%0A%09%09
+%09
 System.o
@@ -1944,16 +1944,17 @@
 ----%22);%0A
+%09
 %09%09for (C
@@ -1976,13 +1976,8 @@
 r : 
-this.
 repo
@@ -2009,24 +2009,25 @@
 ith%22)) %7B%0A%09%09%09
+%09
 System.out.p
@@ -2046,17 +2046,23 @@
 mer);%0A%09%09
-%7D
+%09%7D%0A%09%09%7D;
 %0A%09%7D%0A%0A%09@B

Remove field inject and circular reference from Data Mongo smoke test