001package org.apache.maven.doxia.macro; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.io.File; 023 024import java.util.HashMap; 025import java.util.Iterator; 026import java.util.Map; 027 028import org.apache.maven.doxia.sink.impl.SinkEventElement; 029import org.apache.maven.doxia.sink.impl.SinkEventTestingSink; 030 031import junit.framework.TestCase; 032 033/** 034 * Test echo macro. 035 * 036 * @author ltheussl 037 */ 038public class EchoMacroTest 039 extends TestCase 040{ 041 042 /** 043 * Test of execute method, of class EchoMacro. 044 */ 045 public void testExecute() 046 { 047 final Map<String,Object> macroParameters = new HashMap<String,Object>(); 048 macroParameters.put( "paramName", "paramValue" ); 049 macroParameters.put( "parser", "parserValue" ); 050 macroParameters.put( "sourceContent", "sourceContentValue" ); 051 052 SinkEventTestingSink sink = new SinkEventTestingSink(); 053 MacroRequest request = new MacroRequest( macroParameters, new File( "." ) ); 054 055 new EchoMacro().execute( sink, request ); 056 057 Iterator<SinkEventElement> it = sink.getEventList().iterator(); 058 SinkEventElement event = it.next(); 059 assertEquals( "verbatim", event.getName() ); 060 event = it.next(); 061 assertEquals( "text", event.getName() ); 062 assertEquals( "echo" + Macro.EOL, (String) event.getArgs()[0] ); 063 event = it.next(); 064 assertEquals( "text", event.getName() ); 065 assertEquals( "paramName ---> paramValue" + Macro.EOL, (String) event.getArgs()[0] ); 066 event = it.next(); 067 assertEquals( "verbatim_", event.getName() ); 068 assertFalse( it.hasNext() ); 069 } 070 071 /** 072 * Test log. 073 */ 074 public void testLog() 075 { 076 EchoMacro macro = new EchoMacro(); 077 macro.enableLogging( null ); 078 assertNotNull ( macro.getLog() ); 079 assertNotNull ( macro.getLog() ); 080 } 081}