@Test
  public void testDeleteDownloadedArtifactShouldReturnErrorResponse() throws Exception {
    doReturn(artifact).when(service).createArtifact(artifact.getName());
    doThrow(new IOException("error")).when(mockFacade).deleteDownloadedArtifact(artifact, version);

    Response response = service.deleteDownloadedArtifact(artifact.getName(), version.toString());
    assertErrorResponse(response);
  }
  @Test
  public void testDeleteDownloadedArtifact() throws Exception {
    doReturn(artifact).when(service).createArtifact(artifact.getName());

    Response response = service.deleteDownloadedArtifact(artifact.getName(), version.toString());
    assertEquals(response.getStatus(), Response.Status.NO_CONTENT.getStatusCode());
    verify(mockFacade).deleteDownloadedArtifact(artifact, version);
  }
  @Test
  public void testDeleteNonDownloadedArtifact() throws Exception {
    doReturn(artifact).when(service).createArtifact(artifact.getName());
    doThrow(new ArtifactNotFoundException(artifact, version))
        .when(mockFacade)
        .deleteDownloadedArtifact(artifact, version);

    Response response = service.deleteDownloadedArtifact(artifact.getName(), version.toString());
    assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
    assertEquals(response.getEntity().toString(), "{message=Artifact codenvy:1.0.0 not found}");
  }
  @BeforeMethod
  public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    service = spy(new InstallationManagerService(BACKUP_DIR, mockFacade, configManager));

    doReturn(TEST_SYSTEM_ADMIN_NAME).when(mockPrincipal).getName();
    doReturn(mockArtifact).when(service).createArtifact(anyString());

    artifact = createArtifact(ARTIFACT_NAME);
    version = Version.valueOf(VERSION_NUMBER);
  }
  @Test
  public void testUpdateCodenvy() throws Exception {
    doReturn(InstallType.SINGLE_SERVER).when(configManager).detectInstallationType();
    doReturn(ImmutableList.of("a"))
        .when(mockFacade)
        .getUpdateInfo(any(Artifact.class), any(InstallType.class));
    doReturn("id")
        .when(mockFacade)
        .update(any(Artifact.class), any(Version.class), any(InstallOptions.class));
    doReturn(Version.valueOf("3.1.0"))
        .when(mockFacade)
        .getLatestInstallableVersion(any(Artifact.class));

    Map<String, String> testConfigProperties = new HashMap<>();
    testConfigProperties.put("property1", "value1");
    testConfigProperties.put("property2", "value2");

    doReturn(testConfigProperties)
        .when(configManager)
        .prepareInstallProperties(
            null,
            null,
            InstallType.SINGLE_SERVER,
            createArtifact(ARTIFACT_NAME),
            Version.valueOf("3.1.0"),
            false);

    Response result = service.updateCodenvy(0);
    assertEquals(result.getStatus(), Response.Status.ACCEPTED.getStatusCode());

    result = service.updateCodenvy(-1);
    assertEquals(result.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());

    result = service.updateCodenvy(1);
    assertEquals(result.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
  }