Package com.hp.jena.net.deploy.local

Source Code of com.hp.jena.net.deploy.local.TestRulesWithActions$A$RecordNodes

/* 
  (c) Copyright 2009 Hewlett-Packard Development Company, LP
  [See end of file]
  $Id$
*/
package com.hp.jena.net.deploy.local;

import static org.junit.Assert.assertEquals;

import java.util.*;

import org.junit.Test;

import com.hp.hpl.jena.graph.*;
import com.hp.hpl.jena.graph.test.GraphTestBase;
import com.hp.hpl.jena.shared.NotFoundException;
import com.hp.jena.ymris.deploy.local.BindingSink;
import com.hp.jena.ymris.yast.expr.*;

import static com.hp.hpl.jena.graph.test.GraphTestBase.nodeArray;
import static com.hp.jena.net.deploy.local.Utils.*;

public class TestRulesWithActions
    {
    static class A implements HowTo
        {
        protected final List<Node> nodes;
       
        public A( List<Node> nodes )
            {
            this.nodes = nodes;
            nodes.add( null );
            }
       
        @Override public Operation operationNamed( String f )
            {
            if (f.equals( "spoo" )) return new RecordNodes();
            throw new NotFoundException( "no relation " + f + " known." );
            }
       
        public class RecordNodes implements Operation
            {
            public RecordNodes()
                { super(); }
           
            @Override public Node evalValue( Node[] values )
                {
//                for (Node v: values) System.out.print( v );
                for (Node v: values) nodes.add( v );
                return Node.createURI( "eh:/done" );
                }
            }

        @Override public Graph getGraph()
            { throw new RuntimeException( "OOPS" ); }
        };
       
    protected final LogBindings sink = new LogBindings();
    protected final List<Node> nodes = new ArrayList<Node>();
   
    @Test public void testActionWithConclusion()
        {
        String rules = "RULE { ?x <eh:/P> ?y } => DO spoo(?x, ?y) { ?x a <eh:/PD> }";
        BindingSink in = rulesToDeployment( sink, rules, new A( nodes ) );
    //
        in.consume( nodeArray( "X S P O" ) );
        assertEquals( bindings( "S rdf:type PD" ), sink.bindings );
        assertEquals( bindings( "S O" ).get( 0 ), nodes );
        }
       
    @Test public void testActionWithEmptyConclusion()
        {
        String rules = "RULE { ?x <eh:/P> ?y } => DO spoo(?x, ?y) {}";
        BindingSink in = rulesToDeployment( sink, rules, new A( nodes ) );
    //
        in.consume( GraphTestBase.nodeArray( "X S P O" ) );
        assertEquals( bindings( "" ), sink.bindings );
        assertEquals( bindings( "S O" ).get( 0 ), nodes );
        }
    }


/*
    (c) Copyright 2009 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.
*/ 
TOP

Related Classes of com.hp.jena.net.deploy.local.TestRulesWithActions$A$RecordNodes

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.