public void testSenderDoesNotSendInvalidQuery() throws InterruptedException, ExecutionException {
    BLASTQuery query = anInvalidPendingBLASTQuery();

    sender.execute(query);

    Integer numberSent = sender.get();

    assertThat("Expected no query to be send", numberSent, is(0));
    assertThat("The BLAST query's status should be draft", query.getStatus(), is(Status.DRAFT));
  }
  private BLASTQuery anInvalidPendingBLASTQuery() {
    BLASTQuery aBLASTQuery = aBLASTQueryWithStatus(Status.PENDING);
    aBLASTQuery.setSequence("");
    switch (aBLASTQuery.getVendorID()) {
      case BLASTVendor.EMBL_EBI:
        aBLASTQuery.setSearchParameter("email", "user@@email.com");
        break;
    }

    return aBLASTQuery;
  }
  public void testSenderSendsAValidQuery() throws InterruptedException, ExecutionException {
    BLASTQuery query = aValidPendingBLASTQuery();

    sender.execute(query);

    Integer numberSent = sender.get();
    assertThat("Expected the number of queries sent to be more than 1", numberSent, is(1));
    assertThat(
        "The BLAST query's identifier should be set",
        query.getJobIdentifier(),
        is(not(nullValue())));
  }
  public void testWeCannotDownloadResultsIfThereIsNoWebConnection()
      throws InterruptedException, ExecutionException {
    BLASTQuery query = BLASTQueryBuilder.aValidPendingBLASTQuery();
    BLASTHitsLoaderTask downloader =
        new BLASTHitsLoaderTask(context, getServiceFor(query.getVendorID())) {
          protected boolean connectedToWeb() {
            return false;
          }
        };
    downloader.execute(query);
    String nameOfFile = downloader.get();

    assertNull("Name of file with BLAST hits", nameOfFile);
  }
  public void testWeCanDownloadResultsOfAFINISHEDEMBLQuery()
      throws InterruptedException, ExecutionException {
    BLASTQuery emblQuery = BLASTQueryBuilder.validPendingEMBLBLASTQuery();
    save(emblQuery);
    SendBLASTQuery.sendToEBIEMBL(context, emblQuery);
    waitUntilFinished(emblQuery);
    BLASTHitsLoaderTask downloader =
        new BLASTHitsLoaderTask(context, getServiceFor(emblQuery.getVendorID()));
    downloader.execute(emblQuery);

    String nameOfFile = downloader.get();
    assertNotNull("Name of file with BLAST hits being non-nulled: " + nameOfFile, nameOfFile);
    assertFileOnDisk(String.format("%s.xml", emblQuery.getJobIdentifier()));
    removeFileFromDisk(emblQuery);
  }
 private void waitUntilFinished(BLASTQuery query) throws InterruptedException, ExecutionException {
   StatusTranslator translator = new StatusTranslator();
   BLASTSearchEngine service = getServiceFor(query.getVendorID());
   SearchStatus current = service.pollQuery(query.getJobIdentifier());
   query.setStatus(translator.translate(current));
   while (current.equals(SearchStatus.RUNNING)) {
     current = service.pollQuery(query.getJobIdentifier());
     query.setStatus(translator.translate(current));
     Log.i(TAG, current.toString());
   }
   Log.i(TAG, "BLAST search finished. Status of query is " + query.getStatus());
 }
 private void removeFileFromDisk(BLASTQuery query) {
   if (context.deleteFile(query.getJobIdentifier() + ".xml")) {
     Log.i(TAG, "BLAST hits file deleted");
   }
 }