@Override public void evosuite_updateProperty(String clientRmiIdentifier, String propertyName, Object value) throws RemoteException, IllegalArgumentException, IllegalAccessException, NoSuchParameterException { Properties.getInstance().setValue(propertyName, value); }
/** * Initialize properties from property file or command line parameters */ private void initializeProperties() throws IllegalStateException{ for (String parameter : parameterMap.keySet()) { try { String property = System.getProperty(parameter); if (property == null) { property = properties.getProperty(parameter); } if (property != null) { setValue(parameter, property); } } catch (Exception e) { throw new IllegalStateException("Wrong parameter settings for '" + parameter + "': " + e.getMessage()); } } if (POPULATION_LIMIT == PopulationLimit.STATEMENTS) { if (MAX_LENGTH < POPULATION) { MAX_LENGTH = POPULATION; } } }
setValue(key, Integer.parseInt(value)); } else if (f.getType().equals(Integer.class)) { setValue(key, (Integer) Integer.parseInt(value)); setValue(key, Long.parseLong(value)); } else if (f.getType().equals(Long.class)) { setValue(key, (Long) Long.parseLong(value)); setValue(key, strictParseBoolean(value)); } else if (f.getType().equals(Boolean.class)) { setValue(key, (Boolean) strictParseBoolean(value)); setValue(key, Double.parseDouble(value)); } else if (f.getType().equals(Double.class)) { setValue(key, (Double) Double.parseDouble(value)); setValue(key, value.split(":")); } else if (f.getType().getComponentType().equals(Criterion.class)) { String[] values = value.split(":");
/** * Add all the properties that were set with -D * * @param javaOpts * @param line * @throws Error */ public static void addJavaDOptions(List<String> javaOpts, CommandLine line) throws Error { java.util.Properties properties = line.getOptionProperties("D"); Set<String> propertyNames = new HashSet<>(Properties.getParameters()); for (String propertyName : properties.stringPropertyNames()) { if (!propertyNames.contains(propertyName)) { LoggingUtils.getEvoLogger().error("* Unknown property: " + propertyName); throw new Error("Unknown property: " + propertyName); } String propertyValue = properties.getProperty(propertyName); javaOpts.add("-D" + propertyName + "=" + propertyValue); System.setProperty(propertyName, propertyValue); try { Properties.getInstance().setValue(propertyName, propertyValue); } catch (Exception e) { throw new Error("Invalid value for property " + propertyName+": "+propertyValue+". Exception "+e.getMessage(),e); } } }
Properties.getInstance().setValue("inheritance_file", Properties.OUTPUT_DIR + "/" + "inheritance.xml.gz");
@Test public void testOutOfRangeInput() throws IllegalArgumentException, IllegalAccessException, NoSuchParameterException{ Properties.getInstance().setValue("crossover_rate", 0.6); //this should be OK try{ Properties.getInstance().setValue("crossover_rate", 2.5); fail(); } catch(Exception e){/* OK*/} try{ Properties.getInstance().setValue("crossover_rate", -10.6); fail(); } catch(Exception e){/* OK*/} }
@Test public void testParameterThatDoesNotExist(){ try { Properties.getInstance().setValue("a_parameter_that_does_not_exist", 1); fail(); } catch (IllegalArgumentException | IllegalAccessException | NoSuchParameterException e) { //expected } }
Properties.getInstance().setValue("criterion", line.getOptionValue("criterion")); } catch (Exception e) { throw new Error("Invalid value for criterion: "+e.getMessage()); Properties.getInstance().setValue("num_parallel_clients", values[0]); Properties.getInstance().setValue("migrants_iteration_frequency", values[1]); Properties.getInstance().setValue("migrants_communication_rate", values[2]); } catch (Properties.NoSuchParameterException | IllegalAccessException e) { throw new Error("Invalid values for parallel: " + e.getMessage()); Properties.getInstance().setValue("num_parallel_clients", 1); } catch (Properties.NoSuchParameterException | IllegalAccessException e) { throw new Error("Could not set value: " + e.getMessage());
@Test public void testInvalidBooleanInput() throws Exception{ final boolean defaultValue = Properties.TEST_CARVING; boolean value = Properties.getBooleanValue("test_carving"); Assert.assertEquals(defaultValue, value); Properties.getInstance().setValue("test_carving", !defaultValue); value = Properties.getBooleanValue("test_carving"); Assert.assertNotEquals(defaultValue, value); try{ Properties.getInstance().setValue("test_carving", "tru"); fail(); } catch(Exception e){ //expected } }