<commit_before>/*******************************************************************************
 * Copyright (c) 2006 - 2006 Mylar eclipse.org project and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Mylar project committers - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylar.trac.tests;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.eclipse.mylar.internal.trac.core.ITracClient;
import org.eclipse.mylar.internal.trac.core.TracException;
import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
import org.eclipse.mylar.internal.trac.core.model.TracSearch;
import org.eclipse.mylar.internal.trac.core.model.TracTicket;
import org.eclipse.mylar.internal.trac.core.model.TracTicket.Key;
import org.eclipse.mylar.trac.tests.support.TestFixture;
import org.eclipse.mylar.trac.tests.support.XmlRpcServer.TestData;
import org.eclipse.mylar.trac.tests.support.XmlRpcServer.Ticket;

/**
 * Test cases that validate search results for classes that implement
 * {@link ITracClient}.
 * 
 * @author <NAME>
 */
public abstract class AbstractTracClientSearchTest extends AbstractTracClientTest {

	protected List<Ticket> tickets;

	private TestData data;

	public AbstractTracClientSearchTest(Version version) {
		super(version);
	}

	@Override
	protected void setUp() throws Exception {
		super.setUp();

		data = TestFixture.init010();
		tickets = data.tickets;
	}

	@Override
	protected void tearDown() throws Exception {
		super.tearDown();

		// TestFixture.cleanupRepository1();
	}

	protected void assertTicketEquals(Ticket ticket, TracTicket tracTicket) throws Exception {
		assertTrue(tracTicket.isValid());

		Map<?, ?> expectedValues = ticket.getValues();
		Map<String, String> values = tracTicket.getValues();
		for (String key : values.keySet()) {
			assertEquals("Values for key '" + key + "' did not match", expectedValues.get(key), values.get(key));
		}
	}

	public void testGetTicket010() throws Exception {
		connect010();
		getTickets();
	}

//	public void testGetTicket011() throws Exception {
//		connect011();
//		getTickets();
//	}

	private void getTickets() throws Exception {
		TracTicket ticket = repository.getTicket(tickets.get(0).getId());
		assertTicketEquals(tickets.get(0), ticket);

		ticket = repository.getTicket(tickets.get(1).getId());
		assertTicketEquals(tickets.get(1), ticket);
	}

	public void testGetTicketInvalidId010() throws Exception {
		connect010();
		getTicketInvalidId();
	}

	public void testGetTicketInvalidId011() throws Exception {
		connect011();
		getTicketInvalidId();
	}

	private void getTicketInvalidId() throws Exception {
		try {
			repository.getTicket(Integer.MAX_VALUE);
			fail("Expected TracException");
		} catch (TracException e) {
		}
	}

	public void testGetTicketUmlaute010() throws Exception {
		connect010();
		getTicketUmlaute();
	}

//	public void testGetTicketUmlaute011() throws Exception {
//		connect011();
//		getTicketUmlaute();
//	}

	private void getTicketUmlaute() throws Exception {
		TracTicket ticket = repository.getTicket(data.htmlEntitiesTicketId);
		assertEquals("test html entities: \u00E4\u00F6\u00FC", ticket.getValue(Key.SUMMARY));
		if (version == Version.XML_RPC) {
			assertEquals("\u00C4\u00D6\u00DC\n\nmulti\nline\n\n'''bold'''\n", ticket.getValue(Key.DESCRIPTION));
		} else {
			assertEquals(null, ticket.getValue(Key.DESCRIPTION));
		}
	}

	public void testSearchAll010() throws Exception {
		connect010();
		searchAll();
	}

	public void testSearchAll011() throws Exception {
		connect011();
		searchAll();
	}

	private void searchAll() throws Exception {
		TracSearch search = new TracSearch();
		List<TracTicket> result = new ArrayList<TracTicket>();
		repository.search(search, result);
		assertEquals(tickets.size(), result.size());
	}

	public void testSearchEmpty010() throws Exception {
		connect010();
		searchEmpty();		
	}

	public void testSearchEmpty011() throws Exception {
		connect011();
		searchEmpty();
	}

	private void searchEmpty() throws Exception {
		TracSearch search = new TracSearch();
		search.addFilter("milestone", "does not exist");
		List<TracTicket> result = new ArrayList<TracTicket>();
		repository.search(search, result);
		assertEquals(0, result.size());
	}

	public void testSearchMilestone1010() throws Exception {
		connect010();
		searchMilestone1();
	}

	public void testSearchMilestone1011() throws Exception {
		connect011();
		searchMilestone1();
	}

	private void searchMilestone1() throws Exception {
		TracSearch search = new TracSearch();
		search.addFilter("milestone", "milestone1");
		List<TracTicket> result = new ArrayList<TracTicket>();
		repository.search(search, result);
		assertEquals(1, result.size());
		assertTicketEquals(tickets.get(0), result.get(0));
	}

	public void testSearchMilestone2010() throws Exception {
		connect010();
		searchMilestone2();
	}

	public void testSearchMilestone2011() throws Exception {
		connect011();
		searchMilestone2();
	}

	private void searchMilestone2() throws Exception {
		TracSearch search = new TracSearch();
		search.addFilter("milestone", "milestone1");
		search.addFilter("milestone", "milestone2");
		search.setOrderBy("id");
		List<TracTicket> result = new ArrayList<TracTicket>();
		repository.search(search, result);
		assertEquals(3, result.size());
		assertTicketEquals(tickets.get(0), result.get(0));
		assertTicketEquals(tickets.get(1), result.get(1));
		assertTicketEquals(tickets.get(2), result.get(2));
	}

	public void testSearchExactMatch010() throws Exception {
		connect010();
		searchExactMatch();
	}
	
	public void testSearchExactMatch011() throws Exception {
		connect011();
		searchExactMatch();
	}
	
	private void searchExactMatch() throws Exception {
		TracSearch search = new TracSearch();
		search.addFilter("milestone", "milestone1");
		search.addFilter("summary", "summary1");
		List<TracTicket> result = new ArrayList<TracTicket>();
		repository.search(search, result);
		assertEquals(1, result.size());
		assertTicketEquals(tickets.get(0), result.get(0));
		assertEquals("milestone1", result.get(0).getValue(Key.MILESTONE));
		assertEquals("summary1", result.get(0).getValue(Key.SUMMARY));
	}

}
<commit_msg>NEW - bug 175211: Support Trac 0.11 https://bugs.eclipse.org/bugs/show_bug.cgi?id=175211<commit_after>/*******************************************************************************
 * Copyright (c) 2006 - 2006 Mylar eclipse.org project and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Mylar project committers - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylar.trac.tests;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.eclipse.mylar.internal.trac.core.ITracClient;
import org.eclipse.mylar.internal.trac.core.TracException;
import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
import org.eclipse.mylar.internal.trac.core.model.TracSearch;
import org.eclipse.mylar.internal.trac.core.model.TracTicket;
import org.eclipse.mylar.internal.trac.core.model.TracTicket.Key;
import org.eclipse.mylar.trac.tests.support.TestFixture;
import org.eclipse.mylar.trac.tests.support.XmlRpcServer.TestData;
import org.eclipse.mylar.trac.tests.support.XmlRpcServer.Ticket;

/**
 * Test cases that validate search results for classes that implement
 * {@link ITracClient}.
 * 
 * @author <NAME>
 */
public abstract class AbstractTracClientSearchTest extends AbstractTracClientTest {

	protected List<Ticket> tickets;

	private TestData data;

	public AbstractTracClientSearchTest(Version version) {
		super(version);
	}

	@Override
	protected void setUp() throws Exception {
		super.setUp();

		data = TestFixture.init010();
		tickets = data.tickets;
	}

	@Override
	protected void tearDown() throws Exception {
		super.tearDown();

		// TestFixture.cleanupRepository1();
	}

	protected void assertTicketEquals(Ticket ticket, TracTicket tracTicket) throws Exception {
		assertTrue(tracTicket.isValid());

		Map<?, ?> expectedValues = ticket.getValues();
		Map<String, String> values = tracTicket.getValues();
		for (String key : values.keySet()) {
			assertEquals("Values for key '" + key + "' did not match", expectedValues.get(key), values.get(key));
		}
	}

	public void testGetTicket010() throws Exception {
		connect010();
		getTickets();
	}

	public void testGetTicket011() throws Exception {
		if (version == Version.TRAC_0_9) {
			// XXX need to fix bug 175211
			return;
		}
		
		connect011();
		getTickets();
	}

	private void getTickets() throws Exception {
		TracTicket ticket = repository.getTicket(tickets.get(0).getId());
		assertTicketEquals(tickets.get(0), ticket);

		ticket = repository.getTicket(tickets.get(1).getId());
		assertTicketEquals(tickets.get(1), ticket);
	}

	public void testGetTicketInvalidId010() throws Exception {
		connect010();
		getTicketInvalidId();
	}

	public void testGetTicketInvalidId011() throws Exception {
		connect011();
		getTicketInvalidId();
	}

	private void getTicketInvalidId() throws Exception {
		try {
			repository.getTicket(Integer.MAX_VALUE);
			fail("Expected TracException");
		} catch (TracException e) {
		}
	}

	public void testGetTicketUmlaute010() throws Exception {
		connect010();
		getTicketUmlaute();
	}

	public void testGetTicketUmlaute011() throws Exception {
		if (version == Version.TRAC_0_9) {
			// XXX need to fix bug 175211
			return;
		}

		connect011();
		getTicketUmlaute();
	}

	private void getTicketUmlaute() throws Exception {
		TracTicket ticket = repository.getTicket(data.htmlEntitiesTicketId);
		assertEquals("test html entities: \u00E4\u00F6\u00FC", ticket.getValue(Key.SUMMARY));
		if (version == Version.XML_RPC) {
			assertEquals("\u00C4\u00D6\u00DC\n\nmulti\nline\n\n'''bold'''\n", ticket.getValue(Key.DESCRIPTION));
		} else {
			assertEquals(null, ticket.getValue(Key.DESCRIPTION));
		}
	}

	public void testSearchAll010() throws Exception {
		connect010();
		searchAll();
	}

	public void testSearchAll011() throws Exception {
		connect011();
		searchAll();
	}

	private void searchAll() throws Exception {
		TracSearch search = new TracSearch();
		List<TracTicket> result = new ArrayList<TracTicket>();
		repository.search(search, result);
		assertEquals(tickets.size(), result.size());
	}

	public void testSearchEmpty010() throws Exception {
		connect010();
		searchEmpty();
	}

	public void testSearchEmpty011() throws Exception {
		connect011();
		searchEmpty();
	}

	private void searchEmpty() throws Exception {
		TracSearch search = new TracSearch();
		search.addFilter("milestone", "does not exist");
		List<TracTicket> result = new ArrayList<TracTicket>();
		repository.search(search, result);
		assertEquals(0, result.size());
	}

	public void testSearchMilestone1010() throws Exception {
		connect010();
		searchMilestone1();
	}

	public void testSearchMilestone1011() throws Exception {
		connect011();
		searchMilestone1();
	}

	private void searchMilestone1() throws Exception {
		TracSearch search = new TracSearch();
		search.addFilter("milestone", "milestone1");
		List<TracTicket> result = new ArrayList<TracTicket>();
		repository.search(search, result);
		assertEquals(1, result.size());
		assertTicketEquals(tickets.get(0), result.get(0));
	}

	public void testSearchMilestone2010() throws Exception {
		connect010();
		searchMilestone2();
	}

	public void testSearchMilestone2011() throws Exception {
		connect011();
		searchMilestone2();
	}

	private void searchMilestone2() throws Exception {
		TracSearch search = new TracSearch();
		search.addFilter("milestone", "milestone1");
		search.addFilter("milestone", "milestone2");
		search.setOrderBy("id");
		List<TracTicket> result = new ArrayList<TracTicket>();
		repository.search(search, result);
		assertEquals(3, result.size());
		assertTicketEquals(tickets.get(0), result.get(0));
		assertTicketEquals(tickets.get(1), result.get(1));
		assertTicketEquals(tickets.get(2), result.get(2));
	}

	public void testSearchExactMatch010() throws Exception {
		connect010();
		searchExactMatch();
	}

	public void testSearchExactMatch011() throws Exception {
		connect011();
		searchExactMatch();
	}

	private void searchExactMatch() throws Exception {
		TracSearch search = new TracSearch();
		search.addFilter("milestone", "milestone1");
		search.addFilter("summary", "summary1");
		List<TracTicket> result = new ArrayList<TracTicket>();
		repository.search(search, result);
		assertEquals(1, result.size());
		assertTicketEquals(tickets.get(0), result.get(0));
		assertEquals("milestone1", result.get(0).getValue(Key.MILESTONE));
		assertEquals("summary1", result.get(0).getValue(Key.SUMMARY));
	}

}

{'fraction_non_alphanumeric': 0.14805587013967536, 'fraction_numerical': 0.02725556813892035, 'mean_word_length': 5.239284032030146, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 1, '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': '4269189', 'n_tokens_mistral': 4546, 'n_tokens_neox': 4088, 'n_words': 876}