|
| 1 | +package com.amihaiemil.docker; |
| 2 | + |
| 3 | +import com.amihaiemil.docker.mock.AssertRequest; |
| 4 | +import com.amihaiemil.docker.mock.Response; |
| 5 | +import org.apache.http.HttpStatus; |
| 6 | +import org.hamcrest.MatcherAssert; |
| 7 | +import org.hamcrest.Matchers; |
| 8 | +import org.junit.Test; |
| 9 | +import org.mockito.Mockito; |
| 10 | + |
| 11 | +import javax.json.Json; |
| 12 | +import java.net.URI; |
| 13 | + |
| 14 | +/** |
| 15 | + * Unit tests for RtDockerSystem. |
| 16 | + * |
| 17 | + * @author Boris Kuzmic ([email protected]) |
| 18 | + * @since 0.0.6 |
| 19 | + * @checkstyle MethodName (500 lines) |
| 20 | + */ |
| 21 | +public final class RtDockerSystemTestCase { |
| 22 | + |
| 23 | + /** |
| 24 | + * Must return the same disk space usage for images, containers and |
| 25 | + * volumes as in json array returned by the service. |
| 26 | + * |
| 27 | + * @throws Exception If an error occurs. |
| 28 | + */ |
| 29 | + @Test |
| 30 | + public void returnsDiskSpaceUsage() throws Exception { |
| 31 | + long totalSpace = new RtDockerSystem( |
| 32 | + new AssertRequest( |
| 33 | + new Response( |
| 34 | + HttpStatus.SC_OK, |
| 35 | + Json.createObjectBuilder() |
| 36 | + .add("LayersSize", 250) |
| 37 | + .add( |
| 38 | + "Containers", |
| 39 | + Json.createArrayBuilder() |
| 40 | + .add( |
| 41 | + Json.createObjectBuilder() |
| 42 | + .add("SizeRootFs", 50) |
| 43 | + ).add( |
| 44 | + Json.createObjectBuilder() |
| 45 | + .add("SizeRootFs", 60) |
| 46 | + ) |
| 47 | + ) |
| 48 | + .add( |
| 49 | + "Volumes", |
| 50 | + Json.createArrayBuilder() |
| 51 | + .add( |
| 52 | + Json.createObjectBuilder() |
| 53 | + .add( |
| 54 | + "UsageData", |
| 55 | + Json.createObjectBuilder() |
| 56 | + .add("Size", 200) |
| 57 | + ) |
| 58 | + ).add( |
| 59 | + Json.createObjectBuilder() |
| 60 | + .add( |
| 61 | + "UsageData", |
| 62 | + Json.createObjectBuilder() |
| 63 | + .add("Size", 100) |
| 64 | + ) |
| 65 | + ) |
| 66 | + ).build().toString() |
| 67 | + ) |
| 68 | + ), |
| 69 | + URI.create("http://localhost/system"), |
| 70 | + Mockito.mock(Docker.class) |
| 71 | + ).diskUsage().totalSpace(); |
| 72 | + MatcherAssert.assertThat( |
| 73 | + totalSpace, |
| 74 | + Matchers.is(660L) |
| 75 | + ); |
| 76 | + } |
| 77 | + |
| 78 | + |
| 79 | +} |
0 commit comments