From 8b3e628e601370884331e5040a07c251c65e4146 Mon Sep 17 00:00:00 2001
From: Colin Coe <colin.coe@gmail.com>
Date: Sun, 5 Oct 2008 16:39:31 +0800
Subject: [PATCH] Add JUnit tests for get/setCustomOptions

---
 .../kickstart/profile/test/ProfileHandlerTest.java |   81 ++++++++++++++++++++
 1 files changed, 81 insertions(+), 0 deletions(-)
 create mode 100644 java/code/src/com/redhat/rhn/frontend/xmlrpc/kickstart/profile/test/ProfileHandlerTest.java

diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/kickstart/profile/test/ProfileHandlerTest.java b/java/code/src/com/redhat/rhn/frontend/xmlrpc/kickstart/profile/test/ProfileHandlerTest.java
new file mode 100644
index 0000000..1f46dc9
--- /dev/null
+++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/kickstart/profile/test/ProfileHandlerTest.java
@@ -0,0 +1,81 @@
+/**
+ * Copyright (c) 2008 Red Hat, Inc.
+ *
+ * This software is licensed to you under the GNU General Public License,
+ * version 2 (GPLv2). There is NO WARRANTY for this software, express or
+ * implied, including the implied warranties of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+ * along with this software; if not, see
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+ * 
+ * Red Hat trademarks are not licensed under GPLv2. No permission is
+ * granted to use or replicate Red Hat trademarks that are incorporated
+ * in this software or its documentation. 
+ */
+
+package com.redhat.rhn.frontend.xmlrpc.kickstart.profile.test;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import com.redhat.rhn.domain.channel.Channel;
+import com.redhat.rhn.domain.channel.test.ChannelFactoryTest;
+import com.redhat.rhn.domain.kickstart.KickstartData;
+import com.redhat.rhn.domain.kickstart.KickstartFactory;
+import com.redhat.rhn.domain.kickstart.KickstartableTree;
+import com.redhat.rhn.domain.kickstart.test.KickstartableTreeTest;
+import com.redhat.rhn.frontend.xmlrpc.kickstart.KickstartHandler;
+import com.redhat.rhn.frontend.xmlrpc.kickstart.profile.ProfileHandler;
+import com.redhat.rhn.frontend.xmlrpc.test.BaseHandlerTestCase;
+import com.redhat.rhn.testing.TestUtils;
+
+
+/**
+ * @author paji
+ *
+ */
+public class ProfileHandlerTest  extends BaseHandlerTestCase {
+    
+    private ProfileHandler handler = new ProfileHandler();
+    
+    public void testCustomOptions() throws Exception {
+        
+        KickstartData newProfile = createProfile();
+        List<String> options = new ArrayList<String>();
+
+        options.add("Java");
+        options.add("is");
+        options.add("the");
+        options.add("new");
+        options.add("COBOL");
+
+        assertEquals(handler.setCustomOptions(adminKey, newProfile.getLabel(), 
+                options), 1);
+
+        Object[] results = handler.getCustomOptions(adminKey, newProfile.getLabel());
+        Integer countOpt = 0;
+        for (Object opt : results) {
+            countOpt++;
+        }
+        
+        assertTrue(countOpt == 5);
+    }
+
+    private KickstartData createProfile() throws Exception {
+        KickstartHandler kh = new KickstartHandler();
+        Channel baseChan = ChannelFactoryTest.createTestChannel(admin);
+        KickstartableTree testTree = KickstartableTreeTest.
+            createTestKickstartableTree(baseChan);
+
+        String profileLabel = "new-ks-profile" + TestUtils.randomString();
+        kh.createProfile(adminKey, profileLabel, "none",
+                testTree.getLabel(), "localhost", "rootpw");
+
+        KickstartData newKsProfile = KickstartFactory.lookupKickstartDataByLabelAndOrgId(
+                profileLabel, admin.getOrg().getId());
+        assertNotNull(newKsProfile);
+        assertTrue(newKsProfile.getCommand("url").getArguments().contains("http"));
+        return newKsProfile;
+    }
+
+}
-- 
1.5.5.1

