KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdf > model > test > TestModelSpecMore


1 /*
2 (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3 [See end of file]
4 $$
5 */

6 package com.hp.hpl.jena.rdf.model.test;
7
8 import java.io.*;
9
10 import com.hp.hpl.jena.rdf.model.*;
11 import com.hp.hpl.jena.util.* ;
12
13 import junit.framework.TestSuite;
14
15 /**
16     A second bunch of tests for ModelSpecs [because the first bunch is too busy]
17 */

18 public class TestModelSpecMore extends ModelTestBase
19     {
20
21     public TestModelSpecMore( String JavaDoc name )
22         { super( name ); }
23
24     public static TestSuite suite()
25         { return new TestSuite( TestModelSpecMore.class ); }
26     
27     public void testLoadWorks() throws Exception JavaDoc
28         {
29         String JavaDoc url = makeModel( "a bb c" );
30         Model wanted = FileManager.get().loadModel( url );
31         Model spec = modelWithStatements( "_root rdf:type jms:PlainModelSpec; _root jms:maker jms:MemMaker; _root jms:loadWith " + url );
32         ModelSpec ms = ModelFactory.createSpec( spec );
33         Model m = ModelFactory.createModel( ms );
34         assertIsoModels( wanted, m );
35         }
36     
37     public void testLoadMultiWorks() throws Exception JavaDoc
38         {
39         String JavaDoc url1 = makeModel( "dogs may bark" ), url2 = makeModel( "pigs might fly" );
40         Model wanted = FileManager.get().loadModel(url1) ;
41         FileManager.get().readModel(wanted,url2) ;
42         Model spec = modelWithStatements( "_root rdf:type jms:PlainModelSpec; _root jms:maker jms:MemMaker" );
43         modelAdd( spec, "_root jms:loadWith " + url1 );
44         modelAdd( spec, "_root jms:loadWith " + url2 );
45         ModelSpec ms = ModelFactory.createSpec( spec );
46         Model m = ModelFactory.createModel( ms );
47         assertIsoModels( wanted, m );
48         }
49     
50     protected String JavaDoc makeModel( String JavaDoc statements ) throws FileNotFoundException, IOException
51         {
52         String JavaDoc name = FileUtils.tempFileName( "test-load-with-", ".rdf" ).getAbsolutePath();
53         Model m = modelWithStatements( statements );
54         FileOutputStream fos = new FileOutputStream( name );
55         m.write( fos, FileUtils.guessLang( name ) );
56         fos.close();
57         return "file:" + name;
58         }
59     
60     public void testOpenModel()
61         {
62         Model s = modelWithStatements( "_root jms:maker jms:MemMaker" );
63         assertTrue( ModelFactory.createSpec( s ).openModel( "nosuch" ) instanceof Model );
64         }
65     }
66
67 /*
68 (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
69 All rights reserved.
70
71 Redistribution and use in source and binary forms, with or without
72 modification, are permitted provided that the following conditions
73 are met:
74
75 1. Redistributions of source code must retain the above copyright
76    notice, this list of conditions and the following disclaimer.
77
78 2. Redistributions in binary form must reproduce the above copyright
79    notice, this list of conditions and the following disclaimer in the
80    documentation and/or other materials provided with the distribution.
81
82 3. The name of the author may not be used to endorse or promote products
83    derived from this software without specific prior written permission.
84
85 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
86 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
87 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
88 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
89 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
90 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
91 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
92 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
93 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
94 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
95 */

96
Popular Tags