public void testLoadSchemaFromClasspath() 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 schemaResourceName =
        absoluteSchemaFilePath.substring(testSchemasDirectoryPath.length() + 1);

    // test schema not on classpath
    MWOXProject project =
        new MWOXProject(
            "Test Load Schema From Classpath", MappingsModelTestTools.buildSPIManager());
    MWXmlSchemaRepository schemaRepository = project.getSchemaRepository();
    try {
      schemaRepository.createSchemaFromClasspath("SchemaFromClasspath", schemaResourceName);
      assertTrue("ResourceException was not thrown.", false);
    } catch (ResourceException re) {
    } catch (Throwable t) {
      assertTrue("ResourceException was not thrown.", false);
    }

    // test schema on classpath
    project.getRepository().addClasspathEntry(testSchemasDirectoryPath);
    schemaRepository.createSchemaFromClasspath("SchemaFromClasspath", schemaResourceName);
  }
 private MWRelationalProject buildProject() {
   MWRelationalProject result =
       new MWRelationalProject(
           this.getClass().getName(), MappingsModelTestTools.buildSPIManager(), null);
   Classpath cp = Classpath.javaClasspath();
   Classpath.Entry[] entries = cp.getEntries();
   for (int i = 0; i < entries.length; i++) {
     result.getRepository().addClasspathEntry(entries[i].fileName());
   }
   return result;
 }
  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 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();
  }
  protected void setUp() throws Exception {
    super.setUp();

    this.databasePlatform = DatabasePlatformRepository.getDefault().platformNamed("MySQL");
    String projectName = ClassTools.shortClassNameForObject(this);
    this.project =
        new MWRelationalProject(
            projectName, MappingsModelTestTools.buildSPIManager(), this.databasePlatform);
    this.database = this.project.getDatabase();
    this.loginSpec = TestDatabases.mySQLLoginSpec(this.database);
    this.catalogName = null;
    this.schemaName = null;

    // EMP
    this.table_EMP = this.database.addTable(this.catalogName, this.schemaName, "emp");

    this.field_EMP_ID = this.table_EMP.addColumn("emp_id");
    this.field_EMP_ID.setDatabaseType(this.databasePlatform.databaseTypeNamed("integer"));
    this.field_EMP_ID.setSize(0);
    this.field_EMP_ID.setPrimaryKey(true);

    this.field_ADDR_ID1_FK = this.table_EMP.addColumn("addr_id1");
    this.field_ADDR_ID1_FK.setDatabaseType(this.databasePlatform.databaseTypeNamed("integer"));
    this.field_ADDR_ID1_FK.setSize(0);

    this.field_ADDR_ID2_FK = this.table_EMP.addColumn("addr_id2");
    this.field_ADDR_ID2_FK.setDatabaseType(this.databasePlatform.databaseTypeNamed("integer"));
    this.field_ADDR_ID2_FK.setSize(0);

    this.field_PHONE = this.table_EMP.addColumn("phone");
    this.field_PHONE.setDatabaseType(this.databasePlatform.databaseTypeNamed("varchar"));
    this.field_PHONE.setSize(20);

    this.field_BOSS_ID_FK = this.table_EMP.addColumn("boss_id");
    this.field_BOSS_ID_FK.setDatabaseType(this.databasePlatform.databaseTypeNamed("integer"));
    this.field_BOSS_ID_FK.setSize(0);

    // ADDR
    this.table_ADDR = this.database.addTable(this.catalogName, this.schemaName, "addr");

    this.field_ADDR_ID1 = this.table_ADDR.addColumn("addr_id1");
    this.field_ADDR_ID1.setDatabaseType(this.databasePlatform.databaseTypeNamed("integer"));
    this.field_ADDR_ID1.setSize(0);
    this.field_ADDR_ID1.setPrimaryKey(true);

    this.field_ADDR_ID2 = this.table_ADDR.addColumn("addr_id2");
    this.field_ADDR_ID2.setDatabaseType(this.databasePlatform.databaseTypeNamed("integer"));
    this.field_ADDR_ID2.setSize(0);
    this.field_ADDR_ID2.setPrimaryKey(true);

    this.field_STREET = this.table_ADDR.addColumn("street");
    this.field_STREET.setSize(20);
    this.field_CITY = this.table_ADDR.addColumn("city");
    this.field_CITY.setSize(20);

    this.field_STATE_ID1_FK = this.table_ADDR.addColumn("state_id1");
    this.field_STATE_ID1_FK.setDatabaseType(this.databasePlatform.databaseTypeNamed("integer"));
    this.field_STATE_ID1_FK.setSize(0);

    this.field_STATE_ID2_FK = this.table_ADDR.addColumn("state_id2");
    this.field_STATE_ID2_FK.setDatabaseType(this.databasePlatform.databaseTypeNamed("integer"));
    this.field_STATE_ID2_FK.setSize(0);

    this.field_ZIP = this.table_ADDR.addColumn("zip");
    this.field_ZIP.setDatabaseType(this.databasePlatform.databaseTypeNamed("varchar"));
    this.field_ZIP.setSize(9);

    // STATE
    this.table_STATE = this.database.addTable(this.catalogName, this.schemaName, "state");
    this.field_STATE_ID1 = this.table_STATE.addColumn("state_id1");
    this.field_STATE_ID1.setDatabaseType(this.databasePlatform.databaseTypeNamed("integer"));
    this.field_STATE_ID1.setSize(0);
    this.field_STATE_ID1.setPrimaryKey(true);

    this.field_STATE_ID2 = this.table_STATE.addColumn("state_id2");
    this.field_STATE_ID2.setDatabaseType(this.databasePlatform.databaseTypeNamed("integer"));
    this.field_STATE_ID2.setSize(0);
    this.field_STATE_ID2.setPrimaryKey(true);

    this.field_STATE_CODE = this.table_STATE.addColumn("code");
    this.field_STATE_CODE.setDatabaseType(this.databasePlatform.databaseTypeNamed("varchar"));
    this.field_STATE_CODE.setSize(2);

    this.field_STATE_NAME = this.table_STATE.addColumn("name");
    this.field_STATE_NAME.setDatabaseType(this.databasePlatform.databaseTypeNamed("varchar"));
    this.field_STATE_NAME.setSize(20);

    // constraints
    this.reference_EMP_ADDR = this.table_EMP.addReference("emp_addr", this.table_ADDR);
    this.reference_EMP_ADDR.setOnDatabase(true);
    this.reference_EMP_ADDR.addColumnPair(this.field_ADDR_ID1_FK, this.field_ADDR_ID1);
    this.reference_EMP_ADDR.addColumnPair(this.field_ADDR_ID2_FK, this.field_ADDR_ID2);

    this.reference_EMP_BOSS = this.table_EMP.addReference("emp_boss", this.table_EMP);
    this.reference_EMP_BOSS.setOnDatabase(true);
    this.reference_EMP_BOSS.addColumnPair(this.field_BOSS_ID_FK, this.field_EMP_ID);

    this.reference_ADDR_STATE = this.table_ADDR.addReference("addr_state", this.table_STATE);
    this.reference_ADDR_STATE.setOnDatabase(true);
    this.reference_ADDR_STATE.addColumnPair(this.field_STATE_ID1_FK, this.field_STATE_ID1);
    this.reference_ADDR_STATE.addColumnPair(this.field_STATE_ID2_FK, this.field_STATE_ID2);
  }