DecodeBase64Function implements Function { @Override public String execute(List<String> parameterList, TestContext context) { if (CollectionUtils.isEmpty(parameterList) || parameterList.size() < 1) { throw new InvalidFunctionUsageException("Invalid function parameter usage! Missing parameters!"); } String charset = "UTF-8"; if (parameterList.size() > 1) { charset = parameterList.get(1); } try { return new String(Base64.decodeBase64(parameterList.get(0)), charset); } catch (UnsupportedEncodingException e) { throw new CitrusRuntimeException("Unsupported character encoding", e); } }  @Override String execute(List<String> parameterList, TestContext context);  }
@Test public void testFunction() { Assert.assertEquals(function.execute(Collections.singletonList("Zm9v"), context), "foo"); }
@Test public void testCustomCharset() { Assert.assertEquals(function.execute(Arrays.asList("Zm9v", "UTF-8"), context), "foo"); }
@Test public void testUnsupportedCharset() { try { function.execute(Arrays.asList("foo", "UNKNOWN"), context); Assert.fail("Missing exception due to unsupported charset encoding"); } catch (CitrusRuntimeException e) { Assert.assertTrue(e.getCause().getClass().equals(UnsupportedEncodingException.class)); } }
@Test(expectedExceptions = {InvalidFunctionUsageException.class}) public void testNoParameters() { function.execute(Collections.emptyList(), context); }