Commit a9625ba8 authored by Eric Tobias's avatar Eric Tobias

Added simple test for adapter reflexive instantiation. Bugfix in EventLogger regarding spam.

+ Added a simple test to see whether the adapter is reflexively instantiated by issuing connect and disconnect calls.
+ Added the disconnect method to the application. The methods were present in the adapter and addint it only seemed consistent.
~ Changed a few lines of the EventLogger to prevent it from spamming empty files when logging was disabled.
parent e94b3952
......@@ -45,7 +45,7 @@ import javax.swing.JComponent;
*
* @author Eric TOBIAS [eric.tobias@list.lu]
* @since 1.0
* @version 1.0.2
* @version 2.0.3
*/
@NonNullByDefault
public abstract class TangibleApplication {
......@@ -101,12 +101,10 @@ public abstract class TangibleApplication {
}
configureLogger(logger);
interfaceManager = new TangibleInterfaceManager(this, logger, properties);
try {
adapter = (TuiAdapter) Class.forName(properties.getProperty("adapter.class")).getConstructor(TangibleInterfaceManager.class).newInstance(interfaceManager); //$NON-NLS-1$
} catch (InstantiationException e) {
logger.log(Level.SEVERE, "Cannot instantiate adapter. The adapter must be a concrete class, not an interface or abstract class and it must directly inherit from TuiAdapter! Check your properties file and set adapter.class accordingly."); //$NON-NLS-1$s
System.exit(42);
......@@ -131,7 +129,6 @@ public abstract class TangibleApplication {
}
GlobalContext.setGlobalContext(adapter);
IDMapper.initialise(properties);
EventLogger.getInstance().initialise(properties);
}
......@@ -140,9 +137,9 @@ public abstract class TangibleApplication {
* Method for configuring a {@link Logger} with several properties as given by the loader
* properties file.
*
* @pre logger != null
* @param unconfiguredLogger
* The {@link Logger} instance to configure.
* @pre logger != null
*/
public static void configureLogger(final Logger unconfiguredLogger) {
Preconditions.checkArgument(unconfiguredLogger != null, "The provider logger must not be null!"); //$NON-NLS-1$
......@@ -159,14 +156,27 @@ public abstract class TangibleApplication {
/**
* Method used to connect the application to the NUI device sending out events for the listener
* to capture.
* to capture. Before this method can be evoked successfully, the {@link TangibleObjectManager}
* needs to be set.
*
* @pre objectManager != <code>null</code>
*
* @pre objectManager != null
* @see #setObjectManager(TangibleObjectManager)
*/
public void connect() {
adapter.connect();
}
/**
* Method used to disconnect the application from the NUI device sending out events for the
* listener to capture.
*
* @pre objectManager != <code>null</code>
*/
public void disconnect() {
adapter.disconnect();
}
/**
* Simple getter method for interfaceManager.
*
......@@ -204,6 +214,7 @@ public abstract class TangibleApplication {
*/
public void setObjectManager(TangibleObjectManager objectManager) {
this.objectManager = objectManager;
adapter.setObjectManager(objectManager);
}
/**
......
......@@ -66,6 +66,8 @@ public abstract class TangibleContentManager implements ContentEventListener {
* Method to sort all content by the functionality it offers as given by a parent class or
* interface.
*
* TODO DESIGN This method is not scalable. It needs to be redesigned.
*
* @param desiredParent
* The class that all content we filter by should implement or extend.
* @return A {@link ConcurrentHashMap} of content that implements the desired interface or
......@@ -91,7 +93,6 @@ public abstract class TangibleContentManager implements ContentEventListener {
}
}
return implementingContent;
}
......
......@@ -262,7 +262,7 @@ public class TangibleInterfaceManager extends JComponent {
}
/**
* The method draws the application. {@inheritDoc}
* This method draws the application. {@inheritDoc}
*
* @pre canvas != null
*/
......
......@@ -37,16 +37,16 @@ import java.util.logging.Logger;
*/
@NonNullByDefault
public class EventLogger {
private static final EventLogger INSTANCE = new EventLogger();
private static final EventLogger INSTANCE = new EventLogger();
@SuppressWarnings("null")
private static final Logger EVENTLOGGER = Logger.getLogger(EventLogger.class.getName());
private boolean enabled;
private FileHandler file_handler = null;
private int[][] config_fid = null;
private int[][] config_fid_t = null;
private int[] config_cur = null;
private Vector<String> config_coronas = new Vector<String>();
private Vector<String> config_var_app = new Vector<String>();
private static final Logger EVENTLOGGER = Logger.getLogger(EventLogger.class.getName());
private boolean enabled;
private FileHandler file_handler = null;
private int[][] config_fid = null;
private int[][] config_fid_t = null;
private int[] config_cur = null;
private Vector<String> config_coronas = new Vector<String>();
private Vector<String> config_var_app = new Vector<String>();
/**
* Private constructor to enforce Singleton pattern.
......@@ -357,9 +357,11 @@ public class EventLogger {
*/
public void initialise(Properties properties) {
try {
setLogFilename(properties.getProperty("logger.event.output.location"));
enabled = Boolean.parseBoolean(properties.getProperty("logger.event.output.enabled"));
readSettings(properties.getProperty("logger.event.configuration"));
if (enabled) {
setLogFilename(properties.getProperty("logger.event.output.location"));
readSettings(properties.getProperty("logger.event.configuration"));
}
} catch (SecurityException | IOException | JDOMException e) {
Logger.getLogger(EventLogger.class.getSimpleName()).log(Level.SEVERE, "Configuration of the TULIP logger failed! Logging will be disabled!", e);
}
......
......@@ -105,7 +105,7 @@ public class TangibleApplicationTest {
logger.setAccessible(true);
assertThat(logger.get(application), is(not(nullValue())));
assertEquals(Level.FINE, ((Logger) logger.get(application)).getLevel());
assertEquals(1, ((Logger) logger.get(application)).getHandlers().length);
assertEquals(0, ((Logger) logger.get(application)).getHandlers().length);
objectManager.setAccessible(true);
assertEquals(null, objectManager.get(application));
interfaceManager.setAccessible(true);
......@@ -118,10 +118,11 @@ public class TangibleApplicationTest {
}
/**
* Test method for {@link lu.list.itis.dkd.tui.TangibleApplication#connect()}.
* Test method for {@link lu.list.itis.dkd.tui.TangibleApplication#connect()} when the object
* manager is not correctly set.
*/
@Test
public void testConnect() {
public void testConnect_exception() {
try {
application.connect();
fail("As no adapter is specified, the connect() call should throw an exception!"); //$NON-NLS-1$
......@@ -130,6 +131,18 @@ public class TangibleApplicationTest {
}
}
/**
* Test method for {@link TangibleApplication#connect()} without exception.
*/
@Test
public void testConnect() {
TestTangibleObjectManager testManager = new TestTangibleObjectManager(application, TangibleApplication.logger, TangibleApplication.properties);
application.setObjectManager(testManager);
application.connect();
// TODO It might be interesting to add checks for isConnected() on the TuiAdapter level.
}
/**
* Test method for {@link lu.list.itis.dkd.tui.TangibleApplication#getInterfaceManager()}.
*/
......
......@@ -18,8 +18,7 @@ infoTimerFreq=600
centeredLuxembourg=false
font=Arial
splitWidgetID=22
logger.event.output.enabled=true
tableAdapter=lu.list.itis.dkd.tui.adapter.TuiAdapter
logger.event.output.enabled=false
calibrationMode=false
legendScale=0.8
centred=false
......
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