Skip to content

Commit

Permalink
[JBIDE-23648] fixed ImageTagTest#addUpperCaseTagToImage
Browse files Browse the repository at this point in the history
  • Loading branch information
adietish committed Dec 16, 2016
1 parent 01bda73 commit 8b78a5a
Showing 1 changed file with 64 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.apache.commons.lang.StringUtils;
import org.jboss.reddeer.common.wait.TimePeriod;
import org.jboss.reddeer.common.wait.WaitWhile;
import org.jboss.reddeer.core.condition.JobIsRunning;
import org.jboss.reddeer.core.condition.ShellWithTextIsAvailable;
import org.jboss.reddeer.eclipse.ui.views.properties.PropertiesView;
import org.jboss.reddeer.swt.impl.button.OkButton;
import org.jboss.reddeer.swt.impl.shell.DefaultShell;
import org.jboss.tools.docker.reddeer.ui.DockerImagesTab;
import org.jboss.tools.docker.ui.bot.test.AbstractDockerBotTest;
import org.junit.After;
Expand All @@ -31,53 +33,96 @@
*/

public class ImageTagTest extends AbstractDockerBotTest {
private static String imageName = "busybox";
private static String imageNameToPull = "busybox:latest";
private static String imageTag = "testtag";
private static String imageTagUppercase = "UPPERCASETAG";
private static final String IMAGE_NAME = "busybox";
private static final String IMAGE_NAME_TO_PULL = "busybox:latest";
private static final String IMAGE_TAG = "testtag";
private static String IMAGE_TAG_UPPERCASE = "UPPERCASETAG";

@Test
public void testAddRemoveTagToImage() {
DockerImagesTab imageTab = new DockerImagesTab();
imageTab.activate();
imageTab.refresh();
new WaitWhile(new JobIsRunning(), TimePeriod.NORMAL);
pullImage(imageNameToPull);
pullImage(IMAGE_NAME_TO_PULL);
new WaitWhile(new JobIsRunning());
assertTrue("Image has not been deployed!", imageIsDeployed(imageName));
assertTrue("Image has not been deployed!", imageIsDeployed(IMAGE_NAME));

imageTab.activate();
imageTab.addTagToImage(imageName, imageTag);
imageTab.addTagToImage(IMAGE_NAME, IMAGE_TAG);
new WaitWhile(new JobIsRunning());
assertTrue("Image tag has not been added", imageTab.getImageTags(imageName).contains(imageTag));
assertTrue("Image tag has not been added", imageTab.getImageTags(IMAGE_NAME).contains(IMAGE_TAG));

imageTab.activate();
imageTab.removeTagFromImage(imageName, imageTag);
imageTab.removeTagFromImage(IMAGE_NAME, IMAGE_TAG);
new WaitWhile(new JobIsRunning());
assertTrue("ImageTaghasNotBeenRemoved", !imageTab.getImageTags(imageName).contains(imageTag));
assertTrue("ImageTaghasNotBeenRemoved", !imageTab.getImageTags(IMAGE_NAME).contains(IMAGE_TAG));
}

/**
* Tries to add an uppercase tag to an image. This errors in docker daemon
* >= 1.11 while it succeeds in older versions.
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=509223
*/
@Test
public void testAddRemoveUpperCaseTagToImage() {
public void testAddUpperCaseTagToImage() {
DockerImagesTab imageTab = new DockerImagesTab();
imageTab.activate();
imageTab.refresh();
new WaitWhile(new JobIsRunning(), TimePeriod.NORMAL);
pullImage(imageNameToPull);
pullImage(IMAGE_NAME_TO_PULL);
new WaitWhile(new JobIsRunning());
assertTrue("Image has not been deployed!", imageIsDeployed(imageName));
assertTrue("Image has not been deployed!", imageIsDeployed(IMAGE_NAME));

imageTab.activate();
imageTab.addTagToImage(imageName, imageTagUppercase);
new ShellWithTextIsAvailable("Error tagging image to <" + imageTagUppercase + ">");
new OkButton().click();
assertFalse("Image tag has been added!", imageTab.getImageTags(imageName).contains(imageTag));
imageTab.addTagToImage(IMAGE_NAME, IMAGE_TAG_UPPERCASE);

if (isDockerDaemon(1, 11)) {
// docker daemon >= 1.11
new DefaultShell("Error tagging image to <" + IMAGE_TAG_UPPERCASE + ">");
new OkButton().click();
assertFalse("Image tag has been added!", imageTab.getImageTags(IMAGE_NAME).contains(IMAGE_TAG));
} else {
assertTrue("Image tag has not been added!", imageTab.getImageTags(IMAGE_NAME).contains(IMAGE_TAG_UPPERCASE));
}
}

/**
* Returns {@code true} if the running docker daemon matches at least the
* given major and minor version. Returns {@code false} otherwise.
*
* @param majorVersion
* @param minorVersion
* @return
*/
private boolean isDockerDaemon(int majorVersion, int minorVersion) {
getConnection().select();
PropertiesView infoTab = openPropertiesTab("Info");
String daemonVersion = infoTab.getProperty("Version").getPropertyValue();
assertTrue("Could not retrieve docker daemon version.", !StringUtils.isBlank(daemonVersion));
String[] versionComponents = daemonVersion.split("\\.");
assertTrue("Could not evaluate docker daemon version " + daemonVersion,
versionComponents == null || versionComponents.length >= 2);
int actualMajorVersion = Integer.parseInt(versionComponents[0]);
if (actualMajorVersion > majorVersion) {
return true;
}
int actualMinorVersion = Integer.parseInt(versionComponents[1]);
return actualMinorVersion >= minorVersion;
}

@After
public void after() {
deleteImageContainerAfter(imageName);
deleteImageContainerAfter(IMAGE_NAME);
cleanUpWorkspace();
}

protected PropertiesView openPropertiesTab(String tabName) {
PropertiesView propertiesView = new PropertiesView();
propertiesView.open();
propertiesView.selectTab(tabName);
return propertiesView;
}


}

0 comments on commit 8b78a5a

Please sign in to comment.