Skip to content

Commit 977cb19

Browse files
authored
Merge pull request #487 from ISISComputingGroup/Ticket2023_dae_crashing_if_disconnected
Ticket2023 dae crashing if disconnected
2 parents 37713f1 + fc0c5b2 commit 977cb19

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

base/uk.ac.stfc.isis.ibex.dae.tests/src/uk/ac/stfc/isis/ibex/dae/tests/periods/WritingXmlFromPeriodSettingsTest.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
package uk.ac.stfc.isis.ibex.dae.tests.periods;
2121

2222
import static org.hamcrest.CoreMatchers.*;
23-
import static org.junit.Assert.assertThat;
23+
import static org.junit.Assert.*;
2424

2525
import java.io.IOException;
2626
import java.net.MalformedURLException;
@@ -116,6 +116,20 @@ public void setup_source_is_updated() {
116116
assertThat(periodSettings.getSetupSource(), is(newValue));
117117
}
118118

119+
@Test
120+
public void setup_source_is_not_updated_if_null() {
121+
122+
// Arrange: Check that null is not the current setup source.
123+
assertNotEquals(periodSettings.getSetupSource(), null);
124+
125+
// Act: Try to set a setup source as null.
126+
periodSettings.setSetupSource(null);
127+
reloadSettingsFromCurrentValues();
128+
129+
// Assert: Check that null has been ignored.
130+
assertNotEquals(periodSettings.getSetupSource(), null);
131+
}
132+
119133

120134
@Test
121135
public void period_file_is_updated() {
@@ -139,6 +153,20 @@ public void period_control_type_is_updated() {
139153
assertThat(periodSettings.getPeriodType(), is(newValue));
140154
}
141155

156+
@Test
157+
public void period_control_type_is_not_updated_if_null() {
158+
159+
// Arrange: Check that null is not the current period type.
160+
assertNotEquals(periodSettings.getPeriodType(), null);
161+
162+
// Act: Try to set a period type as null.
163+
periodSettings.setPeriodType(null);
164+
reloadSettingsFromCurrentValues();
165+
166+
// Assert: Check that null has been ignored.
167+
assertNotEquals(periodSettings.getPeriodType(), null);
168+
}
169+
142170
@Test
143171
public void software_periods_is_updated() {
144172
int newValue = 12121;

base/uk.ac.stfc.isis.ibex.dae/src/uk/ac/stfc/isis/ibex/dae/experimentsetup/periods/XMLBackedPeriodSettings.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
import uk.ac.stfc.isis.ibex.dae.xml.XmlNode;
3434
import uk.ac.stfc.isis.ibex.logger.IsisLog;
3535

36+
/**
37+
* Gets the DAE period settings from XML.
38+
*/
3639
public class XMLBackedPeriodSettings extends PeriodSettings {
3740

3841
private static final Logger LOG = IsisLog.getLogger(XMLBackedPeriodSettings.class);
@@ -51,6 +54,9 @@ public class XMLBackedPeriodSettings extends PeriodSettings {
5154

5255
private final ArrayList<XmlBackedPeriod> periods = new ArrayList<>();
5356

57+
/**
58+
* Constructor.
59+
*/
5460
public XMLBackedPeriodSettings() {
5561
nodes.add(setupSource);
5662
nodes.add(periodFile);
@@ -68,45 +74,79 @@ public XMLBackedPeriodSettings() {
6874
xmlFile = new XmlFile(nodes);
6975
}
7076

77+
/**
78+
* Sets the xml.
79+
* @param xml the xml to set
80+
*/
7181
public void setXml(String xml) {
7282
xmlFile.setXml(xml);
7383
initialiseFromXml();
7484
}
7585

86+
/**
87+
* Gets the xml from file.
88+
* @return the xml
89+
*/
7690
public String xml() {
7791
return xmlFile.toString();
7892
}
7993

94+
/**
95+
* {@inheritDoc}
96+
*/
8097
@Override
8198
public void setSetupSource(PeriodSetupSource value) {
99+
if (value == null) {
100+
LOG.info("Error, attempted to set a null PeriodSetupSource.");
101+
return;
102+
}
82103
super.setSetupSource(value);
83104
setupSource.setValue(value);
84105
}
85106

107+
/**
108+
* {@inheritDoc}
109+
*/
86110
@Override
87111
public void setNewPeriodFile(String value) {
88112
super.setNewPeriodFile(value);
89113
periodFile.setValue(value);
90114
}
91115

116+
/**
117+
* {@inheritDoc}
118+
*/
92119
@Override
93120
public void setPeriodType(PeriodControlType value) {
121+
if (value == null) {
122+
LOG.info("Error, attempted to set a null PeriodControlType.");
123+
return;
124+
}
94125
super.setPeriodType(value);
95126
periodType.setValue(value);
96127
}
97128

129+
/**
130+
* {@inheritDoc}
131+
*/
98132
@Override
99133
public void setSoftwarePeriods(int value) {
100134
super.setSoftwarePeriods(value);
101135
softwarePeriods.setValue(value);
102136
}
103137

138+
/**
139+
* {@inheritDoc}
140+
*/
104141
@Override
105142
public void setHardwarePeriods(double value) {
106143
super.setHardwarePeriods(value);
107144
hardwarePeriods.setValue(value);
108145
}
109146

147+
/**
148+
* {@inheritDoc}
149+
*/
110150
@Override
111151
public void setOutputDelay(double value) {
112152
super.setOutputDelay(value);

0 commit comments

Comments
 (0)