Commit fd51f3b4 authored by Nicolas Gilmard's avatar Nicolas Gilmard

Complete JUnit test for the adapter loading

parent 5ce6383e
......@@ -128,7 +128,7 @@ public class TuioAdapter extends TuiAdapter implements TuioListener {
private TangibleObject convertTuioObjectToTangibleObject(TuioObject tuioObject) {
Preconditions.checkArgument(tuioObject != null, "The passed tangible cursor cannot be null!"); //$NON-NLS-1$
// get the object if present
TangibleObject updateObject = tangibleObjectList.get(tuioObject.getSymbolID()) != null ? tangibleObjectList.get(tuioObject.getSymbolID()) : null;
TangibleObject updateObject = tangibleObjectList.get(tuioObject.getSymbolID());
TangibleObject convertedTangibleObject;
if (updateObject == null) {
// if the object is not present simply convert the tuioPath
......@@ -177,13 +177,26 @@ public class TuioAdapter extends TuiAdapter implements TuioListener {
*/
private TangibleObject convertTuioBlobToTangibleObject(TuioBlob tuioBlob) {
Preconditions.checkArgument(tuioBlob != null, "The passed tangible cursor cannot be null!"); //$NON-NLS-1$
// get the object if present
TangibleObject updateObject = tangibleObjectList.get(tuioBlob.getBlobID());
TangibleObject convertedTangibleObject;
if (updateObject == null) {
// if the object is not present simply convert the tuioPath
ArrayList<Point> tempPath = new ArrayList<>();
tuioBlob.getPath().forEach(path -> tempPath.add(new Point(path.getX(), path.getY(), tuioBlob.getAngle())));
convertedTangibleObject = new TangibleObjectBuilder(IDMapper.remapCursorID(tuioBlob.getBlobID()), Type.BLOB, tuioBlob.getPath().get(tuioBlob.getPath().size() - 1).getX(), tuioBlob.getPath().get(tuioBlob.getPath().size() - 1).getY()).withSeconds(tuioBlob.getTuioTime().getSeconds()).withMicroSeconds(tuioBlob.getTuioTime().getMicroseconds()).withxSpeed(tuioBlob.getXSpeed()).withySpeed(tuioBlob.getYSpeed()).withMotionSpeed(tuioBlob.getMotionSpeed()).withMotionAccel(tuioBlob.getMotionAccel()).withRotationSpeed(tuioBlob.getRotationSpeed()).withRotationAccel(tuioBlob.getRotationAccel()).withPath(tempPath).withState(tuioBlob.getTuioState()).build();
ArrayList<Point> tempPath = new ArrayList<>();
tuioBlob.getPath().forEach(path -> tempPath.add(new Point(path.getX(), path.getY(), tuioBlob.getAngle())));
// !!! MAPPING ID !!!!!!!!!!!
TangibleObject convertedTangibleObject = new TangibleObjectBuilder(IDMapper.remapCursorID(tuioBlob.getBlobID()), Type.BLOB, tuioBlob.getPath().get(tuioBlob.getPath().size() - 1).getX(), tuioBlob.getPath().get(tuioBlob.getPath().size() - 1).getY()).withSeconds(tuioBlob.getTuioTime().getSeconds()).withMicroSeconds(tuioBlob.getTuioTime().getMicroseconds()).withxSpeed(tuioBlob.getXSpeed()).withySpeed(tuioBlob.getYSpeed()).withMotionSpeed(tuioBlob.getMotionSpeed()).withMotionAccel(tuioBlob.getMotionAccel()).withRotationSpeed(tuioBlob.getRotationSpeed()).withRotationAccel(tuioBlob.getRotationAccel()).withPath(tempPath).withState(tuioBlob.getTuioState()).withWidth(tuioBlob.getWidth()).withHeight(tuioBlob.getHeight()).withArea(tuioBlob.getArea()).build();
} else {
// if the object is present in the list, get previous path and add the last point
ArrayList<Point> tempPath = new ArrayList<>();
tempPath = updateObject.getPath();
int index = tuioBlob.getPath().size() - 1;
tempPath.add(new Point(tuioBlob.getPath().get(index).getX(), tuioBlob.getPath().get(index).getY(), tuioBlob.getAngle()));
convertedTangibleObject = new TangibleObjectBuilder(IDMapper.remapCursorID(tuioBlob.getBlobID()), Type.BLOB, tuioBlob.getPath().get(tuioBlob.getPath().size() - 1).getX(), tuioBlob.getPath().get(tuioBlob.getPath().size() - 1).getY()).withSeconds(tuioBlob.getTuioTime().getSeconds()).withMicroSeconds(tuioBlob.getTuioTime().getMicroseconds()).withxSpeed(tuioBlob.getXSpeed()).withySpeed(tuioBlob.getYSpeed()).withMotionSpeed(tuioBlob.getMotionSpeed()).withMotionAccel(tuioBlob.getMotionAccel()).withRotationSpeed(tuioBlob.getRotationSpeed()).withRotationAccel(tuioBlob.getRotationAccel()).withPath(tempPath).withState(tuioBlob.getTuioState()).build();
}
return convertedTangibleObject;
}
/**
......@@ -223,6 +236,7 @@ public class TuioAdapter extends TuiAdapter implements TuioListener {
Preconditions.checkArgument(tangibleObject != null, "The passed tangible object cannot be null!"); //$NON-NLS-1$
TangibleObject convertedTangibleObject = convertTuioBlobToTangibleObject(tangibleObject);
tangibleObjectList.put(convertedTangibleObject.getObjectId(), convertedTangibleObject);
super.addObjInfo(convertedTangibleObject, "down"); //$NON-NLS-1$
......@@ -271,9 +285,14 @@ public class TuioAdapter extends TuiAdapter implements TuioListener {
/** {@inheritDoc} */
@Override
public void removeTuioBlob(TuioBlob arg0) {
// TODO Auto-generated method stub
public void removeTuioBlob(TuioBlob tuioBlob) {
Preconditions.checkArgument(tuioBlob != null, "The passed tangible object cannot be null!"); //$NON-NLS-1$
TangibleObject convertedTangibleObject = convertTuioBlobToTangibleObject(tuioBlob);
tangibleObjectList.remove(convertedTangibleObject.getObjectId());
super.addObjInfo(convertedTangibleObject, "up"); //$NON-NLS-1$
objectManager.liftObject(convertedTangibleObject);
}
/**
......@@ -285,7 +304,6 @@ public class TuioAdapter extends TuiAdapter implements TuioListener {
Preconditions.checkArgument(tangibleCursor != null, "The passed tangible cursor cannot be null!"); //$NON-NLS-1$
TangibleObject convertedTangibleObject = convertTuioCursorToTangibleObject(tangibleCursor);
super.addCurInfo(convertedTangibleObject, "move"); //$NON-NLS-1$
objectManager.updateObject(convertedTangibleObject);
......@@ -300,6 +318,7 @@ public class TuioAdapter extends TuiAdapter implements TuioListener {
Preconditions.checkArgument(tangibleObject != null, "The passed tangible object cannot be null!"); //$NON-NLS-1$
TangibleObject convertedTangibleObject = convertTuioObjectToTangibleObject(tangibleObject);
// convertedTangibleObject.getPath().forEach(path -> System.out.println(path.getAngle()));
super.addObjInfo(convertedTangibleObject, "move"); //$NON-NLS-1$
objectManager.updateObject(convertedTangibleObject);
......@@ -308,9 +327,13 @@ public class TuioAdapter extends TuiAdapter implements TuioListener {
/** {@inheritDoc} */
@Override
public void updateTuioBlob(TuioBlob arg0) {
// TODO Auto-generated method stub
public void updateTuioBlob(TuioBlob tuioBlob) {
Preconditions.checkArgument(tuioBlob != null, "The passed tangible object cannot be null!"); //$NON-NLS-1$
TangibleObject convertedTangibleObject = convertTuioBlobToTangibleObject(tuioBlob);
super.addObjInfo(convertedTangibleObject, "move"); //$NON-NLS-1$
objectManager.updateObject(convertedTangibleObject);
}
/**
......
......@@ -41,6 +41,4 @@ public class ExitDeniedSecurityManager extends SecurityManager {
@Override
public void checkPermission(final Permission perm) {}
/* TODO: Make sure you override everything with an empty method as above */
}
\ No newline at end of file
......@@ -19,21 +19,16 @@ import static org.junit.Assert.fail;
import lu.list.itis.dkd.tui.ExitDeniedSecurityManager.ExitSecurityException;
import lu.list.itis.dkd.tui.adapter.TangibleObject;
import lu.list.itis.dkd.tui.adapter.TuiAdapter;
import lu.list.itis.dkd.tui.content.Content;
import lu.list.itis.dkd.tui.event.ContentEvent;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.tudor.ssi.kiss.dbc.annotation.NonNullByDefault;
import org.junit.Before;
import org.junit.Test;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.HashSet;
import java.util.Properties;
import java.util.logging.Logger;
import java.util.logging.Level;
/**
* Test case for testing the {@link TangibleApplication} class.
......@@ -64,16 +59,16 @@ public class TangibleApplicationTest2 {
@Test
public void testTangibleApplication() throws Exception {
FileInputStream in = new FileInputStream(propertiesLocation);
FileInputStream inputStream = new FileInputStream(propertiesLocation);
Properties props = new Properties();
props.load(in);
props.load(inputStream);
FileOutputStream out = new FileOutputStream(propertiesLocation);
FileOutputStream outputStream = new FileOutputStream(propertiesLocation);
// InstanciationException
props.setProperty("tableAdapter", "lu.list.itis.dkd.tui.adapter.TuiAdapter"); //$NON-NLS-1$ //$NON-NLS-2$
props.store(out, null);
props.store(outputStream, null);
try {
application = new TestTangibleApplication(propertiesLocation);
......@@ -84,9 +79,9 @@ public class TangibleApplicationTest2 {
}
// ClassNotFoundException
props.load(in);
props.load(inputStream);
props.setProperty("tableAdapter", "lu.list.itis.dkd.tui.adapter.TuAdapter"); //$NON-NLS-1$ //$NON-NLS-2$
props.store(out, null);
props.store(outputStream, null);
try {
......@@ -98,56 +93,44 @@ public class TangibleApplicationTest2 {
assertEquals(42, status);
}
// NoSuchMethodException
props.load(inputStream);
props.setProperty("tableAdapter", "lu.list.itis.dkd.tui.adapter.TuioAdapter"); //$NON-NLS-1$ //$NON-NLS-2$
props.store(outputStream, null);
try {
// props.load(in);
// props.setProperty("tableAdapter", "lu.list.itis.dkd.tui.adapter.TuAdapter");
// props.store(out, null);
// try {
//
// application = new TestTangibleApplication(propertiesLocation);
// fail("Expected exit25"); //$NON-NLS-1$
// } catch (ExitSecurityException e) {
// int status = e.getStatus();
// assertEquals(42, status);
// }
in.close();
out.close();
}
application = new TestTangibleApplicationNoSuchMethod(propertiesLocation);
fail("Expected exit"); //$NON-NLS-1$
} catch (ExitSecurityException e) {
int status = e.getStatus();
assertEquals(42, status);
}
/**
* Test method for {@link lu.list.itis.dkd.tui.TangibleApplication#connect()}.
*/
public void testConnect() {
fail("Method not implemented in mock!"); //$NON-NLS-1$
}
// IllegalArgumentException
try {
/**
* Test method for {@link lu.list.itis.dkd.tui.TangibleApplication#getInterfaceManager()}.
*/
public void testGetInterfaceManager() {
fail("Method not implemented in mock!"); //$NON-NLS-1$
}
application = new TestTangibleApplicationIllegalArgument(propertiesLocation);
fail("Expected exit"); //$NON-NLS-1$
} catch (ExitSecurityException e) {
int status = e.getStatus();
assertEquals(42, status);
}
// InvocationTargetException
try {
/**
* Test method for {@link lu.list.itis.dkd.tui.TangibleApplication#getObjectManager()} and
* {@link lu.list.itis.dkd.tui.TangibleApplication#setObjectManager(TangibleObjectManager)}.
*/
@SuppressWarnings("null")
public void testSetAndGetObjectManager() {
fail("Method not implemented in mock!"); //$NON-NLS-1$
}
application = new TestTangibleApplicationInvocationTargetException(propertiesLocation);
fail("Expected exit"); //$NON-NLS-1$
} catch (ExitSecurityException e) {
int status = e.getStatus();
assertEquals(42, status);
}
/**
* Test method for {@link lu.list.itis.dkd.tui.TangibleApplication#getContentManager()} and
* {@link lu.list.itis.dkd.tui.TangibleApplication#setContentManager(lu.list.itis.dkd.tui.TangibleContentManager)}
* .
*/
public void testSetAndGetContentManager() {
fail("Method not implemented in mock!"); //$NON-NLS-1$
inputStream.close();
outputStream.close();
}
/**
......@@ -171,128 +154,140 @@ public class TangibleApplicationTest2 {
}
/**
* Class implementing the abstract {@link TangibleContentManager} for test purposes.
* Class implementing the abstract {@link TangibleApplication} for test purposes.
*
* @author Eric TOBIAS [eric.tobias@tudor.lu]
* @since 1.0
* @version 1.0.2
* @author Nicolas GILMARD [nicolas.gilmard@list.lu]
* @since 11/05/2015
* @version 1
*/
@NonNullByDefault
public class TestTangibleContentManager extends TangibleContentManager {
/**
* {@inheritDoc}
*/
@Override
public void contentUpdated(ContentEvent event) {
fail("Method not implemented in mock!"); //$NON-NLS-1$
}
public class TestTangibleApplicationNoSuchMethod extends TangibleApplication {
/**
* {@inheritDoc}
* Constructor initialising several basic properties.
*
* @param newPropertiesFileURI
* The URI of the properties file to load.
* @throws Exception
*/
@Override
public Collection<Content> getDrawableContents() {
fail("Method not implemented in mock!"); //$NON-NLS-1$
return new HashSet<Content>();
protected TestTangibleApplicationNoSuchMethod(String newPropertiesFileURI) throws Exception {
super(newPropertiesFileURI);
try {
adapter = (TuiAdapter) Class.forName(properties.getProperty("tableAdapter")).getConstructor().newInstance(); //$NON-NLS-1$
} catch (NoSuchMethodException e) {
logger.log(Level.SEVERE, "The called method was not found"); //$NON-NLS-1$
System.exit(42);
}
}
}
/**
* Class implementing the abstract {@link TangibleObjectManager} for test purposes.
* Class implementing the abstract {@link TangibleApplication} for test purposes.
*
* @author Eric TOBIAS [eric.tobias@tudor.lu]
* @since 13 Mar 2014
* @author Nicolas GILMARD [nicolas.gilmard@list.lu]
* @since 11/05/2015
* @version 1
*/
public class TestTangibleObjectManager extends TangibleObjectManager {
public class TestTangibleApplicationIllegalArgument extends TangibleApplication {
/**
* Constructor initialising several fields and setting up the list of managed tangibles.
* Constructor initialising several basic properties.
*
* @param applicationContext
* The {@link TangibleApplication} hosting this manager.
* @param applicationLogger
* The {@link Logger} to use for all logging purposes.
* @param properties
* The properties instance from which to load the default values from.
* @param newPropertiesFileURI
* The URI of the properties file to load.
* @throws Exception
*/
@NonNullByDefault
public TestTangibleObjectManager(TangibleApplication applicationContext, Logger applicationLogger, Properties properties) {
super(applicationContext, applicationLogger, properties);
protected TestTangibleApplicationIllegalArgument(String newPropertiesFileURI) throws Exception {
super(newPropertiesFileURI);
try {
adapter = (TuiAdapter) Class.forName(properties.getProperty("tableAdapter")).getConstructor(TangibleInterfaceManager.class).newInstance(new String()); //$NON-NLS-1$
} catch (IllegalArgumentException e) {
logger.log(Level.SEVERE, "A wrong argument has been passed to the adapter."); //$NON-NLS-1$
System.exit(42);
}
}
}
/**
* Class implementing the abstract {@link TangibleApplication} for test purposes.
*
* @author Nicolas GILMARD [nicolas.gilmard@list.lu]
* @since 11/05/2015
* @version 1
*/
public class TestTangibleApplicationInvocationTargetException extends TangibleApplication {
/**
* {@inheritDoc}
* Constructor initialising several basic properties.
*
* @param newPropertiesFileURI
* The URI of the properties file to load.
* @throws Exception
*/
@Override
public void defineWidgets() throws BuildException {
throw new BuildException("No widgets to build in this mock!"); //$NON-NLS-1$
protected TestTangibleApplicationInvocationTargetException(String newPropertiesFileURI) {
super(newPropertiesFileURI);
try {
adapter = new TestFakeAdapter(null);
} catch (InvocationTargetException e) {
logger.log(Level.SEVERE, "An exception has been thrown in the constructor of the adapter"); //$NON-NLS-1$
System.exit(42);
}
}
}
/**
* Class implementing the abstract {@link TangibleObjectManager} for test purposes.
*
* @author Eric TOBIAS [eric.tobias@tudor.lu]
* @since 13 Mar 2014
* @author Nicolas GILMARD [nicolas.gilmard@list.lu]
* @since 11/05/2015
* @version 1
*/
public class TestTuioConcreteAdapter extends TuiAdapter {
public class TestFakeAdapter extends TuiAdapter {
/**
* Default constructor.
*
* @param interfaceManager
* The {@link TangibleInterfaceManager} responsible for refreshing the interface.
* @throws InvocationTargetException
*/
public TestTuioConcreteAdapter(TangibleInterfaceManager interfaceManager) {
public TestFakeAdapter(TangibleInterfaceManager interfaceManager) throws InvocationTargetException {
super(interfaceManager);
throw new InvocationTargetException(null);
}
@Override
public void connect() {
// TODO Auto-generated method stub
// unnecessary
}
@Override
public void disconnect() {
// TODO Auto-generated method stub
// unnecessary
}
@Override
public TangibleObjectManager getObjectManager() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setObjectManager(TangibleObjectManager objectManager) {
// TODO Auto-generated method stub
// unnecessary
}
@Override
public Collection<TangibleObject> getActiveCursors() {
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<TangibleObject> getActiveObjects() {
// TODO Auto-generated method stub
return null;
}
@Override
public TangibleObject getCursor(long id) {
// TODO Auto-generated method stub
return null;
}
@Override
public TangibleObject getObject(long id) {
// TODO Auto-generated method stub
return null;
}
......@@ -304,4 +299,5 @@ public class TangibleApplicationTest2 {
* BuildException("No widgets to build in this mock!"); }
*/
}
}
\ No newline at end of file
<?xml version="1.0" encoding="windows-1252" standalone="no"?>
<!DOCTYPE log SYSTEM "logger.dtd">
<log>
</log>
<?xml version="1.0" encoding="windows-1252" standalone="no"?>
<!DOCTYPE log SYSTEM "logger.dtd">
<log>
</log>
<?xml version="1.0" encoding="windows-1252" standalone="no"?>
<!DOCTYPE log SYSTEM "logger.dtd">
<log>
<record>
<date>2015-05-04T14:10:36</date>
<millis>1430741436587</millis>
<date>2015-05-11T15:11:19</date>
<millis>1431349879911</millis>
<sequence>0</sequence>
<logger>TangibleApplication</logger>
<level>SEVERE</level>
<class>lu.list.itis.dkd.tui.TangibleApplication</class>
<method>&lt;init&gt;</method>
<thread>1</thread>
<message>The class tuio was not found. Check the spelling !</message>
<message>Cannot instantiate adapter. You try to instantiate an abstract class or an interface!</message>
</record>
<record>
<date>2015-05-04T14:10:42</date>
<millis>1430741442122</millis>
<date>2015-05-11T15:11:19</date>
<millis>1431349879939</millis>
<sequence>1</sequence>
<logger>TangibleApplication</logger>
<level>CONFIG</level>
<class>lu.list.itis.dkd.tui.TangibleInterfaceManager$TUIKeyAdapter</class>
<method>keyPressed</method>
<thread>15</thread>
<message>The keypress could not be associated to a case!</message>
<level>SEVERE</level>
<class>lu.list.itis.dkd.tui.TangibleApplication</class>
<method>&lt;init&gt;</method>
<thread>1</thread>
<message>The class lu.list.itis.dkd.tui.adapter.TuAdapter was not found. Check the spelling !</message>
</record>
<record>
<date>2015-05-04T14:10:42</date>
<millis>1430741442273</millis>
<date>2015-05-11T15:11:20</date>
<millis>1431349880041</millis>
<sequence>2</sequence>
<logger>TangibleApplication</logger>
<level>CONFIG</level>
<class>lu.list.itis.dkd.tui.TangibleInterfaceManager$TUIKeyAdapter</class>
<method>keyPressed</method>
<thread>15</thread>
<message>The keypress could not be associated to a case!</message>
<level>SEVERE</level>
<class>lu.list.itis.dkd.tui.TangibleApplicationTest2$TestTangibleApplicationNoSuchMethod</class>
<method>&lt;init&gt;</method>
<thread>1</thread>
<message>The called method was not found</message>
</record>
<record>
<date>2015-05-04T14:10:50</date>
<millis>1430741450625</millis>
<date>2015-05-11T15:11:20</date>
<millis>1431349880091</millis>
<sequence>3</sequence>
<logger>TangibleApplication</logger>
<level>CONFIG</level>
<class>lu.list.itis.dkd.tui.TangibleInterfaceManager$TUIKeyAdapter</class>
<method>keyPressed</method>
<thread>15</thread>
<message>The keypress could not be associated to a case!</message>
<level>SEVERE</level>
<class>lu.list.itis.dkd.tui.TangibleApplicationTest2$TestTangibleApplicationIllegalArgument</class>
<method>&lt;init&gt;</method>
<thread>1</thread>
<message>A wrong argument has been passed to the adapter.</message>
</record>
<record>
<date>2015-05-04T14:10:50</date>
<millis>1430741450833</millis>
<date>2015-05-11T15:11:20</date>
<millis>1431349880121</millis>
<sequence>4</sequence>
<logger>TangibleApplication</logger>
<level>CONFIG</level>
<class>lu.list.itis.dkd.tui.TangibleInterfaceManager$TUIKeyAdapter</class>
<method>keyPressed</method>
<thread>15</thread>
<message>The keypress could not be associated to a case!</message>
<level>SEVERE</level>
<class>lu.list.itis.dkd.tui.TangibleApplicationTest2$TestTangibleApplicationInvocationTargetException</class>
<method>&lt;init&gt;</method>
<thread>1</thread>
<message>An exception has been thrown in the constructor of the adapter</message>
</record>
<?xml version="1.0" encoding="windows-1252" standalone="no"?>
<!DOCTYPE log SYSTEM "logger.dtd">
<log>
<record>
<date>2015-05-11T15:13:12</date>
<millis>1431349992725</millis>
<sequence>1</sequence>
<logger>TangibleApplication</logger>
<level>SEVERE</level>
<class>lu.list.itis.dkd.tui.TangibleApplication</class>
<method>&lt;init&gt;</method>
<thread>1</thread>
<message>The class lu.list.itis.dkd.tui.adapter.TuAdapter was not found. Check the spelling !</message>
</record>
<record>
<date>2015-05-11T15:13:12</date>
<millis>1431349992786</millis>
<sequence>2</sequence>
<logger>TangibleApplication</logger>
<level>SEVERE</level>
<class>lu.list.itis.dkd.tui.TangibleApplicationTest2$TestTangibleApplicationNoSuchMethod</class>
<method>&lt;init&gt;</method>
<thread>1</thread>
<message>The called method was not found</message>
</record>
<record>
<date>2015-05-11T15:13:12</date>
<millis>1431349992825</millis>
<sequence>3</sequence>
<logger>TangibleApplication</logger>
<level>SEVERE</level>
<class>lu.list.itis.dkd.tui.TangibleApplicationTest2$TestTangibleApplicationIllegalArgument</class>
<method>&lt;init&gt;</method>
<thread>1</thread>