2121import org .testng .collections .Lists ;
2222
2323import java .lang .reflect .Method ;
24+ import java .util .Arrays ;
25+ import java .util .HashMap ;
2426import java .util .List ;
27+ import java .util .Map ;
2528
2629import static org .hamcrest .MatcherAssert .assertThat ;
30+ import static org .hamcrest .Matchers .containsString ;
2731import static org .hamcrest .Matchers .hasSize ;
2832import static org .hamcrest .Matchers .is ;
33+ import static org .hamcrest .Matchers .notNullValue ;
2934
3035@ Test (groups = "swarm-integration" )
3136public class CreateServiceCmdExecTest extends AbstractSwarmDockerClientTest {
@@ -59,11 +64,13 @@ public void testCreateService() throws DockerException {
5964 .withListenAddr ("127.0.0.1" )
6065 .withAdvertiseAddr ("127.0.0.1" )
6166 .exec ();
62-
67+ List <String > command = Arrays .asList ("sleep" , "300" );
68+ Map <String ,String > labels =new HashMap <>();
69+ labels .put ("com.docker.java.usage" ,"test" );
6370 dockerClient .createServiceCmd (new ServiceSpec ()
64- .withName (SERVICE_NAME )
71+ .withName (SERVICE_NAME ). withLabels ( labels )
6572 .withTaskTemplate (new TaskSpec ()
66- .withContainerSpec (new ContainerSpec ()
73+ .withContainerSpec (new ContainerSpec (). withCommand ( command )
6774 .withImage ("busybox" ))))
6875 .exec ();
6976
@@ -72,7 +79,7 @@ public void testCreateService() throws DockerException {
7279 .exec ();
7380
7481 assertThat (services , hasSize (1 ));
75-
82+ assertThat ( services . get ( 0 ). getSpec (). getLabels (). get ( "com.docker.java.usage" ), is ( "test" ));
7683 dockerClient .removeServiceCmd (SERVICE_NAME ).exec ();
7784 }
7885
0 commit comments