You are viewing a plain text version of this content. The canonical link for it is here.
Posted to doxia-commits@maven.apache.org by lt...@apache.org on 2009/04/07 13:14:49 UTC
svn commit: r762692 - in
/maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/document:
./ DocumentModelTest.java
Author: ltheussl
Date: Tue Apr 7 11:14:49 2009
New Revision: 762692
URL: http://svn.apache.org/viewvc?rev=762692&view=rev
Log:
Test DocumentModel
Added:
maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/document/
maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/document/DocumentModelTest.java (with props)
Added: maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/document/DocumentModelTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/document/DocumentModelTest.java?rev=762692&view=auto
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/document/DocumentModelTest.java (added)
+++ maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/document/DocumentModelTest.java Tue Apr 7 11:14:49 2009
@@ -0,0 +1,359 @@
+package org.apache.maven.doxia.document;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.maven.doxia.document.io.xpp3.DocumentXpp3Reader;
+import org.apache.maven.doxia.document.io.xpp3.DocumentXpp3Writer;
+
+import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.ReaderFactory;
+import org.codehaus.plexus.util.WriterFactory;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+/**
+ * Test DocumentModel.
+ *
+ * @author ltheussl
+ */
+public class DocumentModelTest
+ extends PlexusTestCase
+{
+ /**
+ * Test DocumentModel.
+ *
+ * @throws Exception if any.
+ */
+ public void testDocumentModel()
+ throws Exception
+ {
+ DocumentModel model = getModel();
+ verifyModel( model );
+
+ DocumentModel copy = writeAndRecover( model );
+ verifyModel( copy );
+ assertTrue( copy.equals( model ) );
+ }
+
+ private DocumentModel getModel()
+ {
+ DocumentModel model = new DocumentModel();
+
+ model.setOutputName( "outputName" );
+ model.setModelEncoding( "ISO-8859-1" );
+ model.setCover( getDocumentCover() );
+ model.setToc( getDocumentToc() );
+ model.setMeta( getDocumentMeta() );
+
+ return model ;
+ }
+
+ private void verifyModel( DocumentModel model )
+ {
+ assertTrue( model.equals( model ) );
+ assertFalse( model.equals( null ) );
+ assertTrue ( model.hashCode() != 0 );
+ assertTrue( model.toString().length() > 0 );
+
+ assertEquals( "outputName", model.getOutputName() );
+ //assertEquals( "ISO-8859-1", model.getModelEncoding() ); // MODELLO-189
+ verifyDocumentCover( model.getCover() );
+ verifyDocumentTOC( model.getToc() );
+ verifyDocumentMeta( model.getMeta() );
+ }
+
+ private DocumentAuthor getAuthor( int i )
+ {
+ DocumentAuthor author = new DocumentAuthor();
+
+ author.setCity( "city" + i );
+ author.setCompanyName( "companyName" + i );
+ author.setCountry( "country" + i );
+ author.setEmail( "email" + i );
+ author.setFaxNumber( "faxNumber" + i );
+ author.setFirstName( "firstName" + i );
+ author.setInitials( "initials" + i );
+ author.setLastName( "lastName" + i );
+ author.setPhoneNumber( "phoneNumber" + i );
+ author.setPosition( "position" + i );
+ author.setPostalCode( "postalCode" + i );
+ author.setState( "state" + i );
+ author.setStreet( "street" + i );
+ author.setTitle( "title" + i );
+
+ return author;
+ }
+
+ private void verifyAuthor( DocumentAuthor documentAuthor, int i )
+ {
+ assertEquals( "city" + i, documentAuthor.getCity() );
+ assertEquals( "companyName" + i, documentAuthor.getCompanyName() );
+ assertEquals( "country" + i, documentAuthor.getCountry() );
+ assertEquals( "email" + i, documentAuthor.getEmail() );
+ assertEquals( "faxNumber" + i, documentAuthor.getFaxNumber() );
+ assertEquals( "firstName" + i, documentAuthor.getFirstName() );
+ assertEquals( "initials" + i, documentAuthor.getInitials() );
+ assertEquals( "lastName" + i, documentAuthor.getLastName() );
+ assertEquals( "phoneNumber" + i, documentAuthor.getPhoneNumber() );
+ assertEquals( "position" + i, documentAuthor.getPosition() );
+ assertEquals( "postalCode" + i, documentAuthor.getPostalCode() );
+ assertEquals( "state" + i, documentAuthor.getState() );
+ assertEquals( "street" + i, documentAuthor.getStreet() );
+ assertEquals( "title" + i, documentAuthor.getTitle() );
+ }
+
+ private DocumentCover getDocumentCover()
+ {
+ DocumentCover cover = new DocumentCover();
+ cover.addAuthor( getAuthor( 1 ) );
+ cover.setCompanyLogo( "companyLogo" );
+ cover.setCompanyName( "companyName" );
+ cover.setCoverDate( new Date( 0L ) );
+ cover.setCoverSubTitle( "coverSubTitle" );
+ cover.setCoverTitle( "coverTitle" );
+ cover.setCoverType( "coverType" );
+ cover.setCoverVersion( "coverVersion" );
+ cover.setProjectLogo( "projectLogo" );
+ cover.setProjectName( "projectName" );
+
+ return cover;
+ }
+
+ private void verifyDocumentCover( DocumentCover cover )
+ {
+ List authors = cover.getAuthors();
+ assertEquals( 1, authors.size() );
+ verifyAuthor( (DocumentAuthor) authors.get( 0 ), 1 );
+ assertEquals( "companyLogo", cover.getCompanyLogo() );
+ assertEquals( "companyName", cover.getCompanyName() );
+ assertEquals( 0L, cover.getCoverDate().getTime() );
+ assertEquals( "coverSubTitle", cover.getCoverSubTitle() );
+ assertEquals( "coverTitle", cover.getCoverTitle() );
+ assertEquals( "coverType", cover.getCoverType() );
+ assertEquals( "coverVersion", cover.getCoverVersion() );
+ assertEquals( "projectLogo", cover.getProjectLogo() );
+ assertEquals( "projectName", cover.getProjectName() );
+ }
+
+ private DocumentStatistic getDocumentStatistic()
+ {
+ DocumentStatistic statistic = new DocumentStatistic();
+
+ statistic.setCharacterCount( 2L );
+ statistic.setDrawCount( 3L );
+ statistic.setFrameCount( 4L );
+ statistic.setImageCount( 5L );
+ statistic.setNonWhitespaceCharacterCount( 6L );
+ statistic.setObjectCount( 1L );
+ statistic.setOleObjectCount( 8L );
+ statistic.setPageCount( 7L );
+ statistic.setParagraphCount( 5L );
+ statistic.setRowCount( 6L );
+ statistic.setSentenceCount( 3L );
+ statistic.setSyllableCount( 10L );
+ statistic.setTableCount( 2L );
+ statistic.setWordCount( 11L );
+
+ return statistic;
+ }
+
+ private void verifyDocumentStatistic( DocumentStatistic documentStatistic )
+ {
+ assertEquals( 2L, documentStatistic.getCharacterCount() );
+ assertEquals( 3L, documentStatistic.getDrawCount() );
+ assertEquals( 4L, documentStatistic.getFrameCount() );
+ assertEquals( 5L, documentStatistic.getImageCount() );
+ assertEquals( 6L, documentStatistic.getNonWhitespaceCharacterCount() );
+ assertEquals( 1L, documentStatistic.getObjectCount() );
+ assertEquals( 8L, documentStatistic.getOleObjectCount() );
+ assertEquals( 7L, documentStatistic.getPageCount() );
+ assertEquals( 5L, documentStatistic.getParagraphCount() );
+ assertEquals( 6L, documentStatistic.getRowCount() );
+ assertEquals( 3L, documentStatistic.getSentenceCount() );
+ assertEquals( 10L, documentStatistic.getSyllableCount() );
+ assertEquals( 2L, documentStatistic.getTableCount() );
+ assertEquals( 11L, documentStatistic.getWordCount() );
+ }
+
+ private DocumentHyperlinkBehaviour getDocumentHyperlinkBehaviour()
+ {
+ DocumentHyperlinkBehaviour hylink = new DocumentHyperlinkBehaviour();
+
+ hylink.setTargetFrame( "targetFrame" );
+
+ return hylink;
+ }
+
+ private void verifyDocumentHyperlinkBehaviour( DocumentHyperlinkBehaviour hyperlinkBehaviour )
+ {
+ assertEquals( "targetFrame", hyperlinkBehaviour.getTargetFrame() );
+ }
+
+ private DocumentMeta getDocumentMeta()
+ {
+ DocumentMeta meta = new DocumentMeta();
+
+ meta.setAuthor( "author" );
+ meta.addAuthor( getAuthor( 2 ) );
+ meta.setConfidential( true );
+ meta.setCreationDate( new Date( 1L ) );
+ meta.setCreator( "creator" );
+ meta.setDate( new Date( 2L ) );
+ meta.setDescription( "description" );
+ meta.setDocumentStatistic( getDocumentStatistic() );
+ meta.setDraft( true );
+ meta.setEditingCycles( 15L );
+ meta.setEditingDuration( 3L );
+ meta.setGenerator( "generator" );
+ meta.setHyperlinkBehaviour( getDocumentHyperlinkBehaviour() );
+ meta.setInitialCreator( "initialCreator" );
+ meta.setKeywords( "keywords" );
+ meta.setLanguage( "language" );
+ meta.setPageSize( "pageSize" );
+ meta.setPrintDate( new Date( 4L ) );
+ meta.setPrintedBy( "printedBy" );
+ meta.setSubject( "subject" );
+ meta.setTemplate( getDocumentTemplate() );
+ meta.setTitle( "title" );
+
+ return meta;
+ }
+
+ private void verifyDocumentMeta( DocumentMeta meta )
+ {
+ assertEquals( "author", meta.getAuthor() );
+ List authors = meta.getAuthors();
+ assertEquals( 1, authors.size() );
+ verifyAuthor( (DocumentAuthor) authors.get( 0 ), 2 );
+
+ assertTrue( meta.isConfidential() );
+ assertEquals( 1L, meta.getCreationDate().getTime() );
+ assertEquals( "creator", meta.getCreator() );
+ assertEquals( 2L, meta.getDate().getTime() );
+ assertEquals( "description", meta.getDescription() );
+ verifyDocumentStatistic( meta.getDocumentStatistic() );
+ assertTrue( meta.isDraft() );
+ assertEquals( 15L, meta.getEditingCycles() );
+ assertEquals( 3L, meta.getEditingDuration() );
+ assertEquals( "generator", meta.getGenerator() );
+ verifyDocumentHyperlinkBehaviour( meta.getHyperlinkBehaviour() );
+ assertEquals( "initialCreator", meta.getInitialCreator() );
+ assertEquals( "keywords", meta.getKeywords() );
+ assertEquals( "language", meta.getLanguage() );
+ assertEquals( "pageSize", meta.getPageSize() );
+ assertEquals( 4L, meta.getPrintDate().getTime() );
+ assertEquals( "printedBy", meta.getPrintedBy() );
+ assertEquals( "subject", meta.getSubject() );
+ verifyDocumentTemplate( meta.getTemplate() );
+ assertEquals( "title", meta.getTitle() );
+ }
+
+ private DocumentTemplate getDocumentTemplate()
+ {
+ DocumentTemplate template = new DocumentTemplate();
+
+ template.setDate( new Date( 3L ) );
+ template.setHref( "href" );
+ template.setTitle( "title" );
+
+ return template;
+ }
+
+ private void verifyDocumentTemplate( DocumentTemplate template )
+ {
+ assertEquals( 3L, template.getDate().getTime() );
+ assertEquals( "href", template.getHref() );
+ assertEquals( "title", template.getTitle() );
+ }
+
+ private DocumentTOC getDocumentToc()
+ {
+ DocumentTOCItem item1 = new DocumentTOCItem();
+ item1.setName( "First document" );
+ item1.setRef( "doc1.apt" );
+
+ DocumentTOCItem item2 = new DocumentTOCItem();
+ item2.setName( "Second document" );
+ item2.setRef( "doc2.xml" );
+
+ DocumentTOC toc = new DocumentTOC();
+ toc.setName( "name" );
+ toc.addItem( item1 );
+ toc.addItem( item2 );
+
+ return toc;
+ }
+
+ private void verifyDocumentTOC( DocumentTOC toc )
+ {
+ assertEquals( "name", toc.getName() );
+ }
+
+ private DocumentModel writeAndRecover( DocumentModel model )
+ throws IOException
+ {
+ File dir = getTestFile( "target/test-output/xpp3/" );
+
+ if ( !dir.exists() )
+ {
+ dir.mkdirs();
+ }
+
+ File testFile = getTestFile( dir.getAbsolutePath(), "testModel.xml" );
+ Writer w = null;
+
+ try
+ {
+ w = WriterFactory.newPlatformWriter( testFile );
+ new DocumentXpp3Writer().write( w, model );
+ }
+ finally
+ {
+ IOUtil.close( w );
+ }
+
+ DocumentModel documentModel;
+
+ Reader reader = null;
+
+ try
+ {
+ reader = ReaderFactory.newXmlReader( testFile );
+ documentModel = new DocumentXpp3Reader().read( reader );
+ }
+ catch ( XmlPullParserException e )
+ {
+ throw new IOException( "Error parsing document descriptor", e );
+ }
+ finally
+ {
+ IOUtil.close( reader );
+ }
+
+ return documentModel;
+ }
+}
\ No newline at end of file
Propchange: maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/document/DocumentModelTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/document/DocumentModelTest.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"