/** Tests searching by gene pathways with case sensitivity disabled. */
  @Test
  public void searchPathwaysCaseInsensitive() {
    action.getSearchParameters().setSearchType(SearchType.PATHWAY);
    action.getSearchParameters().setInputValues(PATHWAY_NAME);
    action.getSearchParameters().setCaseSensitiveSearch(false);

    assertEquals(GENE_RESULT, action.search());
    assertTrue(action.getGeneResults().size() > 0);

    Db2DbParams expectedInput = new Db2DbParams();
    expectedInput.setInputValues("H_BARD1PATHWAY,H_bard1Pathway,h_bard1Pathway,h_bard1pathway");
    verify(bioDbNetRemoteService).db2db(refEq(expectedInput, ignoredParams));
  }
  /** Tests searching by gene id with case sensitivity enabled. */
  @Test
  public void searchGeneId() {
    action.getSearchParameters().setSearchType(SearchType.GENE_ID);
    action.getSearchParameters().setInputValues("1,2,3,4");
    action.getSearchParameters().setCaseSensitiveSearch(true);

    assertEquals(GENE_RESULT, action.search());
    assertTrue(action.getGeneResults().size() > 0);

    Db2DbParams expectedInput = new Db2DbParams();
    expectedInput.setInputValues("1,2,3,4");
    verify(bioDbNetRemoteService).db2db(refEq(expectedInput, ignoredParams));
  }
  /** Tests searching by gene alias with case sensitivity enabled. */
  @Test
  public void searchGeneSymbolCaseInsensitive() {
    action.getSearchParameters().setSearchType(SearchType.GENE_SYMBOL);
    action.getSearchParameters().setInputValues("BRCA1,BRCA2");
    action.getSearchParameters().setCaseSensitiveSearch(false);

    assertEquals(GENE_RESULT, action.search());
    assertTrue(action.getGeneResults().size() > 0);

    Db2DbParams expectedInput = new Db2DbParams();
    expectedInput.setInputValues("BRCA1,BRCA2,brca1,brca2");
    verify(bioDbNetRemoteService).db2db(refEq(expectedInput, ignoredParams));
  }
  /** Tests searching by gene alias with case sensitivity disabled. */
  @Test
  public void searchGeneAliasCaseInsensitive() {
    action.getSearchParameters().setSearchType(SearchType.GENE_ALIAS);
    action.getSearchParameters().setInputValues(GENE_ALIAS);
    action.getSearchParameters().setCaseSensitiveSearch(false);

    assertEquals(GENE_RESULT, action.search());
    assertTrue(action.getGeneResults().size() > 0);

    DbWalkParams expectedInput = new DbWalkParams();
    expectedInput.setInputValues("BRCC1,Brcc1,brcc1");
    verify(bioDbNetRemoteService).dbWalk(refEq(expectedInput, "dbPath", "taxonId"));
  }
  /** Tests search of pathways by genes with case sensitivity disabled. */
  @Test
  public void searchPathwaysByGeneCaseInsensitive() {
    action.getSearchParameters().setSearchType(SearchType.PATHWAY_BY_GENE);
    action.getSearchParameters().setInputValues("BRCA1");
    action.getSearchParameters().setCaseSensitiveSearch(false);

    assertEquals(PATHWAY_RESULTS, action.search());
    assertTrue(action.getGeneResults().isEmpty());
    assertFalse(action.getPathwayResults().isEmpty());
    assertEquals(5, action.getPathwayResults().size());

    Db2DbParams expectedInput = new Db2DbParams();
    expectedInput.setInputValues("BRCA1,brca1");
    verify(bioDbNetRemoteService).db2db(refEq(expectedInput, ignoredParams));
  }
  /** Tests expected behavior when no gene results are found. */
  @Test
  public void searchPathwayNoResults() {
    bioDbNetRemoteService = mock(BioDbNetRemoteService.class);
    when(bioDbNetRemoteService.db2db(any(Db2DbParams.class)))
        .thenAnswer(
            new Answer<String>() {
              @Override
              public String answer(InvocationOnMock invocation) throws Throwable {
                return "Gene Symbol Biocarta Pathway Name";
              }
            });

    BioDbNetSearchImpl bioDbNetSvc = new BioDbNetSearchImpl();
    bioDbNetSvc.setBioDbNetRemoteService(bioDbNetRemoteService);

    action.setBioDbNetService(bioDbNetSvc);
    action.getSearchParameters().setSearchType(SearchType.PATHWAY_BY_GENE);
    action.getSearchParameters().setInputValues(StringUtils.EMPTY);

    assertEquals(PATHWAY_RESULTS, action.search());
    assertTrue(action.getGeneResults().isEmpty());
    assertTrue(action.hasActionErrors());
    assertEquals(1, action.getActionErrors().size());
    assertEquals("bioDbNet.noPathwayResultsFound", action.getActionErrors().iterator().next());
  }
  /** Tests expected behavior when no gene results are found. */
  @Test
  public void searchGenesNoResults() {
    action.getSearchParameters().setSearchType(null);
    action.getSearchParameters().setInputValues(StringUtils.EMPTY);

    assertEquals(GENE_RESULT, action.search());
    assertTrue(action.getGeneResults().isEmpty());
    assertTrue(action.hasActionErrors());
    assertEquals(1, action.getActionErrors().size());
    assertEquals("bioDbNet.noGeneResultsFound", action.getActionErrors().iterator().next());
  }
  /** Tests expected behavior when an exception occurs during the search process. */
  @Test
  public void searchWithException() {
    doThrow(Exception.class).when(bioDbNetRemoteService).db2db(any(Db2DbParams.class));
    action.getSearchParameters().setSearchType(SearchType.PATHWAY);
    action.getSearchParameters().setInputValues(PATHWAY_NAME);

    assertEquals(Action.INPUT, action.search());
    assertTrue(action.hasActionErrors());
    assertEquals(1, action.getActionErrors().size());
    assertEquals("bioDbNet.error", action.getActionErrors().iterator().next());
  }
  /** Tests action validation. */
  @Test
  public void validate() {
    action.validate();
    assertTrue(action.hasActionErrors());
    assertEquals(1, action.getActionErrors().size());
    assertEquals(
        "struts.messages.error.must.enter.keywords", action.getActionErrors().iterator().next());

    action.clearActionErrors();
    action.prepare();
    action.getSearchParameters().setInputValues("input");
    action.validate();
    assertFalse(action.hasActionErrors());
  }