Search in sources :

Example 1 with ApiClient

use of io.swagger.client.ApiClient in project CommandHelper by EngineHub.

the class AppsApiUtil method getClient.

public ApiClient getClient() {
    ApiClient client = new ApiClient();
    client.setBasePath(baseApiUrl);
    client.setConnectTimeout(TIMEOUT);
    client.setDebugging(debug);
    return client;
}
Also used : ApiClient(io.swagger.client.ApiClient)

Example 2 with ApiClient

use of io.swagger.client.ApiClient in project dockstore by dockstore.

the class CRUDClientIT method testUpdatingDefaultVersionHostedTool.

/**
 * Ensures that hosted tools can have their default path updated
 */
@Test
public void testUpdatingDefaultVersionHostedTool() throws IOException {
    ApiClient webClient = getWebClient(ADMIN_USERNAME, testingPostgres);
    ContainersApi containersApi = new ContainersApi(webClient);
    HostedApi hostedApi = new HostedApi(webClient);
    // Add a tool with a version
    DockstoreTool hostedTool = hostedApi.createHostedTool("awesomeTool", Registry.QUAY_IO.getDockerPath().toLowerCase(), CWL.getShortName(), "coolNamespace", null);
    SourceFile descriptorFile = new SourceFile();
    descriptorFile.setContent(FileUtils.readFileToString(new File(ResourceHelpers.resourceFilePath("tar-param.cwl")), StandardCharsets.UTF_8));
    descriptorFile.setType(SourceFile.TypeEnum.DOCKSTORE_CWL);
    descriptorFile.setPath("/Dockstore.cwl");
    descriptorFile.setAbsolutePath("/Dockstore.cwl");
    SourceFile dockerfile = new SourceFile();
    dockerfile.setContent("FROM ubuntu:latest");
    dockerfile.setType(SourceFile.TypeEnum.DOCKERFILE);
    dockerfile.setPath("/Dockerfile");
    dockerfile.setAbsolutePath("/Dockerfile");
    DockstoreTool dockstoreTool = hostedApi.editHostedTool(hostedTool.getId(), Lists.newArrayList(descriptorFile, dockerfile));
    Optional<Tag> first = dockstoreTool.getWorkflowVersions().stream().max(Comparator.comparingInt((Tag t) -> Integer.parseInt(t.getName())));
    assertTrue(first.isPresent());
    assertEquals("correct number of source files", 2, fileDAO.findSourceFilesByVersion(first.get().getId()).size());
    // Update the default version of the tool
    containersApi.updateToolDefaultVersion(hostedTool.getId(), first.get().getName());
    // test deletion of hosted tool for #3171
    containersApi.deleteContainer(hostedTool.getId());
}
Also used : ContainersApi(io.swagger.client.api.ContainersApi) DockstoreTool(io.swagger.client.model.DockstoreTool) SourceFile(io.swagger.client.model.SourceFile) Tag(io.swagger.client.model.Tag) ApiClient(io.swagger.client.ApiClient) HostedApi(io.swagger.client.api.HostedApi) SourceFile(io.swagger.client.model.SourceFile) File(java.io.File) Test(org.junit.Test) ConfidentialTest(io.dockstore.common.ConfidentialTest)

Example 3 with ApiClient

use of io.swagger.client.ApiClient in project dockstore by dockstore.

the class CheckerWorkflowIT method testCWLWorkflowAddCheckerRefreshPublishUnpublish.

/**
 * This tests the process of adding a checker workflow to a CWL workflow entry and that some calls to the workflow will also trigger the calls to the checker
 * - Refresh workflow should refresh checker
 * - Publish workflow should publish checker
 * - Unpublish workflow should unpublish checker
 *
 * @throws ApiException
 */
@Test
public void testCWLWorkflowAddCheckerRefreshPublishUnpublish() throws ApiException {
    // Setup for test
    final ApiClient webClient = getWebClient(USER_2_USERNAME, testingPostgres);
    WorkflowsApi workflowApi = new WorkflowsApi(webClient);
    final PublishRequest publishRequest = CommonTestUtilities.createPublishRequest(true);
    final PublishRequest unpublishRequest = CommonTestUtilities.createPublishRequest(false);
    // Manually register a workflow
    Workflow githubWorkflow = workflowApi.manualRegister("github", "DockstoreTestUser2/md5sum-checker", "/md5sum/md5sum-workflow.cwl", "altname", "cwl", "/testcwl.json");
    final long count = testingPostgres.runSelectStatement("select count(*) from workflow where mode = '" + Workflow.ModeEnum.FULL + "'", long.class);
    assertEquals("No workflows are in full mode, there are " + count, 0, count);
    // Refresh the workflow
    workflowApi.refresh(githubWorkflow.getId(), false);
    final long count2 = testingPostgres.runSelectStatement("select count(*) from workflow where mode = '" + Workflow.ModeEnum.FULL + "'", long.class);
    assertEquals("One workflow should be full, there are " + count2, 1, count2);
    // Add checker workflow
    workflowApi.registerCheckerWorkflow("/checker-workflow-wrapping-workflow.cwl", githubWorkflow.getId(), "cwl", null);
    // Refresh workflow
    Workflow refreshedEntry = workflowApi.refresh(githubWorkflow.getId(), false);
    // Should be able to download zip for first version
    Workflow checkerWorkflow = workflowApi.getWorkflow(refreshedEntry.getCheckerId(), null);
    workflowApi.getWorkflowZip(checkerWorkflow.getId(), checkerWorkflow.getWorkflowVersions().get(0).getId());
    // Refreshing the entry also calls the update user metadata function which populates the user profile
    refreshedEntry.getUsers().forEach(entryUser -> {
        Assert.assertNotEquals("refresh() endpoint should have user profiles", null, entryUser.getUserProfiles());
    });
    // Checker workflow should refresh
    final long count3 = testingPostgres.runSelectStatement("select count(*) from workflow where mode = '" + Workflow.ModeEnum.FULL + "'", long.class);
    assertEquals("Two workflows should be full (one being the checker), there are " + count3, 2, count3);
    // Checker workflow should have the same test path as entry
    final long count4 = testingPostgres.runSelectStatement("select count(*) from workflow w, entry_defaultpaths ed where ed.path = '/testcwl.json' and w.id = ed.entry_id", long.class);
    assertEquals("There should be two workflows with default test parameter file path of /testcwl.json, there are " + count4, 2, count4);
    // Checker workflow should have the correct workflow path
    final long count5 = testingPostgres.runSelectStatement("select count(*) from workflow where sourcecontrol = 'github.com' and organization = 'DockstoreTestUser2' and repository = 'md5sum-checker' and workflowname = 'altname_cwl_checker' and giturl = 'git@github.com:DockstoreTestUser2/md5sum-checker.git'", long.class);
    assertEquals("The workflow should have the correct path, there are " + count5, 1, count5);
    // Publish workflow
    final long count6 = testingPostgres.runSelectStatement("select count(*) from workflow where ispublished = true", long.class);
    assertEquals("No workflows should be published, there are " + count6, 0, count6);
    workflowApi.publish(githubWorkflow.getId(), publishRequest);
    // Checker workflow should publish
    final long count7 = testingPostgres.runSelectStatement("select count(*) from workflow where ispublished = true", long.class);
    assertEquals("Two workflows should be published (one being the checker), there are " + count7, 2, count7);
    // Should still be able to download zip for first version
    workflowApi.getWorkflowZip(checkerWorkflow.getId(), checkerWorkflow.getWorkflowVersions().get(0).getId());
    // Unpublish workflow
    workflowApi.publish(githubWorkflow.getId(), unpublishRequest);
    // Checker workflow should unpublish
    final long count8 = testingPostgres.runSelectStatement("select count(*) from workflow where ispublished = true", long.class);
    assertEquals("No workflows should be published, there are " + count8, 0, count8);
    // Should not be able to directly publish the checker
    try {
        workflowApi.publish(refreshedEntry.getCheckerId(), publishRequest);
        fail("Should not reach this statement.");
    } catch (ApiException ex) {
        assertEquals(ex.getCode(), HttpStatus.SC_BAD_REQUEST);
    }
}
Also used : Workflow(io.swagger.client.model.Workflow) WorkflowsApi(io.swagger.client.api.WorkflowsApi) ApiClient(io.swagger.client.ApiClient) PublishRequest(io.swagger.client.model.PublishRequest) ApiException(io.swagger.client.ApiException) WorkflowTest(io.dockstore.common.WorkflowTest) Test(org.junit.Test) ConfidentialTest(io.dockstore.common.ConfidentialTest)

Example 4 with ApiClient

use of io.swagger.client.ApiClient in project dockstore by dockstore.

the class CheckerWorkflowIT method testAddCheckerToStub.

/**
 * Should not be able to add a checker workflow to a stub workflow (Should fail)
 *
 * @throws ApiException
 */
@Test
public void testAddCheckerToStub() throws ApiException {
    // Setup for test
    final ApiClient webClient = getWebClient(USER_2_USERNAME, testingPostgres);
    WorkflowsApi workflowApi = new WorkflowsApi(webClient);
    // Manually register a workflow
    Workflow githubWorkflow = workflowApi.manualRegister("github", "DockstoreTestUser2/md5sum-checker", "/md5sum/md5sum-workflow.cwl", "altname", "cwl", "/testcwl.json");
    final long count = testingPostgres.runSelectStatement("select count(*) from workflow where mode = '" + Workflow.ModeEnum.FULL + "'", long.class);
    assertEquals("No workflows are in full mode, there are " + count, 0, count);
    thrown.expect(ApiException.class);
    // Add checker workflow
    workflowApi.registerCheckerWorkflow("checker-workflow-wrapping-workflow.cwl", githubWorkflow.getId(), "cwl", null);
}
Also used : Workflow(io.swagger.client.model.Workflow) WorkflowsApi(io.swagger.client.api.WorkflowsApi) ApiClient(io.swagger.client.ApiClient) WorkflowTest(io.dockstore.common.WorkflowTest) Test(org.junit.Test) ConfidentialTest(io.dockstore.common.ConfidentialTest)

Example 5 with ApiClient

use of io.swagger.client.ApiClient in project dockstore by dockstore.

the class CheckerWorkflowIT method testCheckerWorkflowAndRefresh.

private void testCheckerWorkflowAndRefresh(boolean workflow, boolean all) {
    // Setup for test
    final ApiClient webClient = getWebClient(USER_2_USERNAME, testingPostgres);
    WorkflowsApi workflowApi = new WorkflowsApi(webClient);
    ContainersApi containersApi = new ContainersApi(webClient);
    long baseEntryId;
    if (workflow) {
        // Manually register a workflow
        Workflow githubWorkflow = workflowApi.manualRegister("github", "DockstoreTestUser2/md5sum-checker", "/md5sum/md5sum-workflow.cwl", "", "cwl", "/testcwl.json");
        Assert.assertEquals("Should be able to get license after manual register", "Apache License 2.0", githubWorkflow.getLicenseInformation().getLicenseName());
        // Clear license name to mimic old workflow that does not have a license associated with it
        testingPostgres.runUpdateStatement("update workflow set licensename=null");
        Workflow refreshedWorkflow = workflowApi.refresh(githubWorkflow.getId(), false);
        Assert.assertEquals("Should be able to get license after refresh", "Apache License 2.0", refreshedWorkflow.getLicenseInformation().getLicenseName());
        // Refresh the workflow
        baseEntryId = refreshedWorkflow.getId();
    } else {
        // Manually register a tool
        DockstoreTool newTool = new DockstoreTool();
        newTool.setMode(DockstoreTool.ModeEnum.MANUAL_IMAGE_PATH);
        newTool.setName("my-md5sum");
        newTool.setGitUrl("git@github.com:DockstoreTestUser2/md5sum-checker.git");
        newTool.setDefaultDockerfilePath("/md5sum/Dockerfile");
        newTool.setDefaultCwlPath("/md5sum/md5sum-tool.cwl");
        newTool.setRegistryString(Registry.QUAY_IO.getDockerPath());
        newTool.setNamespace("dockstoretestuser2");
        newTool.setToolname("altname");
        newTool.setPrivateAccess(false);
        newTool.setDefaultCWLTestParameterFile("/testcwl.json");
        DockstoreTool githubTool = containersApi.registerManual(newTool);
        // Refresh the workflow
        DockstoreTool refresh = containersApi.refresh(githubTool.getId());
        baseEntryId = refresh.getId();
    }
    // Add checker workflow
    final Entry checkerWorkflowBase = workflowApi.registerCheckerWorkflow("/checker-workflow-wrapping-workflow.cwl", baseEntryId, "cwl", null);
    final Workflow stubCheckerWorkflow = workflowApi.getWorkflow(checkerWorkflowBase.getCheckerId(), null);
    assertSame(stubCheckerWorkflow.getMode(), Workflow.ModeEnum.STUB);
    // should be able to refresh all or the organization when a checker stub is present without a failure (constraints issue from #1405)
    List<Workflow> workflows = new ArrayList<>();
    workflows.add(workflowApi.manualRegister(SourceControl.GITHUB.name(), "DockstoreTestUser/dockstore-whalesay-wdl", "/dockstore.wdl", "", DescriptorLanguage.WDL.getShortName(), ""));
    workflows.add(workflowApi.manualRegister(SourceControl.GITHUB.name(), "DockstoreTestUser/dockstore-whalesay-2", "/dockstore.wdl", "", DescriptorLanguage.WDL.getShortName(), ""));
    workflows.add(workflowApi.manualRegister(SourceControl.GITHUB.name(), "DockstoreTestUser/ampa-nf", "/nextflow.config", "", DescriptorLanguage.NEXTFLOW.getShortName(), ""));
    workflows.add(workflowApi.manualRegister("github", "DockstoreTestUser2/dockstore_workflow_cnv", "/workflow/cnv.cwl", "", "cwl", "/test.json"));
    if (all) {
        for (Workflow workflowItem : workflows) {
            workflowApi.refresh(workflowItem.getId(), false);
        }
    } else {
        for (Workflow workflowItem : workflows) {
            if (workflowItem.getOrganization().equalsIgnoreCase(stubCheckerWorkflow.getOrganization())) {
                workflowApi.refresh(workflowItem.getId(), false);
            }
        }
    }
}
Also used : ContainersApi(io.swagger.client.api.ContainersApi) Entry(io.swagger.client.model.Entry) DockstoreTool(io.swagger.client.model.DockstoreTool) ArrayList(java.util.ArrayList) Workflow(io.swagger.client.model.Workflow) WorkflowsApi(io.swagger.client.api.WorkflowsApi) ApiClient(io.swagger.client.ApiClient)

Aggregations

ApiClient (io.swagger.client.ApiClient)285 Test (org.junit.Test)261 ConfidentialTest (io.dockstore.common.ConfidentialTest)257 WorkflowsApi (io.swagger.client.api.WorkflowsApi)133 ApiException (io.swagger.client.ApiException)127 Workflow (io.swagger.client.model.Workflow)115 ContainersApi (io.swagger.client.api.ContainersApi)112 DockstoreTool (io.swagger.client.model.DockstoreTool)112 UsersApi (io.swagger.client.api.UsersApi)87 WorkflowTest (io.dockstore.common.WorkflowTest)79 SlowTest (io.dockstore.common.SlowTest)64 ToolTest (io.dockstore.common.ToolTest)62 HostedApi (io.swagger.client.api.HostedApi)59 ArrayList (java.util.ArrayList)54 Category (org.junit.experimental.categories.Category)54 Before (org.junit.Before)53 CommonTestUtilities (io.dockstore.common.CommonTestUtilities)52 List (java.util.List)52 Assert (org.junit.Assert)52 Assert.assertEquals (org.junit.Assert.assertEquals)52