@Test
public void testFindExecutions() {

    if (!TestEnvironment.canRunTest(ConfigOption.RUN_JOBS)) {
        System.err.println("Skipping test that would run jobs");
        return;
    }
    DXApplet applet = createMinimalApplet();
    // A sample input: {input_string: "java"}
    SampleAppInput appInput = new SampleAppInput("java");
    // Run the applet!
    DXJob job =
            applet.newRun().setInput(appInput).setProject(testProject).setName("javatest")
                    .addTags(ImmutableList.of("t1")).putProperty("k1", "v1").run();
    // Some findJobs queries
    assertEqualsAnyOrder(DXSearch.findExecutions().inProject(testProject)
            .withExecutable(applet).execute().asList(), job);
    assertEqualsAnyOrder(DXSearch.findExecutions().inProject(testProject).withTag("t1")
            .execute().asList(), job);
    assertEqualsAnyOrder(DXSearch.findExecutions().inProject(testProject).withTag("t2")
            .execute().asList());
    assertEqualsAnyOrder(
            DXSearch.findExecutions().inProject(testProject).withProperty("k1", "v1").execute()
                    .asList(), job);
    assertEqualsAnyOrder(DXSearch.findExecutions().inProject(testProject).withProperty("k1")
            .execute().asList(), job);
    assertEqualsAnyOrder(DXSearch.findExecutions().inProject(testProject)
            .withProperty("k1", "v2").execute().asList());
    assertEqualsAnyOrder(DXSearch.findExecutions().inProject(testProject).withProperty("k2")
            .execute().asList());
    assertEqualsAnyOrder(
            DXSearch.findExecutions()
                    .inProject(testProject)
                    .withProperties(
                            PropertiesQuery.anyOf(PropertiesQuery.withKey("k1"),
                                    PropertiesQuery.withKeyAndValue("does", "not exist")))
                    .execute().asList(), job);
    assertEqualsAnyOrder(DXSearch
            .findExecutions()
            .inProject(testProject)
            .withProperties(
                    PropertiesQuery.allOf(PropertiesQuery.withKey("k1"),
                            PropertiesQuery.withKeyAndValue("does", "not exist"))).execute()
            .asList());
    assertEqualsAnyOrder(
            DXSearch.findExecutions().inProject(testProject).nameMatchesExactly("javatest")
                    .execute().asList(), job);
    assertEqualsAnyOrder(DXSearch.findExecutions().inProject(testProject)
            .nameMatchesExactly("java").execute().asList());
    assertEqualsAnyOrder(
            DXSearch.findExecutions().inProject(testProject).nameMatchesGlob("*test").execute()
                    .asList(), job);
    assertEqualsAnyOrder(DXSearch.findExecutions().inProject(testProject)
            .nameMatchesGlob("python*").execute().asList());
    assertEqualsAnyOrder(DXSearch.findExecutions().inProject(testProject).withOriginJob(job)
            .execute().asList(), job);
    // With describe calls
    DXJob resultJobWithDescribe =
            Iterables.getOnlyElement(DXSearch.findExecutions().inProject(testProject)
                    .withTag("t1").withClassJob().includeDescribeOutput().execute().asList());
    Assert.assertEquals("javatest", resultJobWithDescribe.getCachedDescribe().getName());
    DXJob resultJobWithoutDescribe =
            Iterables.getOnlyElement(DXSearch.findExecutions().inProject(testProject)
                    .withTag("t1").withClassJob().execute().asList());
    try {
        resultJobWithoutDescribe.getCachedDescribe();
        Assert.fail("Expected IllegalStateException to be thrown because includeDescribeOutput was not specified");
    } catch (IllegalStateException e) {
        // Expected
    }
    assertEqualsAnyOrder(DXSearch.findExecutions().withIdsIn(ImmutableList.of(job)).execute()
            .asList(), job);
    assertEqualsAnyOrder(DXSearch.findExecutions().withIdsIn(ImmutableList.<DXExecution>of())
            .execute().asList());
}