### Question:
CPEParameters { public Map<String, String> getConfigFileMap() { Map<String, String> cMap = new HashMap<>(); cpeParams.forEach((namePN, value) -> { if (namePN.contains(CONFIG_FILES) && namePN.endsWith("Name")) { String namePV = value.getValue(); String versionPN = namePN.substring(0, namePN.length() - "Name".length()) + "Version"; ParameterValueStruct valueStruct = cpeParams.get(versionPN); if (valueStruct != null) { String versionPV = valueStruct.getValue(); cMap.put(namePV, versionPV); } } }); return cMap; } CPEParameters(String keyRoot); String getValue(String param); Map<String, String> getConfigFileMap(); public String CONFIG_FILES; public String SOFTWARE_VERSION; public String PERIODIC_INFORM_INTERVAL; public String CONNECTION_URL; public String CONNECTION_USERNAME; public String CONNECTION_PASSWORD; }### Answer:
@Test public void shouldNotFailWithNoParameters() { CPEParameters cpeParameters = new CPEParameters("Device."); Map<String, String> result = cpeParameters.getConfigFileMap(); assertNotNull(result); }
@Test public void shouldNotFailOnMissingVersion() { CPEParameters cpeParameters = new CPEParameters("Device."); cpeParameters.getCpeParams().put("Device.DeviceInfo.VendorConfigFile.1.Name", new ParameterValueStruct( "Device.DeviceInfo.VendorConfigFile.1.Name", "Current ROS configuration", "xsd:string" )); cpeParameters.getCpeParams().put("Device.DeviceInfo.VendorConfigFile.1.Description", new ParameterValueStruct( "Device.DeviceInfo.VendorConfigFile.1.Description", "Currently applied ROS configuration which will return dynamic /export output when Uploaded.", "xsd:string" )); cpeParameters.getCpeParams().put("Device.DeviceInfo.VendorConfigFile.1.UseForBackupRestore", new ParameterValueStruct( "Device.DeviceInfo.VendorConfigFile.1.UseForBackupRestore", "0", "xsd:boolean" )); assertNotNull(cpeParameters.getConfigFileMap()); }
@Test public void shouldReturnVersion() { CPEParameters cpeParameters = new CPEParameters("Device."); cpeParameters.getCpeParams().put("Device.DeviceInfo.VendorConfigFile.1.Name", new ParameterValueStruct( "Device.DeviceInfo.VendorConfigFile.1.Name", "SomeName", "xsd:string" )); cpeParameters.getCpeParams().put("Device.DeviceInfo.VendorConfigFile.1.Version", new ParameterValueStruct( "Device.DeviceInfo.VendorConfigFile.1.Version", "123", "xsd:string" )); cpeParameters.getCpeParams().put("Device.DeviceInfo.VendorConfigFile.1.Description", new ParameterValueStruct( "Device.DeviceInfo.VendorConfigFile.1.Description", "Currently applied ROS configuration which will return dynamic /export output when Uploaded.", "xsd:string" )); cpeParameters.getCpeParams().put("Device.DeviceInfo.VendorConfigFile.1.UseForBackupRestore", new ParameterValueStruct( "Device.DeviceInfo.VendorConfigFile.1.UseForBackupRestore", "0", "xsd:boolean" )); assertNotNull(cpeParameters.getConfigFileMap()); assertEquals("123", cpeParameters.getConfigFileMap().get("SomeName")); }