1 /****************************************************************
2 * Licensed to the Apache Software Foundation (ASF) under one *
3 * or more contributor license agreements. See the NOTICE file *
4 * distributed with this work for additional information *
5 * regarding copyright ownership. The ASF licenses this file *
6 * to you under the Apache License, Version 2.0 (the *
7 * "License"); you may not use this file except in compliance *
8 * with the License. You may obtain a copy of the License at *
9 * *
10 * http://www.apache.org/licenses/LICENSE-2.0 *
11 * *
12 * Unless required by applicable law or agreed to in writing, *
13 * software distributed under the License is distributed on an *
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15 * KIND, either express or implied. See the License for the *
16 * specific language governing permissions and limitations *
17 * under the License. *
18 ****************************************************************/
19 package org.apache.jsieve.util;
20
21 import java.io.ByteArrayInputStream;
22 import java.io.StringWriter;
23
24 import org.apache.jsieve.ConfigurationManager;
25 import org.apache.jsieve.parser.generated.Node;
26
27 import junit.framework.TestCase;
28
29 public class XmlGenerationTest extends TestCase {
30
31 //@Override
32 protected void setUp() throws Exception {
33 super.setUp();
34 }
35
36 //@Override
37 protected void tearDown() throws Exception {
38 super.tearDown();
39 }
40
41 public void testShouldGenerateXmlFromSimpleScript() throws Exception {
42 // Set up
43 final String script = "if address :all :is \"from\" \"user@domain\" {stop;}";
44 final Node node = new ConfigurationManager().build().parse(new ByteArrayInputStream(script.getBytes()));
45 final StringWriter monitor = new StringWriter();
46
47 // Exercise
48 OutputUtils.toXml(node, monitor);
49
50 // Verify
51 assertEquals("<sieve:control xmlns:sieve='urn:ietf:params:xml:ns:sieve' sieve:name='if'>" +
52 "<sieve:test sieve:name='address'>" +
53 "<sieve:tag>all</sieve:tag>" +
54 "<sieve:tag>is</sieve:tag>" +
55 "<sieve:str>from</sieve:str>" +
56 "<sieve:str>user@domain</sieve:str>" +
57 "</sieve:test>" +
58 "<sieve:control sieve:name='stop'/>" +
59 "</sieve:control>", monitor.toString());
60 }
61 }