⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testpackage.java

📁 Jena推理机
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
               new boolean[]{true,true,false},
               new boolean[]{false,false,true}
        });
        
        g.delete(triple( "a b c" ) );


    	// Again like in the basic test the triples have now changed,
    	// so different methods will now work.
        canImplement(title+"(c)",nodes, 
           new boolean[][]{
               new boolean[]{false,true,false}, 
               new boolean[]{true,false,false},
               new boolean[]{false,false,true}
        });

        // Another twist.
        canImplement(title+"(c)",new TestNode[]{
            nodes[1].asSubject().aProperty(),
            nodes[2].asObject().aSubject(),
            nodes[0].asProperty().anObject()
        }, 
           new boolean[][]{
               new boolean[]{false,true,false}, 
               new boolean[]{true,false,false},
               new boolean[]{false,false,true}
        });                
        assertTrue("Model cache test",nodes[0].asProperty().anObject()==nodes[2]);
    }
    private  void cache(String title, Personality p) {
        Graph g = Factory.createGraphMem();
        TestModel model =  new TestModelImpl(g,p);
        // create some data
        graphAdd( g, "a b a;" );
        
        // get the same node in two different ways.
        assertTrue("Caching is on",model.aSubject().asObject()==model.anObject());
        
        ((TestModelImpl)model).getNodeCacheControl().setEnabled(false);
        

    	// get the same node in two different ways; if there isn't any caching
    	// then we reconstruct the node.
        assertFalse("Caching is off",model.aSubject()==model.anObject());
        
    }
    public static void testSplitBasic() {
       basic("Split: ",split);
    }
    public static void testComboBasic() {
     basic("Combo: ",combo);
    }
    public  void testSplitFollow() {
       follow("Split: ",split);
    }
    public  void testComboFollow() {
     follow("Combo: ",combo);
    }
    
    public  void testSplitCache() {
        cache("Split: ",split);
    }
    public  void testComboCache() {
     cache("Combo: ",combo);
    }
    
    public static void testBitOfBothBasic() {
       basic("bob: ",bitOfBoth);
    }
    public  void testBitOfBothFollow() {
       follow("bob: ",bitOfBoth);
    }
    
    public  void testBitOfBothCache() {
        cache("bob: ",bitOfBoth);
    }
    
    public static void testBitOfBothSurprise() {
    	// bitOfBoth is a surprising personality ...
    	// we can have two different java objects implementing the same interface.
    	
		Graph g = Factory.createGraphMem();
		TestModel model =  new TestModelImpl(g,bitOfBoth);
		// create some data
		graphAdd( g, "a a a;" );
		TestSubject testSubjectImpl = model.aSubject();
		assertTrue("BitOfBoth makes subjects using TestSubjectImpl",
		         testSubjectImpl instanceof TestSubjectImpl);
		TestProperty testAllImpl = testSubjectImpl.aProperty();
    	assertTrue("BitOfBoth makes properties using TestAllImpl",
    			 testAllImpl instanceof TestAllImpl);
    	assertTrue("turning a TestAllImpl into a TestSubject is a no-op",
    	          testAllImpl == testAllImpl.asSubject() );
    	assertTrue("turning a TestAllImpl into a TestSubject is a no-op",
    			  testSubjectImpl != testAllImpl.asSubject() );
    	assertTrue("turning a TestAllImpl into a TestSubject is a no-op",
    			  testSubjectImpl.asSubject() != testSubjectImpl.asSubject().asProperty().asSubject() );
    	          
    }
    
    public static void testBrokenBasic() {
    	try {
    		// Any of the tests ought to work up and til the point
    		// that they don't. At that point they need to detect the
    		// error and throw the PersonalityConfigException.
           basic("Broken: ",broken);
           fail("broken is a misconfigured personality, but it wasn't detected.");
    	} 
    	catch (PersonalityConfigException e ) {
    		
    	}
    }
    
    static class Example 
        {
        static final Implementation factory = new Implementation()
            {
            public EnhNode wrap( Node n, EnhGraph g ) { return new EnhNode( n, g ); }
            
            public boolean canWrap( Node n, EnhGraph g ) { return n.isURI(); }
            };
        }
    
    public void testSimple()
        {
        Graph g = Factory.createGraphMem();
        Personality ours = BuiltinPersonalities.model.copy().add( Example.class, Example.factory );
        EnhGraph eg = new EnhGraph( g, ours ); 
        Node n = Node.createURI( "spoo:bar" );
        EnhNode eNode = new EnhNode( Node.createURI( "spoo:bar" ), eg );
        EnhNode eBlank = new EnhNode( Node.createAnon(), eg );
        assertTrue( "URI node can be an Example", eNode.supports( Example.class ) );
        assertFalse( "Blank node cannot be an Example", eBlank.supports( Example.class ) );
        }
        
    static class AnotherExample 
        {
        static final Implementation factory = new Implementation()
            {
            public EnhNode wrap( Node n, EnhGraph g ) { return new EnhNode( n, g ); }
            
            public boolean canWrap( Node n, EnhGraph g ) { return n.isURI(); }
            };
        }
    
    public void testAlreadyLinkedViewException()
        {
         Graph g = Factory.createGraphMem();
         Personality ours = BuiltinPersonalities.model.copy().add( Example.class, Example.factory );
         EnhGraph eg = new EnhGraph( g, ours ); 
         Node n = Node.create( "spoo:bar" );
         EnhNode eNode = new EnhNode( n, eg );
         eNode.viewAs( Example.class );
         try
            { 
            eNode.addView( eNode ); 
            fail( "should raise an AlreadyLinkedViewException " );
            }
        catch (AlreadyLinkedViewException e)
            {}                
        }
        
    /**
        Test that an attempt to polymorph an enhanced node into a class that isn't
        supported by the enhanced graph generates an UnsupportedPolymorphism
        exception. 
    */
    public void testNullPointerTrap()
        {
        EnhGraph eg = new EnhGraph( Factory.createGraphMem(), BuiltinPersonalities.model );
        Node n = Node.create( "eh:something" );
        EnhNode en = new EnhNode( n, eg );
        try 
            { 
            en.as( TestPackage.class ); 
            fail( "oops" ); 
            }
        catch (UnsupportedPolymorphismException e) 
            {
            assertEquals( en, e.getBadNode() );
            assertTrue( "exception should have cuplprit graph", eg == e.getBadGraph() );
            assertTrue( "exception should have culprit class", TestPackage.class == e.getBadClass() );
            }
        }
    
    public void testNullPointerTrapInCanSupport()
        {
        EnhGraph eg = new EnhGraph( Factory.createGraphMem(), BuiltinPersonalities.model );
        Node n = Node.create( "eh:something" );
        EnhNode en = new EnhNode( n, eg );
        assertFalse( en.canAs( Integer.class ) );        
        }
    
    public void testAsToOwnClassWithNoModel()
        {
        Resource r = ResourceFactory.createResource();
        assertEquals( null, r.getModel() );
        assertTrue( r.canAs( Resource.class ) );
        assertSame( r, r.as( Resource.class ) );
        }

    public void testCanAsReturnsFalseIfNoModel()
        {
        Resource r = ResourceFactory.createResource();
        assertEquals( false, r.canAs( Example.class ) ); 
        }
    
    public void testAsThrowsPolymorphismExceptionIfNoModel()
        {
        Resource r = ResourceFactory.createResource();
        try 
            { r.as( Example.class ); 
            fail( "should throw UnsupportedPolymorphismException" ); }
        catch (UnsupportedPolymorphismException e) 
            {
            assertEquals( null, e.getBadGraph() );
            assertEquals( Example.class, e.getBadClass() );
            }
        }

}

/*
    (c) Copyright 2003, 2004, 2005, 2006, 2007 Hewlett-Packard Development Company, LP
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions
    are met:

    1. Redistributions of source code must retain the above copyright
       notice, this list of conditions and the following disclaimer.

    2. Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.

    3. The name of the author may not be used to endorse or promote products
       derived from this software without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
    NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -