Search in sources :

Example 1 with ListContainersParams

use of org.eclipse.che.plugin.docker.client.params.ListContainersParams in project che by eclipse.

the class DockerConnectorTest method shouldThrowDockerExceptionWhileGettingListContainersByParamsObjectIfResponseCodeIsNotSuccess.

@Test(expectedExceptions = DockerException.class, expectedExceptionsMessageRegExp = EXCEPTION_ERROR_MESSAGE)
public void shouldThrowDockerExceptionWhileGettingListContainersByParamsObjectIfResponseCodeIsNotSuccess() throws IOException, JsonParseException {
    ListContainersParams listContainersParams = ListContainersParams.create();
    when(dockerResponse.getStatus()).thenReturn(RESPONSE_ERROR_CODE);
    dockerConnector.listContainers(listContainersParams);
    verify(dockerResponse).getStatus();
}
Also used : ListContainersParams(org.eclipse.che.plugin.docker.client.params.ListContainersParams) Test(org.testng.annotations.Test)

Example 2 with ListContainersParams

use of org.eclipse.che.plugin.docker.client.params.ListContainersParams in project che by eclipse.

the class DockerConnectorTest method shouldBeAbleToGetListContainersByFiltersInTheListContainersParams.

@Test
public void shouldBeAbleToGetListContainersByFiltersInTheListContainersParams() throws IOException, JsonParseException {
    Filters filters = new Filters().withFilter("testKey", "testValue");
    ListContainersParams listContainersParams = ListContainersParams.create().withFilters(filters);
    ContainerListEntry containerListEntry = mock(ContainerListEntry.class);
    List<ContainerListEntry> expectedListContainers = singletonList(containerListEntry);
    doReturn(expectedListContainers).when(dockerConnector).parseResponseStreamAndClose(eq(inputStream), Matchers.<TypeToken<List<ContainerListEntry>>>any());
    List<ContainerListEntry> containers = dockerConnector.listContainers(listContainersParams);
    verify(dockerConnection).query(eq("filters"), anyObject());
    assertEquals(containers, expectedListContainers);
}
Also used : Filters(org.eclipse.che.plugin.docker.client.json.Filters) ContainerListEntry(org.eclipse.che.plugin.docker.client.json.ContainerListEntry) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) ListContainersParams(org.eclipse.che.plugin.docker.client.params.ListContainersParams) Test(org.testng.annotations.Test)

Example 3 with ListContainersParams

use of org.eclipse.che.plugin.docker.client.params.ListContainersParams in project che by eclipse.

the class DockerConnectorTest method shouldCallListContainersWithParametersObject.

@Test
public void shouldCallListContainersWithParametersObject() throws IOException {
    ListContainersParams listContainersParams = ListContainersParams.create().withAll(true);
    ContainerListEntry containerListEntry = mock(ContainerListEntry.class);
    List<ContainerListEntry> expectedListContainers = singletonList(containerListEntry);
    doReturn(expectedListContainers).when(dockerConnector).listContainers(listContainersParams);
    List<ContainerListEntry> result = dockerConnector.listContainers();
    ArgumentCaptor<ListContainersParams> listContainersParamsArgumentCaptor = ArgumentCaptor.forClass(ListContainersParams.class);
    verify(dockerConnector).listContainers(listContainersParamsArgumentCaptor.capture());
    assertEquals(result, expectedListContainers);
    assertEquals(listContainersParamsArgumentCaptor.getValue(), listContainersParams);
}
Also used : ContainerListEntry(org.eclipse.che.plugin.docker.client.json.ContainerListEntry) ListContainersParams(org.eclipse.che.plugin.docker.client.params.ListContainersParams) Test(org.testng.annotations.Test)

Example 4 with ListContainersParams

use of org.eclipse.che.plugin.docker.client.params.ListContainersParams in project che by eclipse.

the class DockerConnectorTest method shouldBeAbleToGetListContainersWithListContainersParams.

@Test
public void shouldBeAbleToGetListContainersWithListContainersParams() throws IOException, JsonParseException {
    ListContainersParams listContainersParams = ListContainersParams.create().withAll(true).withSize(true);
    ContainerListEntry containerListEntry = mock(ContainerListEntry.class);
    List<ContainerListEntry> expectedListContainers = singletonList(containerListEntry);
    doReturn(expectedListContainers).when(dockerConnector).parseResponseStreamAndClose(eq(inputStream), Matchers.<TypeToken<List<ContainerListEntry>>>any());
    List<ContainerListEntry> containers = dockerConnector.listContainers(listContainersParams);
    verify(dockerConnectionFactory).openConnection(any(URI.class));
    verify(dockerConnection).method(REQUEST_METHOD_GET);
    verify(dockerConnection).path("/containers/json");
    verify(dockerConnection).query("all", 1);
    verify(dockerConnection).query("size", 1);
    verify(dockerConnection).request();
    verify(dockerResponse).getStatus();
    verify(dockerResponse).getInputStream();
    verify(dockerConnector).parseResponseStreamAndClose(eq(inputStream), Matchers.<TypeToken<List<ContainerListEntry>>>any());
    assertEquals(containers, expectedListContainers);
}
Also used : ContainerListEntry(org.eclipse.che.plugin.docker.client.json.ContainerListEntry) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) URI(java.net.URI) ListContainersParams(org.eclipse.che.plugin.docker.client.params.ListContainersParams) Test(org.testng.annotations.Test)

Aggregations

ListContainersParams (org.eclipse.che.plugin.docker.client.params.ListContainersParams)4 Test (org.testng.annotations.Test)4 ContainerListEntry (org.eclipse.che.plugin.docker.client.json.ContainerListEntry)3 ArrayList (java.util.ArrayList)2 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 URI (java.net.URI)1 Filters (org.eclipse.che.plugin.docker.client.json.Filters)1