Esempio n. 1
0
  public void testExceptionContainsFileNameUnmarshalResourceWithBadResource()
      throws MarshalException, ValidationException, FileNotFoundException, IOException {
    /*
     * We are going to attempt to unmarshal groups.xml with the wrong
     * class so we get a MarshalException and we can then test to see if the
     * file name is embedded in the exception.
     */
    boolean gotException = false;
    File file = ConfigurationTestUtils.getFileForConfigFile("groups.xml");
    try {
      CastorUtils.unmarshal(Userinfo.class, new FileSystemResource(file));
    } catch (MarshalException e) {
      String matchString = file.getAbsolutePath().replace('\\', '/');
      if (e.toString().contains(matchString)) {
        gotException = true;
      } else {
        AssertionFailedError ae =
            new AssertionFailedError(
                "Got an exception, but not one containing the message we were expecting ('"
                    + matchString
                    + "'): "
                    + e);
        ae.initCause(e);
        throw ae;
      }
    }

    if (!gotException) {
      fail("Did not get a MarshalException, but we were expecting one.");
    }
  }
  protected void initializeDatabase() throws Exception {

    // Create a ByteArrayOutputSteam to effectively throw away output.
    resetOutputStream();
    m_installerDb.setDatabaseName(getTestDatabase());
    m_installerDb.setDataSource(getDataSource());

    m_installerDb.setAdminDataSource(getAdminDataSource());
    m_installerDb.setPostgresOpennmsUser(getAdminUser());

    m_installerDb.setCreateSqlLocation(
        ConfigurationTestUtils.getFileForConfigFile("create.sql").getAbsolutePath());
    m_installerDb.setStoredProcedureDirectory(
        ConfigurationTestUtils.getFileForConfigFile("getPercentAvailabilityInWindow.sql")
            .getParentFile()
            .getAbsolutePath());

    // m_installerDb.setDebug(true);

    m_installerDb.readTables();

    m_installerDb.createSequences();
    m_installerDb.updatePlPgsql();
    m_installerDb.addStoredProcedures();

    /*
     * Here's an example of an iplike function that always returns true.
     * CREATE OR REPLACE FUNCTION iplike(text, text) RETURNS bool AS ' BEGIN RETURN true; END; ' LANGUAGE 'plpgsql';
     *
     * Found this in BaseIntegrationTestCase.
     */

    if (m_setupIpLike) {
      m_installerDb.setPostgresIpLikeLocation(null);
      m_installerDb.updateIplike();
    }

    m_installerDb.createTables();

    if (m_insertData) {
      m_installerDb.insertData();
    }
  }