@Test
  public void testStubDeploymentConfig() {
    IImageStream is = givenAnImageStreamTo(project.getName(), DOCKER_TAG);

    IResource resource = job.stubDeploymentConfig(factory, RESOURCE_NAME, DOCKER_TAG, is);
    assertTrue(resource instanceof IDeploymentConfig);
    IDeploymentConfig dc = (IDeploymentConfig) resource;

    assertEquals(
        "Exp. replicas to match incoming params", parameters.getReplicas(), dc.getReplicas());
    assertEquals(
        "Exp. the selector key to be the resourceName",
        RESOURCE_NAME,
        dc.getReplicaSelector().get(DeployImageJob.SELECTOR_KEY));

    IContainer container = dc.getContainer(RESOURCE_NAME);
    assertNotNull("Exp. to find a container with the resource name", container);
    Collection<IDeploymentTrigger> triggers = dc.getTriggers();
    assertTrue(
        "Exp. a config change trigger",
        triggers
            .stream()
            .filter(t -> DeploymentTriggerType.CONFIG_CHANGE.equals(t.getType()))
            .findFirst()
            .isPresent());

    // assert ict matches container spec
    Optional<IDeploymentTrigger> icTrigger =
        triggers
            .stream()
            .filter(t -> DeploymentTriggerType.IMAGE_CHANGE.equals(t.getType()))
            .findFirst();
    assertTrue(icTrigger.isPresent());

    IDeploymentImageChangeTrigger imageChangeTrigger =
        (IDeploymentImageChangeTrigger) icTrigger.get();
    Collection<String> names = imageChangeTrigger.getContainerNames();
    assertEquals(1, names.size());
    assertEquals(
        "Exp. the container and trigger names to match",
        container.getName(),
        names.iterator().next());
    assertTrue(imageChangeTrigger.isAutomatic());
    assertEquals(ResourceKind.IMAGE_STREAM_TAG, imageChangeTrigger.getKind());
    assertEquals(
        "Exp. the trigger to point to the imagestream name",
        new DockerImageURI(null, null, is.getName(), DOCKER_TAG.getTag()),
        imageChangeTrigger.getFrom());
    assertEquals(
        "Exp. the trigger to point to the imagestream name",
        is.getNamespace(),
        imageChangeTrigger.getNamespace());
  }
 private void givenTheDeploymentConfigExistFor(
     String name, String tag, String triggerNamespace, String triggerKind) {
   IDeploymentImageChangeTrigger trigger = mock(IDeploymentImageChangeTrigger.class);
   when(trigger.getType()).thenReturn(DeploymentTriggerType.IMAGE_CHANGE);
   when(trigger.getNamespace()).thenReturn(triggerNamespace);
   when(trigger.getKind()).thenReturn(triggerKind);
   when(trigger.getFrom()).thenReturn(new DockerImageURI(null, null, name, tag));
   IDeploymentConfig dc =
       createResource(
           IDeploymentConfig.class,
           new IResourceVisitor<IDeploymentConfig>() {
             @Override
             public void visit(IDeploymentConfig resource) {
               Collection<IDeploymentTrigger> triggers = new ArrayList<IDeploymentTrigger>();
               triggers.add(trigger);
               when(resource.getTriggers()).thenReturn(triggers);
             }
           });
   when(connection.getResource(
           ResourceKind.DEPLOYMENT_CONFIG, project.getName(), parameters.getResourceName()))
       .thenReturn(dc);
 }