<commit_before><!--- 
 *
 * Copyright (c) 2015, Lucee Assosication Switzerland. All rights reserved.
 * Copyright (c) 2014, the Railo Company LLC. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either 
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public 
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 * 
 ---><cfscript>
component extends="org.lucee.cfml.test.LuceeTestCase"	{

	// skip closure
	function isNotSupported() {
		variables.mongodb=getCredentials();
		if(!isNull(variables.mongodb.host)) {
			variables.supported=true;
		}
		else 
			variables.supported=false;

		return !variables.supported;
	}

	private struct function getCredentials() {
		// getting the credetials from the enviroment variables
		var mongoDB={};
		if(!isNull(server.system.environment.MONGODB_HOST) && !isNull(server.system.environment.MONGODB_PORT) && !isNull(server.system.environment.MONGODB_USERNAME) && !isNull(server.system.environment.MONGODB_PASSWORD)) {
			mongoDB.host=server.system.environment.MONGODB_HOST;
			mongoDB.port=server.system.environment.MONGODB_PORT;
			mongoDB.user=server.system.environment.MONGODB_USERNAME;
			mongoDB.pass=server.system.environment.MONGODB_PASSWORD;
		}
		// getting the credetials from the system variables
		else if(!isNull(server.system.properties.MONGODB_HOST) && !isNull(server.system.properties.MONGODB_PORT) && !isNull(server.system.properties.MONGODB_USERNAME) && !isNull(server.system.properties.MONGODB_PASSWORD)) {
			mongoDB.host=server.system.properties.MONGODB_HOST;
			mongoDB.port=server.system.properties.MONGODB_PORT;
			mongoDB.user=server.system.properties.MONGODB_USERNAME;
			mongoDB.pass=server.system.properties.MONGODB_PASSWORD;
		}
		return mongoDB;
	}

	private any function resetTestCollection() {
		var coll = db.getCollection("test");
		var docs = [
			 {"_id":1, "grp":1, "name":"One"}
			,{"_id":2, "grp":1, "name":"Two"}
			,{"_id":3, "grp":1, "name":"Three"}
			,{"_id":4, "grp":2, "name":"Four"}
			,{"_id":5, "grp":2, "name":"Five"}
		];

		coll.drop();
		coll.insert(docs);

		return coll;		
	}
	
	// public function setUp(){}

	public function beforeTests() {
		db = MongoDBConnect("test",variables.mongoDB.host,variables.mongoDB.port);
	}
	
	//public function afterTests(){}
	

	public void function testConnectByArgs() skip="isNotSupported" {
		var mongo = MongoDBConnect("test",variables.mongoDB.host,variables.mongoDB.port);
		assertEquals("test",mongo.getName());
	}
<commit_msg>Connect via URI<commit_after><!--- 
 *
 * Copyright (c) 2015, <NAME>ication Switzerland. All rights reserved.
 * Copyright (c) 2014, the Railo Company LLC. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either 
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public 
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 * 
 ---><cfscript>
component extends="org.lucee.cfml.test.LuceeTestCase"	{

	// skip closure
	function isNotSupported() {
		variables.mongodb=getCredentials();
		if(!isNull(variables.mongodb.host)) {
			variables.supported=true;
		}
		else 
			variables.supported=false;

		return !variables.supported;
	}

	private struct function getCredentials() {
		// getting the credetials from the enviroment variables
		var mongoDB={};
		if(!isNull(server.system.environment.MONGODB_HOST) && !isNull(server.system.environment.MONGODB_PORT) && !isNull(server.system.environment.MONGODB_USERNAME) && !isNull(server.system.environment.MONGODB_PASSWORD)) {
			mongoDB.host=server.system.environment.MONGODB_HOST;
			mongoDB.port=server.system.environment.MONGODB_PORT;
			mongoDB.user=server.system.environment.MONGODB_USERNAME;
			mongoDB.pass=server.system.environment.MONGODB_PASSWORD;
		}
		// getting the credetials from the system variables
		else if(!isNull(server.system.properties.MONGODB_HOST) && !isNull(server.system.properties.MONGODB_PORT) && !isNull(server.system.properties.MONGODB_USERNAME) && !isNull(server.system.properties.MONGODB_PASSWORD)) {
			mongoDB.host=server.system.properties.MONGODB_HOST;
			mongoDB.port=server.system.properties.MONGODB_PORT;
			mongoDB.user=server.system.properties.MONGODB_USERNAME;
			mongoDB.pass=server.system.properties.MONGODB_PASSWORD;
		}
		return mongoDB;
	}

	private any function resetTestCollection() {
		var coll = db.getCollection("test");
		var docs = [
			 {"_id":1, "grp":1, "name":"One"}
			,{"_id":2, "grp":1, "name":"Two"}
			,{"_id":3, "grp":1, "name":"Three"}
			,{"_id":4, "grp":2, "name":"Four"}
			,{"_id":5, "grp":2, "name":"Five"}
		];

		coll.drop();
		coll.insert(docs);

		return coll;		
	}
	
	// public function setUp(){}

	public function beforeTests() {
		db = MongoDBConnect("test","mongodb://#variables.mongoDB.user#:#variables.mongoDB.pass#@#variables.mongoDB.host#:#variables.mongoDB.port#");
	}
	
	//public function afterTests(){}
	

	public void function testConnectByArgs() skip="isNotSupported" {
		var mongo = MongoDBConnect("test",variables.mongoDB.host,variables.mongoDB.port);
		assertEquals("test",mongo.getName());
	}

{'fraction_non_alphanumeric': 0.13241858158373285, 'fraction_numerical': 0.006612663250123987, 'mean_word_length': 4.664794007490637, 'pattern_counts': {'":': 30, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3182625', 'n_tokens_mistral': 2125, 'n_tokens_neox': 1957, 'n_words': 447}