use of com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType in project midpoint by Evolveum.
the class TestResourceSchema method testResourceSchemaJaxbRoundTrip.
// The support for the xsd:any properties is missing in JAXB generator. Otherwise this test should work.
@Test(enabled = false)
public void testResourceSchemaJaxbRoundTrip() throws SchemaException {
// GIVEN
ResourceSchema schema = createResourceSchema();
System.out.println("Resource schema before serializing to XSD: ");
System.out.println(schema.debugDump());
System.out.println();
Document xsd = schema.serializeToXsd();
ResourceType resource = new ResourceType();
resource.setName(PrismTestUtil.createPolyStringType("JAXB With Dynamic Schemas Test"));
ResourceTypeUtil.setResourceXsdSchema(resource, DOMUtil.getFirstChildElement(xsd));
// WHEN
String marshalledResource = PrismTestUtil.serializeObjectToString(resource.asPrismObject());
System.out.println("Marshalled resource");
System.out.println(marshalledResource);
ResourceType unmarshalledResource = (ResourceType) PrismTestUtil.parseObject(marshalledResource).asObjectable();
System.out.println("unmarshalled resource");
System.out.println(ObjectTypeUtil.dump(unmarshalledResource));
XmlSchemaType unXmlSchemaType = unmarshalledResource.getSchema();
Element unXsd = unXmlSchemaType.getDefinition().getAny().get(0);
ResourceSchema unSchema = ResourceSchemaParser.parse(unXsd, "unmarshalled resource");
System.out.println("unmarshalled schema");
System.out.println(unSchema.debugDump());
// THEN
assertResourceSchema(unSchema);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType in project midpoint by Evolveum.
the class TestResourceSchema method testResourceSchemaSerializationInResource.
@Test
public void testResourceSchemaSerializationInResource() throws SchemaException {
// GIVEN
ResourceSchema schema = createResourceSchema();
// WHEN
Document xsdDocument = schema.serializeToXsd();
Element xsdElement = DOMUtil.getFirstChildElement(xsdDocument);
PrismObject<ResourceType> resource = wrapInResource(xsdElement);
String resourceXmlString = PrismTestUtil.getPrismContext().xmlSerializer().serialize(resource);
System.out.println("Serialized resource");
System.out.println(resourceXmlString);
PrismObject<ResourceType> reparsedResource = PrismTestUtil.getPrismContext().parseObject(resourceXmlString);
System.out.println("Re-parsed resource");
System.out.println(reparsedResource.debugDump());
XmlSchemaType reparsedSchemaType = reparsedResource.asObjectable().getSchema();
Element reparsedXsdElement = ObjectTypeUtil.findXsdElement(reparsedSchemaType);
System.out.println("Reparsed XSD schema");
System.out.println(DOMUtil.serializeDOMToString(reparsedXsdElement));
assertDomSchema(reparsedXsdElement);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType in project midpoint by Evolveum.
the class TestParseResource method assertResourceJaxb.
private void assertResourceJaxb(ResourceType resourceType, boolean isSimple) throws SchemaException {
assertEquals("Wrong oid (JAXB)", TestConstants.RESOURCE_OID, resourceType.getOid());
assertEquals("Wrong name (JAXB)", PrismTestUtil.createPolyStringType("Embedded Test OpenDJ"), resourceType.getName());
assertEquals("Wrong namespace (JAXB)", MidPointConstants.NS_RI, MidPointConstants.NS_RI);
ObjectReferenceType connectorRef = resourceType.getConnectorRef();
assertNotNull("No connectorRef (JAXB)", connectorRef);
assertEquals("Wrong type in connectorRef (JAXB)", ConnectorType.COMPLEX_TYPE, connectorRef.getType());
SearchFilterType filter = connectorRef.getFilter();
assertNotNull("No filter in connectorRef (JAXB)", filter);
MapXNode filterElement = filter.getFilterClauseXNode();
assertNotNull("No filter element in connectorRef (JAXB)", filterElement);
EvaluationTimeType resolutionTime = connectorRef.getResolutionTime();
if (isSimple) {
assertEquals("Wrong resolution time in connectorRef (JAXB)", EvaluationTimeType.RUN, resolutionTime);
} else {
assertEquals("Wrong resolution time in connectorRef (JAXB)", EvaluationTimeType.IMPORT, resolutionTime);
}
XmlSchemaType xmlSchemaType = resourceType.getSchema();
SchemaHandlingType schemaHandling = resourceType.getSchemaHandling();
if (isSimple) {
assertNull("Schema sneaked in", xmlSchemaType);
assertNull("SchemaHandling sneaked in", schemaHandling);
} else {
assertNotNull("No schema element (JAXB)", xmlSchemaType);
SchemaDefinitionType definition = xmlSchemaType.getDefinition();
assertNotNull("No definition element in schema (JAXB)", definition);
List<Element> anyElements = definition.getAny();
assertNotNull("Null element list in definition element in schema (JAXB)", anyElements);
assertFalse("Empty element list in definition element in schema (JAXB)", anyElements.isEmpty());
assertNotNull("No schema handling (JAXB)", schemaHandling);
for (ResourceObjectTypeDefinitionType accountType : schemaHandling.getObjectType()) {
String name = accountType.getIntent();
assertNotNull("Account type without a name", name);
assertNotNull("Account type " + name + " does not have an objectClass", accountType.getObjectClass());
boolean foundDescription = false;
boolean foundDepartmentNumber = false;
for (ResourceAttributeDefinitionType attributeDefinitionType : accountType.getAttribute()) {
if ("description".equals(ItemPathTypeUtil.asSingleNameOrFail(attributeDefinitionType.getRef()).getLocalPart())) {
foundDescription = true;
MappingType outbound = attributeDefinitionType.getOutbound();
JAXBElement<?> valueEvaluator = outbound.getExpression().getExpressionEvaluator().get(0);
System.out.println("value evaluator for description = " + valueEvaluator);
assertNotNull("no expression evaluator for description", valueEvaluator);
assertEquals("wrong expression evaluator element name for description", SchemaConstantsGenerated.C_VALUE, valueEvaluator.getName());
assertEquals("wrong expression evaluator actual type for description", RawType.class, valueEvaluator.getValue().getClass());
} else if ("departmentNumber".equals(ItemPathTypeUtil.asSingleNameOrFail(attributeDefinitionType.getRef()).getLocalPart())) {
foundDepartmentNumber = true;
MappingType outbound = attributeDefinitionType.getOutbound();
VariableBindingDefinitionType source = outbound.getSource().get(0);
System.out.println("source for departmentNumber = " + source);
assertNotNull("no source for outbound mapping for departmentNumber", source);
// <path xmlns:z="http://z/">$user/extension/z:dept</path>
ItemPath expected = ItemPath.create(new VariableItemPathSegment(new QName("user")), new QName("extension"), namespaces ? new QName("http://z/", "dept") : new QName("dept"));
PrismAsserts.assertPathEqualsExceptForPrefixes("source for departmentNubmer", expected, source.getPath().getItemPath());
}
}
assertTrue("ri:description attribute was not found", foundDescription);
assertTrue("ri:departmentNumber attribute was not found", foundDepartmentNumber);
}
// checking <class> element in fetch result
OperationResultType fetchResult = resourceType.getFetchResult();
assertNotNull("No fetchResult (JAXB)", fetchResult);
JAXBElement<?> value = fetchResult.getParams().getEntry().get(0).getEntryValue();
assertNotNull("No fetchResult param value (JAXB)", value);
assertEquals("Wrong value class", UnknownJavaObjectType.class, value.getValue().getClass());
UnknownJavaObjectType unknownJavaObjectType = (UnknownJavaObjectType) value.getValue();
assertEquals("Wrong value class", "my.class", unknownJavaObjectType.getClazz());
assertEquals("Wrong value toString value", "my.value", unknownJavaObjectType.getToString());
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType in project midpoint by Evolveum.
the class ResourceUtils method deleteSchema.
public static void deleteSchema(PrismObject<ResourceType> resource, ModelService modelService, PrismContext prismContext, Task task, OperationResult parentResult) throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
PrismContainer<XmlSchemaType> schemaContainer = resource.findContainer(ResourceType.F_SCHEMA);
if (schemaContainer != null && schemaContainer.getValue() != null) {
PrismProperty<SchemaDefinitionType> definitionProperty = schemaContainer.findProperty(XmlSchemaType.F_DEFINITION);
if (definitionProperty != null && !definitionProperty.isEmpty()) {
PrismPropertyValue<SchemaDefinitionType> definitionValue = definitionProperty.getValue().clone();
ObjectDelta<ResourceType> deleteSchemaDefinitionDelta = ObjectDelta.createModificationDeleteProperty(ResourceType.class, resource.getOid(), new ItemPath(ResourceType.F_SCHEMA, XmlSchemaType.F_DEFINITION), prismContext, // TODO ...or replace with null?
definitionValue.getValue());
// delete schema
modelService.executeChanges(Collections.<ObjectDelta<? extends ObjectType>>singleton(deleteSchemaDefinitionDelta), null, task, parentResult);
}
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType in project midpoint by Evolveum.
the class AbstractManualResourceTest method test003Connection.
@Test
public void test003Connection() throws Exception {
final String TEST_NAME = "test003Connection";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
// Check that there is a schema, but no capabilities before test (pre-condition)
ResourceType resourceBefore = repositoryService.getObject(ResourceType.class, getResourceOid(), null, result).asObjectable();
Element resourceXsdSchemaElementBefore = ResourceTypeUtil.getResourceXsdSchema(resourceBefore);
assertResourceSchemaBeforeTest(resourceXsdSchemaElementBefore);
CapabilitiesType capabilities = resourceBefore.getCapabilities();
if (capabilities != null) {
AssertJUnit.assertNull("Native capabilities present before test connection. Bad test setup?", capabilities.getNative());
}
// WHEN
OperationResult testResult = modelService.testResource(getResourceOid(), task);
// THEN
display("Test result", testResult);
TestUtil.assertSuccess("Test resource failed (result)", testResult);
PrismObject<ResourceType> resourceRepoAfter = repositoryService.getObject(ResourceType.class, getResourceOid(), null, result);
ResourceType resourceTypeRepoAfter = resourceRepoAfter.asObjectable();
display("Resource after test", resourceTypeRepoAfter);
XmlSchemaType xmlSchemaTypeAfter = resourceTypeRepoAfter.getSchema();
assertNotNull("No schema after test connection", xmlSchemaTypeAfter);
Element resourceXsdSchemaElementAfter = ResourceTypeUtil.getResourceXsdSchema(resourceTypeRepoAfter);
assertNotNull("No schema after test connection", resourceXsdSchemaElementAfter);
String resourceXml = prismContext.serializeObjectToString(resourceRepoAfter, PrismContext.LANG_XML);
display("Resource XML", resourceXml);
CachingMetadataType cachingMetadata = xmlSchemaTypeAfter.getCachingMetadata();
assertNotNull("No caching metadata", cachingMetadata);
assertNotNull("No retrievalTimestamp", cachingMetadata.getRetrievalTimestamp());
assertNotNull("No serialNumber", cachingMetadata.getSerialNumber());
Element xsdElement = ObjectTypeUtil.findXsdElement(xmlSchemaTypeAfter);
ResourceSchema parsedSchema = ResourceSchemaImpl.parse(xsdElement, resourceBefore.toString(), prismContext);
assertNotNull("No schema after parsing", parsedSchema);
// schema will be checked in next test
}
Aggregations