@Test
    public void testGetServiceStateWithDefaultPath() throws Throwable {
      ExampleService exampleService = new ExampleService();
      ExampleService.ExampleServiceState exampleServiceState =
          new ExampleService.ExampleServiceState();
      exampleServiceState.name = UUID.randomUUID().toString();

      Operation post = host.startServiceSynchronously(exampleService, exampleServiceState);
      assertThat(post.getStatusCode(), is(200));

      ExampleService.ExampleServiceState result =
          host.getServiceState(ExampleService.ExampleServiceState.class);
      assertThat(result.name, is(exampleServiceState.name));
    }
    @Test
    public void testWaitForState() throws Throwable {
      ExampleService exampleService = new ExampleService();
      final ExampleService.ExampleServiceState exampleServiceState =
          new ExampleService.ExampleServiceState();
      exampleServiceState.name = UUID.randomUUID().toString();

      Operation post = host.startServiceSynchronously(exampleService, exampleServiceState);
      assertThat(post.getStatusCode(), is(200));

      try {
        host.waitForState(
            ExampleService.ExampleServiceState.class,
            new Predicate<ExampleService.ExampleServiceState>() {
              @Override
              public boolean test(ExampleService.ExampleServiceState state) {
                return false;
              }
            });

        Assert.fail("this state transition should not have succeeded");
      } catch (TimeoutException e) {
        assertThat(
            e.getMessage(), is(equalToIgnoringCase("timeout waiting for state transition.")));
      }

      try {
        host.waitForState(
            ExampleService.ExampleServiceState.class,
            new Predicate<ExampleService.ExampleServiceState>() {
              @Override
              public boolean test(ExampleService.ExampleServiceState state) {
                return state.name.equals(exampleServiceState.name);
              }
            });
      } catch (RuntimeException runtimeException) {
        Assert.fail("failed to detect state transition");
      }
    }
    @Test
    public void testWaitForQuery() throws Throwable {
      ExampleService exampleService = new ExampleService();
      final ExampleService.ExampleServiceState exampleServiceState =
          new ExampleService.ExampleServiceState();
      exampleServiceState.name = UUID.randomUUID().toString();

      QueryTask.Query kindClause =
          new QueryTask.Query()
              .setTermPropertyName(ServiceDocument.FIELD_NAME_KIND)
              .setTermMatchValue(Utils.buildKind(ExampleService.ExampleServiceState.class));

      QueryTask.Query nameClause =
          new QueryTask.Query()
              .setTermPropertyName("name")
              .setTermMatchValue(exampleServiceState.name);

      QueryTask.QuerySpecification spec = new QueryTask.QuerySpecification();
      spec.query.addBooleanClause(kindClause);
      spec.query.addBooleanClause(nameClause);
      spec.options = EnumSet.of(QueryTask.QuerySpecification.QueryOption.EXPAND_CONTENT);

      QueryTask query = QueryTask.create(spec).setDirect(true);

      try {
        host.waitForQuery(
            query,
            new Predicate<QueryTask>() {
              @Override
              public boolean test(QueryTask queryTask) {
                return queryTask.results.documentLinks.size() > 0;
              }
            });

        Assert.fail("waitForQuery should not have succeeded before documents are created");
      } catch (RuntimeException runtimeException) {
        assertThat(
            runtimeException.getMessage(),
            is(equalToIgnoringCase("timeout waiting for query result.")));
      }

      Operation post = host.startServiceSynchronously(exampleService, exampleServiceState);
      assertThat(post.getStatusCode(), is(200));

      ExampleService.ExampleServiceState result =
          host.getServiceState(ExampleService.ExampleServiceState.class);
      assertThat(result.name, is(exampleServiceState.name));

      QueryTask response =
          host.waitForQuery(
              query,
              new Predicate<QueryTask>() {
                @Override
                public boolean test(QueryTask queryTask) {
                  return queryTask.results.documentLinks.size() > 0;
                }
              });
      assertThat(response.results.documentLinks.size(), is(1));

      // verify fields are passed down correctly
      for (Map.Entry<String, Object> document : response.results.documents.entrySet()) {
        ExampleService.ExampleServiceState docState =
            Utils.fromJson(document.getValue(), ExampleService.ExampleServiceState.class);
        assertThat(docState.name, is(equalTo(exampleServiceState.name)));
      }
    }