package uk.ac.ebi.quickgo.annotation.download.converter.helpers;

import org.junit.Test;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.*;

/**
 * Can the GeneProduct helper class turn full, null or empty strings in to the right result?
 * @author Tony Wardell
 * Date: 10/04/2018
 * Time: 08:42
 * Created with IntelliJ IDEA.
 */
public class GeneProductTest {

    @Test
    public void uniprot() {
        final String fullId = "UniProtKB:A0A000";

        GeneProduct uniprot = GeneProduct.fromString(fullId);

        assertThat(uniprot.db(), is("UniProtKB"));
        assertThat(uniprot.id(), is("A0A000"));
        assertThat(uniprot.withIsoformOrVariant(), equalTo(null));
        assertThat(uniprot.type(), is("protein"));
    }

    @Test
    public void uniprotWithIsoformOrVarient() {
        final String fullId = "UniProtKB:A0A000-2";

        GeneProduct uniprot = GeneProduct.fromString(fullId);

        assertThat(uniprot.db(), is("UniProtKB"));
        assertThat(uniprot.id(), is("A0A000"));
        assertThat(uniprot.withIsoformOrVariant(), equalTo(fullId));
        assertThat(uniprot.type(), is("protein"));
    }

    @Test
    public void rna() {
        final String fullId = "RNAcentral:URS00000064B1_559292";

        GeneProduct uniprot = GeneProduct.fromString(fullId);

        assertThat(uniprot.db(), is("RNAcentral"));
        assertThat(uniprot.id(), is("URS00000064B1_559292"));
        assertThat(uniprot.withIsoformOrVariant(), equalTo(null));
        assertThat(uniprot.type(), is("miRNA"));
    }

    @Test
    public void intact() {
        final String fullId = "IntAct:EBI-10043081";

        GeneProduct uniprot = GeneProduct.fromString(fullId);

        assertThat(uniprot.db(), is("IntAct"));
        assertThat(uniprot.id(), is("EBI-10043081"));
        assertThat(uniprot.withIsoformOrVariant(), equalTo(null));
        assertThat(uniprot.type(), is("complex"));
    }

    @Test(expected = IllegalArgumentException.class)
    public void nulThrowsException() {
        GeneProduct.fromString(null);
    }

    @Test(expected = IllegalArgumentException.class)
    public void emptyThrowsException() {
        GeneProduct.fromString("");
    }

    @Test(expected = IllegalArgumentException.class)
    public void garbageGeneProductIdThrowsException() {
        GeneProduct.fromString("siasdfia'sif'a");
    }

    @Test(expected = IllegalArgumentException.class)
    public void uniprotIdIsBrokenThrowsException() {
        final String fullId = "UniProtKB:123444444444444";

        GeneProduct.fromString(fullId);
    }
}

@@ -1632,14 +1632,21 @@
 oid 
-intact
+complexPortal
 () %7B
@@ -1681,27 +1681,30 @@
  = %22
-IntAct:EBI
+ComplexPortal:CPX
 -1004
-3081
 %22;%0A%0A
@@ -1807,14 +1807,21 @@
 is(%22
-IntAct
+ComplexPortal
 %22));
@@ -1862,20 +1862,16 @@
 is(%22
-EBI
+CPX
 -1004
-3081
 %22));

Change test for complex portal.