package uk.ac.ebi.quickgo.common.validator;

import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.mockito.Mockito.when;

/**
 * @author Tony Wardell
 *         Date: 19/04/2016
 *         Time: 14:04
 *         Created with IntelliJ IDEA.
 */
@RunWith(MockitoJUnitRunner.class)
public class DbXRefEntityValidationTest {
	@Rule
	public ExpectedException thrown = ExpectedException.none();

	private DbXRefEntityValidation dbXrefEntities;

	@Mock
	private DbXRefEntity rnaCentralEntity;

	@Mock
	private DbXRefEntity intactEntity;

	@Mock
	private DbXRefEntity uniprotEntity;

	@Before
	public void setup(){
		List<DbXRefEntity> listOfFormats = new ArrayList<>();
		listOfFormats.add(rnaCentralEntity);
		listOfFormats.add(intactEntity);
		listOfFormats.add(uniprotEntity);

		when(rnaCentralEntity.getDatabase()).thenReturn("RNAcentral");
		when(rnaCentralEntity.getEntityType()).thenReturn("CHEBI:33697");
		when(rnaCentralEntity.matches("71URS0000000001_733")).thenReturn(true);

		when(intactEntity.getDatabase()).thenReturn("IntAct");
		when(intactEntity.getEntityType()).thenReturn("GO:0043234");
		when(intactEntity.matches("EBI-11166735")).thenReturn(true);

		when(uniprotEntity.getDatabase()).thenReturn("UniProtKB");
		when(uniprotEntity.getEntityType()).thenReturn("PR:000000001");
		when(uniprotEntity.matches("A0A000")).thenReturn(true);
		when(uniprotEntity.matches("999999")).thenReturn(false);

		dbXrefEntities = DbXRefEntityValidation.createWithData(listOfFormats);
	}

	@Test
	public void isValidId(){
		assertThat(dbXrefEntities.test("A0A000"), is(true));
	}

	@Test
	public void isValidRNACentralID(){
		assertThat(dbXrefEntities.test("71URS0000000001_733"), is(true));
	}

	@Test
	public void isValidIntActID(){
		assertThat(dbXrefEntities.test("EBI-11166735"), is(true));
	}

	@Test
	public void invalidDatabaseAndTypeName(){
		assertThat(dbXrefEntities.test("ABC"), is(false));
	}

	@Test
	public void isInvalidId(){
		assertThat(dbXrefEntities.test("9999"), is(false));
	}

	@Test
	public void throwsErrorIfEntitiesIsNull(){
		thrown.expect(IllegalArgumentException.class);
		dbXrefEntities = DbXRefEntityValidation.createWithData(null);
	}
}

@@ -1481,24 +1481,228 @@
 urn(true);%0A%0A
+        when(intactEntity.getDatabase()).thenReturn(%22ComplexPortal%22);%0A        when(intactEntity.getEntityType()).thenReturn(%22GO:0032991%22);%0A        when(intactEntity.matches(%22CPX-101%22)).thenReturn(true);%0A%0A
 %09%09when(unipr
@@ -2214,32 +2214,38 @@
 true));%0A%09%7D%0A%0A
-%09
+    
 @Test%0A
-%09
+    
 public void 
@@ -2257,28 +2257,35 @@
 idIntActID()
+ 
 %7B%0A
-%09%09
+        
 assertThat(d
@@ -2323,32 +2323,157 @@
 5%22), is(true));%0A
+    %7D%0A%0A%09@Test%0A    public void isValidWasIntActIDNowComplex() %7B%0A        assertThat(dbXrefEntities.test(%22CPX-101%22), is(true));%0A
 %09%7D%0A%0A%09@Test%0A%09publ

Add ComplexPortal as a default gene product source.