2017-12-14 15:33:27 +01:00
|
|
|
/**
|
|
|
|
* Copyright (C) 2011-2013,2017 Nicolas Vinot <aeris@imirhil.fr>
|
|
|
|
* Copyright (C) 2017 Christian Pierre MOMON <cmomon@april.org>
|
|
|
|
*
|
|
|
|
* This file is part of (April) Hebdobot.
|
|
|
|
*
|
|
|
|
* Hebdobot is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Hebdobot is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with Hebdobot. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
2017-12-14 21:57:51 +01:00
|
|
|
package org.april.hebdobot.irc;
|
2011-12-11 15:02:17 +01:00
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.io.Reader;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
import org.apache.commons.io.FileUtils;
|
2017-12-14 21:57:51 +01:00
|
|
|
import org.april.hebdobot.review.Review;
|
2011-12-11 15:02:17 +01:00
|
|
|
import org.joda.time.DateTime;
|
|
|
|
import org.joda.time.format.ISODateTimeFormat;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.runner.RunWith;
|
|
|
|
import org.springframework.test.context.ContextConfiguration;
|
|
|
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
|
|
|
2017-12-14 16:58:45 +01:00
|
|
|
/**
|
|
|
|
* The Class BotTest.
|
|
|
|
*/
|
2011-12-11 15:02:17 +01:00
|
|
|
@RunWith(SpringJUnit4ClassRunner.class)
|
2017-12-14 21:57:51 +01:00
|
|
|
@ContextConfiguration(locations = "/org/april/hebdobot/conf.xml")
|
2017-12-14 15:37:29 +01:00
|
|
|
public class BotTest implements ReviewListener
|
|
|
|
{
|
2017-12-14 16:58:45 +01:00
|
|
|
/**
|
|
|
|
* The Class BotMock.
|
|
|
|
*/
|
2017-12-14 17:14:59 +01:00
|
|
|
private static class BotMock extends Hebdobot
|
2017-12-14 15:37:29 +01:00
|
|
|
{
|
2017-12-14 16:58:45 +01:00
|
|
|
/**
|
|
|
|
* Instantiates a new bot mock.
|
|
|
|
*
|
|
|
|
* @throws Exception
|
|
|
|
* the exception
|
|
|
|
*/
|
2017-12-14 15:37:29 +01:00
|
|
|
public BotMock() throws Exception
|
|
|
|
{
|
|
|
|
super("", 0, "bot", "channel");
|
|
|
|
}
|
2011-12-11 15:02:17 +01:00
|
|
|
|
2017-12-14 16:58:45 +01:00
|
|
|
/* (non-Javadoc)
|
2017-12-14 21:57:51 +01:00
|
|
|
* @see org.april.hebdobot.irc.Bot#onMessage(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
|
2017-12-14 16:58:45 +01:00
|
|
|
*/
|
2017-12-14 15:37:29 +01:00
|
|
|
@Override
|
|
|
|
public void onMessage(final String channel, final String sender, final String login, final String hostname, final String message)
|
|
|
|
{
|
|
|
|
super.onMessage(channel, sender, login, hostname, message);
|
|
|
|
}
|
|
|
|
}
|
2011-12-11 15:02:17 +01:00
|
|
|
|
2017-12-14 16:58:45 +01:00
|
|
|
/* (non-Javadoc)
|
2017-12-14 21:57:51 +01:00
|
|
|
* @see org.april.hebdobot.irc.ReviewListener#onEnd(org.april.hebdobot.review.Review)
|
2017-12-14 16:58:45 +01:00
|
|
|
*/
|
2017-12-14 15:37:29 +01:00
|
|
|
@Override
|
|
|
|
public void onEnd(final Review review)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
final String date = ISODateTimeFormat.basicDate().print(new DateTime());
|
|
|
|
final String text = review.toString();
|
|
|
|
final File file = new File("target/" + date + "_revue.txt");
|
|
|
|
FileUtils.writeStringToFile(file, text);
|
|
|
|
}
|
2017-12-14 16:58:45 +01:00
|
|
|
catch (final IOException exception)
|
2017-12-14 15:37:29 +01:00
|
|
|
{
|
2017-12-14 16:58:45 +01:00
|
|
|
throw new RuntimeException(exception);
|
2017-12-14 15:37:29 +01:00
|
|
|
}
|
|
|
|
}
|
2011-12-11 15:02:17 +01:00
|
|
|
|
2017-12-14 16:58:45 +01:00
|
|
|
/**
|
|
|
|
* Redo.
|
|
|
|
*
|
|
|
|
* @throws Exception
|
|
|
|
* the exception
|
|
|
|
*/
|
2017-12-14 15:37:29 +01:00
|
|
|
@Test
|
|
|
|
public void redo() throws Exception
|
|
|
|
{
|
2017-12-14 17:14:59 +01:00
|
|
|
final Hebdobot bot = new BotMock();
|
2017-12-14 15:37:29 +01:00
|
|
|
bot.add(this);
|
2011-12-11 15:02:17 +01:00
|
|
|
|
2017-12-14 21:57:51 +01:00
|
|
|
final InputStream is = BotTest.class.getResourceAsStream("/org/april/hebdobot/review.log");
|
2017-12-14 15:37:29 +01:00
|
|
|
if (is == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try
|
|
|
|
{
|
|
|
|
final Reader isr = new InputStreamReader(is);
|
|
|
|
try
|
|
|
|
{
|
|
|
|
final BufferedReader isbr = new BufferedReader(isr);
|
|
|
|
try
|
|
|
|
{
|
|
|
|
String line;
|
|
|
|
final Pattern pattern = Pattern.compile(".*\\s+<([^>]+)>\\s+(.*)");
|
|
|
|
while ((line = isbr.readLine()) != null)
|
|
|
|
{
|
|
|
|
final Matcher matcher = pattern.matcher(line);
|
|
|
|
if (matcher.matches())
|
|
|
|
{
|
|
|
|
bot.onMessage("channel", matcher.group(1), "", "", matcher.group(2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
isbr.close();
|
|
|
|
}
|
2011-12-11 15:02:17 +01:00
|
|
|
|
2017-12-14 15:37:29 +01:00
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
isr.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
is.close();
|
|
|
|
}
|
|
|
|
}
|
2011-12-11 15:02:17 +01:00
|
|
|
}
|