From b0635d2d657401599a60bf6c15bcf2df85c08404 Mon Sep 17 00:00:00 2001 From: Jeff Cantrill Date: Thu, 21 Aug 2014 11:33:59 -0400 Subject: [PATCH 1/2] [OSJC-101] Add support for setting and retrieving additional gear storage --- .../com/openshift/client/IApplication.java | 11 +- .../java/com/openshift/client/IGearGroup.java | 10 ++ .../IDeployedStandaloneCartridge.java | 44 +++++ .../client/cartridge/IEmbeddedCartridge.java | 21 +-- .../client/cartridge/StandaloneCartridge.java | 7 +- .../internal/client/ApplicationResource.java | 43 +++-- .../client/EmbeddedCartridgeResource.java | 34 +++- .../internal/client/GearGroupResource.java | 15 +- .../client/StandaloneCartridgeResource.java | 162 ++++++++++++++++++ .../client/cartridge/BaseCartridge.java | 3 +- .../client/response/GearGroupResourceDTO.java | 20 ++- .../response/OpenShiftJsonDTOFactory.java | 8 +- .../client/utils/IOpenShiftJsonConstants.java | 1 + .../client/utils/ApplicationTestUtils.java | 2 +- .../client/utils/CartridgeAssert.java | 3 +- .../DeployedStandaloneCartridgeAssert.java | 36 ++++ .../client/utils/GearGroupAssert.java | 8 +- .../ApplicationResourceIntegrationTest.java | 20 +-- .../client/GearGroupsResourceTest.java | 1 + .../client/OpenShiftIntegrationTestSuite.java | 2 +- .../internal/client/OpenShiftTestSuite.java | 1 + ...aloneCartridgeResourceIntegrationTest.java | 132 ++++++++++++++ .../StandaloneCartridgeResourceTest.java | 103 +++++++++++ .../client/StandaloneCartridgeTest.java | 15 +- .../StandaloneCartridgesIntegrationTest.java | 70 -------- ...rz-applications-springeap6-geargroups.json | 2 +- 26 files changed, 642 insertions(+), 132 deletions(-) create mode 100644 src/main/java/com/openshift/client/cartridge/IDeployedStandaloneCartridge.java create mode 100644 src/main/java/com/openshift/internal/client/StandaloneCartridgeResource.java create mode 100644 src/test/java/com/openshift/client/utils/DeployedStandaloneCartridgeAssert.java create mode 100755 src/test/java/com/openshift/internal/client/StandaloneCartridgeResourceIntegrationTest.java create mode 100644 src/test/java/com/openshift/internal/client/StandaloneCartridgeResourceTest.java delete mode 100755 src/test/java/com/openshift/internal/client/StandaloneCartridgesIntegrationTest.java diff --git a/src/main/java/com/openshift/client/IApplication.java b/src/main/java/com/openshift/client/IApplication.java index 55d0340b..433443ba 100755 --- a/src/main/java/com/openshift/client/IApplication.java +++ b/src/main/java/com/openshift/client/IApplication.java @@ -19,15 +19,16 @@ import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; import com.openshift.client.cartridge.ICartridge; +import com.openshift.client.cartridge.IDeployedStandaloneCartridge; import com.openshift.client.cartridge.IEmbeddableCartridge; import com.openshift.client.cartridge.IEmbeddedCartridge; -import com.openshift.client.cartridge.IStandaloneCartridge; import com.openshift.internal.client.ApplicationResource; /** * @author André Dietisheim * @author Syed Iqbal * @author Martes G Wigglesworth + * @author Jeff Cantrill */ public interface IApplication extends IOpenShiftResource { @@ -67,9 +68,11 @@ public interface IApplication extends IOpenShiftResource { * @return the initial git url */ public String getInitialGitUrl(); - + /** - * Returns the deployment type for this application. Either "binary" or "git" currently. + * Returns the deployment type for this application. Either "binary" or + * "git" currently. + * * @return "binary" or "git" */ public String getDeploymentType(); @@ -105,7 +108,7 @@ public interface IApplication extends IOpenShiftResource { * @return the cartridge of this application * */ - public IStandaloneCartridge getCartridge(); + public IDeployedStandaloneCartridge getCartridge(); /** * Adds the given embeddable cartridge to this application. diff --git a/src/main/java/com/openshift/client/IGearGroup.java b/src/main/java/com/openshift/client/IGearGroup.java index 2e4023d8..689ffd40 100755 --- a/src/main/java/com/openshift/client/IGearGroup.java +++ b/src/main/java/com/openshift/client/IGearGroup.java @@ -16,6 +16,8 @@ public interface IGearGroup { + public static final int NO_ADDITIONAL_GEAR_STORAGE = -1; + /** * Returns the uuid of this gear groups. * @@ -43,4 +45,12 @@ public interface IGearGroup { * @return the gears */ public Collection getCartridges(); + + /** + * Returns the additional storage configured for this gear group in gigabytes + * + * @return the additional storage value + */ + public int getAdditionalStorage(); + } diff --git a/src/main/java/com/openshift/client/cartridge/IDeployedStandaloneCartridge.java b/src/main/java/com/openshift/client/cartridge/IDeployedStandaloneCartridge.java new file mode 100644 index 00000000..c8c73c1f --- /dev/null +++ b/src/main/java/com/openshift/client/cartridge/IDeployedStandaloneCartridge.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2014 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package com.openshift.client.cartridge; + +import com.openshift.client.IGearGroup; + +/** + * Represents a standalone cartridge that has been deployed as opposed to IStandaloneCartridge + * which really represents the metadata about a standalone cartridge + * + * @author Jeff Cantrill + * @author Andre Dietisheim + */ +public interface IDeployedStandaloneCartridge extends IStandaloneCartridge{ + + /** + * set the additional gear storage for the cartridge to the given + * size. + * + * @param size The total additional gear storage for the cartridge + * in gigabytes + */ + public void setAdditionalGearStorage(int size); + + /** + * Returns the additional gear storage for this cartridge + * @return + */ + public int getAdditionalGearStorage(); + + /** + * Returns the gear group that this cartridge is deployed on + * @return + */ + public IGearGroup getGearGroup(); +} diff --git a/src/main/java/com/openshift/client/cartridge/IEmbeddedCartridge.java b/src/main/java/com/openshift/client/cartridge/IEmbeddedCartridge.java index 9f71ccbc..8147cbac 100755 --- a/src/main/java/com/openshift/client/cartridge/IEmbeddedCartridge.java +++ b/src/main/java/com/openshift/client/cartridge/IEmbeddedCartridge.java @@ -10,8 +10,6 @@ ******************************************************************************/ package com.openshift.client.cartridge; -import java.net.URL; - import com.openshift.client.IApplication; import com.openshift.client.IOpenShiftResource; import com.openshift.client.OpenShiftException; @@ -19,18 +17,12 @@ /** * Interface to designate a cartridge that has been added and configured + * * @author André Dietisheim + * @author Jeff Cantrill */ public interface IEmbeddedCartridge extends IOpenShiftResource, IEmbeddableCartridge { - /** - * The url at which this cartridge may be reached - * - * @return the url for this cartridge - * @throws OpenShiftException - */ - public URL getUrl() throws OpenShiftException; - /** * Destroys this cartridge (and removes it from the list of existing cartridges) * @@ -52,4 +44,13 @@ public interface IEmbeddedCartridge extends IOpenShiftResource, IEmbeddableCartr * @return the resource properties */ public CartridgeResourceProperties getProperties(); + + /** + * set the additional gear storage for the cartridge to the given + * size. + * + * @param size The total additional gear storage for the cartridge + * in gigabytes + */ + public void setAdditionalGearStorage(int size); } \ No newline at end of file diff --git a/src/main/java/com/openshift/client/cartridge/StandaloneCartridge.java b/src/main/java/com/openshift/client/cartridge/StandaloneCartridge.java index 915c46ba..30bbb445 100755 --- a/src/main/java/com/openshift/client/cartridge/StandaloneCartridge.java +++ b/src/main/java/com/openshift/client/cartridge/StandaloneCartridge.java @@ -23,6 +23,7 @@ * since we dont know all available types and they may change at any time. * * @author André Dietisheim + * @author Jeff Cantrill */ public class StandaloneCartridge extends BaseCartridge implements IStandaloneCartridge { @@ -56,8 +57,12 @@ public StandaloneCartridge(String name, URL url, String displayName, String desc super(name, url, displayName, description); } + public StandaloneCartridge(String name, URL url, String displayName, String description) { + this(name, url, displayName, description, false); + } + @Override public CartridgeType getType() { return CartridgeType.STANDALONE; } -} \ No newline at end of file +} diff --git a/src/main/java/com/openshift/internal/client/ApplicationResource.java b/src/main/java/com/openshift/internal/client/ApplicationResource.java index f6e15689..80181388 100755 --- a/src/main/java/com/openshift/internal/client/ApplicationResource.java +++ b/src/main/java/com/openshift/internal/client/ApplicationResource.java @@ -49,10 +49,9 @@ import com.openshift.client.OpenShiftException; import com.openshift.client.OpenShiftSSHOperationException; import com.openshift.client.cartridge.ICartridge; +import com.openshift.client.cartridge.IDeployedStandaloneCartridge; import com.openshift.client.cartridge.IEmbeddableCartridge; import com.openshift.client.cartridge.IEmbeddedCartridge; -import com.openshift.client.cartridge.IStandaloneCartridge; -import com.openshift.client.cartridge.StandaloneCartridge; import com.openshift.client.utils.HostUtils; import com.openshift.client.utils.RFC822DateUtils; import com.openshift.internal.client.httpclient.request.StringParameter; @@ -73,6 +72,7 @@ * @author André Dietisheim * @author Syed Iqbal * @author Martes G Wigglesworth + * @author Jeff Cantrill */ public class ApplicationResource extends AbstractOpenShiftResource implements IApplication { @@ -107,7 +107,7 @@ public class ApplicationResource extends AbstractOpenShiftResource implements IA private Date creationTime; /** The cartridge (application type/framework) of this application. */ - private IStandaloneCartridge cartridge; + private IDeployedStandaloneCartridge cartridge; /** The scalability enablement. */ private ApplicationScale scale; @@ -235,7 +235,7 @@ public String getUUID() { } @Override - public IStandaloneCartridge getCartridge() { + public IDeployedStandaloneCartridge getCartridge() { return cartridge; } @@ -449,7 +449,7 @@ private void updateCartridges(Map cartridgeDTOByNa for (CartridgeResourceDTO cartridgeDTO : cartridgeDTOByName.values()) { switch(cartridgeDTO.getType()) { case STANDALONE: - createStandaloneCartrdige(cartridgeDTO); + createStandaloneCartridge(cartridgeDTO); break; case EMBEDDED: addOrUpdateEmbeddedCartridge(cartridgeDTO.getName(), cartridgeDTO); @@ -460,13 +460,8 @@ private void updateCartridges(Map cartridgeDTOByNa } } - private void createStandaloneCartrdige(CartridgeResourceDTO cartridgeDTO) { - this.cartridge = new StandaloneCartridge( - cartridgeDTO.getName(), - cartridgeDTO.getUrl(), - cartridgeDTO.getDisplayName(), - cartridgeDTO.getDescription(), - cartridgeDTO.getObsolete()); + private void createStandaloneCartridge(CartridgeResourceDTO dto) { + this.cartridge = new StandaloneCartridgeResource(dto,this); } private void addOrUpdateEmbeddedCartridge(String name, CartridgeResourceDTO cartridgeDTO) { @@ -544,6 +539,7 @@ public void removeEmbeddedCartridges(Collection cartridges } } + @Override public Collection getGearGroups() throws OpenShiftException { // this collection is not cached so we always have the latest info // about the gear groups consumed by this application. @@ -551,6 +547,29 @@ public Collection getGearGroups() throws OpenShiftException { return gearGroups; } + public IGearGroup getGearGroup(ICartridge cartridge) throws OpenShiftException { + // this collection is not cached so we always have the latest info + // about the gear groups consumed by this application. + loadGearGroups(); + return getGearGroup(cartridge, gearGroups); + } + + public IGearGroup getGearGroup(ICartridge cartridge, Collection gearGroups) { + if (cartridge == null + || gearGroups == null) { + return null; + } + + for (IGearGroup gearGroup : gearGroups) { + for (ICartridge groupCartridge : gearGroup.getCartridges()) { + if (cartridge.equals(cartridge)) { + return gearGroup; + } + } + } + return null; + } + private Collection loadGearGroups() throws OpenShiftException { List gearGroups = new ArrayList(); Collection dtos = new GetGearGroupsRequest().execute(); diff --git a/src/main/java/com/openshift/internal/client/EmbeddedCartridgeResource.java b/src/main/java/com/openshift/internal/client/EmbeddedCartridgeResource.java index 693ca89e..4c36ba82 100755 --- a/src/main/java/com/openshift/internal/client/EmbeddedCartridgeResource.java +++ b/src/main/java/com/openshift/internal/client/EmbeddedCartridgeResource.java @@ -17,8 +17,10 @@ import com.openshift.client.cartridge.EmbeddableCartridge; import com.openshift.client.cartridge.IEmbeddableCartridge; import com.openshift.client.cartridge.IEmbeddedCartridge; +import com.openshift.internal.client.httpclient.request.Parameter; import com.openshift.internal.client.response.CartridgeResourceDTO; import com.openshift.internal.client.response.CartridgeResourceProperties; +import com.openshift.internal.client.utils.IOpenShiftJsonConstants; /** * A cartridge that is embedded into an application. @@ -28,6 +30,7 @@ public class EmbeddedCartridgeResource extends AbstractOpenShiftResource implements IEmbeddedCartridge { private static final String LINK_DELETE_CARTRIDGE = "DELETE"; + private static final String LINK_UPDATE_CARTRIDGE = "UPDATE"; private final String name; private String displayName; @@ -98,6 +101,16 @@ protected void update(CartridgeResourceDTO dto) { setLinks(dto.getLinks()); } + /** + * Update the additional gear storage for this cartridge to the given value + * + * @param size The total size of storage in gigabytes for the gear + */ + @Override + public void setAdditionalGearStorage(int size) { + new UpdateCartridgeRequest().execute(new Parameter(IOpenShiftJsonConstants.PROPERTY_ADDITIONAL_GEAR_STORAGE, String.valueOf(size))); + + } /** * Refreshes the content of this embedded cartridge. Causes all embedded * cartridges of the same application to get updated. @@ -137,18 +150,24 @@ public int hashCode() { */ @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (!(IEmbeddableCartridge.class.isAssignableFrom(obj.getClass()))) + } + if (!(IEmbeddableCartridge.class.isAssignableFrom(obj.getClass()))) { return false; + } IEmbeddableCartridge other = (IEmbeddableCartridge) obj; if (name == null) { - if (other.getName() != null) + if (other.getName() != null) { return false; - } else if (!name.equals(other.getName())) + } + } + if (!name.equals(other.getName())) { return false; + } return true; } @@ -170,4 +189,9 @@ private DeleteCartridgeRequest() { super(LINK_DELETE_CARTRIDGE); } } + private class UpdateCartridgeRequest extends ServiceRequest { + private UpdateCartridgeRequest() { + super(LINK_UPDATE_CARTRIDGE); + } + } } diff --git a/src/main/java/com/openshift/internal/client/GearGroupResource.java b/src/main/java/com/openshift/internal/client/GearGroupResource.java index 38d93ce6..3aebf516 100755 --- a/src/main/java/com/openshift/internal/client/GearGroupResource.java +++ b/src/main/java/com/openshift/internal/client/GearGroupResource.java @@ -42,6 +42,9 @@ public class GearGroupResource extends AbstractOpenShiftResource implements IGea /** the gears of this gear group resource */ private final Collection gears; + /** the additional storage configured for this gear group, in gigabytes */ + private final int additionalStorage; + /** the cartridges in this gear group resource */ private final Collection cartridges; @@ -52,15 +55,17 @@ public class GearGroupResource extends AbstractOpenShiftResource implements IGea * @param name the gear group's name * @param gearDTOs the gear group's gears * @param cartridgeDTOs the gear group's cartridges, indexed by their name + * @param additionalStorage the gear group's additional storage value * @param application the gear group's parent application * @param service the underlying REST Service */ protected GearGroupResource(final String uuid, final String name, final Collection gearDTOs, - final Map cartridgeDTOs, final ApplicationResource application, final IRestService service) { + final Map cartridgeDTOs, final int additionalStorage, final ApplicationResource application, final IRestService service) { super(service); this.uuid = uuid; this.name = name; this.gears = new ArrayList(); + this.additionalStorage = additionalStorage; for(GearResourceDTO dto : gearDTOs) { this.gears.add(new Gear(dto.getUuid(), new GearState(dto.getState()), dto.getSshUrl())); } @@ -82,7 +87,7 @@ protected GearGroupResource(final String uuid, final String name, final Collecti * @param servicethe underlying REST Service */ protected GearGroupResource(final GearGroupResourceDTO dto, final ApplicationResource application, final IRestService service) { - this(dto.getUuid(), dto.getName(), dto.getGears(), dto.getCartridges(), application, service); + this(dto.getUuid(), dto.getName(), dto.getGears(), dto.getCartridges(), dto.getAdditionalStorage(), application, service); } public final String getUUID() { @@ -92,11 +97,15 @@ public final String getUUID() { public final String getName() { return name; } - + public Collection getGears() { return Collections.unmodifiableCollection(gears); } + public int getAdditionalStorage() { + return additionalStorage; + } + /** * @return the cartridges */ diff --git a/src/main/java/com/openshift/internal/client/StandaloneCartridgeResource.java b/src/main/java/com/openshift/internal/client/StandaloneCartridgeResource.java new file mode 100644 index 00000000..6877a018 --- /dev/null +++ b/src/main/java/com/openshift/internal/client/StandaloneCartridgeResource.java @@ -0,0 +1,162 @@ +/******************************************************************************* + * Copyright (c) 2014 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat, Inc. + ******************************************************************************/ +package com.openshift.internal.client; + +import java.net.URL; + +import com.openshift.client.IGearGroup; +import com.openshift.client.OpenShiftException; +import com.openshift.client.cartridge.IDeployedStandaloneCartridge; +import com.openshift.client.cartridge.IStandaloneCartridge; +import com.openshift.internal.client.httpclient.request.Parameter; +import com.openshift.internal.client.response.CartridgeResourceDTO; +import com.openshift.internal.client.utils.Assert; +import com.openshift.internal.client.utils.IOpenShiftJsonConstants; + +/** + * A deployed standalone cartridge. + * + * @author Jeff Cantrill + * @author Andre Dietisheim + */ +public class StandaloneCartridgeResource extends AbstractOpenShiftResource implements IStandaloneCartridge, + IDeployedStandaloneCartridge { + + private static final String LINK_UPDATE_CARTRIDGE = "UPDATE"; + + private ApplicationResource application; + private String name; + private String displayName; + private String description; + private URL url; + private CartridgeType cartridgeType; + private boolean obsolete; + + protected StandaloneCartridgeResource(final CartridgeResourceDTO dto, final ApplicationResource application) { + super(application.getService(), dto.getLinks(), dto.getMessages()); + Assert.isTrue(dto.getType().equals(CartridgeType.STANDALONE)); + this.application = application; + this.name = dto.getName(); + this.displayName = dto.getDisplayName(); + this.description = dto.getDescription(); + this.url = dto.getUrl(); + this.cartridgeType = dto.getType(); + this.obsolete = dto.getObsolete(); + } + + /** + * set the additional gear storage for this cartridge to the given value + * + * @param size + * The total size of storage in gigabytes for the gear + */ + @Override + public void setAdditionalGearStorage(int size) { + new UpdateCartridgeRequest().execute( + new Parameter(IOpenShiftJsonConstants.PROPERTY_ADDITIONAL_GEAR_STORAGE, String.valueOf(size))); + } + + @Override + public int getAdditionalGearStorage() { + IGearGroup gearGroup = getGearGroup(); + if (gearGroup == null) { + return IGearGroup.NO_ADDITIONAL_GEAR_STORAGE; + } + return gearGroup.getAdditionalStorage(); + + } + + @Override + public IGearGroup getGearGroup() { + return application.getGearGroup(this); + } + + /** + * Refreshes the content of this embedded cartridge. Causes all embedded + * cartridges of the same application to get updated. + * + * @see #update(CartridgeResourceDTO) + * @see ApplicationResource#refreshEmbeddedCartridges() + */ + @Override + public void refresh() throws OpenShiftException { + application.refreshEmbeddedCartridges(); + } + + @Override + public String getName() { + return this.name; + } + + @Override + public String getDisplayName() { + return this.displayName; + } + + @Override + public String getDescription() { + return this.description; + } + + @Override + public boolean isDownloadable() { + return this.url != null; + } + + @Override + public URL getUrl() { + return this.url; + } + + @Override + public CartridgeType getType() { + return this.cartridgeType; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (!IStandaloneCartridge.class.isAssignableFrom(obj.getClass())) + return false; + IStandaloneCartridge other = (IStandaloneCartridge) obj; + if (name == null) { + if (other.getName() != null) { + return false; + } + } + if (!name.equals(other.getName())) { + return false; + } + return true; + } + + private class UpdateCartridgeRequest extends ServiceRequest { + private UpdateCartridgeRequest() { + super(LINK_UPDATE_CARTRIDGE); + } + } + + @Override + public boolean isObsolete() { + return obsolete; + } +} diff --git a/src/main/java/com/openshift/internal/client/cartridge/BaseCartridge.java b/src/main/java/com/openshift/internal/client/cartridge/BaseCartridge.java index 95839e9f..030eca38 100644 --- a/src/main/java/com/openshift/internal/client/cartridge/BaseCartridge.java +++ b/src/main/java/com/openshift/internal/client/cartridge/BaseCartridge.java @@ -15,6 +15,7 @@ import com.openshift.client.cartridge.EmbeddableCartridge; import com.openshift.client.cartridge.ICartridge; import com.openshift.client.cartridge.StandaloneCartridge; +import com.openshift.internal.client.APIResource; import com.openshift.internal.client.CartridgeType; import com.openshift.internal.client.utils.StringUtils; @@ -127,7 +128,7 @@ public boolean equals(Object obj) { if (obj == null) { return false; } - if (!(obj instanceof BaseCartridge)) { + if (!(BaseCartridge.class.isAssignableFrom(obj.getClass()))) { return false; } diff --git a/src/main/java/com/openshift/internal/client/response/GearGroupResourceDTO.java b/src/main/java/com/openshift/internal/client/response/GearGroupResourceDTO.java index b1af5e6a..8ad81ccb 100644 --- a/src/main/java/com/openshift/internal/client/response/GearGroupResourceDTO.java +++ b/src/main/java/com/openshift/internal/client/response/GearGroupResourceDTO.java @@ -17,6 +17,7 @@ * The DTO for a gear groups * * @author Andre Dietisheim + * @author Jeff Cantrill */ public class GearGroupResourceDTO extends BaseResourceDTO { @@ -32,6 +33,11 @@ public class GearGroupResourceDTO extends BaseResourceDTO { /** The cartridges part of this group, indexed by their name. */ private final Map cartridges; + /** + * The additional storage configured for this gear group in gigabytes + */ + private int additionalStorage; + /** * Instantiates a new gears resource dto. * @@ -43,14 +49,17 @@ public class GearGroupResourceDTO extends BaseResourceDTO { * the gears in this group * @param cartridges * the cartridges in this group + * @param additionalStorage + * the additional storage in gigabytes for this gear group * */ - GearGroupResourceDTO(final String uuid, final String name, final Collection gears, final Map cartridges) { + GearGroupResourceDTO(final String uuid, final String name, final int additionalStorage, final Collection gears, final Map cartridges) { super(); this.uuid = uuid; this.name = name; this.gears = gears; this.cartridges = cartridges; + this.additionalStorage = additionalStorage; } /** @@ -96,4 +105,13 @@ public CartridgeResourceDTO getCartridge(final String name) { return cartridges.get(name); } + /** + * Returns the additional storage configured for this gear group in gigabytes + * + * @return the additional storage value + */ + public int getAdditionalStorage(){ + return this.additionalStorage; + } + } diff --git a/src/main/java/com/openshift/internal/client/response/OpenShiftJsonDTOFactory.java b/src/main/java/com/openshift/internal/client/response/OpenShiftJsonDTOFactory.java index 620af692..905afab6 100755 --- a/src/main/java/com/openshift/internal/client/response/OpenShiftJsonDTOFactory.java +++ b/src/main/java/com/openshift/internal/client/response/OpenShiftJsonDTOFactory.java @@ -10,6 +10,7 @@ ******************************************************************************/ package com.openshift.internal.client.response; +import static com.openshift.internal.client.utils.IOpenShiftJsonConstants.PROPERTY_ADDITIONAL_GEAR_STORAGE; import static com.openshift.internal.client.utils.IOpenShiftJsonConstants.PROPERTY_ALIASES; import static com.openshift.internal.client.utils.IOpenShiftJsonConstants.PROPERTY_APP_URL; import static com.openshift.internal.client.utils.IOpenShiftJsonConstants.PROPERTY_CARTRIDGES; @@ -50,9 +51,6 @@ import static com.openshift.internal.client.utils.IOpenShiftJsonConstants.PROPERTY_UUID; import static com.openshift.internal.client.utils.IOpenShiftJsonConstants.PROPERTY_VALID_OPTIONS; import static com.openshift.internal.client.utils.IOpenShiftJsonConstants.PROPERTY_VALUE; -import static com.openshift.internal.client.utils.IOpenShiftJsonConstants.PROPERTY_NOTE; -import static com.openshift.internal.client.utils.IOpenShiftJsonConstants.PROPERTY_SCOPES; -import static com.openshift.internal.client.utils.IOpenShiftJsonConstants.PROPERTY_TOKEN; import java.net.MalformedURLException; import java.net.URL; @@ -84,6 +82,7 @@ * @author Xavier Coulon * @author Andre Dietisheim * @author Sean Kavanagh + * @author Jeff Cantrill */ public class OpenShiftJsonDTOFactory extends AbstractJsonDTOFactory { @@ -415,9 +414,10 @@ private GearGroupResourceDTO createGearGroupResourceDTO(ModelNode gearGroupNode) } final String uuid = getAsString(gearGroupNode, PROPERTY_UUID); final String name = getAsString(gearGroupNode, PROPERTY_NAME); + final int additionalStorage = getAsInteger(gearGroupNode, PROPERTY_ADDITIONAL_GEAR_STORAGE); final Collection gears = createGears(gearGroupNode.get(PROPERTY_GEARS)); final Map cartridges = createCartridges(gearGroupNode.get(PROPERTY_CARTRIDGES)); - return new GearGroupResourceDTO(uuid, name, gears, cartridges); + return new GearGroupResourceDTO(uuid, name, additionalStorage, gears, cartridges); } private Collection createGears(ModelNode gearsNode) { diff --git a/src/main/java/com/openshift/internal/client/utils/IOpenShiftJsonConstants.java b/src/main/java/com/openshift/internal/client/utils/IOpenShiftJsonConstants.java index 619972ac..73a264f2 100755 --- a/src/main/java/com/openshift/internal/client/utils/IOpenShiftJsonConstants.java +++ b/src/main/java/com/openshift/internal/client/utils/IOpenShiftJsonConstants.java @@ -17,6 +17,7 @@ public class IOpenShiftJsonConstants { public static final String PROPERTY_ACTION = "action"; + public static final String PROPERTY_ADDITIONAL_GEAR_STORAGE = "additional_gear_storage"; public static final String PROPERTY_ALIAS = "alias"; public static final String PROPERTY_ALIASES = "aliases"; public static final String PROPERTY_ALTER = "alter"; diff --git a/src/test/java/com/openshift/client/utils/ApplicationTestUtils.java b/src/test/java/com/openshift/client/utils/ApplicationTestUtils.java index c63547ed..3697fae1 100755 --- a/src/test/java/com/openshift/client/utils/ApplicationTestUtils.java +++ b/src/test/java/com/openshift/client/utils/ApplicationTestUtils.java @@ -91,7 +91,7 @@ public static void silentlyDestroyAllApplicationsByCartridge(IStandaloneCartridg } public static IApplication getOrCreateApplication(IDomain domain) throws OpenShiftException { - return getOrCreateApplication(domain, LatestVersionOf.jbossAs().get(domain.getUser())); + return getOrCreateApplication(domain, LatestVersionOf.php().get(domain.getUser())); } public static IApplication getOrCreateApplication(IDomain domain, IStandaloneCartridge cartridge) diff --git a/src/test/java/com/openshift/client/utils/CartridgeAssert.java b/src/test/java/com/openshift/client/utils/CartridgeAssert.java index 86a7cd4c..5faecffa 100644 --- a/src/test/java/com/openshift/client/utils/CartridgeAssert.java +++ b/src/test/java/com/openshift/client/utils/CartridgeAssert.java @@ -18,7 +18,6 @@ import com.openshift.client.OpenShiftException; import com.openshift.client.cartridge.ICartridge; -import com.openshift.internal.client.cartridge.BaseCartridge; /** * @author André Dietisheim @@ -92,7 +91,7 @@ public CartridgeAssert hasUrl(String url) throws OpenShiftException { return this; } - public CartridgeAssert isEqualsTo(BaseCartridge otherCartridge) throws OpenShiftException { + public CartridgeAssert isEqualTo(C otherCartridge) throws OpenShiftException { assertThat(otherCartridge).isNotNull(); hasName(otherCartridge.getName()); hasDescription(otherCartridge.getDescription()); diff --git a/src/test/java/com/openshift/client/utils/DeployedStandaloneCartridgeAssert.java b/src/test/java/com/openshift/client/utils/DeployedStandaloneCartridgeAssert.java new file mode 100644 index 00000000..3dc3d138 --- /dev/null +++ b/src/test/java/com/openshift/client/utils/DeployedStandaloneCartridgeAssert.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2013 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package com.openshift.client.utils; + +import static org.fest.assertions.Assertions.assertThat; + +import com.openshift.client.OpenShiftException; +import com.openshift.client.cartridge.IDeployedStandaloneCartridge; + +/** + * @author André Dietisheim + */ +public class DeployedStandaloneCartridgeAssert extends CartridgeAssert { + + public DeployedStandaloneCartridgeAssert(IDeployedStandaloneCartridge cartridge) { + super(cartridge); + } + + public CartridgeAssert isEqualTo(IDeployedStandaloneCartridge otherCartridge) + throws OpenShiftException { + super.isEqualTo(otherCartridge); + + assertThat(getCartridge().getAdditionalGearStorage()).equals(otherCartridge.getAdditionalGearStorage()); + return this; + } + + +} diff --git a/src/test/java/com/openshift/client/utils/GearGroupAssert.java b/src/test/java/com/openshift/client/utils/GearGroupAssert.java index 820cc1f8..3d2db24f 100644 --- a/src/test/java/com/openshift/client/utils/GearGroupAssert.java +++ b/src/test/java/com/openshift/client/utils/GearGroupAssert.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 Red Hat, Inc. + * Copyright (c) 2011-2014 Red Hat, Inc. * Distributed under license by Red Hat, Inc. All rights reserved. * This program is made available under the terms of the * Eclipse Public License v1.0 which accompanies this distribution, @@ -31,6 +31,7 @@ /** * @author André Dietisheim + * @author Jeff Cantrill */ public class GearGroupAssert implements AssertExtension { @@ -61,6 +62,11 @@ public GearGroupAssert hasGears() { return this; } + public GearGroupAssert hasAdditionalStorageSize(int size){ + assertThat(gearGroup.getAdditionalStorage()).isEqualTo(size); + return this; + } + public GearAssert assertGear(String id) { assertNotNull(id); diff --git a/src/test/java/com/openshift/internal/client/ApplicationResourceIntegrationTest.java b/src/test/java/com/openshift/internal/client/ApplicationResourceIntegrationTest.java index 2a31d416..520b9944 100755 --- a/src/test/java/com/openshift/internal/client/ApplicationResourceIntegrationTest.java +++ b/src/test/java/com/openshift/internal/client/ApplicationResourceIntegrationTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 Red Hat, Inc. + * Copyright (c) 2013-2014 Red Hat, Inc. * Distributed under license by Red Hat, Inc. All rights reserved. * This program is made available under the terms of the * Eclipse Public License v1.0 which accompanies this distribution, @@ -33,7 +33,6 @@ import com.openshift.client.IUser; import com.openshift.client.OpenShiftEndpointException; import com.openshift.client.OpenShiftException; -import com.openshift.client.cartridge.IStandaloneCartridge; import com.openshift.client.cartridge.query.LatestVersionOf; import com.openshift.client.utils.ApplicationTestUtils; import com.openshift.client.utils.DomainTestUtils; @@ -44,6 +43,7 @@ * @author André Dietisheim * @author Syed Iqbal * @author Martes G Wigglesworth + * @author Jeff Cantrill */ public class ApplicationResourceIntegrationTest extends TestTimer { @@ -60,24 +60,20 @@ public void setUp() throws Exception { } @Test - public void shouldReturnGears() throws Exception { + public void shouldReturnGearGroups() throws Exception { // pre-conditions - ApplicationTestUtils.destroyIfMoreThan(2, domain); + IApplication application = ApplicationTestUtils.getOrCreateApplication(domain); // operation - String applicationName = - ApplicationTestUtils.createRandomApplicationName(); - IStandaloneCartridge jbossas = LatestVersionOf.jbossAs().get(user); - IApplication application = - domain.createApplication(applicationName, jbossas); - Collection gearGroups = application.getGearGroups(); - assertThat(new GearGroupsAssert(gearGroups)).hasSize(1); + + // verification + assertThat(gearGroups.size()).isGreaterThanOrEqualTo(1); assertThat(new GearGroupsAssert(gearGroups)) .assertGroup(0).hasUUID().hasGears() .assertGear(0).hasId().hasState(); } - + @Test public void shouldDestroyApplication() throws Exception { // pre-condition diff --git a/src/test/java/com/openshift/internal/client/GearGroupsResourceTest.java b/src/test/java/com/openshift/internal/client/GearGroupsResourceTest.java index 1214f1dc..45ca97af 100644 --- a/src/test/java/com/openshift/internal/client/GearGroupsResourceTest.java +++ b/src/test/java/com/openshift/internal/client/GearGroupsResourceTest.java @@ -60,6 +60,7 @@ public void shouldGetGearGroups() throws Throwable { assertThat(new GearGroupsAssert(gearGroups)).hasSize(2); assertThat(new GearGroupsAssert(gearGroups)).assertGroup("514207b84382ec1fef0000ab") .hasUUID("514207b84382ec1fef0000ab") + .hasAdditionalStorageSize(8) .assertGear("514207b84382ec1fef000098").inState(new GearState("idle")) .assertGear("514207b84382ec1fef000098").hasSshUrl("ssh://52380549e0b8cd1e0e000032@springeap6-foobarz.rhcloud.com") .assertGear("5146f047500446f12d00002e").inState(new GearState("building")) diff --git a/src/test/java/com/openshift/internal/client/OpenShiftIntegrationTestSuite.java b/src/test/java/com/openshift/internal/client/OpenShiftIntegrationTestSuite.java index d263b08d..8390a4b8 100755 --- a/src/test/java/com/openshift/internal/client/OpenShiftIntegrationTestSuite.java +++ b/src/test/java/com/openshift/internal/client/OpenShiftIntegrationTestSuite.java @@ -22,7 +22,7 @@ UserResourceIntegrationTest.class, DomainResourceIntegrationTest.class, ApplicationResourceIntegrationTest.class, - StandaloneCartridgesIntegrationTest.class, + StandaloneCartridgeResourceIntegrationTest.class, EmbeddedCartridgeResourceIntegrationTest.class, EnvironmentVariableResourceIntegrationTest.class, AuthorizationIntegrationTest.class diff --git a/src/test/java/com/openshift/internal/client/OpenShiftTestSuite.java b/src/test/java/com/openshift/internal/client/OpenShiftTestSuite.java index a6fbe835..38801968 100755 --- a/src/test/java/com/openshift/internal/client/OpenShiftTestSuite.java +++ b/src/test/java/com/openshift/internal/client/OpenShiftTestSuite.java @@ -35,6 +35,7 @@ QuickstartTest.class, BaseCartridgeTest.class, StandaloneCartridgeTest.class, + StandaloneCartridgeResourceTest.class, EmbeddableCartridgeTest.class, EmbeddedCartridgeResourceTest.class, CartridgeQueryTest.class, diff --git a/src/test/java/com/openshift/internal/client/StandaloneCartridgeResourceIntegrationTest.java b/src/test/java/com/openshift/internal/client/StandaloneCartridgeResourceIntegrationTest.java new file mode 100755 index 00000000..c8998b71 --- /dev/null +++ b/src/test/java/com/openshift/internal/client/StandaloneCartridgeResourceIntegrationTest.java @@ -0,0 +1,132 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package com.openshift.internal.client; + +import static org.fest.assertions.Assertions.assertThat; + +import java.io.IOException; +import java.net.URISyntaxException; + +import org.junit.Before; +import org.junit.Test; + +import com.openshift.client.IApplication; +import com.openshift.client.IDomain; +import com.openshift.client.IGearGroup; +import com.openshift.client.IUser; +import com.openshift.client.OpenShiftException; +import com.openshift.client.cartridge.IDeployedStandaloneCartridge; +import com.openshift.client.cartridge.IStandaloneCartridge; +import com.openshift.client.cartridge.query.CartridgeNameQuery; +import com.openshift.client.utils.ApplicationTestUtils; +import com.openshift.client.utils.DomainTestUtils; +import com.openshift.client.utils.StandaloneCartridgeAssert; +import com.openshift.client.utils.TestConnectionBuilder; + +/** + * @author André Dietisheim + * @author Jeff Cantrill + */ +public class StandaloneCartridgeResourceIntegrationTest extends TestTimer { + + private IUser user; + private IDomain domain; + private IApplication application; + + @Before + public void setUp() throws OpenShiftException, IOException { + this.user = new TestConnectionBuilder().defaultCredentials().disableSSLCertificateChecks().create().getUser(); + this.domain = DomainTestUtils.ensureHasDomain(user); + this.application = ApplicationTestUtils.getOrCreateApplication(domain); + } + + @Test + public void shouldReportStandaloneCartridge() throws OpenShiftException, URISyntaxException { + // precondition + + // operation + IStandaloneCartridge cartridge = application.getCartridge(); + + // verification + assertThat(cartridge).isNotNull(); + assertThat(cartridge.getName()).isNotEmpty(); + IStandaloneCartridge availableCartridge = new CartridgeNameQuery(cartridge.getName()).get(user.getConnection().getStandaloneCartridges()); + new StandaloneCartridgeAssert(cartridge).equals(availableCartridge); + } + + @Test + public void shouldReportGearGroup() throws OpenShiftException, URISyntaxException { + // precondition + IDeployedStandaloneCartridge cartridge = application.getCartridge(); + assertThat(cartridge).isNotNull(); + + // operation + IGearGroup gearGroup = cartridge.getGearGroup(); + + // verification + assertThat(gearGroup).isNotNull(); + assertThat(gearGroup.getCartridges()).contains(cartridge); + } + + @Test + public void shouldGetGearStorage() throws OpenShiftException, URISyntaxException, IOException { + // precondition + IDeployedStandaloneCartridge cartridge = application.getCartridge(); + assertThat(cartridge).isNotNull(); + + // operation + int additionalGearStorage = cartridge.getAdditionalGearStorage(); + + // verification + // reload user info to ensure the storage info isnt cached + assertThat(additionalGearStorage).isNotEqualTo(IGearGroup.NO_ADDITIONAL_GEAR_STORAGE); + } + + @Test + public void shouldSetGearStorage() throws OpenShiftException, URISyntaxException, IOException { + // precondition + IDeployedStandaloneCartridge cartridge = application.getCartridge(); + assertThat(cartridge).isNotNull(); + int additionalGearStorage = cartridge.getAdditionalGearStorage(); + int newAdditionalGearStorage = 3; + + // operation + cartridge.setAdditionalGearStorage(newAdditionalGearStorage); + + // verification + // reload user info to ensure the storage info isnt cached + assertThat(cartridge.getAdditionalGearStorage()).isEqualTo(newAdditionalGearStorage); + } + + @Test + public void shouldSeeNewAdditionalGearStorageInNewConnection() throws OpenShiftException, URISyntaxException, IOException { + // precondition + IDeployedStandaloneCartridge cartridge = application.getCartridge(); + assertThat(cartridge).isNotNull(); + int additionalGearStorage = 4; + + // operation + cartridge.setAdditionalGearStorage(additionalGearStorage); + + // verification + // reload user info to ensure the storage info isnt cached + IUser newUser = new TestConnectionBuilder() + .defaultCredentials() + .disableSSLCertificateChecks() + .create() + .getUser(); + IApplication newApplication = newUser.getDefaultDomain().getApplicationByName(application.getName()); + IDeployedStandaloneCartridge newCartridge = newApplication.getCartridge(); + new StandaloneCartridgeAssert(newCartridge).isEqualTo(cartridge); + assertThat(newCartridge.getAdditionalGearStorage()).isEqualTo(additionalGearStorage); + + } +} \ No newline at end of file diff --git a/src/test/java/com/openshift/internal/client/StandaloneCartridgeResourceTest.java b/src/test/java/com/openshift/internal/client/StandaloneCartridgeResourceTest.java new file mode 100644 index 00000000..ab1bd306 --- /dev/null +++ b/src/test/java/com/openshift/internal/client/StandaloneCartridgeResourceTest.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright (c) 2014 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package com.openshift.internal.client; + +import static com.openshift.client.utils.Samples.GET_DOMAINS; +import static com.openshift.client.utils.Samples.GET_DOMAINS_FOOBARZ_APPLICATIONS_3EMBEDDED; +import static com.openshift.client.utils.UrlEndsWithMatcher.urlEndsWith; +import static org.fest.assertions.Assertions.assertThat; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyInt; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.junit.Before; +import org.junit.Test; + +import com.openshift.client.IApplication; +import com.openshift.client.IDomain; +import com.openshift.client.IHttpClient; +import com.openshift.client.IUser; +import com.openshift.client.cartridge.IDeployedStandaloneCartridge; +import com.openshift.client.cartridge.IStandaloneCartridge; +import com.openshift.client.cartridge.StandaloneCartridge; +import com.openshift.client.utils.TestConnectionBuilder; +import com.openshift.internal.client.httpclient.request.JsonMediaType; +import com.openshift.internal.client.httpclient.request.Parameter; +import com.openshift.internal.client.response.CartridgeResourceDTO; +import com.openshift.internal.client.utils.IOpenShiftJsonConstants; + +/** + * @author Jeff Cantrill + * @author Andre Dietisheim + * + */ +public class StandaloneCartridgeResourceTest { + + private ApplicationResource app = mock(ApplicationResource.class); + private CartridgeResourceDTO dto = mock(CartridgeResourceDTO.class); + private IStandaloneCartridge cartridge = mock(IStandaloneCartridge.class); + private StandaloneCartridgeResource cartridgeResource; + + @Before + public void setup() { + when(dto.getName()).thenReturn("cartridgeName"); + when(dto.getType()).thenReturn(CartridgeType.STANDALONE); + when(cartridge.getName()).thenReturn("cartridgeName"); + this.cartridgeResource = new StandaloneCartridgeResource(dto, app); + } + + @Test + public void testUpdateAdditionalGearStorage() throws Exception { + HttpClientMockDirector builder = new HttpClientMockDirector(); + IHttpClient httpClient = builder + .mockGetDomains(GET_DOMAINS) + .mockGetApplications( + "foobarz", GET_DOMAINS_FOOBARZ_APPLICATIONS_3EMBEDDED) + .client(); + IUser user = new TestConnectionBuilder().defaultCredentials().create(httpClient).getUser(); + IDomain domain = user.getDomain("foobarz"); + IApplication application = domain.getApplicationByName("springeap6"); + + IDeployedStandaloneCartridge cartridge = application.getCartridge(); + + cartridge.setAdditionalGearStorage(40); + + verify(httpClient, times(1)).put( + urlEndsWith("applications/springeap6/cartridges/jbosseap-6"), + any(JsonMediaType.class), + anyInt(), + eq(new Parameter(IOpenShiftJsonConstants.PROPERTY_ADDITIONAL_GEAR_STORAGE, "40"))); + } + + @Test + public void standaloneCartridgeResourceShouldEqualStandAloneCartridge() { + // pre-conditions + // operation + // verification + assertThat(cartridgeResource).isEqualTo(cartridge); + + when(cartridge.getName()).thenReturn("other"); + assertThat(cartridgeResource).isNotEqualTo(cartridge); + } + + @Test + public void standaloneCartridgeResourceAndStandAloneCartridgeShouldHaveSameHashCode() { + // pre-conditions + + // operation + // verification + assertThat(cartridgeResource.hashCode()).isEqualTo(new StandaloneCartridge("cartridgeName").hashCode()); + } +} diff --git a/src/test/java/com/openshift/internal/client/StandaloneCartridgeTest.java b/src/test/java/com/openshift/internal/client/StandaloneCartridgeTest.java index ca310d86..38e7e542 100644 --- a/src/test/java/com/openshift/internal/client/StandaloneCartridgeTest.java +++ b/src/test/java/com/openshift/internal/client/StandaloneCartridgeTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 Red Hat, Inc. + * Copyright (c) 2013-2014 Red Hat, Inc. * Distributed under license by Red Hat, Inc. All rights reserved. * This program is made available under the terms of the * Eclipse Public License v1.0 which accompanies this distribution, @@ -11,6 +11,7 @@ package com.openshift.internal.client; import static org.fest.assertions.Assertions.assertThat; +import static org.junit.Assert.*; import java.net.MalformedURLException; import java.net.URL; @@ -30,6 +31,7 @@ /** * @author Andre Dietisheim + * @author Jeff Cantrill */ public class StandaloneCartridgeTest extends TestTimer { @@ -81,6 +83,13 @@ public void shouldHaveNameDisplaynameDescription() throws Throwable { + "scalable network applications. Node.js is perfect for data-intensive real-time " + "applications that run across distributed devices."); } - - + + @Test + public void standaloneCartridgeResourceShouldEqualStandAloneCartridgeWithoutName() throws MalformedURLException { + // pre-coniditions + // operation + // verification + assertEquals(new StandaloneCartridge(new URL(CartridgeTestUtils.FOREMAN_URL)), + new StandaloneCartridge("redhat", new URL(CartridgeTestUtils.FOREMAN_URL))); + } } diff --git a/src/test/java/com/openshift/internal/client/StandaloneCartridgesIntegrationTest.java b/src/test/java/com/openshift/internal/client/StandaloneCartridgesIntegrationTest.java deleted file mode 100755 index 8a721740..00000000 --- a/src/test/java/com/openshift/internal/client/StandaloneCartridgesIntegrationTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Red Hat, Inc. - * Distributed under license by Red Hat, Inc. All rights reserved. - * This program is made available under the terms of the - * Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Red Hat, Inc. - initial API and implementation - ******************************************************************************/ -package com.openshift.internal.client; - -import static org.fest.assertions.Assertions.assertThat; - -import java.io.IOException; -import java.net.URISyntaxException; - -import org.junit.Before; -import org.junit.Test; - -import com.openshift.client.IApplication; -import com.openshift.client.IDomain; -import com.openshift.client.IUser; -import com.openshift.client.OpenShiftException; -import com.openshift.client.cartridge.IStandaloneCartridge; -import com.openshift.client.utils.ApplicationTestUtils; -import com.openshift.client.utils.DomainTestUtils; -import com.openshift.client.utils.StandaloneCartridgeAssert; -import com.openshift.client.utils.TestConnectionBuilder; - -/** - * @author André Dietisheim - */ -public class StandaloneCartridgesIntegrationTest extends TestTimer { - - private IUser user; - private IDomain domain; - private IApplication application; - - @Before - public void setUp() throws OpenShiftException, IOException { - this.user = new TestConnectionBuilder().defaultCredentials().disableSSLCertificateChecks().create().getUser(); - this.domain = DomainTestUtils.ensureHasDomain(user); - this.application = ApplicationTestUtils.getOrCreateApplication(domain); - } - - @Test - public void shouldReportStandaloneCartridge() throws OpenShiftException, URISyntaxException { - // precondition - - // operation - IStandaloneCartridge cartridge = application.getCartridge(); - - // verification - assertThat(cartridge).isNotNull(); - assertThat(cartridge.getName()).isNotEmpty(); - IStandaloneCartridge availableCartridge = getAvailableCartridge(cartridge.getName()); - new StandaloneCartridgeAssert(cartridge).equals(availableCartridge); - } - - private IStandaloneCartridge getAvailableCartridge(String name) { - assertThat(name).isNotNull(); - for(IStandaloneCartridge cartridge : user.getConnection().getStandaloneCartridges()) { - if (name.equals(cartridge.getName())) { - return cartridge; - } - } - return null; - } -} diff --git a/src/test/resources/samples/get-domains-foobarz-applications-springeap6-geargroups.json b/src/test/resources/samples/get-domains-foobarz-applications-springeap6-geargroups.json index 19ff28de..8e8ac82b 100644 --- a/src/test/resources/samples/get-domains-foobarz-applications-springeap6-geargroups.json +++ b/src/test/resources/samples/get-domains-foobarz-applications-springeap6-geargroups.json @@ -1,7 +1,7 @@ { "data":[ { - "additional_gear_storage":0, + "additional_gear_storage":8, "base_gear_storage":1, "cartridges":[ { From f1e8cf52a2447597f2a5b8142c58b96c10a96432 Mon Sep 17 00:00:00 2001 From: Andre Dietisheim Date: Tue, 14 Oct 2014 23:05:03 +0200 Subject: [PATCH 2/2] [OSJC-101] fixed I(Deployed)StandaloneCartridge#equals --- .../client/cartridge/StandaloneCartridge.java | 30 ++- .../client/StandaloneCartridgeResource.java | 56 ++-- .../client/cartridge/BaseCartridge.java | 4 +- .../client/utils/ApplicationTestUtils.java | 15 +- .../com/openshift/client/utils/Samples.java | 3 +- .../ApplicationResourceIntegrationTest.java | 10 +- .../ApplicationSSHSessionIntegrationTest.java | 3 +- .../client/DomainResourceIntegrationTest.java | 36 +-- ...eddedCartridgeResourceIntegrationTest.java | 61 ++--- .../client/HttpClientMockDirector.java | 251 +++++++++++++----- ...aloneCartridgeResourceIntegrationTest.java | 43 +-- .../StandaloneCartridgeResourceTest.java | 99 ++++++- .../client/StandaloneCartridgeTest.java | 4 +- ...p6-geargroups-12additionalgearstorage.json | 149 +++++++++++ 14 files changed, 568 insertions(+), 196 deletions(-) create mode 100644 src/test/resources/samples/get-domains-foobarz-applications-springeap6-geargroups-12additionalgearstorage.json diff --git a/src/main/java/com/openshift/client/cartridge/StandaloneCartridge.java b/src/main/java/com/openshift/client/cartridge/StandaloneCartridge.java index 30bbb445..8d90d92d 100755 --- a/src/main/java/com/openshift/client/cartridge/StandaloneCartridge.java +++ b/src/main/java/com/openshift/client/cartridge/StandaloneCartridge.java @@ -17,7 +17,6 @@ import com.openshift.internal.client.CartridgeType; import com.openshift.internal.client.cartridge.BaseCartridge; - /** * A cartridge that is available on the openshift server. This class is no enum * since we dont know all available types and they may change at any time. @@ -60,9 +59,36 @@ public StandaloneCartridge(String name, URL url, String displayName, String desc public StandaloneCartridge(String name, URL url, String displayName, String description) { this(name, url, displayName, description, false); } - + @Override public CartridgeType getType() { return CartridgeType.STANDALONE; } + + @Override + public boolean equals(Object obj) { + if (!(IStandaloneCartridge.class.isAssignableFrom(obj.getClass()))) { + return super.equals(obj); + } + + IStandaloneCartridge otherCartridge = (IStandaloneCartridge) obj; + // shortcut: downloadable cartridges get their name only when + // they're deployed thus should equal on url only + if (isDownloadable()) { + if (otherCartridge.isDownloadable()) { + if (getUrl() == null) { + return otherCartridge.getUrl() == null; + } + return getUrl().equals(otherCartridge.getUrl()); + } + } + if (getName() == null) { + if (otherCartridge.getName() != null) { + return false; + } + } else if (!getName().equals(otherCartridge.getName())) { + return false; + } + return true; + } } diff --git a/src/main/java/com/openshift/internal/client/StandaloneCartridgeResource.java b/src/main/java/com/openshift/internal/client/StandaloneCartridgeResource.java index 6877a018..ae197489 100644 --- a/src/main/java/com/openshift/internal/client/StandaloneCartridgeResource.java +++ b/src/main/java/com/openshift/internal/client/StandaloneCartridgeResource.java @@ -43,13 +43,13 @@ public class StandaloneCartridgeResource extends AbstractOpenShiftResource imple protected StandaloneCartridgeResource(final CartridgeResourceDTO dto, final ApplicationResource application) { super(application.getService(), dto.getLinks(), dto.getMessages()); Assert.isTrue(dto.getType().equals(CartridgeType.STANDALONE)); - this.application = application; this.name = dto.getName(); this.displayName = dto.getDisplayName(); this.description = dto.getDescription(); this.url = dto.getUrl(); this.cartridgeType = dto.getType(); this.obsolete = dto.getObsolete(); + this.application = application; } /** @@ -71,14 +71,14 @@ public int getAdditionalGearStorage() { return IGearGroup.NO_ADDITIONAL_GEAR_STORAGE; } return gearGroup.getAdditionalStorage(); - + } - + @Override public IGearGroup getGearGroup() { return application.getGearGroup(this); } - + /** * Refreshes the content of this embedded cartridge. Causes all embedded * cartridges of the same application to get updated. @@ -121,34 +121,33 @@ public CartridgeType getType() { return this.cartridgeType; } - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((name == null) ? 0 : name.hashCode()); - return result; - } - @Override public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!IStandaloneCartridge.class.isAssignableFrom(obj.getClass())) + if (!(IDeployedStandaloneCartridge.class.isAssignableFrom(obj.getClass()))) { return false; - IStandaloneCartridge other = (IStandaloneCartridge) obj; - if (name == null) { - if (other.getName() != null) { + } + + IDeployedStandaloneCartridge otherCartridge = (IDeployedStandaloneCartridge) obj; + // shortcut: downloadable cartridges get their name only when + // they're deployed thus should equal on url only + if (getName() == null) { + if (otherCartridge.getName() != null) { return false; } - } - if (!name.equals(other.getName())) { + } else if (!getName().equals(otherCartridge.getName())) { return false; } return true; } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + private class UpdateCartridgeRequest extends ServiceRequest { private UpdateCartridgeRequest() { super(LINK_UPDATE_CARTRIDGE); @@ -159,4 +158,17 @@ private UpdateCartridgeRequest() { public boolean isObsolete() { return obsolete; } + + @Override + public String toString() { + return "StandaloneCartridgeResource [" + + "application=" + application + + ", name=" + name + + ", displayName=" + displayName + + ", description=" + description + + ", url=" + url + + ", cartridgeType=" + cartridgeType + + ", obsolete=" + obsolete + + "]"; + } } diff --git a/src/main/java/com/openshift/internal/client/cartridge/BaseCartridge.java b/src/main/java/com/openshift/internal/client/cartridge/BaseCartridge.java index 030eca38..54e7a9b6 100644 --- a/src/main/java/com/openshift/internal/client/cartridge/BaseCartridge.java +++ b/src/main/java/com/openshift/internal/client/cartridge/BaseCartridge.java @@ -128,11 +128,11 @@ public boolean equals(Object obj) { if (obj == null) { return false; } - if (!(BaseCartridge.class.isAssignableFrom(obj.getClass()))) { + if (!(ICartridge.class.isAssignableFrom(obj.getClass()))) { return false; } - BaseCartridge other = (BaseCartridge) obj; + ICartridge other = (ICartridge) obj; // shortcut: downloadable cartridges get their name only when // they're deployed thus should equal on url only if (isDownloadable()) { diff --git a/src/test/java/com/openshift/client/utils/ApplicationTestUtils.java b/src/test/java/com/openshift/client/utils/ApplicationTestUtils.java index 3697fae1..edf15a19 100755 --- a/src/test/java/com/openshift/client/utils/ApplicationTestUtils.java +++ b/src/test/java/com/openshift/client/utils/ApplicationTestUtils.java @@ -43,6 +43,9 @@ public static IApplication createApplication(IStandaloneCartridge cartridge, IDo } public static IApplication createApplication(String name, IStandaloneCartridge cartridge, IDomain domain) { + if (cartridge == null) { + cartridge = getDefaultCartridge(domain); + } IApplication application = domain.createApplication(name, cartridge); assertTrue(application.waitForAccessible(WAIT_FOR_APPLICATION)); return application; @@ -91,14 +94,15 @@ public static void silentlyDestroyAllApplicationsByCartridge(IStandaloneCartridg } public static IApplication getOrCreateApplication(IDomain domain) throws OpenShiftException { - return getOrCreateApplication(domain, LatestVersionOf.php().get(domain.getUser())); + return getOrCreateApplication(domain, null); } public static IApplication getOrCreateApplication(IDomain domain, IStandaloneCartridge cartridge) throws OpenShiftException { for (Iterator it = domain.getApplications().iterator(); it.hasNext();) { IApplication application = it.next(); - if (cartridge.equals(application.getCartridge())) { + if (cartridge == null + || cartridge.equals(application.getCartridge())) { return application; } } @@ -188,6 +192,10 @@ public static IApplication ensureHasExactly1Application(IStandaloneCartridge car return domain.getApplications().get(0); } + public static IApplication ensureHasExactly1Application(IDomain domain) { + return ensureHasExactly1Application(getDefaultCartridge(domain), domain); + } + public static IApplication ensureHasExactly1Application(LatestStandaloneCartridge selector, IDomain domain) { IStandaloneCartridge cartridge = selector.get(domain.getUser()); ensureHasExactly(1, cartridge, domain); @@ -239,4 +247,7 @@ public static IApplication destroyAllEnvironmentVariables(IApplication applicati return application; } + private static IStandaloneCartridge getDefaultCartridge(IDomain domain) { + return LatestVersionOf.php().get(domain.getUser()); + } } diff --git a/src/test/java/com/openshift/client/utils/Samples.java b/src/test/java/com/openshift/client/utils/Samples.java index 150c830e..335ed746 100644 --- a/src/test/java/com/openshift/client/utils/Samples.java +++ b/src/test/java/com/openshift/client/utils/Samples.java @@ -21,7 +21,8 @@ public enum Samples { // gear groups GET_DOMAINS_FOOBARZ_APPLICATIONS_SPRINGEAP6_GEARGROUPS("get-domains-foobarz-applications-springeap6-geargroups.json"), // 1.2 - + GET_DOMAINS_FOOBARZ_APPLICATIONS_SPRINGEAP6_GEARGROUPS_12ADDITIONALGEARSTORAGE("get-domains-foobarz-applications-springeap6-geargroups-12additionalgearstorage.json"), // 1.2 + // cartridges GET_DOMAINS_FOOBARZ_APPLICATIONS_SPRINGEAP6_CARTRIDGES_1EMBEDDED("get-domains-foobarz-applications-springeap6-cartridges_1embedded.json"), // 1.2 GET_DOMAINS_FOOBARZ_APPLICATIONS_SPRINGEAP6_CARTRIDGES_2EMBEDDED("get-domains-foobarz-applications-springeap6-cartridges_2embedded.json"), // 1.2 diff --git a/src/test/java/com/openshift/internal/client/ApplicationResourceIntegrationTest.java b/src/test/java/com/openshift/internal/client/ApplicationResourceIntegrationTest.java index 520b9944..d9120566 100755 --- a/src/test/java/com/openshift/internal/client/ApplicationResourceIntegrationTest.java +++ b/src/test/java/com/openshift/internal/client/ApplicationResourceIntegrationTest.java @@ -177,7 +177,7 @@ public void shouldNotScaleDownIfNotScaledUpApplication() throws Throwable { // pre-condition ApplicationTestUtils.silentlyDestroyAllApplications(domain); IApplication application = domain.createApplication( - ApplicationTestUtils.createRandomApplicationName(), LatestVersionOf.jbossAs().get(user), ApplicationScale.NO_SCALE); + ApplicationTestUtils.createRandomApplicationName(), LatestVersionOf.php().get(user), ApplicationScale.NO_SCALE); // operation application.scaleDown(); @@ -191,7 +191,7 @@ public void shouldNotScaleUpApplication() throws Throwable { // pre-condition ApplicationTestUtils.silentlyDestroyAllApplications(domain); IApplication application = domain.createApplication( - ApplicationTestUtils.createRandomApplicationName(), LatestVersionOf.jbossAs().get(user), ApplicationScale.NO_SCALE); + ApplicationTestUtils.createRandomApplicationName(), LatestVersionOf.php().get(user), ApplicationScale.NO_SCALE); // operation application.scaleUp(); @@ -204,7 +204,7 @@ public void shouldScaleUpApplication() throws Throwable { // pre-condition ApplicationTestUtils.silentlyDestroyAllApplications(domain); IApplication application = domain.createApplication( - ApplicationTestUtils.createRandomApplicationName(), LatestVersionOf.jbossAs().get(user), ApplicationScale.SCALE); + ApplicationTestUtils.createRandomApplicationName(), LatestVersionOf.php().get(user), ApplicationScale.SCALE); // operation application.scaleUp(); @@ -218,7 +218,7 @@ public void shouldScaleDownApplication() throws Throwable { // pre-condition ApplicationTestUtils.silentlyDestroyAllApplications(domain); IApplication application = domain.createApplication( - ApplicationTestUtils.createRandomApplicationName(), LatestVersionOf.jbossAs().get(user), ApplicationScale.SCALE); + ApplicationTestUtils.createRandomApplicationName(), LatestVersionOf.php().get(user), ApplicationScale.SCALE); application.scaleUp(); // operation @@ -276,7 +276,7 @@ public void shouldWaitForApplication() throws OpenShiftException, MalformedURLEx // pre-condition ApplicationTestUtils.destroyIfMoreThan(2, domain); long startTime = System.currentTimeMillis(); - IApplication application = domain.createApplication(ApplicationTestUtils.createRandomApplicationName(), LatestVersionOf.jbossAs().get(user)); + IApplication application = domain.createApplication(ApplicationTestUtils.createRandomApplicationName(), LatestVersionOf.php().get(user)); // operation boolean successfull = application.waitForAccessible(WAIT_TIMEOUT); diff --git a/src/test/java/com/openshift/internal/client/ApplicationSSHSessionIntegrationTest.java b/src/test/java/com/openshift/internal/client/ApplicationSSHSessionIntegrationTest.java index 64650fd7..854ac2c2 100644 --- a/src/test/java/com/openshift/internal/client/ApplicationSSHSessionIntegrationTest.java +++ b/src/test/java/com/openshift/internal/client/ApplicationSSHSessionIntegrationTest.java @@ -36,7 +36,6 @@ import com.openshift.client.IApplication; import com.openshift.client.IDomain; import com.openshift.client.IUser; -import com.openshift.client.cartridge.query.LatestVersionOf; import com.openshift.client.utils.ApplicationAssert; import com.openshift.client.utils.ApplicationTestUtils; import com.openshift.client.utils.DomainTestUtils; @@ -66,7 +65,7 @@ public static void createSSHKeys() throws IOException, JSchException { @Before public void setUp() throws Exception { IDomain domain = DomainTestUtils.ensureHasDomain(user); - this.application = ApplicationTestUtils.getOrCreateApplication(domain, LatestVersionOf.php().get(user)); + this.application = ApplicationTestUtils.getOrCreateApplication(domain); this.session = createSSHSession(application.getSshUrl()); } diff --git a/src/test/java/com/openshift/internal/client/DomainResourceIntegrationTest.java b/src/test/java/com/openshift/internal/client/DomainResourceIntegrationTest.java index ac3a6ae0..1767c40c 100755 --- a/src/test/java/com/openshift/internal/client/DomainResourceIntegrationTest.java +++ b/src/test/java/com/openshift/internal/client/DomainResourceIntegrationTest.java @@ -197,7 +197,7 @@ public void shouldMissApplicationAfterRefresh() throws OpenShiftException, FileN public void shouldGetApplicationByNameCaseInsensitive() throws OpenShiftException, FileNotFoundException, IOException { // pre-condition IDomain domain = DomainTestUtils.ensureHasDomain(user); - IApplication application = ApplicationTestUtils.ensureHasExactly1Application(LatestVersionOf.jbossAs(), domain); + IApplication application = ApplicationTestUtils.ensureHasExactly1Application(domain); assertThat(application).isNotNull(); String name = application.getName(); assertThat(name).isNotNull(); @@ -221,16 +221,16 @@ public void shouldCreateNonScalableApplication() throws Exception { // operation String applicationName = ApplicationTestUtils.createRandomApplicationName(); - IStandaloneCartridge jbossas = LatestVersionOf.jbossAs().get(user); + IStandaloneCartridge php = LatestVersionOf.php().get(user); IApplication application = - domain.createApplication(applicationName, jbossas); + domain.createApplication(applicationName, php); // verification assertThat(new ApplicationAssert(application)) .hasName(applicationName) .hasUUID() .hasCreationTime() - .hasCartridge(jbossas) + .hasCartridge(php) .hasValidApplicationUrl() .hasValidGitUrl() .hasNoInitialGitUrl() @@ -246,15 +246,15 @@ public void shouldCreateNonScalableApplicationWithSmallGear() throws Exception { // operation String applicationName = ApplicationTestUtils.createRandomApplicationName(); - IStandaloneCartridge jbossas = LatestVersionOf.jbossAs().get(user); - IApplication application = domain.createApplication(applicationName, jbossas, GearProfileTestUtils.getFirstAvailableGearProfile(domain)); + IStandaloneCartridge php = LatestVersionOf.php().get(user); + IApplication application = domain.createApplication(applicationName, php, GearProfileTestUtils.getFirstAvailableGearProfile(domain)); // verification assertThat(new ApplicationAssert(application)) .hasName(applicationName) .hasUUID() .hasCreationTime() - .hasCartridge(jbossas) + .hasCartridge(php) .hasValidApplicationUrl() .hasValidGitUrl() .hasNoInitialGitUrl() @@ -319,18 +319,18 @@ public void shouldCreateScalableApplication() throws Exception { ApplicationTestUtils.destroyAllApplications(domain); String applicationName = ApplicationTestUtils.createRandomApplicationName(); - IStandaloneCartridge jbossas = LatestVersionOf.jbossAs().get(user); + IStandaloneCartridge php = LatestVersionOf.php().get(user); // operation IApplication application = domain.createApplication( - applicationName, jbossas, ApplicationScale.SCALE, GearProfileTestUtils.getFirstAvailableGearProfile(domain)); + applicationName, php, ApplicationScale.SCALE, GearProfileTestUtils.getFirstAvailableGearProfile(domain)); // verification assertThat(new ApplicationAssert(application)) .hasName(applicationName) .hasUUID() .hasCreationTime() - .hasCartridge(jbossas) + .hasCartridge(php) .hasValidApplicationUrl() .hasValidGitUrl() .hasNoInitialGitUrl() @@ -388,12 +388,12 @@ public void shouldCreateApplicationWithDownloadableCartridge() throws Throwable } @Test - public void shouldCreateApplicationWithJBossAsAndDownloadableCartridge() throws Throwable { + public void shouldCreateApplicationWithPhpAndDownloadableCartridge() throws Throwable { // pre-conditions ApplicationTestUtils.destroyAllApplications(domain); String applicationName = ApplicationTestUtils.createRandomApplicationName(); - IStandaloneCartridge jbossAs = LatestVersionOf.jbossAs().get(user); + IStandaloneCartridge jbossAs = LatestVersionOf.php().get(user); // operation final IApplication app = domain.createApplication( @@ -413,18 +413,18 @@ public void shouldCreateApplicationWithJBossAsAndDownloadableCartridge() throws } @Test - public void shouldCreateJBossAsAndCronWithBuilder() throws Throwable { + public void shouldCreatePhpAndCronWithBuilder() throws Throwable { // pre-conditions ApplicationTestUtils.destroyAllApplications(domain); String applicationName = ApplicationTestUtils.createRandomApplicationName(); - IStandaloneCartridge jbossAs = LatestVersionOf.jbossAs().get(user); + IStandaloneCartridge php = LatestVersionOf.php().get(user); IEmbeddableCartridge cron = LatestVersionOf.cron().get(user); // operation IApplication app = new ApplicationBuilder(domain) .setName(applicationName) - .setStandaloneCartridge(jbossAs) + .setStandaloneCartridge(php) .setEmbeddableCartridges(cron) .build(); @@ -435,7 +435,7 @@ public void shouldCreateJBossAsAndCronWithBuilder() throws Throwable { .hasUUID() .hasValidApplicationUrl() .hasValidGitUrl() - .hasCartridge(jbossAs) + .hasCartridge(php) .hasEmbeddedCartridge(cron); } @@ -462,7 +462,7 @@ public void createDuplicateApplicationThrowsException() throws Exception { IApplication application = ApplicationTestUtils.getOrCreateApplication(domain); // operation - domain.createApplication(application.getName(), LatestVersionOf.jbossAs().get(user)); + domain.createApplication(application.getName(), LatestVersionOf.php().get(user)); } @Test(expected = OpenShiftException.class) @@ -472,6 +472,6 @@ public void createApplicationWithSameButUppercaseNameThrowsException() throws Ex String name = application.getName(); // operation - domain.createApplication(name.toUpperCase(), LatestVersionOf.jbossAs().get(user)); + domain.createApplication(name.toUpperCase(), LatestVersionOf.php().get(user)); } } diff --git a/src/test/java/com/openshift/internal/client/EmbeddedCartridgeResourceIntegrationTest.java b/src/test/java/com/openshift/internal/client/EmbeddedCartridgeResourceIntegrationTest.java index 6ac1ae1c..0d920cb2 100755 --- a/src/test/java/com/openshift/internal/client/EmbeddedCartridgeResourceIntegrationTest.java +++ b/src/test/java/com/openshift/internal/client/EmbeddedCartridgeResourceIntegrationTest.java @@ -59,9 +59,7 @@ public void setUp() throws OpenShiftException, IOException { @Test public void shouldReturnEmbeddedCartridgesForApplication() throws SocketTimeoutException, OpenShiftException { // pre-conditions - IStandaloneCartridge jbossAs = LatestVersionOf.jbossAs().get(user); - assertThat(jbossAs).isNotNull(); - IApplication application = ApplicationTestUtils.ensureHasExactly1Application(jbossAs, domain); + IApplication application = ApplicationTestUtils.ensureHasExactly1Application(domain); // operation List embeddedCartridges = application.getEmbeddedCartridges(); @@ -72,9 +70,9 @@ public void shouldReturnEmbeddedCartridgesForApplication() throws SocketTimeoutE @Test public void shouldNotContainTypeInEmbeddedCartridges() throws SocketTimeoutException, OpenShiftException { // pre-conditions - final IStandaloneCartridge jbossAs = LatestVersionOf.jbossAs().get(user); - assertThat(jbossAs).isNotNull(); - IApplication application = ApplicationTestUtils.ensureHasExactly1Application(jbossAs, domain); + final IStandaloneCartridge php = LatestVersionOf.php().get(user); + assertThat(php).isNotNull(); + IApplication application = ApplicationTestUtils.ensureHasExactly1Application(php, domain); // operation List embeddedCartridges = application.getEmbeddedCartridges(); @@ -87,7 +85,7 @@ public boolean matches(List values) { if (!(value instanceof ICartridge)) { continue; } - if (jbossAs.getName().equals(((ICartridge)value).getName())) { + if (php.getName().equals(((ICartridge)value).getName())) { return true; }; } @@ -99,8 +97,7 @@ public boolean matches(List values) { @Test public void shouldEmbedMySQL() throws SocketTimeoutException, OpenShiftException, URISyntaxException { // pre-conditions - IApplication application = ApplicationTestUtils.ensureHasExactly1Application( - LatestVersionOf.jbossAs(), domain); + IApplication application = ApplicationTestUtils.ensureHasExactly1Application(domain); EmbeddedCartridgeTestUtils.silentlyDestroyAllEmbeddedCartridges(application); IEmbeddableCartridge mysql = LatestVersionOf.mySQL().get(user); assertThat(mysql).isNotNull(); @@ -123,8 +120,7 @@ public void shouldEmbedMySQL() throws SocketTimeoutException, OpenShiftException public void shouldHaveUrlInEmbeddedMySQL() throws OpenShiftException, URISyntaxException, FileNotFoundException, IOException { // pre-conditions - IApplication application = ApplicationTestUtils.ensureHasExactly1Application( - LatestVersionOf.jbossAs(), domain); + IApplication application = ApplicationTestUtils.ensureHasExactly1Application(domain); EmbeddedCartridgeTestUtils.ensureHasEmbeddedCartridges(LatestVersionOf.mySQL(), application); // verify using user instance that's not the one used to create IUser user2 = new TestConnectionBuilder().defaultCredentials().disableSSLCertificateChecks().create().getUser(); @@ -149,8 +145,7 @@ public void shouldHaveUrlInEmbeddedMySQL() throws OpenShiftException, URISyntaxE public void shouldHaveDescriptionAndDisplayNameInEmbeddedMySQL() throws OpenShiftException, URISyntaxException, FileNotFoundException, IOException { // pre-conditions - IApplication application = ApplicationTestUtils.ensureHasExactly1Application( - LatestVersionOf.jbossAs(), domain); + IApplication application = ApplicationTestUtils.ensureHasExactly1Application(domain); EmbeddedCartridgeTestUtils.ensureHasEmbeddedCartridges(LatestVersionOf.mySQL(), application); // verify using user instance that's not the one used to create @@ -166,8 +161,7 @@ public void shouldHaveDescriptionAndDisplayNameInEmbeddedMySQL() throws OpenShif @Test public void shouldReturnThatHasMySQL() throws OpenShiftException, FileNotFoundException, IOException { // pre-conditions - IApplication application = ApplicationTestUtils.ensureHasExactly1Application( - LatestVersionOf.jbossAs(), domain); + IApplication application = ApplicationTestUtils.ensureHasExactly1Application(domain); EmbeddedCartridgeTestUtils.ensureHasEmbeddedCartridges( LatestVersionOf.mySQL(), application); // verify using user instance that's not the one used to create @@ -186,8 +180,7 @@ public void shouldReturnThatHasMySQL() throws OpenShiftException, FileNotFoundEx @Test public void shouldEmbedPostgreSQL() throws SocketTimeoutException, OpenShiftException, URISyntaxException { // pre-conditions - IApplication application = ApplicationTestUtils.ensureHasExactly1Application( - LatestVersionOf.jbossAs(), domain); + IApplication application = ApplicationTestUtils.ensureHasExactly1Application(domain); EmbeddedCartridgeTestUtils.silentlyDestroyAllEmbeddedCartridges(application); IEmbeddableCartridge postgres = LatestVersionOf.postgreSQL().get(user); assertThat(new ApplicationAssert(application)) @@ -207,8 +200,7 @@ public void shouldEmbedPostgreSQL() throws SocketTimeoutException, OpenShiftExce public void shouldHaveUrlInEmbeddedPostgres() throws OpenShiftException, URISyntaxException, FileNotFoundException, IOException { // pre-conditions - IApplication application = ApplicationTestUtils.ensureHasExactly1Application( - LatestVersionOf.jbossAs(), domain); + IApplication application = ApplicationTestUtils.ensureHasExactly1Application(domain); EmbeddedCartridgeTestUtils.ensureHasEmbeddedCartridges( LatestVersionOf.postgreSQL(), application); // verify using user instance that's not the one used to create @@ -228,7 +220,7 @@ public void shouldHaveUrlInEmbeddedPostgres() throws OpenShiftException, URISynt @Test public void shouldEmbedMongo() throws Exception { // pre-conditions - IApplication application = ApplicationTestUtils.ensureHasExactly1Application(LatestVersionOf.jbossAs(), domain); + IApplication application = ApplicationTestUtils.ensureHasExactly1Application(domain); EmbeddedCartridgeTestUtils.silentlyDestroyAllEmbeddedCartridges(application); IEmbeddableCartridge mongo = LatestVersionOf.mongoDB().get(user); assertThat(new ApplicationAssert(application)) @@ -248,7 +240,7 @@ public void shouldEmbedMongo() throws Exception { public void shouldHaveUrlInEmbeddedMongo() throws OpenShiftException, URISyntaxException, FileNotFoundException, IOException { // pre-conditions - IApplication jbossAs = ApplicationTestUtils.getOrCreateApplication(domain, LatestVersionOf.jbossAs().get(user)); + IApplication jbossAs = ApplicationTestUtils.getOrCreateApplication(domain); EmbeddedCartridgeTestUtils.silentlyDestroyAllEmbeddedCartridges(jbossAs); // operation @@ -269,7 +261,7 @@ public void shouldHaveUrlInEmbeddedMongo() throws OpenShiftException, URISyntaxE public void shouldEmbedRockMongo() throws Exception { // pre-conditions // have to make sure have non-scalable app without cartridges - IApplication jbossAs = ApplicationTestUtils.getOrCreateApplication(domain, LatestVersionOf.jbossAs().get(user)); + IApplication jbossAs = ApplicationTestUtils.getOrCreateApplication(domain); jbossAs = ApplicationTestUtils.destroyAndRecreateIfScalable(jbossAs); EmbeddedCartridgeTestUtils.silentlyDestroyAllEmbeddedCartridges(jbossAs); @@ -291,7 +283,7 @@ public void shouldEmbedRockMongo() throws Exception { public void shouldHaveUrlInEmbeddedRockMongo() throws OpenShiftException, URISyntaxException, FileNotFoundException, IOException { // pre-conditions - IApplication jbossAs = ApplicationTestUtils.getOrCreateApplication(domain, LatestVersionOf.jbossAs().get(user)); + IApplication jbossAs = ApplicationTestUtils.getOrCreateApplication(domain); jbossAs = ApplicationTestUtils.destroyAndRecreateIfScalable(jbossAs); EmbeddedCartridgeTestUtils.silentlyDestroyAllEmbeddedCartridges(jbossAs); assertThat(new ApplicationAssert(jbossAs) @@ -318,7 +310,7 @@ public void shouldHaveUrlInEmbeddedRockMongo() @Test public void shouldEmbedPhpMyAdmin() throws Exception { // pre-conditions - IApplication jbossAs = ApplicationTestUtils.getOrCreateApplication(domain, LatestVersionOf.jbossAs().get(user)); + IApplication jbossAs = ApplicationTestUtils.getOrCreateApplication(domain); jbossAs = ApplicationTestUtils.destroyAndRecreateIfScalable(jbossAs); EmbeddedCartridgeTestUtils.silentlyDestroyAllEmbeddedCartridges(jbossAs); assertThat(new ApplicationAssert(jbossAs) @@ -340,7 +332,7 @@ public void shouldHaveUrlInEmbeddedPhpMyadmin() throws OpenShiftException, URISyntaxException, FileNotFoundException, IOException { // pre-conditions // pre-conditions - IApplication jbossAs = ApplicationTestUtils.getOrCreateApplication(domain, LatestVersionOf.jbossAs().get(user)); + IApplication jbossAs = ApplicationTestUtils.getOrCreateApplication(domain); jbossAs = ApplicationTestUtils.destroyAndRecreateIfScalable(jbossAs); EmbeddedCartridgeTestUtils.silentlyDestroyAllEmbeddedCartridges(jbossAs); assertThat(new ApplicationAssert(jbossAs) @@ -367,8 +359,7 @@ public void shouldHaveUrlInEmbeddedPhpMyadmin() public void shouldEmbedJenkinsClient() throws Exception { // pre-conditions // need 2 free gears; jenkins + builder - IApplication application = ApplicationTestUtils.ensureHasExactly1Application( - LatestVersionOf.jbossAs(), domain); + IApplication application = ApplicationTestUtils.ensureHasExactly1Application(domain); EmbeddedCartridgeTestUtils.silentlyDestroyAllEmbeddedCartridges(application); ApplicationTestUtils.createApplication( LatestVersionOf.jenkins().get(user), domain); @@ -392,7 +383,7 @@ public void shouldEmbedJenkinsClient() throws Exception { public void shouldHaveUrlInEmbeddedJenkinsClient() throws OpenShiftException, URISyntaxException, FileNotFoundException, IOException { // pre-conditions - IApplication jbossAs = ApplicationTestUtils.getOrCreateApplication(domain, LatestVersionOf.jbossAs().get(user)); + IApplication jbossAs = ApplicationTestUtils.getOrCreateApplication(domain); jbossAs = ApplicationTestUtils.destroyAndRecreateIfScalable(jbossAs); EmbeddedCartridgeTestUtils.silentlyDestroyAllEmbeddedCartridges(jbossAs); ApplicationTestUtils.getOrCreateApplication(domain, LatestVersionOf.jenkins().get(user)); @@ -415,7 +406,7 @@ public void shouldHaveUrlInEmbeddedJenkinsClient() throws OpenShiftException, UR @Test public void shouldEmbedDownloadableCartridge() throws Exception { // pre-conditions - IApplication application = ApplicationTestUtils.ensureHasExactly1Application(LatestVersionOf.jbossAs(), domain); + IApplication application = ApplicationTestUtils.ensureHasExactly1Application(domain); EmbeddedCartridgeTestUtils.silentlyDestroyAllEmbeddedCartridges(application); assertThat(new ApplicationAssert(application)) .hasNotEmbeddableCartridge(CartridgeTestUtils.foreman063()); @@ -431,8 +422,7 @@ public void shouldEmbedDownloadableCartridge() throws Exception { @Test(expected = OpenShiftEndpointException.class) public void shouldNotAddEmbeddedCartridgeTwice() throws Exception { // pre-conditions - IApplication application = ApplicationTestUtils.ensureHasExactly1Application( - LatestVersionOf.jbossAs(), domain); + IApplication application = ApplicationTestUtils.ensureHasExactly1Application(domain); EmbeddedCartridgeTestUtils.ensureHasEmbeddedCartridges(LatestVersionOf.mySQL(), application); // operation @@ -442,8 +432,7 @@ public void shouldNotAddEmbeddedCartridgeTwice() throws Exception { @Test public void shouldRemoveEmbeddedCartridge() throws Exception { // pre-conditions - IApplication application = ApplicationTestUtils.ensureHasExactly1Application( - LatestVersionOf.jbossAs(), domain); + IApplication application = ApplicationTestUtils.ensureHasExactly1Application(domain); EmbeddedCartridgeTestUtils.ensureHasEmbeddedCartridges(LatestVersionOf.mySQL(), application); int numOfEmbeddedCartridges = application.getEmbeddedCartridges().size(); @@ -459,8 +448,7 @@ public void shouldRemoveEmbeddedCartridge() throws Exception { @Test public void shouldNotRemoveEmbeddedCartridgeThatWasNotAdded() throws SocketTimeoutException, OpenShiftException { // pre-conditions - IApplication application = ApplicationTestUtils.ensureHasExactly1Application( - LatestVersionOf.jbossAs(), domain); + IApplication application = ApplicationTestUtils.ensureHasExactly1Application(domain); EmbeddedCartridgeTestUtils.silentlyDestroy(LatestVersionOf.mySQL(), application); int numOfEmbeddedCartridges = application.getEmbeddedCartridges().size(); @@ -477,8 +465,7 @@ public void shouldNotRemoveEmbeddedCartridgeThatWasNotAdded() throws SocketTimeo @Test public void shouldSeeCartridgeRemovedWithOtherUser() throws Exception { // pre-condition - IApplication application = ApplicationTestUtils.ensureHasExactly1Application( - LatestVersionOf.jbossAs(), domain); + IApplication application = ApplicationTestUtils.ensureHasExactly1Application(domain); IEmbeddableCartridge mySqlEmbeddableCartridge = LatestVersionOf.mySQL().get(user); EmbeddedCartridgeTestUtils.ensureHasEmbeddedCartridge(mySqlEmbeddableCartridge, application); diff --git a/src/test/java/com/openshift/internal/client/HttpClientMockDirector.java b/src/test/java/com/openshift/internal/client/HttpClientMockDirector.java index 51aa47fe..6788a6c2 100644 --- a/src/test/java/com/openshift/internal/client/HttpClientMockDirector.java +++ b/src/test/java/com/openshift/internal/client/HttpClientMockDirector.java @@ -53,24 +53,36 @@ public HttpClientMockDirector() throws HttpClientException, SocketTimeoutExcepti .mockGetCartridges(Samples.GET_CARTRIDGES) .mockGetUser(Samples.GET_USER); } - + public HttpClientMockDirector mockGetAny(String response) throws SocketTimeoutException, HttpClientException { - when(client.get(any(URL.class), anyInt())).thenReturn(response); + when(client.get( + any(URL.class), + anyInt())) + .thenReturn(response); return this; } public HttpClientMockDirector mockGetAny(Exception exception) throws SocketTimeoutException, HttpClientException { - when(client.get(any(URL.class), anyInt())).thenThrow(exception); + when(client.get( + any(URL.class), + anyInt())) + .thenThrow(exception); return this; } public HttpClientMockDirector mockHeadAny(String response) throws SocketTimeoutException, HttpClientException { - when(client.head(any(URL.class), anyInt())).thenReturn(response); + when(client.head( + any(URL.class), + anyInt())) + .thenReturn(response); return this; } public HttpClientMockDirector mockHeadtAny(Exception exception) throws SocketTimeoutException, HttpClientException { - when(client.head(any(URL.class), anyInt())).thenThrow(exception); + when(client.head(any( + URL.class), + anyInt())) + .thenThrow(exception); return this; } @@ -81,14 +93,22 @@ public HttpClientMockDirector mockPostAny(Samples postRequestResponse) public HttpClientMockDirector mockPostAny(String jsonResponse) throws SocketTimeoutException, HttpClientException, EncodingException { - when(client.post(any(URL.class), any(IMediaType.class), anyInt(), Matchers.anyVararg())) + when(client.post( + any(URL.class), + any(IMediaType.class), + anyInt(), + Matchers. anyVararg())) .thenReturn(jsonResponse); return this; } public HttpClientMockDirector mockPostAny(Exception exception) throws SocketTimeoutException, HttpClientException, EncodingException { - when(client.post(any(URL.class), any(IMediaType.class), anyInt(), Matchers.anyVararg())) + when(client.post( + any(URL.class), + any(IMediaType.class), + anyInt(), + Matchers. anyVararg())) .thenThrow(exception); return this; } @@ -100,123 +120,170 @@ public HttpClientMockDirector mockPatchAny(Samples postRequestResponse) public HttpClientMockDirector mockPatchAny(String jsonResponse) throws SocketTimeoutException, HttpClientException, EncodingException { - when(client.patch(any(URL.class), any(IMediaType.class), anyInt(), Matchers.anyVararg())) + when(client.patch( + any(URL.class), + any(IMediaType.class), + anyInt(), + Matchers. anyVararg())) .thenReturn(jsonResponse); return this; } public HttpClientMockDirector mockPatchAny(Exception exception) throws SocketTimeoutException, HttpClientException, EncodingException { - when(client.patch(any(URL.class), any(IMediaType.class), anyInt(), Matchers.anyVararg())) + when(client.patch( + any(URL.class), + any(IMediaType.class), + anyInt(), + Matchers. anyVararg())) .thenThrow(exception); return this; } public HttpClientMockDirector mockPutAny(String jsonResponse) throws SocketTimeoutException, HttpClientException, EncodingException { - when(client.put(any(URL.class), any(IMediaType.class), anyInt(), Matchers.anyVararg())) + when(client.put( + any(URL.class), + any(IMediaType.class), + anyInt(), + Matchers. anyVararg())) .thenReturn(jsonResponse); return this; } public HttpClientMockDirector mockDeleteAny(String jsonResponse) throws SocketTimeoutException, HttpClientException, EncodingException { - when(client.delete(any(URL.class), any(IMediaType.class), anyInt(), Matchers.anyVararg())) + when(client.delete( + any(URL.class), + any(IMediaType.class), + anyInt(), + Matchers. anyVararg())) .thenReturn(jsonResponse); return this; } - public HttpClientMockDirector mockGetAPI(Samples getApiResourceResponse) + public HttpClientMockDirector mockGetAPI(Samples getApiResourceResponse) throws HttpClientException, SocketTimeoutException { - when(client.get(urlEndsWith("/api"), anyInt())) + when(client.get( + urlEndsWith("/api"), + anyInt())) .thenReturn(getApiResourceResponse.getContentAsString()); return this; } public HttpClientMockDirector mockGetAPI(Exception exception) throws SocketTimeoutException { - when(client.get(urlEndsWith("/api"), anyInt())) + when(client.get( + urlEndsWith("/api"), + anyInt())) .thenThrow(exception); return this; } public HttpClientMockDirector mockGetCartridges(Samples cartridgesResourceResponse) throws HttpClientException, SocketTimeoutException { - when(client.get(urlEndsWith("/cartridges"), anyInt())) + when(client.get( + urlEndsWith("/cartridges"), + anyInt())) .thenReturn(cartridgesResourceResponse.getContentAsString()); return this; } public HttpClientMockDirector mockGetUser(Samples userResourceResponse) throws HttpClientException, SocketTimeoutException { - when(client.get(urlEndsWith("/user"), anyInt())) + when(client.get( + urlEndsWith("/user"), + anyInt())) .thenReturn(userResourceResponse.getContentAsString()); return this; } - public HttpClientMockDirector mockGetKeys(Samples keysRequestResponse) throws SocketTimeoutException, HttpClientException { - when(client.get(urlEndsWith("/user/keys"), anyInt())) + public HttpClientMockDirector mockGetKeys(Samples keysRequestResponse) throws SocketTimeoutException, + HttpClientException { + when(client.get( + urlEndsWith("/user/keys"), + anyInt())) .thenReturn(keysRequestResponse.getContentAsString()); return this; } - - public HttpClientMockDirector mockCreateKey(Samples createKeyRequestResponse) + + public HttpClientMockDirector mockCreateKey(Samples createKeyRequestResponse) throws SocketTimeoutException, HttpClientException, EncodingException { when(client.post( urlEndsWith("/user/keys"), any(IMediaType.class), anyInt(), - Matchers.anyVararg())) + Matchers. anyVararg())) .thenReturn(createKeyRequestResponse.getContentAsString()); return this; } - public HttpClientMockDirector mockUpdateKey(String keyName, Samples updateKeyRequestResponse, Parameter... parameters) + public HttpClientMockDirector mockUpdateKey(String keyName, Samples updateKeyRequestResponse, + Parameter... parameters) throws SocketTimeoutException, HttpClientException, EncodingException { when(client.put( urlEndsWith("/user/keys/" + keyName), any(IMediaType.class), anyInt(), - Matchers.anyVararg())) + Matchers. anyVararg())) .thenReturn(updateKeyRequestResponse.getContentAsString()); return this; } public HttpClientMockDirector mockGetDomains(Samples domainsResourceResponse) throws SocketTimeoutException, HttpClientException { - when(client.get(urlEndsWith("/domains"), anyInt())) + when(client.get( + urlEndsWith("/domains"), + anyInt())) .thenReturn(domainsResourceResponse.getContentAsString()); return this; } public HttpClientMockDirector mockCreateDomain(Samples domainResourceResponse) throws SocketTimeoutException, HttpClientException, EncodingException { - when(client.post(urlEndsWith("/domains"), any(IMediaType.class), anyInt(), Matchers.anyVararg())) + when(client.post( + urlEndsWith("/domains"), + any(IMediaType.class), + anyInt(), + Matchers. anyVararg())) .thenReturn(domainResourceResponse.getContentAsString()); return this; } public HttpClientMockDirector mockDeleteDomain(String domainId, Samples deleteDomainResourceResponse) throws SocketTimeoutException, HttpClientException, EncodingException { - when(client.delete(urlEndsWith("/domains/" + domainId), any(IMediaType.class), anyInt(), Matchers.anyVararg())) + when( + client.delete( + urlEndsWith("/domains/" + domainId), + any(IMediaType.class), + anyInt(), + Matchers. anyVararg())) .thenReturn(deleteDomainResourceResponse.getContentAsString()); return this; } public HttpClientMockDirector mockDeleteDomain(String domainId, Exception exception) throws SocketTimeoutException, HttpClientException, EncodingException { - when(client.delete(urlEndsWith("/domains/" + domainId), any(IMediaType.class), anyInt(), Matchers.anyVararg())) + when(client.delete( + urlEndsWith("/domains/" + domainId), any(IMediaType.class), + anyInt(), + Matchers. anyVararg())) .thenThrow(exception); return this; } public HttpClientMockDirector mockRenameDomain(String domainId, Samples getDomainsResourceResponse) throws SocketTimeoutException, HttpClientException, EncodingException { - when(client.put(urlEndsWith("/domains/" + domainId), any(IMediaType.class), anyInt(), Matchers.anyVararg())) + when(client.put( + urlEndsWith("/domains/" + domainId), + any(IMediaType.class), + anyInt(), + Matchers. anyVararg())) .thenReturn(getDomainsResourceResponse.getContentAsString()); return this; } public HttpClientMockDirector mockGetDomain(String domainId, Samples domainResourceResponse) throws SocketTimeoutException, HttpClientException { - when(client.get(urlEndsWith("/domains/" + domainId), anyInt())) + when(client.get( + urlEndsWith("/domains/" + domainId), anyInt())) .thenReturn(domainResourceResponse.getContentAsString()); return this; @@ -224,14 +291,18 @@ public HttpClientMockDirector mockGetDomain(String domainId, Samples domainResou public HttpClientMockDirector mockGetApplications(String domainId, Samples applicationsResourceResponse) throws SocketTimeoutException, HttpClientException { - when(client.get(urlEndsWith("/domains/" + domainId + "/applications?include=cartridges"), anyInt())) + when(client.get( + urlEndsWith("/domains/" + domainId + "/applications?include=cartridges"), + anyInt())) .thenReturn(applicationsResourceResponse.getContentAsString()); return this; } public HttpClientMockDirector mockGetApplications(String domainId, Exception exception) throws SocketTimeoutException, HttpClientException { - when(client.get(urlEndsWith("/domains/" + domainId + "/applications?include=cartridges"), anyInt())) + when(client.get( + urlEndsWith("/domains/" + domainId + "/applications?include=cartridges"), + anyInt())) .thenThrow(exception); return this; } @@ -239,7 +310,10 @@ public HttpClientMockDirector mockGetApplications(String domainId, Exception exc public HttpClientMockDirector mockCreateApplication(String domainId, Samples postDomainsResourceResponse) throws SocketTimeoutException, HttpClientException, EncodingException { when(client.post( - urlEndsWith("/domains/" + domainId + "/applications?include=cartridges"), any(IMediaType.class), anyInt(), Matchers.anyVararg())) + urlEndsWith("/domains/" + domainId + "/applications?include=cartridges"), + any(IMediaType.class), + anyInt(), + Matchers. anyVararg())) .thenReturn(postDomainsResourceResponse.getContentAsString()); return this; } @@ -249,8 +323,9 @@ public HttpClientMockDirector mockPostApplicationEvent(String domainId, String a throws SocketTimeoutException, HttpClientException, EncodingException { when(client.post( urlEndsWith("/domains/" + domainId + "/applications/" + applicationName + "/events"), - any(IMediaType.class), anyInt(), - Matchers.anyVararg())) + any(IMediaType.class), + anyInt(), + Matchers. anyVararg())) .thenReturn(postApplicationEvent.getContentAsString()); return this; } @@ -258,7 +333,9 @@ public HttpClientMockDirector mockPostApplicationEvent(String domainId, String a public HttpClientMockDirector mockGetApplication(String domainId, String applicationName, Samples applicationResourceResponse) throws SocketTimeoutException, HttpClientException { - when(client.get(urlEndsWith("/domains/" + domainId + "/applications/" + applicationName), anyInt())) + when(client.get( + urlEndsWith("/domains/" + domainId + "/applications/" + applicationName), + anyInt())) .thenReturn(applicationResourceResponse.getContentAsString()); return this; } @@ -283,12 +360,25 @@ public HttpClientMockDirector mockGetGearGroups(String domainId, String applicat return this; } + public HttpClientMockDirector mockSetGearGroups(String domainId, String applicationName, + Samples gearGroupsResourceResponse) + throws SocketTimeoutException, HttpClientException { + when(client.put( + urlEndsWith("/domains/" + domainId + "/applications/" + applicationName), + any(IMediaType.class), + anyInt(), + Matchers. anyVararg())) + .thenReturn(gearGroupsResourceResponse.getContentAsString()); + return this; + } + public HttpClientMockDirector mockPostApplicationEvent(String domainId, String applicationName, Exception exception) throws SocketTimeoutException, HttpClientException, EncodingException { when(client.post( urlEndsWith("/domains/" + domainId + "/applications/" + applicationName + "/events"), - any(IMediaType.class), anyInt(), - Matchers.anyVararg())) + any(IMediaType.class), + anyInt(), + Matchers. anyVararg())) .thenThrow(exception); return this; } @@ -299,7 +389,7 @@ public HttpClientMockDirector mockAddEmbeddableCartridge(String domainId, String when(client.post( urlEndsWith("/domains/" + domainId + "/applications/" + applicationName + "/cartridges"), any(IMediaType.class), anyInt(), - Matchers.anyVararg())) + Matchers. anyVararg())) .thenReturn(addEmbeddedCartridgeResponse.getContentAsString()); return this; } @@ -309,8 +399,8 @@ public HttpClientMockDirector mockAddEmbeddableCartridge(String domainId, String throws SocketTimeoutException, HttpClientException, EncodingException { when(client.post( urlEndsWith("/domains/" + domainId + "/applications/" + applicationName + "/cartridges"), - any(IMediaType.class), anyInt(), - Matchers.anyVararg())) + any(IMediaType.class), anyInt(), + Matchers. anyVararg())) .thenThrow(exception); return this; } @@ -323,7 +413,7 @@ public HttpClientMockDirector mockRemoveEmbeddableCartridge(String domainId, Str urlEndsWith( "/domains/" + domainId + "/applications/" + applicationName + "/cartridges/" + cartridgeName), any(IMediaType.class), anyInt(), - Matchers.anyVararg())) + Matchers. anyVararg())) .thenThrow(exception); return this; } @@ -333,7 +423,7 @@ public HttpClientMockDirector verifyPostApplicationEvent(String domainId, String verify(client, times(1)).post( urlEndsWith("/domains/" + domainId + "/applications/" + applicationName + "/events"), any(IMediaType.class), anyInt(), - Matchers.anyVararg()); + Matchers. anyVararg()); return this; } @@ -359,7 +449,7 @@ public HttpClientMockDirector verifyAddEmbeddableCartridge(String domainId, Stri verify(client, times(1)).post( urlEndsWith("/domains/" + domainId + "/applications/" + applicationName + "/cartridges"), any(IMediaType.class), anyInt(), - Matchers.anyVararg()); + Matchers. anyVararg()); return this; } @@ -370,7 +460,7 @@ public HttpClientMockDirector verifyDeleteEmbeddableCartridge(String domainId, S urlEndsWith("/domains/" + domainId + "/applications/" + applicationName + "/cartridges/" + cartridgeName), any(IMediaType.class), anyInt(), - Matchers.anyVararg()); + Matchers. anyVararg()); return this; } @@ -387,7 +477,8 @@ public HttpClientMockDirector verifyGet(String url, int times) public HttpClientMockDirector verifyPostAny(int times) throws SocketTimeoutException, HttpClientException, EncodingException { - verify(client, times(times)).post(any(URL.class), any(IMediaType.class), anyInt(),Matchers.anyVararg()); + verify(client, times(times)).post(any(URL.class), any(IMediaType.class), anyInt(), + Matchers. anyVararg()); return this; } @@ -399,37 +490,43 @@ public HttpClientMockDirector verifyPost(Parameter... parameters) public HttpClientMockDirector verifyPost(String url, int times) throws SocketTimeoutException, HttpClientException, EncodingException, MalformedURLException { - verify(client, times(times)).post(new URL(url), any(IMediaType.class), anyInt(), Matchers.anyVararg()); + verify(client, times(times)).post(new URL(url), any(IMediaType.class), anyInt(), + Matchers. anyVararg()); return this; } public HttpClientMockDirector verifyPutAny(int times) throws SocketTimeoutException, HttpClientException, EncodingException { - verify(client, times(times)).put(any(URL.class), any(IMediaType.class), anyInt(),Matchers.anyVararg()); + verify(client, times(times)).put(any(URL.class), any(IMediaType.class), anyInt(), + Matchers. anyVararg()); return this; } public HttpClientMockDirector verifyPut(String url, int times) throws SocketTimeoutException, HttpClientException, EncodingException, MalformedURLException { - verify(client, times(times)).put(new URL(url), any(IMediaType.class), anyInt(),Matchers.anyVararg()); + verify(client, times(times)).put(new URL(url), any(IMediaType.class), anyInt(), + Matchers. anyVararg()); return this; } public HttpClientMockDirector verifyDeleteAny(int times) throws SocketTimeoutException, HttpClientException, EncodingException { - verify(client, times(times)).delete(any(URL.class), any(IMediaType.class), anyInt(),Matchers.anyVararg()); + verify(client, times(times)).delete(any(URL.class), any(IMediaType.class), anyInt(), + Matchers. anyVararg()); return this; } public HttpClientMockDirector verifyDelete(String url, int times) throws SocketTimeoutException, HttpClientException, EncodingException, MalformedURLException { - verify(client, times(times)).delete(new URL(url), any(IMediaType.class), anyInt(), Matchers.anyVararg()); + verify(client, times(times)).delete(new URL(url), any(IMediaType.class), anyInt(), + Matchers. anyVararg()); return this; } public HttpClientMockDirector verifyPatchAny(int times) throws SocketTimeoutException, HttpClientException, EncodingException { - verify(client, times(times)).patch(any(URL.class), any(IMediaType.class), anyInt(),Matchers.anyVararg()); + verify(client, times(times)).patch(any(URL.class), any(IMediaType.class), anyInt(), + Matchers. anyVararg()); return this; } @@ -446,7 +543,8 @@ public HttpClientMockDirector verifyGetDomains() throws SocketTimeoutException, public HttpClientMockDirector verifyRenameDomain(String domainId) throws SocketTimeoutException, HttpClientException, EncodingException { - verify(client, times(1)).put(urlEndsWith(domainId), any(IMediaType.class), anyInt(),Matchers.anyVararg()); + verify(client, times(1)).put(urlEndsWith(domainId), any(IMediaType.class), anyInt(), + Matchers. anyVararg()); return this; } @@ -457,7 +555,8 @@ public HttpClientMockDirector verifyGetDomain(String domainId) throws SocketTime public HttpClientMockDirector verifyGetApplications(String domainId, int times) throws SocketTimeoutException, HttpClientException { - verify(client, times(times)).get(urlEndsWith("/domains/" + domainId + "/applications?include=cartridges"), anyInt()); + verify(client, times(times)).get(urlEndsWith("/domains/" + domainId + "/applications?include=cartridges"), + anyInt()); return this; } @@ -488,7 +587,7 @@ public HttpClientMockDirector verifyUpdateKey(String keyName, Parameter... param public HttpClientMockDirector verifyCreateApplication(String domainId, int timeout, Parameter... parameters) throws SocketTimeoutException, HttpClientException, EncodingException { verify(client).post( - urlEndsWith("/domains/" + domainId + "/applications?include=cartridges"), + urlEndsWith("/domains/" + domainId + "/applications?include=cartridges"), any(IMediaType.class), eq(timeout), eq(parameters)); return this; } @@ -501,47 +600,59 @@ public IDomain getDomain(String string) throws OpenShiftException, FileNotFoundE IUser user = new TestConnectionBuilder().defaultCredentials().create(client).getUser(); return user.getDomain("foobarz"); } - + public HttpClientMockDirector mockAddEnvironmentVariable(String domainId, String applicationName, Samples addEnvironmentVariableRequestResponse) throws SocketTimeoutException, HttpClientException, EncodingException { - when(client.post(urlEndsWith("/domains/" + domainId + "/applications/" + applicationName + "/environment-variables"), - any(IMediaType.class), anyInt(), Matchers.anyVararg())) + when( + client.post(urlEndsWith("/domains/" + domainId + "/applications/" + applicationName + + "/environment-variables"), + any(IMediaType.class), anyInt(), Matchers. anyVararg())) .thenReturn(addEnvironmentVariableRequestResponse.getContentAsString()); return this; } - + public HttpClientMockDirector mockGetEnvironmentVariables(String domainId, String applicationName, Samples getZeroEnvironmentVariableRequestResponse, Samples getOneEnvironmentVariableRequestResponse) throws SocketTimeoutException, HttpClientException, EncodingException { - when(client.get(urlEndsWith("/domains/" + domainId + "/applications/" + applicationName + "/environment-variables"), - anyInt())) - .thenReturn(getZeroEnvironmentVariableRequestResponse.getContentAsString(), getOneEnvironmentVariableRequestResponse.getContentAsString()); + when( + client.get(urlEndsWith("/domains/" + domainId + "/applications/" + applicationName + + "/environment-variables"), + anyInt())) + .thenReturn(getZeroEnvironmentVariableRequestResponse.getContentAsString(), + getOneEnvironmentVariableRequestResponse.getContentAsString()); return this; } public HttpClientMockDirector mockGetEnvironmentVariables(String domainId, String applicationName, Samples getOneEnvironmentVariableRequestResponse) throws SocketTimeoutException, HttpClientException, EncodingException { - when(client.get(urlEndsWith("/domains/" + domainId + "/applications/" + applicationName + "/environment-variables"), - anyInt())) - .thenReturn(getOneEnvironmentVariableRequestResponse.getContentAsString(),getOneEnvironmentVariableRequestResponse.getContentAsString()); + when( + client.get(urlEndsWith("/domains/" + domainId + "/applications/" + applicationName + + "/environment-variables"), + anyInt())) + .thenReturn(getOneEnvironmentVariableRequestResponse.getContentAsString(), + getOneEnvironmentVariableRequestResponse.getContentAsString()); return this; } - + public HttpClientMockDirector mockUpdateEnvironmentVariableValue(String domainId, String applicationName, String environmentName, Samples updateEnvironmentVariableValue) throws SocketTimeoutException, HttpClientException, EncodingException { - when(client.put(urlEndsWith("/domains/" + domainId + "/applications/" + applicationName + "/environment-variables/"+ environmentName), - any(IMediaType.class), anyInt(), Matchers. anyVararg())) - .thenReturn(updateEnvironmentVariableValue.getContentAsString()); + when( + client.put(urlEndsWith("/domains/" + domainId + "/applications/" + applicationName + + "/environment-variables/" + environmentName), + any(IMediaType.class), + anyInt(), + Matchers. anyVararg())) + .thenReturn(updateEnvironmentVariableValue.getContentAsString()); return this; } - public HttpClientMockDirector mockGetQuickstarts(Samples getQuickstartsResponse) + public HttpClientMockDirector mockGetQuickstarts(Samples getQuickstartsResponse) throws SocketTimeoutException, HttpClientException { when(client.get(urlEndsWith("api/v1/quickstarts/promoted.json"), anyInt())) - .thenReturn(getQuickstartsResponse.getContentAsString()); + .thenReturn(getQuickstartsResponse.getContentAsString()); return this; } } diff --git a/src/test/java/com/openshift/internal/client/StandaloneCartridgeResourceIntegrationTest.java b/src/test/java/com/openshift/internal/client/StandaloneCartridgeResourceIntegrationTest.java index c8998b71..fd7e14c7 100755 --- a/src/test/java/com/openshift/internal/client/StandaloneCartridgeResourceIntegrationTest.java +++ b/src/test/java/com/openshift/internal/client/StandaloneCartridgeResourceIntegrationTest.java @@ -16,6 +16,7 @@ import java.net.URISyntaxException; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import com.openshift.client.IApplication; @@ -54,79 +55,81 @@ public void shouldReportStandaloneCartridge() throws OpenShiftException, URISynt // operation IStandaloneCartridge cartridge = application.getCartridge(); - + // verification assertThat(cartridge).isNotNull(); assertThat(cartridge.getName()).isNotEmpty(); - IStandaloneCartridge availableCartridge = new CartridgeNameQuery(cartridge.getName()).get(user.getConnection().getStandaloneCartridges()); + IStandaloneCartridge availableCartridge = new CartridgeNameQuery(cartridge.getName()).get(user.getConnection() + .getStandaloneCartridges()); new StandaloneCartridgeAssert(cartridge).equals(availableCartridge); } - + @Test public void shouldReportGearGroup() throws OpenShiftException, URISyntaxException { // precondition IDeployedStandaloneCartridge cartridge = application.getCartridge(); assertThat(cartridge).isNotNull(); - + // operation IGearGroup gearGroup = cartridge.getGearGroup(); - + // verification assertThat(gearGroup).isNotNull(); assertThat(gearGroup.getCartridges()).contains(cartridge); } - + @Test public void shouldGetGearStorage() throws OpenShiftException, URISyntaxException, IOException { // precondition IDeployedStandaloneCartridge cartridge = application.getCartridge(); assertThat(cartridge).isNotNull(); - + // operation int additionalGearStorage = cartridge.getAdditionalGearStorage(); - + // verification // reload user info to ensure the storage info isnt cached assertThat(additionalGearStorage).isNotEqualTo(IGearGroup.NO_ADDITIONAL_GEAR_STORAGE); } - + + @Ignore("This application is not allowed to have additional gear storage") @Test public void shouldSetGearStorage() throws OpenShiftException, URISyntaxException, IOException { // precondition IDeployedStandaloneCartridge cartridge = application.getCartridge(); assertThat(cartridge).isNotNull(); - int additionalGearStorage = cartridge.getAdditionalGearStorage(); int newAdditionalGearStorage = 3; // operation cartridge.setAdditionalGearStorage(newAdditionalGearStorage); - + // verification // reload user info to ensure the storage info isnt cached assertThat(cartridge.getAdditionalGearStorage()).isEqualTo(newAdditionalGearStorage); } - + + @Ignore("This application is not allowed to have additional gear storage") @Test - public void shouldSeeNewAdditionalGearStorageInNewConnection() throws OpenShiftException, URISyntaxException, IOException { + public void shouldSeeNewAdditionalGearStorageInNewConnection() throws OpenShiftException, URISyntaxException, + IOException { // precondition IDeployedStandaloneCartridge cartridge = application.getCartridge(); assertThat(cartridge).isNotNull(); int additionalGearStorage = 4; - + // operation cartridge.setAdditionalGearStorage(additionalGearStorage); - + // verification // reload user info to ensure the storage info isnt cached IUser newUser = new TestConnectionBuilder() - .defaultCredentials() - .disableSSLCertificateChecks() - .create() - .getUser(); + .defaultCredentials() + .disableSSLCertificateChecks() + .create() + .getUser(); IApplication newApplication = newUser.getDefaultDomain().getApplicationByName(application.getName()); IDeployedStandaloneCartridge newCartridge = newApplication.getCartridge(); new StandaloneCartridgeAssert(newCartridge).isEqualTo(cartridge); assertThat(newCartridge.getAdditionalGearStorage()).isEqualTo(additionalGearStorage); - } } \ No newline at end of file diff --git a/src/test/java/com/openshift/internal/client/StandaloneCartridgeResourceTest.java b/src/test/java/com/openshift/internal/client/StandaloneCartridgeResourceTest.java index ab1bd306..d88ec32e 100644 --- a/src/test/java/com/openshift/internal/client/StandaloneCartridgeResourceTest.java +++ b/src/test/java/com/openshift/internal/client/StandaloneCartridgeResourceTest.java @@ -22,16 +22,24 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.io.IOException; +import java.net.URISyntaxException; + import org.junit.Before; import org.junit.Test; +import org.mockito.Mockito; import com.openshift.client.IApplication; import com.openshift.client.IDomain; +import com.openshift.client.IGearGroup; import com.openshift.client.IHttpClient; import com.openshift.client.IUser; +import com.openshift.client.OpenShiftException; import com.openshift.client.cartridge.IDeployedStandaloneCartridge; import com.openshift.client.cartridge.IStandaloneCartridge; import com.openshift.client.cartridge.StandaloneCartridge; +import com.openshift.client.utils.CartridgeTestUtils; +import com.openshift.client.utils.Samples; import com.openshift.client.utils.TestConnectionBuilder; import com.openshift.internal.client.httpclient.request.JsonMediaType; import com.openshift.internal.client.httpclient.request.Parameter; @@ -45,17 +53,40 @@ */ public class StandaloneCartridgeResourceTest { - private ApplicationResource app = mock(ApplicationResource.class); + private ApplicationResource application = mock(ApplicationResource.class); private CartridgeResourceDTO dto = mock(CartridgeResourceDTO.class); - private IStandaloneCartridge cartridge = mock(IStandaloneCartridge.class); - private StandaloneCartridgeResource cartridgeResource; + private IStandaloneCartridge as7Cartridge = new StandaloneCartridge(CartridgeTestUtils.JBOSSAS_7_NAME); + private IStandaloneCartridge phpCartridge = new StandaloneCartridge(CartridgeTestUtils.PHP_53_NAME); + private IDeployedStandaloneCartridge deployedPhpCartridge; + + private IUser user; + private IDomain domain; + private IApplication springeap6Application; + private IHttpClient client; + private HttpClientMockDirector mockDirector; @Before - public void setup() { - when(dto.getName()).thenReturn("cartridgeName"); + public void setup() throws Throwable { + when(dto.getName()).thenReturn(CartridgeTestUtils.PHP_53_NAME); when(dto.getType()).thenReturn(CartridgeType.STANDALONE); - when(cartridge.getName()).thenReturn("cartridgeName"); - this.cartridgeResource = new StandaloneCartridgeResource(dto, app); + this.deployedPhpCartridge = new StandaloneCartridgeResource(dto, application); + this.mockDirector = new HttpClientMockDirector(); + this.client = mockDirector + .mockGetDomains(GET_DOMAINS) + .mockGetApplications( + "foobarz", Samples.GET_DOMAINS_FOOBARZ_APPLICATIONS_1EMBEDDED) + .mockGetApplication( + "foobarz", "springeap6", Samples.GET_DOMAINS_FOOBARZ_APPLICATIONS_SPRINGEAP6_1EMBEDDED) + .mockGetGearGroups( + "foobarz", "springeap6", Samples.GET_DOMAINS_FOOBARZ_APPLICATIONS_SPRINGEAP6_GEARGROUPS) + // ATTENTION: nothing changed in the mocked response (works + // since application is not caching geargroups) + .mockSetGearGroups( + "foobarz", "springeap6", Samples.GET_DOMAINS_FOOBARZ_APPLICATIONS_SPRINGEAP6_GEARGROUPS) + .client(); + this.user = new TestConnectionBuilder().defaultCredentials().create(client).getUser(); + this.domain = user.getDomain("foobarz"); + this.springeap6Application = domain.getApplicationByName("springeap6"); } @Test @@ -82,14 +113,12 @@ public void testUpdateAdditionalGearStorage() throws Exception { } @Test - public void standaloneCartridgeResourceShouldEqualStandAloneCartridge() { + public void standaloneCartridgeShouldEqualStandaloneCartridgeResource() { // pre-conditions // operation // verification - assertThat(cartridgeResource).isEqualTo(cartridge); - - when(cartridge.getName()).thenReturn("other"); - assertThat(cartridgeResource).isNotEqualTo(cartridge); + assertThat(phpCartridge).isEqualTo(deployedPhpCartridge); + assertThat(as7Cartridge).isNotEqualTo(deployedPhpCartridge); } @Test @@ -98,6 +127,50 @@ public void standaloneCartridgeResourceAndStandAloneCartridgeShouldHaveSameHashC // operation // verification - assertThat(cartridgeResource.hashCode()).isEqualTo(new StandaloneCartridge("cartridgeName").hashCode()); + assertThat(deployedPhpCartridge.hashCode()).isEqualTo(phpCartridge.hashCode()); + } + + @Test + public void shouldReportGearGroup() throws OpenShiftException, URISyntaxException { + // precondition + IDeployedStandaloneCartridge cartridge = springeap6Application.getCartridge(); + assertThat(cartridge).isNotNull(); + + // operation + IGearGroup gearGroup = cartridge.getGearGroup(); + + // verification + assertThat(gearGroup).isNotNull(); + assertThat(gearGroup.getCartridges()).contains(cartridge); + } + + @Test + public void shouldGetGearStorage() throws OpenShiftException, IOException { + // precondition + IDeployedStandaloneCartridge cartridge = springeap6Application.getCartridge(); + assertThat(cartridge).isNotNull(); + + // operation + int additionalGearStorage = cartridge.getAdditionalGearStorage(); + + // verification + // reload user info to ensure the storage info isnt cached + assertThat(additionalGearStorage).isNotEqualTo(IGearGroup.NO_ADDITIONAL_GEAR_STORAGE); + } + + @Test + public void shouldSetGearStorage() throws OpenShiftException, IOException { + // precondition + IDeployedStandaloneCartridge cartridge = springeap6Application.getCartridge(); + assertThat(cartridge).isNotNull(); + int newAdditionalGearStorage = 12; + + // operation + cartridge.setAdditionalGearStorage(newAdditionalGearStorage); + + // verification + // reload user info to ensure the storage info isnt cached + mockDirector.mockGetGearGroups("foobarz", "springeap6", Samples.GET_DOMAINS_FOOBARZ_APPLICATIONS_SPRINGEAP6_GEARGROUPS_12ADDITIONALGEARSTORAGE); + assertThat(cartridge.getAdditionalGearStorage()).isEqualTo(newAdditionalGearStorage); } } diff --git a/src/test/java/com/openshift/internal/client/StandaloneCartridgeTest.java b/src/test/java/com/openshift/internal/client/StandaloneCartridgeTest.java index 38e7e542..90e1e733 100644 --- a/src/test/java/com/openshift/internal/client/StandaloneCartridgeTest.java +++ b/src/test/java/com/openshift/internal/client/StandaloneCartridgeTest.java @@ -11,7 +11,7 @@ package com.openshift.internal.client; import static org.fest.assertions.Assertions.assertThat; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import java.net.MalformedURLException; import java.net.URL; @@ -66,7 +66,7 @@ public void shouldDownloadableStandaloneNotEqualsDownloadableEmbeddable() throws assertThat(new StandaloneCartridge(new URL(CartridgeTestUtils.GO_URL))) .isNotEqualTo(new EmbeddableCartridge(new URL(CartridgeTestUtils.FOREMAN_URL))); } - + @Test public void shouldHaveNameDisplaynameDescription() throws Throwable { // pre-condition diff --git a/src/test/resources/samples/get-domains-foobarz-applications-springeap6-geargroups-12additionalgearstorage.json b/src/test/resources/samples/get-domains-foobarz-applications-springeap6-geargroups-12additionalgearstorage.json new file mode 100644 index 00000000..b77701ac --- /dev/null +++ b/src/test/resources/samples/get-domains-foobarz-applications-springeap6-geargroups-12additionalgearstorage.json @@ -0,0 +1,149 @@ +{ + "data":[ + { + "additional_gear_storage":12, + "base_gear_storage":1, + "cartridges":[ + { + "name":"jbosseap-6", + "display_name":"JBoss Enterprise Application Platform 6.0", + "tags":[ + "service", + "web_framework", + "java", + "jboss", + "jee_full_profile" + ] + }, + { + "connection_url":"mongodb://$OPENSHIFT_MONGODB_DB_HOST:$OPENSHIFT_MONGODB_DB_PORT/", + "username":"admin", + "password":"NNxXMT1z8dVj", + "database_name":"springeap6", + "name":"mongodb-2.2", + "display_name":"MongoDB NoSQL Database 2.2", + "tags":[ + "service", + "database", + "nosql", + "embedded" + ] + } + ], + "gear_profile":"small", + "gears":[ + { + "id":"514207b84382ec1fef000098", + "state":"idle", + "ssh_url":"ssh://52380549e0b8cd1e0e000032@springeap6-foobarz.rhcloud.com", + "port_interfaces":[ + { + "_id":"52380576e0b8cd1e0e000050", + "cartridge_name":"jbossas-7", + "external_address":"54.226.57.149", + "external_port":"38526", + "internal_address":"127.2.37.129", + "internal_port":"8080" + }, + { + "_id":"52380576e0b8cd1e0e000051", + "cartridge_name":"jbossas-7", + "external_address":"54.226.57.149", + "external_port":"38527", + "internal_address":"127.2.37.129", + "internal_port":"7600" + }, + { + "_id":"52380576e0b8cd1e0e000052", + "cartridge_name":"jbossas-7", + "external_address":"54.226.57.149", + "external_port":"38528", + "internal_address":"127.2.37.129", + "internal_port":"5445" + }, + { + "_id":"52380576e0b8cd1e0e000053", + "cartridge_name":"jbossas-7", + "external_address":"54.226.57.149", + "external_port":"38529", + "internal_address":"127.2.37.129", + "internal_port":"5455" + }, + { + "_id":"52380576e0b8cd1e0e000054", + "cartridge_name":"jbossas-7", + "external_address":"54.226.57.149", + "external_port":"38530", + "internal_address":"127.2.37.129", + "internal_port":"4447" + } + + ] + }, + { + "id":"5146f047500446f12d00002e", + "state":"building" + } + ], + "name":"514207b84382ec1fef0000ab", + "scales_from":1, + "scales_to":1, + "uuid":"514207b84382ec1fef0000ab" + }, + { + "additional_gear_storage":0, + "base_gear_storage":1, + "cartridges":[ + { + "connection_url":"mongodb://514212ce50-foobarz.rhcloud.com:37076/", + "username":"admin", + "password":"DLCVKnnzuGfF", + "database_name":"sringeap6", + "name":"mongodb-2.2", + "display_name":"MongoDB NoSQL Database 2.2", + "tags":[ + "service", + "database", + "nosql", + "embedded" + ] + } + ], + "gear_profile":"small", + "gears":[ + { + "id":"514212ce500446b64e0000b4", + "state":"deploying", + "ssh_url":"ssh://523809b75973ca569600019b@523809b75973ca569600019b-foobarz.rhcloud.com", + "port_interfaces":[ + { + "_id":"52380a0a5973ca56960001b0", + "cartridge_name":"mongodb-2.2", + "external_address":"174.129.147.144", + "external_port":"52931", + "internal_address":"127.7.198.1", + "internal_port":"27017" + } + ] + } + ], + "name":"514212ce500446b64e0000c0", + "scales_from":null, + "scales_to":null, + "uuid":"514212ce500446b64e0000c0" + } + ], + "messages":[ + + ], + "status":"ok", + "supported_api_versions":[ + 1.0, + 1.1, + 1.2, + 1.3, + 1.4 + ], + "type":"gear_groups", + "version":"1.2" +} \ No newline at end of file