コード例 #1
0
  public void testReadAllRecords() throws IOException {
    FeatureCollection records = store.getRecords(Query.ALL, Transaction.AUTO_COMMIT);
    int fileCount = root.list(new RegexFileFilter("Record_.*\\.xml")).length;
    assertEquals(fileCount, records.size());

    FeatureIterator<Feature> fi = records.features();
    try {
      while (fi.hasNext()) {
        Feature f = fi.next();

        // check the id has be read and matches the expected format (given what we have in the
        // files)
        String id = getSimpleLiteralValue(f, "identifier");
        assertNotNull(id);
        assertTrue(
            id.matches("urn:uuid:[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}"));

        // check the feature id is the same as the id attribute
        assertEquals(id, f.getIdentifier().getID());

        // the other thing we always have in these records is the type
        Attribute type = (Attribute) f.getProperty("type");
        assertNotNull(type);
        assertNotNull(type.getValue());
      }
    } finally {
      fi.close();
    }
  }
コード例 #2
0
  public void testMaxFeatures() throws IOException {
    Query query = new Query("Record");
    query.setMaxFeatures(2);

    FeatureCollection records = store.getRecords(query, Transaction.AUTO_COMMIT);
    assertEquals(2, records.size());
  }
コード例 #3
0
 public void testSpatialFilterWorld() throws IOException {
   Filter filter = FF.bbox("", -90, -180, 90, 180, CSWRecordDescriptor.DEFAULT_CRS_NAME);
   FeatureCollection records =
       store.getRecords(new Query("Record", filter), Transaction.AUTO_COMMIT);
   // there are only 3 records with a bbox
   assertEquals(3, records.size());
 }
コード例 #4
0
  public void testOffsetFeatures() throws IOException {
    Query queryAll = new Query("Record");
    FeatureCollection allRecords = store.getRecords(queryAll, Transaction.AUTO_COMMIT);
    int size = allRecords.size();
    assertEquals(12, size);

    // with an offset
    Query queryOffset = new Query("Record");
    queryOffset.setStartIndex(1);
    FeatureCollection offsetRecords = store.getRecords(queryOffset, Transaction.AUTO_COMMIT);
    assertEquals(size - 1, offsetRecords.size());

    // paged one, but towards the end so that we won't get a full page
    Query queryPaged = new Query("Record");
    queryPaged.setStartIndex(10);
    queryPaged.setMaxFeatures(3);
    FeatureCollection pagedRecords = store.getRecords(queryPaged, Transaction.AUTO_COMMIT);
    assertEquals(2, pagedRecords.size());
  }
コード例 #5
0
 public void testScheme() throws IOException {
   Filter filter =
       FF.equals(
           FF.property("dc:identifier/dc:value", CSWRecordDescriptor.NAMESPACES),
           FF.literal("urn:uuid:6a3de50b-fa66-4b58-a0e6-ca146fdd18d4"));
   FeatureCollection records =
       store.getRecords(new Query("Record", filter), Transaction.AUTO_COMMIT);
   assertEquals(1, records.size());
   Feature record = (Feature) records.toArray()[0];
   assertEquals("http://www.digest.org/2.1", getSimpleLiteralScheme(record, "subject"));
 }
コード例 #6
0
 public void testSpatialFilter() throws IOException {
   Filter filter =
       FF.bbox("", 60.042, 13.754, 68.410, 17.920, CSWRecordDescriptor.DEFAULT_CRS_NAME);
   FeatureCollection records =
       store.getRecords(new Query("Record", filter), Transaction.AUTO_COMMIT);
   assertEquals(1, records.size());
   Feature record = (Feature) records.toArray()[0];
   assertEquals(
       "urn:uuid:1ef30a8b-876d-4828-9246-c37ab4510bbd",
       getSimpleLiteralValue(record, "identifier"));
 }
コード例 #7
0
  public void testSortNatural() throws IOException {
    Query queryImage = new Query("Record");
    queryImage.setSortBy(new SortBy[] {SortBy.NATURAL_ORDER});

    FeatureCollection records = store.getRecords(queryImage, Transaction.AUTO_COMMIT);
    assertEquals(12, records.size());

    // check they were sorted
    final List<String> values = collectElement(records, "identifier");
    List<String> sorted = new ArrayList<String>(values);
    Collections.sort(sorted);
    assertEquals(sorted, values);
  }
コード例 #8
0
 public void testElementValueFilter() throws IOException {
   Filter filter =
       FF.equals(
           FF.property("dc:identifier/dc:value", CSWRecordDescriptor.NAMESPACES),
           FF.literal("urn:uuid:1ef30a8b-876d-4828-9246-c37ab4510bbd"));
   FeatureCollection records =
       store.getRecords(new Query("Record", filter), Transaction.AUTO_COMMIT);
   assertEquals(1, records.size());
   Feature record = (Feature) records.toArray()[0];
   assertEquals(
       "urn:uuid:1ef30a8b-876d-4828-9246-c37ab4510bbd",
       getSimpleLiteralValue(record, "identifier"));
   assertEquals("http://purl.org/dc/dcmitype/Service", getSimpleLiteralValue(record, "type"));
   assertEquals(
       "Proin sit amet justo. In justo. Aenean adipiscing nulla id tellus.",
       getSimpleLiteralValue(record, "abstract"));
 }
コード例 #9
0
  public void testLimitAttributes() throws IOException {
    Query query = new Query("Record");
    Filter typeDataset =
        FF.equals(
            FF.property("dc:type/dc:value", CSWRecordDescriptor.NAMESPACES),
            FF.literal("http://purl.org/dc/dcmitype/Dataset"));
    query.setFilter(typeDataset);
    query.setSortBy(
        new SortBy[] {
          new SortByImpl(
              FF.property("dc:subject/dc:value", CSWRecordDescriptor.NAMESPACES),
              SortOrder.ASCENDING)
        });
    // select some properties we did not use for filtering and sorting
    query.setProperties(
        Arrays.asList(FF.property("dc:identifier", CSWRecordDescriptor.NAMESPACES)));

    FeatureCollection records = store.getRecords(query, Transaction.AUTO_COMMIT);
    assertEquals(3, records.size());

    // check the properties and collect their identifier
    final List<String> values = new ArrayList<String>();
    records.accepts(
        new FeatureVisitor() {

          @Override
          public void visit(Feature feature) {
            // has the id
            ComplexAttribute id = (ComplexAttribute) feature.getProperty("identifier");
            assertNotNull(id);
            String value = (String) id.getProperty("value").getValue();
            values.add(value);

            // only has the id
            assertEquals(1, feature.getProperties().size());
          }
        },
        null);

    // if they were actually sorted by subject, here is the expected identifier order
    assertEquals("urn:uuid:9a669547-b69b-469f-a11f-2d875366bbdc", values.get(0));
    assertEquals("urn:uuid:88247b56-4cbc-4df9-9860-db3f8042e357", values.get(1));
    assertEquals("urn:uuid:94bc9c83-97f6-4b40-9eb8-a8e8787a5c63", values.get(2));
  }
コード例 #10
0
  public void testSortAscend() throws IOException {
    Query queryImage = new Query("Record");
    queryImage.setFilter(
        FF.equals(
            FF.property("dc:type/dc:value", CSWRecordDescriptor.NAMESPACES),
            FF.literal("http://purl.org/dc/dcmitype/Image")));
    queryImage.setSortBy(
        new SortBy[] {
          new SortByImpl(
              FF.property("dc:title/dc:value", CSWRecordDescriptor.NAMESPACES), SortOrder.ASCENDING)
        });

    FeatureCollection records = store.getRecords(queryImage, Transaction.AUTO_COMMIT);
    // there are only 3 records with Image type
    assertEquals(3, records.size());

    // check they were sorted
    final List<String> values = collectElement(records, "title");
    assertEquals(3, values.size());
    assertEquals("Lorem ipsum", values.get(0));
    assertEquals("Lorem ipsum dolor sit amet", values.get(1));
    assertEquals("Vestibulum massa purus", values.get(2));
  }