Skip to content

Commit

Permalink
Merge branch 'master' of github.com:bdecoste/openshift-java-client
Browse files Browse the repository at this point in the history
  • Loading branch information
adietish committed Feb 14, 2012
2 parents 4bb5978 + ef03554 commit 172930b
Show file tree
Hide file tree
Showing 14 changed files with 134 additions and 24 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Expand Up @@ -55,6 +55,12 @@
<url>git://github.com/arquillian/arquillian-core.git</url> </scm -->

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down
Expand Up @@ -22,7 +22,6 @@
public interface IOpenShiftService {

public static final String ID = "com.openshift.express.client";
public static final String VERSION = "2.3.0";

/**
* The path (url path addition) to the service
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/com/openshift/express/client/JBossCartridge.java
@@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright (c) 2011 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package com.openshift.express.client;


/**
* A cartridge that is available on the openshift server. This class is no enum
* since we dont know all available types and they may change at any time.
*
* @author André Dietisheim
*/
public class JBossCartridge extends Cartridge {

public JBossCartridge(String name) {
super(name);
}

public String getLogLocation() {
return "/jbossas-7.0/";
}

}
24 changes: 23 additions & 1 deletion src/main/java/com/openshift/express/client/OpenShiftService.java
Expand Up @@ -10,6 +10,9 @@
******************************************************************************/
package com.openshift.express.client;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
Expand Down Expand Up @@ -68,6 +71,8 @@ public class OpenShiftService implements IOpenShiftService {
private String baseUrl;
private String id;
private boolean doSSLChecks = false;

protected static String version = null;

public OpenShiftService(String id, String baseUrl) {
this.id = id;
Expand Down Expand Up @@ -429,8 +434,25 @@ private String sendRequest(final String request, final String url, final String

protected IHttpClient createHttpClient(final String id, final String url, final boolean verifyHostnames)
throws MalformedURLException {
String userAgent = MessageFormat.format(USERAGENT_FORMAT, VERSION, id);
String userAgent = MessageFormat.format(USERAGENT_FORMAT, version, id);
return new UrlConnectionHttpClient(userAgent, new URL(url), verifyHostnames);
}

public static String getVersion() throws IOException {
if (version == null){
InputStream is = null;
try {
Properties props = new Properties();
is = OpenShiftService.class.getClassLoader().getResourceAsStream("version.properties");
props.load(is);
version = props.getProperty("version");
} finally {
if (is != null)
is.close();
}
}

return version;
}

}
26 changes: 26 additions & 0 deletions src/main/java/com/openshift/express/client/RubyCartridge.java
@@ -0,0 +1,26 @@
/*******************************************************************************
* Copyright (c) 2011 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package com.openshift.express.client;


/**
* A cartridge that is available on the openshift server. This class is no enum
* since we dont know all available types and they may change at any time.
*
* @author André Dietisheim
*/
public class RubyCartridge extends Cartridge {

public RubyCartridge(String name) {
super(name);
}

}
Expand Up @@ -129,7 +129,12 @@ && getUserInfo().hasDomain()) {
}

public boolean hasDomain() throws OpenShiftException {
return getDomain() != null;
try {
return getDomain() != null;
} catch(NotFoundOpenShiftException e) {
// domain not found
return false;
}
}

private void setSshKey(ISSHPublicKey key) {
Expand Down
Expand Up @@ -16,7 +16,9 @@
import com.openshift.express.client.IApplication;
import com.openshift.express.client.ICartridge;
import com.openshift.express.client.IUser;
import com.openshift.express.client.JBossCartridge;
import com.openshift.express.client.OpenShiftService;
import com.openshift.express.client.RubyCartridge;
import com.openshift.express.internal.client.Application;
import com.openshift.express.internal.client.InternalUser;
import com.openshift.express.internal.client.JBossASApplication;
Expand Down Expand Up @@ -45,9 +47,9 @@ protected IApplication createOpenShiftObject(ModelNode node) {
String creationLog = getString(IOpenShiftJsonConstants.PROPERTY_RESULT, node);
String healthCheckPath = getDataNodeProperty(IOpenShiftJsonConstants.PROPERTY_HEALTH_CHECK_PATH, node);
String uuid = getDataNodeProperty(IOpenShiftJsonConstants.PROPERTY_UUID, node);
if (cartridge == Cartridge.JBOSSAS_7) {
if (cartridge instanceof JBossCartridge) {
return new JBossASApplication(applicationName, uuid, creationLog, healthCheckPath, cartridge, user, service);
} else if (cartridge == Cartridge.RUBY_18) {
} else if (cartridge instanceof RubyCartridge) {
return new RubyApplication(applicationName, uuid, creationLog, healthCheckPath, cartridge, user, service);
} else {
return new Application(applicationName, uuid, creationLog, healthCheckPath, cartridge, user, service);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/version.properties
@@ -0,0 +1 @@
version=${pom.version}
Expand Up @@ -50,6 +50,7 @@ public void canListCartridges() throws Exception {
List<ICartridge> cartridges = openShiftService.getCartridges(user);
assertNotNull(cartridges);
assertTrue(cartridges.size() > 0);
System.out.println("!!!!!! " + cartridges);
}

@Test
Expand Down
Expand Up @@ -13,6 +13,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.File;
Expand All @@ -26,12 +27,15 @@
import org.junit.Test;

import com.openshift.express.client.OpenShiftException;
import com.openshift.express.client.OpenShiftService;
import com.openshift.express.client.configuration.DefaultConfiguration;
import com.openshift.express.client.configuration.IOpenShiftConfiguration;
import com.openshift.express.client.configuration.OpenShiftConfiguration;
import com.openshift.express.client.configuration.SystemConfiguration;
import com.openshift.express.client.configuration.SystemProperties;
import com.openshift.express.client.configuration.UserConfiguration;
import com.openshift.express.internal.client.test.fakes.SystemConfigurationFake;
import com.openshift.express.internal.client.test.fakes.TestUser;
import com.openshift.express.internal.client.test.fakes.UserConfigurationFake;
import com.openshift.express.internal.client.utils.StreamUtils;

Expand All @@ -47,6 +51,14 @@ public class ConfigurationTest {
private static final String ANOTHER_USERNAME = "anotherUser";
protected static final String LIBRA_SERVER = "openshift.redhat.com";

@Test
public void versionTest() throws OpenShiftException, IOException {
String version = OpenShiftService.getVersion();

assertNotNull(version);
assertFalse(version.contains("pom"));
}

@Test
public void canReadUsername() throws OpenShiftException, IOException {
UserConfigurationFake userConfiguration = new UserConfigurationFake() {
Expand Down
Expand Up @@ -20,14 +20,14 @@

@RunWith(Suite.class)
@Suite.SuiteClasses({
ApplicationIntegrationTest.class,
EmbedIntegrationTest.class,
ApplicationLogReaderIntegrationTest.class,
CartridgesIntegrationTest.class,
DomainIntegrationTest.class,
UserInfoIntegrationTest.class,
UserIntegrationTest.class,
CertTrustIntegrationTest.class
// ApplicationIntegrationTest.class,
// EmbedIntegrationTest.class,
// ApplicationLogReaderIntegrationTest.class,
CartridgesIntegrationTest.class
// DomainIntegrationTest.class,
// UserInfoIntegrationTest.class,
// UserIntegrationTest.class,
// CertTrustIntegrationTest.class
})


Expand Down
Expand Up @@ -16,16 +16,16 @@

@RunWith(Suite.class)
@Suite.SuiteClasses({
ConfigurationTest.class,
ApplicationTest.class,
EmbedTest.class,
ApplicationLogReaderTest.class,
DomainTest.class,
UserInfoTest.class,
UserTest.class,
CartridgeTest.class,
EmbeddableCartridgeTest.class,
SSHKeyTest.class
ConfigurationTest.class
// ApplicationTest.class,
// EmbedTest.class,
// ApplicationLogReaderTest.class,
// DomainTest.class,
// UserInfoTest.class,
// UserTest.class,
// CartridgeTest.class,
// EmbeddableCartridgeTest.class,
// SSHKeyTest.class
})
/**
* @author André Dietisheim
Expand Down
Expand Up @@ -117,6 +117,12 @@ public void cannotCreateDomainIfAlreadyExists() throws OpenShiftException {
user.createDomain("newDomain", key);
}

@Test
public void getFalseIfNoDomainPresent() throws OpenShiftException {
Boolean hasDomain = userWithoutDomain.hasDomain();
assertFalse(hasDomain);
}

@Test
public void getNullIfNoDomainPresent() throws OpenShiftException {
IDomain domain = userWithoutDomain.getDomain();
Expand Down
Expand Up @@ -26,7 +26,7 @@
*/
public class TestUser extends User {

public static final String ID = "com.openshift.express.client.test " + OpenShiftService.VERSION;
public static final String ID = "com.openshift.express.client.test ";

public static final String RHLOGIN_USER_WITHOUT_DOMAIN = "toolsjboss+unittests_nodomain@gmail.com";
public static final String PASSWORD_USER_WITHOUT_DOMAIN = "1q2w3e";
Expand Down

0 comments on commit 172930b

Please sign in to comment.