Java tutorial
/* * Copyright (C) 2012 Nicolas A. Brard-Nault * * Licensed 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. */ package org.sitemap4j.dom4j; import static org.junit.Assert.assertEquals; import static org.sitemap4j.TestHelper.getRandomUrl; import java.io.OutputStream; import org.apache.commons.vfs2.FileObject; import org.apache.commons.vfs2.VFS; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.junit.Test; import org.sitemap4j.dom4j.Dom4jSiteMapIndexReader; import org.sitemap4j.dom4j.Dom4jSiteMapIndexWriter; import org.sitemap4j.reader.RawSiteMap; import org.sitemap4j.reader.SiteMapIndexReader; import org.sitemap4j.sitemapindex.ArrayListMutableSiteMapIndex; import org.sitemap4j.sitemapindex.MutableSiteMapIndex; import org.sitemap4j.sitemapindex.SiteMapLocation; import org.sitemap4j.writer.SiteMapIndexWriter; public class Dom4jSiteMapIndexWriterTest { @Test public void test() throws Exception { // Given final MutableSiteMapIndex siteMapIndex = ArrayListMutableSiteMapIndex.create(); siteMapIndex.add(SiteMapLocation.create(getRandomUrl())); siteMapIndex.add(SiteMapLocation.create(getRandomUrl(), new DateTime(DateTimeZone.UTC))); final FileObject siteMapIndexFile = VFS.getManager().resolveFile("ram:///sitemap-index.xml"); siteMapIndexFile.createFile(); final OutputStream outputStream = siteMapIndexFile.getContent().getOutputStream(); // When final SiteMapIndexWriter writer = Dom4jSiteMapIndexWriter.forSiteMapIndex(siteMapIndex); writer.write(outputStream); // Then final SiteMapIndexReader siteMapIndexReader = Dom4jSiteMapIndexReader.create(); assertEquals(siteMapIndex, siteMapIndexReader .read(RawSiteMap.fromInputStream(siteMapIndexFile.getContent().getInputStream()))); } }