# HG changeset patch # User Elliott Baron # Date 1361832576 18000 # Node ID 0d9534310a175f5997924c331435bff19e21ab94 # Parent db2b89cdef62743cf59a78ca14c51f939ae71ab6 Use bundle version in SystemBackend I have noticed that SystemBackend is reporting 0.5.0 as its version number. It turns out this is still using a hard-coded version string, while the other Backends use the version of their containing bundle. This commit changes SystemBackend to use the bundle version and includes a test for this as well. Reviewed-by: omajid Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-February/005850.html diff -r db2b89cdef62 -r 0d9534310a17 system-backend/src/main/java/com/redhat/thermostat/backend/system/SystemBackend.java --- a/system-backend/src/main/java/com/redhat/thermostat/backend/system/SystemBackend.java Fri Feb 22 16:53:10 2013 +0100 +++ b/system-backend/src/main/java/com/redhat/thermostat/backend/system/SystemBackend.java Mon Feb 25 17:49:36 2013 -0500 @@ -47,6 +47,7 @@ import sun.jvmstat.monitor.MonitoredHost; import com.redhat.thermostat.backend.BaseBackend; +import com.redhat.thermostat.common.Version; import com.redhat.thermostat.common.utils.LoggingUtils; import com.redhat.thermostat.storage.dao.HostInfoDAO; import com.redhat.thermostat.storage.dao.NetworkInterfaceInfoDAO; @@ -72,11 +73,12 @@ private final HostInfoBuilder hostInfoBuilder; - public SystemBackend(HostInfoDAO hostInfoDAO, NetworkInterfaceInfoDAO netInfoDAO, VmInfoDAO vmInfoDAO, VmStatusChangeNotifier notifier) { + public SystemBackend(HostInfoDAO hostInfoDAO, NetworkInterfaceInfoDAO netInfoDAO, VmInfoDAO vmInfoDAO, + Version version, VmStatusChangeNotifier notifier) { super("System Backend", "Gathers basic information from the system", "Red Hat, Inc.", - "0.5.0", true); + version.getVersionNumber(), true); this.hostInfos = hostInfoDAO; this.networkInterfaces = netInfoDAO; diff -r db2b89cdef62 -r 0d9534310a17 system-backend/src/main/java/com/redhat/thermostat/backend/system/osgi/SystemBackendActivator.java --- a/system-backend/src/main/java/com/redhat/thermostat/backend/system/osgi/SystemBackendActivator.java Fri Feb 22 16:53:10 2013 +0100 +++ b/system-backend/src/main/java/com/redhat/thermostat/backend/system/osgi/SystemBackendActivator.java Mon Feb 25 17:49:36 2013 -0500 @@ -48,6 +48,7 @@ import com.redhat.thermostat.backend.system.VmStatusChangeNotifier; import com.redhat.thermostat.common.MultipleServiceTracker; import com.redhat.thermostat.common.MultipleServiceTracker.Action; +import com.redhat.thermostat.common.Version; import com.redhat.thermostat.storage.dao.HostInfoDAO; import com.redhat.thermostat.storage.dao.NetworkInterfaceInfoDAO; import com.redhat.thermostat.storage.dao.VmInfoDAO; @@ -79,7 +80,8 @@ NetworkInterfaceInfoDAO netInfoDAO = (NetworkInterfaceInfoDAO) services .get(NetworkInterfaceInfoDAO.class.getName()); VmInfoDAO vmInfoDAO = (VmInfoDAO) services.get(VmInfoDAO.class.getName()); - backend = new SystemBackend(hostInfoDAO, netInfoDAO, vmInfoDAO, notifier); + Version version = new Version(context.getBundle()); + backend = new SystemBackend(hostInfoDAO, netInfoDAO, vmInfoDAO, version, notifier); reg = context.registerService(Backend.class, backend, null); } diff -r db2b89cdef62 -r 0d9534310a17 system-backend/src/test/java/com/redhat/thermostat/backend/system/SystemBackendTest.java --- a/system-backend/src/test/java/com/redhat/thermostat/backend/system/SystemBackendTest.java Fri Feb 22 16:53:10 2013 +0100 +++ b/system-backend/src/test/java/com/redhat/thermostat/backend/system/SystemBackendTest.java Mon Feb 25 17:49:36 2013 -0500 @@ -36,19 +36,23 @@ package com.redhat.thermostat.backend.system; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import org.junit.Before; import org.junit.Test; +import com.redhat.thermostat.common.Version; import com.redhat.thermostat.storage.dao.HostInfoDAO; import com.redhat.thermostat.storage.dao.NetworkInterfaceInfoDAO; import com.redhat.thermostat.storage.dao.VmInfoDAO; public class SystemBackendTest { + private static final String VERSION = "0.0.0"; private SystemBackend b; @Before @@ -57,9 +61,12 @@ NetworkInterfaceInfoDAO nDAO = mock(NetworkInterfaceInfoDAO.class); VmInfoDAO vmInfoDAO = mock(VmInfoDAO.class); + Version version = mock(Version.class); + when(version.getVersionNumber()).thenReturn(VERSION); + VmStatusChangeNotifier notifier = mock(VmStatusChangeNotifier.class); - b = new SystemBackend(hDAO, nDAO, vmInfoDAO, notifier); + b = new SystemBackend(hDAO, nDAO, vmInfoDAO, version, notifier); } @Test @@ -84,6 +91,11 @@ b.deactivate(); assertFalse(b.isActive()); } + + @Test + public void testVersion() { + assertEquals(VERSION, b.getVersion()); + } }