Mercurial > hg > release > thermostat-0.15
changeset 243:f51208ae449a
hide vm controllers
review-by: omajid
review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-April/000922.html
author | Mario Torre <neugens.limasoftware@gmail.com> |
---|---|
date | Wed, 18 Apr 2012 19:48:46 +0200 |
parents | 1c37a952b712 |
children | aac2461e2fa5 |
files | client/src/main/java/com/redhat/thermostat/client/ui/VmClassStatController.java client/src/main/java/com/redhat/thermostat/client/ui/VmCpuController.java client/src/main/java/com/redhat/thermostat/client/ui/VmGcController.java client/src/main/java/com/redhat/thermostat/client/ui/VmMemoryController.java client/src/main/java/com/redhat/thermostat/client/ui/VmOverviewController.java client/src/test/java/com/redhat/thermostat/client/VmClassStatControllerTest.java client/src/test/java/com/redhat/thermostat/client/ui/VmClassStatControllerTest.java |
diffstat | 7 files changed, 106 insertions(+), 107 deletions(-) [+] |
line wrap: on
line diff
--- a/client/src/main/java/com/redhat/thermostat/client/ui/VmClassStatController.java Wed Apr 18 11:54:25 2012 -0400 +++ b/client/src/main/java/com/redhat/thermostat/client/ui/VmClassStatController.java Wed Apr 18 19:48:46 2012 +0200 @@ -50,7 +50,7 @@ import com.redhat.thermostat.common.model.DiscreteTimeData; import com.redhat.thermostat.common.model.VmClassStat; -public class VmClassStatController implements AsyncUiFacade { +class VmClassStatController implements AsyncUiFacade { private class UpdateChartData extends TimerTask { @Override
--- a/client/src/main/java/com/redhat/thermostat/client/ui/VmCpuController.java Wed Apr 18 11:54:25 2012 -0400 +++ b/client/src/main/java/com/redhat/thermostat/client/ui/VmCpuController.java Wed Apr 18 19:48:46 2012 +0200 @@ -50,7 +50,7 @@ import com.redhat.thermostat.common.model.DiscreteTimeData; import com.redhat.thermostat.common.model.VmCpuStat; -public class VmCpuController implements AsyncUiFacade { +class VmCpuController implements AsyncUiFacade { private final VmRef ref; private final VmCpuStatDAO dao; @@ -64,7 +64,6 @@ view = ApplicationContext.getInstance().getViewFactory().getView(VmCpuView.class); } - @Override public void start() { timer.scheduleAtFixedRate(new TimerTask() {
--- a/client/src/main/java/com/redhat/thermostat/client/ui/VmGcController.java Wed Apr 18 11:54:25 2012 -0400 +++ b/client/src/main/java/com/redhat/thermostat/client/ui/VmGcController.java Wed Apr 18 19:48:46 2012 +0200 @@ -61,7 +61,7 @@ import com.redhat.thermostat.common.model.VmMemoryStat; import com.redhat.thermostat.common.model.VmMemoryStat.Generation; -public class VmGcController implements AsyncUiFacade { +class VmGcController implements AsyncUiFacade { private final VmRef ref; private final VmGcView view;
--- a/client/src/main/java/com/redhat/thermostat/client/ui/VmMemoryController.java Wed Apr 18 11:54:25 2012 -0400 +++ b/client/src/main/java/com/redhat/thermostat/client/ui/VmMemoryController.java Wed Apr 18 19:48:46 2012 +0200 @@ -50,7 +50,7 @@ import com.redhat.thermostat.common.model.VmMemoryStat.Generation; import com.redhat.thermostat.common.model.VmMemoryStat.Space; -public class VmMemoryController implements AsyncUiFacade { +class VmMemoryController implements AsyncUiFacade { private final VmRef ref; private final VmMemoryView view;
--- a/client/src/main/java/com/redhat/thermostat/client/ui/VmOverviewController.java Wed Apr 18 11:54:25 2012 -0400 +++ b/client/src/main/java/com/redhat/thermostat/client/ui/VmOverviewController.java Wed Apr 18 19:48:46 2012 +0200 @@ -52,7 +52,7 @@ import com.redhat.thermostat.common.dao.VmRef; import com.redhat.thermostat.common.model.VmInfo; -public class VmOverviewController implements AsyncUiFacade { +class VmOverviewController implements AsyncUiFacade { private final VmRef ref; private final VmInfoDAO dao;
--- a/client/src/test/java/com/redhat/thermostat/client/VmClassStatControllerTest.java Wed Apr 18 11:54:25 2012 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,101 +0,0 @@ -/* - * Copyright 2012 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat 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 - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.client; - -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.atLeast; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Test; - -import com.redhat.thermostat.client.ui.VmClassStatController; -import com.redhat.thermostat.client.ui.VmClassStatView; -import com.redhat.thermostat.common.ViewFactory; -import com.redhat.thermostat.common.appctx.ApplicationContext; -import com.redhat.thermostat.common.dao.DAOFactory; -import com.redhat.thermostat.common.dao.MongoDAOFactory; -import com.redhat.thermostat.common.dao.VmClassStatDAO; -import com.redhat.thermostat.common.dao.VmRef; -import com.redhat.thermostat.common.model.VmClassStat; - -public class VmClassStatControllerTest { - - @SuppressWarnings("unchecked") // any(List.class) - @Test - public void testChartUpdate() { - - VmClassStat stat1 = new VmClassStat(123, 12345, 1234); - List<VmClassStat> stats = new ArrayList<VmClassStat>(); - stats.add(stat1); - - VmClassStatDAO vmClassStatDAO = mock(VmClassStatDAO.class); - when(vmClassStatDAO.getLatestClassStats(any(VmRef.class))).thenReturn(stats).thenReturn(new ArrayList<VmClassStat>()); - - DAOFactory daoFactory = mock(MongoDAOFactory.class); - when(daoFactory.getVmClassStatsDAO()).thenReturn(vmClassStatDAO); - - ApplicationContext.getInstance().setDAOFactory(daoFactory); - VmRef ref = mock(VmRef.class); - - VmClassStatView view = mock(VmClassStatView.class); - ViewFactory viewFactory = mock(ViewFactory.class); - when(viewFactory.getView(eq(VmClassStatView.class))).thenReturn(view); - - ApplicationContext.getInstance().setViewFactory(viewFactory); - - VmClassStatController controller = new VmClassStatController(ref); - - controller.start(); - - try { - Thread.sleep(500); - } catch (InterruptedException e) { - // Get out of here ASAP. - return; - } - - verify(view, atLeast(1)).addClassCount(any(List.class)); - // We don't verify atMost() since we might increase the update rate in the future. - } - -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/src/test/java/com/redhat/thermostat/client/ui/VmClassStatControllerTest.java Wed Apr 18 19:48:46 2012 +0200 @@ -0,0 +1,101 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.client.ui; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.atLeast; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.redhat.thermostat.client.ui.VmClassStatController; +import com.redhat.thermostat.client.ui.VmClassStatView; +import com.redhat.thermostat.common.ViewFactory; +import com.redhat.thermostat.common.appctx.ApplicationContext; +import com.redhat.thermostat.common.dao.DAOFactory; +import com.redhat.thermostat.common.dao.MongoDAOFactory; +import com.redhat.thermostat.common.dao.VmClassStatDAO; +import com.redhat.thermostat.common.dao.VmRef; +import com.redhat.thermostat.common.model.VmClassStat; + +public class VmClassStatControllerTest { + + @SuppressWarnings("unchecked") // any(List.class) + @Test + public void testChartUpdate() { + + VmClassStat stat1 = new VmClassStat(123, 12345, 1234); + List<VmClassStat> stats = new ArrayList<VmClassStat>(); + stats.add(stat1); + + VmClassStatDAO vmClassStatDAO = mock(VmClassStatDAO.class); + when(vmClassStatDAO.getLatestClassStats(any(VmRef.class))).thenReturn(stats).thenReturn(new ArrayList<VmClassStat>()); + + DAOFactory daoFactory = mock(MongoDAOFactory.class); + when(daoFactory.getVmClassStatsDAO()).thenReturn(vmClassStatDAO); + + ApplicationContext.getInstance().setDAOFactory(daoFactory); + VmRef ref = mock(VmRef.class); + + VmClassStatView view = mock(VmClassStatView.class); + ViewFactory viewFactory = mock(ViewFactory.class); + when(viewFactory.getView(eq(VmClassStatView.class))).thenReturn(view); + + ApplicationContext.getInstance().setViewFactory(viewFactory); + + VmClassStatController controller = new VmClassStatController(ref); + + controller.start(); + + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // Get out of here ASAP. + return; + } + + verify(view, atLeast(1)).addClassCount(any(List.class)); + // We don't verify atMost() since we might increase the update rate in the future. + } + +}