sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1497825 - in /sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis: test/suite/MetadataTestSuite.java xml/CustomMetadataTest.java
Date Fri, 28 Jun 2013 16:05:32 GMT
Author: desruisseaux
Date: Fri Jun 28 16:05:32 2013
New Revision: 1497825

URL: http://svn.apache.org/r1497825
Log:
More tests.

Added:
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/xml/CustomMetadataTest.java
  (with props)
Modified:
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java

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=1497825&r1=1497824&r2=1497825&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] Fri Jun 28 16:05:32 2013
@@ -62,7 +62,8 @@ import org.junit.BeforeClass;
     org.apache.sis.xml.FreeTextMarshallingTest.class,
     org.apache.sis.xml.NilReasonMarshallingTest.class,
     org.apache.sis.xml.AnchorMarshallingTest.class,
-    org.apache.sis.xml.ObjectReferenceMarshallingTest.class
+    org.apache.sis.xml.ObjectReferenceMarshallingTest.class,
+    org.apache.sis.xml.CustomMetadataTest.class
 })
 public final strictfp class MetadataTestSuite extends TestSuite {
     /**

Added: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/xml/CustomMetadataTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/xml/CustomMetadataTest.java?rev=1497825&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/xml/CustomMetadataTest.java
(added)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/xml/CustomMetadataTest.java
[UTF-8] Fri Jun 28 16:05:32 2013
@@ -0,0 +1,142 @@
+/*
+ * 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.Map;
+import java.util.HashMap;
+import java.util.Collection;
+import java.util.Locale;
+import java.lang.reflect.Proxy;
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationHandler;
+import javax.xml.bind.JAXBException;
+import org.opengis.metadata.Metadata;
+import org.opengis.metadata.identification.*;
+import org.opengis.metadata.citation.Citation;
+import org.opengis.metadata.citation.ResponsibleParty;
+import org.opengis.metadata.constraint.Constraints;
+import org.opengis.metadata.distribution.Format;
+import org.opengis.metadata.extent.Extent;
+import org.opengis.metadata.maintenance.MaintenanceInformation;
+import org.opengis.metadata.spatial.SpatialRepresentationType;
+import org.opengis.util.InternationalString;
+import org.apache.sis.internal.system.DefaultFactories;
+import org.apache.sis.metadata.iso.DefaultMetadata;
+import org.apache.sis.test.XMLTestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Tests XML marshalling of custom implementation of metadata interfaces. The custom implementations
+ * need to be converted to implementations from the {@link org.apache.sis.metadata.iso} package
by
+ * the JAXB converters.
+ *
+ * @author  Damiano Albani (for code snippet on the mailing list)
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-3.14)
+ * @version 0.3
+ * @module
+ */
+public final strictfp class CustomMetadataTest extends XMLTestCase {
+    /**
+     * Tests the marshalling of a metadata implemented by {@link Proxy}.
+     *
+     * @throws JAXBException Should never happen.
+     */
+    @Test
+    public void testProxy() throws JAXBException {
+        /*
+         * A trivial metadata implementation which return the method name
+         * for every attribute of type String.
+         */
+        final InvocationHandler handler = new InvocationHandler() {
+            @Override public Object invoke(Object proxy, Method method, Object[] args) {
+                if (method.getReturnType() == String.class) {
+                    return method.getName();
+                }
+                return null;
+            }
+        };
+        Metadata data = (Metadata) Proxy.newProxyInstance(getClass().getClassLoader(),
+                    new Class<?>[] { Metadata.class }, handler);
+        /*
+         * Wrap the metadata in a DefaultMetadata, and ensure
+         * we can marshall it without an exception being throw.
+         */
+        data = new DefaultMetadata(data);
+        final String xml = XML.marshal(data);
+        /*
+         * A few simple checks.
+         */
+        assertTrue(xml.contains("getMetadataStandardName"));
+        assertTrue(xml.contains("getMetadataStandardVersion"));
+    }
+
+    /**
+     * Tests that the attributes defined in subtypes are also marshalled.
+     *
+     * @throws JAXBException Should never happen.
+     *
+     * @see <a href="http://jira.geotoolkit.org/browse/GEOTK-108">GEOTK-108</a>
+     */
+    @Test
+    public void testSubtypeAttributes() throws JAXBException {
+        final DataIdentification identification = new DataIdentification() {
+            @Override public InternationalString getAbstract() {
+                Map<Locale, String> names = new HashMap<>();
+                names.put(Locale.ENGLISH, "Description");
+                return DefaultFactories.NAMES.createInternationalString(names);
+            }
+
+            @Override public InternationalString getEnvironmentDescription() {
+                Map<Locale, String> names = new HashMap<>();
+                names.put(Locale.ENGLISH, "Environment");
+                return DefaultFactories.NAMES.createInternationalString(names);
+            }
+
+            @Override public InternationalString                   getSupplementalInformation()
   {return null;}
+            @Override public Citation                              getCitation()        
          {return null;}
+            @Override public InternationalString                   getPurpose()         
          {return null;}
+            @Override public Collection<SpatialRepresentationType> getSpatialRepresentationTypes()
{return null;}
+            @Override public Collection<Resolution>                getSpatialResolutions()
        {return null;}
+            @Override public Collection<Locale>                    getLanguages() 
                {return null;}
+            @Override public Collection<CharacterSet>              getCharacterSets()
             {return null;}
+            @Override public Collection<TopicCategory>             getTopicCategories()
           {return null;}
+            @Override public Collection<Extent>                    getExtents()   
                {return null;}
+            @Override public Collection<String>                    getCredits()   
                {return null;}
+            @Override public Collection<Progress>                  getStatus()    
                {return null;}
+            @Override public Collection<ResponsibleParty>          getPointOfContacts()
           {return null;}
+            @Override public Collection<MaintenanceInformation>    getResourceMaintenances()
      {return null;}
+            @Override public Collection<BrowseGraphic>             getGraphicOverviews()
          {return null;}
+            @Override public Collection<Format>                    getResourceFormats()
           {return null;}
+            @Override public Collection<Keywords>                  getDescriptiveKeywords()
       {return null;}
+            @Override public Collection<Usage>                     getResourceSpecificUsages()
    {return null;}
+            @Override public Collection<Constraints>               getResourceConstraints()
       {return null;}
+            @Override public Collection<AggregateInformation>      getAggregationInfo()
           {return null;}
+        };
+        final DefaultMetadata data = new DefaultMetadata();
+        assertTrue(data.getIdentificationInfo().add(identification));
+        final String xml = XML.marshal(data);
+        /*
+         * A few simple checks.
+         */
+        assertTrue("Missing Identification attribute.",     xml.contains("Description"));
+        assertTrue("Missing DataIdentification attribute.", xml.contains("Environment"));
+    }
+}

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

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



Mime
View raw message