001: /*
002: (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: All rights reserved - see end of file.
004: $Id: NewRegressionAddModel.java,v 1.4 2008/01/02 12:07:04 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.regression;
008:
009: import junit.framework.*;
010:
011: import com.hp.hpl.jena.rdf.model.*;
012: import com.hp.hpl.jena.rdf.model.test.ModelTestBase;
013: import com.hp.hpl.jena.vocabulary.RDF;
014:
015: public class NewRegressionAddModel extends ModelTestBase {
016: public NewRegressionAddModel(String name) {
017: super (name);
018: }
019:
020: public static Test suite() {
021: return new TestSuite(NewRegressionAddModel.class);
022: }
023:
024: protected Model getModel() {
025: return ModelFactory.createDefaultModel();
026: }
027:
028: protected Model m;
029:
030: public void setUp() {
031: m = getModel();
032: }
033:
034: public void tearDown() {
035: m = null;
036: }
037:
038: public void testAddByIterator() {
039: Model m1 = getModel();
040: Model m2 = getModel();
041: modelAdd(m1, "a P b; c P d; x Q 1; y Q 2");
042: m2.add(m1.listStatements());
043: assertEquals(m1.size(), m2.size());
044: assertSameStatements(m1, m2);
045: m1.add(m1.createResource(), RDF.value, m1.createResource());
046: m1.add(m1.createResource(), RDF.value, m1.createResource());
047: m1.add(m1.createResource(), RDF.value, m1.createResource());
048: StmtIterator s = m1.listStatements();
049: m2.remove(s.nextStatement()).remove(s);
050: assertEquals(0, m2.size());
051: }
052:
053: public void testAddByModel() {
054: Model m1 = getModel(), m2 = getModel();
055: modelAdd(m1, "a P b; c P d; x Q 1; y Q 2");
056: m2.add(m1);
057: assertEquals(m1.size(), m2.size());
058: assertSameStatements(m1, m2);
059: }
060:
061: public void testRemoveByModel() {
062: Model m1 = getModel(), m2 = getModel();
063: modelAdd(m1, "a P b; c P d; x Q 1; y Q 2");
064: m2.add(m1).remove(m1);
065: assertEquals(0, m2.size());
066: assertFalse(m2.listStatements().hasNext());
067: }
068:
069: protected void assertSameStatements(Model m1, Model m2) {
070: assertContainsAll(m1, m2);
071: assertContainsAll(m2, m1);
072: }
073:
074: protected void assertContainsAll(Model m1, Model m2) {
075: for (StmtIterator s = m2.listStatements(); s.hasNext();)
076: assertTrue(m1.contains(s.nextStatement()));
077: }
078: }
079:
080: /*
081: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
082: * All rights reserved.
083: *
084: * Redistribution and use in source and binary forms, with or without
085: * modification, are permitted provided that the following conditions
086: * are met:
087: * 1. Redistributions of source code must retain the above copyright
088: * notice, this list of conditions and the following disclaimer.
089: * 2. Redistributions in binary form must reproduce the above copyright
090: * notice, this list of conditions and the following disclaimer in the
091: * documentation and/or other materials provided with the distribution.
092: * 3. The name of the author may not be used to endorse or promote products
093: * derived from this software without specific prior written permission.
094: *
095: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
096: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
097: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
098: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
099: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
100: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
101: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
102: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
103: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
104: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
105: */
|