sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1724531 [13/13] - in /sis/trunk: ./ application/sis-console/src/main/artifact/bin/ application/sis-console/src/main/artifact/log/ application/sis-console/src/main/java/org/apache/sis/console/ core/sis-build-helper/src/main/java/org/apache/...
Date Wed, 13 Jan 2016 23:59:41 GMT
Modified: sis/trunk/storage/sis-shapefile/src/test/java/org/apache/sis/storage/shapefile/ShapeFileTest.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-shapefile/src/test/java/org/apache/sis/storage/shapefile/ShapeFileTest.java?rev=1724531&r1=1724530&r2=1724531&view=diff
==============================================================================
--- sis/trunk/storage/sis-shapefile/src/test/java/org/apache/sis/storage/shapefile/ShapeFileTest.java
[UTF-8] (original)
+++ sis/trunk/storage/sis-shapefile/src/test/java/org/apache/sis/storage/shapefile/ShapeFileTest.java
[UTF-8] Wed Jan 13 23:59:38 2016
@@ -16,6 +16,7 @@
  */
 package org.apache.sis.storage.shapefile;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
 import java.io.File;
@@ -25,8 +26,10 @@ import java.util.logging.Logger;
 
 import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.test.TestCase;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.apache.sis.feature.AbstractFeature;
+import org.apache.sis.feature.AbstractAttribute;
 
 
 /**
@@ -82,30 +85,118 @@ public final strictfp class ShapeFileTes
      }
 
      /**
-      * Test loading of shapefile descriptors. 
+      * Test loading of shapefile descriptors.
       * @throws URISyntaxException if the resource name is incorrect.
       * @throws DataStoreException if a general file reading trouble occurs.
       */
      @Test
      public void testDescriptors() throws URISyntaxException, DataStoreException {
          Logger log = org.apache.sis.util.logging.Logging.getLogger(ShapeFileTest.class.getName());
-         
+
          ShapeFile shp = new ShapeFile(path("ABRALicenseePt_4326_clipped.shp"));
          shp.loadDescriptors();
-         
+
          assertNotNull("The features type of the shapefile should have been set.", shp.getFeaturesType());
          log.info(MessageFormat.format("ABRALicenseePt_4326_clipped.shp features type : {0}",
shp.getFeaturesType()));
-         
+
          assertNotNull("The shapefile descriptor of the shapefile should have been set.",
shp.getShapefileDescriptor());
          log.info(MessageFormat.format("ABRALicenseePt_4326_clipped.shp shapefile descriptor
: {0}", shp.getShapefileDescriptor()));
 
          assertNotNull("The DBase III fields descriptors of the shapefile should have been
set.", shp.getDatabaseFieldsDescriptors());
          log.info(MessageFormat.format("ABRALicenseePt_4326_clipped.shp DBase fields descriptors
: {0}", shp.getDatabaseFieldsDescriptors()));
-         
+
          // Loading of the descriptor shall not prevent the shapefile from being red again.
          readAll(shp);
      }
-     
+
+     /**
+      * Checks that the reader is able to detect EoF signs in the DBase file.
+      * @throws URISyntaxException if the resource name is incorrect.
+      * @throws DataStoreException if a general file reading trouble occurs.
+      */
+     @Test @Ignore // TODO Adapt with another shapefile.
+     public void testHandleEofNotification() throws URISyntaxException, DataStoreException
{
+         ShapeFile shp = new ShapeFile(path("DEPARTEMENT.SHP"));
+         AbstractFeature first = null, last = null;
+
+         Logger log = org.apache.sis.util.logging.Logging.getLogger(ShapeFileTest.class.getName());
+
+         InputFeatureStream is = shp.findAll();
+         try {
+             AbstractFeature feature = is.readFeature();
+
+             // Read and retain the first and the last feature.
+             while(feature != null) {
+                 if (first == null) {
+                     first = feature;
+                 }
+
+                 // Advice : To debug just before the last record, put a conditional breakpoint
on department name "MEURTHE-ET-MOSELLE".
+                 String deptName = (String)((AbstractAttribute) feature.getProperty("NOM_DEPT")).getValue();
+                 log.info(deptName);
+
+                 last = feature;
+                 feature = is.readFeature();
+             }
+         } finally {
+             is.close();
+         }
+
+         assertNotNull("No record has been found in the DBase file or Shapefile.", first);
+         assertNotNull("This test is not working well : last feature should always be set
if any feature has been found.", last);
+         assertEquals("The first record red must be JURA department.", "JURA", ((AbstractAttribute)
first.getProperty("NOM_DEPT")).getValue());
+         assertEquals("The last record red must be DEUX-SEVRES department.", "DEUX-SEVRES",
((AbstractAttribute) last.getProperty("NOM_DEPT")).getValue());
+     }
+
+     /**
+      * Testing direct access in the shapefile.
+      * @throws URISyntaxException if the resource name is incorrect.
+      * @throws DataStoreException if a general file reading trouble occurs.
+      */
+     @Test
+     public void testDirectAcces() throws DataStoreException, URISyntaxException {
+         ShapeFile shp = new ShapeFile(path("ABRALicenseePt_4326_clipped.shp"));
+
+         // 1) Find the third record, sequentially.
+         AbstractFeature thirdFeature;
+
+         InputFeatureStream isSequential = shp.findAll();
+         try {
+             isSequential.readFeature();
+             isSequential.readFeature();
+             thirdFeature = isSequential.readFeature();
+         } finally {
+             isSequential.close();
+         }
+
+         // Take one of its key fields and another field for reference, and its geometry.
+         Double sequentialAddressId = Double.valueOf((String)(((AbstractAttribute) thirdFeature.getProperty("ADDRID"))).getValue());
+         String sequentialAddress = (String)(((AbstractAttribute) thirdFeature.getProperty("ADDRESS"))).getValue();
+         Object sequentialGeometry = thirdFeature.getPropertyValue("geometry");
+
+         // 2) Now attempt a direct access to this feature.
+         AbstractFeature directFeature;
+         String sql = MessageFormat.format("SELECT * FROM ABRALicenseePt_4326_clipped WHERE
ADDRID = {0,number,#0}", sequentialAddressId);
+
+         InputFeatureStream isDirect = shp.find(sql);
+         try {
+             directFeature = isDirect.readFeature();
+             assertNotNull("The direct access feature returned should not be null", directFeature);
+         } finally {
+             isDirect.close();
+         }
+
+         assertNotNull("The field ADDRID in the direct access feature has not been found
again.", directFeature.getProperty("ADDRID"));
+
+         Double directAddressId = Double.valueOf((String)(((AbstractAttribute) directFeature.getProperty("ADDRID"))).getValue());
+         String directAddress = (String)(((AbstractAttribute) directFeature.getProperty("ADDRESS"))).getValue();
+         Object directGeometry = directFeature.getPropertyValue("geometry");
+
+         assertEquals("DBase part : direct access didn't returned the same address id than
sequential access.", sequentialAddressId, directAddressId);
+         assertEquals("DBase part : direct access didn't returned the same address than sequential
access.", sequentialAddress, directAddress);
+         assertEquals("Shapefile part : direct access didn't returned the same geometry than
sequential access.", sequentialGeometry, directGeometry);
+     }
+
     /**
      * Read all the shapefile content.
      * @param shp Shapefile to read.

Modified: sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelImageInputStream.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelImageInputStream.java?rev=1724531&r1=1724530&r2=1724531&view=diff
==============================================================================
--- sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelImageInputStream.java
[UTF-8] (original)
+++ sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/ChannelImageInputStream.java
[UTF-8] Wed Jan 13 23:59:38 2016
@@ -289,7 +289,7 @@ loop:   while ((c = read()) >= 0) {
      */
     @Override
     public final long skipBytes(final long n) throws IOException {
-        return skipBytes(Math.min((int) n, Integer.MAX_VALUE));
+        return skipBytes((int) Math.min(n, Integer.MAX_VALUE));
     }
 
     /**

Modified: sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java
URL: http://svn.apache.org/viewvc/sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java?rev=1724531&r1=1724530&r2=1724531&view=diff
==============================================================================
--- sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java [UTF-8]
(original)
+++ sis/trunk/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java [UTF-8]
Wed Jan 13 23:59:38 2016
@@ -44,7 +44,8 @@ import org.apache.sis.internal.jdk7.Auto
  *
  * @see DataStores#open(Object)
  */
-public abstract class DataStore implements Localized, AutoCloseable {
+@AutoCloseable
+public abstract class DataStore implements Localized {
     /**
      * The locale to use for formatting warnings.
      *
@@ -146,6 +147,5 @@ public abstract class DataStore implemen
      *
      * @throws DataStoreException If an error occurred while closing this data store.
      */
-    @Override
     public abstract void close() throws DataStoreException;
 }



Mime
View raw message