/*
 *                    BioJava development code
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  If you do not have a copy,
 * see:
 *
 *      http://www.gnu.org/copyleft/lesser.html
 *
 * Copyright for this code is held jointly by the individual
 * authors.  These should be listed in @author doc comments.
 *
 * For more information on the BioJava project and its aims,
 * or to join the biojava-l mailing list, visit the home page
 * at:
 *
 *      http://www.biojava.org/
 *
 * Created on Jun 2, 2010
 * Author: Jianjiong Gao 
 *
 */

package org.biojava3.protmod;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

import junit.framework.TestCase;

/**
 * 
 * @author Jianjiong Gao
 * @since 3.0
 */
public class ProteinModificationRegistryTest extends TestCase {
	
	public void testRegisterModification() {
		List<Component> components = new ArrayList<Component>(2);
		components.add(Component.of("COMP1", ComponentType.AMINOACID));
		components.add(Component.of("COMP2", ComponentType.AMINOACID, true, false));
		
		ModificationLinkage linkage = new ModificationLinkage(components, 0, "ATOM1", 1, "ATOM2");
		
		ModificationCondition condition = new ModificationConditionImpl(components, 
				Collections.singletonList(linkage));
		
		ProteinModification.register("TEST", 
				ModificationCategory.CROSS_LINK_2,
				ModificationOccurrenceType.NATURAL,
				condition)
				.setDescription("TEST")
				.setFormula("TEST")
				.setResidId("TEST")
				.setResidName("TEST")
				.setPsimodId("TEST")
				.setPsimodName("TEST")
				.setSystematicName("TEST");
		assertNotNull(ProteinModification.getById("TEST"));
	}
	
	/**
	 * Test the initialization registry of common protein modifications. 
	 */
	public void testRegisterCommonModification() {		
		Set<ProteinModification> mods = ProteinModification.getProteinModifications();
		assertTrue(mods!=null && !mods.isEmpty());
		
		System.out.println("There are totally "+mods.size()
				+" protein modifications registered.");
		
		printModifications(mods);
	}
	
	public void testGetBy() {
		ProteinModification mod;
		Set<ProteinModification> mods;
		
		System.out.println("getById");
		mod = ProteinModification.getById("0001");
		assertNotNull(mod);
		System.out.println(mod);

		System.out.println("getByPdbccId");
		mods = ProteinModification.getByPdbccId("SEP");
		assertNotNull(mods);
		System.out.println(mods);

		System.out.println("getByResidId");
		mods = ProteinModification.getByResidId("AA0076");
		assertNotNull(mods);
		System.out.println(mods);

		System.out.println("getByPsimodId");
		mods = ProteinModification.getByPsimodId("MOD:00110");
		assertNotNull(mods);
		System.out.println(mods);

		System.out.println("getByComponent");
		mods = ProteinModification.getByComponent(Component.of("FAD", ComponentType.LIGAND));
		assertNotNull(mods);
		printModifications(mods);

		System.out.println("getByCategory");
		mods = ProteinModification.getByCategory(ModificationCategory.ATTACHMENT);
		assertNotNull(mods);
		printModifications(mods);

		System.out.println("getByOccurrenceType");
		mods = ProteinModification.getByOccurrenceType(ModificationOccurrenceType.NATURAL);
		assertNotNull(mods);
		printModifications(mods);
	}
	
	/**
	 * Print modifications.
	 * @param mods {@link ProteinModification}s.
	 */
	private void printModifications(Set<ProteinModification> mods) {
		for (ProteinModification mod:mods) {
			System.out.println(mod);	
		}
	}
	
}

@@ -2109,24 +2109,26 @@
 ty());%0D%0A%09%09%0D%0A
+//
 %09%09System.out
@@ -2170,16 +2170,18 @@
 size()%0D%0A
+//
 %09%09%09%09+%22 p
@@ -2221,16 +2221,18 @@
 );%0D%0A%09%09%0D%0A
+//
 %09%09printM
@@ -2353,44 +2353,8 @@
 s;%0D%0A
-%09%09%0D%0A%09%09System.out.println(%22getById%22);
 %0D%0A%09%09
@@ -2424,75 +2424,8 @@
 );%0D%0A
-%09%09System.out.println(mod);%0D%0A%0D%0A%09%09System.out.println(%22getByPdbccId%22);
 %0D%0A%09%09
@@ -2501,76 +2501,8 @@
 );%0D%0A
-%09%09System.out.println(mods);%0D%0A%0D%0A%09%09System.out.println(%22getByResidId%22);
 %0D%0A%09%09
@@ -2581,77 +2581,8 @@
 );%0D%0A
-%09%09System.out.println(mods);%0D%0A%0D%0A%09%09System.out.println(%22getByPsimodId%22);
 %0D%0A%09%09
@@ -2665,78 +2665,8 @@
 );%0D%0A
-%09%09System.out.println(mods);%0D%0A%0D%0A%09%09System.out.println(%22getByComponent%22);
 %0D%0A%09%09
@@ -2780,77 +2780,8 @@
 );%0D%0A
-%09%09printModifications(mods);%0D%0A%0D%0A%09%09System.out.println(%22getByCategory%22);
 %0D%0A%09%09
@@ -2884,83 +2884,8 @@
 );%0D%0A
-%09%09printModifications(mods);%0D%0A%0D%0A%09%09System.out.println(%22getByOccurrenceType%22);
 %0D%0A%09%09
@@ -2997,50 +2997,25 @@
 );%0D%0A
-%09%09printModifications(mods);%0D%0A
 %09%7D%0D%0A%09%0D%0A
+//
 %09/**%0D%0A
+//
 %09 * 
@@ -3036,16 +3036,18 @@
 tions.%0D%0A
+//
 %09 * @par
@@ -3085,22 +3085,26 @@
 ion%7Ds.%0D%0A
+//
 %09 */%0D%0A
+//
 %09private
@@ -3162,16 +3162,18 @@
 ods) %7B%0D%0A
+//
 %09%09for (P
@@ -3204,16 +3204,18 @@
 ods) %7B%0D%0A
+//
 %09%09%09Syste
@@ -3240,13 +3240,17 @@
 ;%09%0D%0A
+//
 %09%09%7D%0D%0A
+//
 %09%7D%0D%0A

remove prints when testing.