/******************************************************************************* * This file is part of OpenNMS(R). * * Copyright (C) 2011 The OpenNMS Group, Inc. * OpenNMS(R) is Copyright (C) 1999-2011 The OpenNMS Group, Inc. * * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc. * * OpenNMS(R) is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published * by the Free Software Foundation, either version 3 of the License, * or (at your option) any later version. * * OpenNMS(R) 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with OpenNMS(R). If not, see: * http://www.gnu.org/licenses/ * * For more information contact: * OpenNMS(R) Licensing <license@opennms.org> * http://www.opennms.org/ * http://www.opennms.com/ *******************************************************************************/ package org.opennms.protocols.nsclient; import java.io.IOException; import java.io.OutputStream; import org.junit.After; import org.junit.Before; import org.opennms.core.test.MockLogAppender; import org.opennms.netmgt.provision.server.SimpleServer; import org.opennms.netmgt.provision.server.exchange.RequestHandler; /** * <p>Abstract Class for NSClient Tests.</p> * * @author Alejandro Galue <agalue@opennms.org> * @version $Id: $ */ public abstract class AbstractNsclientTest { private SimpleServer m_server = null; @Before public void setUp() throws Exception { MockLogAppender.setupLogging(); } @After public void tearDown() throws Exception { MockLogAppender.assertNoWarningsOrGreater(); } public SimpleServer getServer() { return m_server; } public void startServer(final String command, final String response) throws Exception { m_server = new SimpleServer() { public void onInit() { addResponseHandler(startsWith(command), new RequestHandler() { @Override public void doRequest(OutputStream out) throws IOException { out.write(response.getBytes()); } }); } }; m_server.init(); m_server.startServer(); Thread.sleep(100); // make sure the server is really started } public void stopServer() throws Exception { if (m_server != null) { m_server.stopServer(); m_server = null; } } }