Пример #1
0
  /**
   * Loads the configuration resource (usually, a file) with the specified name from the first
   * {@link ResourceStreamSource} available.
   *
   * <p>If the configuration resource cannot be found then the provided {@link NotFoundPolicy}
   * determines whether an exception is thrown or not.
   */
  private void loadConfigurationResource(
      final String configurationResource,
      final NotFoundPolicy notFoundPolicy,
      final IsisConfigurationDefault.ContainsPolicy containsPolicy) {

    try {
      final PropertiesReader propertiesReader =
          loadConfigurationResource(resourceStreamSourceChain, configurationResource);
      LOG.info("loading properties from " + configurationResource);
      configuration.add(propertiesReader.getProperties(), containsPolicy);
      configurationResourcesFound.add(configurationResource);
      return;
    } catch (final IOException ignore) {
      // ignore
    }
    if (notFoundPolicy == NotFoundPolicy.FAIL_FAST) {
      throw new IsisException(
          String.format(
              "failed to load '%s'; tried using: %s",
              configurationResource, resourceStreamSourceChain.getName()));
    }
    configurationResourcesNotFound.add(configurationResource);
    if (LOG.isDebugEnabled()) {
      LOG.debug(String.format("'%s' not found, but not needed", configurationResource));
    }
  }
  public static ConfigurationStore buildConfigurationStore() {
    ConfigurationStore store = new ConfigurationStore();
    PropertiesReader propertiesReader = PropertiesReader.getInstance();

    namespace = propertiesReader.getString("namespace");

    tableMapping = new HashMap<String, String>();
    for (String table : propertiesReader.getList("tables")) {
      tableMapping.put(table, namespace + ":" + table);
    }

    return store;
  }
Пример #3
0
  @Test
  public void testInitFalse() throws IOException {

    List<WelcomeMessage> expected = new ArrayList<>(3);
    WelcomeMessage welcomeMessage1 = new WelcomeMessage(LocalTime.of(1, 0), LocalTime.of(12, 0));
    welcomeMessage1.setHelloMessage("Good morning");
    WelcomeMessage welcomeMessage2 = new WelcomeMessage(LocalTime.of(12, 0), LocalTime.of(19, 0));
    welcomeMessage2.setHelloMessage("Good day");
    WelcomeMessage welcomeMessage3 = new WelcomeMessage(LocalTime.of(19, 0), LocalTime.of(6, 0));
    welcomeMessage3.setHelloMessage("God evening");
    expected.add(welcomeMessage1);
    expected.add(welcomeMessage2);
    expected.add(welcomeMessage3);

    PropertiesReader prop = new PropertiesReader("projectTest.properties", Locale.ENGLISH);
    List<WelcomeMessage> result = prop.getWelcomeMessageList();

    assertThat(result, not(expected));
  }
Пример #4
0
  @Test
  public void testSetStringMessageWithLocalizationIfNoTranslation() throws Exception {
    String expected = "Good morning";
    WelcomeMessage welcomeMessage = new WelcomeMessage();

    PropertiesReader.setStringMessageWithLocalization(welcomeMessage, "welcomeObj1", Locale.CHINA);
    String result = welcomeMessage.getHelloMessage();

    assertThat(result, is(expected));
  }
Пример #5
0
  @Test
  public void testSetStringMessageWithLocalizationRu() throws Exception {
    String expected = "Доброе утро";
    WelcomeMessage welcomeMessage = new WelcomeMessage();

    PropertiesReader.setStringMessageWithLocalization(
        welcomeMessage, "welcomeObj1", new Locale("ru"));
    String result = welcomeMessage.getHelloMessage();

    assertThat(result, is(expected));
  }
Пример #6
0
 public static String toDateSring(Calendar date, PropertiesReader prop, String Format) {
   try {
     DateFormat df = new SimpleDateFormat(prop.getProperty(Format, false));
     String strDate = df.format(date.getTime());
     log.info("strDate Out " + strDate);
     return strDate;
   } catch (Exception e) {
     log.error("Error toDateString : " + Format, e);
   }
   return "Error toDateString : " + Format;
 }
Пример #7
0
  public DB2Manager() throws Exception {
    dbReader =
        DbReader.getInstance(
            Constants.JDBC_DRVER_DB2,
            Constants.JDBC_CONNECTION_URL,
            Constants.DB_USER,
            Constants.DB_PASS);

    configProp = PropertiesReader.loadPropertyFile(Constants.CONFIG_PROP_PATH);
    sqlPropFileName = configProp.getProperty(Constants.KEY_SQL_PROP_FILE);
  }
  @Before
  public void runEnvironment(TestContext context) {

    PropertiesReader propertiesReader = new PropertiesReader();
    propertiesReader.read();

    DeploymentOptions dopts = new DeploymentOptions();
    dopts.setConfig(propertiesReader.getAsJson());

    PotatoVerticle potatoVerticle = new PotatoVerticle();
    rule.vertx().deployVerticle(potatoVerticle, dopts, context.asyncAssertSuccess());

    Guice.createInjector(
            new GuiceModuleForTests(propertiesReader.getAsProperties()),
            new DbModule(),
            new GuiceModule(rule.vertx()))
        .injectMembers(this);

    // Clear DB before running tests
    dBCleaner.apply();
  }
Пример #9
0
  /**
   * �õ�ϵͳ���õ��ϴ��ļ�����·��
   *
   * @return String
   */
  public static String getPath(String loadPath) {
    String path = PropertiesReader.GetProptery(loadPath);
    if (path == null || "".equals(path)) {
      throw new java.lang.IllegalStateException("�ϴ��ļ��ı���·��û�����á�" + loadPath + "=?");
    }

    File file = new File(path);
    if (!file.isDirectory()) {
      file.mkdirs();
    }
    return path;
  }
Пример #10
0
 public static Calendar fromDateSring(String strDate, PropertiesReader prop, String Format) {
   Calendar date = new GregorianCalendar();
   if (!strDate.isEmpty()) {
     try {
       log.info("strDate in " + strDate);
       DateFormat df = new SimpleDateFormat(prop.getProperty(Format, false));
       date.setTime(df.parse(strDate));
       return date;
     } catch (Exception e) {
       log.error("Error fromDateSring : " + Format, e);
     }
   }
   return date;
 }
 @Override
 protected void configure() {
   Names.bindProperties(binder(), PropertiesReader.read(env));
 }
Пример #12
0
 public static String getString(String key) {
   return PropertiesReader.readProperty(BUNDLE_NAME, key);
 }
Пример #13
0
 public static String getDocumentPath() {
   return PropertiesReader.GetProptery(UPLOAD_FILE_SAVE_PATH);
 }