java/code/src/com/redhat/rhn/frontend/configuration/tags/ConfigChannelTag.java |
157 +------
java/code/src/com/redhat/rhn/frontend/configuration/tags/test/ConfigChannelTagTest.java |
200 ----------
java/code/src/com/redhat/rhn/frontend/taglibs/IconTag.java |
1
3 files changed, 31 insertions(+), 327 deletions(-)
New commits:
commit 8da6ecedda9ef8297bc8c6c49bb510f77d369111
Author: Tomas Kasparek <tkasparek(a)redhat.com>
Date: Thu Dec 12 16:01:57 2013 +0100
remove obsolete unit test as tag was rewritten
diff --git
a/java/code/src/com/redhat/rhn/frontend/configuration/tags/test/ConfigChannelTagTest.java
b/java/code/src/com/redhat/rhn/frontend/configuration/tags/test/ConfigChannelTagTest.java
deleted file mode 100644
index 1df7aa4..0000000
---
a/java/code/src/com/redhat/rhn/frontend/configuration/tags/test/ConfigChannelTagTest.java
+++ /dev/null
@@ -1,200 +0,0 @@
-/**
- * Copyright (c) 2009--2010 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.configuration.tags.test;
-
-import com.redhat.rhn.common.localization.LocalizationService;
-import com.redhat.rhn.domain.config.ConfigChannelType;
-import com.redhat.rhn.frontend.configuration.tags.ConfigChannelTag;
-import com.redhat.rhn.frontend.configuration.tags.ConfigTagHelper;
-import com.redhat.rhn.testing.RhnBaseTestCase;
-import com.redhat.rhn.testing.RhnMockHttpServletRequest;
-import com.redhat.rhn.testing.RhnMockJspWriter;
-import com.redhat.rhn.testing.TagTestUtils;
-
-import com.mockobjects.helpers.TagTestHelper;
-
-import java.net.URL;
-
-import javax.servlet.jsp.tagext.Tag;
-
-/**
- * ConfigChannelTagTest
- * @version $Rev$
- */
-public class ConfigChannelTagTest extends RhnBaseTestCase {
- /**
- * Called once per test method.
- * @throws Exception if an error occurs during setup.
- */
- protected void setUp() throws Exception {
- super.setUp();
- ConfigChannelTag tag = new ConfigChannelTag();
- RhnMockHttpServletRequest request = new RhnMockHttpServletRequest();
- TagTestHelper tth = TagTestUtils.setupTagTest(tag,
- new URL("http://localhost"),
- request);
- tag.setPageContext(tth.getPageContext());
- }
-
- /** Test tag output for central
- */
- public void testCentral() throws Exception {
-
- String alt = ConfigChannelTag.CENTRAL_ALT_KEY;
- String imgName = ConfigChannelTag.CENTRAL_LIST_ICON;
-
- execTest(0, "bar",
- ConfigChannelType.global().getLabel(),
- false, alt, imgName);
-
- execTest(1, "bar1", "central", false, alt, imgName);
-
- execTest(2, "bar2", "global", false, alt, imgName);
- //also checking case sensititvity
- execTest(2, "bar2", "gloBal", false, alt, imgName);
- execTest(-2, "bar2", "gloBal", false, alt, imgName);
- execTest(2, "bar2", "global", true, alt, imgName);
- }
-
- /** Test tag output for central
- */
- public void testLocal() throws Exception {
-
- String alt = ConfigChannelTag.LOCAL_ALT_KEY;
- String imgName = ConfigChannelTag.LOCAL_LIST_ICON;
- execTest(0, "bar",
- ConfigChannelType.local().getLabel(),
- false, alt, imgName);
- execTest(1, "bar1", "local", false, alt, imgName);
- }
-
- public void testSandbox() throws Exception {
-
- String alt = ConfigChannelTag.SANDBOX_ALT_KEY;
- String imgName = ConfigChannelTag.SANDBOX_LIST_ICON;
- execTest(0, "bar",
- ConfigChannelType.sandbox().getLabel(),
- false, alt, imgName);
- execTest(1, "bar1", "sandbox", false, alt, imgName);
- }
-
- public void testFailure() throws Exception {
-
- ConfigChannelTag tag = new ConfigChannelTag();
- RhnMockHttpServletRequest request = new RhnMockHttpServletRequest();
- TagTestHelper tth = TagTestUtils.setupTagTest(tag,
- new URL("http://localhost"),
- request);
- tag.setPageContext(tth.getPageContext());
- tag.setId(String.valueOf(1));
- tag.setName("FOO");
-
- String type = "FAILURE";
- tag.setType(type);
-
- // ok let's test the tag
- tth.assertDoStartTag(Tag.SKIP_BODY);
- tth.assertDoEndTag(Tag.SKIP_BODY);
- RhnMockJspWriter rout = (RhnMockJspWriter) tth.getPageContext().getOut();
- assertTrue(rout.toString().
- indexOf(ConfigTagHelper.CONFIG_ERROR_ALT_TEXT) > -1);
- assertTrue(rout.toString().
- indexOf(ConfigTagHelper.CONFIG_ERROR_IMG) > -1);
- }
-
- public void execTest(int id, String name,
- String type, boolean nolink,
- String altKey, String imgName) throws Exception {
- ConfigChannelTag tag = new ConfigChannelTag();
- RhnMockHttpServletRequest request = new RhnMockHttpServletRequest();
- TagTestHelper tth = TagTestUtils.setupTagTest(tag,
- new URL("http://localhost"),
- request);
- tag.setPageContext(tth.getPageContext());
- if (id >= 0) {
- tag.setId(String.valueOf(id));
- }
-
- tag.setName(name);
- tag.setType(type);
- tag.setNolink(String.valueOf(nolink));
-
- // ok let's test the tag
- tth.assertDoStartTag(Tag.SKIP_BODY);
- tth.assertDoEndTag(Tag.SKIP_BODY);
-
- RhnMockJspWriter rout = (RhnMockJspWriter) tth.getPageContext().getOut();
-
- assertTrue(rout.toString().indexOf(name) > -1);
- assertFalse(rout.toString().indexOf("alt = \"\"") > -1);
-
- LocalizationService service = LocalizationService.getInstance();
- String alt = service.getMessage(altKey);
- assertTrue(rout.toString().indexOf(alt) > -1);
- assertTrue(rout.toString().indexOf(imgName) > -1);
- if (!nolink && id >= 0) {
- String url = "<a href=\"" + ConfigChannelTag.CHANNEL_URL +
- "?ccid=" + id;
- assertTrue(rout.toString().startsWith(url));
- }
- else {
- assertFalse(rout.toString().startsWith("<a href"));
- }
- }
-
- public void testFunctions() {
- checkFunctions(ConfigChannelTag.CENTRAL_HEADER_ICON,
- ConfigChannelTag.CENTRAL_ALT_KEY,
- "global");
- //also checking case sensititvity
- checkFunctions(ConfigChannelTag.CENTRAL_HEADER_ICON,
- ConfigChannelTag.CENTRAL_ALT_KEY,
- "cenTral");
-
- checkFunctions(ConfigChannelTag.CENTRAL_HEADER_ICON,
- ConfigChannelTag.CENTRAL_ALT_KEY,
- ConfigChannelType.global().getLabel());
-
-
-
- checkFunctions(ConfigChannelTag.LOCAL_HEADER_ICON,
- ConfigChannelTag.LOCAL_ALT_KEY,
- "local");
-
-
- checkFunctions(ConfigChannelTag.LOCAL_HEADER_ICON,
- ConfigChannelTag.LOCAL_ALT_KEY,
- ConfigChannelType.local().getLabel());
-
-
- checkFunctions(ConfigChannelTag.SANDBOX_HEADER_ICON,
- ConfigChannelTag.SANDBOX_ALT_KEY,
- "sandbox");
-
-
- checkFunctions(ConfigChannelTag.SANDBOX_HEADER_ICON,
- ConfigChannelTag.SANDBOX_ALT_KEY,
- ConfigChannelType.sandbox().getLabel());
-
- String url = ConfigChannelTag.makeConfigChannelUrl("" + 1);
- assertTrue(url.indexOf("ccid=1") > -1);
- assertTrue(url.startsWith(ConfigChannelTag.CHANNEL_URL));
- }
-
- private void checkFunctions(String icon, String altKey, String type) {
- assertEquals(altKey, ConfigChannelTag.getAltKeyFor(type));
- assertEquals(icon, ConfigChannelTag.getHeaderIconFor(type));
- }
-}
commit 8d477a93ec7c04b1cb0837b606e50f82b4177a91
Author: Tomas Kasparek <tkasparek(a)redhat.com>
Date: Thu Dec 12 16:01:40 2013 +0100
simplify logic in cfg:channel tag
diff --git
a/java/code/src/com/redhat/rhn/frontend/configuration/tags/ConfigChannelTag.java
b/java/code/src/com/redhat/rhn/frontend/configuration/tags/ConfigChannelTag.java
index 718e2ce..d52cca9 100644
--- a/java/code/src/com/redhat/rhn/frontend/configuration/tags/ConfigChannelTag.java
+++ b/java/code/src/com/redhat/rhn/frontend/configuration/tags/ConfigChannelTag.java
@@ -14,18 +14,15 @@
*/
package com.redhat.rhn.frontend.configuration.tags;
-import com.redhat.rhn.domain.config.ConfigChannelType;
+import com.redhat.rhn.frontend.taglibs.IconTag;
-import org.apache.log4j.Logger;
-
-import java.util.HashMap;
-import java.util.Map;
+import java.io.IOException;
import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.TagSupport;
-
/**
* ConfigChannelTag
* @version $Rev$
@@ -39,20 +36,6 @@ public class ConfigChannelTag extends TagSupport {
private String name;
private String type;
private boolean nolink;
- private static final Logger LOG = Logger.getLogger(ConfigChannelTag.class);
- private static final Map ICON_PATH_RETRIEVER = new HashMap();
-
- public static final String CENTRAL_ALT_KEY = "config.common.globalAlt";
- public static final String LOCAL_ALT_KEY = "config.common.localAlt";
- public static final String SANDBOX_ALT_KEY = "config.common.sandboxAlt";
-
- public static final String CENTRAL_LIST_ICON =
"/img/rhn-listicon-channel.gif";
- public static final String LOCAL_LIST_ICON =
"/img/rhn-listicon-system.gif";
- public static final String SANDBOX_LIST_ICON =
"/img/rhn-listicon-sandbox.gif";
-
- public static final String CENTRAL_HEADER_ICON =
"/img/rhn-config_central.gif";
- public static final String LOCAL_HEADER_ICON =
"/img/rhn-config_system.gif";
- public static final String SANDBOX_HEADER_ICON =
"/img/rhn-config_sandbox.gif";
public static final String CHANNEL_URL =
"/rhn/configuration/ChannelOverview.do";
@@ -67,16 +50,23 @@ public class ConfigChannelTag extends TagSupport {
* {@inheritDoc}
*/
public int doEndTag() throws JspException {
+ StringBuilder result = new StringBuilder();
if (nolink || id == null) {
writeIcon();
- ConfigTagHelper.write(" " + name, pageContext);
+ result.append(name);
}
else {
- ConfigTagHelper.write("<a href=\"" +
- ConfigChannelTag.makeConfigChannelUrl(id) +
- "\">", pageContext);
- writeIcon();
- ConfigTagHelper.write(" " + name + "</a>",
pageContext);
+ result.append("<a href=\"" +
+ ConfigChannelTag.makeConfigChannelUrl(id) +
"\">");
+ result.append(writeIcon());
+ result.append(name + "</a>");
+ }
+ JspWriter writer = pageContext.getOut();
+ try {
+ writer.write(result.toString());
+ }
+ catch (IOException e) {
+ throw new JspException(e);
}
return BodyTagSupport.SKIP_BODY;
}
@@ -118,79 +108,31 @@ public class ConfigChannelTag extends TagSupport {
}
/**
- * Checks to see if no invalid values are specified
- */
- private boolean checkType() {
- try {
- ConfigChannelType.lookup(type);
- return true;
- }
- catch (IllegalArgumentException ie) {
- LOG.warn(ie.getMessage());
- return false;
- }
-
-
- }
-
-
- /**
* @param value the value to set
*/
public void setName(String value) {
this.name = value;
}
- private void writeIcon() throws JspException {
- if (checkType()) {
- Map iconMap = getIconMap();
-
- String imgPath = (String)iconMap.get("LIST_" +
type.toUpperCase());
- String altKey = (String)iconMap.get("KEY_" + type.toUpperCase());
- ConfigTagHelper.writeIcon(imgPath, altKey, pageContext);
+ private String writeIcon() throws JspException {
+ IconTag i = new IconTag();
+ i.setParent(getParent());
+ i.setPageContext(pageContext);
+ if (type.equals("central") || type.equals("global")) {
+ i.setType("header-channel-configuration");
}
- else {
- ConfigTagHelper.writeErrorIcon(pageContext);
+ else if (type.equals("local_override")) {
+ i.setType("header-system");
}
-
- }
-
- private static Map getIconMap() {
- if (ICON_PATH_RETRIEVER.isEmpty()) {
- ICON_PATH_RETRIEVER.put("LIST_LOCAL_OVERRIDE", LOCAL_LIST_ICON);
- ICON_PATH_RETRIEVER.put("HEADER_LOCAL_OVERRIDE",
LOCAL_HEADER_ICON);
- ICON_PATH_RETRIEVER.put("KEY_LOCAL_OVERRIDE", LOCAL_ALT_KEY);
-
- ICON_PATH_RETRIEVER.put("LIST_LOCAL", LOCAL_LIST_ICON);
- ICON_PATH_RETRIEVER.put("HEADER_LOCAL", LOCAL_HEADER_ICON);
- ICON_PATH_RETRIEVER.put("KEY_LOCAL", LOCAL_ALT_KEY);
-
-
- ICON_PATH_RETRIEVER.put("LIST_NORMAL", CENTRAL_LIST_ICON);
- ICON_PATH_RETRIEVER.put("HEADER_NORMAL", CENTRAL_HEADER_ICON);
- ICON_PATH_RETRIEVER.put("KEY_NORMAL", CENTRAL_ALT_KEY);
-
- ICON_PATH_RETRIEVER.put("LIST_CENTRAL", CENTRAL_LIST_ICON);
- ICON_PATH_RETRIEVER.put("HEADER_CENTRAL", CENTRAL_HEADER_ICON);
- ICON_PATH_RETRIEVER.put("KEY_CENTRAL", CENTRAL_ALT_KEY);
-
- ICON_PATH_RETRIEVER.put("LIST_GLOBAL", CENTRAL_LIST_ICON);
- ICON_PATH_RETRIEVER.put("HEADER_GLOBAL", CENTRAL_HEADER_ICON);
- ICON_PATH_RETRIEVER.put("KEY_GLOBAL", CENTRAL_ALT_KEY);
-
- ICON_PATH_RETRIEVER.put("LIST_SERVER_IMPORT", SANDBOX_LIST_ICON);
- ICON_PATH_RETRIEVER.put("HEADER_SERVER_IMPORT",
SANDBOX_HEADER_ICON);
- ICON_PATH_RETRIEVER.put("KEY_SERVER_IMPORT", SANDBOX_ALT_KEY);
-
- ICON_PATH_RETRIEVER.put("LIST_SANDBOX", SANDBOX_LIST_ICON);
- ICON_PATH_RETRIEVER.put("HEADER_SANDBOX", SANDBOX_HEADER_ICON);
- ICON_PATH_RETRIEVER.put("KEY_SANDBOX", SANDBOX_ALT_KEY);
+ else {
+ i.setType("sandbox");
+ i.setTitle(type);
}
-
- return ICON_PATH_RETRIEVER;
+ String result = i.renderStartTag();
+ i.release();
+ return result;
}
-
/**
* Returns the URL to view a config channel
* This method may also be used with the el expression
@@ -204,43 +146,4 @@ public class ConfigChannelTag extends TagSupport {
public static String makeConfigChannelUrl(String ccId) {
return CHANNEL_URL + "?ccid=" + ccId;
}
-
- /**
- * Returns the Header icon image path for a given channel type
- * This method is public static because
- * EL functions defined in a TLD file,
- * need to be public static methods..
- * @param type the config channel type
- * @return the image path
- */
- public static final String getHeaderIconFor(String type) {
- Map map = getIconMap();
- return (String) map.get("HEADER_" + type.toUpperCase());
- }
-
- /**
- * Returns the list icon image path for a given channel type
- * This method is public static because
- * EL functions defined in a TLD file,
- * need to be public static methods..
- * @param type the config channel type
- * @return the image path
- */
- public static final String getListIconFor(String type) {
- Map map = getIconMap();
- return (String) map.get("LIST_" + type.toUpperCase());
- }
-
- /**
- * Returns the Header alt key for a given channel type
- * This method is public static because
- * EL functions defined in a TLD file,
- * need to be public static methods..
- * @param type the config channel type
- * @return the alt key
- */
- public static final String getAltKeyFor(String type) {
- Map map = getIconMap();
- return (String) map.get("KEY_" + type.toUpperCase());
- }
}
diff --git a/java/code/src/com/redhat/rhn/frontend/taglibs/IconTag.java
b/java/code/src/com/redhat/rhn/frontend/taglibs/IconTag.java
index a12b89a..0f871fc 100644
--- a/java/code/src/com/redhat/rhn/frontend/taglibs/IconTag.java
+++ b/java/code/src/com/redhat/rhn/frontend/taglibs/IconTag.java
@@ -103,6 +103,7 @@ public class IconTag extends TagSupport {
icons.put("nav-bullet", "fa fa-caret-right");
icons.put("nav-right", "fa fa-arrow-right");
icons.put("nav-up", "fa fa-caret-up");
+ icons.put("sandbox", "fa spacewalk-icon-sandbox");
icons.put("system-crit", "fa fa-exclamation-circle fa-1-5x
text-danger");
icons.put("system-kickstarting", "fa fa-rocket fa-1-5x");
icons.put("system-locked", "fa fa-1-5x
spacewalk-icon-locked-system");