All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bigdata.rdf.internal.encoder.TestIVSolutionSetEncoder Maven / Gradle / Ivy

There is a newer version: 2.1.4
Show newest version
/**

Copyright (C) SYSTAP, LLC DBA Blazegraph 2006-2016.  All rights reserved.

Contact:
     SYSTAP, LLC DBA Blazegraph
     2501 Calvert ST NW #106
     Washington, DC 20008
     [email protected]

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
/*
 * Created on Feb 15, 2012
 */

package com.bigdata.rdf.internal.encoder;

import java.util.ArrayList;
import java.util.List;

import com.bigdata.bop.Constant;
import com.bigdata.bop.IBindingSet;
import com.bigdata.bop.Var;
import com.bigdata.bop.bindingSet.ListBindingSet;
import com.bigdata.io.DataInputBuffer;
import com.bigdata.io.DataOutputBuffer;
import com.bigdata.rdf.internal.IV;

/**
 * Test suite for {@link IVSolutionSetEncoder} and {@link IVSolutionSetDecoder}.
 * 
 * @author Bryan Thompson
 * @version $Id: TestIVSolutionSetEncoder.java 6033 2012-02-16 16:12:27Z
 *          thompsonbry $
 */
public class TestIVSolutionSetEncoder extends AbstractBindingSetEncoderTestCase {

    /**
     * 
     */
    public TestIVSolutionSetEncoder() {
    }

    /**
     * @param name
     */
    public TestIVSolutionSetEncoder(String name) {
        super(name);
    }

    @Override
    protected void setUp() throws Exception {
     
        super.setUp();

        // The encoder under test.
        encoder = new IVSolutionSetEncoder();
        
        // The decoder under test (same object as the encoder).
        decoder = new IVSolutionSetDecoder();
        
    }

//    protected void tearDown() throws Exception {
//        
//        super.tearDown();
//        
//        // Clear references.
//        encoder.release();
//        encoder = null;
//        decoder = null;
//        
//    }

    /**
     * Unit test of the stream-oriented API.
     */
    @SuppressWarnings("rawtypes")
    public void test_streamAPI() {
        
        final List expectedSolutions = new ArrayList();

        {
            final IBindingSet expected = new ListBindingSet();
            expected.set(Var.var("x"), new Constant(termId));

            expectedSolutions.add(expected);
        }

        {
            final IBindingSet expected = new ListBindingSet();
            expected.set(Var.var("x"), new Constant(termId));
            expected.set(Var.var("y"), new Constant(blobIV));

            expectedSolutions.add(expected);
        }

        doEncodeDecodeTest(expectedSolutions);

    }

    /**
     * Multiple solutions where an empty solution appears in the middle of the
     * sequence.
     */
    @SuppressWarnings("rawtypes")
    public void test_streamAPI2() {

        final List expectedSolutions = new ArrayList();
        {
            final IBindingSet expected = new ListBindingSet();
            expected.set(Var.var("x"), new Constant(termId));

            expectedSolutions.add(expected);
        }

        {
            final IBindingSet expected = new ListBindingSet();

            expectedSolutions.add(expected);
        }

        {
            final IBindingSet expected = new ListBindingSet();
            expected.set(Var.var("x"), new Constant(termId));
            expected.set(Var.var("y"), new Constant(blobIV));

            expectedSolutions.add(expected);
        }

        doEncodeDecodeTest(expectedSolutions);

    }

    protected void doEncodeDecodeTest(final List expectedSolutions) {

        final int nsolutions = expectedSolutions.size();
        
        final DataOutputBuffer out = new DataOutputBuffer();
        
        for (IBindingSet bset : expectedSolutions) {
        
            ((IVSolutionSetEncoder) encoder).encodeSolution(out, bset);
            
        }
        
        final DataInputBuffer in = new DataInputBuffer(out.array());

        for (int i = 0; i < nsolutions; i++) {

            final IBindingSet expected = expectedSolutions.get(i);
            
            final IBindingSet actual = ((IVSolutionSetDecoder) decoder)
                    .decodeSolution(in, true/* resolveCachedValues */);

            assertEquals(expected, actual, true/* testCache */);
            
        }
        
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy