changeset 646:654fc29f96f2

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
author Omair Majid <omajid@redhat.com>
date Fri, 28 Sep 2012 11:35:11 -0400
parents 9702e8f0da26
children 4323e78903af 8cc8dea8b9d6
files client/core/src/main/java/com/redhat/thermostat/client/locale/LocaleResources.java client/core/src/main/java/com/redhat/thermostat/client/ui/AgentInformationDisplayController.java client/core/src/main/java/com/redhat/thermostat/client/ui/AgentInformationDisplayFrame.java client/core/src/main/resources/com/redhat/thermostat/client/locale/strings.properties client/core/src/test/java/com/redhat/thermostat/client/ui/AgentInformationDisplayControllerTest.java
diffstat 5 files changed, 27 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- 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,
 
--- 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() {
--- 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);
--- 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.
--- 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.<AgentInformation>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);