Author: adietish
Date: 2011-09-26 04:47:57 -0400 (Mon, 26 Sep 2011)
New Revision: 35036
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/Application.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/utils/ApplicationAsserts.java
Log:
[JBIDE-9762] implemented Application#getApplicationUrl and (integration-) tests
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-26
08:07:52 UTC (rev 35035)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/Application.java 2011-09-26
08:47:57 UTC (rev 35036)
@@ -13,14 +13,13 @@
import java.text.MessageFormat;
import java.util.Date;
-import org.jboss.ide.eclipse.as.openshift.core.internal.utils.Assert;
-
/**
* @author André Dietisheim
*/
public class Application {
private static final String GIT_URI_PATTERN =
"ssh://{0}@{1}-{2}.{3}/~/git/{1}.git/";
+ private static final String APPLICATION_URL_PATTERN = "http://{0}-{1}.{2}/";
private String name;
private Cartridge cartridge;
@@ -29,7 +28,7 @@
private String embedded;
private IOpenshiftService service;
private ApplicationLogReader logReader;
-
+
private User user;
public Application(String name, Cartridge cartridge, User user, IOpenshiftService
service) {
@@ -70,10 +69,6 @@
return creationTime;
}
- protected IUser getUser() throws OpenshiftException {
- return user;
- }
-
public void destroy() throws OpenshiftException {
service.destroyApplication(name, cartridge, user);
}
@@ -98,19 +93,20 @@
}
public String getGitUri() throws OpenshiftException {
- String namespace = null;
- String rhcDomain = null;
- Domain domain = getDomain();
- if (domain != null) {
- namespace = domain.getNamespace();
- rhcDomain = domain.getRhcDomain();
+ Domain domain = user.getDomain();
+ if (domain == null) {
+ return null;
}
-
- return MessageFormat.format(GIT_URI_PATTERN, getUUID(), getName(), namespace,
rhcDomain);
+ return MessageFormat
+ .format(GIT_URI_PATTERN, getUUID(), getName(), domain.getNamespace(),
domain.getRhcDomain());
}
- private Domain getDomain() throws OpenshiftException {
- return Assert.assertNotNull(getUser()).getDomain();
+ public String getApplicationUrl() throws OpenshiftException {
+ Domain domain = user.getDomain();
+ if (domain == null) {
+ return null;
+ }
+ return MessageFormat.format(APPLICATION_URL_PATTERN, name, domain.getNamespace(),
domain.getRhcDomain());
}
void update(ApplicationInfo applicationInfo) {
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-26
08:07:52 UTC (rev 35035)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/ApplicationIntegrationTest.java 2011-09-26
08:47:57 UTC (rev 35036)
@@ -11,6 +11,7 @@
package org.jboss.ide.eclipse.as.openshift.test.internal.core;
import static
org.jboss.ide.eclipse.as.openshift.test.internal.core.utils.ApplicationAsserts.assertGitUri;
+import static
org.jboss.ide.eclipse.as.openshift.test.internal.core.utils.ApplicationAsserts.assertAppliactionUrl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -37,7 +38,7 @@
private static final String PASSWORD = "1q2w3e";
private User user;
private User invalidUser;
-
+
@Ignore
@Before
public void setUp() {
@@ -121,7 +122,8 @@
* freshly created apps are started
*
* @link
- *
https://github.com/openshift/os-client-tools/blob/master/express/doc/API
+ *
https://github.com/openshift/os-client-tools/blob/master/express
+ * /doc/API
*/
service.createApplication(applicationName, Cartridge.JBOSSAS_7, user);
service.startApplication(applicationName, Cartridge.JBOSSAS_7, user);
@@ -139,7 +141,8 @@
* freshly created apps are started
*
* @link
- *
https://github.com/openshift/os-client-tools/blob/master/express/doc/API
+ *
https://github.com/openshift/os-client-tools/blob/master/express
+ * /doc/API
*/
service.createApplication(applicationName, Cartridge.JBOSSAS_7, user);
service.stopApplication(applicationName, Cartridge.JBOSSAS_7, user);
@@ -148,7 +151,7 @@
silentlyDestroyAS7Application(applicationName, service);
}
}
-
+
@Ignore
@Test
public void canRestartApplication() throws Exception {
@@ -158,7 +161,8 @@
* freshly created apps are started
*
* @link
- *
https://github.com/openshift/os-client-tools/blob/master/express/doc/API
+ *
https://github.com/openshift/os-client-tools/blob/master/express
+ * /doc/API
*/
service.createApplication(applicationName, Cartridge.JBOSSAS_7, user);
service.restartApplication(applicationName, Cartridge.JBOSSAS_7, user);
@@ -179,7 +183,7 @@
silentlyDestroyAS7Application(applicationName, service);
}
}
-
+
@Ignore
@Test
public void getStatusReturnsTheWholeLog() throws Exception {
@@ -207,6 +211,19 @@
}
}
+ @Test
+ public void returnsValidApplicationUrl() throws Exception {
+ String applicationName = createRandomApplicationName();
+ try {
+ Application application = service.createApplication(applicationName,
Cartridge.JBOSSAS_7, user);
+ String applicationUrl = application.getApplicationUrl();
+ assertNotNull(applicationUrl);
+ assertAppliactionUrl(applicationName, applicationUrl);
+ } finally {
+ silentlyDestroyAS7Application(applicationName, service);
+ }
+ }
+
private String createRandomApplicationName() {
return String.valueOf(System.currentTimeMillis());
}
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-26
08:07:52 UTC (rev 35035)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/test/internal/core/ApplicationTest.java 2011-09-26
08:47:57 UTC (rev 35036)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.jboss.ide.eclipse.as.openshift.test.internal.core;
+import static
org.jboss.ide.eclipse.as.openshift.test.internal.core.utils.ApplicationAsserts.assertAppliactionUrl;
import static
org.jboss.ide.eclipse.as.openshift.test.internal.core.utils.ApplicationAsserts.assertGitUri;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -23,7 +24,6 @@
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;
@@ -115,42 +115,13 @@
}
@Test
- public void canGetGitUri() throws OpenshiftException {
- OpenshiftService userInfoService = new NoopOpenshiftServiceFake() {
- @Override
- public UserInfo getUserInfo(User user) throws OpenshiftException {
- ApplicationInfo applicationInfo = new ApplicationInfo(
- ApplicationResponseFake.APPLICATION_NAME,
- ApplicationResponseFake.APPLICATION_UUID,
- ApplicationResponseFake.APPLICATION_EMBEDDED,
- 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 }));
- }
- };
- User user = new User(ApplicationResponseFake.RHLOGIN, ApplicationResponseFake.PASSWORD,
userInfoService);
- Application application = new Application(
- ApplicationResponseFake.APPLICATION_NAME
- , ApplicationResponseFake.APPLICATION_UUID
- , ApplicationResponseFake.APPLICATION_CARTRIDGE
- , ApplicationResponseFake.APPLICATION_EMBEDDED
- , ApplicationResponseFake.APPLICATION_CREATIONTIME
- , user
- , userInfoService);
- // we need to add it manually since we dont use the service
- user.add(application);
+ public void returnsValidGitUri() throws OpenshiftException {
+ OpenshiftService userInfoService = createUserInfoService();
+ User user = createUser(userInfoService);
+ Application application = createApplication(userInfoService, user);
- assertNotNull(application);
String gitUri = application.getGitUri();
assertNotNull(gitUri);
- Domain domain = user.getDomain();
- assertNotNull(domain);
assertGitUri(
ApplicationResponseFake.APPLICATION_UUID
, ApplicationResponseFake.APPLICATION_NAME
@@ -160,6 +131,21 @@
}
@Test
+ public void returnsValidApplicationUrl() throws OpenshiftException {
+ OpenshiftService userInfoService = createUserInfoService();
+ User user = createUser(userInfoService);
+ Application application = createApplication(userInfoService, user);
+
+ String applicationUrl = application.getApplicationUrl();
+ assertNotNull(applicationUrl);
+ assertAppliactionUrl(
+ ApplicationResponseFake.APPLICATION_NAME
+ , ApplicationResponseFake.NAMESPACE
+ , ApplicationResponseFake.RHC_DOMAIN
+ , applicationUrl);
+ }
+
+ @Test
public void canUnmarshallApplicationStatus() throws OpenshiftException {
String response = JsonSanitizer.sanitize(ApplicationResponseFake.statusResponse);
OpenshiftResponse<String> openshiftResponse =
@@ -193,4 +179,45 @@
ApplicationResponseFake.log.charAt(toMatchIndex++), character);
}
}
+
+ private Application createApplication(OpenshiftService userInfoService, User user) {
+ Application application = new Application(
+ ApplicationResponseFake.APPLICATION_NAME
+ , ApplicationResponseFake.APPLICATION_UUID
+ , ApplicationResponseFake.APPLICATION_CARTRIDGE
+ , ApplicationResponseFake.APPLICATION_EMBEDDED
+ , ApplicationResponseFake.APPLICATION_CREATIONTIME
+ , user
+ , userInfoService);
+ // we need to add it manually since we dont use the service
+ user.add(application);
+ return application;
+ }
+
+ private User createUser(OpenshiftService userInfoService) {
+ User user = new User(ApplicationResponseFake.RHLOGIN, ApplicationResponseFake.PASSWORD,
userInfoService);
+ return user;
+ }
+
+ private OpenshiftService createUserInfoService() {
+ OpenshiftService userInfoService = new NoopOpenshiftServiceFake() {
+ @Override
+ public UserInfo getUserInfo(User user) throws OpenshiftException {
+ ApplicationInfo applicationInfo = new ApplicationInfo(
+ ApplicationResponseFake.APPLICATION_NAME,
+ ApplicationResponseFake.APPLICATION_UUID,
+ ApplicationResponseFake.APPLICATION_EMBEDDED,
+ 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 }));
+ }
+ };
+ return userInfoService;
+ }
}
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-26
08:07:52 UTC (rev 35035)
+++
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-26
08:47:57 UTC (rev 35036)
@@ -40,6 +40,8 @@
*/
public static final Pattern GIT_URI_REGEXP =
Pattern.compile("ssh://(.+)@(.+)-([^\\.]+)\\.(.+)/~/git/(.+).git/");
+ public static final Pattern APPLICATION_URL_REGEXP =
Pattern.compile("http://(.+)-([^\\.]+)\\.(.+)/");
+
public static void assertThatContainsApplication(String applicationName, String
embedded, String applicationUUID,
String cartridgeName, String creationTime, List<Application> applications)
throws OpenshiftException {
Application application = getApplication(applicationName, applications);
@@ -96,4 +98,19 @@
assertEquals(name, matcher.group(5));
}
+ public static void assertAppliactionUrl(String name, String applicationUrl) {
+ Matcher matcher = APPLICATION_URL_REGEXP.matcher(applicationUrl);
+ assertTrue(matcher.matches());
+ assertEquals(3, matcher.groupCount());
+ assertEquals(name, matcher.group(1));
+ }
+
+ public static void assertAppliactionUrl(String name, String namespace, String rhcDomain,
String applicationUrl) {
+ Matcher matcher = APPLICATION_URL_REGEXP.matcher(applicationUrl);
+ assertTrue(matcher.matches());
+ assertEquals(3, matcher.groupCount());
+ assertEquals(name, matcher.group(1));
+ assertEquals(namespace, matcher.group(2));
+ assertEquals(rhcDomain, matcher.group(3));
+ }
}