1 6 7 package com.hp.hpl.jena.rdf.model.test; 8 9 import com.hp.hpl.jena.rdf.model.*; 10 import com.hp.hpl.jena.shared.*; 11 12 import java.util.*; 13 import junit.framework.*; 14 15 20 21 public class TestModelBulkUpdate extends ModelTestBase 22 { 23 public TestModelBulkUpdate( String name ) 24 { super( name ); } 25 26 public static TestSuite suite() 27 { return new TestSuite( TestModelBulkUpdate.class ); } 28 29 public void testMBU() 30 { testMBU( ModelFactory.createDefaultModel() ); } 31 32 public void testContains( Model m, Statement [] statements ) 33 { 34 for (int i = 0; i < statements.length; i += 1) 35 assertTrue( "it should be here", m.contains( statements[i] ) ); 36 } 37 38 public void testContains( Model m, List statements ) 39 { 40 for (int i = 0; i < statements.size(); i += 1) 41 assertTrue( "it should be here", m.contains( (Statement) statements.get(i) ) ); 42 } 43 44 public void testOmits( Model m, Statement [] statements ) 45 { 46 for (int i = 0; i < statements.length; i += 1) 47 assertFalse( "it should not be here", m.contains( statements[i] ) ); 48 } 49 50 public void testOmits( Model m, List statements ) 51 { 52 for (int i = 0; i < statements.size(); i += 1) 53 assertFalse( "it should not be here", m.contains( (Statement) statements.get(i) ) ); 54 } 55 56 public void testMBU( Model m ) 57 { 58 Statement [] sArray = statements( m, "moon orbits earth; earth orbits sun" ); 59 List sList = Arrays.asList( statements( m, "I drink tea; you drink coffee" ) ); 60 m.add( sArray ); 61 testContains( m, sArray ); 62 m.add( sList ); 63 testContains( m, sList ); 64 testContains( m, sArray ); 65 66 m.remove( sArray ); 67 testOmits( m, sArray ); 68 testContains( m, sList ); 69 m.remove( sList ); 70 testOmits( m, sArray ); 71 testOmits( m, sList ); 72 } 73 74 public void testBulkByModel() 75 { testBulkByModel( ModelFactory.createDefaultModel() ); } 76 77 public void testBulkByModel( Model m ) 78 { 79 assertEquals( "precondition: model must be empty", 0, m.size() ); 80 Model A = modelWithStatements( "clouds offer rain; trees offer shelter" ); 81 Model B = modelWithStatements( "x R y; y Q z; z P x" ); 82 m.add( A ); 83 assertIsoModels( A, m ); 84 m.add( B ); 85 m.remove( A ); 86 assertIsoModels( B, m ); 87 m.remove( B ); 88 assertEquals( "", 0, m.size() ); 89 } 90 91 public void testBulkRemoveSelf() 92 { 93 Model m = modelWithStatements( "they sing together; he sings alone" ); 94 m.remove( m ); 95 assertEquals( "", 0, m.size() ); 96 } 97 98 public void testBulkByModelReifying() 99 { 100 testBulkByModelReifying( false ); 101 testBulkByModelReifying( true ); 102 } 103 104 public void testBulkByModelReifying( boolean suppress ) 105 { 106 Model m = modelWithStatements( ReificationStyle.Minimal, "a P b" ); 107 addReification( m, "x", "S P O" ); 108 addReification( m, "a", "x R y" ); 109 Model target = modelWithStatements( ReificationStyle.Minimal, "" ); 110 target.add( m, suppress ); 111 target.setNsPrefixes( PrefixMapping.Standard ); 112 assertIsoModels( (suppress ? modelWithStatements("a P b") : m), target ); 113 } 114 115 public void testBulkDeleteByModelReifying() 116 { 117 testBulkDeleteByModelReifying( false ); 118 testBulkDeleteByModelReifying( true ); 119 } 120 121 public void testBulkDeleteByModelReifying( boolean suppress ) 122 { 123 Model target = modelWithStatements( ReificationStyle.Minimal, "" ); 124 addReification( target, "x", "S P O" ); 125 addReification( target, "y", "A P B" ); 126 Model remove = modelWithStatements( "" ); 127 addReification( remove, "y", "A P B" ); 128 Model answer = modelWithStatements( "" ); 129 addReification( answer, "x", "S P O" ); 130 if (suppress) addReification( answer, "y", "A P B" ); 131 target.remove( remove, suppress ); 132 assertIsoModels( answer, target ); 133 } 134 135 public void addReification( Model m, String tag, String statement ) 136 { 137 m.createReifiedStatement( tag, statement( m, statement ) ); 138 } 139 } 140 141 142 | Popular Tags |