<commit_before>package org.intermine.dataconversion;

/*
 * Copyright (C) 2002-2004 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

import java.io.InputStream;
import java.io.Reader;
import java.io.InputStreamReader;

import org.intermine.modelproduction.ModelParser;
import org.intermine.modelproduction.xml.InterMineModelParser;
import org.intermine.metadata.AttributeDescriptor;
import org.intermine.metadata.ReferenceDescriptor;
import org.intermine.metadata.CollectionDescriptor;
import org.intermine.metadata.ClassDescriptor;
import org.intermine.metadata.Model;

import junit.framework.TestCase;

public class XmlMetaDataTest extends TestCase
{

    public XmlMetaDataTest(String arg) {
        super(arg);
    }

    public void testProcess() throws Exception {
        Reader xsdReader = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("xmlschematest.xsd"));
        XmlMetaData xmlInfo = new XmlMetaData(xsdReader);

        System.out.println("idFields: " + xmlInfo.idFields);
        System.out.println("refFields: " + xmlInfo.refFields);

        assertTrue(xmlInfo.isReference("company/department/employee/businessAddress"));
        assertTrue(xmlInfo.isReference("company/department/manager/businessAddress"));
        assertTrue(xmlInfo.isReference("company/addressBook/address"));
        assertTrue(xmlInfo.isId("company/address"));
        assertEquals("ref", xmlInfo.getReferenceField("company/department/employee/businessAddress"));
        assertEquals("ref", xmlInfo.getReferenceField("company/department/manager/businessAddress"));
        assertEquals("ref", xmlInfo.getReferenceField("company/addressBook/address"));
        assertEquals("id", xmlInfo.getIdField("company/address"));
        assertEquals("company/address", xmlInfo.getIdPath("company/department/employee/businessAddress"));

        // check correct class names returned for all paths
        assertEquals("Company", xmlInfo.getClsNameFromXPath("company"));
        assertEquals("Department_Company", xmlInfo.getClsNameFromXPath("company/department"));
        assertEquals("Employee", xmlInfo.getClsNameFromXPath("company/department/manager"));
        assertEquals("Employee", xmlInfo.getClsNameFromXPath("company/department/employee"));
        assertEquals("Address_Company", xmlInfo.getClsNameFromXPath("company/address"));
        assertEquals("Address_Company", xmlInfo.getClsNameFromXPath("company/department/manager/businessAddress"));
        assertEquals("Address_Company", xmlInfo.getClsNameFromXPath("company/department/employee/businessAddress"));
        assertEquals("Address_Company", xmlInfo.getClsNameFromXPath("company/addressBook/address"));
    }
}
<commit_msg>Updated XMLMetaData tests.<commit_after>package org.intermine.dataconversion;

/*
 * Copyright (C) 2002-2004 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

import java.io.InputStream;
import java.io.Reader;
import java.io.InputStreamReader;

import org.intermine.modelproduction.ModelParser;
import org.intermine.modelproduction.xml.InterMineModelParser;
import org.intermine.metadata.AttributeDescriptor;
import org.intermine.metadata.ReferenceDescriptor;
import org.intermine.metadata.CollectionDescriptor;
import org.intermine.metadata.ClassDescriptor;
import org.intermine.metadata.Model;

import junit.framework.TestCase;

public class XmlMetaDataTest extends TestCase
{
    XmlMetaData xmlInfo;

    public XmlMetaDataTest(String arg) {
        super(arg);
    }

    public void setUp() throws Exception {
        Reader xsdReader = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("xmlschematest.xsd"));
        xmlInfo = new XmlMetaData(xsdReader);
    }
    
    public void testReferenceElements() throws Exception {
        assertTrue(xmlInfo.isReferenceElement("company/department/employee/businessAddress"));
        assertTrue(xmlInfo.isReferenceElement("company/department/manager/businessAddress"));
        assertTrue(xmlInfo.isReferenceElement("company/addressBook/address"));
        
        assertEquals("ref", xmlInfo.getReferenceElementField("company/department/employee/businessAddress"));
        assertEquals("ref", xmlInfo.getReferenceElementField("company/department/manager/businessAddress"));
        assertEquals("ref", xmlInfo.getReferenceElementField("company/addressBook/address"));
    }
    
    public void testKeyRef() throws Exception { 
        assertEquals("addressKey", xmlInfo.getReferencingKeyName("company/department/employee/businessAddress", "ref"));
    }
    
    public void testKey() throws Exception {
        assertEquals("company/address", xmlInfo.getKeyPath("addressKey"));
        assertEquals("id", xmlInfo.getKeyField("addressKey"));
    }
    
    public void testKeyFields() throws Exception {
        assertTrue(xmlInfo.getKeyFields("company/address").contains("id"));
    }
    
    public void testClassNames() throws Exception {
        // check correct class names returned for all paths
        assertEquals("Company", xmlInfo.getClsNameFromXPath("company"));
        assertEquals("Department_Company", xmlInfo.getClsNameFromXPath("company/department"));
        assertEquals("Employee", xmlInfo.getClsNameFromXPath("company/department/manager"));
        assertEquals("Employee", xmlInfo.getClsNameFromXPath("company/department/employee"));
        assertEquals("Address_Company", xmlInfo.getClsNameFromXPath("company/address"));
        assertEquals("Address_Company", xmlInfo.getClsNameFromXPath("company/department/manager/businessAddress"));
        assertEquals("Address_Company", xmlInfo.getClsNameFromXPath("company/department/employee/businessAddress"));
        assertEquals("Address_Company", xmlInfo.getClsNameFromXPath("company/addressBook/address"));
    }
}

{'fraction_non_alphanumeric': 0.11191743267214965, 'fraction_numerical': 0.002580228995323335, 'mean_word_length': 4.895437262357414, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 44}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3751335', 'n_tokens_mistral': 1644, 'n_tokens_neox': 1594, 'n_words': 279}