001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: TestCmfProperty.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.cmf;
009:
010: import com.uwyn.rife.cmf.dam.exceptions.ContentManagerException;
011: import com.uwyn.rife.cmf.transform.ImageContentTransformer;
012: import junit.framework.TestCase;
013:
014: import java.awt.*;
015: import java.util.Map;
016:
017: public class TestCmfProperty extends TestCase {
018: public TestCmfProperty(String name) {
019: super (name);
020: }
021:
022: public void testInstantiation() {
023: CmfProperty property = new CmfProperty("property");
024: assertFalse(property.isListed());
025: assertEquals(-1, property.getPosition());
026: assertFalse(property.hasPosition());
027: assertNull(property.getMimeType());
028: assertFalse(property.hasMimeType());
029: assertFalse(property.isAutoRetrieved());
030: assertFalse(property.isFragment());
031: assertFalse(property.hasName());
032: assertNull(property.getName());
033: assertFalse(property.isOrdinal());
034: assertNull(property.getOrdinalRestriction());
035: assertFalse(property.hasOrdinalRestriction());
036: assertNull(property.getContentAttributes());
037: assertNull(property.getTransformer());
038: assertFalse(property.hasTransformer());
039: assertNull(property.getCachedLoadedData());
040: }
041:
042: public void testListed() {
043: CmfProperty property = new CmfProperty("property");
044: assertSame(property, property.listed(true));
045: assertTrue(property.isListed());
046: property.setListed(false);
047: assertFalse(property.isListed());
048: }
049:
050: public void testPosition() {
051: CmfProperty property = new CmfProperty("property");
052: assertSame(property, property.position(9));
053: assertEquals(9, property.getPosition());
054: assertTrue(property.hasPosition());
055: property.setPosition(-1);
056: assertEquals(-1, property.getPosition());
057: assertFalse(property.hasPosition());
058: }
059:
060: public void testMimeType() {
061: CmfProperty property = new CmfProperty("property");
062: property.setPersistent(true);
063: property.setDisplayedRaw(false);
064: assertSame(property, property.mimeType(MimeType.IMAGE_GIF));
065: assertEquals(MimeType.IMAGE_GIF, property.getMimeType());
066: assertTrue(property.hasMimeType());
067: assertFalse(property.isPersistent());
068: assertTrue(property.isDisplayedRaw());
069: property.setMimeType(null);
070: assertNull(property.getMimeType());
071: assertFalse(property.hasMimeType());
072: }
073:
074: public void testAutoRetrieved() {
075: CmfProperty property = new CmfProperty("property");
076: assertSame(property, property.autoRetrieved(true));
077: assertTrue(property.isAutoRetrieved());
078: property.setAutoRetrieved(false);
079: assertFalse(property.isAutoRetrieved());
080: }
081:
082: public void testName() {
083: CmfProperty property = new CmfProperty("property");
084: property.setName("myname.gif");
085: assertTrue(property.hasName());
086: assertEquals("myname.gif", property.getName());
087: assertSame(property, property.name("anothername.png"));
088: assertTrue(property.hasName());
089: assertEquals("anothername.png", property.getName());
090: property.name(null);
091: assertFalse(property.hasName());
092: assertNull(property.getName());
093: }
094:
095: public void testPersistent() {
096: CmfProperty property = new CmfProperty("property");
097: property.setPersistent(true);
098: assertTrue(property.isPersistent());
099: property.setPersistent(false);
100: assertFalse(property.isPersistent());
101: property.mimeType(MimeType.IMAGE_GIF);
102: try {
103: property.setPersistent(true);
104: fail();
105: } catch (IllegalArgumentException e) {
106: assertFalse(property.isPersistent());
107: }
108: property.setPersistent(false);
109: assertFalse(property.isPersistent());
110: }
111:
112: public void testDisplayedRaw() {
113: CmfProperty property = new CmfProperty("property");
114: property.setDisplayedRaw(true);
115: assertTrue(property.isDisplayedRaw());
116: property.setDisplayedRaw(false);
117: assertFalse(property.isDisplayedRaw());
118: property.mimeType(MimeType.IMAGE_GIF);
119: try {
120: property.setDisplayedRaw(false);
121: fail();
122: } catch (IllegalArgumentException e) {
123: assertTrue(property.isDisplayedRaw());
124: }
125: property.setDisplayedRaw(true);
126: assertTrue(property.isDisplayedRaw());
127: }
128:
129: public void testFragment() {
130: CmfProperty property = new CmfProperty("property");
131: assertSame(property, property.fragment(true));
132: assertTrue(property.isFragment());
133: property.setFragment(false);
134: assertFalse(property.isFragment());
135: }
136:
137: public void testOrdinal() {
138: CmfProperty property = new CmfProperty("property");
139: assertSame(property, property.ordinal(true));
140: assertTrue(property.isOrdinal());
141: property.setOrdinal(false);
142: assertFalse(property.isOrdinal());
143: }
144:
145: public void testOrdinalRestriction() {
146: CmfProperty property = new CmfProperty("property");
147: assertSame(property, property.ordinal(true, "restriction"));
148: assertTrue(property.isOrdinal());
149: assertTrue(property.hasOrdinalRestriction());
150: assertEquals("restriction", property.getOrdinalRestriction());
151: property.setOrdinal(false);
152: assertFalse(property.isOrdinal());
153: assertFalse(property.hasOrdinalRestriction());
154: assertNull(property.getOrdinalRestriction());
155: assertSame(property, property.ordinal(true, "restriction"));
156: assertSame(property, property.ordinal(false, "restriction2"));
157: assertFalse(property.hasOrdinalRestriction());
158: assertNull(property.getOrdinalRestriction());
159: }
160:
161: public void testContentAttribute() {
162: CmfProperty property = new CmfProperty("property");
163: assertSame(property, property.contentAttribute("attribute",
164: true));
165: assertEquals("true", property.getContentAttributes().get(
166: "attribute"));
167: assertSame(property, property
168: .contentAttribute("attribute", 'K'));
169: assertEquals("K", property.getContentAttributes().get(
170: "attribute"));
171: assertSame(property, property.contentAttribute("attribute",
172: (byte) 24));
173: assertEquals("24", property.getContentAttributes().get(
174: "attribute"));
175: assertSame(property, property.contentAttribute("attribute",
176: (short) 213));
177: assertEquals("213", property.getContentAttributes().get(
178: "attribute"));
179: assertSame(property, property.contentAttribute("attribute",
180: 1243876));
181: assertEquals("1243876", property.getContentAttributes().get(
182: "attribute"));
183: assertSame(property, property.contentAttribute("attribute",
184: 8692322879L));
185: assertEquals("8692322879", property.getContentAttributes().get(
186: "attribute"));
187: assertSame(property, property.contentAttribute("attribute",
188: 6872.23f));
189: assertEquals("6872.23", property.getContentAttributes().get(
190: "attribute"));
191: assertSame(property, property.contentAttribute("attribute",
192: 9249273.13d));
193: assertEquals("9249273.13", property.getContentAttributes().get(
194: "attribute"));
195: assertSame(property, property.contentAttribute("attribute",
196: "somestring"));
197: assertEquals("somestring", property.getContentAttributes().get(
198: "attribute"));
199: }
200:
201: public void testTransformer() {
202: CmfProperty property = new CmfProperty("property");
203: ImageContentTransformer transformer = new ImageContentTransformer() {
204: public Image transform(Image data,
205: Map<String, String> attributes)
206: throws ContentManagerException {
207: return data;
208: }
209: };
210: assertSame(property, property.transformer(transformer));
211: assertEquals(transformer, property.getTransformer());
212: assertTrue(property.hasTransformer());
213: property.setTransformer(null);
214: assertNull(property.getTransformer());
215: assertFalse(property.hasTransformer());
216: }
217:
218: public void testCachedLoadedData() {
219: CmfProperty property = new CmfProperty("property");
220: Object cache = new Object();
221: property.setCachedLoadedData(cache);
222: assertSame(cache, property.getCachedLoadedData());
223: property.setCachedLoadedData(null);
224: assertNull(property.getCachedLoadedData());
225: }
226: }
|