modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/RHNActivator.java
| 82 ++--------
modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/ApacheXmlRpcExecutor.java
| 7
modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/XmlRpcExecutor.java
| 10 +
modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/RHNActivatorTest.java
| 73 +++-----
modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/MockRhnXmlRpcExecutor.java
| 12 -
5 files changed, 80 insertions(+), 104 deletions(-)
New commits:
commit 7f5db18b86fe6cb7503e359fd7c1fd94ade455b6
Author: Mike McCune <mmccune(a)gibson.pdx.redhat.com>
Date: Fri Oct 30 13:26:19 2009 -0700
400 - fixing rhnactivator test to not actually touch rhnhosted
diff --git
a/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/RHNActivator.java
b/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/RHNActivator.java
index 60a9430..4c7ee1e 100644
---
a/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/RHNActivator.java
+++
b/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/RHNActivator.java
@@ -21,10 +21,8 @@ package org.rhq.enterprise.server.plugins.rhnhosted;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.PrintStream;
import java.net.URL;
import java.security.KeyException;
import java.util.ArrayList;
@@ -32,13 +30,10 @@ import java.util.ArrayList;
import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.rhq.enterprise.server.plugins.rhnhosted.certificate.PublicKeyRing;
-import org.rhq.enterprise.server.plugins.rhnhosted.xmlrpc.RhnSSLTransportFactory;
-
-import org.apache.xmlrpc.client.XmlRpcClient;
-import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
-
+import org.rhq.enterprise.server.plugins.rhnhosted.certificate.PublicKeyRing;
+import org.rhq.enterprise.server.plugins.rhnhosted.xmlrpc.XmlRpcExecutor;
+import org.rhq.enterprise.server.plugins.rhnhosted.xmlrpc.XmlRpcExecutorFactory;
/**
* @author pkilambi
@@ -46,28 +41,25 @@ import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
*/
public class RHNActivator {
- private String certificateFileName;
private String certificateText;
private String systemid;
- private XmlRpcClient client;
+ private XmlRpcExecutor client;
private final Log log = LogFactory.getLog(RHNActivator.class);
/**
- * RHN Connector Constructor
- * @param systemidIn systemId file path
- * @param certificateIn certificate file path
+ * Constructor
+ * @param systemIdString xml systemid
+ * @param certificateTextIn certificate file path
* @param serverUrlIn hosted server url as a string
- *
+ * @throws Exception
*/
- public RHNActivator(String systemidIn, String certificateIn, String serverUrlIn)
- throws Exception {
-
- this.certificateFileName = certificateIn;
- this.certificateText = FileUtils.readFileToString(new
File(this.certificateFileName));
+ public RHNActivator(String systemIdString, String certificateTextIn, String
serverUrlIn) throws Exception {
+
+ this.certificateText = certificateTextIn;
+ this.systemid = systemIdString;
URL serverUrl = new URL(serverUrlIn);
client = newClient(serverUrl);
- File systemid_file = new File(systemidIn);
- this.systemid = FileUtils.readFileToString(systemid_file);
+
}
/**
@@ -79,24 +71,16 @@ public class RHNActivator {
public RHNActivator(String certificateTextIn, String serverUrlIn) throws Exception {
this.certificateText = certificateTextIn;
- // store the file to local server
- this.writeStringToFile();
URL serverUrl = new URL(serverUrlIn);
client = newClient(serverUrl);
File systemid_file = new File(RHNConstants.DEFAULT_SYSTEM_ID);
this.systemid = FileUtils.readFileToString(systemid_file);
}
- protected XmlRpcClient newClient(URL serverUrl) {
- XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
- config.setServerURL(serverUrl);
- client = new XmlRpcClient();
- client.setConfig(config);
- // Add support for SSL connections to RHN Hosted
- RhnSSLTransportFactory transportFactory = new RhnSSLTransportFactory(client);
- client.setTransportFactory(transportFactory);
- return client;
+ protected XmlRpcExecutor newClient(URL serverUrl) {
+ return XmlRpcExecutorFactory.getClient(serverUrl.toString());
}
+
/**
* Call that invokes the server object and passing in the xmlrpc
* exposed call to activate the rhq server.
@@ -127,32 +111,12 @@ public class RHNActivator {
// this.deleteCertTempFile(this.certificateFileName);
}
- public PublicKeyRing readDefaultKeyRing()
- throws ClassNotFoundException, KeyException, IOException {
+ public PublicKeyRing readDefaultKeyRing() throws ClassNotFoundException,
KeyException, IOException {
InputStream keyringStream = new
FileInputStream(RHNConstants.DEFAULT_WEBAPP_GPG_KEY_RING);
return new PublicKeyRing(keyringStream);
}
/**
- * Stores the certificate text string as a file on the filesystem
- *
- */
- protected void writeStringToFile() throws Exception {
- String tmpDir = System.getProperty("java.io.tmpdir");
-
- this.certificateFileName = tmpDir + "/rhn-entitlement-cert" +
".cert";
-
- FileOutputStream out = new FileOutputStream(this.certificateFileName);
- PrintStream printer = new PrintStream(out);
- try {
- printer.println(this.certificateText);
- }
- finally {
- printer.close();
- }
- }
-
- /**
* Delete the certificate file from the filesystem.
* @param fileName certificate filename
* @return boolean returns delete operation status
@@ -163,22 +127,22 @@ public class RHNActivator {
return f.delete();
}
- public static void main(String[] args) {
+ public static void main(String[] args) throws Exception {
// commandline test
if (args.length > 0) {
- String systemid = args[0];
- String cert = args[1];
+ String systemId = FileUtils.readFileToString(new File(args[0]));
+ String cert = FileUtils.readFileToString(new File(args[1]));
+
String serverUrl = "http://satellite.rhn.redhat.com/rpc/api";
try {
- RHNActivator rhqServer = new RHNActivator(systemid, cert, serverUrl);
+ RHNActivator rhqServer = new RHNActivator(systemId, cert, serverUrl);
rhqServer.processActivation();
System.out.println("Activation Complete");
rhqServer.processDeActivation();
System.out.println("De-Activation Complete");
- }
- catch (Exception e) {
+ } catch (Exception e) {
e.printStackTrace();
}
}
diff --git
a/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/ApacheXmlRpcExecutor.java
b/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/ApacheXmlRpcExecutor.java
index eee13b6..f3c75e2 100644
---
a/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/ApacheXmlRpcExecutor.java
+++
b/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/ApacheXmlRpcExecutor.java
@@ -19,6 +19,8 @@
package org.rhq.enterprise.server.plugins.rhnhosted.xmlrpc;
+import java.util.List;
+
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
@@ -35,4 +37,9 @@ public class ApacheXmlRpcExecutor implements XmlRpcExecutor {
return client.execute(methodName, params);
}
+ @Override
+ public Object execute(String pMethodName, List pParams) throws XmlRpcException {
+ return client.execute(pMethodName, pParams);
+ }
+
}
diff --git
a/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/XmlRpcExecutor.java
b/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/XmlRpcExecutor.java
index d84b402..721b350 100644
---
a/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/XmlRpcExecutor.java
+++
b/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/XmlRpcExecutor.java
@@ -19,6 +19,8 @@
package org.rhq.enterprise.server.plugins.rhnhosted.xmlrpc;
+import java.util.List;
+
import org.apache.xmlrpc.XmlRpcException;
public interface XmlRpcExecutor {
@@ -31,4 +33,12 @@ public interface XmlRpcExecutor {
*/
public Object execute(String methodName, Object[] params) throws XmlRpcException;
+ /** Performs a request with the clients default configuration.
+ * @param pMethodName The method being performed.
+ * @param pParams The parameters.
+ * @return The result object.
+ * @throws XmlRpcException Performing the request failed.
+ */
+ public Object execute(String pMethodName, List pParams) throws XmlRpcException;
+
}
diff --git
a/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/RHNActivatorTest.java
b/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/RHNActivatorTest.java
index aa62ca2..13c56cc 100644
---
a/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/RHNActivatorTest.java
+++
b/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/RHNActivatorTest.java
@@ -21,39 +21,36 @@ package org.rhq.enterprise.server.plugins.rhnhosted;
import junit.framework.TestCase;
-import java.io.File;
-import java.io.IOException;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.StringUtils;
+import org.rhq.enterprise.server.plugins.rhnhosted.xmlrpc.ApacheXmlRpcExecutor;
+import org.rhq.enterprise.server.plugins.rhnhosted.xmlrpc.MockRhnHttpURLConnection;
+import org.rhq.enterprise.server.plugins.rhnhosted.xmlrpc.MockRhnXmlRpcExecutor;
+import org.rhq.enterprise.server.plugins.rhnhosted.xmlrpc.RhnCommTest;
+import org.rhq.enterprise.server.plugins.rhnhosted.xmlrpc.RhnHttpURLConnectionFactory;
public class RHNActivatorTest extends TestCase {
- private static final String TEST_CERT_PATH = "./entitlement-cert.xml";
private static final String TEST_SERVER_URL =
"http://satellite.rhn.redhat.com/rpc/api";
private static final String TEST_SYSTEM_ID = RHNConstants.DEFAULT_SYSTEM_ID;
private RHNActivator rhnObject;
public void setUp() throws Exception {
- rhnObject = new RHNActivator(TEST_SYSTEM_ID, TEST_CERT_PATH, TEST_SERVER_URL);
+ /* OVERRIDE THE XMLRPC CLIENT WITH A MOCK OBJECT */
+ System.setProperty(ApacheXmlRpcExecutor.class.getName(),
MockRhnXmlRpcExecutor.class.getName());
+ System.setProperty(RhnHttpURLConnectionFactory.RHN_MOCK_HTTP_URL_CONNECTION,
MockRhnHttpURLConnection.class
+ .getName());
+
+ rhnObject = new RHNActivator(RhnCommTest.SYSTEM_ID, ENT_CERT, TEST_SERVER_URL);
+
assertNotNull(rhnObject);
- }
+ }
public final void testActivate() throws Exception {
- String systemid = readSystemId();
- String cert = readCertificate();
- System.out.println("systemid and cert are:" + systemid + cert);
- if (StringUtils.isBlank(systemid) || StringUtils.isBlank(cert)) {
- System.out.println("Skipping test since systemid or cert is not
readable");
- return;
- }
boolean success = true;
try {
rhnObject.processActivation();
- }
- catch (Exception e) {
+ } catch (Exception e) {
e.printStackTrace();
success = false;
}
@@ -61,38 +58,32 @@ public class RHNActivatorTest extends TestCase {
}
public final void testDeActivate() throws Exception {
- String systemid = readSystemId();
- String cert = readCertificate();
- if (StringUtils.isBlank(systemid) || StringUtils.isBlank(cert)) {
- System.out.println("Skipping test since systemid or cert is not
readable");
- return;
- }
+ String systemid = RhnCommTest.SYSTEM_ID;
boolean success = true;
try {
rhnObject.processDeActivation();
- }
- catch (Exception e) {
+ } catch (Exception e) {
e.printStackTrace();
success = false;
}
assertEquals(true, success);
}
- protected String readSystemId() throws Exception {
- try {
- return FileUtils.readFileToString(new File(TEST_SYSTEM_ID));
- } catch (IOException e) {
- return "";
- }
- }
-
- protected String readCertificate() throws Exception {
- try {
- return FileUtils.readFileToString(new File(TEST_CERT_PATH));
- } catch (IOException e) {
- return "";
- }
-
- }
+ private static String ENT_CERT = "<?xml version=\"1.0\"
encoding=\"UTF-8\"?>" + "<rhn-cert
version=\"0.1\">"
+ + " <rhn-cert-field
name=\"product\">RHN-SATELLITE-001</rhn-cert-field>"
+ + " <rhn-cert-field name=\"owner\">Test Lab - Base
Organization</rhn-cert-field>"
+ + " <rhn-cert-field name=\"issued\">2009-08-17
00:00:00</rhn-cert-field>"
+ + " <rhn-cert-field name=\"expires\">2010-08-17
00:00:00</rhn-cert-field>"
+ + " <rhn-cert-field
name=\"slots\">10</rhn-cert-field>"
+ + " <rhn-cert-field
name=\"monitoring-slots\">10</rhn-cert-field>"
+ + " <rhn-cert-field
name=\"provisioning-slots\">10</rhn-cert-field>"
+ + " <rhn-cert-field
name=\"virtualization_host\">10</rhn-cert-field>"
+ + " <rhn-cert-field
name=\"virtualization_host_platform\">10</rhn-cert-field>"
+ + " <rhn-cert-field name=\"channel-families\"
quantity=\"10\" family=\"rhel-server\"/>"
+ + " <rhn-cert-field name=\"channel-families\"
quantity=\"10\" family=\"rhel-server-vt\"/>"
+ + " <rhn-cert-field name=\"channel-families\"
quantity=\"10\" family=\"rhn-tools\"/>"
+ + " <rhn-cert-field
name=\"satellite-version\">5.3</rhn-cert-field>"
+ + " <rhn-cert-field
name=\"generation\">2</rhn-cert-field>" + "
<rhn-cert-signature>"
+ + "-----BEGIN PGP SIGNATURE-----" + "-----END PGP
SIGNATURE-----" + "</rhn-cert-signature>" +
"</rhn-cert>";
}
diff --git
a/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/MockRhnXmlRpcExecutor.java
b/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/MockRhnXmlRpcExecutor.java
index 80bc290..5cc7d5e 100644
---
a/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/MockRhnXmlRpcExecutor.java
+++
b/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/MockRhnXmlRpcExecutor.java
@@ -34,15 +34,14 @@ import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
-
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnChannelFamiliesType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnChannelFamilyType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnChannelType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnChannelsType;
-import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnKickstartableTreeType;
-import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnKickstartableTreesType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnKickstartFileType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnKickstartFilesType;
+import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnKickstartableTreeType;
+import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnKickstartableTreesType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnPackageShortType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnPackageType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnPackagesShortType;
@@ -129,7 +128,7 @@ public class MockRhnXmlRpcExecutor implements XmlRpcExecutor {
JAXBElement element = getRhnSatelliteType();
RhnSatelliteType retval = (RhnSatelliteType) element.getValue();
RhnKickstartableTreesType parentKSTree = new RhnKickstartableTreesType();
- List<RhnKickstartableTreeType> ksTreeList =
parentKSTree.getRhnKickstartableTree();
+ List<RhnKickstartableTreeType> ksTreeList =
parentKSTree.getRhnKickstartableTree();
List<String> kstids = (List<String>) params[1];
for (String kid : kstids) {
RhnKickstartableTreeType kstype = new RhnKickstartableTreeType();
@@ -242,4 +241,9 @@ public class MockRhnXmlRpcExecutor implements XmlRpcExecutor {
}
}
+
+ @Override
+ public Object execute(String pMethodName, List pParams) throws XmlRpcException {
+ return execute(pMethodName, pParams.toArray());
+ }
}