@Test public void testNonStringSystemProperties() { Object key1 = "1"; Object key2 = new Object(); System.getProperties().put(key1, new Object()); System.getProperties().put(key2, "value-2"); try { final PropertiesUtil util = new PropertiesUtil(new Properties()); assertNull(util.getStringProperty("1")); } finally { System.getProperties().remove(key1); System.getProperties().remove(key2); } } }
@Test public void testGetMappedProperty_sun_stdout_encoding() { final PropertiesUtil pu = new PropertiesUtil(System.getProperties()); Charset expected = System.console() == null ? Charset.defaultCharset() : StandardCharsets.UTF_8; assertEquals(expected, pu.getCharsetProperty("sun.stdout.encoding")); }
@Test public void testGetMappedProperty_sun_stderr_encoding() { final PropertiesUtil pu = new PropertiesUtil(System.getProperties()); Charset expected = System.console() == null ? Charset.defaultCharset() : StandardCharsets.UTF_8; assertEquals(expected, pu.getCharsetProperty("sun.err.encoding")); }
public SimpleLoggerContext() { props = new PropertiesUtil("log4j2.simplelog.properties"); showContextMap = props.getBooleanProperty(SYSTEM_PREFIX + "showContextMap", false); showLogName = props.getBooleanProperty(SYSTEM_PREFIX + "showlogname", false); showShortName = props.getBooleanProperty(SYSTEM_PREFIX + "showShortLogname", true); showDateTime = props.getBooleanProperty(SYSTEM_PREFIX + "showdatetime", false); final String lvl = props.getStringProperty(SYSTEM_PREFIX + "level"); defaultLevel = Level.toLevel(lvl, Level.ERROR); dateTimeFormat = showDateTime ? props.getStringProperty(SimpleLoggerContext.SYSTEM_PREFIX + "dateTimeFormat", DEFAULT_DATE_TIME_FORMAT) : null; final String fileName = props.getStringProperty(SYSTEM_PREFIX + "logFile", SYSTEM_ERR); PrintStream ps; if (SYSTEM_ERR.equalsIgnoreCase(fileName)) { ps = System.err; } else if (SYSTEM_OUT.equalsIgnoreCase(fileName)) { ps = System.out; } else { try { final FileOutputStream os = new FileOutputStream(fileName); ps = new PrintStream(os); } catch (final FileNotFoundException fnfe) { ps = System.err; } } this.stream = ps; }
@Test public void testGetCharsetProperty() throws Exception { final Properties p = new Properties(); p.setProperty("e.1", StandardCharsets.US_ASCII.name()); p.setProperty("e.2", "wrong-charset-name"); final PropertiesUtil pu = new PropertiesUtil(p); assertEquals(Charset.defaultCharset(), pu.getCharsetProperty("e.0")); assertEquals(StandardCharsets.US_ASCII, pu.getCharsetProperty("e.1")); assertEquals(Charset.defaultCharset(), pu.getCharsetProperty("e.2")); }
/** * Makes sure we do not blow up with exception below due to a security manager * rejecting environment variable access in * {@link SystemPropertiesPropertySource}. * * <pre> * </pre> */ @Test public void test() { final PropertiesUtil propertiesUtil = new PropertiesUtil(TEST_FIXTURE_PATH); Assert.assertEquals(null, propertiesUtil.getStringProperty("a.1")); } }
/** * Makes sure we do not blow up with exception below due to a security manager * rejecting environment variable access in * {@link SystemPropertiesPropertySource}. * * <pre> * java.lang.ExceptionInInitializerError * at org.apache.logging.log4j.util.SystemPropertiesPropertySourceSecurityManagerTest.test(SystemPropertiesPropertySourceSecurityManagerTest.java:64) * ... * Caused by: java.lang.SecurityException * at org.apache.logging.log4j.util.SystemPropertiesPropertySourceSecurityManagerTest$TestSecurityManager.checkPermission(SystemPropertiesPropertySourceSecurityManagerTest.java:49) * at java.lang.SecurityManager.checkPropertiesAccess(SecurityManager.java:1265) * at java.lang.System.getProperties(System.java:624) * at org.apache.logging.log4j.util.SystemPropertiesPropertySource.forEach(SystemPropertiesPropertySource.java:40) * at org.apache.logging.log4j.util.PropertiesUtil$Environment.reload(PropertiesUtil.java:330) * at org.apache.logging.log4j.util.PropertiesUtil$Environment.<init>(PropertiesUtil.java:322) * at org.apache.logging.log4j.util.PropertiesUtil$Environment.<init>(PropertiesUtil.java:310) * at org.apache.logging.log4j.util.PropertiesUtil.<init>(PropertiesUtil.java:69) * at org.apache.logging.log4j.util.PropertiesUtil.<clinit>(PropertiesUtil.java:49) * ... 26 more * </pre> */ @Test public void test() { final PropertiesUtil propertiesUtil = new PropertiesUtil("src/test/resources/PropertiesUtilTest.properties"); Assert.assertEquals(null, propertiesUtil.getStringProperty("a.1")); } }
@Test public void testIsGemfireObject() { assertTrue("Instances of Function are GemFire objects", InternalDataSerializer.isGemfireObject(new TestFunction())); assertFalse("Instances of PdxSerializaerObject are NOT GemFire objects", InternalDataSerializer.isGemfireObject(new TestPdxSerializerObject())); assertFalse("Instances of anything under org.apache. are GemFire objects", InternalDataSerializer.isGemfireObject(new SimpleLogger("", Level.OFF, false, false, false, false, "", null, new PropertiesUtil(new Properties()), null))); assertTrue("Instances of anything in org.apache.geode. are GemFire objects", InternalDataSerializer.isGemfireObject(new InternalGemFireException())); assertTrue("Instances of anything under org.apache.geode. are GemFire objects", InternalDataSerializer.isGemfireObject(new ExampleSecurityManager())); }
protected Charset getCharset(final String property, Charset defaultCharset) { return new PropertiesUtil(PropertiesUtil.getSystemProperties()).getCharsetProperty(property, defaultCharset); }
: (FallbackLoggerConfiguration.isDebugEnabled() ? Level.DEBUG : Level.INFO); Logger logger = new SimpleLogger(name, level, true, false, true, true, "yyyy-MM-dd HH:mm:ss.SSSZ", null, new PropertiesUtil(new Properties()), System.out); if (logWarning.get()) { logger.info("No Log4j2 compatible logger was found. Using default Javacord implementation!");
public SimpleLoggerContext() { props = new PropertiesUtil("log4j2.simplelog.properties"); showContextMap = props.getBooleanProperty(SYSTEM_PREFIX + "showContextMap", false); showLogName = props.getBooleanProperty(SYSTEM_PREFIX + "showlogname", false); showShortName = props.getBooleanProperty(SYSTEM_PREFIX + "showShortLogname", true); showDateTime = props.getBooleanProperty(SYSTEM_PREFIX + "showdatetime", false); final String lvl = props.getStringProperty(SYSTEM_PREFIX + "level"); defaultLevel = Level.toLevel(lvl, Level.ERROR); dateTimeFormat = showDateTime ? props.getStringProperty(SimpleLoggerContext.SYSTEM_PREFIX + "dateTimeFormat", DEFAULT_DATE_TIME_FORMAT) : null; final String fileName = props.getStringProperty(SYSTEM_PREFIX + "logFile", SYSTEM_ERR); PrintStream ps; if (SYSTEM_ERR.equalsIgnoreCase(fileName)) { ps = System.err; } else if (SYSTEM_OUT.equalsIgnoreCase(fileName)) { ps = System.out; } else { try { final FileOutputStream os = new FileOutputStream(fileName); ps = new PrintStream(os); } catch (final FileNotFoundException fnfe) { ps = System.err; } } this.stream = ps; }