Search in sources :

Example 6 with IDeploymentImageChangeTrigger

use of com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger in project jbosstools-openshift by jbosstools.

the class DeployImageJobTest method testStubDeploymentConfig.

@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.getNamespaceName(), imageChangeTrigger.getNamespace());
}
Also used : Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger) IStatus(org.eclipse.core.runtime.IStatus) DeployImageJob(org.jboss.tools.openshift.internal.ui.job.DeployImageJob) IDeploymentTrigger(com.openshift.restclient.model.deploy.IDeploymentTrigger) Matchers.eq(org.mockito.Matchers.eq) IResourceVisitor(org.jboss.tools.openshift.test.util.ResourceMocks.IResourceVisitor) Mockito.doReturn(org.mockito.Mockito.doReturn) ResourceKind(com.openshift.restclient.ResourceKind) Collection(java.util.Collection) Status(org.eclipse.core.runtime.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) Matchers.any(org.mockito.Matchers.any) List(java.util.List) ICommonAttributes(org.jboss.tools.openshift.core.ICommonAttributes) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) ResourceMocks.createResource(org.jboss.tools.openshift.test.util.ResourceMocks.createResource) Mockito.mock(org.mockito.Mockito.mock) ResourceFactory(com.openshift.internal.restclient.ResourceFactory) Mock(org.mockito.Mock) IImageStream(com.openshift.restclient.model.IImageStream) RunWith(org.junit.runner.RunWith) Mockito.spy(org.mockito.Mockito.spy) Matchers.anyString(org.mockito.Matchers.anyString) IProject(com.openshift.restclient.model.IProject) ArrayList(java.util.ArrayList) ResourceMocks.createConnection(org.jboss.tools.openshift.test.util.ResourceMocks.createConnection) IResourceFactory(com.openshift.restclient.IResourceFactory) Before(org.junit.Before) DockerImageURI(com.openshift.restclient.images.DockerImageURI) IResource(com.openshift.restclient.model.IResource) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Connection(org.jboss.tools.openshift.core.connection.Connection) Mockito.verify(org.mockito.Mockito.verify) IDeployImageParameters(org.jboss.tools.openshift.internal.ui.wizard.deployimage.IDeployImageParameters) Assert.assertNull(org.junit.Assert.assertNull) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) IClient(com.openshift.restclient.IClient) DeploymentTriggerType(com.openshift.restclient.model.deploy.DeploymentTriggerType) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) IContainer(com.openshift.restclient.model.IContainer) DockerImageURI(com.openshift.restclient.images.DockerImageURI) IImageStream(com.openshift.restclient.model.IImageStream) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IDeploymentTrigger(com.openshift.restclient.model.deploy.IDeploymentTrigger) Matchers.anyString(org.mockito.Matchers.anyString) IContainer(com.openshift.restclient.model.IContainer) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger) IResource(com.openshift.restclient.model.IResource) Test(org.junit.Test)

Example 7 with IDeploymentImageChangeTrigger

use of com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger in project jbosstools-openshift by jbosstools.

the class DeployImageJobTest method shouldUpdateImageTagIfItDifferesFromExisting.

@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"));
}
Also used : DockerImageURI(com.openshift.restclient.images.DockerImageURI) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger) IResource(com.openshift.restclient.model.IResource) Test(org.junit.Test)

Example 8 with IDeploymentImageChangeTrigger

use of com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger in project jbosstools-openshift by jbosstools.

the class ResourceUtilsTest method testImageRefForDeploymentImageChangeTrigger.

@Test
public void testImageRefForDeploymentImageChangeTrigger() {
    assertEquals("", imageRef((IDeploymentImageChangeTrigger) null));
    when(deployTrigger.getKind()).thenReturn("something");
    assertEquals("", imageRef(deployTrigger));
    DockerImageURI uri = new DockerImageURI(IMAGE_REF);
    when(deployTrigger.getFrom()).thenReturn(uri);
    when(deployTrigger.getKind()).thenReturn(ResourceKind.IMAGE_STREAM_TAG);
    assertEquals(IMAGE_REF, imageRef(deployTrigger));
    when(deployTrigger.getKind()).thenReturn(ResourceUtils.IMAGE_STREAM_IMAGE_KIND);
    assertEquals(IMAGE_REF, imageRef(deployTrigger));
    when(deployTrigger.getKind()).thenReturn(ResourceUtils.DOCKER_IMAGE_KIND);
    assertEquals(IMAGE_REF, imageRef(deployTrigger));
}
Also used : DockerImageURI(com.openshift.restclient.images.DockerImageURI) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger) Test(org.junit.Test)

Example 9 with IDeploymentImageChangeTrigger

use of com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger in project jbosstools-openshift by jbosstools.

the class DeployImageJobTest method givenTheDeploymentConfigExistFor.

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, ResourceKind.DEPLOYMENT_CONFIG, 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);
}
Also used : DockerImageURI(com.openshift.restclient.images.DockerImageURI) Collection(java.util.Collection) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IDeploymentTrigger(com.openshift.restclient.model.deploy.IDeploymentTrigger) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger)

Aggregations

IDeploymentImageChangeTrigger (com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger)9 DockerImageURI (com.openshift.restclient.images.DockerImageURI)8 IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)5 IResource (com.openshift.restclient.model.IResource)4 Collection (java.util.Collection)3 Test (org.junit.Test)3 IResourceFactory (com.openshift.restclient.IResourceFactory)2 ResourceKind (com.openshift.restclient.ResourceKind)2 IImageStream (com.openshift.restclient.model.IImageStream)2 IProject (com.openshift.restclient.model.IProject)2 DeploymentTriggerType (com.openshift.restclient.model.deploy.DeploymentTriggerType)2 IDeploymentTrigger (com.openshift.restclient.model.deploy.IDeploymentTrigger)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 ICommonAttributes (org.jboss.tools.openshift.core.ICommonAttributes)2 Connection (org.jboss.tools.openshift.core.connection.Connection)2