/*
 * Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0,
 * or the Eclipse Distribution License v. 1.0 which is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
 */

// Contributors:
//     Oracle - initial API and implementation from Oracle TopLink
package org.eclipse.persistence.testing.sdo.helper.xmlhelper.loadandsave;

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


import junit.textui.TestRunner;

import org.eclipse.persistence.sdo.SDOConstants;
import org.eclipse.persistence.sdo.SDOProperty;
import org.eclipse.persistence.sdo.SDOType;

import commonj.sdo.DataObject;
import commonj.sdo.Type;

public class LoadAndSaveWithReadOnlyTestCases extends LoadAndSaveTestCases {
    public LoadAndSaveWithReadOnlyTestCases(String name) {
        super(name);
    }

    public static void main(String[] args) {
        String[] arguments = { "-c", "org.eclipse.persistence.testing.sdo.helper.xmlhelper.loadandsave.LoadAndSavePurchaseOrderComplexTestCases" };
        TestRunner.main(arguments);
    }

    @Override
    protected String getControlFileName() {
        return "./org/eclipse/persistence/testing/sdo/helper/xmlhelper/loadandsave/readonly.xml";
    }

    @Override
    protected String getSchemaName() {
        return "org/eclipse/persistence/testing/sdo/schemas/ReadOnly.xsd";
    }

    @Override
    protected String getControlRootURI() {
        return "myns";
    }

    @Override
    protected String getControlRootName() {
        return "employee";
    }

    @Override
    protected String getRootInterfaceName() {
        return "EmployeeType";
    }

    // Override package generation based on the JAXB 2.0 algorithm in SDOUtil.java
    @Override
    protected List<String> getPackages() {
        List<String> packages = new ArrayList<String>();
        packages.add("myns");
        return packages;
    }

    @Override
    protected void registerTypes() {
        Type stringType = SDOConstants.SDO_STRING;
        SDOType propertyType = (SDOType) typeHelper.getType(SDOConstants.SDO_URL, SDOConstants.PROPERTY);

        DataObject employeeTypeType = dataFactory.create("commonj.sdo", "Type");
        SDOProperty prop = (SDOProperty)employeeTypeType.getType().getProperty("uri");
        employeeTypeType.set(prop, getControlRootURI());
        prop = (SDOProperty)employeeTypeType.getType().getProperty("name");
        employeeTypeType.set(prop, "employee");
        addProperty(employeeTypeType, "name", stringType, false, false, true);

        Type EMPType = typeHelper.define(employeeTypeType);

        DataObject propDO = dataFactory.create(propertyType);
        propDO.set("name", getControlRootName());
        propDO.set("type", EMPType);
        typeHelper.defineOpenContentProperty(getControlRootURI(), propDO);
    }
}
