Author: adietish
Date: 2011-09-23 09:38:47 -0400 (Fri, 23 Sep 2011)
New Revision: 34998
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/ApplicationInfo.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/IUser.java
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/CartridgeTest.java
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/UserTest.java
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/fakes/CartridgeResponseFake.java
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/utils/ApplicationInfoAsserts.java
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/Application.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/ApplicationLogReader.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/Cartridge.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/Domain.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/IOpenshiftService.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/ISSHPublicKey.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/SSHKeyPair.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/SSHPublicKey.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/User.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/UserInfo.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/OpenshiftService.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/response/ApplicationResponseUnmarshaller.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/response/DomainResponseUnmarshaller.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/response/UserInfoResponseUnmarshaller.java
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/ApplicationIntegrationTest.java
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/ApplicationTest.java
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/CartridgesIntegrationTest.java
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/DomainIntegrationTest.java
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/DomainTest.java
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/ListCartridgesIntegrationTest.java
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/OpenshiftTestSuite.java
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/UserInfoIntegrationTest.java
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/UserInfoTest.java
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/fakes/ApplicationResponseFake.java
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/fakes/NoopOpenshiftServiceFake.java
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/fakes/UserInfoResponseFake.java
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/utils/ApplicationAsserts.java
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/utils/CartridgeAsserts.java
Log:
[JBIDE-9591] implementing Application#getGitUri:
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/Application.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/Application.java 2011-09-23
13:26:18 UTC (rev 34997)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/Application.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -32,12 +32,8 @@
private User user;
- private boolean userInfoQueried;
-
- public Application(String name, Cartridge cartridge, IOpenshiftService service) {
- this(name, null, cartridge, null, null, null, service);
-
- this.userInfoQueried = false;
+ public Application(String name, Cartridge cartridge, User user, IOpenshiftService
service) {
+ this(name, null, cartridge, null, null, user, service);
}
public Application(String name, String uuid, Cartridge cartridge, String embedded, Date
creationTime, User user,
@@ -49,8 +45,6 @@
this.creationTime = creationTime;
this.user = user;
this.service = service;
-
- this.userInfoQueried = true;
}
public String getName() {
@@ -58,7 +52,7 @@
}
public String getUUID() throws OpenshiftException {
- updateFromUserInfoIfNeeded();
+ user.loadLazyValues();
return uuid;
}
@@ -67,39 +61,38 @@
}
public String getEmbedded() throws OpenshiftException {
- updateFromUserInfoIfNeeded();
+ user.loadLazyValues();
return embedded;
}
public Date getCreationTime() throws OpenshiftException {
- updateFromUserInfoIfNeeded();
+ user.loadLazyValues();
return creationTime;
}
- protected User getUser() throws OpenshiftException {
- updateFromUserInfoIfNeeded();
+ protected IUser getUser() throws OpenshiftException {
return user;
}
public void destroy() throws OpenshiftException {
- service.destroyApplication(name, cartridge);
+ service.destroyApplication(name, cartridge, user);
}
public void start() throws OpenshiftException {
- service.startApplication(name, cartridge);
+ service.startApplication(name, cartridge, user);
}
public void restart() throws OpenshiftException {
- service.restartApplication(name, cartridge);
+ service.restartApplication(name, cartridge, user);
}
public void stop() throws OpenshiftException {
- service.stopApplication(name, cartridge);
+ service.stopApplication(name, cartridge, user);
}
public ApplicationLogReader getLog() throws OpenshiftException {
if (logReader == null) {
- this.logReader = new ApplicationLogReader(this, service);
+ this.logReader = new ApplicationLogReader(this, user, service);
}
return logReader;
}
@@ -120,24 +113,39 @@
return Assert.assertNotNull(getUser()).getDomain();
}
- private void updateFromUserInfoIfNeeded() throws OpenshiftException {
- if (!userInfoQueried) {
- updateFrom(service.getUserInfo());
- this.userInfoQueried = true;
+ void update(ApplicationInfo applicationInfo) {
+ if (applicationInfo == null) {
+ return;
}
+ this.cartridge = applicationInfo.getCartridge();
+ this.creationTime = applicationInfo.getCreationTime();
+ this.name = applicationInfo.getName();
+ this.uuid = applicationInfo.getUuid();
}
-
- private void updateFrom(UserInfo userInfo) {
- updateFrom(userInfo.getApplicationByName(getName()));
- this.user = userInfo.getUser();
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ return result;
}
- private void updateFrom(Application application) {
- this.cartridge = application.cartridge;
- this.creationTime = application.creationTime;
- this.name = application.name;
- this.uuid = application.uuid;
-
- this.userInfoQueried = false;
+ @Override
+ public boolean equals(Object object) {
+ if (this == object)
+ return true;
+ if (object == null)
+ return false;
+ if (getClass() != object.getClass())
+ return false;
+ Application other = (Application) object;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ return true;
}
+
}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/ApplicationInfo.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/ApplicationInfo.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/ApplicationInfo.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * 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 org.jboss.ide.eclipse.as.openshift.core;
+
+import java.util.Date;
+
+/**
+ * @author André Dietisheim
+ */
+public class ApplicationInfo {
+
+ private String name;
+ private String uuid;
+ private String embedded;
+ private Cartridge cartridge;
+ private Date creationTime;
+
+ public ApplicationInfo(String name, String uuid, String embedded, Cartridge cartridge,
Date creationTime) {
+ this.name = name;
+ this.uuid = uuid;
+ this.embedded = embedded;
+ this.cartridge = cartridge;
+ this.creationTime = creationTime;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getEmbedded() {
+ return embedded;
+ }
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ public Cartridge getCartridge() {
+ return cartridge;
+ }
+
+ public Date getCreationTime() {
+ return creationTime;
+ }
+
+}
Property changes on:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/ApplicationInfo.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/ApplicationLogReader.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/ApplicationLogReader.java 2011-09-23
13:26:18 UTC (rev 34997)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/ApplicationLogReader.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -33,8 +33,11 @@
private Application application;
private int logIndex = 0;
- public ApplicationLogReader(Application application, IOpenshiftService service) {
+ private User user;
+
+ public ApplicationLogReader(Application application, User user, IOpenshiftService
service) {
this.application = application;
+ this.user = user;
this.service = service;
}
@@ -68,7 +71,7 @@
protected String requestStatus() throws IOException {
try {
- return service.getStatus(application.getName(), application.getCartridge());
+ return service.getStatus(application.getName(), application.getCartridge(), user);
} catch (OpenshiftException e) {
throw new IOException(e);
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/Cartridge.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/Cartridge.java 2011-09-23
13:26:18 UTC (rev 34997)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/Cartridge.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -7,17 +7,19 @@
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ ******************************************************************************/
package org.jboss.ide.eclipse.as.openshift.core;
-
/**
+ * CA 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.
+ *
* @author André Dietisheim
*/
public class Cartridge {
public static final Cartridge JBOSSAS_7 = new Cartridge("jbossas-7.0");
-
+
private String name;
public Cartridge(String name) {
@@ -27,4 +29,11 @@
public String getName() {
return name;
}
+
+ public static Cartridge valueOf(String name) {
+ if (JBOSSAS_7.getName().equals(name)) {
+ return JBOSSAS_7;
+ }
+ return null;
+ }
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/Domain.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/Domain.java 2011-09-23
13:26:18 UTC (rev 34997)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/Domain.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -18,21 +18,29 @@
private String namespace;
private String rhcDomain;
+ private User user;
- public Domain(String namespace) {
- this(namespace, null);
+ public Domain(String namespace, User user) {
+ this(namespace, null, user);
}
- public Domain(String namespace, String rhcDomain) {
+ public Domain(String namespace, String rhcDomain, User user) {
this.namespace = namespace;
this.rhcDomain = rhcDomain;
+ this.user = user;
}
- public String getRhcDomain() {
+ public String getNamespace() throws OpenshiftException {
+ return namespace;
+ }
+
+ public String getRhcDomain() throws OpenshiftException {
+ user.loadLazyValues();
return rhcDomain;
}
- public String getNamespace() {
- return namespace;
+ void update(UserInfo userInfo) {
+ this.rhcDomain = userInfo.getRhcDomain();
+ this.namespace = userInfo.getNamespace();
}
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/IOpenshiftService.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/IOpenshiftService.java 2011-09-23
13:26:18 UTC (rev 34997)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/IOpenshiftService.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -17,27 +17,23 @@
*/
public interface IOpenshiftService {
- public UserInfo getUserInfo() throws OpenshiftException;
+ public UserInfo getUserInfo(User user) throws OpenshiftException;
- public List<Cartridge> getCartridges() throws OpenshiftException;
+ public List<Cartridge> getCartridges(User user) throws OpenshiftException;
- public Application createApplication(String name, Cartridge cartridge) throws
OpenshiftException;
+ public Application createApplication(String name, Cartridge cartridge, User user) throws
OpenshiftException;
- public Application destroyApplication(String name, Cartridge cartridge) throws
OpenshiftException;
+ public Application destroyApplication(String name, Cartridge cartridge, User user)
throws OpenshiftException;
- public Application startApplication(String name, Cartridge cartridge) throws
OpenshiftException;
+ public Application startApplication(String name, Cartridge cartridge, User user) throws
OpenshiftException;
- public Application restartApplication(String name, Cartridge cartridge) throws
OpenshiftException;
+ public Application restartApplication(String name, Cartridge cartridge, User user)
throws OpenshiftException;
- public Application stopApplication(String name, Cartridge cartridge) throws
OpenshiftException;
+ public Application stopApplication(String name, Cartridge cartridge, User user) throws
OpenshiftException;
- public String getStatus(String name, Cartridge cartridge) throws OpenshiftException;
+ public String getStatus(String name, Cartridge cartridge, User user) throws
OpenshiftException;
- public Domain changeDomain(String domainName, ISSHPublicKey sshKey) throws
OpenshiftException;
+ public Domain changeDomain(String name, ISSHPublicKey sshKey, User user) throws
OpenshiftException;
- public Domain createDomain(String name, ISSHPublicKey sshKey) throws
OpenshiftException;
-
- public SSHKeyPair createKey(String passPhrase, String privateKeyPath, String
publicKeyPath) throws OpenshiftException;
-
- public SSHKeyPair loadKey(String privateKeyPath, String publicKeyPath) throws
OpenshiftException;
+ public Domain createDomain(String name, ISSHPublicKey sshKey, User user) throws
OpenshiftException;
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/ISSHPublicKey.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/ISSHPublicKey.java 2011-09-23
13:26:18 UTC (rev 34997)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/ISSHPublicKey.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -23,6 +23,7 @@
* comment)
* @throws OpenshiftException
*/
- public String getPublicKey() throws OpenshiftException;
-
+ public String getPublicKey() throws OpenshiftException ;
+
+ public void update(ISSHPublicKey sshPublicKey) throws OpenshiftException;
}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/IUser.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/IUser.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/IUser.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -0,0 +1,19 @@
+package org.jboss.ide.eclipse.as.openshift.core;
+
+import java.util.Collection;
+
+public interface IUser {
+
+ public abstract String getRhlogin();
+
+ public abstract String getPassword();
+
+ public abstract Domain getDomain() throws OpenshiftException;
+
+ public abstract ISSHPublicKey getSshKey() throws OpenshiftException;
+
+ public abstract Collection<Cartridge> getCartridges() throws OpenshiftException;
+
+ public abstract Collection<Application> getApplications() throws
OpenshiftException;
+
+}
\ No newline at end of file
Property changes on:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/IUser.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/SSHKeyPair.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/SSHKeyPair.java 2011-09-23
13:26:18 UTC (rev 34997)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/SSHKeyPair.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -101,4 +101,10 @@
return publicKeyPath;
}
+ @Override
+ public void update(ISSHPublicKey sshPublicKey) {
+ // do nothing, there's no sense to update this key since the public key
+ // misses the private key
+ }
+
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/SSHPublicKey.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/SSHPublicKey.java 2011-09-23
13:26:18 UTC (rev 34997)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/SSHPublicKey.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -21,7 +21,14 @@
this.publicKey = publicKey;
}
- public String getPublicKey() throws OpenshiftException {
+ public String getPublicKey() {
return publicKey;
}
+
+ void update(String publicKey) {
+ }
+
+ public void update(ISSHPublicKey sshPublicKey) throws OpenshiftException {
+ this.publicKey = sshPublicKey.getPublicKey();
+ }
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/User.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/User.java 2011-09-23
13:26:18 UTC (rev 34997)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/User.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -7,39 +7,169 @@
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ ******************************************************************************/
package org.jboss.ide.eclipse.as.openshift.core;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.jboss.ide.eclipse.as.openshift.core.internal.OpenshiftService;
+
/**
* @author André Dietisheim
*/
-public class User {
+public class User implements IUser {
private String rhlogin;
+ private String password;
private String uuid;
private ISSHPublicKey sshKey;
private Domain domain;
+ private UserInfo userInfo;
+ private List<Cartridge> cartridges;
+ private List<Application> applications = new ArrayList<Application>();
- public User(String rhlogin, String uuid, ISSHPublicKey sshKey, Domain domain) {
+ private OpenshiftService service;
+
+ public User(String rhlogin, String password) {
+ this(rhlogin, password, (ISSHPublicKey) null, new OpenshiftService());
+ }
+
+ public User(String rhlogin, String password, OpenshiftService service) {
+ this(rhlogin, password, (ISSHPublicKey) null, service);
+ }
+
+ public User(String rhlogin, String password, ISSHPublicKey sshKey, OpenshiftService
service) {
this.rhlogin = rhlogin;
- this.uuid = uuid;
+ this.password = password;
this.sshKey = sshKey;
- this.domain = domain;
+ this.service = service;
}
-
- public Domain getDomain() {
+
+ @Override
+ public Domain getDomain() throws OpenshiftException {
+ loadLazyValues();
return domain;
}
- public ISSHPublicKey getSshKey() {
+ @Override
+ public ISSHPublicKey getSshKey() throws OpenshiftException {
+ loadLazyValues();
return sshKey;
}
+ @Override
public String getRhlogin() {
return rhlogin;
}
- public String getUuid() {
+ @Override
+ public String getPassword() {
+ return password;
+ }
+
+ public String getUUID() throws OpenshiftException {
+ loadLazyValues();
return uuid;
}
+
+ @Override
+ public List<Cartridge> getCartridges() throws OpenshiftException {
+ if (cartridges == null) {
+ this.cartridges = service.getCartridges(this);
+ }
+ return Collections.unmodifiableList(cartridges);
+ }
+
+ @Override
+ public Collection<Application> getApplications() throws OpenshiftException {
+ loadLazyValues();
+ return Collections.unmodifiableList(applications);
+ }
+
+ public Application getApplicationByName(String name) throws OpenshiftException {
+ loadLazyValues();
+ return getApplicationByName(name, applications);
+ }
+
+ private Application getApplicationByName(String name, Collection<Application>
applications) {
+ Application matchingApplication = null;
+ for (Application application : applications) {
+ if (name.equals(application.getName())) {
+ matchingApplication = application;
+ }
+ }
+ return matchingApplication;
+ }
+
+ public void add(Application application) {
+ applications.add(application);
+ }
+
+ /**
+ * Loads the lazy values from the server if needed. Updates itself all
+ * referenced objects (applications, domain).
+ *
+ * @throws OpenshiftException
+ * if an error occurred while loading the values
+ */
+ void loadLazyValues() throws OpenshiftException {
+ if (userInfo == null) {
+ refresh();
+ }
+ }
+
+ public void refresh() throws OpenshiftException {
+ this.userInfo = service.getUserInfo(this);
+ update(userInfo);
+ }
+
+ private void update(UserInfo userInfo) throws OpenshiftException {
+ this.uuid = userInfo.getUuid();
+ updateDomain(userInfo);
+ updateSshPublicKey(userInfo);
+ update(userInfo.getApplicationInfos());
+ }
+
+ private void updateDomain(UserInfo userInfo) {
+ if (domain == null) {
+ this.domain = new Domain(userInfo.getNamespace(), userInfo.getRhcDomain(), this);
+ } else {
+ domain.update(userInfo);
+ }
+ }
+
+ private void updateSshPublicKey(UserInfo userInfo) throws OpenshiftException {
+ if (sshKey == null) {
+ sshKey = userInfo.getSshPublicKey();
+ } else {
+ sshKey.update(userInfo.getSshPublicKey());
+ }
+ }
+
+ private void update(List<ApplicationInfo> applicationInfos) {
+ for (ApplicationInfo applicationInfo : applicationInfos) {
+ Application application = getApplicationByName(applicationInfo.getName(),
applications);
+ if (application != null) {
+ application.update(applicationInfo);
+ } else {
+ applications.add(createApplication(applicationInfo));
+ }
+ }
+ }
+
+ private Application createApplication(ApplicationInfo applicationInfo) {
+ return new Application(applicationInfo.getName()
+ , applicationInfo.getUuid()
+ , applicationInfo.getCartridge()
+ , applicationInfo.getEmbedded()
+ , applicationInfo.getCreationTime()
+ , this, service);
+ }
+
+ public void setSshPublicKey(ISSHPublicKey key) {
+ this.sshKey = key;
+ }
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/UserInfo.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/UserInfo.java 2011-09-23
13:26:18 UTC (rev 34997)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/UserInfo.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -17,31 +17,55 @@
*/
public class UserInfo {
- private User user;
- private List<Application> applications;
+ private String rhLogin;
+ private String uuid;
+ private SSHPublicKey sshPublicKey;
+ private String rhcDomain;
+ private String namespace;
+ private List<ApplicationInfo> applicationInfos;
- public UserInfo(User user, List<Application> applications) {
- this.user = user;
- this.applications = applications;
+ public UserInfo(String rhLogin, String uuid, String sshPublicKey, String rhcDomain,
String namespace, List<ApplicationInfo> applicationInfos) {
+ this.rhLogin = rhLogin;
+ this.uuid = uuid;
+ this.sshPublicKey = new SSHPublicKey(sshPublicKey);
+ this.rhcDomain = rhcDomain;
+ this.namespace = namespace;
+ this.applicationInfos = applicationInfos;
}
- public User getUser() {
- return user;
+ public String getUuid() {
+ return uuid;
}
- public List<Application> getApplications() {
- return applications;
+ public SSHPublicKey getSshPublicKey() {
+ return sshPublicKey;
}
- public Application getApplicationByName(String applicationName) {
- Application matchingApplication = null;
- for (Application application : applications) {
- if (applicationName.equals(application.getName())) {
- matchingApplication = application;
+ public String getRhLogin() {
+ return rhLogin;
+ }
+
+ public String getNamespace() {
+ return namespace;
+ }
+
+ public List<ApplicationInfo> getApplicationInfos() {
+ return applicationInfos;
+ }
+
+ public ApplicationInfo getApplicationInfoByName(String name) {
+ ApplicationInfo matchingApplicationInfo = null;
+ for (ApplicationInfo applicationInfo : applicationInfos) {
+ if (name.equals(applicationInfo.getName())) {
+ matchingApplicationInfo = applicationInfo;
break;
}
}
- return matchingApplication;
+ return matchingApplicationInfo;
}
+
+ public String getRhcDomain() {
+ return rhcDomain;
+ }
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/OpenshiftService.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/OpenshiftService.java 2011-09-23
13:26:18 UTC (rev 34997)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/OpenshiftService.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -12,6 +12,7 @@
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.Collection;
import java.util.List;
import org.jboss.ide.eclipse.as.openshift.core.Application;
@@ -23,7 +24,7 @@
import org.jboss.ide.eclipse.as.openshift.core.InvalidCredentialsOpenshiftException;
import org.jboss.ide.eclipse.as.openshift.core.OpenshiftEndpointException;
import org.jboss.ide.eclipse.as.openshift.core.OpenshiftException;
-import org.jboss.ide.eclipse.as.openshift.core.SSHKeyPair;
+import org.jboss.ide.eclipse.as.openshift.core.User;
import org.jboss.ide.eclipse.as.openshift.core.UserInfo;
import org.jboss.ide.eclipse.as.openshift.core.internal.httpclient.HttpClientException;
import
org.jboss.ide.eclipse.as.openshift.core.internal.httpclient.UnauthorizedException;
@@ -55,48 +56,36 @@
private static final String BASE_URL = "https://openshift.redhat.com/broker";
- private String username;
- private String password;
-
- public OpenshiftService(String username, String password) {
- this.username = username;
- this.password = password;
- }
-
- public UserInfo getUserInfo() throws OpenshiftException {
- UserInfoRequest request = new UserInfoRequest(username, true);
+ public UserInfo getUserInfo(User user) throws OpenshiftException {
+ UserInfoRequest request = new UserInfoRequest(user.getRhlogin(), true);
String url = request.getUrlString(BASE_URL);
try {
String requestString = new UserInfoRequestJsonMarshaller().marshall(request);
- String openShiftRequestString = new OpenshiftEnvelopeFactory(password,
requestString).createString();
+ String openShiftRequestString = new OpenshiftEnvelopeFactory(user.getPassword(),
requestString)
+ .createString();
String responseString = createHttpClient(url).post(openShiftRequestString);
responseString = JsonSanitizer.sanitize(responseString);
OpenshiftResponse<UserInfo> response =
- new UserInfoResponseUnmarshaller(this).unmarshall(responseString);
+ new UserInfoResponseUnmarshaller().unmarshall(responseString);
return response.getOpenshiftObject();
} catch (MalformedURLException e) {
throw new OpenshiftEndpointException(
- url, e, "Could not get user info for user \"{0}\" at
\"{1}\"", username, url, e);
+ url, e, "Could not get user info for user \"{0}\" at
\"{1}\"", user.getRhlogin(), url, e);
} catch (HttpClientException e) {
throw new OpenshiftEndpointException(
- url, e, "Could not get user info for user \"{0}\" at
\"{1}\"", username, url, e);
+ url, e, "Could not get user info for user \"{0}\" at
\"{1}\"", user.getRhlogin(), url, e);
}
}
- /**
- * WARNING: the current server implementation returns invalid json.
- *
- * @see ListCartridgesResponseUnmarshaller
- * @see JsonSanitizer#sanitize(String)
- */
@Override
- public List<Cartridge> getCartridges() throws OpenshiftException {
- ListCartridgesRequest listCartridgesRequest = new ListCartridgesRequest(username,
true);
+ public List<Cartridge> getCartridges(User user) throws OpenshiftException {
+ ListCartridgesRequest listCartridgesRequest = new
ListCartridgesRequest(user.getRhlogin(), true);
String url = listCartridgesRequest.getUrlString(BASE_URL);
try {
String listCartridgesRequestString =
new ListCartridgesRequestJsonMarshaller().marshall(listCartridgesRequest);
- String request = new OpenshiftEnvelopeFactory(password,
listCartridgesRequestString).createString();
+ String request = new OpenshiftEnvelopeFactory(user.getPassword(),
listCartridgesRequestString)
+ .createString();
String listCatridgesReponse = createHttpClient(url).post(request);
listCatridgesReponse = JsonSanitizer.sanitize(listCatridgesReponse);
OpenshiftResponse<List<Cartridge>> response =
@@ -110,37 +99,27 @@
}
@Override
- public SSHKeyPair createKey(String passPhrase, String privateKeyPath, String
publicKeyPath) throws OpenshiftException {
- return SSHKeyPair.create(passPhrase, privateKeyPath, publicKeyPath);
+ public Domain createDomain(String name, ISSHPublicKey sshKey, User user) throws
OpenshiftException {
+ return requestDomainAction(new CreateDomainRequest(name, sshKey, user.getRhlogin(),
true), user);
}
@Override
- public SSHKeyPair loadKey(String privateKeyPath, String publicKeyPath) throws
OpenshiftException {
- return SSHKeyPair.load(privateKeyPath, publicKeyPath);
+ public Domain changeDomain(String newName, ISSHPublicKey sshKey, User user) throws
OpenshiftException {
+ return requestDomainAction(new ChangeDomainRequest(newName, sshKey, user.getRhlogin(),
true), user);
}
- @Override
- public Domain createDomain(String name, ISSHPublicKey sshKey) throws OpenshiftException
{
- return requestDomainAction(new CreateDomainRequest(name, sshKey, username, true));
- }
-
- @Override
- public Domain changeDomain(String newName, ISSHPublicKey sshKey) throws
OpenshiftException {
- return requestDomainAction(new ChangeDomainRequest(newName, sshKey, username, true));
- }
-
- protected Domain requestDomainAction(AbstractDomainRequest request) throws
OpenshiftException {
+ protected Domain requestDomainAction(AbstractDomainRequest request, User user) throws
OpenshiftException {
String url = request.getUrlString(BASE_URL);
try {
String requestString =
new OpenshiftEnvelopeFactory(
- password,
+ user.getPassword(),
new DomainRequestJsonMarshaller().marshall(request))
.createString();
String responseString = createHttpClient(url).post(requestString);
responseString = JsonSanitizer.sanitize(responseString);
OpenshiftResponse<Domain> response =
- new DomainResponseUnmarshaller(request.getName()).unmarshall(responseString);
+ new DomainResponseUnmarshaller(request.getName(), user).unmarshall(responseString);
return response.getOpenshiftObject();
} catch (MalformedURLException e) {
throw new OpenshiftEndpointException(url, e, "Could not list available cartridges
at \"{0}\"", url);
@@ -150,31 +129,33 @@
}
@Override
- public Application createApplication(String name, Cartridge cartridge) throws
OpenshiftException {
- return requestApplicationAction(new ApplicationRequest(name, cartridge,
ApplicationAction.CONFIGURE, username,
- true));
+ public Application createApplication(String name, Cartridge cartridge, User user) throws
OpenshiftException {
+ return requestApplicationAction(new ApplicationRequest(name, cartridge,
ApplicationAction.CONFIGURE,
+ user.getRhlogin(), true), user);
}
@Override
- public Application destroyApplication(String name, Cartridge cartridge) throws
OpenshiftException {
+ public Application destroyApplication(String name, Cartridge cartridge, User user)
throws OpenshiftException {
return requestApplicationAction(new ApplicationRequest(name, cartridge,
ApplicationAction.DECONFIGURE,
- username, true));
+ user.getRhlogin(), true), user);
}
@Override
- public Application startApplication(String name, Cartridge cartridge) throws
OpenshiftException {
- return requestApplicationAction(new ApplicationRequest(name, cartridge,
ApplicationAction.START, username, true));
+ public Application startApplication(String name, Cartridge cartridge, User user) throws
OpenshiftException {
+ return requestApplicationAction(new ApplicationRequest(name, cartridge,
ApplicationAction.START,
+ user.getRhlogin(), true), user);
}
@Override
- public Application restartApplication(String name, Cartridge cartridge) throws
OpenshiftException {
- return requestApplicationAction(new ApplicationRequest(name, cartridge,
ApplicationAction.RESTART, username,
- true));
+ public Application restartApplication(String name, Cartridge cartridge, User user)
throws OpenshiftException {
+ return requestApplicationAction(new ApplicationRequest(name, cartridge,
ApplicationAction.RESTART,
+ user.getRhlogin(), true), user);
}
@Override
- public Application stopApplication(String name, Cartridge cartridge) throws
OpenshiftException {
- return requestApplicationAction(new ApplicationRequest(name, cartridge,
ApplicationAction.STOP, username, true));
+ public Application stopApplication(String name, Cartridge cartridge, User user) throws
OpenshiftException {
+ return requestApplicationAction(new ApplicationRequest(name, cartridge,
ApplicationAction.STOP,
+ user.getRhlogin(), true), user);
}
/**
@@ -189,14 +170,14 @@
* ,"app_name","api"],"exit_code":0}
*/
@Override
- public String getStatus(String applicationName, Cartridge cartridge) throws
OpenshiftException {
- ApplicationRequest applicationRequest =
- new ApplicationRequest(applicationName, cartridge, ApplicationAction.STATUS,
username, true);
+ public String getStatus(String applicationName, Cartridge cartridge, User user) throws
OpenshiftException {
+ ApplicationRequest applicationRequest =
+ new ApplicationRequest(applicationName, cartridge, ApplicationAction.STATUS,
user.getRhlogin(), true);
String url = applicationRequest.getUrlString(BASE_URL);
try {
String applicationRequestString =
new ApplicationRequestJsonMarshaller().marshall(applicationRequest);
- String request = new OpenshiftEnvelopeFactory(password,
applicationRequestString).createString();
+ String request = new OpenshiftEnvelopeFactory(user.getPassword(),
applicationRequestString).createString();
String response = createHttpClient(url).post(request);
response = JsonSanitizer.sanitize(response);
@@ -211,8 +192,8 @@
throw new InvalidCredentialsOpenshiftException(
url, e,
"Could not {0} application \"{1}\" at \"{2}\": Invalid
credentials user \"{3}\", password \"{4}\"",
- applicationRequest.getAction().toHumanReadable(), applicationRequest.getName(), url,
username,
- password);
+ applicationRequest.getAction().toHumanReadable(), applicationRequest.getName(),
url,
+ user.getRhlogin(), user.getPassword());
} catch (HttpClientException e) {
throw new OpenshiftEndpointException(
url, e, "Could not {0} application \"{1}\" at
\"{2}\"",
@@ -220,18 +201,19 @@
}
}
- protected Application requestApplicationAction(ApplicationRequest applicationRequest)
throws OpenshiftException {
+ protected Application requestApplicationAction(ApplicationRequest applicationRequest,
User user)
+ throws OpenshiftException {
String url = applicationRequest.getUrlString(BASE_URL);
try {
String applicationRequestString =
new ApplicationRequestJsonMarshaller().marshall(applicationRequest);
- String request = new OpenshiftEnvelopeFactory(password,
applicationRequestString).createString();
+ String request = new OpenshiftEnvelopeFactory(user.getPassword(),
applicationRequestString).createString();
String response = createHttpClient(url).post(request);
response = JsonSanitizer.sanitize(response);
OpenshiftResponse<Application> openshiftResponse =
new ApplicationResponseUnmarshaller(applicationRequest.getName(),
- applicationRequest.getCartridge(), this).unmarshall(response);
+ applicationRequest.getCartridge(), user, this).unmarshall(response);
return openshiftResponse.getOpenshiftObject();
} catch (MalformedURLException e) {
throw new OpenshiftException(
@@ -241,8 +223,9 @@
throw new InvalidCredentialsOpenshiftException(
url, e,
"Could not {0} application \"{1}\" at \"{2}\": Invalid
credentials user \"{3}\", password \"{4}\"",
- applicationRequest.getAction().toHumanReadable(), applicationRequest.getName(), url,
username,
- password);
+ applicationRequest.getAction().toHumanReadable(), applicationRequest.getName(),
url,
+ user.getRhlogin(),
+ user.getPassword());
} catch (HttpClientException e) {
throw new OpenshiftEndpointException(
url, e, "Could not {0} application \"{1}\" at
\"{2}\"",
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/response/ApplicationResponseUnmarshaller.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/response/ApplicationResponseUnmarshaller.java 2011-09-23
13:26:18 UTC (rev 34997)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/response/ApplicationResponseUnmarshaller.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -14,24 +14,27 @@
import org.jboss.ide.eclipse.as.openshift.core.Application;
import org.jboss.ide.eclipse.as.openshift.core.Cartridge;
import org.jboss.ide.eclipse.as.openshift.core.IOpenshiftService;
+import org.jboss.ide.eclipse.as.openshift.core.User;
/**
* @author André Dietisheim
*/
public class ApplicationResponseUnmarshaller extends
AbstractOpenshiftJsonResponseUnmarshaller<Application> {
+ private User user;
private String applicationName;
private Cartridge cartridge;
private IOpenshiftService service;
- public ApplicationResponseUnmarshaller(String applicationName, Cartridge cartridge,
IOpenshiftService service) {
+ public ApplicationResponseUnmarshaller(String applicationName, Cartridge cartridge, User
user, IOpenshiftService service) {
this.applicationName = applicationName;
this.cartridge = cartridge;
+ this.user = user;
this.service = service;
}
@Override
protected Application createOpenshiftObject(ModelNode node) {
- return new Application(applicationName, cartridge, service);
+ return new Application(applicationName, cartridge, user, service);
}
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/response/DomainResponseUnmarshaller.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/response/DomainResponseUnmarshaller.java 2011-09-23
13:26:18 UTC (rev 34997)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/response/DomainResponseUnmarshaller.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -12,6 +12,7 @@
import org.jboss.dmr.ModelNode;
import org.jboss.ide.eclipse.as.openshift.core.Domain;
+import org.jboss.ide.eclipse.as.openshift.core.User;
/**
* @author André Dietisheim
@@ -19,13 +20,15 @@
public class DomainResponseUnmarshaller extends
AbstractOpenshiftJsonResponseUnmarshaller<Domain> {
private String domainName;
-
- public DomainResponseUnmarshaller(String domainName) {
+ private User user;
+
+ public DomainResponseUnmarshaller(String domainName, User user) {
this.domainName = domainName;
+ this.user = user;
}
@Override
protected Domain createOpenshiftObject(ModelNode node) {
- return new Domain(domainName);
+ return new Domain(domainName, user);
}
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/response/UserInfoResponseUnmarshaller.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/response/UserInfoResponseUnmarshaller.java 2011-09-23
13:26:18 UTC (rev 34997)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/internal/response/UserInfoResponseUnmarshaller.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -17,14 +17,9 @@
import javax.xml.datatype.DatatypeConfigurationException;
import org.jboss.dmr.ModelNode;
-import org.jboss.ide.eclipse.as.openshift.core.Application;
+import org.jboss.ide.eclipse.as.openshift.core.ApplicationInfo;
import org.jboss.ide.eclipse.as.openshift.core.Cartridge;
-import org.jboss.ide.eclipse.as.openshift.core.Domain;
import org.jboss.ide.eclipse.as.openshift.core.IOpenshiftJsonConstants;
-import org.jboss.ide.eclipse.as.openshift.core.IOpenshiftService;
-import org.jboss.ide.eclipse.as.openshift.core.ISSHPublicKey;
-import org.jboss.ide.eclipse.as.openshift.core.SSHPublicKey;
-import org.jboss.ide.eclipse.as.openshift.core.User;
import org.jboss.ide.eclipse.as.openshift.core.UserInfo;
/**
@@ -32,12 +27,6 @@
*/
public class UserInfoResponseUnmarshaller extends
AbstractOpenshiftJsonResponseUnmarshaller<UserInfo> {
- private IOpenshiftService service;
-
- public UserInfoResponseUnmarshaller(IOpenshiftService service) {
- this.service = service;
- }
-
@Override
protected UserInfo createOpenshiftObject(ModelNode node) throws
DatatypeConfigurationException {
ModelNode dataNode = node.get(IOpenshiftJsonConstants.PROPERTY_DATA);
@@ -50,47 +39,34 @@
return null;
}
- ISSHPublicKey sshKey = createSSHKey(userInfoNode);
- User user = createUser(userInfoNode, sshKey, createDomain(userInfoNode));
- List<Application> applications =
createApplications(dataNode.get(IOpenshiftJsonConstants.PROPERTY_APP_INFO), user);
+ String sshPublicKey = getString(IOpenshiftJsonConstants.PROPERTY_SSH_KEY,
userInfoNode);
+ String rhlogin = getString(IOpenshiftJsonConstants.PROPERTY_RHLOGIN, userInfoNode);
+ String uuid = getString(IOpenshiftJsonConstants.PROPERTY_UUID, userInfoNode);
+ String namespace = getString(IOpenshiftJsonConstants.PROPERTY_NAMESPACE,
userInfoNode);
+ String rhcDomain = getString(IOpenshiftJsonConstants.PROPERTY_RHC_DOMAIN,
userInfoNode);
- return new UserInfo(user, applications);
- }
+ List<ApplicationInfo> applicationInfos =
createApplicationInfos(dataNode.get(IOpenshiftJsonConstants.PROPERTY_APP_INFO));
- private ISSHPublicKey createSSHKey(ModelNode userInfoNode) {
- String sshPublicKey = getString(IOpenshiftJsonConstants.PROPERTY_SSH_KEY,
userInfoNode);
- return new SSHPublicKey(sshPublicKey);
+ return new UserInfo(rhlogin, uuid, sshPublicKey, rhcDomain, namespace,
applicationInfos);
}
- private List<Application> createApplications(ModelNode appInfoNode, User user)
throws DatatypeConfigurationException {
- List<Application> applications = new ArrayList<Application>();
+ private List<ApplicationInfo> createApplicationInfos(ModelNode appInfoNode) throws
DatatypeConfigurationException {
+ List<ApplicationInfo> applicationInfos = new ArrayList<ApplicationInfo>();
if (!isSet(appInfoNode)) {
- return applications;
+ return applicationInfos;
}
for (String name : appInfoNode.keys()) {
- applications.add(createApplication(name, appInfoNode.get(name), user));
+ applicationInfos.add(createApplicationInfo(name, appInfoNode.get(name)));
}
- return applications;
+ return applicationInfos;
}
- private Application createApplication(String name, ModelNode appNode, User user) throws
DatatypeConfigurationException {
- String embedded = getString(IOpenshiftJsonConstants.PROPERTY_EMBEDDED, appNode);
+ private ApplicationInfo createApplicationInfo(String name, ModelNode appNode) throws
DatatypeConfigurationException {
String uuid = getString(IOpenshiftJsonConstants.PROPERTY_UUID, appNode);
+ String embedded = getString(IOpenshiftJsonConstants.PROPERTY_EMBEDDED, appNode);
Cartridge cartrdige = new
Cartridge(getString(IOpenshiftJsonConstants.PROPERTY_FRAMEWORK, appNode));
Date creationTime = getDate(IOpenshiftJsonConstants.PROPERTY_CREATION_TIME, appNode);
- return new Application(name, uuid, cartrdige, embedded, creationTime, user, service);
+ return new ApplicationInfo(name, uuid, embedded, cartrdige, creationTime);
}
-
- private User createUser(ModelNode userInfoNode, ISSHPublicKey sshKey, Domain domain) {
- String rhlogin = getString(IOpenshiftJsonConstants.PROPERTY_RHLOGIN, userInfoNode);
- String uuid = getString(IOpenshiftJsonConstants.PROPERTY_UUID, userInfoNode);
- return new User(rhlogin, uuid, sshKey, domain);
- }
-
- private Domain createDomain(ModelNode userInfoNode) {
- String namespace = getString(IOpenshiftJsonConstants.PROPERTY_NAMESPACE,
userInfoNode);
- String rhcDomain = getString(IOpenshiftJsonConstants.PROPERTY_RHC_DOMAIN,
userInfoNode);
- return new Domain(namespace, rhcDomain);
- }
}
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/ApplicationIntegrationTest.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/ApplicationIntegrationTest.java 2011-09-23
13:26:18 UTC (rev 34997)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/ApplicationIntegrationTest.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -18,6 +18,7 @@
import org.jboss.ide.eclipse.as.openshift.core.IOpenshiftService;
import org.jboss.ide.eclipse.as.openshift.core.InvalidCredentialsOpenshiftException;
import org.jboss.ide.eclipse.as.openshift.core.OpenshiftException;
+import org.jboss.ide.eclipse.as.openshift.core.User;
import org.jboss.ide.eclipse.as.openshift.core.internal.OpenshiftService;
import org.junit.Before;
import org.junit.Ignore;
@@ -28,23 +29,26 @@
*/
public class ApplicationIntegrationTest {
- private IOpenshiftService openshiftService;
+ private IOpenshiftService service;
private IOpenshiftService invalidCredentialsOpenshiftService;
- private static final String USERNAME = "toolsjboss(a)gmail.com";
+ private static final String RHLOGIN = "toolsjboss(a)gmail.com";
private static final String PASSWORD = "1q2w3e";
-
+ private User user;
+ private User invalidUser;
+
@Ignore
@Before
public void setUp() {
- this.openshiftService = new OpenshiftService(USERNAME, PASSWORD);
- this.invalidCredentialsOpenshiftService = new OpenshiftService(USERNAME,
"bogus");
+ this.service = new OpenshiftService();
+ this.user = new User(RHLOGIN, PASSWORD);
+ this.invalidUser = new User(RHLOGIN, "bogusPassword");
}
@Ignore
@Test(expected = InvalidCredentialsOpenshiftException.class)
public void createApplicationWithInvalidCredentialsThrowsException() throws Exception {
- invalidCredentialsOpenshiftService.createApplication(createRandomApplicationName(),
Cartridge.JBOSSAS_7);
+ service.createApplication(createRandomApplicationName(), Cartridge.JBOSSAS_7,
invalidUser);
}
@Test
@@ -52,12 +56,12 @@
String applicationName = createRandomApplicationName();
try {
Cartridge cartridge = Cartridge.JBOSSAS_7;
- Application application = openshiftService.createApplication(applicationName,
cartridge);
+ Application application = service.createApplication(applicationName, cartridge,
user);
assertNotNull(application);
assertEquals(applicationName, application.getName());
assertEquals(cartridge, application.getCartridge());
} finally {
- silentlyDestroyAS7Application(applicationName, openshiftService);
+ silentlyDestroyAS7Application(applicationName, service);
}
}
@@ -65,8 +69,8 @@
@Test
public void canDestroyApplication() throws Exception {
String applicationName = createRandomApplicationName();
- openshiftService.createApplication(applicationName, Cartridge.JBOSSAS_7);
- openshiftService.destroyApplication(applicationName, Cartridge.JBOSSAS_7);
+ service.createApplication(applicationName, Cartridge.JBOSSAS_7, user);
+ service.destroyApplication(applicationName, Cartridge.JBOSSAS_7, user);
}
@Ignore
@@ -74,10 +78,10 @@
public void createDuplicateApplicationThrowsException() throws Exception {
String applicationName = createRandomApplicationName();
try {
- openshiftService.createApplication(applicationName, Cartridge.JBOSSAS_7);
- openshiftService.createApplication(applicationName, Cartridge.JBOSSAS_7);
+ service.createApplication(applicationName, Cartridge.JBOSSAS_7, user);
+ service.createApplication(applicationName, Cartridge.JBOSSAS_7, user);
} finally {
- silentlyDestroyAS7Application(applicationName, openshiftService);
+ silentlyDestroyAS7Application(applicationName, service);
}
}
@@ -86,10 +90,10 @@
public void canStopApplication() throws Exception {
String applicationName = createRandomApplicationName();
try {
- openshiftService.createApplication(applicationName, Cartridge.JBOSSAS_7);
- openshiftService.stopApplication(applicationName, Cartridge.JBOSSAS_7);
+ service.createApplication(applicationName, Cartridge.JBOSSAS_7, user);
+ service.stopApplication(applicationName, Cartridge.JBOSSAS_7, user);
} finally {
- silentlyDestroyAS7Application(applicationName, openshiftService);
+ silentlyDestroyAS7Application(applicationName, service);
}
}
@@ -98,11 +102,11 @@
public void canStartStoppedApplication() throws Exception {
String applicationName = createRandomApplicationName();
try {
- openshiftService.createApplication(applicationName, Cartridge.JBOSSAS_7);
- openshiftService.stopApplication(applicationName, Cartridge.JBOSSAS_7);
- openshiftService.startApplication(applicationName, Cartridge.JBOSSAS_7);
+ service.createApplication(applicationName, Cartridge.JBOSSAS_7, user);
+ service.stopApplication(applicationName, Cartridge.JBOSSAS_7, user);
+ service.startApplication(applicationName, Cartridge.JBOSSAS_7, user);
} finally {
- silentlyDestroyAS7Application(applicationName, openshiftService);
+ silentlyDestroyAS7Application(applicationName, service);
}
}
@@ -117,10 +121,10 @@
* @link
*
https://github.com/openshift/os-client-tools/blob/master/express/doc/API
*/
- openshiftService.createApplication(applicationName, Cartridge.JBOSSAS_7);
- openshiftService.startApplication(applicationName, Cartridge.JBOSSAS_7);
+ service.createApplication(applicationName, Cartridge.JBOSSAS_7, user);
+ service.startApplication(applicationName, Cartridge.JBOSSAS_7, user);
} finally {
- silentlyDestroyAS7Application(applicationName, openshiftService);
+ silentlyDestroyAS7Application(applicationName, service);
}
}
@@ -135,11 +139,11 @@
* @link
*
https://github.com/openshift/os-client-tools/blob/master/express/doc/API
*/
- openshiftService.createApplication(applicationName, Cartridge.JBOSSAS_7);
- openshiftService.stopApplication(applicationName, Cartridge.JBOSSAS_7);
- openshiftService.stopApplication(applicationName, Cartridge.JBOSSAS_7);
+ service.createApplication(applicationName, Cartridge.JBOSSAS_7, user);
+ service.stopApplication(applicationName, Cartridge.JBOSSAS_7, user);
+ service.stopApplication(applicationName, Cartridge.JBOSSAS_7, user);
} finally {
- silentlyDestroyAS7Application(applicationName, openshiftService);
+ silentlyDestroyAS7Application(applicationName, service);
}
}
@@ -154,10 +158,10 @@
* @link
*
https://github.com/openshift/os-client-tools/blob/master/express/doc/API
*/
- openshiftService.createApplication(applicationName, Cartridge.JBOSSAS_7);
- openshiftService.restartApplication(applicationName, Cartridge.JBOSSAS_7);
+ service.createApplication(applicationName, Cartridge.JBOSSAS_7, user);
+ service.restartApplication(applicationName, Cartridge.JBOSSAS_7, user);
} finally {
- silentlyDestroyAS7Application(applicationName, openshiftService);
+ silentlyDestroyAS7Application(applicationName, service);
}
}
@@ -165,11 +169,11 @@
public void canGetStatus() throws Exception {
String applicationName = createRandomApplicationName();
try {
- Application application = openshiftService.createApplication(applicationName,
Cartridge.JBOSSAS_7);
- String applicationStatus = openshiftService.getStatus(application.getName(),
application.getCartridge());
+ Application application = service.createApplication(applicationName,
Cartridge.JBOSSAS_7, user);
+ String applicationStatus = service.getStatus(application.getName(),
application.getCartridge(), user);
assertNotNull(applicationStatus);
} finally {
- silentlyDestroyAS7Application(applicationName, openshiftService);
+ silentlyDestroyAS7Application(applicationName, service);
}
}
@@ -178,12 +182,12 @@
public void getStatusReturnsTheWholeLog() throws Exception {
String applicationName = createRandomApplicationName();
try {
- Application application = openshiftService.createApplication(applicationName,
Cartridge.JBOSSAS_7);
- String applicationStatus = openshiftService.getStatus(application.getName(),
application.getCartridge());
- String applicationStatus2 = openshiftService.getStatus(application.getName(),
application.getCartridge());
+ Application application = service.createApplication(applicationName,
Cartridge.JBOSSAS_7, user);
+ String applicationStatus = service.getStatus(application.getName(),
application.getCartridge(), user);
+ String applicationStatus2 = service.getStatus(application.getName(),
application.getCartridge(), user);
assertEquals(applicationStatus, applicationStatus2);
} finally {
- silentlyDestroyAS7Application(applicationName, openshiftService);
+ silentlyDestroyAS7Application(applicationName, service);
}
}
@@ -193,7 +197,7 @@
private void silentlyDestroyAS7Application(String name, IOpenshiftService service) {
try {
- service.destroyApplication(name, Cartridge.JBOSSAS_7);
+ service.destroyApplication(name, Cartridge.JBOSSAS_7, user);
} catch (OpenshiftException e) {
e.printStackTrace();
}
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/ApplicationTest.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/ApplicationTest.java 2011-09-23
13:26:18 UTC (rev 34997)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/ApplicationTest.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -19,9 +19,9 @@
import java.util.Arrays;
import org.jboss.ide.eclipse.as.openshift.core.Application;
+import org.jboss.ide.eclipse.as.openshift.core.ApplicationInfo;
import org.jboss.ide.eclipse.as.openshift.core.ApplicationLogReader;
import org.jboss.ide.eclipse.as.openshift.core.Cartridge;
-import org.jboss.ide.eclipse.as.openshift.core.Domain;
import org.jboss.ide.eclipse.as.openshift.core.IOpenshiftService;
import org.jboss.ide.eclipse.as.openshift.core.OpenshiftException;
import org.jboss.ide.eclipse.as.openshift.core.User;
@@ -43,28 +43,28 @@
*/
public class ApplicationTest {
- private static final String USERNAME = "toolsjboss(a)gmail.com";
- private static final String PASSWORD = "1q2w3e";
+ private User user = new User(ApplicationResponseFake.RHLOGIN,
ApplicationResponseFake.PASSWORD, new NoopOpenshiftServiceFake());
@Test
public void canMarshallApplicationCreateRequest() throws Exception {
String expectedRequestString =
"password="
- + PASSWORD
+ + URLEncoder.encode(ApplicationResponseFake.PASSWORD, "UTF-8")
+ "&json_data=%7B"
+ "%22rhlogin%22+%3A+%22"
- + URLEncoder.encode(USERNAME, "UTF-8")
+ + URLEncoder.encode(ApplicationResponseFake.RHLOGIN, "UTF-8")
+ "%22"
+ "%2C+%22debug%22+%3A+%22true%22"
+ "%2C+%22cartridge%22+%3A+%22jbossas-7.0%22"
- + "%2C+%22action%22+%3A+%22configure%22"
- + "%2C+%22app_name%22+%3A+%22test-application%22"
+ + "%2C+%22action%22+%3A+%22"
+ + "configure"
+ + "%22%2C+%22app_name%22+%3A+%22test-application%22"
+ "%7D";
String createApplicationRequest = new ApplicationRequestJsonMarshaller().marshall(
new ApplicationRequest(
- "test-application", Cartridge.JBOSSAS_7, ApplicationAction.CONFIGURE,
USERNAME, true));
- String effectiveRequest = new OpenshiftEnvelopeFactory(PASSWORD,
createApplicationRequest).createString();
+ "test-application", Cartridge.JBOSSAS_7, ApplicationAction.CONFIGURE,
ApplicationResponseFake.RHLOGIN, true));
+ String effectiveRequest = new
OpenshiftEnvelopeFactory(ApplicationResponseFake.PASSWORD,
createApplicationRequest).createString();
assertEquals(expectedRequestString, effectiveRequest);
}
@@ -73,20 +73,21 @@
public void canMarshallApplicationDestroyRequest() throws Exception {
String expectedRequestString =
"password="
- + PASSWORD
+ + URLEncoder.encode(ApplicationResponseFake.PASSWORD, "UTF-8")
+ "&json_data=%7B"
+ "%22rhlogin%22+%3A+"
- + "%22" + URLEncoder.encode(USERNAME, "UTF-8") +
"%22"
+ + "%22" + URLEncoder.encode(ApplicationResponseFake.RHLOGIN,
"UTF-8") + "%22"
+ "%2C+%22debug%22+%3A+%22true%22"
+ "%2C+%22cartridge%22+%3A+%22jbossas-7.0%22"
- + "%2C+%22action%22+%3A+%22deconfigure%22"
- + "%2C+%22app_name%22+%3A+%22test-application%22"
+ + "%2C+%22action%22+%3A+%22"
+ + "deconfigure"
+ + "%22%2C+%22app_name%22+%3A+%22test-application%22"
+ "%7D";
String createApplicationRequest = new ApplicationRequestJsonMarshaller().marshall(
new ApplicationRequest(
- "test-application", Cartridge.JBOSSAS_7, ApplicationAction.DECONFIGURE,
USERNAME, true));
- String effectiveRequest = new OpenshiftEnvelopeFactory(PASSWORD,
createApplicationRequest).createString();
+ "test-application", Cartridge.JBOSSAS_7, ApplicationAction.DECONFIGURE,
ApplicationResponseFake.RHLOGIN, true));
+ String effectiveRequest = new
OpenshiftEnvelopeFactory(ApplicationResponseFake.PASSWORD,
createApplicationRequest).createString();
assertEquals(expectedRequestString, effectiveRequest);
}
@@ -97,7 +98,7 @@
OpenshiftResponse<Application> openshiftResponse =
new ApplicationResponseUnmarshaller(
ApplicationResponseFake.APPLICATION_NAME,
ApplicationResponseFake.APPLICATION_CARTRIDGE,
- new NoopOpenshiftServiceFake())
+ user, new NoopOpenshiftServiceFake())
.unmarshall(response);
Application application = openshiftResponse.getOpenshiftObject();
assertNotNull(application);
@@ -110,29 +111,26 @@
String response = JsonSanitizer.sanitize(ApplicationResponseFake.appResponse);
IOpenshiftService service = new NoopOpenshiftServiceFake() {
@Override
- public UserInfo getUserInfo() throws OpenshiftException {
- Domain domain =
- new Domain("adietish", "openshift.redhat.com");
- User user = new User(
- ApplicationResponseFake.USERNAME,
- "1234567890abcdef",
- null,
- domain);
- Application application = new Application(
+ public UserInfo getUserInfo(User user) throws OpenshiftException {
+ ApplicationInfo applicationInfo = new ApplicationInfo(
ApplicationResponseFake.APPLICATION_NAME,
ApplicationResponseFake.APPLICATION_UUID,
- ApplicationResponseFake.APPLICATION_CARTRIDGE,
ApplicationResponseFake.APPLICATION_EMBEDDED,
- ApplicationResponseFake.APPLICATION_CREATIONTIME,
- user,
- this);
- return new UserInfo(user, Arrays.asList(new Application[] { application }));
+ ApplicationResponseFake.APPLICATION_CARTRIDGE,
+ ApplicationResponseFake.APPLICATION_CREATIONTIME);
+ return new UserInfo(
+ ApplicationResponseFake.RHLOGIN,
+ ApplicationResponseFake.UUID,
+ ApplicationResponseFake.SSHPUBLICKEY,
+ ApplicationResponseFake.RHC_DOMAIN,
+ ApplicationResponseFake.NAMESPACE,
+ Arrays.asList(new ApplicationInfo[] { applicationInfo }));
}
};
OpenshiftResponse<Application> openshiftResponse =
new ApplicationResponseUnmarshaller(
ApplicationResponseFake.APPLICATION_NAME,
ApplicationResponseFake.APPLICATION_CARTRIDGE,
- service)
+ user, service)
.unmarshall(response);
Application application = openshiftResponse.getOpenshiftObject();
assertNotNull(application);
@@ -155,15 +153,15 @@
IOpenshiftService service = new NoopOpenshiftServiceFake() {
@Override
- public String getStatus(String applicationName, Cartridge cartridge) throws
OpenshiftException {
+ public String getStatus(String applicationName, Cartridge cartridge, User user) throws
OpenshiftException {
return ApplicationResponseFake.tail;
}
};
Application application =
new Application(ApplicationResponseFake.APPLICATION_NAME,
- ApplicationResponseFake.APPLICATION_CARTRIDGE, service);
- ApplicationLogReader reader = new ApplicationLogReader(application, service);
+ ApplicationResponseFake.APPLICATION_CARTRIDGE, user, service);
+ ApplicationLogReader reader = new ApplicationLogReader(application, user, service);
int toMatchIndex = 0;
for (int character = -1; (character = reader.read()) != -1;) {
Added:
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/CartridgeTest.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/CartridgeTest.java
(rev 0)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/CartridgeTest.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * 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 org.jboss.ide.eclipse.as.openshift.test.internal.core;
+
+import static
org.jboss.ide.eclipse.as.openshift.test.internal.core.utils.CartridgeAsserts.assertThatContainsCartridge;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.List;
+
+import org.jboss.ide.eclipse.as.openshift.core.Cartridge;
+import org.jboss.ide.eclipse.as.openshift.core.OpenshiftException;
+import org.jboss.ide.eclipse.as.openshift.core.internal.response.JsonSanitizer;
+import
org.jboss.ide.eclipse.as.openshift.core.internal.response.ListCartridgesResponseUnmarshaller;
+import org.jboss.ide.eclipse.as.openshift.core.internal.response.OpenshiftResponse;
+import
org.jboss.ide.eclipse.as.openshift.test.internal.core.fakes.CartridgeResponseFake;
+import org.junit.Test;
+
+/**
+ * @author André Dietisheim
+ */
+public class CartridgeTest {
+
+ @Test
+ public void canUnmarshallApplicationResponse() throws OpenshiftException {
+ String response = JsonSanitizer.sanitize(CartridgeResponseFake.RESPONSE);
+ OpenshiftResponse<List<Cartridge>> openshiftResponse =
+ new ListCartridgesResponseUnmarshaller().unmarshall(response);
+ List<Cartridge> cartridges = openshiftResponse.getOpenshiftObject();
+ assertNotNull(cartridges);
+ assertThatContainsCartridge(CartridgeResponseFake.CARTRIDGE_JBOSSAS70, cartridges);
+ assertThatContainsCartridge(CartridgeResponseFake.CARTRIDGE_PERL5, cartridges);
+ assertThatContainsCartridge(CartridgeResponseFake.CARTRIDGE_PHP53, cartridges);
+ assertThatContainsCartridge(CartridgeResponseFake.CARTRIDGE_RACK11, cartridges);
+ assertThatContainsCartridge(CartridgeResponseFake.CARTRIDGE_WSGI32, cartridges);
+ }
+}
Property changes on:
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/CartridgeTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/CartridgesIntegrationTest.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/CartridgesIntegrationTest.java 2011-09-23
13:26:18 UTC (rev 34997)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/CartridgesIntegrationTest.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -6,6 +6,7 @@
import java.util.List;
import org.jboss.ide.eclipse.as.openshift.core.Cartridge;
+import org.jboss.ide.eclipse.as.openshift.core.User;
import org.jboss.ide.eclipse.as.openshift.core.internal.OpenshiftService;
import org.junit.Before;
import org.junit.Ignore;
@@ -15,18 +16,21 @@
private OpenshiftService openshiftService;
- private static final String USERNAME = "toolsjboss(a)gmail.com";
+ private static final String RHLOGIN = "toolsjboss(a)gmail.com";
private static final String PASSWORD = "1q2w3e";
-
+
+ private User user;
+
@Before
public void setUp() {
- this.openshiftService = new OpenshiftService(USERNAME, PASSWORD);
+ this.openshiftService = new OpenshiftService();
+ this.user = new User(RHLOGIN, PASSWORD);
}
@Ignore
@Test
public void canRequestListCartridges() throws Exception {
- List<Cartridge> cartridges = openshiftService.getCartridges();
+ List<Cartridge> cartridges = openshiftService.getCartridges(user);
assertNotNull(cartridges);
assertTrue(cartridges.size() > 0);
}
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/DomainIntegrationTest.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/DomainIntegrationTest.java 2011-09-23
13:26:18 UTC (rev 34997)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/DomainIntegrationTest.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -15,6 +15,7 @@
import org.jboss.ide.eclipse.as.openshift.core.Domain;
import org.jboss.ide.eclipse.as.openshift.core.SSHKeyPair;
+import org.jboss.ide.eclipse.as.openshift.core.User;
import org.jboss.ide.eclipse.as.openshift.core.internal.OpenshiftService;
import org.jboss.ide.eclipse.as.openshift.test.internal.core.fakes.TestSSHKey;
import org.junit.Before;
@@ -24,12 +25,12 @@
private OpenshiftService openshiftService;
- private static final String USERNAME = "toolsjboss(a)gmail.com";
+ private static final String RHLOGIN = "toolsjboss(a)gmail.com";
private static final String PASSWORD = "1q2w3e";
@Before
public void setUp() {
- this.openshiftService = new OpenshiftService(USERNAME, PASSWORD);
+ this.openshiftService = new OpenshiftService();
}
@Test
@@ -37,7 +38,8 @@
String domainName = createRandomString();
SSHKeyPair sshKey = TestSSHKey.create();
- Domain domain = openshiftService.createDomain(domainName, sshKey);
+ User user = new User(RHLOGIN, PASSWORD);
+ Domain domain = openshiftService.createDomain(domainName, sshKey, user);
assertNotNull(domain);
assertEquals(domainName, domain.getNamespace());
@@ -48,7 +50,8 @@
String domainName = createRandomString();
SSHKeyPair sshKey = TestSSHKey.create();
- Domain domain = openshiftService.changeDomain(domainName, sshKey);
+ User user = new User(RHLOGIN, PASSWORD);
+ Domain domain = openshiftService.changeDomain(domainName, sshKey, user);
assertNotNull(domain);
assertEquals(domainName, domain.getNamespace());
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/DomainTest.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/DomainTest.java 2011-09-23
13:26:18 UTC (rev 34997)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/DomainTest.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -20,6 +20,7 @@
import org.jboss.ide.eclipse.as.openshift.core.Domain;
import org.jboss.ide.eclipse.as.openshift.core.OpenshiftException;
import org.jboss.ide.eclipse.as.openshift.core.SSHKeyPair;
+import org.jboss.ide.eclipse.as.openshift.core.User;
import org.jboss.ide.eclipse.as.openshift.core.internal.request.ChangeDomainRequest;
import org.jboss.ide.eclipse.as.openshift.core.internal.request.CreateDomainRequest;
import
org.jboss.ide.eclipse.as.openshift.core.internal.request.OpenshiftEnvelopeFactory;
@@ -27,6 +28,7 @@
import
org.jboss.ide.eclipse.as.openshift.core.internal.response.DomainResponseUnmarshaller;
import org.jboss.ide.eclipse.as.openshift.core.internal.response.JsonSanitizer;
import org.jboss.ide.eclipse.as.openshift.core.internal.response.OpenshiftResponse;
+import
org.jboss.ide.eclipse.as.openshift.test.internal.core.fakes.NoopOpenshiftServiceFake;
import org.jboss.ide.eclipse.as.openshift.test.internal.core.fakes.TestSSHKey;
import org.junit.Test;
@@ -35,17 +37,17 @@
*/
public class DomainTest {
- private static final String USERNAME = "toolsjboss(a)gmail.com";
+ private static final String RHLOGIN = "toolsjboss(a)gmail.com";
private static final String PASSWORD = "1q2w3e";
private static final String UUID = "0c82860dae904a4d87f8e5d87a5af840";
@Test
public void canMarshallDomainCreateRequest() throws IOException, OpenshiftException {
SSHKeyPair sshKey = TestSSHKey.create();
- String expectedRequestString = createDomainRequestString(PASSWORD, USERNAME, true,
"myDomain", false,
+ String expectedRequestString = createDomainRequestString(PASSWORD, RHLOGIN, true,
"myDomain", false,
sshKey.getPublicKey());
- CreateDomainRequest request = new CreateDomainRequest("myDomain", sshKey,
USERNAME, true);
+ CreateDomainRequest request = new CreateDomainRequest("myDomain", sshKey,
RHLOGIN, true);
String requestString =
new OpenshiftEnvelopeFactory(
PASSWORD,
@@ -57,10 +59,11 @@
@Test
public void canUnmarshallDomainCreateResponse() throws IOException, OpenshiftException
{
String domainName = "myDomain";
- String responseString = createDomainResponseString(USERNAME, UUID);
+ String responseString = createDomainResponseString(RHLOGIN, UUID);
responseString = JsonSanitizer.sanitize(responseString);
- OpenshiftResponse<Domain> response = new
DomainResponseUnmarshaller(domainName).unmarshall(responseString);
+ User user = new User(RHLOGIN, PASSWORD, new NoopOpenshiftServiceFake());
+ OpenshiftResponse<Domain> response = new DomainResponseUnmarshaller(domainName,
user).unmarshall(responseString);
assertNotNull(response);
Domain domain = response.getOpenshiftObject();
@@ -70,10 +73,10 @@
@Test
public void canMarshallDomainAlterRequest() throws IOException, OpenshiftException {
SSHKeyPair sshKey = TestSSHKey.create();
- String expectedRequestString = createDomainRequestString(PASSWORD, USERNAME, true,
"myDomain", true,
+ String expectedRequestString = createDomainRequestString(PASSWORD, RHLOGIN, true,
"myDomain", true,
sshKey.getPublicKey());
- ChangeDomainRequest request = new ChangeDomainRequest("myDomain", sshKey,
USERNAME, true);
+ ChangeDomainRequest request = new ChangeDomainRequest("myDomain", sshKey,
RHLOGIN, true);
String requestString =
new OpenshiftEnvelopeFactory(
PASSWORD,
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/ListCartridgesIntegrationTest.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/ListCartridgesIntegrationTest.java 2011-09-23
13:26:18 UTC (rev 34997)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/ListCartridgesIntegrationTest.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -10,13 +10,14 @@
******************************************************************************/
package org.jboss.ide.eclipse.as.openshift.test.internal.core;
+import static
org.jboss.ide.eclipse.as.openshift.test.internal.core.utils.CartridgeAsserts.assertThatContainsCartridge;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static
org.jboss.ide.eclipse.as.openshift.test.internal.core.utils.CartridgeAsserts.assertThatContainsCartridge;
import java.util.List;
import org.jboss.ide.eclipse.as.openshift.core.Cartridge;
+import org.jboss.ide.eclipse.as.openshift.core.User;
import org.jboss.ide.eclipse.as.openshift.core.internal.OpenshiftService;
import org.junit.Before;
import org.junit.Test;
@@ -33,12 +34,12 @@
@Before
public void setUp() {
- this.openshiftService = new OpenshiftService(USERNAME, PASSWORD);
+ this.openshiftService = new OpenshiftService();
}
@Test
public void canListCartridges() throws Exception {
- List<Cartridge> cartridges = openshiftService.getCartridges();
+ List<Cartridge> cartridges = openshiftService.getCartridges(new User(USERNAME,
PASSWORD));
assertNotNull(cartridges);
assertTrue(cartridges.size() > 0);
assertThatContainsCartridge("jbossas-7.0", cartridges);
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/OpenshiftTestSuite.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/OpenshiftTestSuite.java 2011-09-23
13:26:18 UTC (rev 34997)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/OpenshiftTestSuite.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -20,6 +20,8 @@
ListCartridgesTest.class,
DomainTest.class,
UserInfoTest.class,
+ UserTest.class,
+ CartridgeTest.class,
SSHKeyTest.class
})
/**
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/UserInfoIntegrationTest.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/UserInfoIntegrationTest.java 2011-09-23
13:26:18 UTC (rev 34997)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/UserInfoIntegrationTest.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -15,7 +15,7 @@
import java.util.List;
-import org.jboss.ide.eclipse.as.openshift.core.Application;
+import org.jboss.ide.eclipse.as.openshift.core.ApplicationInfo;
import org.jboss.ide.eclipse.as.openshift.core.Cartridge;
import org.jboss.ide.eclipse.as.openshift.core.IOpenshiftService;
import org.jboss.ide.eclipse.as.openshift.core.ISSHPublicKey;
@@ -23,7 +23,7 @@
import org.jboss.ide.eclipse.as.openshift.core.User;
import org.jboss.ide.eclipse.as.openshift.core.UserInfo;
import org.jboss.ide.eclipse.as.openshift.core.internal.OpenshiftService;
-import org.jboss.ide.eclipse.as.openshift.test.internal.core.utils.ApplicationAsserts;
+import
org.jboss.ide.eclipse.as.openshift.test.internal.core.utils.ApplicationInfoAsserts;
import org.junit.Before;
import org.junit.Test;
@@ -34,39 +34,39 @@
private IOpenshiftService openshiftService;
- private static final String USERNAME = "toolsjboss(a)gmail.com";
+ private static final String RHLOGIN = "toolsjboss(a)gmail.com";
private static final String PASSWORD = "1q2w3e";
@Before
public void setUp() {
- this.openshiftService = new OpenshiftService(USERNAME, PASSWORD);
+ this.openshiftService = new OpenshiftService();
}
@Test
public void canGetUserInfo() throws Exception {
- UserInfo userInfo = openshiftService.getUserInfo();
+ UserInfo userInfo = openshiftService.getUserInfo(new User(RHLOGIN, PASSWORD));
assertNotNull(userInfo);
- User user = userInfo.getUser();
- assertEquals(USERNAME, user.getRhlogin());
+ assertEquals(RHLOGIN, userInfo.getRhLogin());
}
@Test
public void userInfoContainsOneMoreApplicationAfterCreatingNewApplication() throws
Exception {
- UserInfo userInfo = openshiftService.getUserInfo();
+ User user = new User(RHLOGIN, PASSWORD);
+ UserInfo userInfo = openshiftService.getUserInfo(user);
assertNotNull(userInfo);
- List<Application> applications = userInfo.getApplications();
- assertNotNull(applications);
- int numberOfApplications = applications.size();
+ List<ApplicationInfo> applicationInfos = userInfo.getApplicationInfos();
+ assertNotNull(applicationInfos);
+ int numberOfApplicationInfos = applicationInfos.size();
String applicationName = createRandomName();
try {
- openshiftService.createApplication(applicationName, Cartridge.JBOSSAS_7);
+ openshiftService.createApplication(applicationName, Cartridge.JBOSSAS_7, user);
- UserInfo userInfo2 = openshiftService.getUserInfo();
- assertEquals(numberOfApplications + 1, userInfo2.getApplications().size());
- ApplicationAsserts.assertThatContainsApplication(applicationName,
userInfo2.getApplications());
+ UserInfo userInfo2 = openshiftService.getUserInfo(user);
+ assertEquals(numberOfApplicationInfos + 1, userInfo2.getApplicationInfos().size());
+ ApplicationInfoAsserts.assertThatContainsApplicationInfo(applicationName,
userInfo2.getApplicationInfos());
} finally {
silentlyDestroyAS7Application(applicationName, openshiftService);
}
@@ -74,13 +74,12 @@
@Test
public void canUseReturnedSSHKeyToChangeDomain() throws Exception {
- UserInfo userInfo = openshiftService.getUserInfo();
+ User user = new User(RHLOGIN, PASSWORD);
+ UserInfo userInfo = openshiftService.getUserInfo(user);
assertNotNull(userInfo);
- User user = userInfo.getUser();
- assertNotNull(user);
- ISSHPublicKey sshKey = user.getSshKey();
- openshiftService.changeDomain(createRandomName(), sshKey);
+ ISSHPublicKey sshKey = userInfo.getSshPublicKey();
+ openshiftService.changeDomain(createRandomName(), sshKey, user);
}
private String createRandomName() {
@@ -89,10 +88,9 @@
private void silentlyDestroyAS7Application(String name, IOpenshiftService service) {
try {
- service.destroyApplication(name, Cartridge.JBOSSAS_7);
+ service.destroyApplication(name, Cartridge.JBOSSAS_7, new User(RHLOGIN, PASSWORD));
} catch (OpenshiftException e) {
e.printStackTrace();
}
}
-
}
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/UserInfoTest.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/UserInfoTest.java 2011-09-23
13:26:18 UTC (rev 34997)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/UserInfoTest.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -10,18 +10,16 @@
******************************************************************************/
package org.jboss.ide.eclipse.as.openshift.test.internal.core;
-import static
org.jboss.ide.eclipse.as.openshift.test.internal.core.utils.ApplicationAsserts.assertThatContainsApplication;
+import static
org.jboss.ide.eclipse.as.openshift.test.internal.core.utils.ApplicationInfoAsserts.assertThatContainsApplicationInfo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.net.URLEncoder;
import java.util.List;
-import org.jboss.ide.eclipse.as.openshift.core.Application;
-import org.jboss.ide.eclipse.as.openshift.core.Domain;
+import org.jboss.ide.eclipse.as.openshift.core.ApplicationInfo;
import org.jboss.ide.eclipse.as.openshift.core.ISSHPublicKey;
import org.jboss.ide.eclipse.as.openshift.core.OpenshiftException;
-import org.jboss.ide.eclipse.as.openshift.core.User;
import org.jboss.ide.eclipse.as.openshift.core.UserInfo;
import
org.jboss.ide.eclipse.as.openshift.core.internal.request.OpenshiftEnvelopeFactory;
import org.jboss.ide.eclipse.as.openshift.core.internal.request.UserInfoRequest;
@@ -29,7 +27,6 @@
import org.jboss.ide.eclipse.as.openshift.core.internal.response.JsonSanitizer;
import org.jboss.ide.eclipse.as.openshift.core.internal.response.OpenshiftResponse;
import
org.jboss.ide.eclipse.as.openshift.core.internal.response.UserInfoResponseUnmarshaller;
-import
org.jboss.ide.eclipse.as.openshift.test.internal.core.fakes.NoopOpenshiftServiceFake;
import org.jboss.ide.eclipse.as.openshift.test.internal.core.fakes.UserInfoResponseFake;
import org.junit.Test;
@@ -43,12 +40,13 @@
String expectedRequestString =
"password=" + URLEncoder.encode(UserInfoResponseFake.PASSWORD,
"UTF-8")
+ "&json_data=%7B"
- + "%22rhlogin%22+%3A+%22" +
URLEncoder.encode(UserInfoResponseFake.USERNAME, "UTF-8") + "%22%2C+"
+ + "%22rhlogin%22+%3A+%22" +
URLEncoder.encode(UserInfoResponseFake.RHLOGIN, "UTF-8")
+ + "%22%2C+"
+ "%22debug%22+%3A+%22true%22"
+ "%7D";
String userInfoRequest = new UserInfoRequestJsonMarshaller().marshall(
- new UserInfoRequest(UserInfoResponseFake.USERNAME, true));
+ new UserInfoRequest(UserInfoResponseFake.RHLOGIN, true));
String effectiveRequest =
new OpenshiftEnvelopeFactory(UserInfoResponseFake.PASSWORD,
userInfoRequest).createString();
@@ -60,50 +58,45 @@
UserInfo userInfo =
getUserInfo(JsonSanitizer.sanitize(UserInfoResponseFake.RESPONSE));
assertNotNull(userInfo);
- User user = userInfo.getUser();
- assertNotNull(user);
- assertEquals(UserInfoResponseFake.USERNAME, user.getRhlogin());
- assertEquals(UserInfoResponseFake.UUID, user.getUuid());
- ISSHPublicKey sshKey = user.getSshKey();
- assertNotNull(sshKey);
- assertEquals(UserInfoResponseFake.SSH_KEY, sshKey.getPublicKey());
+ assertEquals(UserInfoResponseFake.RHLOGIN, userInfo.getRhLogin());
+ assertEquals(UserInfoResponseFake.UUID, userInfo.getUuid());
+ ISSHPublicKey sshPublicKey = userInfo.getSshPublicKey();
+ assertNotNull(sshPublicKey);
+ assertEquals(UserInfoResponseFake.SSH_KEY, sshPublicKey.getPublicKey());
- Domain domain = user.getDomain();
- assertEquals(UserInfoResponseFake.NAMESPACE, domain.getNamespace());
- assertEquals(UserInfoResponseFake.RHC_DOMAIN, domain.getRhcDomain());
+ assertEquals(UserInfoResponseFake.NAMESPACE, userInfo.getNamespace());
+ assertEquals(UserInfoResponseFake.RHC_DOMAIN, userInfo.getRhcDomain());
- List<Application> applications = userInfo.getApplications();
- assertNotNull(applications);
- assertEquals(2, applications.size());
- assertThatContainsApplication(
+ List<ApplicationInfo> applicationInfos = userInfo.getApplicationInfos();
+ assertNotNull(applicationInfos);
+ assertEquals(2, applicationInfos.size());
+ assertThatContainsApplicationInfo(
UserInfoResponseFake.APP1_NAME,
UserInfoResponseFake.APP1_EMBEDDED,
UserInfoResponseFake.APP1_UUID,
UserInfoResponseFake.APP1_CARTRIDGE,
UserInfoResponseFake.APP1_CREATION_TIME,
- applications);
- assertThatContainsApplication(
+ applicationInfos);
+ assertThatContainsApplicationInfo(
UserInfoResponseFake.APP2_NAME,
UserInfoResponseFake.APP2_EMBEDDED,
UserInfoResponseFake.APP2_UUID,
UserInfoResponseFake.APP2_CARTRIDGE,
UserInfoResponseFake.APP2_CREATION_TIME,
- applications);
+ applicationInfos);
}
-
+
@Test
public void canGetApplicationByName() throws OpenshiftException {
UserInfo userInfo =
getUserInfo(JsonSanitizer.sanitize(UserInfoResponseFake.RESPONSE));
- Application application =
userInfo.getApplicationByName(UserInfoResponseFake.APP1_NAME);
- assertNotNull(application);
- assertEquals(UserInfoResponseFake.APP1_NAME, application.getName());
+ ApplicationInfo applicationInfo =
userInfo.getApplicationInfoByName(UserInfoResponseFake.APP1_NAME);
+ assertNotNull(applicationInfo);
+ assertEquals(UserInfoResponseFake.APP1_NAME, applicationInfo.getName());
}
protected UserInfo getUserInfo(String response) throws OpenshiftException {
- UserInfoResponseUnmarshaller unmarshaller = new UserInfoResponseUnmarshaller(new
NoopOpenshiftServiceFake());
- OpenshiftResponse<UserInfo> openshiftResponse =
- unmarshaller.unmarshall(response);
-
+ UserInfoResponseUnmarshaller unmarshaller = new UserInfoResponseUnmarshaller();
+ OpenshiftResponse<UserInfo> openshiftResponse =
unmarshaller.unmarshall(response);
return openshiftResponse.getOpenshiftObject();
}
}
Added:
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/UserTest.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/UserTest.java
(rev 0)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/UserTest.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -0,0 +1,153 @@
+/*******************************************************************************
+ * 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 org.jboss.ide.eclipse.as.openshift.test.internal.core;
+
+import static
org.jboss.ide.eclipse.as.openshift.test.internal.core.utils.ApplicationAsserts.assertApplication;
+import static
org.jboss.ide.eclipse.as.openshift.test.internal.core.utils.CartridgeAsserts.assertThatContainsCartridge;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import javax.xml.datatype.DatatypeConfigurationException;
+
+import org.jboss.ide.eclipse.as.openshift.core.Application;
+import org.jboss.ide.eclipse.as.openshift.core.ApplicationInfo;
+import org.jboss.ide.eclipse.as.openshift.core.Cartridge;
+import org.jboss.ide.eclipse.as.openshift.core.Domain;
+import org.jboss.ide.eclipse.as.openshift.core.ISSHPublicKey;
+import org.jboss.ide.eclipse.as.openshift.core.OpenshiftException;
+import org.jboss.ide.eclipse.as.openshift.core.User;
+import org.jboss.ide.eclipse.as.openshift.core.UserInfo;
+import org.jboss.ide.eclipse.as.openshift.core.internal.OpenshiftService;
+import org.jboss.ide.eclipse.as.openshift.core.internal.utils.RFC822DateUtils;
+import
org.jboss.ide.eclipse.as.openshift.test.internal.core.fakes.CartridgeResponseFake;
+import
org.jboss.ide.eclipse.as.openshift.test.internal.core.fakes.NoopOpenshiftServiceFake;
+import org.jboss.ide.eclipse.as.openshift.test.internal.core.fakes.UserInfoResponseFake;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author André Dietisheim
+ */
+public class UserTest {
+
+ private OpenshiftService userInfoservice;
+ private User user;
+
+ @Before
+ public void setUp() throws OpenshiftException, DatatypeConfigurationException {
+ UserInfo userInfo = createUserInfo();
+ this.userInfoservice = createUserInfoService(userInfo);
+ this.user = new User(UserInfoResponseFake.RHLOGIN, UserInfoResponseFake.PASSWORD,
userInfoservice);
+ }
+
+ @Test
+ public void canGetUserUUID() throws OpenshiftException {
+ assertEquals(UserInfoResponseFake.UUID, user.getUUID());
+ }
+
+ @Test
+ public void canGetPublicKey() throws OpenshiftException {
+ ISSHPublicKey key = user.getSshKey();
+ assertNotNull(key);
+ assertEquals(UserInfoResponseFake.SSH_KEY, key.getPublicKey());
+ }
+
+ @Test
+ public void canGetDomain() throws OpenshiftException {
+ Domain domain = user.getDomain();
+ assertNotNull(domain);
+ assertEquals(UserInfoResponseFake.RHC_DOMAIN, domain.getRhcDomain());
+ assertEquals(UserInfoResponseFake.NAMESPACE, domain.getNamespace());
+ }
+
+ @Test
+ public void canGetCartridges() throws OpenshiftException {
+ OpenshiftService cartridgeListService = new NoopOpenshiftServiceFake() {
+
+ @Override
+ public List<Cartridge> getCartridges(User user) throws OpenshiftException {
+ ArrayList<Cartridge> cartridges = new ArrayList<Cartridge>();
+ cartridges.add(new Cartridge(CartridgeResponseFake.CARTRIDGE_JBOSSAS70));
+ cartridges.add(new Cartridge(CartridgeResponseFake.CARTRIDGE_PERL5));
+ cartridges.add(new Cartridge(CartridgeResponseFake.CARTRIDGE_PHP53));
+ cartridges.add(new Cartridge(CartridgeResponseFake.CARTRIDGE_RACK11));
+ cartridges.add(new Cartridge(CartridgeResponseFake.CARTRIDGE_WSGI32));
+ return cartridges;
+ }
+ };
+ User user = new User(UserInfoResponseFake.RHLOGIN, UserInfoResponseFake.PASSWORD,
cartridgeListService);
+ Collection<Cartridge> cartridges = user.getCartridges();
+ assertNotNull(cartridges);
+ assertEquals(5, cartridges.size());
+ assertThatContainsCartridge(CartridgeResponseFake.CARTRIDGE_JBOSSAS70, cartridges);
+ assertThatContainsCartridge(CartridgeResponseFake.CARTRIDGE_PERL5, cartridges);
+ assertThatContainsCartridge(CartridgeResponseFake.CARTRIDGE_PHP53, cartridges);
+ assertThatContainsCartridge(CartridgeResponseFake.CARTRIDGE_RACK11, cartridges);
+ assertThatContainsCartridge(CartridgeResponseFake.CARTRIDGE_WSGI32, cartridges);
+ }
+
+ @Test
+ public void canGetApplications() throws OpenshiftException {
+ /** response is UserInfoResponseFake */
+ Collection<Application> applications = user.getApplications();
+ assertNotNull(applications);
+ assertEquals(2, applications.size());
+ }
+
+ @Test
+ public void canGetApplicationByName() throws OpenshiftException,
DatatypeConfigurationException {
+ Application application = user.getApplicationByName(UserInfoResponseFake.APP2_NAME);
+ assertApplication(
+ UserInfoResponseFake.APP2_NAME
+ , UserInfoResponseFake.APP2_UUID
+ , UserInfoResponseFake.APP2_CARTRIDGE
+ , UserInfoResponseFake.APP2_EMBEDDED
+ , UserInfoResponseFake.APP2_CREATION_TIME
+ , application);
+ }
+
+ private UserInfo createUserInfo() throws OpenshiftException,
DatatypeConfigurationException {
+ ApplicationInfo[] applicationInfos = new ApplicationInfo[] {
+ new ApplicationInfo(UserInfoResponseFake.APP1_NAME
+ , UserInfoResponseFake.APP1_UUID
+ , UserInfoResponseFake.APP1_EMBEDDED
+ , Cartridge.valueOf(UserInfoResponseFake.APP1_CARTRIDGE)
+ , RFC822DateUtils.getDate(UserInfoResponseFake.APP1_CREATION_TIME))
+ , new ApplicationInfo(UserInfoResponseFake.APP2_NAME
+ , UserInfoResponseFake.APP2_UUID
+ , UserInfoResponseFake.APP2_EMBEDDED
+ , Cartridge.valueOf(UserInfoResponseFake.APP2_CARTRIDGE)
+ , RFC822DateUtils.getDate(UserInfoResponseFake.APP2_CREATION_TIME))
+ };
+ return new UserInfo(
+ UserInfoResponseFake.RHLOGIN
+ , UserInfoResponseFake.UUID
+ , UserInfoResponseFake.SSH_KEY
+ , UserInfoResponseFake.RHC_DOMAIN
+ , UserInfoResponseFake.NAMESPACE
+ , Arrays.asList(applicationInfos));
+ }
+
+ private OpenshiftService createUserInfoService(final UserInfo userInfo) {
+ return new NoopOpenshiftServiceFake() {
+
+ @Override
+ public UserInfo getUserInfo(User user) throws OpenshiftException {
+ return userInfo;
+ }
+ };
+ }
+}
Property changes on:
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/UserTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/fakes/ApplicationResponseFake.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/fakes/ApplicationResponseFake.java 2011-09-23
13:26:18 UTC (rev 34997)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/fakes/ApplicationResponseFake.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -19,8 +19,10 @@
*/
public class ApplicationResponseFake {
- public static final String USERNAME = "jbosstools(a)redhat.com";
+ public static final String RHLOGIN = "jbosstools(a)redhat.com";
public static final String PASSWORD = "$!445password%&";
+ public static final String UUID = "0123456789abcdefghijklmnopqrstuvwz";
+ public static final String SSHPUBLICKEY = "sshpublicKey&!%$123456";
public static final String RHC_DOMAIN = "rhcloud.com";
public static final String NAMESPACE = "1315839296868";
Added:
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/fakes/CartridgeResponseFake.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/fakes/CartridgeResponseFake.java
(rev 0)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/fakes/CartridgeResponseFake.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -0,0 +1,45 @@
+package org.jboss.ide.eclipse.as.openshift.test.internal.core.fakes;
+
+/**
+ *
+ * @author André Dietisheim
+ *
+ */
+public class CartridgeResponseFake {
+
+ public static final String CARTRIDGE_PERL5 = "perl-5.10";
+ public static final String CARTRIDGE_JBOSSAS70 = "jbossas-7.0";
+ public static final String CARTRIDGE_WSGI32 = "wsgi-3.2";
+ public static final String CARTRIDGE_RACK11 = "rack-1.1";
+ public static final String CARTRIDGE_PHP53 = "php-5.3";
+
+ public static final String RESPONSE =
+ "{"
+ +" \"messages\":\"\","
+ +" \"debug\":\"\","
+ +" \"data\":\"{"
+ +" \\\"carts\\\":"
+ +" [\\\"" + CARTRIDGE_PERL5 +"\\\","
+ +" \\\"" + CARTRIDGE_JBOSSAS70 + "\\\","
+ +" \\\"" + CARTRIDGE_WSGI32+ "\\\","
+ +" \\\"" + CARTRIDGE_RACK11 + "\\\","
+ +" \\\"" + CARTRIDGE_PHP53 + "\\\"]"
+ +" }\","
+ +" \"api\":\"1.1.1\","
+ +" \"api_c\":[\"placeholder\"],"
+ +" \"result\":null,"
+ +" \"broker\":\"1.1.1\","
+ +" \"broker_c\":[\"namespace\","
+ +" \"rhlogin\","
+ +" \"ssh\","
+ +" \"app_uuid\","
+ +" \"debug\","
+ +" \"alter\","
+ +" \"cartridge\","
+ +" \"cart_type\","
+ +" \"action\","
+ +" \"app_name\","
+ +" \"api\"],"
+ +" \"exit_code\":0"
+ + "}";
+}
Property changes on:
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/fakes/CartridgeResponseFake.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/fakes/NoopOpenshiftServiceFake.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/fakes/NoopOpenshiftServiceFake.java 2011-09-23
13:26:18 UTC (rev 34997)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/fakes/NoopOpenshiftServiceFake.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -15,75 +15,64 @@
import org.jboss.ide.eclipse.as.openshift.core.Application;
import org.jboss.ide.eclipse.as.openshift.core.Cartridge;
import org.jboss.ide.eclipse.as.openshift.core.Domain;
-import org.jboss.ide.eclipse.as.openshift.core.IOpenshiftService;
import org.jboss.ide.eclipse.as.openshift.core.ISSHPublicKey;
import org.jboss.ide.eclipse.as.openshift.core.OpenshiftException;
-import org.jboss.ide.eclipse.as.openshift.core.SSHKeyPair;
+import org.jboss.ide.eclipse.as.openshift.core.User;
import org.jboss.ide.eclipse.as.openshift.core.UserInfo;
+import org.jboss.ide.eclipse.as.openshift.core.internal.OpenshiftService;
/**
* @author André Dietisheim
*/
-public class NoopOpenshiftServiceFake implements IOpenshiftService {
+public class NoopOpenshiftServiceFake extends OpenshiftService {
@Override
- public UserInfo getUserInfo() throws OpenshiftException {
+ public UserInfo getUserInfo(User user) throws OpenshiftException {
throw new UnsupportedOperationException();
}
@Override
- public List<Cartridge> getCartridges() throws OpenshiftException {
+ public List<Cartridge> getCartridges(User user) throws OpenshiftException {
throw new UnsupportedOperationException();
}
@Override
- public Application createApplication(String name, Cartridge cartridge) throws
OpenshiftException {
+ public Application createApplication(String name, Cartridge cartridge, User user) throws
OpenshiftException {
throw new UnsupportedOperationException();
}
@Override
- public Application destroyApplication(String name, Cartridge cartridge) throws
OpenshiftException {
+ public Application destroyApplication(String name, Cartridge cartridge, User user)
throws OpenshiftException {
throw new UnsupportedOperationException();
}
@Override
- public Application startApplication(String name, Cartridge cartridge) throws
OpenshiftException {
+ public Application startApplication(String name, Cartridge cartridge, User user) throws
OpenshiftException {
throw new UnsupportedOperationException();
}
@Override
- public Application restartApplication(String name, Cartridge cartridge) throws
OpenshiftException {
+ public Application restartApplication(String name, Cartridge cartridge, User user)
throws OpenshiftException {
throw new UnsupportedOperationException();
}
@Override
- public Application stopApplication(String name, Cartridge cartridge) throws
OpenshiftException {
+ public Application stopApplication(String name, Cartridge cartridge, User user) throws
OpenshiftException {
throw new UnsupportedOperationException();
}
@Override
- public String getStatus(String applicationName, Cartridge cartridge) throws
OpenshiftException {
+ public String getStatus(String applicationName, Cartridge cartridge, User user) throws
OpenshiftException {
throw new UnsupportedOperationException();
}
@Override
- public Domain changeDomain(String domainName, ISSHPublicKey sshKey) throws
OpenshiftException {
+ public Domain changeDomain(String domainName, ISSHPublicKey sshKey, User user) throws
OpenshiftException {
throw new UnsupportedOperationException();
}
@Override
- public Domain createDomain(String name, ISSHPublicKey keyPair) throws OpenshiftException
{
+ public Domain createDomain(String name, ISSHPublicKey keyPair, User user) throws
OpenshiftException {
throw new UnsupportedOperationException();
}
-
- @Override
- public SSHKeyPair createKey(String passPhrase, String privateKeyPath, String
publicKeyPath) throws OpenshiftException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public SSHKeyPair loadKey(String privateKeyPath, String publicKeyPath) throws
OpenshiftException {
- throw new UnsupportedOperationException();
- }
-
}
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/fakes/UserInfoResponseFake.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/fakes/UserInfoResponseFake.java 2011-09-23
13:26:18 UTC (rev 34997)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/fakes/UserInfoResponseFake.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -2,7 +2,7 @@
public class UserInfoResponseFake {
- public static final String USERNAME = "jbosstools(a)redhat.com";
+ public static final String RHLOGIN = "jbosstools(a)redhat.com";
public static final String PASSWORD = "$!445password%&";
public static final String RHC_DOMAIN = "rhcloud.com";
@@ -36,7 +36,7 @@
+ " \\\"user_info\\\":"
+ " {"
+ " \\\"rhc_domain\\\":\\\"" + RHC_DOMAIN +
"\\\"," //
- + " \\\"rhlogin\\\":\\\"" + USERNAME +
"\\\","
+ + " \\\"rhlogin\\\":\\\"" + RHLOGIN +
"\\\","
+ " \\\"namespace\\\":\\\"" + NAMESPACE +
"\\\","
+ " \\\"uuid\\\":\\\"" + UUID + "\\\","
+ " \\\"ssh_key\\\":\\\"" + SSH_KEY +
"\\\""
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/utils/ApplicationAsserts.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/utils/ApplicationAsserts.java 2011-09-23
13:26:18 UTC (rev 34997)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/utils/ApplicationAsserts.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -34,7 +34,7 @@
if (application == null) {
fail(MessageFormat.format("Could not find application with name
\"{0}\"", applicationName));
}
- assertApplication(embedded, applicationUUID, cartridgeName, creationTime,
application);
+ assertApplication(applicationName, applicationUUID, cartridgeName, embedded,
creationTime, application);
}
public static void assertThatContainsApplication(String applicationName,
List<Application> applications) {
@@ -51,8 +51,8 @@
}
return matchingApplication;
}
-
- private static void assertApplication(String embedded, String uuid, String
cartridgeName,
+
+ public static void assertApplication(String name, String uuid, String cartridgeName,
String embedded,
String creationTime, Application application) throws OpenshiftException {
assertEquals(embedded, application.getEmbedded());
assertEquals(uuid, application.getUUID());
Added:
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/utils/ApplicationInfoAsserts.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/utils/ApplicationInfoAsserts.java
(rev 0)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/utils/ApplicationInfoAsserts.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * 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 org.jboss.ide.eclipse.as.openshift.test.internal.core.utils;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.text.MessageFormat;
+import java.util.List;
+
+import javax.xml.datatype.DatatypeConfigurationException;
+
+import org.jboss.ide.eclipse.as.openshift.core.ApplicationInfo;
+import org.jboss.ide.eclipse.as.openshift.core.OpenshiftException;
+import org.jboss.ide.eclipse.as.openshift.core.internal.utils.RFC822DateUtils;
+
+/**
+ * @author André Dietisheim
+ */
+public class ApplicationInfoAsserts {
+
+ public static void assertThatContainsApplicationInfo(String applicationName, String
embedded, String applicationUUID,
+ String cartridgeName, String creationTime, List<ApplicationInfo>
applicationInfos) throws OpenshiftException {
+ ApplicationInfo applicationInfo = getApplicationInfo(applicationName,
applicationInfos);
+ if (applicationInfo == null) {
+ fail(MessageFormat.format("Could not find application with name
\"{0}\"", applicationName));
+ }
+ assertApplicationInfo(embedded, applicationUUID, cartridgeName, creationTime,
applicationInfo);
+ }
+
+ public static void assertThatContainsApplicationInfo(String applicationName,
List<ApplicationInfo> applicationInfos) {
+ assertNotNull(getApplicationInfo(applicationName, applicationInfos));
+ }
+
+ private static ApplicationInfo getApplicationInfo(String name,
List<ApplicationInfo> applicationInfos) {
+ ApplicationInfo matchingApplicationInfo = null;
+ for (ApplicationInfo applicationInfo : applicationInfos) {
+ if (name.equals(applicationInfo.getName())) {
+ matchingApplicationInfo = applicationInfo;
+ break;
+ }
+ }
+ return matchingApplicationInfo;
+ }
+
+ private static void assertApplicationInfo(String embedded, String uuid, String
cartridgeName,
+ String creationTime, ApplicationInfo applicationInfo) throws OpenshiftException {
+ assertEquals(embedded, applicationInfo.getEmbedded());
+ assertEquals(uuid, applicationInfo.getUuid());
+ assertNotNull(applicationInfo.getCartridge());
+ assertEquals(cartridgeName, applicationInfo.getCartridge().getName());
+ try {
+ assertEquals(RFC822DateUtils.getDate(creationTime),
applicationInfo.getCreationTime());
+ } catch (DatatypeConfigurationException e) {
+ fail(e.getMessage());
+ }
+ }
+
+}
Property changes on:
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/utils/ApplicationInfoAsserts.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/utils/CartridgeAsserts.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/utils/CartridgeAsserts.java 2011-09-23
13:26:18 UTC (rev 34997)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/utils/CartridgeAsserts.java 2011-09-23
13:38:47 UTC (rev 34998)
@@ -13,13 +13,16 @@
import static org.junit.Assert.fail;
import java.text.MessageFormat;
-import java.util.List;
+import java.util.Collection;
import org.jboss.ide.eclipse.as.openshift.core.Cartridge;
+/**
+ * @author André Dietisheim
+ */
public class CartridgeAsserts {
- public static void assertThatContainsCartridge(String cartridgeName,
List<Cartridge> cartridges) {
+ public static void assertThatContainsCartridge(String cartridgeName,
Collection<Cartridge> cartridges) {
boolean found = false;
for (Cartridge cartridge : cartridges) {
if (cartridgeName.equals(cartridge.getName())) {