testskinaggregation.java
来自「jetspeed源代码」· Java 代码 · 共 694 行 · 第 1/2 页
JAVA
694 行
/*
* Copyright 2000-2001,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jetspeed.services.portaltoolkit;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.commons.lang.exception.NestableException;
import org.apache.jetspeed.om.profile.IdentityElement;
import org.apache.jetspeed.om.profile.PSMLDocument;
import org.apache.jetspeed.om.profile.Portlets;
import org.apache.jetspeed.om.profile.Skin;
import org.apache.jetspeed.om.profile.psml.PsmlEntry;
import org.apache.jetspeed.om.profile.psml.PsmlSkin;
import org.apache.jetspeed.portal.Portlet;
import org.apache.jetspeed.portal.PortletSet;
import org.apache.jetspeed.services.PortalToolkit;
import org.apache.jetspeed.test.HeadlessBaseTest;
import org.apache.turbine.services.TurbineServices;
import org.apache.turbine.services.resources.ResourceService;
/**
* @author <a href="mailto:sweaver@rippe.com">Scott Weaver</a>
* Tests different use cases of what happens when skins are requested
* /applied.
*
*/
public class TestSkinAggregation extends HeadlessBaseTest
{
public static String SKIN_TEST_PATH = "skin.test";
public static String SKIN_TEST2_PATH = "skin.test2";
public static String SKIN_TEST3_PATH = "skin.test3";
public static String SKIN_TEST4_PATH = "skin.test4";
private File prof1;
private File prof2;
private File prof3;
private File prof4;
private String defaultSkin;
public TestSkinAggregation(String name)
{
super(name);
}
/**
* 1) no skin ref in PSML
* RESULT: uses default skin
*
* This tests to see that, when no skin is defined, the default skin is
* used.
*/
public void testCase1()
{
printDivider();
print("Description: No skin set in PSML ");
print("RESULT: All portlets use the system default skin.");
print("Checking test case 1...");
File file = createTestProfile(prof1);
PSMLDocument doc = getDocumentFromPath(file.getPath());
Portlets portlets = doc.getPortlets();
print("Portlets loaded as: " + portlets);
// checkSkinPresence(portlets, null);
print("Using the PortalToolkit. All Portlets and PsmlEntries (individual portlets) ");
print("should now be using the system default skin, " + this.defaultSkin);
PortletSet pSet = PortalToolkit.getSet(portlets);
assertNotNull(pSet);
// Checking if we are at the root
isRoot(pSet);
checkPortletSkinValues(pSet, new HashMap(), doc);
print("Saving test document...");
saveDocument(doc);
printOk();
print("Re-run check to make sure that the default setting did not get written...");
PSMLDocument doc2 = getDocumentFromPath(file.getPath());
Portlets portlets2 = doc.getPortlets();
PortletSet pSet2 = PortalToolkit.getSet(portlets2);
checkPortletSkinValues(pSet2, new HashMap(), doc2);
printDivider();
}
/**
* Checks if the file path of skin.test exists and is accessable
*/
public void testLoadSkinPath()
{
printDivider();
print("Checking skin test profile...");
assertTrue(prof1.exists());
assertTrue(prof2.exists());
print("Found skin test profile at: " + prof1.getPath());
printDivider();
}
/**
* 1) no skin ref in PSML
* RESULT: uses default skin
*
* This tests to see that, when no skin is defined, the default skin is
* used.
*/
public void testCase2()
{
printDivider();
print("Description: Skin set at root level, skin set in any children.");
print("RESULT: All portlets use the root level skin");
print("Checking test case 2...");
File file = createTestProfile(prof2);
PSMLDocument doc = getDocumentFromPath(file.getPath());
Portlets portlets = doc.getPortlets();
print("Portlets loaded as: " + portlets);
print("Save and re-open document as if it were being loaded for the first time...");
saveDocument(doc);
// re-load everything...
doc = null;
doc = getDocumentFromPath(file.getPath());
portlets = doc.getPortlets();
print("Using the PortalToolkit. All Portlets and PsmlEntries (individual portlets) ");
PortletSet pSet = PortalToolkit.getSet(portlets);
assertNotNull(pSet);
// Checking if we are at the root
isRoot(pSet);
HashMap settingsMap = new HashMap();
settingsMap.put(portlets.getId(), new MatchSettings(false, false, "grey", true));
settingsMap.put("02", new MatchSettings(false, true, null, false));
settingsMap.put("03", new MatchSettings(false, true, null, false));
settingsMap.put("04", new MatchSettings(false, true, null, false));
settingsMap.put("05", new MatchSettings(false, true, null, false));
settingsMap.put("06", new MatchSettings(false, true, null, false));
settingsMap.put("07", new MatchSettings(false, true, null, false));
settingsMap.put("08", new MatchSettings(false, true, null, false));
checkPortletSkinValues(pSet, settingsMap, doc);
printOk();
printDivider();
}
/**
* Case 3
*/
public void testCase3()
{
printDivider();
print("Description: Skin set at top level, and skin set in a child portlet ");
print("and in a child PortletSet.");
print("RESULT: Un-assigned portlets get the top skin. Assigned portlets get there assigned skin. ");
print("Assigned PortletSets use assigned skin and so do their children.");
print("");
print("Checking test case 3...");
File file = createTestProfile(prof3);
PSMLDocument doc = getDocumentFromPath(file.getPath());
Portlets portlets = doc.getPortlets();
print("Portlets loaded as: " + portlets);
print("Save and re-open document as if it were being loaded for the first time...");
saveDocument(doc);
// re-load everything...
doc = null;
doc = getDocumentFromPath(file.getPath());
portlets = doc.getPortlets();
print("Using the PortalToolkit. All Portlets and PsmlEntries (individual portlets) ");
PortletSet pSet = PortalToolkit.getSet(portlets);
assertNotNull(pSet);
// Checking if we are at the root
isRoot(pSet);
HashMap settingsMap = new HashMap();
settingsMap.put("01", new MatchSettings(false, false, "grey", true));
settingsMap.put("02", new MatchSettings(false, true, null, false));
settingsMap.put("03", new MatchSettings(false, false, "BorderedTitleStylesOnly", true));
settingsMap.put("04", new MatchSettings(false, false, "StylesOnly", true));
settingsMap.put("05", new MatchSettings(false, true, null, false));
settingsMap.put("06", new MatchSettings(false, true, null, false));
settingsMap.put("07", new MatchSettings(false, true, null, false));
settingsMap.put("08", new MatchSettings(false, true, null, false));
checkPortletSkinValues(pSet, settingsMap, doc);
printOk();
printDivider();
}
/**
* Case 4
*/
public void testCase4()
{
printDivider();
print("Description: Skin NOT set at top level, and skin set in a child portlet ");
print("and in a child PortletSet.");
print("RESULT: Un-assigned portlets use the system default skin. Assigned portlets get there assigned skin. ");
print("Assigned PortletSets use assigned skin and so do their children.");
print("");
print("Checking test case 4...");
File file = createTestProfile(prof4);
PSMLDocument doc = getDocumentFromPath(file.getPath());
Portlets portlets = doc.getPortlets();
print("Portlets loaded as: " + portlets);
print("Save and re-open document as if it were being loaded for the first time...");
saveDocument(doc);
// re-load everything...
doc = null;
doc = getDocumentFromPath(file.getPath());
portlets = doc.getPortlets();
print("Using the PortalToolkit. All Portlets and PsmlEntries (individual portlets) ");
PortletSet pSet = PortalToolkit.getSet(portlets);
assertNotNull(pSet);
// Checking if we are at the root
isRoot(pSet);
HashMap settingsMap = new HashMap();
settingsMap.put("01", new MatchSettings(true, false, null, false));
settingsMap.put("02", new MatchSettings(false, false, "grey", true));
settingsMap.put("03", new MatchSettings(false, true, null, false));
settingsMap.put("04", new MatchSettings(false, false, null, false));
settingsMap.put("05", new MatchSettings(true, true, null, false));
settingsMap.put("06", new MatchSettings(false, false, "StylesOnly", true));
settingsMap.put("07", new MatchSettings(true, true, null, false));
settingsMap.put("08", new MatchSettings(true, true, null, false));
checkPortletSkinValues(pSet, settingsMap, doc);
printOk();
printDivider();
}
/**
* Case 5
*/
public void testCase5()
{
printDivider();
print("Description: Test that, when setting the root skin and saving that no other ");
print("Portlets get a skin written.");
print("RESULT: Only the root is assigned the selected skin");
print("");
print("Checking test case 5...");
File file = createTestProfile(prof1);
PSMLDocument doc = getDocumentFromPath(file.getPath());
Portlets portlets = doc.getPortlets();
print("Portlets loaded as: " + portlets);
print("Directly setting the rootSet to a \"grey\"...");
Skin rootSkin = new PsmlSkin();
rootSkin.setName("grey");
portlets.setSkin(rootSkin);
print("Save and re-open document as if it were being loaded for the first time...");
saveDocument(doc);
// re-load everything...
doc = null;
doc = getDocumentFromPath(file.getPath());
portlets = doc.getPortlets();
print("Using the PortalToolkit. All Portlets and PsmlEntries (individual portlets) ");
PortletSet pSet = PortalToolkit.getSet(portlets);
assertNotNull(pSet);
// Checking if we are at the root
isRoot(pSet);
HashMap settingsMap = new HashMap();
settingsMap.put("01", new MatchSettings(true, false, "grey", true));
checkPortletSkinValues(pSet, settingsMap, doc);
printOk();
printDivider();
}
/**
* Walks the PSML document tree and checks each Portlet/PortletSet
* for correct skin settings based on the MatchSettings provided.
*/
protected void checkPortletSkinValues(PortletSet pSet, HashMap settingsMap, PSMLDocument doc)
{
// Check that we are using the default skin as defined by the system
performCheck(pSet, doc, null, (MatchSettings) settingsMap.get(pSet.getID()), null);
Enumeration enum = pSet.getPortlets();
while (enum.hasMoreElements())
{
PortletSet subSet = (PortletSet) enum.nextElement();
performCheck(subSet, doc, pSet, (MatchSettings) settingsMap.get(subSet.getID()), " |--- ");
Enumeration singleEnum = subSet.getPortlets();
print(" |--- Checking individual portlets for PortletSet " + getNameTag(subSet) + "...");
while (singleEnum.hasMoreElements())
{
Portlet portlet = (Portlet) singleEnum.nextElement();
performCheck(portlet, doc, subSet, (MatchSettings) settingsMap.get(portlet.getID()), " | |--- ");
}
}
}
protected void isRoot(PortletSet pSet)
{
print("Checking PortletSet is root...");
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?