Commit d929cb22 authored by Eric Tobias's avatar Eric Tobias

Implementation of a few unit tests.

parent 43e06060
<?xml version="1.0" encoding="UTF-8"?>
<tangibles>
<objects>
<object>
<type>BaseWidget</type>
<handles>
<handle>1</handle>
<handle>2</handle>
<handle>3534</handle>
<handle>-1</handle>
</handles>
<coronas>
<corona>
<type>Shadow</type>
<handle>1</handle>
<centre>
<x>0</x>
<y>0</y>
<z>0</z>
</centre>
<drawPriority>0</drawPriority>
</corona>
<corona>
<type>Shadow</type>
<handle>1</handle>
<centre>
<x>0</x>
<y>0</y>
<z>0</z>
</centre>
<drawPriority>1</drawPriority>
</corona>
</coronas>
<name>Marty</name>
<definingShape>Circle</definingShape>
<networkAdapter>
<type>TcpServer</type>
<port>36882</port>
</networkAdapter>
</object>
</objects>
<cursors>
</cursors>
<blobs>
</blobs>
</tangibles>
/**
* Copyright Luxembourg Institute of Science and Technology, 2015. All rights reserved.
*
* This file is part of TULIP.
*
* TULIP is free software: you can redistribute it and/or modify it under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation, version 3 of the
* License.
*
* TULIP 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 Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/
package lu.list.itis.dkd.tui.bootstrapping;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.network.adapter.BluetoothClient;
import lu.list.itis.dkd.tui.network.adapter.BluetoothServer;
import lu.list.itis.dkd.tui.network.adapter.TcpClient;
import lu.list.itis.dkd.tui.network.adapter.TcpServer;
import lu.list.itis.dkd.tui.network.adapter.XbeeAdapter;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.input.SAXBuilder;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.net.UnknownHostException;
/**
* @author Eric Tobias [eric.tobias@list.lu]
* @since 2.2
* @version 2.2.1
*/
public class NetworkAdapterBootstrapperTest {
private static Document xml;
private static Element emptyAdapterElement;
private static Element emptyTypeAdapterElement;
private static Element tcpClientElement;
private static Element tcpServerElement;
private static Element bluetoothClientElement;
private static Element bluetoothServerElement;
private static Element xbeeAdapterElement;
/**
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
SAXBuilder builder = new SAXBuilder();
File xmlFile = new File("test/networkAdapterBootstrapping.xml"); //$NON-NLS-1$
xml = builder.build(xmlFile);
emptyAdapterElement = xml.getRootElement().getChild("emptyAdapter"); //$NON-NLS-1$
emptyTypeAdapterElement = xml.getRootElement().getChild("emptyTypeAdapter"); //$NON-NLS-1$
tcpClientElement = xml.getRootElement().getChild("tcpClient"); //$NON-NLS-1$
tcpServerElement = xml.getRootElement().getChild("tcpServer"); //$NON-NLS-1$
bluetoothClientElement = xml.getRootElement().getChild("bluetoothClient"); //$NON-NLS-1$
bluetoothServerElement = xml.getRootElement().getChild("bluetoothServer"); //$NON-NLS-1$
xbeeAdapterElement = xml.getRootElement().getChild("xbeeAdapter"); //$NON-NLS-1$
}
/**
* Test method for a TcpClient.
*
* @throws BuildException
* @throws SecurityException
* @throws NoSuchFieldException
* @throws IllegalAccessException
* @throws IllegalArgumentException
* @throws IOException
* @throws UnknownHostException
*/
@Test
public final void testGetNetworkAdapterWithTcpClient() throws BuildException, IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException, UnknownHostException, IOException {
TcpServer tcpServer = (TcpServer) NetworkAdapterBootstrapper.getNetworkAdapter(tcpServerElement);
TcpClient tcpClient = (TcpClient) NetworkAdapterBootstrapper.getNetworkAdapter(tcpClientElement);
assertNotNull(tcpClient);
tcpClient.connect();
assertNotNull(tcpClient.getOutputStream());
assertNotNull(tcpClient.getInputStream());
tcpServer.closeClient();
tcpServer.closeServer();
}
/**
* Test method for a TcpServer.
*
* @throws BuildException
* @throws IOException
*/
@Test
public final void testGetNetworkAdapterWithTcpServer() throws BuildException, IOException {
TcpServer tcpServer = (TcpServer) NetworkAdapterBootstrapper.getNetworkAdapter(tcpServerElement);
assertNotNull(tcpServer);
tcpServer.closeServer();
}
@Test
public final void testGetNetworkAdapterWithBluetoothServer() throws BuildException, IOException {
BluetoothServer server = (BluetoothServer) NetworkAdapterBootstrapper.getNetworkAdapter(bluetoothServerElement);
assertNotNull(server);
server.closeServer();
}
@Test
public final void testGetNetworkAdapterWithBluetoothClient() throws BuildException, IOException {
BluetoothServer server = (BluetoothServer) NetworkAdapterBootstrapper.getNetworkAdapter(bluetoothServerElement);
BluetoothClient client = (BluetoothClient) NetworkAdapterBootstrapper.getNetworkAdapter(bluetoothClientElement);
assertNotNull(client);
server.closeClient();
server.closeServer();
}
@Test(expected = UnsatisfiedLinkError.class)
public final void testGetNetworkAdapterWithXbeeAdapter() throws BuildException, IOException {
XbeeAdapter adapter = (XbeeAdapter) NetworkAdapterBootstrapper.getNetworkAdapter(xbeeAdapterElement);
assertNotNull(adapter);
adapter.disconnect();
}
/**
* Method testing
* {@link lu.list.itis.dkd.tui.bootstrapping.NetworkAdapterBootstrapper#getNetworkAdapter(org.jdom2.Element)}
* with a null and empty element parameter.
*
* @throws BuildException
*/
@Test
public final void testGetWithNullAndEmptyElement() throws BuildException {
assertNull(NetworkAdapterBootstrapper.getNetworkAdapter(null));
assertNull(NetworkAdapterBootstrapper.getNetworkAdapter(emptyAdapterElement));
}
/**
* Testing whether an exception is correctly thrown when the type is empty.
*
* @throws BuildException
*/
@Test(expected = BuildException.class)
public final void testExceptionOnEmptyType() throws BuildException {
NetworkAdapterBootstrapper.getNetworkAdapter(emptyTypeAdapterElement);
fail("An exception should have been thrown!"); //$NON-NLS-1$
}
}
\ No newline at end of file
/**
* Copyright Luxembourg Institute of Science and Technology, 2015. All rights reserved.
*
* This file is part of TULIP.
*
* TULIP is free software: you can redistribute it and/or modify it under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation, version 3 of the
* License.
*
* TULIP 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 Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/
package lu.list.itis.dkd.tui.widget.builder;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import lu.list.itis.dkd.tui.bootstrapping.TangibleObjectBootstrapper;
import lu.list.itis.dkd.tui.network.adapter.TcpServer;
import lu.list.itis.dkd.tui.widget.BaseWidget;
import org.jdom2.input.SAXBuilder;
import org.junit.BeforeClass;
import org.junit.Test;
import java.awt.geom.Ellipse2D;
import java.io.File;
/**
* @author Eric Tobias [eric.tobias@list.lu]
* @since 2.2
* @version 2.2.1
*/
public class BaseBuilderBootstrappingTest {
private static TangibleObjectBootstrapper bootstrapper;
/**
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
SAXBuilder builder = new SAXBuilder();
File xmlFile = new File("test/baseBuilderBootstrapping.xml"); //$NON-NLS-1$
bootstrapper = new TangibleObjectBootstrapper(builder.build(xmlFile));
bootstrapper.bootstrap();
}
/**
* Test method for
* {@link lu.list.itis.dkd.tui.widget.builder.BaseBuilder#BaseBuilder(org.jdom2.Element)}.
*/
@Test
public final void testBaseBuilderElement() {
assertEquals(1, bootstrapper.getObjects().size());
BaseWidget widget = bootstrapper.getObjects().get(0);
assertEquals(4, widget.getPositions().size());
assertEquals(2, widget.getCoronas().size());
assertTrue(widget.getDefiningShape() instanceof Ellipse2D);
assertTrue(widget.getNetworkAdapter() instanceof TcpServer);
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<networkAdapterTest>
<emptyAdapter></emptyAdapter>
<emptyTypeAdapter>
<type></type>
</emptyTypeAdapter>
<tcpServer>
<type>TcpServer</type>
<port>36882</port>
</tcpServer>
<tcpClient>
<type>TcpClient</type>
<port>36882</port>
<host>127.0.0.1</host>
</tcpClient>
<bluetoothClient>
<type>BluetoothClient</type>
<serviceUuid>00001101-0000-1000-8000-00805f9b34fb</serviceUuid>
</bluetoothClient>
<bluetoothServer>
<type>BluetoothServer</type>
<serviceUuid>00001101-0000-1000-8000-00805f9b34fb</serviceUuid>
</bluetoothServer>
<xbeeAdapter>
<type>XbeeAdapter</type>
<port>36963</port>
<baudRate>4800</baudRate>
</xbeeAdapter>
</networkAdapterTest>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment