sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1494708 - in /sis/branches/JDK7/core: sis-metadata/src/main/java/org/apache/sis/metadata/iso/ sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/ sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/ sis-utility/src/test/java...
Date Wed, 19 Jun 2013 17:46:14 GMT
Author: desruisseaux
Date: Wed Jun 19 17:46:14 2013
New Revision: 1494708

URL: http://svn.apache.org/r1494708
Log:
Added tests for PropertyType (part of 'gco' namespace in ISO 19139 XML).

Added:
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/PropertyTypeMock.java
  (with props)
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/PropertyTypeTest.java
  (with props)
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/StringAdapterTest.java
  (with props)
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/xml/ReferenceResolverMock.java
  (with props)
Modified:
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ISOMetadata.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/InternationalStringConverter.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/ObjectReference.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/PropertyType.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/StringAdapter.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ISOMetadata.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ISOMetadata.java?rev=1494708&r1=1494707&r2=1494708&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ISOMetadata.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ISOMetadata.java
[UTF-8] Wed Jun 19 17:46:14 2013
@@ -104,20 +104,24 @@ public class ISOMetadata extends Modifia
     /**
      * {@inheritDoc}
      *
-     * <p>The default implementation returns a wrapper around the list returned by
{@link #getIdentifiers()}.
+     * <p>The default implementation returns a wrapper around the {@link #identifiers}
list.
      * That map is <cite>live</cite>: changes in the identifiers list will be
reflected in the map,
      * and conversely.</p>
      */
     @Override
     public IdentifierMap getIdentifierMap() {
         /*
-         * We do not cache (for now) the IdentifierMap because it is cheap to create, and
if were
-         * caching it we would need anyway to check if 'identifiers' still references the
same list.
+         * Do not invoke getIdentifiers(), because some subclasses like DefaultCitation and
+         * DefaultObjective override getIdentifiers() in order to return a filtered list.
          */
-        final Collection<Identifier> identifiers = getIdentifiers();
+        identifiers = nonNullCollection(identifiers, Identifier.class);
         if (identifiers == null) {
             return IdentifierMapWithSpecialCases.EMPTY;
         }
+        /*
+         * We do not cache (for now) the IdentifierMap because it is cheap to create, and
if were
+         * caching it we would need anyway to check if 'identifiers' still references the
same list.
+         */
         return new IdentifierMapWithSpecialCases(identifiers);
     }
 }

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/InternationalStringConverter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/InternationalStringConverter.java?rev=1494708&r1=1494707&r2=1494708&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/InternationalStringConverter.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/InternationalStringConverter.java
[UTF-8] Wed Jun 19 17:46:14 2013
@@ -58,6 +58,6 @@ public final class InternationalStringCo
      */
     @Override
     public String marshal(final InternationalString value) {
-        return (value != null) ? value.toString() : null;
+        return StringAdapter.toString(value);
     }
 }

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/ObjectReference.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/ObjectReference.java?rev=1494708&r1=1494707&r2=1494708&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/ObjectReference.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/ObjectReference.java
[UTF-8] Wed Jun 19 17:46:14 2013
@@ -17,7 +17,6 @@
 package org.apache.sis.internal.jaxb.gco;
 
 import java.util.UUID;
-
 import org.apache.sis.xml.XLink;
 import org.apache.sis.xml.IdentifierMap;
 import org.apache.sis.xml.IdentifierSpace;
@@ -129,7 +128,7 @@ final class ObjectReference {
                 metadata = resolver.newIdentifiedObject(context, type, identifiers);
             }
         } else {
-            // If principle, the XML should contain a full metadata object OR a uuidref attribute.
+            // In principle, the XML should contain a full metadata object OR a uuidref attribute.
             // However if both are present, assign the identifiers to that instance.
             if (metadata instanceof IdentifiedObject) {
                 final IdentifierMap map = ((IdentifiedObject) metadata).getIdentifierMap();

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/PropertyType.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/PropertyType.java?rev=1494708&r1=1494707&r2=1494708&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/PropertyType.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/PropertyType.java
[UTF-8] Wed Jun 19 17:46:14 2013
@@ -28,6 +28,7 @@ import org.apache.sis.xml.Namespaces;
 import org.apache.sis.xml.IdentifierMap;
 import org.apache.sis.xml.IdentifierSpace;
 import org.apache.sis.xml.IdentifiedObject;
+import org.apache.sis.xml.ReferenceResolver;
 import org.apache.sis.internal.jaxb.Context;
 import org.apache.sis.util.iso.SimpleInternationalString;
 
@@ -112,12 +113,12 @@ public abstract class PropertyType<Value
         extends XmlAdapter<ValueType,BoundType>
 {
     /**
-     * The wrapped GeoAPI metadata interface.
+     * The wrapped GeoAPI metadata instance.
      */
     protected BoundType metadata;
 
     /**
-     * Either an {@link ObjectReference} or a {@link String}.
+     * Either {@code null}, an {@link ObjectReference} or a {@link String}.
      *
      * <ul>
      *   <li>{@link ObjectReference} defines the {@code idref}, {@code uuidref}, {@code
xlink:href},
@@ -138,34 +139,44 @@ public abstract class PropertyType<Value
     }
 
     /**
-     * Builds an adapter for the given GeoAPI interface.
+     * Builds an adapter for the given GeoAPI interface. This constructor checks if the given
metadata
+     * implements the {@link NilObject} or {@link IdentifiedObject} interface. If the object
implements
+     * both of them (should not happen, but we never know), then the identifiers will have
precedence.
      *
      * @param metadata The interface to wrap.
      */
     protected PropertyType(final BoundType metadata) {
         this.metadata = metadata;
+        if (metadata instanceof NilObject) {
+            final NilReason reason = ((NilObject) metadata).getNilReason();
+            if (reason != null) {
+                reference = reason.toString();
+            }
+        }
         if (metadata instanceof IdentifiedObject) {
             final IdentifierMap map = ((IdentifiedObject) metadata).getIdentifierMap();
             XLink  link = map.getSpecialized(IdentifierSpace.XLINK);
             UUID   uuid = map.getSpecialized(IdentifierSpace.UUID);
             String anyUUID = (uuid != null) ? uuid.toString() : map.get(IdentifierSpace.UUID);
             if (anyUUID != null || link != null) {
-                final Context context = Context.current();
+                final Context           context  = Context.current();
+                final ReferenceResolver resolver = Context.resolver(context);
+                final Class<BoundType>  type     = getBoundType();
                 if (uuid == null) {
                     uuid = ObjectReference.toUUID(context, anyUUID); // May still null.
                 }
-                if (uuid == null || Context.resolver(context).canSubstituteByReference(context,
getBoundType(), metadata, uuid)) {
+                // Check if the user gives us the permission to use those identifiers.
+                if (uuid != null && !resolver.canSubstituteByReference(context, type,
metadata, uuid)) {
+                    uuid = null;
+                }
+                if (link != null && !resolver.canSubstituteByReference(context, type,
metadata, link)) {
+                    link = null;
+                }
+                if (uuid != null || link != null) {
                     reference = new ObjectReference(uuid, anyUUID, link);
-                    return;
                 }
             }
         }
-        if (metadata instanceof NilObject) {
-            final NilReason reason = ((NilObject) metadata).getNilReason();
-            if (reason != null) {
-                reference = reason.toString();
-            }
-        }
     }
 
     /**
@@ -370,7 +381,7 @@ public abstract class PropertyType<Value
     @XmlAttribute(name = "title", namespace = Namespaces.XLINK)
     public final String getTitle() {
         final XLink link = xlink(false);
-        return (link != null) ? toString(link.getTitle()) : null;
+        return (link != null) ? StringAdapter.toString(link.getTitle()) : null;
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/StringAdapter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/StringAdapter.java?rev=1494708&r1=1494707&r2=1494708&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/StringAdapter.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/StringAdapter.java
[UTF-8] Wed Jun 19 17:46:14 2013
@@ -48,28 +48,38 @@ public final class StringAdapter extends
      * If the context is {@code null} or does not specify any locale, then the choice
      * of locale is left to the {@link InternationalString#toString()} implementation.
      *
-     * @param  value The wrapper for the value, or {@code null}.
-     * @return The string representation of the given text, or {@code null}.
+     * @param  text The {@code CharSequence} to convert to a {@code String}, or {@code null}.
+     * @return The localized representation of the given text, or {@code null} if the text
was null.
+     *
+     * @see org.apache.sis.xml.XML#LOCALE
      */
-    public static String toString(final GO_CharacterString value) {
-        if (value != null) {
-            final CharSequence text = value.toCharSequence();
-            if (text != null) {
-                if (text instanceof InternationalString) {
-                    final Context context = Context.current();
-                    if (context != null) {
-                        final Locale locale = context.getLocale();
-                        if (locale != null) {
-                            // While Apache SIS accepts null locale, foreigner
-                            // implementations are not guaranteed to support null.
-                            return ((InternationalString) text).toString(locale);
-                        }
-                    }
+    static String toString(final CharSequence text) {
+        if (text == null) {
+            return null;
+        }
+        if (text instanceof InternationalString) {
+            final Context context = Context.current();
+            if (context != null) {
+                final Locale locale = context.getLocale();
+                if (locale != null) {
+                    // While Apache SIS accepts null locale, foreigner
+                    // implementations are not guaranteed to support null.
+                    return ((InternationalString) text).toString(locale);
                 }
-                return text.toString();
             }
         }
-        return null;
+        return text.toString();
+    }
+
+    /**
+     * Returns the string representation of the given {@code GO_CharacterString} for the
current locale.
+     * The locale is determined by the {@link org.apache.sis.xml.XML#LOCALE} property given
to the marshaller.
+     *
+     * @param  value The wrapper for the value, or {@code null}.
+     * @return The string representation of the given text, or {@code null}.
+     */
+    public static String toString(final GO_CharacterString value) {
+        return (value != null) ? toString(value.toCharSequence()) : null;
     }
 
     /**

Added: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/PropertyTypeMock.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/PropertyTypeMock.java?rev=1494708&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/PropertyTypeMock.java
(added)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/PropertyTypeMock.java
[UTF-8] Wed Jun 19 17:46:14 2013
@@ -0,0 +1,100 @@
+/*
+ * 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.internal.jaxb.gco;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import org.opengis.metadata.Identifier;
+import org.opengis.metadata.quality.Result;
+import org.apache.sis.xml.IdentifiedObject;
+import org.apache.sis.xml.IdentifierMap;
+import org.apache.sis.internal.jaxb.IdentifierMapWithSpecialCases;
+
+
+/**
+ * A dummy {@link PropertyType} implementation, as a wrapper for instances of the
+ * GeoAPI {@link Result} interface.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3
+ * @version 0.3
+ * @module
+ */
+final strictfp class PropertyTypeMock extends PropertyType<PropertyTypeMock, Result>
{
+    /**
+     * Creates a new adapter. Only the {@link #marshal(Object)}
+     * method shall be invoked on that new instance.
+     */
+    PropertyTypeMock() {
+    }
+
+    /**
+     * Creates a new wrapper around the given metadata.
+     * This constructor is for the {@link #wrap} method only.
+     */
+    private PropertyTypeMock(final Result metadata) {
+        super(metadata);
+    }
+
+    /**
+     * Invoked by {@link #marshal(Object)} for wrapping the given pseudo-metadata value.
+     * If this {@code PropertyTypeMock} class was not for testing purpose only,
+     * this method would be invoked by JAXB at marshalling time.
+     *
+     * @param  metadata The pseudo-metadata element to wrap.
+     * @return A {@code PropertyType} wrapping the given the metadata element.
+     */
+    @Override
+    protected PropertyTypeMock wrap(final Result metadata) {
+        return new PropertyTypeMock(metadata);
+    }
+
+    /**
+     * The metadata interface implemented by the objects wrapped by {@code PropertyTypeMock}.
+     */
+    @Override
+    protected Class<Result> getBoundType() {
+        return Result.class;
+    }
+
+    /**
+     * A dummy implementation of the {@link Result} interface, to be used together with {@link
PropertyTypeMock}.
+     */
+    static final class Value implements IdentifiedObject, Result {
+        /** All identifiers associated with this metadata. */
+        private final Collection<Identifier> identifiers;
+
+        /** A view of the identifiers as a map. */
+        private final IdentifierMap map;
+
+        /** Creates a new instance with initially no identifier. */
+        Value() {
+            identifiers = new ArrayList<>();
+            map = new IdentifierMapWithSpecialCases(identifiers);
+        }
+
+        /** Returns the identifiers as a modifiable list. */
+        @Override public Collection<? extends Identifier> getIdentifiers() {
+            return identifiers;
+        }
+
+        /** Returns a view of the identifiers as a map. */
+        @Override public IdentifierMap getIdentifierMap() {
+            return map;
+        }
+    }
+}

Propchange: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/PropertyTypeMock.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/PropertyTypeMock.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/PropertyTypeTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/PropertyTypeTest.java?rev=1494708&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/PropertyTypeTest.java
(added)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/PropertyTypeTest.java
[UTF-8] Wed Jun 19 17:46:14 2013
@@ -0,0 +1,166 @@
+/*
+ * 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.internal.jaxb.gco;
+
+import java.util.UUID;
+import org.apache.sis.internal.jaxb.Context;
+import org.apache.sis.util.iso.SimpleInternationalString;
+import org.apache.sis.xml.XLink;
+import org.apache.sis.xml.IdentifierSpace;
+import org.apache.sis.xml.ReferenceResolverMock;
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Test {@link PropertyType}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3
+ * @version 0.3
+ * @module
+ */
+@DependsOn(org.apache.sis.internal.jaxb.IdentifierMapAdapterTest.class)
+public final strictfp class PropertyTypeTest extends TestCase {
+    /**
+     * The pseudo-metadata object to wrap for testing purpose.
+     */
+    private final PropertyTypeMock.Value metadata = new PropertyTypeMock.Value();
+
+    /**
+     * Simulates the marshalling of the {@link #metadata} value.
+     */
+    private PropertyTypeMock marshal() {
+        /*
+         * The 'new PropertyTypeMock()' below is for creating the adapter, not the wrapper.
The wrapper is created
+         * by the 'marshal' call. This is because our PropertyType implementations are both
adapters and wrappers.
+         */
+        return new PropertyTypeMock().marshal(metadata);
+    }
+
+    /**
+     * Tests the construction of a plain property (no identifier).
+     *
+     * @throws Exception Should never happen.
+     */
+    @Test
+    public void testWithNoReference() throws Exception {
+        final PropertyTypeMock property = marshal();
+        assertSame(metadata, property.metadata);
+        assertNoReference(property);
+    }
+
+    /**
+     * Asserts that the given property has no UUID, XLink or other references.
+     */
+    private static void assertNoReference(final PropertyType<?,?> property) {
+        assertNull ("nilReason", property.getNilReason());
+        assertNull ("uuidref",   property.getUUIDREF());
+        assertNull ("href",      property.getHRef());
+        assertNull ("role",      property.getRole());
+        assertNull ("arcrole",   property.getArcRole());
+        assertNull ("title",     property.getTitle());
+        assertNull ("show",      property.getShow());
+        assertNull ("actuate",   property.getActuate());
+        assertFalse("skip",      property.skip());
+    }
+
+    /**
+     * Tests the construction of an object containing {@code UUID} and {@code XLink} references,
+     * which shall be discarded because didn't gave us the authorization to use them.
+     *
+     * @throws Exception Should never happen.
+     */
+    @Test
+    public void testWithDiscardedReferences() throws Exception {
+        final UUID  uuid = UUID.randomUUID();
+        final XLink link = createXLink();
+        metadata.getIdentifierMap().putSpecialized(IdentifierSpace.UUID,  uuid);
+        metadata.getIdentifierMap().putSpecialized(IdentifierSpace.XLINK, link);
+        final PropertyTypeMock property = marshal();
+        assertSame(metadata, property.metadata);
+        assertNoReference(property);
+    }
+
+    /**
+     * Tests the construction of an object containing a {@link UUID}.
+     *
+     * @throws Exception Should never happen.
+     */
+    @Test
+    public void testWithUUID() throws Exception {
+        final UUID uuid = UUID.randomUUID();
+        metadata.getIdentifierMap().putSpecialized(IdentifierSpace.UUID, uuid);
+        final Context context = ReferenceResolverMock.begin(true);
+        final PropertyTypeMock property;
+        try {
+            property = marshal();
+        } finally {
+            context.finish();
+        }
+        assertSame  (metadata,        property.metadata);
+        assertNull  ("nilReason",     property.getNilReason());
+        assertEquals(uuid.toString(), property.getUUIDREF());
+        assertNull  ("href",          property.getHRef());
+        assertNull  ("role",          property.getRole());
+        assertNull  ("arcrole",       property.getArcRole());
+        assertNull  ("title",         property.getTitle());
+        assertNull  ("show",          property.getShow());
+        assertNull  ("actuate",       property.getActuate());
+    }
+
+    /**
+     * Creates a dummy XLink.
+     */
+    private static XLink createXLink() {
+        final XLink link = new XLink();
+        link.setShow(XLink.Show.REPLACE);
+        link.setActuate(XLink.Actuate.ON_LOAD);
+        link.setTitle(new SimpleInternationalString("myResult"));
+        return link;
+    }
+
+    /**
+     * Tests the construction of an object containing a {@link XLink}.
+     *
+     * @throws Exception Should never happen.
+     */
+    @Test
+    public void testWithXLink() throws Exception {
+        final XLink link = createXLink();
+        metadata.getIdentifierMap().putSpecialized(IdentifierSpace.XLINK, link);
+        final Context context = ReferenceResolverMock.begin(true);
+        final PropertyTypeMock property;
+        try {
+            property = marshal();
+        } finally {
+            context.finish();
+        }
+        assertSame  (metadata,              property.metadata);
+        assertNull  ("nilReason",           property.getNilReason());
+        assertNull  ("uuidref",             property.getUUIDREF());
+        assertNull  ("href",                property.getHRef());
+        assertNull  ("role",                property.getRole());
+        assertNull  ("arcrole",             property.getArcRole());
+        assertEquals("myResult",            property.getTitle());
+        assertEquals(XLink.Show.REPLACE,    property.getShow());
+        assertEquals(XLink.Actuate.ON_LOAD, property.getActuate());
+    }
+}

Propchange: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/PropertyTypeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/PropertyTypeTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/StringAdapterTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/StringAdapterTest.java?rev=1494708&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/StringAdapterTest.java
(added)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/StringAdapterTest.java
[UTF-8] Wed Jun 19 17:46:14 2013
@@ -0,0 +1,81 @@
+/*
+ * 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.internal.jaxb.gco;
+
+import java.util.Locale;
+import org.apache.sis.util.iso.SimpleInternationalString;
+import org.apache.sis.util.iso.DefaultInternationalString;
+import org.apache.sis.internal.jaxb.Context;
+import org.apache.sis.test.DependsOnMethod;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Tests {@link StringAdapter}
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3
+ * @version 0.3
+ * @module
+ */
+public final strictfp class StringAdapterTest extends TestCase {
+    /**
+     * Tests {@link StringAdapter#toString(CharSequence)} for the trivial cases.
+     */
+    @Test
+    public void testToUnlocalizedString() {
+        assertNull  (        StringAdapter.toString((CharSequence) null));
+        assertEquals("Test", StringAdapter.toString("Test"));
+        assertEquals("Test", StringAdapter.toString(new SimpleInternationalString("Test")));
+    }
+
+    /**
+     * Tests {@link StringAdapter#toString(CharSequence)} for an {@link InternationalString}
+     * having loalization in different languages.
+     */
+    @Test
+    @DependsOnMethod("testToUnlocalizedString")
+    public void testToLocalizedString() {
+        final DefaultInternationalString i18n = new DefaultInternationalString();
+        i18n.add(Locale.ENGLISH,  "A word");
+        i18n.add(Locale.FRENCH,   "Un mot");
+        i18n.add(Locale.JAPANESE, "言葉");
+        Context.push(Locale.JAPANESE);
+        try {
+            assertEquals("言葉", StringAdapter.toString(i18n));
+            Context.push(Locale.FRENCH);
+            try {
+                assertEquals("Un mot", StringAdapter.toString(i18n));
+                Context.push(Locale.ENGLISH);
+                try {
+                    assertEquals("A word", StringAdapter.toString(i18n));
+                } finally {
+                    Context.pull();
+                }
+                assertEquals("Un mot", StringAdapter.toString(i18n));
+            } finally {
+                Context.pull();
+            }
+            assertEquals("言葉", StringAdapter.toString(i18n));
+        } finally {
+            Context.pull();
+        }
+    }
+}

Propchange: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/StringAdapterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/StringAdapterTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java?rev=1494708&r1=1494707&r2=1494708&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
[UTF-8] Wed Jun 19 17:46:14 2013
@@ -114,7 +114,9 @@ import org.junit.BeforeClass;
     org.apache.sis.xml.OGCNamespacePrefixMapperTest.class,
     org.apache.sis.xml.MarshallerPoolTest.class,
     org.apache.sis.internal.jaxb.IdentifierMapAdapterTest.class,
-    org.apache.sis.internal.jaxb.IdentifierMapWithSpecialCasesTest.class
+    org.apache.sis.internal.jaxb.IdentifierMapWithSpecialCasesTest.class,
+    org.apache.sis.internal.jaxb.gco.StringAdapterTest.class,
+    org.apache.sis.internal.jaxb.gco.PropertyTypeTest.class
 })
 public final strictfp class UtilityTestSuite extends TestSuite {
     /**

Added: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/xml/ReferenceResolverMock.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/xml/ReferenceResolverMock.java?rev=1494708&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/xml/ReferenceResolverMock.java
(added)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/xml/ReferenceResolverMock.java
[UTF-8] Wed Jun 19 17:46:14 2013
@@ -0,0 +1,76 @@
+/*
+ * 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.xml;
+
+import java.util.UUID;
+import org.apache.sis.internal.jaxb.Context;
+
+
+/**
+ * A dummy implementation of {@link ReferenceResolver} which authorizes the replacement of
metadata objects
+ * by their {@link XLink} or {@link UUID} references. This resolver is used in test cases
wanting to verify
+ * identifier substitutions.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3
+ * @version 0.3
+ * @module
+ */
+public final strictfp class ReferenceResolverMock extends ReferenceResolver {
+    /**
+     * Creates a new reference resolver.
+     */
+    private ReferenceResolverMock() {
+    }
+
+    /**
+     * Creates a new SIS context using a {@code ReferenceResolverMock}.
+     * Callers shall use this method in a {@code try} … {@code finally} block as below:
+     *
+     * {@preformat java
+     *     final Context context = ReferenceResolverMock.begin(true);
+     *     try {
+     *         // So some test
+     *     } finally {
+     *         context.finish();
+     *     }
+     * }
+     *
+     * @param  marshalling {@code true} for marshalling, or {@code false} for unmarshalling.
+     * @return The (un)marshalling context.
+     */
+    public static Context begin(final boolean marshalling) {
+        return new Context(null, new ReferenceResolverMock(), null, null, null, null,
+                marshalling ? Context.MARSHALLING : 0);
+    }
+
+    /**
+     * Unconditionally returns {@code true}.
+     */
+    @Override
+    public <T> boolean canSubstituteByReference(final MarshalContext context, final
Class<T> type, final T object, final UUID uuid) {
+        return true;
+    }
+
+    /**
+     * Unconditionally returns {@code true}.
+     */
+    @Override
+    public <T> boolean canSubstituteByReference(final MarshalContext context, final
Class<T> type, final T object, final XLink link) {
+        return true;
+    }
+}

Propchange: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/xml/ReferenceResolverMock.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/xml/ReferenceResolverMock.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8



Mime
View raw message