Package com.hp.jena3.rules.retelike.impl.tests

Source Code of com.hp.jena3.rules.retelike.impl.tests.TestBinder

/*
  (c) Copyright 2008, 2009 Hewlett-Packard Development Company, LP
   All rights reserved.
   $Id$
*/


/*
   (c) Copyright 2008 Hewlett-Packard Development Company, LP
   All rights reserved.
   $Id$
*/

package com.hp.jena3.rules.retelike.impl.tests;

import static com.hp.jena3.rules.retelike.impl.tests.TestTripleTerm.tripleTerm;
import static org.junit.Assert.*;

import java.util.*;

import org.junit.Test;

import com.hp.hpl.jena.graph.Node;
import com.hp.jena.rules.retelike.impl.*;
import com.hp.jena.rules.retelike.impl.scratch.Entries;
import com.hp.jena.ymris.util.*;

public class TestBinder
    {
    @Test public void ensureTermBindsElements()
        {
        ensureTermBindsElements( "x p ?y", "x p 1", "?y=1" );
        ensureTermBindsElements( "x ?r 1", "x p 1", "?r=p" );
        ensureTermBindsElements( "?x P ?x", "a P a", "?x=a" );
        }
   
    @Test public void ensureThaNnonmatchingTriplesGenerateNoBindings()
        {
        ensureMismatchProducesNoBindings( "a P b", "x P y" );       
        ensureMismatchProducesNoBindings( "a P b", "a P c" );
        ensureMismatchProducesNoBindings( "a P b", "x P b" );
        ensureMismatchProducesNoBindings( "?x P y", "x P 1" );
        ensureMismatchProducesNoBindings( "?x P ?x", "x P y" );
        }

    private void ensureMismatchProducesNoBindings( String termString, String tripleString )
        { ensureTermBindsElements( termString, tripleString, "" ); }

    private void ensureTermBindsElements( String termString, String tripleString, String expectedString )
        {
        TripleTerm tt = tripleTerm( termString );
        ConsumeToList<Entries> bc = consumeToList();
        Binder b = new Binder( tt, bc );
        b.consume( GraphCreateUtils.triple( tripleString ) );
        assertEquals( bindingsList( expectedString ), bc.elements() );
        }

    private <T> ConsumeToList<T> consumeToList()
        { return new ConsumeToList<T>(); }
   
    @Test public void ensureBinderExposesTerm()
        {       
        TripleTerm tt = tripleTerm( "a P b" );
        assertSame( tt, new Binder( tt, null ).boundTerm() );
        }

    public static List<Entries> bindingsList( String seq )
        {
        List<Entries> result = new ArrayList<Entries>();
        if (seq.length() > 0)
            for (String bindings: seq.split( " *; *" ))
                result.add( new Entries( TestBindings.nodeBindings( bindings ) ) );
        return result;
        }
    }
TOP

Related Classes of com.hp.jena3.rules.retelike.impl.tests.TestBinder

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.