001: /*
002: (c) Copyright 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: All rights reserved - see end of file.
004: $Id: TestLocationMapperAssembler.java,v 1.4 2008/01/02 12:05:57 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.assembler.test;
008:
009: import java.util.*;
010:
011: import com.hp.hpl.jena.assembler.*;
012: import com.hp.hpl.jena.assembler.assemblers.LocationMapperAssembler;
013: import com.hp.hpl.jena.rdf.model.Resource;
014: import com.hp.hpl.jena.util.*;
015: import com.hp.hpl.jena.vocabulary.LocationMappingVocab;
016:
017: public class TestLocationMapperAssembler extends AssemblerTestBase {
018: public TestLocationMapperAssembler(String name) {
019: super (name);
020: }
021:
022: protected Class getAssemblerClass() {
023: return LocationMapperAssembler.class;
024: }
025:
026: public void testLocationMapperAssemblerType() {
027: testDemandsMinimalType(new LocationMapperAssembler(),
028: JA.LocationMapper);
029: }
030:
031: public void testLocationMapperVocabulary() {
032: assertSubclassOf(JA.LocationMapper, JA.Object);
033: assertDomain(JA.LocationMapper, LocationMappingVocab.mapping);
034: }
035:
036: public void testCreatesLocationMapper() {
037: Resource root = resourceInModel("r rdf:type ja:LocationMapper");
038: Assembler a = new LocationMapperAssembler();
039: Object x = a.open(root);
040: assertInstanceOf(LocationMapper.class, x);
041: }
042:
043: public void testCreatesWithCorrectContent() { // TODO should really have some mroe of these
044: Resource root = resourceInModel("r rdf:type ja:LocationMapper; r lm:mapping _m; _m lm:name 'alpha'; _m lm:altName 'beta'");
045: Assembler a = new LocationMapperAssembler();
046: Object x = a.open(root);
047: assertInstanceOf(LocationMapper.class, x);
048: assertEqualMaps(new LocationMapper(root.getModel()),
049: (LocationMapper) x);
050: }
051:
052: private void assertEqualMaps(LocationMapper expected,
053: LocationMapper got) {
054: Set eAltEntryKeys = IteratorCollection.iteratorToSet(expected
055: .listAltEntries());
056: Set gAltEntryKeys = IteratorCollection.iteratorToSet(got
057: .listAltEntries());
058: Set eAltPrefixKeys = IteratorCollection.iteratorToSet(expected
059: .listAltPrefixes());
060: Set gAltPrefixKeys = IteratorCollection.iteratorToSet(got
061: .listAltPrefixes());
062: assertEquals("altEntry keys dhould be equal", eAltEntryKeys,
063: gAltEntryKeys);
064: assertEquals("prefixEntry keys should be equal",
065: eAltPrefixKeys, gAltPrefixKeys);
066: for (Iterator altKeys = eAltEntryKeys.iterator(); altKeys
067: .hasNext();) {
068: String key = (String) altKeys.next();
069: assertEquals("alt entrys should be equal", expected
070: .getAltEntry(key), got.getAltEntry(key));
071: }
072: for (Iterator preKeys = eAltPrefixKeys.iterator(); preKeys
073: .hasNext();) {
074: String key = (String) preKeys.next();
075: assertEquals("prefix entiries should be equal", expected
076: .getAltPrefix(key), got.getAltPrefix(key));
077: }
078: }
079: }
080:
081: /*
082: * (c) Copyright 2006, 2007, 2008 Hewlett-Packard Development Company, LP
083: * All rights reserved.
084: *
085: * Redistribution and use in source and binary forms, with or without
086: * modification, are permitted provided that the following conditions
087: * are met:
088: * 1. Redistributions of source code must retain the above copyright
089: * notice, this list of conditions and the following disclaimer.
090: * 2. Redistributions in binary form must reproduce the above copyright
091: * notice, this list of conditions and the following disclaimer in the
092: * documentation and/or other materials provided with the distribution.
093: * 3. The name of the author may not be used to endorse or promote products
094: * derived from this software without specific prior written permission.
095: *
096: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
097: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
098: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
099: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
100: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
101: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
102: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
103: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
104: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
105: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
106: */
|