public void testNullDescription() { Constructor constructor = new Constructor(); try { constructor.addTypeDescription(null); fail("Description is required."); } catch (Exception e) { assertEquals("TypeDescription is required.", e.getMessage()); } }
private Yaml prepareLoader(ClassLoader classLoader) { final Constructor constructor = new MyConstructor(Holder.class, classLoader); final TypeDescription typeDescription = new TypeDescription(Holder.class); typeDescription.putListPropertyType("prototypes", DefaultEntityPrototype.class); constructor.addTypeDescription(typeDescription); final Loader loader = new Loader(constructor); final Yaml yaml = new Yaml(loader); return yaml; }
public void testLoadClassTag() { Constructor constructor = new Constructor(); constructor.addTypeDescription(new TypeDescription(Car.class, "!car")); Yaml yaml = new Yaml(constructor); String source = Util.getLocalResource("constructor/car-without-tags.yaml"); Car car = (Car) yaml.load(source); assertEquals("12-XP-F4", car.getPlate()); List<Wheel> wheels = car.getWheels(); assertNotNull(wheels); assertEquals(5, wheels.size()); }
public static WeatherStatsConfigInfo getConfiguration(String configFile) throws Exception { BaseConstructor constructor = new Constructor(WeatherStatsConfigInfo.class); TypeDescription configDescription = new TypeDescription(WeatherStatsConfigInfo.class); ((Constructor) constructor).addTypeDescription(configDescription); Yaml yaml = new Yaml(new Loader(constructor)); WeatherStatsConfigInfo info = (WeatherStatsConfigInfo) yaml.load(new FileInputStream(new File(configFile))); return info; }
public static XmlSuite parse(String filePath, InputStream is) throws FileNotFoundException { Constructor constructor = new TestNGConstructor(XmlSuite.class); { TypeDescription suiteDescription = new TypeDescription(XmlSuite.class); suiteDescription.putListPropertyType("packages", XmlPackage.class); suiteDescription.putListPropertyType("listeners", String.class); suiteDescription.putListPropertyType("tests", XmlTest.class); suiteDescription.putListPropertyType("method-selectors", XmlMethodSelector.class); constructor.addTypeDescription(suiteDescription); } { TypeDescription testDescription = new TypeDescription(XmlTest.class); testDescription.putListPropertyType("classes", XmlClass.class); testDescription.putMapPropertyType("metaGroups", String.class, List.class); testDescription.putListPropertyType("method-selectors", XmlMethodSelector.class); constructor.addTypeDescription(testDescription); } org.yaml.snakeyaml.Yaml y = new org.yaml.snakeyaml.Yaml(constructor); if (is == null) is = new FileInputStream(new File(filePath)); XmlSuite result = (XmlSuite) y.load(is); result.setFileName(filePath); // DEBUG // System.out.println("[Yaml] " + result.toXml()); // Adjust XmlTest parents and indices for (XmlTest t : result.getTests()) { t.setSuite(result); int index = 0; for (XmlClass c : t.getClasses()) { c.setIndex(index++); } } return result; }
public Constructor(TypeDescription theRoot) { if (theRoot == null) { throw new NullPointerException("Root type must be provided."); } this.yamlConstructors.put(null, new ConstructYamlObject()); if (!Object.class.equals(theRoot.getType())) { rootTag = new Tag(theRoot.getType()); } typeTags = new HashMap<Tag, Class<? extends Object>>(); typeDefinitions = new HashMap<Class<? extends Object>, TypeDescription>(); yamlClassConstructors.put(NodeId.scalar, new ConstructScalar()); yamlClassConstructors.put(NodeId.mapping, new ConstructMapping()); yamlClassConstructors.put(NodeId.sequence, new ConstructSequence()); addTypeDescription(theRoot); }