# HG changeset patch # User Omair Majid # Date 1348846511 14400 # Node ID 654fc29f96f24f352ecdaee12dfad6066393c11c # Parent 9702e8f0da26b52fcfe44a3fedabd13d5fe0e3b0 PR1180: Agent information dialog throws NPE if no agent is running During initialization, the controller only tries to update the view if it finds a (non-null) agent id. Reviewed-by: jerboaa Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-September/003463.html diff -r 9702e8f0da26 -r 654fc29f96f2 client/core/src/main/java/com/redhat/thermostat/client/locale/LocaleResources.java --- a/client/core/src/main/java/com/redhat/thermostat/client/locale/LocaleResources.java Fri Sep 28 12:29:34 2012 -0400 +++ b/client/core/src/main/java/com/redhat/thermostat/client/locale/LocaleResources.java Fri Sep 28 11:35:11 2012 -0400 @@ -36,11 +36,10 @@ package com.redhat.thermostat.client.locale; -import com.redhat.thermostat.client.ui.ValueField; - public enum LocaleResources { MISSING_INFO, + INFORMATION_NOT_AVAILABLE, COMMAND_GUI_DESCRIPTION, diff -r 9702e8f0da26 -r 654fc29f96f2 client/core/src/main/java/com/redhat/thermostat/client/ui/AgentInformationDisplayController.java --- a/client/core/src/main/java/com/redhat/thermostat/client/ui/AgentInformationDisplayController.java Fri Sep 28 12:29:34 2012 -0400 +++ b/client/core/src/main/java/com/redhat/thermostat/client/ui/AgentInformationDisplayController.java Fri Sep 28 11:35:11 2012 -0400 @@ -78,7 +78,10 @@ view.addAgent(agentName); } view.showDialog(); - updateViewFromModel(agentId); + + if (agentId != null) { + updateViewFromModel(agentId); + } } public void hideView() { diff -r 9702e8f0da26 -r 654fc29f96f2 client/core/src/main/java/com/redhat/thermostat/client/ui/AgentInformationDisplayFrame.java --- a/client/core/src/main/java/com/redhat/thermostat/client/ui/AgentInformationDisplayFrame.java Fri Sep 28 12:29:34 2012 -0400 +++ b/client/core/src/main/java/com/redhat/thermostat/client/ui/AgentInformationDisplayFrame.java Fri Sep 28 11:35:11 2012 -0400 @@ -162,15 +162,17 @@ LabelField agentStartTimeLabel = new LabelField(localize(LocaleResources.AGENT_INFO_AGENT_START_TIME_LABEL)); LabelField agentStopTimeLabel = new LabelField(localize(LocaleResources.AGENT_INFO_AGENT_STOP_TIME_LABEL)); - currentAgentName = new ValueField("${AGENT_NAME}"); + String notAvailable = localize(LocaleResources.INFORMATION_NOT_AVAILABLE); + + currentAgentName = new ValueField(notAvailable); currentAgentName.setName("agentName"); - currentAgentId = new ValueField("${AGENT_ID}"); + currentAgentId = new ValueField(notAvailable); currentAgentId.setName("agentId"); - currentAgentCommandAddress = new ValueField("${AGENT_COMMAND_ADDRESS}"); + currentAgentCommandAddress = new ValueField(notAvailable); currentAgentCommandAddress.setName("commandAddress"); - currentAgentStartTime = new ValueField("${START_TIME}"); + currentAgentStartTime = new ValueField(notAvailable); currentAgentStartTime.setName("startTime"); - currentAgentStopTime = new ValueField("${STOP_TIME}"); + currentAgentStopTime = new ValueField(notAvailable); currentAgentStopTime.setName("stopTime"); SectionHeader backendSectionTitle = new SectionHeader(localize(LocaleResources.AGENT_INFO_BACKENDS_SECTION_TITLE)); @@ -189,7 +191,7 @@ JScrollPane backendsTableScollPane = new JScrollPane(backendsTable); JLabel backendDescriptionLabel = new JLabel(localize(LocaleResources.AGENT_INFO_BACKEND_DESCRIPTION_LABEL)); - backendDescription = new ValueField("${DESCRIPTION}"); + backendDescription = new ValueField(notAvailable); backendDescription.setName("backendDescription"); GroupLayout agentConfigurationPanelLayout = new GroupLayout(agentConfigurationPanel); diff -r 9702e8f0da26 -r 654fc29f96f2 client/core/src/main/resources/com/redhat/thermostat/client/locale/strings.properties --- a/client/core/src/main/resources/com/redhat/thermostat/client/locale/strings.properties Fri Sep 28 12:29:34 2012 -0400 +++ b/client/core/src/main/resources/com/redhat/thermostat/client/locale/strings.properties Fri Sep 28 11:35:11 2012 -0400 @@ -1,4 +1,5 @@ MISSING_INFO = Missing Information +INFORMATION_NOT_AVAILABLE = --- CONNECTION_FAILED_TO_CONNECT_TITLE = Failed to connect to data collector CONNECTION_FAILED_TO_CONNECT_DESCRIPTION = Thermostat failed to connect to the data collector. diff -r 9702e8f0da26 -r 654fc29f96f2 client/core/src/test/java/com/redhat/thermostat/client/ui/AgentInformationDisplayControllerTest.java --- a/client/core/src/test/java/com/redhat/thermostat/client/ui/AgentInformationDisplayControllerTest.java Fri Sep 28 12:29:34 2012 -0400 +++ b/client/core/src/test/java/com/redhat/thermostat/client/ui/AgentInformationDisplayControllerTest.java Fri Sep 28 11:35:11 2012 -0400 @@ -121,6 +121,19 @@ } @Test + public void testDisplayWithNoAgents() { + AgentInformationDisplayView view = mock(AgentInformationDisplayView.class); + AgentInformationDisplayModel model = mock(AgentInformationDisplayModel.class); + + when(model.getAgents()).thenReturn(Arrays.asList()); + + AgentInformationDisplayController controller = new AgentInformationDisplayController(model, view); + controller.showView(); + + verify(view).showDialog(); + } + + @Test public void testAddAgentAndBackendsOnInit() { AgentInformationDisplayView view = mock(AgentInformationDisplayView.class); AgentInformationDisplayModel model = mock(AgentInformationDisplayModel.class);