sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jso...@apache.org
Subject svn commit: r1737814 [2/2] - in /sis/branches/JDK8/core/sis-feature/src: main/java/org/apache/sis/feature/ main/java/org/apache/sis/internal/ main/java/org/apache/sis/internal/feature/ test/java/org/apache/sis/feature/ test/java/org/apache/sis/internal...
Date Tue, 05 Apr 2016 09:55:35 GMT
Added: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/AttributeTypeBuilderTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/AttributeTypeBuilderTest.java?rev=1737814&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/AttributeTypeBuilderTest.java
(added)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/AttributeTypeBuilderTest.java
Tue Apr  5 09:55:35 2016
@@ -0,0 +1,160 @@
+/*
+ * 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.feature;
+
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+import org.opengis.feature.AttributeType;
+import static org.junit.Assert.*;
+
+/**
+ * Tests {@link AttributeTypeBuilder}.
+ *
+ * @author Johann Sorel (Geomatys)
+ * @since   0.7
+ * @version 0.7
+ * @module
+ */
+public class AttributeTypeBuilderTest extends TestCase {
+
+    /**
+     * Test a builder with the minimum number of parameters.
+     */
+    @Test
+    public void testMinimumProperties() {
+
+        final AttributeTypeBuilder atb = new AttributeTypeBuilder();
+
+        //check at least name must be set
+        try{
+            atb.build();
+            fail("Builder should have failed if there is not at least a name set.");
+        }catch(IllegalArgumentException ex){
+            //ok
+        }
+
+        atb.setName("myScope","myName");
+        final AttributeType att = atb.build();
+
+        assertEquals("myScope:myName", att.getName().toString());
+        assertEquals(Object.class, att.getValueClass());
+        assertEquals(null, att.getDefaultValue());
+        assertEquals(null, att.getDefinition());
+        assertEquals(null, att.getDescription());
+        assertEquals(null, att.getDesignation());
+        assertEquals(1, att.getMinimumOccurs());
+        assertEquals(1, att.getMaximumOccurs());
+        
+    }
+
+    /**
+     * Test all properties.
+     */
+    @Test
+    public void testAllProperties() {
+
+        final AttributeTypeBuilder atb = new AttributeTypeBuilder();
+        atb.setName("myScope","myName");
+        atb.setDefinition("test definition");
+        atb.setDesignation("test designation");
+        atb.setDescription("test description");
+        atb.setValueClass(String.class);
+        atb.setDefaultValue("test text with words and letters.");
+        atb.setMinimumOccurs(10);
+        atb.setMaximumOccurs(60);
+        atb.setLengthCharacteristic(80);
+        final AttributeType att = atb.build();
+
+        assertEquals("myScope:myName", att.getName().toString());
+        assertEquals("test definition", att.getDefinition().toString());
+        assertEquals("test description", att.getDescription().toString());
+        assertEquals("test designation", att.getDesignation().toString());
+        assertEquals(String.class, att.getValueClass());
+        assertEquals("test text with words and letters.", att.getDefaultValue());
+        assertEquals(10, att.getMinimumOccurs());
+        assertEquals(60, att.getMaximumOccurs());
+        assertEquals(80, (int)AttributeConvention.getLengthCharacteristic(att));
+    }
+
+    /**
+     * Test copying properties.
+     */
+    @Test
+    public void testCopy() {
+
+        AttributeTypeBuilder atb = new AttributeTypeBuilder();
+        atb.setName("myScope","myName");
+        atb.setDefinition("test definition");
+        atb.setDesignation("test designation");
+        atb.setDescription("test description");
+        atb.setValueClass(String.class);
+        atb.setDefaultValue("test text with words and letters.");
+        atb.setMinimumOccurs(10);
+        atb.setMaximumOccurs(60);
+        atb.setLengthCharacteristic(80);
+        AttributeType att = atb.build();
+
+        //copy the attribute
+        atb = new AttributeTypeBuilder();
+        atb.copy(att);
+        att = atb.build();
+
+        assertEquals("myScope:myName", att.getName().toString());
+        assertEquals("test definition", att.getDefinition().toString());
+        assertEquals("test description", att.getDescription().toString());
+        assertEquals("test designation", att.getDesignation().toString());
+        assertEquals(String.class, att.getValueClass());
+        assertEquals("test text with words and letters.", att.getDefaultValue());
+        assertEquals(10, att.getMinimumOccurs());
+        assertEquals(60, att.getMaximumOccurs());
+        assertEquals(80, (int)AttributeConvention.getLengthCharacteristic(att));
+    }
+
+    /**
+     * Test reset operation.
+     */
+    @Test
+    public void testReset() {
+
+        final AttributeTypeBuilder atb = new AttributeTypeBuilder();
+        atb.setName("myScope","myName1");
+        atb.setDefinition("test definition");
+        atb.setDesignation("test designation");
+        atb.setDescription("test description");
+        atb.setValueClass(String.class);
+        atb.setDefaultValue("test text with words and letters.");
+        atb.setMinimumOccurs(10);
+        atb.setMaximumOccurs(60);
+        atb.setLengthCharacteristic(80);
+        AttributeType att = atb.build();
+
+        atb.reset();
+        atb.setName("myScope","myName2");
+        att = atb.build();
+
+        assertEquals("myScope:myName2", att.getName().toString());
+        assertEquals(Object.class, att.getValueClass());
+        assertEquals(null, att.getDefaultValue());
+        assertEquals(null, att.getDefinition());
+        assertEquals(null, att.getDescription());
+        assertEquals(null, att.getDesignation());
+        assertEquals(1, att.getMinimumOccurs());
+        assertEquals(1, att.getMaximumOccurs());
+
+    }
+
+}

Added: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/FeatureTypeBuilderTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/FeatureTypeBuilderTest.java?rev=1737814&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/FeatureTypeBuilderTest.java
(added)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/internal/feature/FeatureTypeBuilderTest.java
Tue Apr  5 09:55:35 2016
@@ -0,0 +1,232 @@
+/*
+ * 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.feature;
+
+import com.esri.core.geometry.Geometry;
+import com.esri.core.geometry.Point;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.sis.referencing.CommonCRS;
+import org.apache.sis.test.TestCase;
+import static org.junit.Assert.*;
+import org.junit.Test;
+import org.opengis.feature.AttributeType;
+import org.opengis.feature.FeatureType;
+import org.opengis.feature.PropertyType;
+
+/**
+ * Tests {@link FeatureTypeBuilder}.
+ *
+ * @author Johann Sorel (Geomatys)
+ * @since   0.7
+ * @version 0.7
+ * @module
+ */
+public class FeatureTypeBuilderTest extends TestCase {
+
+    /**
+     * Test a builder with the minimum number of parameters.
+     */
+    @Test
+    public void buildMinimal() {
+        final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
+
+        //check at least name must be set
+        try{
+            ftb.build();
+            fail("Builder should have failed if there is not at least a name set.");
+        }catch(IllegalArgumentException ex){
+            //ok
+        }
+
+        ftb.reset();
+        ftb.setName("scope","test");
+        FeatureType type = ftb.build();
+
+        assertEquals("scope:test", type.getName().toString());
+        assertFalse(type.isAbstract());
+        assertEquals(0, type.getProperties(true).size());
+        assertEquals(0, type.getSuperTypes().size());
+
+    }
+
+    /**
+     * Test adding properties.
+     */
+    @Test
+    public void testAddProperties() {
+
+        final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
+        ftb.setName("myScope","myName");
+        ftb.setDefinition("test definition");
+        ftb.setDesignation("test designation");
+        ftb.setDescription("test description");
+        ftb.setAbstract(true);
+        ftb.addProperty("name", String.class);
+        ftb.addProperty("age", Integer.class);
+        ftb.addProperty("location", Point.class, CommonCRS.WGS84.normalizedGeographic());
+        ftb.addProperty("score", Double.class, 5, 50, 10.0);
+
+        final FeatureType type = ftb.build();
+        assertEquals("myScope:myName", type.getName().toString());
+        assertEquals("test definition", type.getDefinition().toString());
+        assertEquals("test description", type.getDescription().toString());
+        assertEquals("test designation", type.getDesignation().toString());
+        assertTrue(type.isAbstract());
+        assertEquals(4, type.getProperties(true).size());
+
+        final List<PropertyType> properties = new ArrayList(type.getProperties(true));
+        assertEquals("name",    properties.get(0).getName().toString());
+        assertEquals("age",     properties.get(1).getName().toString());
+        assertEquals("location",properties.get(2).getName().toString());
+        assertEquals("score",   properties.get(3).getName().toString());
+
+        assertEquals(String.class,  ((AttributeType)properties.get(0)).getValueClass());
+        assertEquals(Integer.class, ((AttributeType)properties.get(1)).getValueClass());
+        assertEquals(Point.class,   ((AttributeType)properties.get(2)).getValueClass());
+        assertEquals(Double.class,  ((AttributeType)properties.get(3)).getValueClass());
+
+        assertEquals(1, ((AttributeType)properties.get(0)).getMinimumOccurs());
+        assertEquals(1, ((AttributeType)properties.get(1)).getMinimumOccurs());
+        assertEquals(1, ((AttributeType)properties.get(2)).getMinimumOccurs());
+        assertEquals(5, ((AttributeType)properties.get(3)).getMinimumOccurs());
+
+        assertEquals( 1, ((AttributeType)properties.get(0)).getMaximumOccurs());
+        assertEquals( 1, ((AttributeType)properties.get(1)).getMaximumOccurs());
+        assertEquals( 1, ((AttributeType)properties.get(2)).getMaximumOccurs());
+        assertEquals(50, ((AttributeType)properties.get(3)).getMaximumOccurs());
+
+        assertEquals(null, ((AttributeType)properties.get(0)).getDefaultValue());
+        assertEquals(null, ((AttributeType)properties.get(1)).getDefaultValue());
+        assertEquals(null, ((AttributeType)properties.get(2)).getDefaultValue());
+        assertEquals(10.0, ((AttributeType)properties.get(3)).getDefaultValue());
+    }
+
+    /**
+     * Test adding properties.
+     */
+    @Test
+    public void testCopy() {
+
+        FeatureTypeBuilder ftb = new FeatureTypeBuilder();
+        ftb.setName("myScope","myName");
+        ftb.setDefinition("test definition");
+        ftb.setDesignation("test designation");
+        ftb.setDescription("test description");
+        ftb.setAbstract(true);
+        ftb.addProperty("name", String.class);
+        ftb.addProperty("age", Integer.class);
+        ftb.addProperty("location", Point.class, CommonCRS.WGS84.normalizedGeographic());
+        ftb.addProperty("score", Double.class, 5, 50, 10.0);
+
+        FeatureType type = ftb.build();
+
+        //copy the feature type
+        ftb = new FeatureTypeBuilder();
+        ftb.copy(type);
+        type = ftb.build();
+
+
+        assertEquals("myScope:myName", type.getName().toString());
+        assertEquals("test definition", type.getDefinition().toString());
+        assertEquals("test description", type.getDescription().toString());
+        assertEquals("test designation", type.getDesignation().toString());
+        assertTrue(type.isAbstract());
+        assertEquals(4, type.getProperties(true).size());
+
+        final List<PropertyType> properties = new ArrayList(type.getProperties(true));
+        assertEquals("name",    properties.get(0).getName().toString());
+        assertEquals("age",     properties.get(1).getName().toString());
+        assertEquals("location",properties.get(2).getName().toString());
+        assertEquals("score",   properties.get(3).getName().toString());
+
+        assertEquals(String.class,  ((AttributeType)properties.get(0)).getValueClass());
+        assertEquals(Integer.class, ((AttributeType)properties.get(1)).getValueClass());
+        assertEquals(Point.class,   ((AttributeType)properties.get(2)).getValueClass());
+        assertEquals(Double.class,  ((AttributeType)properties.get(3)).getValueClass());
+
+        assertEquals(1, ((AttributeType)properties.get(0)).getMinimumOccurs());
+        assertEquals(1, ((AttributeType)properties.get(1)).getMinimumOccurs());
+        assertEquals(1, ((AttributeType)properties.get(2)).getMinimumOccurs());
+        assertEquals(5, ((AttributeType)properties.get(3)).getMinimumOccurs());
+
+        assertEquals( 1, ((AttributeType)properties.get(0)).getMaximumOccurs());
+        assertEquals( 1, ((AttributeType)properties.get(1)).getMaximumOccurs());
+        assertEquals( 1, ((AttributeType)properties.get(2)).getMaximumOccurs());
+        assertEquals(50, ((AttributeType)properties.get(3)).getMaximumOccurs());
+
+        assertEquals(null, ((AttributeType)properties.get(0)).getDefaultValue());
+        assertEquals(null, ((AttributeType)properties.get(1)).getDefaultValue());
+        assertEquals(null, ((AttributeType)properties.get(2)).getDefaultValue());
+        assertEquals(10.0, ((AttributeType)properties.get(3)).getDefaultValue());
+    }
+
+    /**
+     * Test reset operation.
+     */
+    @Test
+    public void testReset(){
+
+        final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
+        ftb.setName("myScope","myName");
+        ftb.setDefinition("test definition");
+        ftb.setDesignation("test designation");
+        ftb.setDescription("test description");
+        ftb.setAbstract(true);
+        ftb.addProperty("name", String.class);
+        ftb.addProperty("age", Integer.class);
+        ftb.addProperty("location", Point.class, CommonCRS.WGS84.normalizedGeographic());
+        ftb.addProperty("score", Double.class, 5, 50, 10.0);
+
+        FeatureType type = ftb.build();
+        ftb.reset();
+        ftb.setName("scope","test");
+        type = ftb.build();
+
+        assertEquals("scope:test", type.getName().toString());
+        assertFalse(type.isAbstract());
+        assertEquals(0, type.getProperties(true).size());
+        assertEquals(0, type.getSuperTypes().size());
+    }
+
+    /**
+     * Test convention properties.
+     */
+    @Test
+    public void testConventionProperties() {
+        final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
+        ftb.setName("scope","test");
+        ftb.setIdOperation("pref.", "name");
+        ftb.setDefaultGeometryOperation("shape");
+        ftb.addProperty("name", String.class);
+        ftb.addProperty("shape", Geometry.class, CommonCRS.WGS84.normalizedGeographic());
+
+        final FeatureType type = ftb.build();
+        assertEquals("scope:test", type.getName().toString());
+        assertFalse(type.isAbstract());
+        assertEquals(5, type.getProperties(true).size());
+
+        final List<PropertyType> properties = new ArrayList(type.getProperties(true));
+        assertEquals(AttributeConvention.ATTRIBUTE_ID, properties.get(0).getName());
+        assertEquals(AttributeConvention.ATTRIBUTE_DEFAULT_GEOMETRY, properties.get(1).getName());
+        assertEquals(AttributeConvention.ATTRIBUTE_BOUNDS, properties.get(2).getName());
+        assertEquals("name", properties.get(3).getName().toString());
+        assertEquals("shape", properties.get(4).getName().toString());
+
+    }
+
+}

Modified: sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java?rev=1737814&r1=1737813&r2=1737814&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java
[UTF-8] Tue Apr  5 09:55:35 2016
@@ -43,8 +43,13 @@ import org.junit.BeforeClass;
     org.apache.sis.feature.SingletonAssociationTest.class,
     org.apache.sis.feature.AbstractOperationTest.class,
     org.apache.sis.feature.LinkOperationTest.class,
+    org.apache.sis.feature.AggregateOperationTest.class,
+    org.apache.sis.feature.BoundsOperationTest.class,
     org.apache.sis.feature.FeatureFormatTest.class,
-    org.apache.sis.feature.FeaturesTest.class
+    org.apache.sis.feature.FeaturesTest.class,
+    org.apache.sis.internal.feature.AttributeConventionTest.class,
+    org.apache.sis.internal.feature.FeatureTypeBuilderTest.class,
+    org.apache.sis.internal.feature.AttributeTypeBuilderTest.class
 })
 public final strictfp class FeatureTestSuite extends TestSuite {
     /**



Mime
View raw message