public String getClusterNamespace() {
   Connection connection = getConnection();
   if (connection != null) {
     return connection.getClusterNamespace();
   }
   return ICommonAttributes.COMMON_NAMESPACE;
 }
 public void setClusterNamespace(String value) {
   Connection connection = getConnection();
   if (connection != null) {
     Map<String, Object> properties = connection.getExtendedProperties();
     Object old = properties.get(ICommonAttributes.CLUSTER_NAMESPACE_KEY);
     connection.setExtendedProperty(ICommonAttributes.CLUSTER_NAMESPACE_KEY, value);
     firePropertyChange(PROP_CLUSTER_NAMESPACE, old, value);
   }
 }
 public void setRegistryURL(String value) {
   Connection connection = getConnection();
   if (connection != null) {
     Map<String, Object> properties = connection.getExtendedProperties();
     Object old = properties.get(ICommonAttributes.IMAGE_REGISTRY_URL_KEY);
     connection.setExtendedProperty(ICommonAttributes.IMAGE_REGISTRY_URL_KEY, value);
     firePropertyChange(PROP_REGISTRY_URL, old, value);
   }
 }
 public String getRegistryURL() {
   Connection connection = getConnection();
   if (connection != null) {
     Map<String, Object> properties = connection.getExtendedProperties();
     return (String)
         ObjectUtils.defaultIfNull(properties.get(ICommonAttributes.IMAGE_REGISTRY_URL_KEY), "");
   }
   return "";
 }
  private IImageStream givenAnImageStreamTo(String namespace, DockerImageURI uri) {
    IImageStream is = mock(IImageStream.class);
    when(is.getNamespace()).thenReturn(namespace);
    when(is.getName()).thenReturn(IMAGE_STREAM_NAME);
    when(is.getDockerImageRepository()).thenReturn(uri);

    List<IResource> streams = Arrays.asList(is);

    Connection conn = mock(Connection.class);
    when(conn.getResources(anyString(), eq(namespace))).thenReturn(streams);
    when(conn.getClusterNamespace()).thenReturn(ICommonAttributes.COMMON_NAMESPACE);
    when(parameters.getConnection()).thenReturn(conn);
    return is;
  }
 @Test
 public void shouldNotUpdateIfNoImageChangeTrigger() {
   givenAConnection();
   givenTheImageStreamExistsTo("myimagename");
   IDeploymentConfig dc = createResource(IDeploymentConfig.class);
   when(dc.getTriggers()).thenReturn(Collections.EMPTY_LIST);
   when(connection.getResource(
           ResourceKind.DEPLOYMENT_CONFIG, project.getName(), parameters.getResourceName()))
       .thenReturn(dc);
   assertFalse(
       job.updateTriggerIfUpdate(connection, project.getName(), parameters.getResourceName()));
 }
  @Test
  public void shouldUpdateImageTagIfItDifferesFromExisting() {
    givenAConnection();
    givenTheImageStreamExistsTo("myimagename");
    givenTheDeploymentConfigExistFor("myimagename", "v0", NAMESPACE, ResourceKind.IMAGE_STREAM_TAG);
    doReturn(DOCKER_NEW_TAG).when(job).getSourceImage();

    IResource resource =
        connection.getResource(
            ResourceKind.DEPLOYMENT_CONFIG, project.getName(), parameters.getResourceName());
    IDeploymentImageChangeTrigger trigger =
        (IDeploymentImageChangeTrigger) ((IDeploymentConfig) resource).getTriggers().toArray()[0];
    assertThat(job.doRun(monitor)).isEqualTo(Status.OK_STATUS);
    verify(trigger, times(1)).setFrom(new DockerImageURI(null, null, "myimagename", "v1"));
  }
 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);
 }
 private void givenTheImageStreamExistsTo(String name) {
   IImageStream is = createResource(IImageStream.class);
   when(connection.getResource(ResourceKind.IMAGE_STREAM, project.getName(), name)).thenReturn(is);
 }