public static ObjectType deserializeObjectFromXml(String xml, PrismContext prismContext) { try { return (ObjectType) prismContext.parserFor(xml).xml().parse().asObjectable(); } catch (SchemaException e) { throw new SystemException("Couldn't deserialize a PrismObject from XML", e); } }
@NotNull public PrismObject<UserType> getJack() throws SchemaException, IOException { return getPrismContext().parserFor(USER_JACK_FILE).parse(); } }
protected void transplantGlobalPolicyRulesAdd(File configWithGlobalRulesFile, Task task, OperationResult parentResult) throws SchemaException, IOException, ObjectNotFoundException, ObjectAlreadyExistsException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException { // copy rules from the file into live system config object PrismObject<SystemConfigurationType> rules = prismContext.parserFor(configWithGlobalRulesFile).parse(); ObjectDelta<SystemConfigurationType> delta = prismContext.deltaFor(SystemConfigurationType.class) .item(SystemConfigurationType.F_GLOBAL_POLICY_RULE).add( rules.asObjectable().getGlobalPolicyRule().stream() .map(r -> r.clone().asPrismContainerValue()) .collect(Collectors.toList())) .asObjectDeltaCast(SystemObjectsType.SYSTEM_CONFIGURATION.value()); modelService.executeChanges(MiscSchemaUtil.createCollection(delta), null, task, parentResult); }
@Test public void testParseModelContextPrism() throws Exception { System.out.println("===[ testParseModelContextPrism ]==="); // GIVEN PrismContext prismContext = PrismTestUtil.getPrismContext(); // WHEN LensContextType lensContextType = prismContext.parserFor(MODEL_CONTEXT_FILE).xml().parseRealValue(LensContextType.class); // THEN System.out.println("Parsed LensContextType: " + lensContextType); }
@Test(enabled = false) public void test100Parsing() throws Exception { long time = System.currentTimeMillis(); int COUNT = 1000; for (int i = 0; i < COUNT; i++) { List<PrismObject<? extends Objectable>> elements = prismContext.parserFor(new File(FOLDER_BASIC, "objects.xml")).parseObjects(); for (PrismObject obj : elements) { prismContext.serializerFor(PrismContext.LANG_XML).serialize(obj); } } LOGGER.info("xxx>> time: {}", (System.currentTimeMillis() - time)); }
@Test public void testParseValueFilterWithAny() throws Exception { PrismContext prismContext = PrismTestUtil.getPrismContext(); Document doc = DOMUtil.parseFile(new File(TestConstants.COMMON_DIR, "value-filter-with-any.xml")); Element rootElement = DOMUtil.getFirstChildElement(doc); // WHEN Object parsedObject = prismContext.parserFor(rootElement).parseRealValue(); // THEN System.out.println("Parsed object: " + parsedObject); }
@Test public void testParsePasswordPolicyFile() throws Exception { System.out.println("===[ testParsePasswordPolicyFile ]==="); // GIVEN PrismContext prismContext = PrismTestUtil.getPrismContext(); // WHEN PrismObject<ValuePolicyType> policy = prismContext.parserFor(FILE).xml().parse(); // THEN System.out.println("Parsed policy:"); System.out.println(policy.debugDump()); assertPolicy(policy); }
private T parseRawElementToNewRealValue(PrismPropertyValue<T> prismPropertyValue, PrismPropertyDefinition<T> definition) throws SchemaException { PrismContext prismCtx = definition.getPrismContext() != null ? definition.getPrismContext() : prismContext; //noinspection UnnecessaryLocalVariable if (prismCtx == null) { throw new SchemaException("Unexpected null prism context."); } T value = prismCtx.parserFor(prismPropertyValue.getRawElement().toRootXNode()).definition(definition).parseRealValue(); return value; }
@Test public void testParseToXNode() throws Exception { PrismContext prismContext = PrismTestUtil.getPrismContext(); RootXNode node = prismContext.parserFor(getFile()).parseToXNode(); System.out.println("Parsed to XNode:"); System.out.println(node.debugDump()); System.out.println("XML -> XNode -> XML:\n" + prismContext.xmlSerializer().serialize(node)); System.out.println("XML -> XNode -> JSON:\n" + prismContext.jsonSerializer().serialize(node)); System.out.println("XML -> XNode -> YAML:\n" + prismContext.yamlSerializer().serialize(node)); }
@Test public void testParseToXNode() throws Exception { PrismContext prismContext = PrismTestUtil.getPrismContext(); RootXNode node = prismContext.parserFor(getFile()).parseToXNode(); System.out.println("Parsed to XNode:"); System.out.println(node.debugDump()); System.out.println("XML -> XNode -> XML:\n" + prismContext.xmlSerializer().serialize(node)); System.out.println("XML -> XNode -> JSON:\n" + prismContext.jsonSerializer().serialize(node)); System.out.println("XML -> XNode -> YAML:\n" + prismContext.yamlSerializer().serialize(node)); }
@Test public void testYamlSerialization() throws Exception { displayTestTitle("testParseToXNode"); String file = MiscUtil.readFile(getFile()); System.out.println("Original text:\n" + file); RootXNode xnode = getPrismContext().parserFor(file).parseToXNode(); System.out.println("XNode:\n" + xnode.debugDump()); String yaml = getPrismContext().yamlSerializer().serialize(xnode); System.out.println("source -> XNode -> YAML:\n" + yaml); PrismValue value = getPrismContext().parserFor(yaml).parseItemValue(); assertPrismPropertyValueLocal((PrismPropertyValue<ExpressionPipelineType>) value); }
@Test public void test310ParseXml() throws Exception { System.out.println("===[ test310ParseXml ]==="); PrismObject<UserType> jack = getJack(); String string = getPrismContext().xmlSerializer().serialize(jack); measure("parse XML (" + string.length() + " chars)", () -> getPrismContext().parserFor(string).xml().parse()); measure("parse XML to XNode (" + string.length() + " chars)", () -> getPrismContext().parserFor(string).xml().parseToXNode()); }
@Test public void test320ParseJson() throws Exception { System.out.println("===[ test320ParseJson ]==="); PrismObject<UserType> jack = getJack(); String string = getPrismContext().jsonSerializer().serialize(jack); measure("parse JSON (" + string.length() + " chars)", () -> getPrismContext().parserFor(string).json().parse()); measure("parse JSON to XNode (" + string.length() + " chars)", () -> getPrismContext().parserFor(string).json().parseToXNode()); }
@Test public void test200CheckEncryptedSystemConfiguration() throws Exception { final String TEST_NAME = "test200CheckEncryptedSystemConfiguration"; TestUtil.displayTestTitle(TEST_NAME); // GIVEN PrismContext prismContext = getPrismContext(); PrismObject<SystemConfigurationType> config = prismContext.parserFor(FILE_SYSTEM_CONFIGURATION).xml().parse(); // WHEN+THEN checkEncryptedObject(config); }
@Test public void test100CheckEncryptedUser() throws Exception { final String TEST_NAME = "test100CheckEncryptedUser"; TestUtil.displayTestTitle(TEST_NAME); // GIVEN PrismContext prismContext = getPrismContext(); PrismObject<UserType> jack = prismContext.parserFor(FILE_USER_JACK).xml().parse(); // WHEN+THEN checkEncryptedObject(jack); }
@Test public void testNamespaces() throws Exception { String file = MiscUtil.readFile(getFile()); RootXNode xnode = getPrismContext().parserFor(file).parseToXNode(); System.out.println("XNode:\n" + xnode.debugDump()); String serialized = getPrismContext().xmlSerializer().serialize(xnode); System.out.println("XML: " + serialized); final String common_3 = "http://midpoint.evolveum.com/xml/ns/public/common/common-3"; int count = StringUtils.countMatches(serialized, common_3); assertEquals("Wrong # of occurrences of '" + common_3 + "' in serialized form", 2, count); }
@Test public void test340ParseXNode() throws Exception { System.out.println("===[ test340ParseXNode ]==="); PrismObject<UserType> jack = getJack(); RootXNode xnode = getPrismContext().xnodeSerializer().serialize(jack); measure("parse XNode", () -> getPrismContext().parserFor(xnode).parse()); }
@Override protected void updateSystemConfiguration(SystemConfigurationType systemConfiguration) throws SchemaException, IOException { super.updateSystemConfiguration(systemConfiguration); PrismObject<SystemConfigurationType> rulesContainer = prismContext.parserFor(GLOBAL_POLICY_RULES_FILE).parse(); systemConfiguration.getGlobalPolicyRule().clear(); systemConfiguration.getGlobalPolicyRule().addAll(cloneCollectionMembers(rulesContainer.asObjectable().getGlobalPolicyRule())); }
@Test public void testParseToXNode() throws Exception { displayTestTitle("testParseToXNode"); System.out.println("\n\n-----------------------------------\n"); String file = MiscUtil.readFile(getFile()); System.out.println("Original text:\n" + file); RootXNode xnode = getPrismContext().parserFor(file).parseToXNode(); System.out.println("XNode:\n" + xnode.debugDump()); System.out.println("source -> XNode -> JSON:\n" + getPrismContext().jsonSerializer().serialize(xnode)); System.out.println("source -> XNode -> YAML:\n" + getPrismContext().yamlSerializer().serialize(xnode)); System.out.println("source -> XNode -> XML:\n" + getPrismContext().xmlSerializer().serialize(xnode)); }
@Test public void test000LoadContext() throws Exception { final String TEST_NAME = "test000LoadContext"; TestUtil.displayTestTitle(this, TEST_NAME); Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); LensContextType lensContextType = prismContext.parserFor(new File("src/test/resources/model-contexts/context-dummy-resource.xml")).xml().parseRealValue(LensContextType.class); display("LensContextType", lensContextType); LensContext<?> lensContext = LensContext.fromLensContextType(lensContextType, prismContext, provisioningService, task, result); display("LensContext", lensContext); }