/*
 * Copyright 2008-2013 Microarray Informatics Team, EMBL-European Bioinformatics Institute
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *
 * For further details of the Gene Expression Atlas project, including source code,
 * downloads and documentation, please see:
 *
 * http://gxa.github.com/gxa
 */

package uk.ac.ebi.atlas.bioentity;

import org.junit.Test;
import uk.ac.ebi.atlas.acceptance.selenium.fixture.SinglePageSeleniumFixture;
import uk.ac.ebi.atlas.acceptance.selenium.pages.BioEntityPage;

import java.net.InetAddress;
import java.net.UnknownHostException;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;

public class ProteinPageControllerSIT extends SinglePageSeleniumFixture {

    private static final String GENE_IDENTIFIER = "ENSP00000355434";

    private BioEntityPage subject;

    @Override
    protected void getStartingPage() {
        subject = new BioEntityPage(driver, GENE_IDENTIFIER, "proteins", "openPanelIndex=0");
        subject.get();
    }

    @Test
    public void checkGeneCardTitle() {
        assertThat(subject.getBioEntityCardTitle(), is("Q8N349 Homo sapiens olfactory receptor, family 2, subfamily L, member 13"));
    }

    //This will fail with PhantomJS
    @Test
    public void checkCardExpansion() throws UnknownHostException {
        assertThat(subject.isInfoCardExpanded(), is(true));

        String hostName = InetAddress.getLocalHost().getHostName();

        //TODO: fix when running on lime
        if (!hostName.equals("coconut.ebi.ac.uk")) {
            subject.clickInfoCard(false);
            assertThat(subject.isInfoCardExpanded(), is(false));
        }
    }

    @Test
    public void checkTableSize() {
        assertThat(subject.getPropertiesTableSize(), is(6));
    }

    @Test
    public void checkTableRows() {
        assertThat(subject.getPropertiesTableRow(0), hasItems("Ensembl Protein", "ENSP00000355434"));
        assertThat(subject.getPropertiesTableRow(1), hasItems("Ensembl Transcript"));
        assertThat(subject.getPropertiesTableRow(1).get(1), containsString("ENST00000366478"));
        assertThat(subject.getPropertiesTableRow(3), hasItems("UniProt", "Q8N349"));
        assertThat(subject.getPropertiesTableRow(5), hasItems("Reactome", "Signal Transduction"));
    }

    @Test
    public void checkLinksInTable() throws UnknownHostException {
        assertThat(subject.getLinksInTableRow(1).get(0), containsString("http://www.ensemblgenomes.org/id/ENST00000366478"));
        assertThat(subject.getLinksInTableRow(2).get(0), startsWith("http://www.ensemblgenomes.org/id-gene/ENSG00000196071"));
        assertThat(subject.getLinksInTableRow(3).get(0), startsWith("http://www.uniprot.org/uniprot/Q8N349"));

        String hostName = InetAddress.getLocalHost().getHostName();

        //TODO: fix when running on lime
        if (!hostName.equals("coconut.ebi.ac.uk")) {
            assertThat(subject.getLinksInTableRow(5).get(0), is("http://www.reactome.org/cgi-bin/eventbrowser_st_id?ST_ID=REACT_111102"));
        }
    }
}
@@ -1018,37 +1018,8 @@
 e;%0A%0A
-import java.net.InetAddress;%0A
 impo
@@ -1508,197 +1508,8 @@
  %7D%0A%0A
-    @Test%0A    public void checkGeneCardTitle() %7B%0A        assertThat(subject.getBioEntityCardTitle(), is(%22Q8N349 Homo sapiens olfactory receptor, family 2, subfamily L, member 13%22));%0A    %7D%0A%0A
     
@@ -1681,176 +1681,8 @@
 ));%0A
-%0A        String hostName = InetAddress.getLocalHost().getHostName();%0A%0A        //TODO: fix when running on lime%0A        if (!hostName.equals(%22coconut.ebi.ac.uk%22)) %7B%0A    
     
@@ -1715,20 +1715,16 @@
 false);%0A
-    
         
@@ -1772,34 +1772,24 @@
 is(false));%0A
-        %7D%0A
     %7D%0A%0A    @
@@ -1813,26 +1813,166 @@
 oid 
-checkTableSize() %7B
+bioEntityPropertyPane() %7B%0A        assertThat(subject.getBioEntityCardTitle(), is(%22Q8N349 Homo sapiens olfactory receptor, family 2, subfamily L, member 13%22));
 %0A   
@@ -2033,60 +2033,8 @@
 ));%0A
-    %7D%0A%0A    @Test%0A    public void checkTableRows() %7B%0A
     
@@ -2477,114 +2477,39 @@
 %22, %22
-Signal Transduction%22));%0A    %7D%0A%0A    @Test%0A    public void checkLinksInTable() throws UnknownHostException %7B
+Olfactory Signaling Pathway%22));
 %0A   
@@ -2873,176 +2873,8 @@
 ));%0A
-%0A        String hostName = InetAddress.getLocalHost().getHostName();%0A%0A        //TODO: fix when running on lime%0A        if (!hostName.equals(%22coconut.ebi.ac.uk%22)) %7B%0A    
     
@@ -2998,27 +2998,16 @@
 CT_1
-11102%22));%0A        %7D
+5488%22));
 %0A   

fix test due to change in uniprot mapping for ENSP00000355434