<commit_before>/***************************** BEGIN LICENSE BLOCK ***************************

 The contents of this file are subject to the Mozilla Public License Version
 1.1 (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.mozilla.org/MPL/MPL-1.1.html
 
 Software distributed under the License is distributed on an "AS IS" basis,
 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 for the specific language governing rights and limitations under the License.
 
 The Original Code is the "OGC Service Framework".
 
 The Initial Developer of the Original Code is Sensia Software LLC.
 Portions created by the Initial Developer are Copyright (C) 2014
 the Initial Developer. All Rights Reserved.
 
 Please Contact <NAME> <<EMAIL>> or
 <NAME> <<EMAIL>> for more information.

 Contributor(s): 
    <NAME> <<EMAIL>>
 
******************************* END LICENSE BLOCK ***************************/

package org.vast.ows.test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import org.custommonkey.xmlunit.Validator;
import org.custommonkey.xmlunit.XMLTestCase;
import org.custommonkey.xmlunit.XMLUnit;
import org.vast.ows.OWSRequest;
import org.vast.ows.OWSResponse;
import org.vast.ows.OWSUtils;
import org.vast.ows.sos.SOSUtils;
import org.vast.xml.DOMHelper;
import org.xml.sax.InputSource;


public class OWSTestCase extends XMLTestCase
{

    public void setUp() throws Exception
    {
        XMLUnit.setIgnoreComments(true);
        XMLUnit.setIgnoreWhitespace(true);
    }
    
    
    protected void validate(InputStream is, String schemaUrl) throws Exception
    {
        InputSource saxIs = new InputSource(is);
        Validator v = new Validator(saxIs);
        v.useXMLSchema(true);
        v.setJAXP12SchemaSource(schemaUrl);
        assertTrue(v.isValid());
    }
        
    
    protected OWSRequest readXmlRequest(String path) throws Exception
    {
        SOSUtils utils = new SOSUtils();
        
        InputStream is = getClass().getResourceAsStream(path);
        OWSRequest request = utils.readXMLQuery(is);
        is.close();
        
        return request;
    }
    
    
    protected void readWriteCompareXmlRequest(String path) throws Exception
    {
        OWSUtils utils = new OWSUtils();
        
        InputStream is = getClass().getResourceAsStream(path);
        DOMHelper dom1 = new DOMHelper(is, false);
        OWSRequest request1 = utils.readXMLQuery(dom1, dom1.getBaseElement());
        is.close();
        
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        System.out.println();
        utils.writeXMLQuery(System.out, request1);
        utils.writeXMLQuery(os, request1);
        os.close();
        
        DOMHelper dom2 = new DOMHelper(new ByteArrayInputStream(os.toByteArray()), false);
        assertXMLEqual(dom1.getDocument(), dom2.getDocument());
    }
    
    
    
    protected void readWriteCompareXmlResponse(String path, String serviceType) throws Exception
    {
        OWSUtils utils = new OWSUtils();
        OWSResponse resp1;
        
        InputStream is = getClass().getResourceAsStream(path);
        DOMHelper dom1 = new DOMHelper(is, false);
        resp1 = utils.readXMLResponse(dom1, dom1.getBaseElement(), serviceType);
        is.close();
        
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        System.out.println();
        utils.writeXMLResponse(System.out, resp1);
        utils.writeXMLResponse(os, resp1);
        os.close();
        
        DOMHelper dom2 = new DOMHelper(new ByteArrayInputStream(os.toByteArray()), false);
        assertXMLEqual(dom1.getDocument(), dom2.getDocument());
    }
}
<commit_msg>Made abstract so it is not run as a JUnit test by Maven<commit_after>/***************************** BEGIN LICENSE BLOCK ***************************

 The contents of this file are subject to the Mozilla Public License Version
 1.1 (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.mozilla.org/MPL/MPL-1.1.html
 
 Software distributed under the License is distributed on an "AS IS" basis,
 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 for the specific language governing rights and limitations under the License.
 
 The Original Code is the "OGC Service Framework".
 
 The Initial Developer of the Original Code is Sensia Software LLC.
 Portions created by the Initial Developer are Copyright (C) 2014
 the Initial Developer. All Rights Reserved.
 
 Please Contact <NAME> <<EMAIL>> or
 <NAME> <<EMAIL>> for more information.

 Contributor(s): 
    <NAME> <<EMAIL>>
 
******************************* END LICENSE BLOCK ***************************/

package org.vast.ows.test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import org.custommonkey.xmlunit.Validator;
import org.custommonkey.xmlunit.XMLTestCase;
import org.custommonkey.xmlunit.XMLUnit;
import org.vast.ows.OWSRequest;
import org.vast.ows.OWSResponse;
import org.vast.ows.OWSUtils;
import org.vast.ows.sos.SOSUtils;
import org.vast.xml.DOMHelper;
import org.xml.sax.InputSource;


public abstract class OWSTestCase extends XMLTestCase
{

    public void setUp() throws Exception
    {
        XMLUnit.setIgnoreComments(true);
        XMLUnit.setIgnoreWhitespace(true);
    }
    
    
    protected void validate(InputStream is, String schemaUrl) throws Exception
    {
        InputSource saxIs = new InputSource(is);
        Validator v = new Validator(saxIs);
        v.useXMLSchema(true);
        v.setJAXP12SchemaSource(schemaUrl);
        assertTrue(v.isValid());
    }
        
    
    protected OWSRequest readXmlRequest(String path) throws Exception
    {
        SOSUtils utils = new SOSUtils();
        
        InputStream is = getClass().getResourceAsStream(path);
        OWSRequest request = utils.readXMLQuery(is);
        is.close();
        
        return request;
    }
    
    
    protected void readWriteCompareXmlRequest(String path) throws Exception
    {
        OWSUtils utils = new OWSUtils();
        
        InputStream is = getClass().getResourceAsStream(path);
        DOMHelper dom1 = new DOMHelper(is, false);
        OWSRequest request1 = utils.readXMLQuery(dom1, dom1.getBaseElement());
        is.close();
        
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        System.out.println();
        utils.writeXMLQuery(System.out, request1);
        utils.writeXMLQuery(os, request1);
        os.close();
        
        DOMHelper dom2 = new DOMHelper(new ByteArrayInputStream(os.toByteArray()), false);
        assertXMLEqual(dom1.getDocument(), dom2.getDocument());
    }
    
    
    
    protected void readWriteCompareXmlResponse(String path, String serviceType) throws Exception
    {
        OWSUtils utils = new OWSUtils();
        OWSResponse resp1;
        
        InputStream is = getClass().getResourceAsStream(path);
        DOMHelper dom1 = new DOMHelper(is, false);
        resp1 = utils.readXMLResponse(dom1, dom1.getBaseElement(), serviceType);
        is.close();
        
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        System.out.println();
        utils.writeXMLResponse(System.out, resp1);
        utils.writeXMLResponse(os, resp1);
        os.close();
        
        DOMHelper dom2 = new DOMHelper(new ByteArrayInputStream(os.toByteArray()), false);
        assertXMLEqual(dom1.getDocument(), dom2.getDocument());
    }
}

{'fraction_non_alphanumeric': 0.11590050787863003, 'fraction_numerical': 0.007553066805573642, 'mean_word_length': 3.1157556270096465, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2016700', 'n_tokens_mistral': 2139, 'n_tokens_neox': 2061, 'n_words': 593}