KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > publication > DublinCoreTest


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 /* $Id: DublinCoreTest.java 42625 2004-03-04 15:45:03Z egli $ */
19
20 package org.apache.lenya.cms.publication;
21
22 import junit.framework.TestCase;
23 import junit.textui.TestRunner;
24
25 import org.apache.lenya.cms.PublicationHelper;
26
27 public class DublinCoreTest extends TestCase {
28
29     private static final String JavaDoc AREA = "authoring";
30     private static final String JavaDoc DOCUMENT_ID = "/tutorial";
31     private static final String JavaDoc LANGUAGE = "de";
32     private static final String JavaDoc CREATOR = "test";
33
34     /**
35      * Constructor for DublinCoreTest.
36      * @param arg0 a test
37      */

38     public DublinCoreTest(String JavaDoc arg0) {
39         super(arg0);
40     }
41
42     /**
43      * The main program.
44      * The parameters are set from the command line arguments.
45      *
46      * @param args The command line arguments.
47      */

48     public static void main(String JavaDoc[] args) {
49         args = PublicationHelper.extractPublicationArguments(args);
50         TestRunner.run(DublinCoreTest.class);
51     }
52
53     /**
54      * Test the fetching, modification and refetching of a dc core object.
55      *
56      * @throws DocumentBuildException if an error occurs
57      * @throws DocumentException if an error occurs
58      */

59     final public void testModifySaveAndReload()
60         throws DocumentBuildException, DocumentException {
61         Publication publication = PublicationHelper.getPublication();
62         DocumentBuilder builder = new DefaultDocumentBuilder();
63         Document doc =
64             builder.buildDocument(
65                 publication,
66                 builder.buildCanonicalUrl(
67                     publication,
68                     AREA,
69                     DOCUMENT_ID,
70                     LANGUAGE));
71         DublinCore dcCore = doc.getDublinCore();
72         String JavaDoc title = dcCore.getTitle();
73         String JavaDoc subject = dcCore.getSubject();
74         String JavaDoc creator = dcCore.getCreator();
75         String JavaDoc dateIssued = dcCore.getDateIssued();
76
77         dcCore.setCreator(CREATOR);
78         dcCore.save();
79
80         Document doc2 =
81             builder.buildDocument(
82                 publication,
83                 builder.buildCanonicalUrl(
84                     publication,
85                     AREA,
86                     DOCUMENT_ID,
87                     LANGUAGE));
88
89         DublinCore dcCore2 = doc2.getDublinCore();
90         assertEquals(title, dcCore2.getTitle());
91         assertEquals(subject, dcCore2.getSubject());
92         assertEquals(dateIssued, dcCore2.getDateIssued());
93         assertFalse(creator.equals(dcCore2.getCreator()));
94         assertEquals(CREATOR, dcCore2.getCreator());
95     }
96
97     /** @see junit.framework.TestCase#setUp() */
98     protected void setUp() throws Exception JavaDoc {
99         if (PublicationHelper.getPublication() == null) {
100             String JavaDoc[] args =
101                 {
102                     "/home/egli/build/jakarta-tomcat-4.1.21-LE-jdk14/webapps/lenya",
103                     "test" };
104             PublicationHelper.extractPublicationArguments(args);
105         }
106     }
107 }
108
Popular Tags