use of org.apache.sling.provisioning.model.Model in project sling by apache.
the class IOTest method testReadWrite.
@Test
public void testReadWrite() throws Exception {
final Model result = U.readCompleteTestModel();
U.verifyTestModel(result, false);
// Write the merged raw model
StringWriter writer = new StringWriter();
try {
ModelWriter.write(writer, result);
} finally {
writer.close();
}
// read it again
StringReader reader = new StringReader(writer.toString());
final Model readModel = ModelReader.read(reader, "memory");
reader.close();
final Map<Traceable, String> readErrors = ModelUtility.validate(readModel);
if (readErrors != null) {
throw new Exception("Invalid read model : " + readErrors);
}
// and verify the result
U.verifyTestModel(readModel, false);
// Resolve variables and verify the result
final Model effective = ModelUtility.getEffectiveModel(readModel);
U.verifyTestModel(effective, true);
// write effective model
writer = new StringWriter();
ModelWriter.write(writer, effective);
writer.close();
reader = new StringReader(writer.toString());
final Model readModel2 = ModelReader.read(reader, "memory");
reader.close();
final Map<Traceable, String> readErrors2 = ModelUtility.validate(readModel2);
if (readErrors2 != null) {
throw new Exception("Invalid read model : " + readErrors2);
}
// and verify the result
U.verifyTestModel(readModel2, true);
}
use of org.apache.sling.provisioning.model.Model in project sling by apache.
the class IOTest method testAddition.
@Test
public void testAddition() throws Exception {
final Model model = U.readCompleteTestModel(new String[] { "additional.txt" });
final Feature f = model.getFeature("main");
assertNotNull(f);
assertEquals(1, f.getAdditionalSections().size());
assertEquals(1, f.getAdditionalSections("additional").size());
}
use of org.apache.sling.provisioning.model.Model in project sling by apache.
the class Launcher method mergeModel.
/** Can be called before launch() to read and merge additional models.
* @param r provisioning model to read, closed by this method after reading */
public static void mergeModel(Model mergeInto, Reader r, String sourceInfo) throws IOException {
log.info("Merging provisioning model {}", sourceInfo);
try {
final Model m = ModelReader.read(r, sourceInfo);
ModelUtility.merge(mergeInto, m);
} finally {
r.close();
}
}
Aggregations