Package com.google.cloud.genomics.api.client.commands

Source Code of com.google.cloud.genomics.api.client.commands.ExportReadsCommandTest

/*
Copyright 2014 Google Inc. All rights reserved.

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.
*/
package com.google.cloud.genomics.api.client.commands;

import com.beust.jcommander.internal.Lists;
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.client.util.store.MemoryDataStoreFactory;
import com.google.api.services.genomics.GenomicsScopes;
import com.google.api.services.genomics.model.ExportReadGroupSetsRequest;
import com.google.api.services.genomics.model.ExportReadGroupSetsResponse;
import com.google.api.services.genomics.model.Job;
import com.google.api.services.genomics.model.ReadGroupSet;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.Mockito;

import static org.junit.Assert.assertTrue;

@RunWith(JUnit4.class)
public class ExportReadsCommandTest extends CommandTest {

  @Test
  public void testScopes() throws Exception {
    assertTrue(new ExportReadsCommand().getScopes()
        .contains(GenomicsScopes.DEVSTORAGE_READ_WRITE));
  }

  @Test
  public void testExportReadsets() throws Exception {
    ExportReadsCommand command = new ExportReadsCommand();
    command.setDataStoreFactory(new MemoryDataStoreFactory());

    command.readGroupSetIds = Lists.newArrayList("r1", "r2");
    command.projectNumber = 3L;
    command.exportUri = "exportme";

    // Get the readsets
    Mockito.when(readsets.get("r1")).thenReturn(readsetGet);
    Mockito.when(readsets.get("r2")).thenReturn(readsetGet);
    Mockito.when(readsetGet.execute()).thenReturn(
        new ReadGroupSet().setName("name1"),
        new ReadGroupSet().setName("name2"));

    // Export them
    Mockito.when(readsets.export(Mockito.any(ExportReadGroupSetsRequest.class)))
        .thenReturn(readsetExport);
    Mockito.when(readsetExport.execute()).thenReturn(
        new ExportReadGroupSetsResponse().setJobId("8675309"));

    // Get the job
    Mockito.when(jobs.get("8675309")).thenReturn(jobGet);
    Mockito.when(jobGet.execute()).thenReturn(new Job().setDetailedStatus("description1"));

    command.handleRequest(genomics);

    String output = outContent.toString();
    assertTrue(output, output.contains("Exporting read group sets name1,name2"));
    assertTrue(output, output.contains("Export job:"));
    assertTrue(output, output.contains("description1"));
  }

  @Test
  public void testExportReadsets_badIds() throws Exception {
    ExportReadsCommand command = new ExportReadsCommand();
    command.readGroupSetIds = Lists.newArrayList("bad");

    // Get the readsets
    Mockito.when(readsets.get(Mockito.anyString())).thenThrow(GoogleJsonResponseException.class);
    command.handleRequest(genomics);

    String output = outContent.toString();
    assertTrue(output, output.contains("The read group set ID bad won't work"));
  }

}
TOP

Related Classes of com.google.cloud.genomics.api.client.commands.ExportReadsCommandTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.