test_class.file: herd-code/herd-service/src/test/java/org/finra/herd/service/helper/VelocityNonStrictHelperTest.java
test_class.identifier: VelocityNonStrictHelperTest
test_class.superclass: extends AbstractServiceTest
test_case.body: @Test
      public void testEvaluateNonStrictReflection()
      {
          String template = "$foo.getClass().forName(\"java.lang.Runtime\").getRuntime().getName()";
          Map<String, Object> variables = new HashMap<>();
          variables.put("foo", "bar");
          String logTag = "test";
          try
          {
              velocityNonStrictHelper.evaluate(template, variables, logTag);
              fail();
          }
          catch (MethodInvocationException methodInvocationException)
          {
              Assert.assertEquals("Exception message not equal.",
                  "Object 'java.lang.Class' does not contain method forName(java.lang.String) at test[line 1, column 17]",
                  methodInvocationException.getMessage());
          }
      }
test_case.class_method_signature: VelocityNonStrictHelperTest.testEvaluateNonStrictReflection()
test_case.full_signature: @Test public void testEvaluateNonStrictReflection()
test_case.identifier: testEvaluateNonStrictReflection
test_case.invocations: put evaluate fail assertEquals getMessage
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testEvaluateNonStrictReflection()
focal_class.file: herd-code/herd-service/src/main/java/org/finra/herd/service/helper/VelocityNonStrictHelper.java
focal_class.identifier: VelocityNonStrictHelper
focal_class.class_method_signature: VelocityNonStrictHelper.evaluate(Reader templateReader, Map<String, Object> variables, String logTag, boolean strict)
focal_class.full_signature: private String evaluate(Reader templateReader, Map<String, Object> variables, String logTag, boolean strict)
focal_class.identifier: evaluate
focal_class.modifiers: private
focal_class.parameters: (Reader templateReader, Map<String, Object> variables, String logTag, boolean strict)
focal_class.return: String
focal_class.signature: String evaluate(Reader templateReader, Map<String, Object> variables, String logTag, boolean strict)
focal_class.class_method_signature: VelocityNonStrictHelper.evaluate(String template, Map<String, Object> variables, String logTag)
focal_class.full_signature: public String evaluate(String template, Map<String, Object> variables, String logTag)
focal_class.identifier: evaluate
focal_class.modifiers: public
focal_class.parameters: (String template, Map<String, Object> variables, String logTag)
focal_class.return: String
focal_class.signature: String evaluate(String template, Map<String, Object> variables, String logTag)
focal_class.class_method_signature: VelocityNonStrictHelper.evaluate(String template, Map<String, Object> variables, String logTag, boolean strict)
focal_class.full_signature: public String evaluate(String template, Map<String, Object> variables, String logTag, boolean strict)
focal_class.identifier: evaluate
focal_class.modifiers: public
focal_class.parameters: (String template, Map<String, Object> variables, String logTag, boolean strict)
focal_class.return: String
focal_class.signature: String evaluate(String template, Map<String, Object> variables, String logTag, boolean strict)
focal_method.body: private String evaluate(Reader templateReader, Map<String, Object> variables, String logTag, boolean strict)
      {
          /*  Get and initialize a velocity engine  */
          VelocityEngine velocityEngine = new VelocityEngine();
          velocityEngine.setProperty(RuntimeConstants.RUNTIME_REFERENCES_STRICT, strict);
          velocityEngine.setProperty(RuntimeConstants.UBERSPECT_CLASSNAME, SecureUberspector.class.getName());
          velocityEngine.init();
  
          VelocityContext velocityContext = new VelocityContext(variables);
          StringWriter writer = new StringWriter();
          if (!velocityEngine.evaluate(velocityContext, writer, logTag, templateReader))
          {
              // Although the velocityEngine.evaluate method's Javadoc states that it will return false to indicate a failure when the template couldn't be
              // processed and to see the Velocity log messages for more details, upon examining the method's implementation, it doesn't look like
              // it will ever return false. Instead, other RuntimeExceptions will be thrown (e.g. ParseErrorException).
              // Nonetheless, we'll leave this checking here to honor the method's contract in case the implementation changes in the future.
              // Having said that, there will be no way to JUnit test this flow.
              throw new IllegalStateException("Error evaluating velocity template. See velocity log message for more details.");
          }
          return writer.toString();
      }
focal_method.class_method_signature: VelocityNonStrictHelper.evaluate(Reader templateReader, Map<String, Object> variables, String logTag, boolean strict)
focal_method.full_signature: private String evaluate(Reader templateReader, Map<String, Object> variables, String logTag, boolean strict)
focal_method.identifier: evaluate
focal_method.invocations: setProperty setProperty getName init evaluate toString
focal_method.modifiers: private
focal_method.parameters: (Reader templateReader, Map<String, Object> variables, String logTag, boolean strict)
focal_method.return: String
focal_method.signature: String evaluate(Reader templateReader, Map<String, Object> variables, String logTag, boolean strict)