Commit fd51f3b4 authored by Nicolas Gilmard's avatar Nicolas Gilmard
Browse files

Complete JUnit test for the adapter loading

parent 5ce6383e
...@@ -128,7 +128,7 @@ public class TuioAdapter extends TuiAdapter implements TuioListener { ...@@ -128,7 +128,7 @@ public class TuioAdapter extends TuiAdapter implements TuioListener {
private TangibleObject convertTuioObjectToTangibleObject(TuioObject tuioObject) { private TangibleObject convertTuioObjectToTangibleObject(TuioObject tuioObject) {
Preconditions.checkArgument(tuioObject != null, "The passed tangible cursor cannot be null!"); //$NON-NLS-1$ Preconditions.checkArgument(tuioObject != null, "The passed tangible cursor cannot be null!"); //$NON-NLS-1$
// get the object if present // 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; TangibleObject convertedTangibleObject;
if (updateObject == null) { if (updateObject == null) {
// if the object is not present simply convert the tuioPath // if the object is not present simply convert the tuioPath
...@@ -177,13 +177,26 @@ public class TuioAdapter extends TuiAdapter implements TuioListener { ...@@ -177,13 +177,26 @@ public class TuioAdapter extends TuiAdapter implements TuioListener {
*/ */
private TangibleObject convertTuioBlobToTangibleObject(TuioBlob tuioBlob) { private TangibleObject convertTuioBlobToTangibleObject(TuioBlob tuioBlob) {
Preconditions.checkArgument(tuioBlob != null, "The passed tangible cursor cannot be null!"); //$NON-NLS-1$ 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<>(); } else {
tuioBlob.getPath().forEach(path -> tempPath.add(new Point(path.getX(), path.getY(), tuioBlob.getAngle()))); // if the object is present in the list, get previous path and add the last point
// !!! MAPPING ID !!!!!!!!!!! ArrayList<Point> tempPath = new ArrayList<>();
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(); 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; return convertedTangibleObject;
} }
/** /**
...@@ -223,6 +236,7 @@ public class TuioAdapter extends TuiAdapter implements TuioListener { ...@@ -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$ Preconditions.checkArgument(tangibleObject != null, "The passed tangible object cannot be null!"); //$NON-NLS-1$
TangibleObject convertedTangibleObject = convertTuioBlobToTangibleObject(tangibleObject); TangibleObject convertedTangibleObject = convertTuioBlobToTangibleObject(tangibleObject);
tangibleObjectList.put(convertedTangibleObject.getObjectId(), convertedTangibleObject);
super.addObjInfo(convertedTangibleObject, "down"); //$NON-NLS-1$ super.addObjInfo(convertedTangibleObject, "down"); //$NON-NLS-1$
...@@ -271,9 +285,14 @@ public class TuioAdapter extends TuiAdapter implements TuioListener { ...@@ -271,9 +285,14 @@ public class TuioAdapter extends TuiAdapter implements TuioListener {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void removeTuioBlob(TuioBlob arg0) { public void removeTuioBlob(TuioBlob tuioBlob) {
// TODO Auto-generated method stub 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 { ...@@ -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$ Preconditions.checkArgument(tangibleCursor != null, "The passed tangible cursor cannot be null!"); //$NON-NLS-1$
TangibleObject convertedTangibleObject = convertTuioCursorToTangibleObject(tangibleCursor); TangibleObject convertedTangibleObject = convertTuioCursorToTangibleObject(tangibleCursor);
super.addCurInfo(convertedTangibleObject, "move"); //$NON-NLS-1$ super.addCurInfo(convertedTangibleObject, "move"); //$NON-NLS-1$
objectManager.updateObject(convertedTangibleObject); objectManager.updateObject(convertedTangibleObject);
...@@ -300,6 +318,7 @@ public class TuioAdapter extends TuiAdapter implements TuioListener { ...@@ -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$ Preconditions.checkArgument(tangibleObject != null, "The passed tangible object cannot be null!"); //$NON-NLS-1$
TangibleObject convertedTangibleObject = convertTuioObjectToTangibleObject(tangibleObject); TangibleObject convertedTangibleObject = convertTuioObjectToTangibleObject(tangibleObject);
// convertedTangibleObject.getPath().forEach(path -> System.out.println(path.getAngle()));
super.addObjInfo(convertedTangibleObject, "move"); //$NON-NLS-1$ super.addObjInfo(convertedTangibleObject, "move"); //$NON-NLS-1$
objectManager.updateObject(convertedTangibleObject); objectManager.updateObject(convertedTangibleObject);
...@@ -308,9 +327,13 @@ public class TuioAdapter extends TuiAdapter implements TuioListener { ...@@ -308,9 +327,13 @@ public class TuioAdapter extends TuiAdapter implements TuioListener {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void updateTuioBlob(TuioBlob arg0) { public void updateTuioBlob(TuioBlob tuioBlob) {
// TODO Auto-generated method stub 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 { ...@@ -41,6 +41,4 @@ public class ExitDeniedSecurityManager extends SecurityManager {
@Override @Override
public void checkPermission(final Permission perm) {} 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; ...@@ -19,21 +19,16 @@ import static org.junit.Assert.fail;
import lu.list.itis.dkd.tui.ExitDeniedSecurityManager.ExitSecurityException; import lu.list.itis.dkd.tui.ExitDeniedSecurityManager.ExitSecurityException;
import lu.list.itis.dkd.tui.adapter.TangibleObject; import lu.list.itis.dkd.tui.adapter.TangibleObject;
import lu.list.itis.dkd.tui.adapter.TuiAdapter; 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.Before;
import org.junit.Test; import org.junit.Test;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Logger; import java.util.logging.Level;
/** /**
* Test case for testing the {@link TangibleApplication} class. * Test case for testing the {@link TangibleApplication} class.
...@@ -64,16 +59,16 @@ public class TangibleApplicationTest2 { ...@@ -64,16 +59,16 @@ public class TangibleApplicationTest2 {
@Test @Test
public void testTangibleApplication() throws Exception { public void testTangibleApplication() throws Exception {
FileInputStream in = new FileInputStream(propertiesLocation); FileInputStream inputStream = new FileInputStream(propertiesLocation);
Properties props = new Properties(); Properties props = new Properties();
props.load(in); props.load(inputStream);
FileOutputStream out = new FileOutputStream(propertiesLocation); FileOutputStream outputStream = new FileOutputStream(propertiesLocation);
// InstanciationException // InstanciationException
props.setProperty("tableAdapter", "lu.list.itis.dkd.tui.adapter.TuiAdapter"); //$NON-NLS-1$ //$NON-NLS-2$ 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 { try {
application = new TestTangibleApplication(propertiesLocation); application = new TestTangibleApplication(propertiesLocation);
...@@ -84,9 +79,9 @@ public class TangibleApplicationTest2 { ...@@ -84,9 +79,9 @@ public class TangibleApplicationTest2 {
} }
// ClassNotFoundException // ClassNotFoundException
props.load(in); props.load(inputStream);
props.setProperty("tableAdapter", "lu.list.itis.dkd.tui.adapter.TuAdapter"); //$NON-NLS-1$ //$NON-NLS-2$ 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 { try {
...@@ -98,56 +93,44 @@ public class TangibleApplicationTest2 { ...@@ -98,56 +93,44 @@ public class TangibleApplicationTest2 {
assertEquals(42, status); 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); application = new TestTangibleApplicationNoSuchMethod(propertiesLocation);
// 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();
}
fail("Expected exit"); //$NON-NLS-1$
} catch (ExitSecurityException e) {
int status = e.getStatus();
assertEquals(42, status);
}
/** // IllegalArgumentException
* Test method for {@link lu.list.itis.dkd.tui.TangibleApplication#connect()}. try {
*/
public void testConnect() {
fail("Method not implemented in mock!"); //$NON-NLS-1$
}
/** application = new TestTangibleApplicationIllegalArgument(propertiesLocation);
* Test method for {@link lu.list.itis.dkd.tui.TangibleApplication#getInterfaceManager()}.
*/ fail("Expected exit"); //$NON-NLS-1$
public void testGetInterfaceManager() { } catch (ExitSecurityException e) {
fail("Method not implemented in mock!"); //$NON-NLS-1$ int status = e.getStatus();
} assertEquals(42, status);
}
// InvocationTargetException
try {
/** application = new TestTangibleApplicationInvocationTargetException(propertiesLocation);
* 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$
}
fail("Expected exit"); //$NON-NLS-1$
} catch (ExitSecurityException e) {
int status = e.getStatus();
assertEquals(42, status);
}
/** inputStream.close();
* Test method for {@link lu.list.itis.dkd.tui.TangibleApplication#getContentManager()} and outputStream.close();
* {@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$
} }
/** /**
...@@ -171,128 +154,140 @@ public class TangibleApplicationTest2 { ...@@ -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] * @author Nicolas GILMARD [nicolas.gilmard@list.lu]
* @since 1.0 * @since 11/05/2015
* @version 1.0.2 * @version 1
*/ */
@NonNullByDefault public class TestTangibleApplicationNoSuchMethod extends TangibleApplication {
public class TestTangibleContentManager extends TangibleContentManager {
/**
* {@inheritDoc}
*/
@Override
public void contentUpdated(ContentEvent event) {
fail("Method not implemented in mock!"); //$NON-NLS-1$
}
/** /**
* {@inheritDoc} * Constructor initialising several basic properties.
*
* @param newPropertiesFileURI
* The URI of the properties file to load.
* @throws Exception
*/ */
@Override protected TestTangibleApplicationNoSuchMethod(String newPropertiesFileURI) throws Exception {
public Collection<Content> getDrawableContents() { super(newPropertiesFileURI);
fail("Method not implemented in mock!"); //$NON-NLS-1$ try {
return new HashSet<Content>(); 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] * @author Nicolas GILMARD [nicolas.gilmard@list.lu]
* @since 13 Mar 2014 * @since 11/05/2015
* @version 1 * @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 * @param newPropertiesFileURI
* The {@link TangibleApplication} hosting this manager. * The URI of the properties file to load.
* @param applicationLogger * @throws Exception
* The {@link Logger} to use for all logging purposes.
* @param properties
* The properties instance from which to load the default values from.
*/ */
@NonNullByDefault protected TestTangibleApplicationIllegalArgument(String newPropertiesFileURI) throws Exception {
public TestTangibleObjectManager(TangibleApplication applicationContext, Logger applicationLogger, Properties properties) { super(newPropertiesFileURI);
super(applicationContext, applicationLogger, properties); 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 protected TestTangibleApplicationInvocationTargetException(String newPropertiesFileURI) {
public void defineWidgets() throws BuildException { super(newPropertiesFileURI);
throw new BuildException("No widgets to build in this mock!"); //$NON-NLS-1$ 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. * Class implementing the abstract {@link TangibleObjectManager} for test purposes.
* *
* @author Eric TOBIAS [eric.tobias@tudor.lu] * @author Nicolas GILMARD [nicolas.gilmard@list.lu]
* @since 13 Mar 2014 * @since 11/05/2015
* @version 1 * @version 1
*/ */
public class TestTuioConcreteAdapter extends TuiAdapter { public class TestFakeAdapter extends TuiAdapter {
/** /**
* Default constructor. * Default constructor.
* *
* @param interfaceManager * @param interfaceManager
* The {@link TangibleInterfaceManager} responsible for refreshing the interface. * The {@link TangibleInterfaceManager} responsible for refreshing the interface.
* @throws InvocationTargetException
*/ */
public TestTuioConcreteAdapter(TangibleInterfaceManager interfaceManager) { public TestFakeAdapter(TangibleInterfaceManager interfaceManager) throws InvocationTargetException {
super(interfaceManager); super(interfaceManager);
throw new InvocationTargetException(null);
} }
@Override @Override
public void connect() { public void connect() {
// TODO Auto-generated method stub // unnecessary
} }
@Override @Override
public void disconnect() { public void disconnect() {
// TODO Auto-generated method stub // unnecessary
} }
@Override @Override
public TangibleObjectManager getObjectManager() { public TangibleObjectManager getObjectManager() {
// TODO Auto-generated method stub
return null; return null;
} }
@Override @Override
public void setObjectManager(TangibleObjectManager objectManager) { public void setObjectManager(TangibleObjectManager objectManager) {
// TODO Auto-generated method stub // unnecessary
} }
@Override @Override
public Collection<TangibleObject> getActiveCursors() { public Collection<TangibleObject> getActiveCursors() {
// TODO Auto-generated method stub
return null; return null;
} }
@Override @Override
public Collection<TangibleObject> getActiveObjects() { public Collection<TangibleObject> getActiveObjects() {
// TODO Auto-generated method stub
return null; return null;
} }
@Override @Override
public TangibleObject getCursor(long id) { public TangibleObject getCursor(long id) {
// TODO Auto-generated method stub
return null; return null;
} }
@Override @Override
public TangibleObject getObject(long id) { public TangibleObject getObject(long id) {
// TODO Auto-generated method stub
return null; return null;
} }
...@@ -304,4 +299,5 @@ public class TangibleApplicationTest2 { ...@@ -304,4 +299,5 @@ public class TangibleApplicationTest2 {
* BuildException("No widgets to build in this mock!"); } * BuildException("No widgets to build in this mock!"); }
*/ */
} }
} }
\ No newline at end of file
<?xml version="1.0" encoding="windows-1252" standalone="no"?> <?xml version="1.0" encoding="windows-1252" standalone="no"?>
<!DOCTYPE log SYSTEM "logger.dtd"> <!DOCTYPE log SYSTEM "logger.dtd">
<log> <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">