<commit_before>package de.cronn.jira.sync;

import static org.junit.Assert.*;

import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import de.cronn.jira.sync.config.JiraConnectionProperties;
import de.cronn.jira.sync.domain.JiraIssue;
import de.cronn.jira.sync.domain.JiraIssueStatus;
import de.cronn.jira.sync.domain.JiraIssueUpdate;
import de.cronn.jira.sync.domain.JiraLoginRequest;
import de.cronn.jira.sync.domain.JiraPriority;
import de.cronn.jira.sync.domain.JiraProject;
import de.cronn.jira.sync.domain.JiraRemoteLink;
import de.cronn.jira.sync.domain.JiraRemoteLinks;
import de.cronn.jira.sync.domain.JiraResolution;
import de.cronn.jira.sync.domain.JiraServerInfo;
import de.cronn.jira.sync.domain.JiraTransitions;
import de.cronn.jira.sync.domain.JiraVersion;
import de.cronn.jira.sync.service.JiraService;

@Component
@Primary
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class JiraDummyService implements JiraService {

	private static final Logger log = LoggerFactory.getLogger(JiraDummyService.class);

	private URL url;

	private static final Map<URL, JiraDummyData> DUMMY_DATA = new LinkedHashMap<>();

	static void reset() {
		DUMMY_DATA.clear();
	}

	void setUrl(URL url) {
		assertNotNull(url);
		this.url = url;
	}

	void expectLoginRequest(String username, String password) throws Exception {
		getDummyData().setCredentials(new JiraLoginRequest(username, password));
	}

	void setDefaultStatus(JiraIssueStatus status) {
		getDummyData().setDefaultStatus(status);
	}

	void addProject(JiraProject jiraProject) {
		assertNotNull(jiraProject.getKey());
		Object old = getProjects().put(jiraProject.getKey(), jiraProject);
		assertNull(old);
	}

	void addPriority(JiraPriority jiraPriority) {
		getDummyData().getPriorities().add(jiraPriority);
	}

	private Map<String, JiraProject> getProjects() {
		return getDummyData().getProjects();
	}

	@Override
	public URL getUrl() {
		return url;
	}

	@Override
	public void login(JiraConnectionProperties connectionProperties) {
		this.url = connectionProperties.getUrl();
		JiraLoginRequest credentials = getDummyData().getCredentials();
		assertNotNull("Expected login not configured for " + url, credentials);
		assertEquals(connectionProperties.getUsername(), credentials.getUsername());
		assertEquals(connectionProperties.getPassword(), credentials.getPassword());
	}

	@Override
	public void logout() {
		log.debug("[{}] logout", getUrl());
		url = null;
	}

	@Override
	public void close() {
		log.debug("closing");
	}

	@Override
	public JiraServerInfo getServerInfo() {
		JiraServerInfo jiraServerInfo = new JiraServerInfo(url.toString());
		jiraServerInfo.setServerTitle(url.getHost());
		return jiraServerInfo;
	}

	@Override
	public JiraIssue getIssueByKey(String key) {
		JiraIssue issue = getIssueMap().get(key);
		assertNotNull("Issue " + key + " not found", issue);
		return issue;
	}

	@Override
	public JiraProject getProjectByKey(String projectKey) {
		JiraProject jiraProject = getProjects().get(projectKey);
		assertNotNull("Project " + projectKey + " not found", jiraProject);
		return jiraProject;
	}

	@Override
	public List<JiraPriority> getPriorities() {
		return getDummyData().getPriorities();
	}

	@Override
	public List<JiraResolution> getResolutions() {
		throw new UnsupportedOperationException("not yet implemented");
	}

	@Override
	public List<JiraVersion> getVersions(String projectKey) {
		throw new UnsupportedOperationException("not yet implemented");
	}

	@Override
	public List<JiraIssue> getIssuesByFilterId(String filterId) {
		return getAllIssues();
	}

	List<JiraIssue> getAllIssues() {
		Map<String, JiraIssue> issuesPerKey = getIssueMap();
		return Collections.unmodifiableList(new ArrayList<>(issuesPerKey.values()));
	}

	private Map<String, JiraIssue> getIssueMap() {
		return getDummyData().getIssues();
	}

	private JiraDummyData getDummyData() {
		assertNotNull(url);
		return DUMMY_DATA.computeIfAbsent(url, k -> new JiraDummyData());
	}

	@Override
	public List<JiraRemoteLink> getRemoteLinks(JiraIssue issue) {
		assertNotNull(issue.getKey());
		Map<String, JiraRemoteLinks> remoteLinksPerIssueKey = getDummyData().getRemoteLinks();
		JiraRemoteLinks jiraRemoteLinks = remoteLinksPerIssueKey.get(issue.getKey());
		if (jiraRemoteLinks == null) {
			return Collections.emptyList();
		}
		return jiraRemoteLinks;
	}

	@Override
	public JiraTransitions getTransitions(JiraIssue issue) {
		throw new UnsupportedOperationException("not yet implemented");
	}

	@Override
	public void addRemoteLink(JiraIssue fromIssue, JiraIssue toIssue, JiraService toJiraService, URL remoteLinkIcon) {
		JiraRemoteLinks remoteLinks = getDummyData().getRemoteLinks().computeIfAbsent(fromIssue.getKey(), k -> new JiraRemoteLinks());<commit_msg>fix JiraDummyService<commit_after>package de.cronn.jira.sync;

import static org.junit.Assert.*;

import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import de.cronn.jira.sync.config.JiraConnectionProperties;
import de.cronn.jira.sync.domain.JiraIssue;
import de.cronn.jira.sync.domain.JiraIssueStatus;
import de.cronn.jira.sync.domain.JiraIssueUpdate;
import de.cronn.jira.sync.domain.JiraLoginRequest;
import de.cronn.jira.sync.domain.JiraPriority;
import de.cronn.jira.sync.domain.JiraProject;
import de.cronn.jira.sync.domain.JiraRemoteLink;
import de.cronn.jira.sync.domain.JiraRemoteLinks;
import de.cronn.jira.sync.domain.JiraResolution;
import de.cronn.jira.sync.domain.JiraServerInfo;
import de.cronn.jira.sync.domain.JiraTransitions;
import de.cronn.jira.sync.domain.JiraVersion;
import de.cronn.jira.sync.service.JiraService;

@Component
@Primary
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class JiraDummyService implements JiraService {

	private static final Logger log = LoggerFactory.getLogger(JiraDummyService.class);

	private URL url;

	private static final Map<String, JiraDummyData> DUMMY_DATA = new LinkedHashMap<>();

	static void reset() {
		DUMMY_DATA.clear();
	}

	void setUrl(URL url) {
		assertNotNull(url);
		this.url = url;
	}

	void expectLoginRequest(String username, String password) throws Exception {
		getDummyData().setCredentials(new JiraLoginRequest(username, password));
	}

	void setDefaultStatus(JiraIssueStatus status) {
		getDummyData().setDefaultStatus(status);
	}

	void addProject(JiraProject jiraProject) {
		assertNotNull(jiraProject.getKey());
		Object old = getProjects().put(jiraProject.getKey(), jiraProject);
		assertNull(old);
	}

	void addPriority(JiraPriority jiraPriority) {
		getDummyData().getPriorities().add(jiraPriority);
	}

	private Map<String, JiraProject> getProjects() {
		return getDummyData().getProjects();
	}

	@Override
	public URL getUrl() {
		return url;
	}

	@Override
	public void login(JiraConnectionProperties connectionProperties) {
		this.url = connectionProperties.getUrl();
		JiraLoginRequest credentials = getDummyData().getCredentials();
		assertNotNull("Expected login not configured for " + url, credentials);
		assertEquals(connectionProperties.getUsername(), credentials.getUsername());
		assertEquals(connectionProperties.getPassword(), credentials.getPassword());
	}

	@Override
	public void logout() {
		log.debug("[{}] logout", getUrl());
		url = null;
	}

	@Override
	public void close() {
		log.debug("closing");
	}

	@Override
	public JiraServerInfo getServerInfo() {
		JiraServerInfo jiraServerInfo = new JiraServerInfo(url.toString());
		jiraServerInfo.setServerTitle(url.getHost());
		return jiraServerInfo;
	}

	@Override
	public JiraIssue getIssueByKey(String key) {
		JiraIssue issue = getIssueMap().get(key);
		assertNotNull("Issue " + key + " not found", issue);
		return issue;
	}

	@Override
	public JiraProject getProjectByKey(String projectKey) {
		JiraProject jiraProject = getProjects().get(projectKey);
		assertNotNull("Project " + projectKey + " not found", jiraProject);
		return jiraProject;
	}

	@Override
	public List<JiraPriority> getPriorities() {
		return getDummyData().getPriorities();
	}

	@Override
	public List<JiraResolution> getResolutions() {
		throw new UnsupportedOperationException("not yet implemented");
	}

	@Override
	public List<JiraVersion> getVersions(String projectKey) {
		throw new UnsupportedOperationException("not yet implemented");
	}

	@Override
	public List<JiraIssue> getIssuesByFilterId(String filterId) {
		return getAllIssues();
	}

	List<JiraIssue> getAllIssues() {
		Map<String, JiraIssue> issuesPerKey = getIssueMap();
		return Collections.unmodifiableList(new ArrayList<>(issuesPerKey.values()));
	}

	private Map<String, JiraIssue> getIssueMap() {
		return getDummyData().getIssues();
	}

	private JiraDummyData getDummyData() {
		assertNotNull(url);
		return DUMMY_DATA.computeIfAbsent(url.toString(), k -> new JiraDummyData());
	}

	@Override
	public List<JiraRemoteLink> getRemoteLinks(JiraIssue issue) {
		assertNotNull(issue.getKey());
		Map<String, JiraRemoteLinks> remoteLinksPerIssueKey = getDummyData().getRemoteLinks();
		JiraRemoteLinks jiraRemoteLinks = remoteLinksPerIssueKey.get(issue.getKey());
		if (jiraRemoteLinks == null) {
			return Collections.emptyList();
		}
		return jiraRemoteLinks;
	}

	@Override
	public JiraTransitions getTransitions(JiraIssue issue) {
		throw new UnsupportedOperationException("not yet implemented");
	}

	@Override
	public void addRemoteLink(JiraIssue fromIssue, JiraIssue toIssue, JiraService toJiraService, URL remoteLinkIcon) {
		JiraRemoteLinks remoteLinks = getDummyData().getRemoteLinks().computeIfAbsent(fromIssue.getKey(), k -> new JiraRemoteLinks());
{'fraction_non_alphanumeric': 0.1126934396658122, 'fraction_numerical': 0.0007595177062565271, 'mean_word_length': 6.112761647535449, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5136335', 'n_tokens_mistral': 3528, 'n_tokens_neox': 3339, 'n_words': 628}