sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1793768 - in /sis/branches/JDK8/core/sis-metadata/src: main/java/org/apache/sis/metadata/ test/java/org/apache/sis/metadata/
Date Thu, 04 May 2017 11:09:37 GMT
Author: desruisseaux
Date: Thu May  4 11:09:37 2017
New Revision: 1793768

URL: http://svn.apache.org/viewvc?rev=1793768&view=rev
Log:
The use of compact mode in metadata tree table view should be optional.

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/AbstractMetadata.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/TitleProperty.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/TreeNodeChildren.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/ValueExistencePolicy.java
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeNodeChildrenTest.java
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeNodeTest.java
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableFormatTest.java
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableViewTest.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/AbstractMetadata.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/AbstractMetadata.java?rev=1793768&r1=1793767&r2=1793768&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/AbstractMetadata.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/AbstractMetadata.java
[UTF-8] Thu May  4 11:09:37 2017
@@ -258,7 +258,7 @@ public abstract class AbstractMetadata i
      * adds a title to a citation:
      *
      * {@preformat java
-     *     TreeTable.Node node = ...; // The node for a DefaultCitation.
+     *     TreeTable.Node node = ...;                               // The node for a DefaultCitation.
      *     TreeTable.Node child = node.newChild();
      *     child.setValue(TableColumn.IDENTIFIER, "title");
      *     child.setValue(TableColumn.VALUE, "Le petit prince");
@@ -272,7 +272,7 @@ public abstract class AbstractMetadata i
      * The default implementation is equivalent to the following method call:
      *
      * {@preformat java
-     *   return getStandard().asTreeTable(this, null, ValueExistencePolicy.NON_EMPTY);
+     *   return getStandard().asTreeTable(this, null, ValueExistencePolicy.COMPACT);
      * }
      *
      * @return a tree table representation of the specified metadata.
@@ -280,7 +280,7 @@ public abstract class AbstractMetadata i
      * @see MetadataStandard#asTreeTable(Object, Class, ValueExistencePolicy)
      */
     public TreeTable asTreeTable() {
-        return getStandard().asTreeTable(this, null, ValueExistencePolicy.NON_EMPTY);
+        return getStandard().asTreeTable(this, null, ValueExistencePolicy.COMPACT);
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java?rev=1793768&r1=1793767&r2=1793768&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/MetadataStandard.java
[UTF-8] Thu May  4 11:09:37 2017
@@ -860,7 +860,7 @@ public class MetadataStandard implements
      * adds a title to a citation:
      *
      * {@preformat java
-     *     TreeTable.Node node = ...; // The node for a DefaultCitation.
+     *     TreeTable.Node node = ...;                               // The node for a DefaultCitation.
      *     TreeTable.Node child = node.newChild();
      *     child.setValue(TableColumn.IDENTIFIER, "title");
      *     child.setValue(TableColumn.VALUE, "Le petit prince");

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/TitleProperty.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/TitleProperty.java?rev=1793768&r1=1793767&r2=1793768&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/TitleProperty.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/TitleProperty.java
[UTF-8] Thu May  4 11:09:37 2017
@@ -60,6 +60,8 @@ import java.lang.annotation.Documented;
  * @version 0.8
  * @since   0.8
  * @module
+ *
+ * @see ValueExistencePolicy#COMPACT
  */
 @Documented
 @Inherited

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/TreeNodeChildren.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/TreeNodeChildren.java?rev=1793768&r1=1793767&r2=1793768&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/TreeNodeChildren.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/TreeNodeChildren.java
[UTF-8] Thu May  4 11:09:37 2017
@@ -145,7 +145,7 @@ final class TreeNodeChildren extends Abs
          * instead than provided as a child. The intend is to have more compact and easy
to read trees.
          * That property shall be a singleton for a simple value (not another metadata object).
          */
-        if (parent.getParent() != null) {
+        if (parent.table.valuePolicy == ValueExistencePolicy.COMPACT) {
             TitleProperty an = accessor.implementation.getAnnotation(TitleProperty.class);
             if (an == null) {
                 Class<?> implementation = parent.table.standard.getImplementation(accessor.type);

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/ValueExistencePolicy.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/ValueExistencePolicy.java?rev=1793768&r1=1793767&r2=1793768&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/ValueExistencePolicy.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/ValueExistencePolicy.java
[UTF-8] Thu May  4 11:09:37 2017
@@ -38,7 +38,7 @@ import org.apache.sis.xml.NilReason;
  * Those explanations can be obtained by calls to the {@link org.apache.sis.xml.NilReason#forObject(Object)}
method.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.4
+ * @version 0.8
  *
  * @see MetadataStandard#asValueMap(Object, Class, KeyNamePolicy, ValueExistencePolicy)
  *
@@ -122,6 +122,59 @@ public enum ValueExistencePolicy {
         /** Skips all null or empty values. */
         @Override boolean isSkipped(final Object value) {
             return isNullOrEmpty(value);
+        }
+
+        /** Never substitute null or empty collections since they should be skipped. */
+        @Override boolean substituteByNullElement(final Collection<?> values) {
+            return false;
+        }
+    },
+
+    /**
+     * Includes non-empty properties but omits {@linkplain TitleProperty title properties}.
+     * Values associated to title properties are instead associated with the parent node.
+     * This policy is relevant for metadata classes annotated with {@link TitleProperty};
+     * for all other classes, this policy is identical to {@link #NON_EMPTY}.
+     *
+     * <div class="note"><b>Example:</b>
+     * the {@link org.apache.sis.metadata.iso.citation.DefaultCitation} and
+     * {@link org.apache.sis.metadata.iso.citation.DefaultCitationDate} classes are annotated
with
+     * <code>&#64;TitleProperty(name="title")</code> and <code>&#64;TitleProperty(name="date")</code>
+     * respectively. The following table compares the trees produces by two policies:
+     *
+     * <table class="sis">
+     *   <caption>Comparison of "non-empty" and "compact" policy on the same metadata</caption>
+     *   <tr>
+     *     <th>{@code NON_EMPTY}</th>
+     *     <th>{@code COMPACT}</th>
+     *   </tr><tr><td>
+     *     {@preformat text
+     *       Citation
+     *        ├─Title……………………… My document
+     *        └─Date
+     *           ├─Date………………… 2012/01/01
+     *           └─Date type…… Creation
+     *     }
+     *   </td><td>
+     *     {@preformat text
+     *       Citation……………………… My document
+     *        └─Date………………………… 2012/01/01
+     *           └─Date type…… Creation
+     *     }
+     *   </td></tr>
+     * </table></div>
+     *
+     * This policy is the default behavior of {@link AbstractMetadata#asTreeTable()},
+     * and consequently defines the default rendering of {@link AbstractMetadata#toString()}.
+     *
+     * @see TitleProperty
+     *
+     * @since 0.8
+     */
+    COMPACT() {
+        /** Skips all null or empty values. */
+        @Override boolean isSkipped(final Object value) {
+            return isNullOrEmpty(value);
         }
 
         /** Never substitute null or empty collections since they should be skipped. */

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeNodeChildrenTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeNodeChildrenTest.java?rev=1793768&r1=1793767&r2=1793768&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeNodeChildrenTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeNodeChildrenTest.java
[UTF-8] Thu May  4 11:09:37 2017
@@ -234,7 +234,7 @@ public final strictfp class TreeNodeChil
          *
          * We need to perform the tests on the "Date" node, not on the "DefaultCitation"
node.
          */
-        final TreeTable.Node node = TestUtilities.getSingleton(create(citation, ValueExistencePolicy.NON_EMPTY));
+        final TreeTable.Node node = TestUtilities.getSingleton(create(citation, ValueExistencePolicy.COMPACT));
         assertEquals("value", 1325376000000L, ((Date) node.getValue(TableColumn.VALUE)).getTime());
         final TreeNodeChildren children = (TreeNodeChildren) node.getChildren();
         final String[] expected = {

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeNodeTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeNodeTest.java?rev=1793768&r1=1793767&r2=1793768&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeNodeTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeNodeTest.java
[UTF-8] Thu May  4 11:09:37 2017
@@ -16,10 +16,12 @@
  */
 package org.apache.sis.metadata;
 
+import java.util.Arrays;
 import java.util.Locale;
 import org.opengis.metadata.citation.Address;
 import org.opengis.metadata.citation.Contact;
 import org.opengis.metadata.citation.Citation;
+import org.opengis.metadata.citation.Party;
 import org.opengis.metadata.citation.Responsibility;
 import org.opengis.metadata.citation.PresentationForm;
 import org.opengis.metadata.citation.Role;
@@ -97,11 +99,14 @@ public final strictfp class TreeNodeTest
     }
 
     /**
+     * The policy to be given to {@link TreeTableView} constructor.
+     */
+    private ValueExistencePolicy valuePolicy = ValueExistencePolicy.NON_EMPTY;
+
+    /**
      * Creates a node to be tested for the given metadata object and value policy.
      */
-    private static <T extends AbstractMetadata> TreeNode create(final T metadata,
-            final Class<? super T> baseType, final ValueExistencePolicy valuePolicy)
-    {
+    private <T extends AbstractMetadata> TreeNode create(final T metadata, final Class<?
super T> baseType) {
         final MetadataStandard  standard = MetadataStandard.ISO_19115;
         final TreeTableView table = new TreeTableView(standard, metadata, baseType, valuePolicy);
         return (TreeNode) table.getRoot();
@@ -113,7 +118,7 @@ public final strictfp class TreeNodeTest
     @Test
     public void testRootNode() {
         final DefaultCitation citation = TreeNodeChildrenTest.metadataWithoutCollections();
-        final TreeNode node = create(citation, Citation.class, ValueExistencePolicy.NON_EMPTY);
+        final TreeNode node = create(citation, Citation.class);
         assertEquals("getName()",        "Citation",     node.getName());
         assertEquals("getIdentifier()",  "CI_Citation",  node.getIdentifier());
         assertEquals("baseType",         Citation.class, node.baseType);
@@ -137,7 +142,7 @@ public final strictfp class TreeNodeTest
     @DependsOnMethod("testRootNode")            // Because tested more basic methods than
'getValue(TableColumn)'.
     public void testGetNameForSingleton() {
         final DefaultCitation citation = TreeNodeChildrenTest.metadataWithSingletonInCollections();
-        assertColumnContentEquals(create(citation, Citation.class, ValueExistencePolicy.NON_EMPTY),
TableColumn.NAME,
+        assertColumnContentEquals(create(citation, Citation.class), TableColumn.NAME,
             "Citation",
               "Title",
               "Alternate title",
@@ -154,7 +159,7 @@ public final strictfp class TreeNodeTest
     @DependsOnMethod("testGetNameForSingleton")
     public void testGetNameForMultiOccurrences() {
         final DefaultCitation citation = TreeNodeChildrenTest.metadataWithMultiOccurrences();
-        assertColumnContentEquals(create(citation, Citation.class, ValueExistencePolicy.NON_EMPTY),
TableColumn.NAME,
+        assertColumnContentEquals(create(citation, Citation.class), TableColumn.NAME,
             "Citation",
               "Title",
               "Alternate title (1 of 2)",
@@ -166,15 +171,38 @@ public final strictfp class TreeNodeTest
     }
 
     /**
-     * Tests {@link TreeNode#getName()} on a metadata with a deeper hierarchy.
+     * Compares the result of the given getter method invoked on all nodes of {@link #metadataWithHierarchy()}.
+     * In the particular case of the {@link TableColumn#NAME}, international strings are
replaced by unlocalized
+     * strings before comparisons.
      *
-     * @see <a href="https://issues.apache.org/jira/browse/SIS-298">SIS-298</a>
+     * <p>If {@link #valuePolicy} is {@link ValueExistencePolicy#COMPACT}, then this
method removes the elements at
+     * indices 0, 6 and 10 (if {@code offset} = 0) or 1, 7 and 11 (if {@code offset} = 1)
from the {@code expected}
+     * array before to perform the comparison.</p>
+     *
+     * @param  offset    0 if compact mode excludes the parent, or 1 if compact mode exclude
the first child.
+     * @param  column    the column from which to get a value.
+     * @param  expected  the expected values. The first value is the result of the getter
method
+     *                   applied on the given node, and all other values are the result of
the
+     *                   getter method applied on the children, in iteration order.
+     */
+    private void assertCitationContentEquals(final int offset, final TableColumn<?>
column, final Object... expected) {
+        if (valuePolicy == ValueExistencePolicy.COMPACT) {
+            assertEquals(19, expected.length);
+            System.arraycopy(expected, 11+offset, expected, 10+offset,  8-offset);    //
Compact the "Individual" element.
+            System.arraycopy(expected,  7+offset, expected,  6+offset, 11-offset);    //
Compact the "Organisation" element.
+            System.arraycopy(expected,  1+offset, expected,    offset, 16-offset);    //
Compact the "Title" element.
+            Arrays.fill(expected, 16, 19, null);
+        }
+        assertColumnContentEquals(create(metadataWithHierarchy(), Citation.class), column,
expected);
+    }
+
+    /**
+     * Tests {@link TreeNode#getName()} on a metadata with a deeper hierarchy.
      */
     @Test
     @DependsOnMethod("testGetNameForMultiOccurrences")
     public void testGetNameForHierarchy() {
-        final DefaultCitation citation = metadataWithHierarchy();
-        assertColumnContentEquals(create(citation, Citation.class, ValueExistencePolicy.NON_EMPTY),
TableColumn.NAME,
+        assertCitationContentEquals(1, TableColumn.NAME,
             "Citation",
               "Title",
               "Alternate title (1 of 2)",
@@ -182,11 +210,11 @@ public final strictfp class TreeNodeTest
               "Edition",
               "Cited responsible party (1 of 2)",
                 "Organisation",                         // A Party subtype
-        //        "Name",                               // Value reported in "Organisation"
node.
+                  "Name",                               // In COMPACT mode, this value is
associated to "Organisation" node.
                 "Role",
               "Cited responsible party (2 of 2)",
                 "Individual",                           // A Party subtype
-        //        "Name",                               // Value reported in "Individual"
node.
+                  "Name",                               // In COMPACT mode, this value is
associated to "Individual" node.
                   "Contact info",
                     "Address",
                       "Electronic mail address",
@@ -205,8 +233,7 @@ public final strictfp class TreeNodeTest
     @Test
     @DependsOnMethod("testGetNameForMultiOccurrences")     // Because similar to names, which
were tested progressively.
     public void testGetIdentifier() {
-        final DefaultCitation citation = metadataWithHierarchy();
-        assertColumnContentEquals(create(citation, Citation.class, ValueExistencePolicy.NON_EMPTY),
TableColumn.IDENTIFIER,
+        assertCitationContentEquals(1, TableColumn.IDENTIFIER,
             "CI_Citation",
               "title",
               "alternateTitle",
@@ -214,11 +241,11 @@ public final strictfp class TreeNodeTest
               "edition",
               "citedResponsibleParty",
                 "party",
-        //        "name",                                   — value reported in "party"
node.
+                  "name",                               // In COMPACT mode, this value is
associated to "party" node.
                 "role",
               "citedResponsibleParty",
                 "party",
-        //        "name",                                   — value reported in "party"
node.
+                  "name",                               // In COMPACT mode, this value is
associated to "party" node.
                   "contactInfo",
                     "address",
                       "electronicMailAddress",
@@ -236,8 +263,7 @@ public final strictfp class TreeNodeTest
     public void testGetIndex() {
         final Integer ZERO = 0;
         final Integer ONE  = 1;
-        final DefaultCitation citation = metadataWithHierarchy();
-        assertColumnContentEquals(create(citation, Citation.class, ValueExistencePolicy.NON_EMPTY),
TableColumn.INDEX,
+        assertCitationContentEquals(1, TableColumn.INDEX,
             null,           // CI_Citation
               null,         // title
               ZERO,         // alternateTitle
@@ -245,11 +271,11 @@ public final strictfp class TreeNodeTest
               null,         // edition
               ZERO,         // citedResponsibleParty
                 ZERO,       // party (organisation)
-        //        null,     // name                         — value reported in "party"
node.
+                  null,     // name                         — in COMPACT mode, this value
is associated to "party" node.
                 null,       // role
               ONE,          // citedResponsibleParty
                 ZERO,       // party (individual)
-        //        null,     // name                         — value reported in "party"
node.
+                  null,     // name                         — in COMPACT mode, this value
is associated to "party" node.
                   ZERO,     // contactInfo
                     ZERO,   // address
                       ZERO, // electronicMailAddress
@@ -265,19 +291,18 @@ public final strictfp class TreeNodeTest
     @Test
     @DependsOnMethod("testGetIdentifier")       // Because if identifiers are wrong, we are
looking at wrong properties.
     public void testGetElementType() {
-        final DefaultCitation citation = metadataWithHierarchy();
-        assertColumnContentEquals(create(citation, Citation.class, ValueExistencePolicy.NON_EMPTY),
TableColumn.TYPE,
+        assertCitationContentEquals(0, TableColumn.TYPE,
             Citation.class,
               InternationalString.class,
               InternationalString.class,
               InternationalString.class,
               InternationalString.class,
               Responsibility.class,
-        //      Party.class,                            // Value with be the one of "name"
node instead.
+                Party.class,                            // In COMPACT mode, value with be
the one of "name" node instead.
                   InternationalString.class,            // Name
                 Role.class,
               Responsibility.class,
-        //      Party.class,                            // Value with be the one of "name"
node instead.
+                Party.class,                            // In COMPACT mode, value with be
the one of "name" node instead.
                   InternationalString.class,            // Name
                   Contact.class,
                     Address.class,
@@ -294,18 +319,19 @@ public final strictfp class TreeNodeTest
     @Test
     @DependsOnMethod("testGetIdentifier")       // Because if identifiers are wrong, we are
looking at wrong properties.
     public void testGetValue() {
-        final DefaultCitation citation = metadataWithHierarchy();
-        assertColumnContentEquals(create(citation, Citation.class, ValueExistencePolicy.NON_EMPTY),
TableColumn.VALUE,
+        assertCitationContentEquals(0, TableColumn.VALUE,
             null,                               // Citation
               "Some title",
               "First alternate title",
               "Second alternate title",
               "Some edition",
               null,                             // ResponsibleParty
-                "Some organisation",            // Party (organisation)
+                null,                           // Party (organisation)
+                  "Some organisation",
                 Role.DISTRIBUTOR,
               null,                             // ResponsibleParty
-                "Some person of contact",       // Party (individual)
+                null,                           // Party (individual)
+                  "Some person of contact",
                   null,                         // Contact
                     null,                       // Address
                       "Some email",
@@ -322,7 +348,7 @@ public final strictfp class TreeNodeTest
     @DependsOnMethod("testGetValue")
     public void testNewChild() {
         final DefaultCitation citation = metadataWithHierarchy();
-        final TreeNode node = create(citation, Citation.class, ValueExistencePolicy.NON_EMPTY);
+        final TreeNode node = create(citation, Citation.class);
         /*
          * Ensure that we can not overwrite existing nodes.
          */
@@ -359,35 +385,57 @@ public final strictfp class TreeNodeTest
      * on all children of that given. In the particular case of the {@link TableColumn#NAME},
      * international strings are replaced by unlocalized strings before comparisons.
      *
-     * @param  node     the node for which to test the children.
-     * @param  column   the column from which to get a value.
-     * @param  values   the expected values. The first value is the result of the getter
method
-     *                  applied on the given node, and all other values are the result of
the
-     *                  getter method applied on the children, in iteration order.
+     * @param  node      the node for which to test the children.
+     * @param  column    the column from which to get a value.
+     * @param  expected  the expected values. The first value is the result of the getter
method
+     *                   applied on the given node, and all other values are the result of
the
+     *                   getter method applied on the children, in iteration order.
      */
-    private static void assertColumnContentEquals(final TreeNode node,
-            final TableColumn<?> column, final Object... values)
+    private void assertColumnContentEquals(final TreeNode node,
+            final TableColumn<?> column, final Object... expected)
     {
-        assertEquals("Missing values in the tested metadata.", values.length,
-                assertColumnContentEquals(node, column, values, 0));
+        int count = expected.length;
+        if (valuePolicy == ValueExistencePolicy.COMPACT) {
+            while (expected[count-1] == null) count--;
+        }
+        assertEquals("Missing values in the tested metadata.", count,
+                assertColumnContentEquals(node, column, expected, 0));
     }
 
     /**
      * Implementation of the above {@code assertGetterReturns}, to be invoked recursively.
+     *
+     * @return number of nodes found in the given metadata tree.
      */
     private static int assertColumnContentEquals(final TreeTable.Node node, final TableColumn<?>
column,
-            final Object[] values, int index)
+            final Object[] expected, int index)
     {
         final Object actual = node.getValue(column);
         Object unlocalized = actual;
         if (unlocalized instanceof InternationalString) {
             unlocalized = ((InternationalString) unlocalized).toString(Locale.ROOT);
         }
-        assertEquals("values[" + index + ']', values[index++], unlocalized);
+        assertEquals("values[" + index + ']', expected[index++], unlocalized);
         for (final TreeTable.Node child : node.getChildren()) {
-            index = assertColumnContentEquals(child, column, values, index);
+            index = assertColumnContentEquals(child, column, expected, index);
         }
         assertSame("Value shall be stable.", actual, node.getValue(column));
         return index;
     }
+
+    /**
+     * Same tests but using {@link ValueExistencePolicy#COMPACT}.
+     *
+     * @see <a href="https://issues.apache.org/jira/browse/SIS-298">SIS-298</a>
+     */
+    @Test
+    @DependsOnMethod({"testGetNameForHierarchy", "testGetIdentifier", "testGetIndex", "testGetElementType",
"testGetValue"})
+    public void testCompactPolicy() {
+        valuePolicy = ValueExistencePolicy.COMPACT;
+        testGetNameForHierarchy();
+        testGetIdentifier();
+        testGetIndex();
+        testGetElementType();
+        testGetValue();
+    }
 }

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableFormatTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableFormatTest.java?rev=1793768&r1=1793767&r2=1793768&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableFormatTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableFormatTest.java
[UTF-8] Thu May  4 11:09:37 2017
@@ -84,8 +84,7 @@ public final strictfp class TreeTableFor
         final DefaultCitation citation = DefaultCitationTest.create();
         final String text = format.format(citation.asTreeTable());
         assertMultilinesEquals(
-            "Citation\n" +
-            "  ├─Title……………………………………………………………………………
Undercurrent\n" +
+            "Citation………………………………………………………………………………
Undercurrent\n" +
             "  ├─Alternate title…………………………………………………
Andākarento\n" +
             "  ├─Identifier………………………………………………………………
9782505004509\n" +
             "  │   ├─Authority………………………………………………………
International Standard Book Number\n" +

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableViewTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableViewTest.java?rev=1793768&r1=1793767&r2=1793768&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableViewTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/TreeTableViewTest.java
[UTF-8] Thu May  4 11:09:37 2017
@@ -54,8 +54,7 @@ public final strictfp class TreeTableVie
      * with {@link ValueExistencePolicy#NON_EMPTY}.
      */
     private static final String EXPECTED =
-            "Citation\n" +
-            "  ├─Title………………………………………………………………………………………………
Some title\n" +
+            "Citation…………………………………………………………………………………………………
Some title\n" +
             "  ├─Alternate title (1 of 2)……………………………………………
First alternate title\n" +
             "  ├─Alternate title (2 of 2)……………………………………………
Second alternate title\n" +
             "  ├─Edition…………………………………………………………………………………………
Some edition\n" +
@@ -79,7 +78,7 @@ public final strictfp class TreeTableVie
      */
     @Test
     public void testToString() {
-        final TreeTableView metadata = create(ValueExistencePolicy.NON_EMPTY);
+        final TreeTableView metadata = create(ValueExistencePolicy.COMPACT);
         assertMultilinesEquals(EXPECTED, formatNameAndValue(metadata));                 
       // Locale-independent
         assertArrayEquals(toTreeStructure(EXPECTED), toTreeStructure(metadata.toString()));
    // Locale-dependent.
     }
@@ -92,7 +91,7 @@ public final strictfp class TreeTableVie
     @Test
     @DependsOnMethod("testToString")
     public void testSerialization() throws Exception {
-        final Object original = create(ValueExistencePolicy.NON_EMPTY);
+        final Object original = create(ValueExistencePolicy.COMPACT);
         final Object deserialized;
         final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
         try (ObjectOutputStream out = new ObjectOutputStream(buffer)) {



Mime
View raw message