Sweet! I was just thinking.. maybe we could use some form of sanity check 
(self-test) on such tests - to ensure that, for example, the source files 
(.java, .xml) are still indeed correctly encoded in utf-8 ? (just in case the 
odd svn client or code editor would temper with them, for instance)
And/or be sure to escape/encode everything, but that might defeat the test 
partially.

-g

On Feb 11, 2010, at 2:23 PM, [email protected] wrote:

> Revision
> 31786
> Author
> lucaboati
> Date
> 2010-02-11 14:23:44 +0100 (Thu, 11 Feb 2010)
> Log Message
> 
> [MAGNOLIA-3009] first utf8 integration test, read a bootstrap file and 
> checked utf8 handles
> Added Paths
> 
>       • 
> community/magnolia/branches/utf8support/magnolia-core/src/test/java/info/magnolia/utf8/
>       • 
> community/magnolia/branches/utf8support/magnolia-core/src/test/java/info/magnolia/utf8/Utf8ContentTest.java
>       • 
> community/magnolia/branches/utf8support/magnolia-core/src/test/resources/info/magnolia/utf8/
>       • 
> community/magnolia/branches/utf8support/magnolia-core/src/test/resources/info/magnolia/utf8/website.utf8test.xml
> Diff
> 
> Added: 
> community/magnolia/branches/utf8support/magnolia-core/src/test/java/info/magnolia/utf8/Utf8ContentTest.java
>  (0 => 31786)
> 
> --- 
> community/magnolia/branches/utf8support/magnolia-core/src/test/java/info/magnolia/utf8/Utf8ContentTest.java
>                                (rev 0)
> +++ 
> community/magnolia/branches/utf8support/magnolia-core/src/test/java/info/magnolia/utf8/Utf8ContentTest.java
>        2010-02-11 13:23:44 UTC (rev 31786)
> 
> @@ -0,0 +1,125 @@
> 
> +/**
> + * This file Copyright (c) 2003-2009 Magnolia International
> + * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
> + *
> + *
> + * This file is dual-licensed under both the Magnolia
> + * Network Agreement and the GNU General Public License.
> + * You may elect to use one or the other of these licenses.
> + *
> + * This file is distributed in the hope that it will be
> + * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
> + * implied warranty of MERCHANTABILITY or FITNESS FOR A
> + * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
> + * Redistribution, except as permitted by whichever of the GPL
> + * or MNA you select, is prohibited.
> + *
> + * 1. For the GPL license (GPL), you can redistribute and/or
> + * modify this file under the terms of the GNU General
> + * Public License, Version 3, as published by the Free Software
> + * Foundation.  You should have received a copy of the GNU
> + * General Public License, Version 3 along with this program;
> + * if not, write to the Free Software Foundation, Inc., 51
> + * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
> + *
> + * 2. For the Magnolia Network Agreement (MNA), this file
> + * and the accompanying materials are made available under the
> + * terms of the MNA which accompanies this distribution, and
> + * is available at http://www.magnolia-cms.com/mna.html
> + *
> + * Any modifications to this file must keep this entire header
> + * intact.
> + *
> + */
> +package info.magnolia.utf8;
> +
> +import info.magnolia.cms.beans.config.ContentRepository;
> +import info.magnolia.cms.core.Content;
> +import info.magnolia.cms.core.HierarchyManager;
> +import info.magnolia.cms.core.ItemType;
> +import info.magnolia.cms.core.NodeData;
> +import info.magnolia.cms.util.ContentUtil;
> +import info.magnolia.cms.util.NodeDataUtil;
> +import info.magnolia.context.MgnlContext;
> +import info.magnolia.importexport.PropertiesImportExport;
> +import info.magnolia.test.RepositoryTestCase;
> +
> +import java.io.File;
> +import java.io.IOException;
> +
> +import javax.jcr.RepositoryException;
> +import javax.jcr.UnsupportedRepositoryOperationException;
> +import javax.jcr.Value;
> +import javax.jcr.ValueFactory;
> +
> +import org.apache.commons.io.IOUtils;
> +
> +
> +/**
> + * @author luca boati
> + */
> +public class Utf8ContentTest extends RepositoryTestCase
> +{
> +
> +    public void testReadingUtf8Contents() throws Exception
> +    {
> +        File f1 = new 
> File(getClass().getResource("/info/magnolia/utf8/website.utf8test.xml").getFile());
> +        bootstrapSingleResource("/info/magnolia/utf8/" + f1.getName());
> +
> +        HierarchyManager hm = 
> MgnlContext.getInstance().getHierarchyManager(ContentRepository.WEBSITE);
> +        hm.save();
> +
> +        Content content = hm.getContent("/utf8test/città");
> +        assertNotNull(content);
> +        assertEquals(content.getHandle(), "/utf8test/città");
> +
> +        Content content1 = hm.getContent("/utf8test/utf8!?#");
> +        assertNotNull(content1);
> +        assertEquals(content1.getHandle(), "/utf8test/utf8!?#");
> +
> +        Content content2 = hm.getContent("/utf8test/モクレン");
> +        assertNotNull(content2);
> +        assertEquals(content2.getHandle(), "/utf8test/モクレン");
> +
> +    }
> +
> +    public void testSettingAnUtf8NodeData() throws IOException, 
> RepositoryException
> +    {
> +        Content content = getTestContent();
> +        // this should not fail
> +        Value value = createValue("città");
> +        NodeData nodeData = content.setNodeData("nd1", value);
> +        assertEquals("città", nodeData.getString());
> +    }
> +
> +    public void testSettingNewUtf8ContentNode() throws IOException, 
> RepositoryException
> +    {
> +        Content content = getTestContent();
> +        ContentUtil.getOrCreateContent(content, "città", ItemType.CONTENT);
> +        Content newContent = content.getContent("città");
> +        String name = newContent.getName();
> +        assertEquals("città", name);
> +    }
> +
> +    private Content getTestContent() throws IOException, RepositoryException
> +    {
> +        String contentProperties = "/myutf8conte...@type=mgnl:content\n" + 
> "/myutf8content.nd1=hello";
> +
> +        HierarchyManager hm = 
> MgnlContext.getHierarchyManager(ContentRepository.WEBSITE);
> +        new PropertiesImportExport().createContent(hm.getRoot(), 
> IOUtils.toInputStream(contentProperties));
> +        hm.save();
> +        Content content = hm.getContent("/myutf8content");
> +        return content;
> +    }
> +
> +    private Value createValue(Object valueObj) throws RepositoryException, 
> UnsupportedRepositoryOperationException
> +    {
> +        ValueFactory valueFactory = MgnlContext
> +            .getHierarchyManager("website")
> +            .getWorkspace()
> +            .getSession()
> +            .getValueFactory();
> +        return NodeDataUtil.createValue(valueObj, valueFactory);
> +    }
> +
> +}
> 
> Property changes on: 
> community/magnolia/branches/utf8support/magnolia-core/src/test/java/info/magnolia/utf8/Utf8ContentTest.java
> 
> ___________________________________________________________________
> 
> Name: svn:mime-type
> 
>    + text/plain
> 
> Added: 
> community/magnolia/branches/utf8support/magnolia-core/src/test/resources/info/magnolia/utf8/website.utf8test.xml
>  (0 => 31786)
> 
> --- 
> community/magnolia/branches/utf8support/magnolia-core/src/test/resources/info/magnolia/utf8/website.utf8test.xml
>                           (rev 0)
> +++ 
> community/magnolia/branches/utf8support/magnolia-core/src/test/resources/info/magnolia/utf8/website.utf8test.xml
>   2010-02-11 13:23:44 UTC (rev 31786)
> 
> @@ -0,0 +1,113 @@
> 
> +<?xml version="1.0" encoding="UTF-8"?>
> +<sv:node sv:name="utf8test" xmlns:sv="http://www.jcp.org/jcr/sv/1.0"; 
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
> +  <sv:property sv:name="jcr:primaryType" sv:type="Name">
> +    <sv:value>mgnl:content</sv:value>
> +  </sv:property>
> +  <sv:property sv:name="jcr:mixinTypes" sv:type="Name">
> +    <sv:value>mix:lockable</sv:value>
> +  </sv:property>
> +  <sv:property sv:name="jcr:uuid" sv:type="String">
> +    <sv:value>af4e8a95-9709-4a40-9506-cafd1c3e320a</sv:value>
> +  </sv:property>
> +  <sv:node sv:name="MetaData">
> +    <sv:property sv:name="jcr:primaryType" sv:type="Name">
> +      <sv:value>mgnl:metaData</sv:value>
> +    </sv:property>
> +    <sv:property sv:name="mgnl:authorid" sv:type="String">
> +      <sv:value>superuser</sv:value>
> +    </sv:property>
> +    <sv:property sv:name="mgnl:creationdate" sv:type="Date">
> +      <sv:value>2010-02-11T13:01:13.015+01:00</sv:value>
> +    </sv:property>
> +    <sv:property sv:name="mgnl:lastmodified" sv:type="Date">
> +      <sv:value>2010-02-11T13:01:54.705+01:00</sv:value>
> +    </sv:property>
> +    <sv:property sv:name="mgnl:template" sv:type="String">
> +      <sv:value>plaintext</sv:value>
> +    </sv:property>
> +  </sv:node>
> +  <sv:node sv:name="città">
> +    <sv:property sv:name="jcr:primaryType" sv:type="Name">
> +      <sv:value>mgnl:content</sv:value>
> +    </sv:property>
> +    <sv:property sv:name="jcr:mixinTypes" sv:type="Name">
> +      <sv:value>mix:lockable</sv:value>
> +    </sv:property>
> +    <sv:property sv:name="jcr:uuid" sv:type="String">
> +      <sv:value>dc4853f5-21e5-45cf-9132-4bb5551f53d2</sv:value>
> +    </sv:property>
> +    <sv:node sv:name="MetaData">
> +      <sv:property sv:name="jcr:primaryType" sv:type="Name">
> +        <sv:value>mgnl:metaData</sv:value>
> +      </sv:property>
> +      <sv:property sv:name="mgnl:authorid" sv:type="String">
> +        <sv:value>superuser</sv:value>
> +      </sv:property>
> +      <sv:property sv:name="mgnl:creationdate" sv:type="Date">
> +        <sv:value>2010-02-11T12:58:51.532+01:00</sv:value>
> +      </sv:property>
> +      <sv:property sv:name="mgnl:lastmodified" sv:type="Date">
> +        <sv:value>2010-02-11T13:01:35.671+01:00</sv:value>
> +      </sv:property>
> +      <sv:property sv:name="mgnl:template" sv:type="String">
> +        <sv:value>plaintext</sv:value>
> +      </sv:property>
> +    </sv:node>
> +  </sv:node>
> +  <sv:node sv:name="utf8!?#">
> +    <sv:property sv:name="jcr:primaryType" sv:type="Name">
> +      <sv:value>mgnl:content</sv:value>
> +    </sv:property>
> +    <sv:property sv:name="jcr:mixinTypes" sv:type="Name">
> +      <sv:value>mix:lockable</sv:value>
> +    </sv:property>
> +    <sv:property sv:name="jcr:uuid" sv:type="String">
> +      <sv:value>3385adf1-e9a1-43ee-b703-fefdc46bbfb5</sv:value>
> +    </sv:property>
> +    <sv:node sv:name="MetaData">
> +      <sv:property sv:name="jcr:primaryType" sv:type="Name">
> +        <sv:value>mgnl:metaData</sv:value>
> +      </sv:property>
> +      <sv:property sv:name="mgnl:authorid" sv:type="String">
> +        <sv:value>superuser</sv:value>
> +      </sv:property>
> +      <sv:property sv:name="mgnl:creationdate" sv:type="Date">
> +        <sv:value>2010-02-11T12:59:01.905+01:00</sv:value>
> +      </sv:property>
> +      <sv:property sv:name="mgnl:lastmodified" sv:type="Date">
> +        <sv:value>2010-02-11T13:01:26.077+01:00</sv:value>
> +      </sv:property>
> +      <sv:property sv:name="mgnl:template" sv:type="String">
> +        <sv:value>plaintext</sv:value>
> +      </sv:property>
> +    </sv:node>
> +  </sv:node>
> +  <sv:node sv:name="モクレン">
> +    <sv:property sv:name="jcr:primaryType" sv:type="Name">
> +      <sv:value>mgnl:content</sv:value>
> +    </sv:property>
> +    <sv:property sv:name="jcr:mixinTypes" sv:type="Name">
> +      <sv:value>mix:lockable</sv:value>
> +    </sv:property>
> +    <sv:property sv:name="jcr:uuid" sv:type="String">
> +      <sv:value>1184adf1-e9a1-43ee-b801-fefdc46bbfb1</sv:value>
> +    </sv:property>
> +    <sv:node sv:name="MetaData">
> +      <sv:property sv:name="jcr:primaryType" sv:type="Name">
> +        <sv:value>mgnl:metaData</sv:value>
> +      </sv:property>
> +      <sv:property sv:name="mgnl:authorid" sv:type="String">
> +        <sv:value>superuser</sv:value>
> +      </sv:property>
> +      <sv:property sv:name="mgnl:creationdate" sv:type="Date">
> +        <sv:value>2010-02-11T12:59:02.905+01:00</sv:value>
> +      </sv:property>
> +      <sv:property sv:name="mgnl:lastmodified" sv:type="Date">
> +        <sv:value>2010-02-11T13:01:25.077+01:00</sv:value>
> +      </sv:property>
> +      <sv:property sv:name="mgnl:template" sv:type="String">
> +        <sv:value>plaintext</sv:value>
> +      </sv:property>
> +    </sv:node>
> +  </sv:node>
> +</sv:node>
> 
> \ No newline at end of file
> 
> Property changes on: 
> community/magnolia/branches/utf8support/magnolia-core/src/test/resources/info/magnolia/utf8/website.utf8test.xml
> 
> ___________________________________________________________________
> 
> Name: svn:mime-type
> 
>    + text/plain
> 
> 
> 
> ----------------------------------------------------------------
> For list details see
> http://www.magnolia-cms.com/home/community/mailing-lists.html
> To unsubscribe, E-mail to: <[email protected]>
> ----------------------------------------------------------------


----------------------------------------------------------------
For list details see
http://www.magnolia-cms.com/home/community/mailing-lists.html
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------

Reply via email to