Author: desruisseaux
Date: Thu Jun 20 13:50:21 2013
New Revision: 1494998
URL: http://svn.apache.org/r1494998
Log:
Ported a test.
Added:
sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableFormatTest.java
(with props)
Modified:
sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/ValueMapTest.java
sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
Added: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableFormatTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableFormatTest.java?rev=1494998&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableFormatTest.java
(added)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableFormatTest.java
[UTF-8] Thu Jun 20 13:50:21 2013
@@ -0,0 +1,206 @@
+/*
+ * 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.
+ */
+package org.apache.sis.metadata;
+
+import java.util.Arrays;
+import java.util.Collections;
+import javax.measure.unit.SI;
+import org.opengis.metadata.citation.Role;
+import org.opengis.metadata.citation.PresentationForm;
+import org.opengis.metadata.identification.TopicCategory;
+import org.opengis.util.InternationalString;
+import org.apache.sis.util.collection.TableColumn;
+import org.apache.sis.util.collection.TreeTableFormat;
+import org.apache.sis.util.iso.SimpleInternationalString;
+import org.apache.sis.metadata.iso.content.DefaultBand;
+import org.apache.sis.metadata.iso.content.DefaultImageDescription;
+import org.apache.sis.metadata.iso.citation.DefaultCitation;
+import org.apache.sis.metadata.iso.citation.DefaultResponsibleParty;
+import org.apache.sis.metadata.iso.identification.DefaultKeywords;
+import org.apache.sis.metadata.iso.identification.DefaultDataIdentification;
+import org.apache.sis.metadata.iso.lineage.DefaultProcessing;
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.apache.sis.test.Assert.*;
+
+
+/**
+ * Tests the {@link TreeTableFormat} applied to the formatting of metadata tree.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.3 (derived from geotk-3.00)
+ * @version 0.3
+ * @module
+ */
+@DependsOn(TreeTableViewTest.class)
+public final strictfp class TreeTableFormatTest extends TestCase {
+ /**
+ * The formatter to use.
+ */
+ private final TreeTableFormat format;
+
+ /**
+ * Creates a new test case.
+ */
+ public TreeTableFormatTest() {
+ format = new TreeTableFormat(null, null);
+ format.setColumns(TableColumn.NAME, TableColumn.VALUE);
+ }
+
+ /**
+ * Creates a band for the given minimum and maximum wavelengths, in centimetres.
+ */
+ private static DefaultBand createBand(final double min, final double max) {
+ final DefaultBand band = new DefaultBand();
+ band.setMinValue(min);
+ band.setMaxValue(max);
+ band.setUnits(SI.CENTIMETRE);
+ return band;
+ }
+
+ /**
+ * Creates the citation to use for testing purpose.
+ */
+ private static DefaultCitation createCitation() {
+ final DefaultCitation citation = new DefaultCitation();
+ final InternationalString title = new SimpleInternationalString("Undercurrent");
+ citation.setTitle(title);
+ citation.setISBN("9782505004509");
+ citation.getPresentationForms().add(PresentationForm.DOCUMENT_HARDCOPY);
+ citation.getPresentationForms().add(PresentationForm.IMAGE_HARDCOPY);
+ citation.getAlternateTitles().add(new SimpleInternationalString("Alt A"));
+ citation.getAlternateTitles().add(new SimpleInternationalString("Alt B"));
+
+ final DefaultResponsibleParty author = new DefaultResponsibleParty();
+ author.setIndividualName("Testsuya Toyoda");
+ author.setRole(Role.AUTHOR);
+ citation.getCitedResponsibleParties().add(author);
+ final DefaultResponsibleParty duplicated = new DefaultResponsibleParty();
+ duplicated.setIndividualName("A japanese author");
+ citation.getCitedResponsibleParties().add(duplicated);
+ return citation;
+ }
+
+ /**
+ * Tests the formatting of a {@link DefaultCitation} object.
+ */
+ @Test
+ public void testCitation() {
+ final DefaultCitation citation = createCitation();
+ final String text = format.format(citation.asTreeTable());
+ assertMultilinesEquals(
+ "DefaultCitation\n" +
+ " ├─Title………………………………………………………………………
Undercurrent\n" +
+ " ├─Alternate title (1 of 2)…………………… Alt A\n" +
+ " ├─Alternate title (2 of 2)…………………… Alt B\n" +
+ " ├─Identifier\n" +
+ " │ ├─Code………………………………………………………………
9782505004509\n" +
+ " │ └─Authority\n" +
+ " │ └─Title…………………………………………………
ISBN\n" +
+ " ├─Cited responsible party (1 of 2)\n" +
+ " │ ├─Individual name………………………………… Testsuya
Toyoda\n" +
+ " │ └─Role………………………………………………………………
Author\n" +
+ " ├─Cited responsible party (2 of 2)\n" +
+ " │ └─Individual name………………………………… A
japanese author\n" +
+ " ├─Presentation form (1 of 2)……………… Document hardcopy\n"
+
+ " ├─Presentation form (2 of 2)……………… Image hardcopy\n" +
+ " └─ISBN…………………………………………………………………………
9782505004509\n", text);
+ }
+
+ /**
+ * Tests the formatting of a {@link DefaultProcessing} object.
+ */
+ @Test
+ public void testProcessing() {
+ final DefaultCitation titled = new DefaultCitation("Some specification");
+ final DefaultCitation coded = new DefaultCitation();
+ final DefaultCitation untitled = new DefaultCitation();
+ titled .getPresentationForms().add(PresentationForm.DOCUMENT_HARDCOPY);
+ coded .getPresentationForms().add(PresentationForm.IMAGE_HARDCOPY);
+ untitled.getCitedResponsibleParties().add(new DefaultResponsibleParty(Role.AUTHOR));
+ final DefaultProcessing processing = new DefaultProcessing();
+ processing.getDocumentations().add(titled);
+ processing.getDocumentations().add(coded);
+ processing.getDocumentations().add(untitled);
+ final String text = format.format(processing.asTreeTable());
+ assertMultilinesEquals(
+ "DefaultProcessing\n" +
+ " ├─Documentation (1 of 3)\n" +
+ " │ ├─Title………………………………………………
Some specification\n" +
+ " │ └─Presentation form……………… Document hardcopy\n"
+
+ " ├─Documentation (2 of 3)\n" +
+ " │ └─Presentation form……………… Image hardcopy\n" +
+ " └─Documentation (3 of 3)\n" +
+ " └─Cited responsible party\n" +
+ " └─Role………………………………………
Author\n", text);
+ }
+
+ /**
+ * Tests the formatting of a {@link DefaultImageDescription} object.
+ */
+ @Test
+ public void testImageDescription() {
+ final DefaultImageDescription image = new DefaultImageDescription();
+ image.getDimensions().add(createBand(0.25, 0.26));
+ image.getDimensions().add(createBand(0.28, 0.29));
+ final String text = format.format(image.asTreeTable());
+ assertMultilinesEquals(
+ "DefaultImageDescription\n" +
+ " ├─Dimension (1 of 2)\n" +
+ " │ ├─Max value……………… 0.26\n" +
+ " │ ├─Min value……………… 0.25\n" +
+ " │ └─Units………………………… cm\n" +
+ " └─Dimension (2 of 2)\n" +
+ " ├─Max value……………… 0.29\n" +
+ " ├─Min value……………… 0.28\n" +
+ " └─Units………………………… cm\n", text);
+ }
+
+ /**
+ * Tests the formatting of a {@link DefaultDataIdentification} object with custom code
list elements
+ * Note that adding enumeration values is normally not allowed, so a future version of
this test may
+ * need to change the code type.
+ */
+ @Test
+ public void testTreeWithCustomElements() {
+ final DefaultKeywords keywords = new DefaultKeywords();
+ keywords.setKeywords(Arrays.asList(
+ new SimpleInternationalString("Apple"),
+ new SimpleInternationalString("Orange"),
+ new SimpleInternationalString("Kiwi")));
+
+ final DefaultDataIdentification identification = new DefaultDataIdentification();
+ identification.setDescriptiveKeywords(Collections.singleton(keywords));
+ identification.setTopicCategories(Arrays.asList(
+ TopicCategory.HEALTH,
+ TopicCategory.valueOf("OCEANS"), // Existing category
+ TopicCategory.valueOf("test"))); // Custom category
+
+ final String text = format.format(identification.asTreeTable());
+ assertMultilinesEquals(
+ "DefaultDataIdentification\n" +
+ " ├─Topic category (1 of 3)…… Health\n" +
+ " ├─Topic category (2 of 3)…… Oceans\n" +
+ " ├─Topic category (3 of 3)…… Test\n" +
+ " └─Descriptive keywords\n" +
+ " ├─Keyword (1 of 3)…………… Apple\n" +
+ " ├─Keyword (2 of 3)…………… Orange\n" +
+ " └─Keyword (3 of 3)…………… Kiwi\n", text);
+ }
+}
Propchange: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableFormatTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableFormatTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Modified: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/ValueMapTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/ValueMapTest.java?rev=1494998&r1=1494997&r2=1494998&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/ValueMapTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/ValueMapTest.java
[UTF-8] Thu Jun 20 13:50:21 2013
@@ -74,10 +74,10 @@ public final strictfp class ValueMapTest
*
* {@preformat text
* Citation
- * ├───Title……………………………………………………
Undercurrent
- * ├───Cited Responsible Parties
- * │ └───Individual Name……………… Testsuya Toyoda
- * └───ISBN………………………………………………………
9782505004509
+ * ├─Title…………………………………………………… Undercurrent
+ * ├─Cited Responsible Parties
+ * │ └─Individual Name……………… Testsuya Toyoda
+ * └─ISBN………………………………………………………
9782505004509
* }
*
* The citation instance is stored in the {@link #citation} field.
@@ -120,11 +120,11 @@ public final strictfp class ValueMapTest
*
* {@preformat text
* Citation
- * ├───Title……………………………………………………
Undercurrent
- * ├───Identifiers…………………………………… 9782505004509
- * ├───Cited Responsible Parties
- * │ └───Individual Name……………… Testsuya Toyoda
- * └───ISBN………………………………………………………
9782505004509
+ * ├─Title…………………………………………………… Undercurrent
+ * ├─Identifiers…………………………………… 9782505004509
+ * ├─Cited Responsible Parties
+ * │ └─Individual Name……………… Testsuya Toyoda
+ * └─ISBN………………………………………………………
9782505004509
* }
*
* Note that this test is intentionally sensitive to iteration order.
@@ -212,9 +212,9 @@ public final strictfp class ValueMapTest
* Remove the ISBN value. Result shall be:
*
* Citation
- * ├───Title……………………………………………………
Undercurrent
- * └───Cited Responsible Parties
- * └───Individual Name……………… Testsuya Toyoda
+ * ├─Title…………………………………………………… Undercurrent
+ * └─Cited Responsible Parties
+ * └─Individual Name……………… Testsuya Toyoda
*/
assertEquals("9782505004509", map.remove("ISBN"));
assertNull("ISBN shall have been removed.", citation.getISBN());
@@ -227,10 +227,10 @@ public final strictfp class ValueMapTest
* Add a value. Result shall be:
*
* Citation
- * ├───Title……………………………………………………
Undercurrent
- * ├───Cited Responsible Parties
- * │ └───Individual Name……………… Testsuya Toyoda
- * └───Presentation Forms………………… document hardcopy
+ * ├─Title…………………………………………………… Undercurrent
+ * ├─Cited Responsible Parties
+ * │ └─Individual Name……………… Testsuya Toyoda
+ * └─Presentation Forms………………… document hardcopy
*/
assertNull(map.put("presentationForm", DOCUMENT_HARDCOPY));
assertEquals(DOCUMENT_HARDCOPY, getSingleton(citation.getPresentationForms()));
@@ -243,12 +243,12 @@ public final strictfp class ValueMapTest
* Add back the ISBN value. Result shall be:
*
* Citation
- * ├───Title……………………………………………………
Undercurrent
- * ├───Identifiers…………………………………… 9782505004509
- * ├───Cited Responsible Parties
- * │ └───Individual Name……………… Testsuya Toyoda
- * ├───Presentation Forms………………… document hardcopy
- * └───ISBN………………………………………………………
9782505004509
+ * ├─Title…………………………………………………… Undercurrent
+ * ├─Identifiers…………………………………… 9782505004509
+ * ├─Cited Responsible Parties
+ * │ └─Individual Name……………… Testsuya Toyoda
+ * ├─Presentation Forms………………… document hardcopy
+ * └─ISBN………………………………………………………
9782505004509
*/
assertNull(map.put("ISBN", "9782505004509"));
assertEquals("9782505004509", citation.getISBN());
Modified: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java?rev=1494998&r1=1494997&r2=1494998&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
[UTF-8] Thu Jun 20 13:50:21 2013
@@ -49,6 +49,7 @@ import org.junit.BeforeClass;
org.apache.sis.metadata.TreeNodeChildrenTest.class,
org.apache.sis.metadata.TreeNodeTest.class,
org.apache.sis.metadata.TreeTableViewTest.class,
+ org.apache.sis.metadata.TreeTableFormatTest.class,
org.apache.sis.metadata.MetadataStandardTest.class,
org.apache.sis.metadata.PrunerTest.class,
org.apache.sis.metadata.AbstractMetadataTest.class,
|