Author: adietish
Date: 2011-09-07 10:03:16 -0400 (Wed, 07 Sep 2011)
New Revision: 34570
Added:
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/OpenshiftService.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/internal/test/core/OpenshiftServiceIntegrationTest.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/internal/test/core/OpenshiftServiceTest.java
Removed:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/IOpenshift.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/Openshift.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/internal/test/core/OpenshiftIntegrationTest.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/internal/test/core/OpenshiftTest.java
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/internal/core/Cartridge.java
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/internal/core/request/ApplicationAction.java
Log:
[JBIDE-9510] renamed OpenShift to OpenShiftService
Deleted:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/IOpenshift.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/IOpenshift.java 2011-09-07
13:29:55 UTC (rev 34569)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/IOpenshift.java 2011-09-07
14:03:16 UTC (rev 34570)
@@ -1,25 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.ide.eclipse.as.openshift.core;
-
-import java.util.List;
-
-import org.jboss.ide.eclipse.as.openshift.internal.core.Cartridge;
-import org.jboss.ide.eclipse.as.openshift.internal.core.UserInfo;
-
-public interface IOpenshift {
-
- public UserInfo getUserInfo() throws OpenshiftException;
-
- public List<Cartridge> getCartridges() throws OpenshiftException;
-
- public Application createApplication(String name, Cartridge cartridge) throws
OpenshiftException;
-}
Copied:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/IOpenshiftService.java
(from rev 34544,
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/IOpenshift.java)
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/IOpenshiftService.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/IOpenshiftService.java 2011-09-07
14:03:16 UTC (rev 34570)
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * 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.List;
+
+import org.jboss.ide.eclipse.as.openshift.internal.core.Cartridge;
+import org.jboss.ide.eclipse.as.openshift.internal.core.UserInfo;
+
+public interface IOpenshiftService {
+
+ public UserInfo getUserInfo() throws OpenshiftException;
+
+ public List<Cartridge> getCartridges() throws OpenshiftException;
+
+ public Application createApplication(String name, Cartridge cartridge) throws
OpenshiftException;
+
+ public Application destroyApplication(String name, Cartridge cartridge) throws
OpenshiftException;
+}
Property changes on:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/IOpenshiftService.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Deleted:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/Openshift.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/Openshift.java 2011-09-07
13:29:55 UTC (rev 34569)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/Openshift.java 2011-09-07
14:03:16 UTC (rev 34570)
@@ -1,112 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.ide.eclipse.as.openshift.core;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.List;
-
-import org.eclipse.osgi.util.NLS;
-import
org.jboss.ide.eclipse.as.openshift.core.internal.marshalling.ApplicationRequestJsonMarshaller;
-import
org.jboss.ide.eclipse.as.openshift.core.internal.marshalling.ListCartridgesRequestJsonMarshaller;
-import
org.jboss.ide.eclipse.as.openshift.core.internal.marshalling.UserInfoRequestJsonMarshaller;
-import org.jboss.ide.eclipse.as.openshift.internal.core.Cartridge;
-import org.jboss.ide.eclipse.as.openshift.internal.core.HttpClientException;
-import org.jboss.ide.eclipse.as.openshift.internal.core.UrlConnectionHttpClient;
-import org.jboss.ide.eclipse.as.openshift.internal.core.UserInfo;
-import org.jboss.ide.eclipse.as.openshift.internal.core.request.ApplicationAction;
-import org.jboss.ide.eclipse.as.openshift.internal.core.request.ApplicationRequest;
-import org.jboss.ide.eclipse.as.openshift.internal.core.request.ListCartridgesRequest;
-import
org.jboss.ide.eclipse.as.openshift.internal.core.request.OpenshiftJsonRequestFactory;
-import org.jboss.ide.eclipse.as.openshift.internal.core.request.UserInfoRequest;
-import
org.jboss.ide.eclipse.as.openshift.internal.core.response.ApplicationResponseUnmarshaller;
-import org.jboss.ide.eclipse.as.openshift.internal.core.response.OpenshiftResponse;
-
-/**
- * @author André Dietisheim
- */
-public class Openshift implements IOpenshift {
-
- private static final String BASE_URL = "https://openshift.redhat.com/broker";
-
- private String username;
- private String password;
-
- public Openshift(String username, String password) {
- this.username = username;
- this.password = password;
- }
-
- public UserInfo getUserInfo() throws OpenshiftException {
- UserInfoRequest userInfoRequest = new UserInfoRequest(username, true);
- try {
- String userInfoRequestString = new
UserInfoRequestJsonMarshaller().marshall(userInfoRequest);
- String request = new OpenshiftJsonRequestFactory(password,
userInfoRequestString).create();
- String userInfoResponse =
createHttpClient(userInfoRequest.getUrl(BASE_URL)).post(request);
- throw new UnsupportedOperationException();
- } catch (MalformedURLException e) {
- throw new OpenshiftException(
- NLS.bind("Could not get user info for user \"{0}\" at
\"{1}\"", username,
- userInfoRequest.getUrlString(BASE_URL)), e);
- } catch (HttpClientException e) {
- throw new OpenshiftException(
- NLS.bind("Could not get user info for user \"{0}\" at
\"{1}\"", username,
- userInfoRequest.getUrlString(BASE_URL)), e);
- }
- }
-
- @Override
- public List<Cartridge> getCartridges() throws OpenshiftException {
- ListCartridgesRequest listCartridgesRequest = new ListCartridgesRequest(username,
true);
- try {
- String listCartridgesRequestString =
- new ListCartridgesRequestJsonMarshaller().marshall(listCartridgesRequest);
- String request = new OpenshiftJsonRequestFactory(password,
listCartridgesRequestString).create();
- String listCatridgesReponse =
createHttpClient(listCartridgesRequest.getUrl(BASE_URL)).post(request);
- throw new UnsupportedOperationException();
- } catch (MalformedURLException e) {
- throw new OpenshiftException(
- NLS.bind("Could not list available cartridges at \"{0}\"",
- listCartridgesRequest.getUrlString(BASE_URL)), e);
- } catch (HttpClientException e) {
- throw new OpenshiftException(
- NLS.bind("Could not list available cartridges at \"{0}\"",
- listCartridgesRequest.getUrlString(BASE_URL)), e);
- }
- }
-
- @Override
- public Application createApplication(String name, Cartridge cartridge) throws
OpenshiftException {
- ApplicationRequest applicationRequest = new ApplicationRequest(name, cartridge,
ApplicationAction.CONFIGURE, username, true);
- try {
- String listCartridgesRequestString =
- new ApplicationRequestJsonMarshaller().marshall(applicationRequest);
- String request = new OpenshiftJsonRequestFactory(password,
listCartridgesRequestString).create();
- String response =
createHttpClient(applicationRequest.getUrl(BASE_URL)).post(request);
- OpenshiftResponse<Application> openshiftResponse = new
ApplicationResponseUnmarshaller(response, name, cartridge).unmarshall();
- return openshiftResponse.getData();
- } catch (MalformedURLException e) {
- throw new OpenshiftException(
- NLS.bind("Could not create application \"{0}\" at
\"{1}\"",
- name, applicationRequest.getUrlString(BASE_URL)), e);
- } catch (HttpClientException e) {
- throw new OpenshiftException(
- NLS.bind("Could not create application \"{0}\" at
\"{1}\"",
- name, applicationRequest.getUrlString(BASE_URL)), e);
- }
-
- }
-
- private IHttpClient createHttpClient(URL url) {
- return new UrlConnectionHttpClient(url);
- }
-
-}
Copied:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/OpenshiftService.java
(from rev 34568,
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/Openshift.java)
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/OpenshiftService.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/OpenshiftService.java 2011-09-07
14:03:16 UTC (rev 34570)
@@ -0,0 +1,126 @@
+/*******************************************************************************
+ * 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.net.MalformedURLException;
+import java.net.URL;
+import java.util.List;
+
+import org.eclipse.osgi.util.NLS;
+import
org.jboss.ide.eclipse.as.openshift.core.internal.marshalling.ApplicationRequestJsonMarshaller;
+import
org.jboss.ide.eclipse.as.openshift.core.internal.marshalling.ListCartridgesRequestJsonMarshaller;
+import
org.jboss.ide.eclipse.as.openshift.core.internal.marshalling.UserInfoRequestJsonMarshaller;
+import org.jboss.ide.eclipse.as.openshift.internal.core.Cartridge;
+import org.jboss.ide.eclipse.as.openshift.internal.core.HttpClientException;
+import org.jboss.ide.eclipse.as.openshift.internal.core.UrlConnectionHttpClient;
+import org.jboss.ide.eclipse.as.openshift.internal.core.UserInfo;
+import org.jboss.ide.eclipse.as.openshift.internal.core.request.ApplicationAction;
+import org.jboss.ide.eclipse.as.openshift.internal.core.request.ApplicationRequest;
+import org.jboss.ide.eclipse.as.openshift.internal.core.request.ListCartridgesRequest;
+import
org.jboss.ide.eclipse.as.openshift.internal.core.request.OpenshiftJsonRequestFactory;
+import org.jboss.ide.eclipse.as.openshift.internal.core.request.UserInfoRequest;
+import
org.jboss.ide.eclipse.as.openshift.internal.core.response.ApplicationResponseUnmarshaller;
+import org.jboss.ide.eclipse.as.openshift.internal.core.response.OpenshiftResponse;
+
+/**
+ * @author André Dietisheim
+ */
+public class OpenshiftService implements IOpenshiftService {
+
+ 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 userInfoRequest = new UserInfoRequest(username, true);
+ try {
+ String userInfoRequestString = new
UserInfoRequestJsonMarshaller().marshall(userInfoRequest);
+ String request = new OpenshiftJsonRequestFactory(password,
userInfoRequestString).create();
+ String userInfoResponse =
createHttpClient(userInfoRequest.getUrl(BASE_URL)).post(request);
+ throw new UnsupportedOperationException();
+ } catch (MalformedURLException e) {
+ throw new OpenshiftException(
+ NLS.bind("Could not get user info for user \"{0}\" at
\"{1}\"", username,
+ userInfoRequest.getUrlString(BASE_URL)), e);
+ } catch (HttpClientException e) {
+ throw new OpenshiftException(
+ NLS.bind("Could not get user info for user \"{0}\" at
\"{1}\"", username,
+ userInfoRequest.getUrlString(BASE_URL)), e);
+ }
+ }
+
+ @Override
+ public List<Cartridge> getCartridges() throws OpenshiftException {
+ ListCartridgesRequest listCartridgesRequest = new ListCartridgesRequest(username,
true);
+ try {
+ String listCartridgesRequestString =
+ new ListCartridgesRequestJsonMarshaller().marshall(listCartridgesRequest);
+ String request = new OpenshiftJsonRequestFactory(password,
listCartridgesRequestString).create();
+ String listCatridgesReponse =
createHttpClient(listCartridgesRequest.getUrl(BASE_URL)).post(request);
+ throw new UnsupportedOperationException();
+ } catch (MalformedURLException e) {
+ throw new OpenshiftException(
+ NLS.bind("Could not list available cartridges at \"{0}\"",
+ listCartridgesRequest.getUrlString(BASE_URL)), e);
+ } catch (HttpClientException e) {
+ throw new OpenshiftException(
+ NLS.bind("Could not list available cartridges at \"{0}\"",
+ listCartridgesRequest.getUrlString(BASE_URL)), e);
+ }
+ }
+
+ @Override
+ public Application createApplication(String name, Cartridge cartridge) throws
OpenshiftException {
+ return requestApplicationAction(name, cartridge,
+ new ApplicationRequest(name, cartridge, ApplicationAction.CONFIGURE, username,
true));
+ }
+
+ @Override
+ public Application destroyApplication(String name, Cartridge cartridge) throws
OpenshiftException {
+ return requestApplicationAction(name, cartridge,
+ new ApplicationRequest(name, cartridge, ApplicationAction.DECONFIGURE, username,
true));
+ }
+
+ protected Application requestApplicationAction(String name, Cartridge cartridge,
+ ApplicationRequest applicationRequest) throws OpenshiftException {
+ try {
+ String applicationRequestString =
+ new ApplicationRequestJsonMarshaller().marshall(applicationRequest);
+ String request = new OpenshiftJsonRequestFactory(password,
applicationRequestString).create();
+ String response =
createHttpClient(applicationRequest.getUrl(BASE_URL)).post(request);
+ OpenshiftResponse<Application> openshiftResponse = new
ApplicationResponseUnmarshaller(response, name,
+ cartridge).unmarshall();
+ return openshiftResponse.getData();
+ } catch (MalformedURLException e) {
+ throw new OpenshiftException(
+ NLS.bind(
+ "Could not {0} application \"{1}\" at \"{2}\"", new
String[] {
+ applicationRequest.getAction().toHumanReadable(), name,
+ applicationRequest.getUrlString(BASE_URL) }), e);
+ } catch (HttpClientException e) {
+ throw new OpenshiftException(
+ NLS.bind("Could not {0} application \"{1}\" at
\"{2}\"", new String[] {
+ applicationRequest.getAction().toHumanReadable(), name,
+ applicationRequest.getUrlString(BASE_URL) }), e);
+ }
+ }
+
+ private IHttpClient createHttpClient(URL url) {
+ return new UrlConnectionHttpClient(url);
+ }
+
+}
Property changes on:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/core/OpenshiftService.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/internal/core/Cartridge.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/internal/core/Cartridge.java 2011-09-07
13:29:55 UTC (rev 34569)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/internal/core/Cartridge.java 2011-09-07
14:03:16 UTC (rev 34570)
@@ -17,6 +17,8 @@
*/
public class Cartridge implements IOpenshiftObject {
+ public static final Cartridge JBOSSAS_7 = new Cartridge("jbossas-7.0");
+
private String name;
public Cartridge(String name) {
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/internal/core/request/ApplicationAction.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/internal/core/request/ApplicationAction.java 2011-09-07
13:29:55 UTC (rev 34569)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.core/src/org/jboss/ide/eclipse/as/openshift/internal/core/request/ApplicationAction.java 2011-09-07
14:03:16 UTC (rev 34570)
@@ -11,5 +11,9 @@
package org.jboss.ide.eclipse.as.openshift.internal.core.request;
public enum ApplicationAction {
- CONFIGURE, DECONFIGURE, START, STOP, RESTART, STATUS
+ CONFIGURE, DECONFIGURE, START, STOP, RESTART, STATUS;
+
+ public String toHumanReadable() {
+ return name().toLowerCase();
+ }
}
Deleted:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/internal/test/core/OpenshiftIntegrationTest.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/internal/test/core/OpenshiftIntegrationTest.java 2011-09-07
13:29:55 UTC (rev 34569)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/internal/test/core/OpenshiftIntegrationTest.java 2011-09-07
14:03:16 UTC (rev 34570)
@@ -1,36 +0,0 @@
-package org.jboss.ide.eclipse.as.openshift.internal.test.core;
-
-import org.jboss.ide.eclipse.as.openshift.core.Openshift;
-import org.jboss.ide.eclipse.as.openshift.core.OpenshiftException;
-import org.jboss.ide.eclipse.as.openshift.internal.core.Cartridge;
-import org.junit.Before;
-import org.junit.Test;
-
-public class OpenshiftIntegrationTest {
-
- private Openshift openshift;
-
- private static final String USERNAME = "toolsjboss(a)gmail.com";
- private static final String PASSWORD = "1q3e5t7u";
-
- @Before
- public void setUp() {
- this.openshift = new Openshift(USERNAME, PASSWORD);
- }
-
- @Test(expected=OpenshiftException.class)
- public void cannotGetUserInfoIfNotAppNorDomainCreated() throws OpenshiftException {
- openshift.getUserInfo();
- }
-
- @Test
- public void canRequestListCartridges() throws Exception {
- openshift.getCartridges();
- }
-
- @Test
- public void canCreateApplication() throws Exception {
- openshift.createApplication("test-application", new
Cartridge("jbossas-7.0"));
- }
-
-}
Copied:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/internal/test/core/OpenshiftServiceIntegrationTest.java
(from rev 34568,
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/internal/test/core/OpenshiftIntegrationTest.java)
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/internal/test/core/OpenshiftServiceIntegrationTest.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/internal/test/core/OpenshiftServiceIntegrationTest.java 2011-09-07
14:03:16 UTC (rev 34570)
@@ -0,0 +1,45 @@
+package org.jboss.ide.eclipse.as.openshift.internal.test.core;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.jboss.ide.eclipse.as.openshift.core.Application;
+import org.jboss.ide.eclipse.as.openshift.core.OpenshiftException;
+import org.jboss.ide.eclipse.as.openshift.core.OpenshiftService;
+import org.jboss.ide.eclipse.as.openshift.internal.core.Cartridge;
+import org.junit.Before;
+import org.junit.Test;
+
+public class OpenshiftServiceIntegrationTest {
+
+ private OpenshiftService openshiftService;
+
+ private static final String USERNAME = "toolsjboss(a)gmail.com";
+ private static final String PASSWORD = "1q3e5t7u";
+
+ @Before
+ public void setUp() {
+ this.openshiftService = new OpenshiftService(USERNAME, PASSWORD);
+ }
+
+ @Test(expected=OpenshiftException.class)
+ public void cannotGetUserInfoIfNotAppNorDomainCreated() throws OpenshiftException {
+ openshiftService.getUserInfo();
+ }
+
+ @Test
+ public void canRequestListCartridges() throws Exception {
+ List<Cartridge> cartridges = openshiftService.getCartridges();
+ assertNotNull(cartridges);
+ assertTrue(cartridges.size() > 0);
+ }
+
+ @Test
+ public void canCreateApplication() throws Exception {
+ Application application =
openshiftService.createApplication("test-application", Cartridge.JBOSSAS_7);
+ assertNotNull(application);
+ }
+
+}
Property changes on:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/internal/test/core/OpenshiftServiceIntegrationTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Copied:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/internal/test/core/OpenshiftServiceTest.java
(from rev 34569,
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/internal/test/core/OpenshiftTest.java)
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/internal/test/core/OpenshiftServiceTest.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/internal/test/core/OpenshiftServiceTest.java 2011-09-07
14:03:16 UTC (rev 34570)
@@ -0,0 +1,130 @@
+package org.jboss.ide.eclipse.as.openshift.internal.test.core;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.net.URLEncoder;
+import java.text.MessageFormat;
+import java.util.List;
+
+import org.jboss.ide.eclipse.as.openshift.core.OpenshiftException;
+import
org.jboss.ide.eclipse.as.openshift.core.internal.marshalling.ApplicationRequestJsonMarshaller;
+import
org.jboss.ide.eclipse.as.openshift.core.internal.marshalling.ListCartridgesRequestJsonMarshaller;
+import
org.jboss.ide.eclipse.as.openshift.core.internal.marshalling.UserInfoRequestJsonMarshaller;
+import org.jboss.ide.eclipse.as.openshift.internal.core.Cartridge;
+import org.jboss.ide.eclipse.as.openshift.internal.core.request.ApplicationAction;
+import org.jboss.ide.eclipse.as.openshift.internal.core.request.ApplicationRequest;
+import org.jboss.ide.eclipse.as.openshift.internal.core.request.ListCartridgesRequest;
+import
org.jboss.ide.eclipse.as.openshift.internal.core.request.OpenshiftJsonRequestFactory;
+import org.jboss.ide.eclipse.as.openshift.internal.core.request.UserInfoRequest;
+import
org.jboss.ide.eclipse.as.openshift.internal.core.response.ListCartridgesResponseUnmarshaller;
+import org.jboss.ide.eclipse.as.openshift.internal.core.response.OpenshiftResponse;
+import org.junit.Test;
+
+public class OpenshiftServiceTest {
+
+ private static final String USERNAME = "toolsjboss(a)gmail.com";
+ private static final String PASSWORD = "1q2w3e";
+
+ @Test
+ public void canMarshallUserInfoRequest() throws Exception {
+ String expectedRequestString =
+ "password=" + PASSWORD
+ + "&json_data=%7B"
+ + "%22rhlogin%22+%3A+%22" + URLEncoder.encode(USERNAME,
"UTF-8") + "%22%2C+"
+ + "%22debug%22+%3A+%22true%22"
+ + "%7D";
+
+ String userInfoRequest = new UserInfoRequestJsonMarshaller().marshall(new
UserInfoRequest(USERNAME, true));
+ String effectiveRequest = new OpenshiftJsonRequestFactory(PASSWORD,
userInfoRequest).create();
+
+ assertEquals(expectedRequestString, effectiveRequest);
+ }
+
+ @Test
+ public void canMarshallListCartridgesRequest() throws Exception {
+ String expectedRequestString = "password=" + PASSWORD +
"&json_data=%7B%22rhlogin%22+%3A+%22"
+ + URLEncoder.encode(USERNAME, "UTF-8")
+ +
"%22%2C+%22debug%22+%3A+%22true%22%2C+%22cart_type%22+%3A+%22standalone%22%7D";
+
+ String listCartridgeRequest = new ListCartridgesRequestJsonMarshaller().marshall(
+ new ListCartridgesRequest(USERNAME, true));
+ String effectiveRequest = new OpenshiftJsonRequestFactory(PASSWORD,
listCartridgeRequest).create();
+
+ assertEquals(expectedRequestString, effectiveRequest);
+ }
+
+ @Test
+ public void canMarshallApplicationCreateRequest() throws Exception {
+ String expectedRequestString =
+ "password="
+ + PASSWORD
+ + "&json_data=%7B"
+ + "%22rhlogin%22+%3A+%22"
+ + URLEncoder.encode(USERNAME, "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"
+ + "%7D";
+
+ String createApplicationRequest = new ApplicationRequestJsonMarshaller().marshall(
+ new ApplicationRequest(
+ "test-application", new Cartridge("jbossas-7.0"),
ApplicationAction.CONFIGURE, USERNAME, true));
+ String effectiveRequest = new OpenshiftJsonRequestFactory(PASSWORD,
createApplicationRequest).create();
+
+ assertEquals(expectedRequestString, effectiveRequest);
+ }
+
+ @Test
+ public void canUnmarshallCartridgeListResponse() throws OpenshiftException {
+ /*
+ * WARNING: the current (9-7-2011) response from the openshift rest
+ * service is invalid. It quotes the nested json object in the data
+ * property: '"data" : "{'. My current unmarshalling code does
not
+ * handle this bad json.
+ */
+ String cartridgeListResponse =
+ "{"
+ + "\"messages\":\"\","
+ + "\"debug\":\"\","
+ + "\"data\":"
+ +
"{\"carts\":[\"perl-5.10\",\"jbossas-7.0\",\"wsgi-3.2\",\"rack-1.1\",\"php-5.3\"]},"
+ + "\"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}";
+
+ OpenshiftResponse<List<Cartridge>> response = new
ListCartridgesResponseUnmarshaller(cartridgeListResponse)
+ .unmarshall();
+ assertEquals("", response.getMessages());
+ assertEquals(false, response.isDebug());
+
+ List<Cartridge> cartridges = response.getData();
+ assertEquals(5, cartridges.size());
+ assertThatContainsCartridge("perl-5.10", cartridges);
+ assertThatContainsCartridge("jbossas-7.0", cartridges);
+ assertThatContainsCartridge("wsgi-3.2", cartridges);
+ assertThatContainsCartridge("rack-1.1", cartridges);
+ assertThatContainsCartridge("php-5.3", cartridges);
+ assertEquals(null, response.getResult());
+ assertEquals(0, response.getExitCode());
+
+ }
+
+ private void assertThatContainsCartridge(String cartridgeName, List<Cartridge>
cartridges) {
+ boolean found = false;
+ for (Cartridge cartridge : cartridges) {
+ if (cartridgeName.equals(cartridge.getName())) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ fail(MessageFormat.format("Could not find cartridge with name
\"{0}\"", cartridgeName));
+ }
+ }
+}
Property changes on:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/internal/test/core/OpenshiftServiceTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Deleted:
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/internal/test/core/OpenshiftTest.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/internal/test/core/OpenshiftTest.java 2011-09-07
13:29:55 UTC (rev 34569)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.openshift.test/src/org/jboss/ide/eclipse/as/openshift/internal/test/core/OpenshiftTest.java 2011-09-07
14:03:16 UTC (rev 34570)
@@ -1,130 +0,0 @@
-package org.jboss.ide.eclipse.as.openshift.internal.test.core;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import java.net.URLEncoder;
-import java.text.MessageFormat;
-import java.util.List;
-
-import org.jboss.ide.eclipse.as.openshift.core.OpenshiftException;
-import
org.jboss.ide.eclipse.as.openshift.core.internal.marshalling.ApplicationRequestJsonMarshaller;
-import
org.jboss.ide.eclipse.as.openshift.core.internal.marshalling.ListCartridgesRequestJsonMarshaller;
-import
org.jboss.ide.eclipse.as.openshift.core.internal.marshalling.UserInfoRequestJsonMarshaller;
-import org.jboss.ide.eclipse.as.openshift.internal.core.Cartridge;
-import org.jboss.ide.eclipse.as.openshift.internal.core.request.ApplicationAction;
-import org.jboss.ide.eclipse.as.openshift.internal.core.request.ApplicationRequest;
-import org.jboss.ide.eclipse.as.openshift.internal.core.request.ListCartridgesRequest;
-import
org.jboss.ide.eclipse.as.openshift.internal.core.request.OpenshiftJsonRequestFactory;
-import org.jboss.ide.eclipse.as.openshift.internal.core.request.UserInfoRequest;
-import
org.jboss.ide.eclipse.as.openshift.internal.core.response.ListCartridgesResponseUnmarshaller;
-import org.jboss.ide.eclipse.as.openshift.internal.core.response.OpenshiftResponse;
-import org.junit.Test;
-
-public class OpenshiftTest {
-
- private static final String USERNAME = "toolsjboss(a)gmail.com";
- private static final String PASSWORD = "1q2w3e";
-
- @Test
- public void canMarshallUserInfoRequest() throws Exception {
- String expectedRequestString =
- "password=" + PASSWORD
- + "&json_data=%7B"
- + "%22rhlogin%22+%3A+%22" + URLEncoder.encode(USERNAME,
"UTF-8") + "%22%2C+"
- + "%22debug%22+%3A+%22true%22"
- + "%7D";
-
- String userInfoRequest = new UserInfoRequestJsonMarshaller().marshall(new
UserInfoRequest(USERNAME, true));
- String effectiveRequest = new OpenshiftJsonRequestFactory(PASSWORD,
userInfoRequest).create();
-
- assertEquals(expectedRequestString, effectiveRequest);
- }
-
- @Test
- public void canMarshallListCartridgesRequest() throws Exception {
- String expectedRequestString = "password=" + PASSWORD +
"&json_data=%7B%22rhlogin%22+%3A+%22"
- + URLEncoder.encode(USERNAME, "UTF-8")
- +
"%22%2C+%22debug%22+%3A+%22true%22%2C+%22cart_type%22+%3A+%22standalone%22%7D";
-
- String listCartridgeRequest = new ListCartridgesRequestJsonMarshaller().marshall(
- new ListCartridgesRequest(USERNAME, true));
- String effectiveRequest = new OpenshiftJsonRequestFactory(PASSWORD,
listCartridgeRequest).create();
-
- assertEquals(expectedRequestString, effectiveRequest);
- }
-
- @Test
- public void canMarshallApplicationCreateRequest() throws Exception {
- String expectedRequestString =
- "password="
- + PASSWORD
- + "&json_data=%7B"
- + "%22rhlogin%22+%3A+%22"
- + URLEncoder.encode(USERNAME, "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"
- + "%7D";
-
- String createApplicationRequest = new ApplicationRequestJsonMarshaller().marshall(
- new ApplicationRequest(
- "test-application", new Cartridge("jbossas-7.0"),
ApplicationAction.CONFIGURE, USERNAME, true));
- String effectiveRequest = new OpenshiftJsonRequestFactory(PASSWORD,
createApplicationRequest).create();
-
- assertEquals(expectedRequestString, effectiveRequest);
- }
-
- @Test
- public void canUnmarshallCartridgeListResponse() throws OpenshiftException {
- /*
- * WARNING: the current (9-7-2011) response from the openshift rest
- * service is invalid. It quotes the nested json object in the data
- * property: '"data" : "{'. My current unmarshalling code does
not
- * handle this bad json.
- */
- String cartridgeListResponse =
- "{"
- + "\"messages\":\"\","
- + "\"debug\":\"\","
- + "\"data\":"
- +
"{\"carts\":[\"perl-5.10\",\"jbossas-7.0\",\"wsgi-3.2\",\"rack-1.1\",\"php-5.3\"]},"
- + "\"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}";
-
- OpenshiftResponse<List<Cartridge>> response = new
ListCartridgesResponseUnmarshaller(cartridgeListResponse)
- .unmarshall();
- assertEquals("", response.getMessages());
- assertEquals(false, response.isDebug());
-
- List<Cartridge> cartridges = response.getData();
- assertEquals(5, cartridges.size());
- assertThatContainsCartridge("perl-5.10", cartridges);
- assertThatContainsCartridge("jbossas-7.0", cartridges);
- assertThatContainsCartridge("wsgi-3.2", cartridges);
- assertThatContainsCartridge("rack-1.1", cartridges);
- assertThatContainsCartridge("php-5.3", cartridges);
- assertEquals(null, response.getResult());
- assertEquals(0, response.getExitCode());
-
- }
-
- private void assertThatContainsCartridge(String cartridgeName, List<Cartridge>
cartridges) {
- boolean found = false;
- for (Cartridge cartridge : cartridges) {
- if (cartridgeName.equals(cartridge.getName())) {
- found = true;
- break;
- }
- }
- if (!found) {
- fail(MessageFormat.format("Could not find cartridge with name
\"{0}\"", cartridgeName));
- }
- }
-}