@Test(dataProvider = "ValidStartStates")
    public void testValidStartState(String containerId) throws Throwable {
      ContainerService.State startState = TestHelper.getContainerServiceStartState();
      startState.containerId = containerId;
      Operation startOperation = testHost.startServiceSynchronously(containerService, startState);
      assertThat(startOperation.getStatusCode(), is(200));

      ContainerService.State savedState = testHost.getServiceState(ContainerService.State.class);
      assertThat(savedState.containerTemplateServiceLink, is("CONTAINER_TEMPLATE_SERVICE_LINK"));
      assertThat(savedState.vmServiceLink, is("VM_SERVICE_LINK"));
      assertThat(savedState.containerId, is(containerId));
    }
    @Test(expectedExceptions = XenonRuntimeException.class)
    public void testInvalidPatchStateOverwriteExistingContainerId() throws Throwable {
      ContainerService.State startState = TestHelper.getContainerServiceStartState();
      startState.containerId = "CONTAINER_ID";
      Operation startOperation = testHost.startServiceSynchronously(containerService, startState);
      assertThat(startOperation.getStatusCode(), is(200));

      ContainerService.State patchState = new ContainerService.State();
      patchState.containerId = "CONTAINER_ID";

      Operation patchOperation =
          Operation.createPatch(UriUtils.buildUri(testHost, TestHost.SERVICE_URI, null))
              .setBody(patchState);

      testHost.sendRequestAndWait(patchOperation);
    }
    @Test(dataProvider = "ValidContainerIdPatchValues")
    public void testValidPatchStateContainerIdFieldSet(String containerId) throws Throwable {
      createContainerService();
      ContainerService.State patchState = new ContainerService.State();
      patchState.containerId = containerId;

      Operation patchOperation =
          Operation.createPatch(UriUtils.buildUri(testHost, TestHost.SERVICE_URI, null))
              .setBody(patchState);

      Operation patchResult = testHost.sendRequestAndWait(patchOperation);
      assertThat(patchResult.getStatusCode(), is(200));

      ContainerService.State savedState = testHost.getServiceState(ContainerService.State.class);
      assertThat(savedState.containerId, is(containerId));
    }
 @AfterMethod
 public void tearDownTest() throws Throwable {
   try {
     testHost.deleteServiceSynchronously();
   } catch (ServiceHost.ServiceNotFoundException e) {
     // Exceptions are expected in the case where a service instance was not successfully
     // created.
   }
 }
    @Test(
        expectedExceptions = XenonRuntimeException.class,
        dataProvider = "fieldNamesWithMissingValue")
    public void testMissingRequiredStateFieldValue(String fieldName) throws Throwable {
      ContainerService.State startState = TestHelper.getContainerServiceStartState();
      Field declaredField = startState.getClass().getDeclaredField(fieldName);
      declaredField.set(startState, null);

      testHost.startServiceSynchronously(containerService, startState);
    }
    @Test(expectedExceptions = XenonRuntimeException.class)
    public void testInvalidPatchStateVmServiceLinkFieldSet() throws Throwable {
      createContainerService();
      ContainerService.State patchState = new ContainerService.State();
      patchState.vmServiceLink = "VM_SERVICE_LINK";

      Operation patchOperation =
          Operation.createPatch(UriUtils.buildUri(testHost, TestHost.SERVICE_URI, null))
              .setBody(patchState);

      testHost.sendRequestAndWait(patchOperation);
    }
 @AfterClass
 public void tearDownClass() throws Throwable {
   TestHost.destroy(testHost);
 }
 @BeforeClass
 public void setUpClass() throws Throwable {
   testHost = TestHost.create();
 }
 @AfterMethod
 public void tearDownTest() throws Throwable {
   testHost.deleteServiceSynchronously();
 }
 private void createContainerService() throws Throwable {
   ContainerService.State startState = TestHelper.getContainerServiceStartState();
   Operation startOperation = testHost.startServiceSynchronously(containerService, startState);
   assertThat(startOperation.getStatusCode(), is(200));
 }