Package org.apache.jackrabbit.api.jsr283.query.qom

Source Code of org.apache.jackrabbit.api.jsr283.query.qom.EquiJoinConditionTest

/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jackrabbit.api.jsr283.query.qom;

import javax.jcr.Node;
import javax.jcr.RepositoryException;

import org.apache.jackrabbit.spi.commons.query.jsr283.qom.QueryObjectModel;
import org.apache.jackrabbit.spi.commons.query.jsr283.qom.JoinCondition;

/**
* <code>EquiJoinConditionTest</code> contains test cases that cover
* <code>EquiJoinCondition</code>.
*/
public class EquiJoinConditionTest extends AbstractJoinTest {

    private Node n1;

    private Node n2;

    protected void setUp() throws Exception {
        super.setUp();
        String value = createRandomString(10);
        n1 = testRootNode.addNode(nodeName1, testNodeType);
        n1.setProperty(propertyName1, value);

        n2 = n1.addNode(nodeName2, testNodeType);
        n2.setProperty(propertyName1, value);
        n2.setProperty(propertyName2, value);
        n2.addMixin(mixReferenceable);
        testRootNode.save();
    }

    public void testInnerJoin1() throws RepositoryException {
        JoinCondition c = qomFactory.equiJoinCondition(
                LEFT, propertyName1, RIGHT, propertyName2);
        QueryObjectModel qom = createQuery(JOIN_TYPE_INNER, c);
        checkResult(qom.execute(), new Node[][]{{n1, n2}, {n2, n2}});
    }

    public void testInnerJoin2() throws RepositoryException {
        JoinCondition c = qomFactory.equiJoinCondition(
                LEFT, propertyName2, RIGHT, propertyName1);
        QueryObjectModel qom = createQuery(JOIN_TYPE_INNER, c);
        checkResult(qom.execute(), new Node[][]{{n2, n1}, {n2, n2}});
    }

    public void testRightOuterJoin1() throws RepositoryException {
        JoinCondition c = qomFactory.equiJoinCondition(
                LEFT, propertyName1, RIGHT, propertyName2);
        QueryObjectModel qom = createQuery(JOIN_TYPE_RIGHT_OUTER, c);
        checkResult(qom.execute(), new Node[][]{{null, n1}, {n1, n2}, {n2, n2}});
    }

    public void testRightOuterJoin2() throws RepositoryException {
        JoinCondition c = qomFactory.equiJoinCondition(
                LEFT, propertyName2, RIGHT, propertyName1);
        QueryObjectModel qom = createQuery(JOIN_TYPE_RIGHT_OUTER, c);
        checkResult(qom.execute(), new Node[][]{{n2, n1}, {n2, n2}});
    }

    public void testLeftOuterJoin1() throws RepositoryException {
        JoinCondition c = qomFactory.equiJoinCondition(
                LEFT, propertyName1, RIGHT, propertyName2);
        QueryObjectModel qom = createQuery(JOIN_TYPE_LEFT_OUTER, c);
        checkResult(qom.execute(), new Node[][]{{n1, n2}, {n2, n2}});
    }


    public void testLeftOuterJoin2() throws RepositoryException {
        JoinCondition c = qomFactory.equiJoinCondition(
                LEFT, propertyName2, RIGHT, propertyName1);
        QueryObjectModel qom = createQuery(JOIN_TYPE_LEFT_OUTER, c);
        checkResult(qom.execute(), new Node[][]{{n1, null}, {n2, n1}, {n2, n2}});
    }
}
TOP

Related Classes of org.apache.jackrabbit.api.jsr283.query.qom.EquiJoinConditionTest

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.