public void testRefreshTopLevelAttribute() throws ResourceException {
    MWXmlSchema schema = this.loadSchema("BasicAttribute");
    MWAttributeDeclaration attribute = schema.attribute("attribute");

    assertNotNull(attribute);
    assertNotNull(attribute.getType());
  }
  public void testRefreshSimpleType() throws ResourceException {
    MWXmlSchema schema = this.loadSchema("BasicSimpleType");

    assertNotNull(schema.simpleType("simple-type-1"));
    assertNotNull(schema.simpleType("simple-type-2"));
    assertNotNull(schema.simpleType("simple-type-3"));
  }
  public void testLoadEmptySchemas() throws ResourceException {
    MWXmlSchema schema;

    schema = this.loadSchema("EmptySchema");
    assertEquals(schema.targetNamespaceUrl(), "");

    schema = this.loadSchema("EmptySchemaWithTargetNS");
    assertEquals(schema.targetNamespaceUrl(), "http://www.target-namespace.com");
  }
  public void testRefreshComplexType() throws ResourceException {
    MWXmlSchema schema = this.loadSchema("BasicComplexType");
    MWComplexTypeDefinition complexType = schema.complexType("complex-type");
    int originalTotalElementCount = complexType.totalElementCount();
    int originalAttributeCount = complexType.attributeCount();

    assertEquals(complexType.getBaseType().getName(), "anyType");
    assertTrue("The type is abstract.", !complexType.isAbstract());
    assertTrue("The number of total elements is zero.", originalTotalElementCount != 0);
    assertTrue("The number of attributes is zero.", originalAttributeCount != 0);

    schema.reload();

    assertTrue("The abstract flag changed.", !complexType.isAbstract());
    assertTrue(
        "The number of total elements changed.",
        complexType.totalElementCount() == originalTotalElementCount);
    assertTrue(
        "The number of attributes changed.",
        complexType.attributeCount() == originalAttributeCount);

    this.reloadSchema(schema, "BasicComplexTypeWithReferences");
    assertTrue(
        "The number of total elements changed.",
        complexType.totalElementCount() == originalTotalElementCount);
    assertTrue(
        "The number of attributes changed.",
        complexType.attributeCount() == originalAttributeCount);

    this.reloadSchema(schema, "BasicComplexTypeWithSimpleBaseType");

    assertNotNull(complexType.getBaseType());
    assertTrue("The number of total elements is not zero.", complexType.totalElementCount() == 0);

    this.reloadSchema(schema, "BasicComplexTypeWithComplexBaseType");

    assertNotNull(complexType.getBaseType());
    assertTrue(
        "The base type is not abstract.",
        ((MWComplexTypeDefinition) complexType.getBaseType()).isAbstract());
    assertTrue(
        "The number of total elements did not increase.",
        complexType.totalElementCount() > originalTotalElementCount);
    assertTrue(
        "The number of attributes did not increase.",
        complexType.attributeCount() > originalAttributeCount);

    this.reloadSchema(schema, "BasicComplexType");
    assertEquals(complexType.getBaseType().getName(), "anyType");
    assertTrue(
        "The number of total elements did not decrease.",
        complexType.totalElementCount() == originalTotalElementCount);
    assertTrue(
        "The number of attributes did not decrease.",
        complexType.attributeCount() == originalAttributeCount);
  }
  public void testRefreshType() throws ResourceException {
    MWXmlSchema schema = this.loadSchema("BasicType_Simple");
    assertNotNull(schema.simpleType("type"));

    this.reloadSchema(schema, "BasicType_Complex");
    assertNotNull(schema.complexType("type"));

    this.reloadSchema(schema, "BasicType_Simple");
    assertNotNull(schema.simpleType("type"));
  }
  public void testLoadSchemaFromUrl() throws ResourceException, URISyntaxException {
    String schemaUrlString =
        this.getClass()
            .getResource("/schema/" + this.adjustSchemaName("BasicSchema.xsd"))
            .toString();

    MWOXProject project =
        new MWOXProject("Test Load Schema From URL", MappingsModelTestTools.buildSPIManager());
    MWXmlSchemaRepository repository = project.getSchemaRepository();
    MWXmlSchema schema = repository.createSchemaFromUrl("SchemaFromUrl", schemaUrlString);
    schema.reload();
  }
  public void testRefreshTopLevelElement() throws ResourceException {
    MWXmlSchema schema = this.loadSchema("BasicElementWithSimpleType");

    assertNotNull(schema.element("element").getType());

    this.reloadSchema(schema, "BasicElementWithComplexType");

    assertNotNull(schema.element("element").getType());

    this.reloadSchema(schema, "BasicElementWithSimpleType");

    assertNotNull(schema.element("element").getType());
  }
  public void testDefaultRootElementType() {
    String errorName = ProblemConstants.DESCRIPTOR_DEFAULT_ROOT_ELEMENT_TYPE;
    this.checkOXDescriptorsForFalseFailures(errorName);

    MWElementDeclaration defaultRootElement = getEmployeeEisDescriptor().getDefaultRootElement();
    MWXmlSchema empSchema = getEmployeeOXProject().getSchemaRepository().getSchema("employee.xsd");
    this.getEmployeeOXDescriptor().setDefaultRootElementType(empSchema.complexType("phone-type"));
    this.getEmployeeOXDescriptor().setDefaultRootElement(null);
    this.assertTrue(
        "default root element is null -- should have problem",
        this.hasProblem(errorName, this.getEmployeeOXDescriptor()));

    this.getEmployeeOXDescriptor().setDefaultRootElement(defaultRootElement);
    this.assertTrue(
        "default root element not null -- should have no problem",
        !this.hasProblem(errorName, this.getEmployeeOXDescriptor()));
  }
  public void testLoadSchemaFromFile() throws ResourceException, URISyntaxException {
    String absoluteSchemaFilePath =
        FileTools.resourceFile("/schema/" + this.adjustSchemaName("BasicSchema.xsd"))
            .getAbsolutePath();
    File testSchemasDirectory = new File(absoluteSchemaFilePath).getParentFile().getParentFile();
    String testSchemasDirectoryPath = testSchemasDirectory.getPath();
    String relativeSchemaFilePath =
        "." + absoluteSchemaFilePath.substring(testSchemasDirectoryPath.length());

    MWOXProject project =
        new MWOXProject("Test Load Schema From File", MappingsModelTestTools.buildSPIManager());
    project.setSaveDirectory(testSchemasDirectory);
    MWXmlSchemaRepository repository = project.getSchemaRepository();

    // test absolute file location
    MWXmlSchema absolutePathSchema =
        repository.createSchemaFromFile("AbsolutePathSchemaFromFile", absoluteSchemaFilePath);
    absolutePathSchema.reload();

    // test relative file location
    MWXmlSchema relativePathSchema =
        repository.createSchemaFromFile("RelativePathSchemaFromFile", relativeSchemaFilePath);
    relativePathSchema.reload();
  }
  public void testRefreshBasicSchema() throws ResourceException {
    MWXmlSchema basicSchema = this.loadSchema("BasicSchema");
    int originalAttributeCount = basicSchema.attributeCount();
    int originalElementCount = basicSchema.elementCount();
    int originalTypeCount = basicSchema.typeCount();
    int originalGroupCount = basicSchema.modelGroupDefinitionCount();

    basicSchema.reload();

    assertTrue(
        "The number of attributes changed.",
        basicSchema.attributeCount() == originalAttributeCount);
    assertTrue(
        "The number of elements changed.", basicSchema.elementCount() == originalElementCount);
    assertTrue("The number of types changed.", basicSchema.typeCount() == originalTypeCount);
    assertTrue(
        "The number of groups changed.",
        basicSchema.modelGroupDefinitionCount() == originalGroupCount);

    this.reloadSchema(basicSchema, "BasicSchemaWithComponentsRemoved");

    assertTrue(
        "The number of attributes did not decrease.",
        basicSchema.attributeCount() < originalAttributeCount);
    assertTrue(
        "The number of elements did not decrease.",
        basicSchema.elementCount() < originalElementCount);
    assertTrue(
        "The number of types did not decrease.", basicSchema.typeCount() < originalTypeCount);
    assertTrue(
        "The number of groups did not decrease.",
        basicSchema.modelGroupDefinitionCount() < originalGroupCount);

    this.reloadSchema(basicSchema, "BasicSchemaWithComponentsAdded");

    assertTrue(
        "The number of attributes did not increase.",
        basicSchema.attributeCount() > originalAttributeCount);
    assertTrue(
        "The number of elements did not increase.",
        basicSchema.elementCount() > originalElementCount);
    assertTrue(
        "The number of types did not increase.", basicSchema.typeCount() > originalTypeCount);
    assertTrue(
        "The number of groups did not increase.",
        basicSchema.modelGroupDefinitionCount() > originalGroupCount);
  }