001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.om.page;
018:
019: // Java imports
020: import java.util.Iterator;
021:
022: import junit.framework.Test;
023: import junit.framework.TestCase;
024: import junit.framework.TestSuite;
025:
026: import org.apache.jetspeed.om.page.psml.FragmentImpl;
027: import org.apache.jetspeed.om.page.psml.PageImpl;
028:
029: /**
030: * TestMarshalPsml
031: *
032: * @author <a href="taylor@apache.org">David Sean Taylor</a>
033: * @version $Id: TestPageObjectModel.java 516448 2007-03-09 16:25:47Z ate $
034: */
035: public class TestPageObjectModel extends TestCase {
036:
037: /**
038: * Defines the testcase name for JUnit.
039: *
040: * @param name the testcase's name.
041: */
042: public TestPageObjectModel(String name) {
043: super (name);
044: }
045:
046: /**
047: * Start the tests.
048: *
049: * @param args the arguments. Not used
050: */
051: public static void main(String args[]) {
052: junit.awtui.TestRunner
053: .main(new String[] { TestPageObjectModel.class
054: .getName() });
055: }
056:
057: public void setup() {
058: System.out
059: .println("Setup: Testing Page Object Model Implementation");
060: }
061:
062: /**
063: * Creates the test suite.
064: *
065: * @return a test suite (<code>TestSuite</code>) that includes all methods
066: * starting with "test"
067: */
068: public static Test suite() {
069: // All methods starting with "test" will be executed in the test suite.
070: return new TestSuite(TestPageObjectModel.class);
071: }
072:
073: private Page buildBasePage() {
074: PageImpl page = new PageImpl();
075: page.setId("MyPageID");
076:
077: FragmentImpl frag = new FragmentImpl();
078: frag.setId("Frag1");
079: frag.setType(Fragment.LAYOUT);
080:
081: page.setRootFragment(frag);
082:
083: return page;
084: }
085:
086: public void testBasicPage() throws Exception {
087: System.out.println("Testing simple Page creation");
088:
089: Page page = buildBasePage();
090: assertTrue(page.getId().equals("MyPageID"));
091: Fragment root = page.getRootFragment();
092: assertNotNull(root);
093: assertTrue(root.getId().equals("Frag1"));
094: assertTrue(root.getType().equals(Fragment.LAYOUT));
095: assertNull(root.getTitle());
096: }
097:
098: public void testFragmentManipulation() throws Exception {
099: System.out.println("Testing Fragments manipulation");
100:
101: // Build a page with a few fragments
102: Page page = buildBasePage();
103: Fragment root = page.getRootFragment();
104: assertNotNull(root.getFragments());
105:
106: FragmentImpl frag1 = new FragmentImpl();
107: frag1.setId("F1");
108: frag1.setType(Fragment.PORTLET);
109: frag1.setName("Portlet1");
110: root.getFragments().add(frag1);
111:
112: FragmentImpl frag2 = new FragmentImpl();
113: frag2.setId("F2");
114: frag2.setType(Fragment.LAYOUT);
115: frag2.setName("TwoColumns");
116: frag2.setDecorator("test");
117:
118: FragmentImpl frag3 = new FragmentImpl();
119: frag3.setId("F3");
120: frag3.setType(Fragment.PORTLET);
121: frag3.setName("Portlet3");
122: frag3.setDecorator("test");
123: frag3.setState("minimized");
124: frag2.getFragments().add(frag3);
125: root.getFragments().add(frag2);
126:
127: //Check the construct
128: assertTrue(root.getFragments().size() == 2);
129: Iterator i = root.getFragments().iterator();
130: FragmentImpl f = (FragmentImpl) i.next();
131: assertNotNull(f);
132: assertTrue(f.getName().equals("Portlet1"));
133: assertTrue(f.getType().equals(Fragment.PORTLET));
134: assertTrue(f.getId().equals("F1"));
135: assertNull(f.getTitle());
136: assertNull(f.getDecorator());
137: assertNull(f.getState());
138: assertTrue(f.getFragments().size() == 0);
139: f = (FragmentImpl) i.next();
140: assertNotNull(f);
141: assertTrue(f.getName().equals("TwoColumns"));
142: assertTrue(f.getType().equals(Fragment.LAYOUT));
143: assertTrue(f.getFragments().size() == 1);
144: assertTrue(f.getDecorator().equals("test"));
145: assertTrue(f.getFragments().size() == 1);
146: i = f.getFragments().iterator();
147: frag1 = (FragmentImpl) i.next();
148: assertNotNull(frag1);
149: assertTrue(frag1.getName().equals("Portlet3"));
150: assertTrue(frag1.getType().equals(Fragment.PORTLET));
151:
152: //Now change the inner child to a new portlet
153: frag2 = new FragmentImpl();
154: frag2.setId("FR4");
155: frag2.setType(Fragment.PORTLET);
156: frag2.setName("P4");
157:
158: frag3 = (FragmentImpl) page.getFragmentById("F3");
159: assertNotNull(frag3);
160: f.getFragments().remove(frag3);
161: frag3 = (FragmentImpl) page.getFragmentById("F3");
162: assertNull(frag3);
163: f.getFragments().add(frag2);
164: assertTrue(f.getFragments().size() == 1);
165: f = (FragmentImpl) f.getFragments().get(0);
166: assertNotNull(f);
167: assertTrue(f.getName().equals("P4"));
168: }
169: }
|