<commit_before>/*
 * Copyright 2012 MarkLogic Corporation
 *
 * 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 com.marklogic.client.test;

import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists;
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathEvaluatesTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.util.Random;

import org.custommonkey.xmlunit.exceptions.XpathException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

import com.marklogic.client.DocumentManager.Metadata;
import com.marklogic.client.Format;
import com.marklogic.client.TextDocumentManager;
import com.marklogic.client.Transaction;
import com.marklogic.client.XMLDocumentManager;
import com.marklogic.client.io.DOMHandle;
import com.marklogic.client.io.DocumentMetadataHandle;
import com.marklogic.client.io.StringHandle;
import com.marklogic.client.io.DocumentMetadataHandle.DocumentCollections;

public class GenericDocumentTest {
	@BeforeClass
	public static void beforeClass() {
		Common.connect();
	}
	@AfterClass
	public static void afterClass() {
		Common.release();
	}

	@Test
	public void testExists() {
		String docId = "/test/testExists1.txt";

		TextDocumentManager docMgr = Common.client.newTextDocumentManager();
		assertTrue("Non-existent document appears to exist", docMgr.exists(docId)==null);
		docMgr.write(docId,new StringHandle().with("A simple text document"));
		assertTrue("Existent document doesn't appear to exist", docMgr.exists(docId)!=null);
		docMgr.delete(docId);
	}

	@Test
	public void testDelete() {
		String docId = "/test/testDelete1.txt";

		TextDocumentManager docMgr = Common.client.newTextDocumentManager();
		docMgr.write(docId, new StringHandle().with("A simple text document"));
		String text = docMgr.read(docId, new StringHandle()).get();
		assertTrue("Could not create document for deletion", text != null && text.length() > 0);
		docMgr.delete(docId);
		text = null;
		boolean hadException = false;
		try {
			text = docMgr.read(docId, new StringHandle()).get();
		} catch (Exception ex) {
			hadException = true;
		}
		assertTrue("Could not delete document", text == null && hadException);
	}

	final static String content = "<?xml version='1.0' encoding='UTF-8'?>\n"+
	"<root mode='mixed' xml:lang='en'>\n"+
	"<child mode='basic'>value</child>\n"+
	"A simple XML document\n"+
	"</root>\n";<commit_msg>test recovery after interruption in previous run <commit_after>/*
 * Copyright 2012 MarkLogic Corporation
 *
 * 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 com.marklogic.client.test;

import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathEvaluatesTo;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.util.Random;

import org.custommonkey.xmlunit.exceptions.XpathException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

import com.marklogic.client.DocumentManager.Metadata;
import com.marklogic.client.Format;
import com.marklogic.client.TextDocumentManager;
import com.marklogic.client.Transaction;
import com.marklogic.client.XMLDocumentManager;
import com.marklogic.client.io.DOMHandle;
import com.marklogic.client.io.DocumentMetadataHandle;
import com.marklogic.client.io.DocumentMetadataHandle.DocumentCollections;
import com.marklogic.client.io.StringHandle;

public class GenericDocumentTest {
	@BeforeClass
	public static void beforeClass() {
		Common.connect();
	}
	@AfterClass
	public static void afterClass() {
		Common.release();
	}

	@Test
	public void testExists() {
		String docId = "/test/testExists1.txt";

		TextDocumentManager docMgr = Common.client.newTextDocumentManager();

		// guarantee that a previous run didn't leave the document
		docMgr.delete(docId);

		assertTrue("Non-existent document appears to exist", docMgr.exists(docId)==null);
		docMgr.write(docId,new StringHandle().with("A simple text document"));
		assertTrue("Existent document doesn't appear to exist", docMgr.exists(docId)!=null);
		docMgr.delete(docId);
	}

	@Test
	public void testDelete() {
		String docId = "/test/testDelete1.txt";

		TextDocumentManager docMgr = Common.client.newTextDocumentManager();
		docMgr.write(docId, new StringHandle().with("A simple text document"));
		String text = docMgr.read(docId, new StringHandle()).get();
		assertTrue("Could not create document for deletion", text != null && text.length() > 0);
		docMgr.delete(docId);
		text = null;
		boolean hadException = false;
		try {
			text = docMgr.read(docId, new StringHandle()).get();
		} catch (Exception ex) {
			hadException = true;
		}
		assertTrue("Could not delete document", text == null && hadException);
	}

	final static String content = "<?xml version='1.0' encoding='UTF-8'?>\n"+
	"<root mode='mixed' xml:lang='en'>\n"+
	"<child mode='basic'>value</child>\n"+
	"A simple XML document\n"+
	"</root>\n";
{'fraction_non_alphanumeric': 0.11570639305445936, 'fraction_numerical': 0.004735595895816891, 'mean_word_length': 5.127659574468085, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 2, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 14}, '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': '2403911', 'n_tokens_mistral': 1942, 'n_tokens_neox': 1862, 'n_words': 514}