View Javadoc

1   package org.apache.maven.doxia.macro;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  
24  import java.util.HashMap;
25  import java.util.Iterator;
26  import java.util.Map;
27  
28  import junit.framework.TestCase;
29  
30  import org.apache.maven.doxia.sink.SinkEventElement;
31  import org.apache.maven.doxia.sink.SinkEventTestingSink;
32  
33  /**
34   * Test echo macro.
35   *
36   * @author ltheussl
37   */
38  public class EchoMacroTest
39          extends TestCase
40  {
41  
42      /**
43       * Test of execute method, of class EchoMacro.
44       */
45      public void testExecute()
46      {
47          final Map<String,Object> macroParameters = new HashMap<String,Object>();
48          macroParameters.put( "paramName", "paramValue" );
49          macroParameters.put( "parser", "parserValue" );
50          macroParameters.put( "sourceContent", "sourceContentValue" );
51  
52          SinkEventTestingSink sink = new SinkEventTestingSink();
53          MacroRequest request = new MacroRequest( macroParameters, new File( "." ) );
54  
55          new EchoMacro().execute( sink, request );
56  
57          Iterator<SinkEventElement> it = sink.getEventList().iterator();
58          SinkEventElement event = it.next();
59          assertEquals( "verbatim", event.getName() );
60          event = it.next();
61          assertEquals( "text", event.getName() );
62          assertEquals( "echo" + Macro.EOL,  (String) event.getArgs()[0] );
63          event = it.next();
64          assertEquals( "text", event.getName() );
65          assertEquals( "paramName ---> paramValue" + Macro.EOL,  (String) event.getArgs()[0] );
66          event = it.next();
67          assertEquals( "verbatim_", event.getName() );
68          assertFalse( it.hasNext() );
69      }
70  
71      /**
72       * Test log.
73       */
74      public void testLog()
75      {
76          EchoMacro macro = new EchoMacro();
77          macro.enableLogging( null );
78          assertNotNull ( macro.getLog() );
79          assertNotNull ( macro.getLog() );
80      }
81  }