コード例 #1
0
 /**
  * Make sure nesting works right
  *
  * @throws ExpressionResolutionException
  */
 @Test
 public void testNesting() {
   assertEquals("{blah}", resolver.resolve("${resolves.to.nothing:{blah}}"));
   assertEquals(
       "{blah}", resolver.resolve("${resolves.to.nothing,also.resolves.to.nothing:{blah}}"));
   assertEquals(System.getProperty("os.name"), resolver.resolve("${os.name:{blah}}"));
   assertEquals("{{fo{o}oo}}", resolver.resolve("${resolves.to.nothing:{{fo{o}oo}}}"));
   assertEquals(
       "blah{{fo{o}oo}}blah", resolver.resolve("${resolves.to.nothing:blah{{fo{o}oo}}}blah"));
 }
コード例 #2
0
  /**
   * Make sure to work with local configured properties that delegates to system properties
   *
   * @throws ExpressionResolutionException
   */
  @Test
  public void testLocalDelegatedToSystemProperties() {
    Properties p = new Properties(System.getProperties());
    p.setProperty("foo", "fooValue");

    ExpressionResolver localResolver = new ExpressionResolver(p);

    assertEquals("fooValue", localResolver.resolve("${foo:default}"));

    assertEquals("default", localResolver.resolve("${baz:default}"));

    assertEquals(
        "System properties should be honored",
        System.getProperty("os.name"),
        localResolver.resolve("${os.name,foo}"));
  }
コード例 #3
0
 /**
  * Test an expression that contains more than one system property name to see that the second
  * property value is used when the first property is not defined.
  *
  * @throws ExpressionResolutionException
  */
 @Test
 public void testSystemPropertyRefs() {
   System.setProperty("test.property2", "test.property2.value");
   try {
     String value = "${test.property1,test.property2}";
     assertEquals("test.property2.value", resolver.resolve(value));
   } finally {
     System.clearProperty("test.property2");
   }
 }
コード例 #4
0
 /**
  * Validate a single system property expression sees the system property value.
  *
  * @throws ExpressionResolutionException
  */
 @Test
 public void testSystemPropertyRef() {
   System.setProperty("test.property1", "test.property1.value");
   try {
     String value = "${test.property1}";
     String result = resolver.resolve(value);
     assertEquals("test.property1.value", result);
   } finally {
     System.clearProperty("test.property1");
   }
 }
コード例 #5
0
 /**
  * Test that a incomplete expression to a system property reference throws an ISE
  *
  * @throws ExpressionResolutionException
  */
 @Test(expected = ExpressionResolutionException.class)
 public void testIncompleteReference() {
   System.setProperty("test.property1", "test.property1.value");
   try {
     String value = "${test.property1";
     String resolved = resolver.resolve(value);
     fail("Did not fail with ISE: " + resolved);
   } finally {
     System.clearProperty("test.property1");
   }
 }
コード例 #6
0
 /**
  * Validate that a environment variable reference is resolved.
  *
  * @throws ExpressionResolutionException
  */
 @Test
 public void testSystemEnvVarRef() {
   // Since we cannot set ENV vars from java, grab first one
   String[] envvar = findEnvVar();
   if (envvar[0].length() == 0) {
     fail("No environment variables found, can't pass test.");
     return;
   }
   final String envvarValue = envvar[1];
   Assert.assertNotNull("Expect non-null env var: " + envvar[0], envvarValue);
   final String value = "${" + envvar[0] + "}";
   assertEquals(envvarValue, resolver.resolve(value));
 }
コード例 #7
0
 /**
  * Validate that a environment variable reference is overriden by a system property of the same
  * name prefixed with "env.".
  *
  * @throws ExpressionResolutionException
  */
 @Test
 public void testSystemEnvVarRefOverride() {
   // Since we cannot set ENV vars from java, grab first one
   String[] envvar = findEnvVar();
   if (envvar[0].length() == 0) {
     fail("No environment variables found");
     return;
   }
   // Override the var
   String sysPropName = envvar[0];
   String overrideValue = sysPropName + "-override";
   try {
     System.setProperty(sysPropName, overrideValue);
     final String envvarValue = envvar[1];
     Assert.assertNotNull("Expect non-null env var: " + envvar[0], envvarValue);
     String value = "${" + envvar[0] + "}";
     assertEquals(overrideValue, resolver.resolve(value));
   } finally {
     System.clearProperty(sysPropName);
   }
 }
コード例 #8
0
 /**
  * Test that a valid expression to a system property reference which has no definition throws an
  * ISE
  *
  * @throws ExpressionResolutionException
  */
 @Test(expected = ExpressionResolutionException.class)
 public void testUnresolvedReference() {
   String value = "${no-such-system-property}";
   String resolved = resolver.resolve(value);
   fail("Did not fail with ISE: " + resolved);
 }
コード例 #9
0
 @Test
 public void testCanonicalResolver() {
   assertEquals("some expression", resolver.resolve("some expression"));
 }
コード例 #10
0
 @Test
 public void testResolverWithNullExpression() {
   assertEquals(null, resolver.resolve(null));
 }
コード例 #11
0
 @Test
 public void testResolverWithBlankExpression() {
   assertEquals("", resolver.resolve(""));
 }
コード例 #12
0
 /**
  * Validate that a property
  *
  * @throws ExpressionResolutionException
  */
 @Test
 public void testRecursiveProperty() {
   final String value = "${test.property1,test.property2:defaultValue}";
   assertEquals(resolver.resolve(value), "defaultValue");
 }
コード例 #13
0
 /**
  * Validate that a system property expression for a property with no value and a default provides
  * sees the default value.
  *
  * @throws ExpressionResolutionException
  */
 @Test
 public void testSystemPropertyRefDefault() {
   final String value = "${test.property2:test.property2.default.value}";
   assertEquals("test.property2.default.value", resolver.resolve(value));
 }