Package com.eviware.soapui.impl.wsdl.teststeps.assertions

Source Code of com.eviware.soapui.impl.wsdl.teststeps.assertions.XQueryContainsTest

/*
* Copyright 2004-2014 SmartBear Software
*
* Licensed under the EUPL, Version 1.1 or - as soon as they will be approved by the European Commission - subsequent
* versions of the EUPL (the "Licence");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://ec.europa.eu/idabc/eupl
*
* Unless required by applicable law or agreed to in writing, software distributed under the Licence is
* distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the Licence for the specific language governing permissions and limitations
* under the Licence.
*/
package com.eviware.soapui.impl.wsdl.teststeps.assertions;

import com.eviware.soapui.config.TestAssertionConfig;
import com.eviware.soapui.impl.wsdl.teststeps.assertions.basic.XQueryContainsAssertion;
import com.eviware.soapui.model.iface.SubmitContext;
import com.eviware.soapui.model.testsuite.Assertable;
import com.eviware.soapui.model.testsuite.AssertionException;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import static org.junit.Assert.assertEquals;

/*
* This test covers bug reported in SOAPUI-3935
*/
public class XQueryContainsTest {
    @Mock
    private Assertable assertable;
    @Mock
    private SubmitContext context;

    private String response;
    private XQueryContainsAssertion assertion;

    @Before
    public void setUp() throws Exception {
        response = readResource("/xqueryassertion/response.xml");
        assertion = new XQueryContainsAssertion(TestAssertionConfig.Factory.newInstance(), assertable);
    }

    private String readResource(String string) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(string)));
        StringBuffer result = new StringBuffer();

        String line = reader.readLine();
        while (line != null) {
            result.append(line);
            line = reader.readLine();
        }

        return result.toString();
    }

    @Test(expected = AssertionException.class)
    public void negativeRouteTest() throws AssertionException {
        assertion.setPath("count(DirectionsResponse/route) > 10");
        assertion.setExpectedContent("true");
        assertion.assertContent(response, context, XQueryContainsAssertion.ID);
    }

    @Test
    public void positiveRouteTest() throws AssertionException {
        assertion.setPath("count(DirectionsResponse/route) > 10");
        assertion.setExpectedContent("false");
        String result = assertion.assertContent(response, context, XQueryContainsAssertion.ID);
        assertEquals("Not matched expected!", "XQuery Match matches content for [count(DirectionsResponse/route) > 10]",
                result);
    }

    @Test(expected = AssertionException.class)
    public void negativeLatitudeTest() throws AssertionException {
        assertion.setPath("/DirectionsResponse/route[1]/leg[1]/step[1]/start_location[1]/lat[1]");
        assertion.setExpectedContent("<lat>-35.9286900</lat>");
        assertion.assertContent(response, context, XQueryContainsAssertion.ID);
    }

    @Test
    public void positiveLatitudeTest() throws AssertionException {
        assertion.setPath("/DirectionsResponse/route[1]/leg[1]/step[1]/start_location[1]/lat[1]");
        assertion.setExpectedContent("<lat>-34.9286900</lat>");
        String result = assertion.assertContent(response, context, XQueryContainsAssertion.ID);
        assertEquals("Not matched expected!", "XQuery Match matches content for [/DirectionsResponse/route[1]/leg[1]/step[1]/start_location[1]/lat[1]]",
                result);
    }

}
TOP

Related Classes of com.eviware.soapui.impl.wsdl.teststeps.assertions.XQueryContainsTest

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.