use of beast.core.BEASTObject in project beast2 by CompEvol.
the class InputTypeTest method testInputTypeCanBeSet.
/*
* Test that the type of an input can be determined, If not, the programmer
* has to manually initialise the type of the input (most easily done
* through a constructor of Input)
*/
@Test
public void testInputTypeCanBeSet() throws Exception {
List<String> beastObjectNames = PackageManager.find(beast.core.BEASTObject.class, PackageManager.IMPLEMENTATION_DIR);
List<String> failingInputs = new ArrayList<String>();
for (String beastObjectName : beastObjectNames) {
try {
BEASTObject beastObject = (BEASTObject) Class.forName(beastObjectName).newInstance();
List<Input<?>> inputs = beastObject.listInputs();
for (Input<?> input : inputs) {
if (input.getType() == null) {
try {
input.determineClass(beastObject);
if (input.getType() == null) {
failingInputs.add(beastObject + ":" + input.getName());
}
} catch (Exception e2) {
failingInputs.add(beastObject + ":" + input.getName());
}
}
}
} catch (Exception e) {
// ignore
}
}
assertTrue("Type of input could not be set for these inputs (probably requires to be set by using the appropriate constructure of Input): " + failingInputs.toString(), failingInputs.size() == 0);
}
use of beast.core.BEASTObject in project beast2 by CompEvol.
the class XMLElementNameTest method test_ReservedElementNames.
/**
* test that Inputs that use reserved names have the correct type *
*/
@Test
public void test_ReservedElementNames() {
// retrieve list of reserved names and their classes
XMLParser parser = new XMLParser();
HashMap<String, String> element2ClassMap = parser.getElement2ClassMap();
// allow 'parameter' for any of the various parameter derivatives, not just RealParameter
element2ClassMap.put("parameter", "beast.core.parameter.Parameter");
// check each beastObject
List<String> pluginNames = PackageManager.find(beast.core.BEASTObject.class, PackageManager.IMPLEMENTATION_DIR);
List<String> improperInputs = new ArrayList<String>();
for (String beastObjectName : pluginNames) {
try {
BEASTObject beastObject = (BEASTObject) Class.forName(beastObjectName).newInstance();
// check each input
List<Input<?>> inputs = beastObject.listInputs();
for (Input<?> input : inputs) {
if (element2ClassMap.containsKey(input.getName())) {
if (beastObject.getClass() == null) {
input.determineClass(beastObject);
}
Class<?> type = input.getType();
String baseType = element2ClassMap.get(input.getName());
if (!isDerivedType(type, baseType)) {
improperInputs.add(beastObjectName + "." + input.getName());
}
}
}
} catch (InstantiationException e) {
// ignore
} catch (Exception e) {
// ignore
}
}
if (improperInputs.size() > 0) {
String str = improperInputs.toString();
str = str.replaceAll(",", "\n");
System.err.println("Reserved element names used for wrong types in:\n" + str);
}
// not activated till problem with naming is solved
assertTrue("Reserved element names used for wrong types in: " + improperInputs.toString(), improperInputs.size() == 0);
}
use of beast.core.BEASTObject in project beast2 by CompEvol.
the class JSONTest method testJSONtoXMLtoJSON.
@Test
public void testJSONtoXMLtoJSON() throws Exception {
JSONParser parser = new JSONParser();
BEASTObject beastObject = parser.parseFile(new File(JSON_FILE));
JSONProducer producer = new JSONProducer();
// .replaceAll("\\s+", " ");
String actual = producer.toJSON(beastObject).trim();
// .replaceAll("\\s+", " ");
String expected = BeautiDoc.load(JSON_FILE).trim();
assertEquals("Produced JSON differs from original", expected, actual);
}
Aggregations