Search in sources :

Example 31 with SchemaRegistry

use of com.evolveum.midpoint.prism.schema.SchemaRegistry in project midpoint by Evolveum.

the class ConsistencyTest method test000Integrity.

/**
	 * Test integrity of the test setup.
	 */
@Test
public void test000Integrity() throws Exception {
    final String TEST_NAME = "test000Integrity";
    TestUtil.displayTestTile(this, TEST_NAME);
    assertNotNull(modelWeb);
    assertNotNull(modelService);
    assertNotNull(repositoryService);
    assertTrue(isSystemInitialized());
    assertNotNull(taskManager);
    assertNotNull(prismContext);
    SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
    assertNotNull(schemaRegistry);
    // This is defined in extra schema. So this effectively checks whether
    // the extra schema was loaded
    PrismPropertyDefinition shipStateDefinition = schemaRegistry.findPropertyDefinitionByElementName(MY_SHIP_STATE);
    assertNotNull("No my:shipState definition", shipStateDefinition);
    assertEquals("Wrong maxOccurs in my:shipState definition", 1, shipStateDefinition.getMaxOccurs());
    assertNoRepoCache();
    OperationResult result = new OperationResult(ConsistencyTest.class.getName() + "." + TEST_NAME);
    // Check if OpenDJ resource was imported correctly
    PrismObject<ResourceType> openDjResource = repositoryService.getObject(ResourceType.class, RESOURCE_OPENDJ_OID, null, result);
    display("Imported OpenDJ resource (repository)", openDjResource);
    AssertJUnit.assertEquals(RESOURCE_OPENDJ_OID, openDjResource.getOid());
    assertNoRepoCache();
    String ldapConnectorOid = openDjResource.asObjectable().getConnectorRef().getOid();
    PrismObject<ConnectorType> ldapConnector = repositoryService.getObject(ConnectorType.class, ldapConnectorOid, null, result);
    display("LDAP Connector: ", ldapConnector);
}
Also used : ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 32 with SchemaRegistry

use of com.evolveum.midpoint.prism.schema.SchemaRegistry in project midpoint by Evolveum.

the class TestPrismContext method testPrefixMapper.

@Test
public void testPrefixMapper() throws SchemaException, SAXException, IOException {
    System.out.println("===[ testPrefixMapper ]===");
    // WHEN
    PrismContextImpl prismContext = constructInitializedPrismContext();
    // THEN
    assertNotNull("No prism context", prismContext);
    SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
    assertNotNull("No schema registry in context", schemaRegistry);
    DynamicNamespacePrefixMapper prefixMapper = schemaRegistry.getNamespacePrefixMapper();
    System.out.println("Prefix mapper:");
    System.out.println(DebugUtil.dump(prefixMapper));
    assertEquals("Wrong foo prefix", "", prefixMapper.getPrefix(NS_FOO));
    assertEquals("Wrong xsd prefix", DOMUtil.NS_W3C_XML_SCHEMA_PREFIX, prefixMapper.getPrefix(XMLConstants.W3C_XML_SCHEMA_NS_URI));
}
Also used : SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) DynamicNamespacePrefixMapper(com.evolveum.midpoint.prism.xml.DynamicNamespacePrefixMapper) Test(org.testng.annotations.Test)

Example 33 with SchemaRegistry

use of com.evolveum.midpoint.prism.schema.SchemaRegistry in project midpoint by Evolveum.

the class TestPrismContext method testExtensionSchema.

@Test
public void testExtensionSchema() throws SchemaException, SAXException, IOException {
    System.out.println("===[ testExtensionSchema ]===");
    // GIVEN
    PrismContext prismContext = constructInitializedPrismContext();
    assertNotNull("No prism context", prismContext);
    SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
    assertNotNull("No schema registry in context", schemaRegistry);
    PrismPropertyDefinition ignoredTypeDef = schemaRegistry.findPropertyDefinitionByElementName(EXTENSION_IGNORED_TYPE_ELEMENT);
    PrismAsserts.assertDefinition(ignoredTypeDef, EXTENSION_IGNORED_TYPE_ELEMENT, DOMUtil.XSD_STRING, 0, -1);
    assertTrue("Element " + EXTENSION_IGNORED_TYPE_ELEMENT + " is NOT ignored", ignoredTypeDef.isIgnored());
    PrismPropertyDefinition stringTypeDef = schemaRegistry.findPropertyDefinitionByElementName(EXTENSION_STRING_TYPE_ELEMENT);
    PrismAsserts.assertDefinition(stringTypeDef, EXTENSION_STRING_TYPE_ELEMENT, DOMUtil.XSD_STRING, 0, -1);
    assertFalse("Element " + EXTENSION_STRING_TYPE_ELEMENT + " is ignored", stringTypeDef.isIgnored());
    PrismPropertyDefinition singleStringTypeDef = schemaRegistry.findPropertyDefinitionByElementName(EXTENSION_SINGLE_STRING_TYPE_ELEMENT);
    PrismAsserts.assertDefinition(singleStringTypeDef, EXTENSION_SINGLE_STRING_TYPE_ELEMENT, DOMUtil.XSD_STRING, 0, 1);
    assertFalse("Element " + EXTENSION_SINGLE_STRING_TYPE_ELEMENT + " is ignored", singleStringTypeDef.isIgnored());
    PrismPropertyDefinition intTypeDef = schemaRegistry.findPropertyDefinitionByElementName(EXTENSION_INT_TYPE_ELEMENT);
    PrismAsserts.assertDefinition(intTypeDef, EXTENSION_INT_TYPE_ELEMENT, DOMUtil.XSD_INT, 0, -1);
    assertFalse("Element " + EXTENSION_INT_TYPE_ELEMENT + " is ignored", intTypeDef.isIgnored());
    PrismContainerDefinition meleeContextDefinition = schemaRegistry.findContainerDefinitionByElementName(EXTENSION_MELEE_CONTEXT_ELEMENT);
    PrismAsserts.assertDefinition(meleeContextDefinition, EXTENSION_MELEE_CONTEXT_ELEMENT, EXTENSION_MELEE_CONTEXT_TYPE_QNAME, 0, 1);
    assertTrue("Melee context container is NOT marked as runtime", meleeContextDefinition.isRuntimeSchema());
    PrismReferenceDefinition opponentRefDef = meleeContextDefinition.findReferenceDefinition(EXTENSION_MELEE_CONTEXT_OPPONENT_REF_ELEMENT);
    assertTrue("opponentRef definition is NOT composite", opponentRefDef.isComposite());
}
Also used : SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) Test(org.testng.annotations.Test)

Example 34 with SchemaRegistry

use of com.evolveum.midpoint.prism.schema.SchemaRegistry in project midpoint by Evolveum.

the class TestSchemaRegistry method testCommonSchema.

@Test
public void testCommonSchema() throws SchemaException, SAXException, IOException {
    MidPointPrismContextFactory factory = getContextFactory();
    PrismContext context = factory.createInitializedPrismContext();
    SchemaRegistry schemaRegistry = context.getSchemaRegistry();
    PrismSchema commonSchema = schemaRegistry.findSchemaByNamespace(SchemaConstants.NS_C);
    assertNotNull("No parsed common schema", commonSchema);
    System.out.println("Parsed common schema:");
    System.out.println(commonSchema.debugDump());
// TODO
}
Also used : PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) Test(org.testng.annotations.Test)

Example 35 with SchemaRegistry

use of com.evolveum.midpoint.prism.schema.SchemaRegistry in project midpoint by Evolveum.

the class TestSchemaRegistry method testUserType.

@Test
public void testUserType() throws Exception {
    MidPointPrismContextFactory factory = getContextFactory();
    PrismContext context = factory.createInitializedPrismContext();
    SchemaRegistry schemaRegistry = context.getSchemaRegistry();
    PrismObjectDefinition<UserType> userDefinition = schemaRegistry.findObjectDefinitionByCompileTimeClass(UserType.class);
    assertNotNull("No user definition", userDefinition);
    System.out.println("testUserType:");
    System.out.println(userDefinition.debugDump());
    assertFalse("User definition is marked as runtime", userDefinition.isRuntimeSchema());
    PrismPropertyDefinition<PolyString> nameDef = userDefinition.findPropertyDefinition(ObjectType.F_NAME);
    assertNotNull("No name definition", nameDef);
    PrismContainerDefinition extensionDef = userDefinition.findContainerDefinition(UserType.F_EXTENSION);
    assertNotNull("No 'extension' definition", extensionDef);
    assertTrue("Extension definition is NOT marked as runtime", extensionDef.isRuntimeSchema());
    PrismPropertyDefinition<PolyString> givenNameDef = userDefinition.findPropertyDefinition(UserType.F_GIVEN_NAME);
    assertNotNull("No givenName definition", givenNameDef);
    PrismPropertyDefinition<String> preferredLanguageDef = userDefinition.findPropertyDefinition(UserType.F_PREFERRED_LANGUAGE);
    assertNotNull("No preferredLanguage definition", preferredLanguageDef);
    PrismReferenceValue preferredLanguageValueEnumerationRef = preferredLanguageDef.getValueEnumerationRef();
    assertNotNull("No valueEnumerationRef in preferredLanguage definition", preferredLanguageValueEnumerationRef);
    assertEquals("Wrong OID in valueEnumerationRef in preferredLanguage definition", SystemObjectsType.LOOKUP_LANGUAGES.value(), preferredLanguageValueEnumerationRef.getOid());
    assertEquals("Wrong type in valueEnumerationRef in preferredLanguage definition", LookupTableType.COMPLEX_TYPE, preferredLanguageValueEnumerationRef.getTargetType());
    // Just make sure this does not end with NPE or stack overflow
    PrismObjectDefinition<UserType> shallowClone = userDefinition.clone();
    PrismObjectDefinition<UserType> deepClone = userDefinition.deepClone(false);
    PrismObjectDefinition<UserType> ultraDeepClone = userDefinition.deepClone(true);
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Aggregations

SchemaRegistry (com.evolveum.midpoint.prism.schema.SchemaRegistry)39 Test (org.testng.annotations.Test)26 PrismContext (com.evolveum.midpoint.prism.PrismContext)10 PrismSchema (com.evolveum.midpoint.prism.schema.PrismSchema)9 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)9 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)6 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)6 Task (com.evolveum.midpoint.task.api.Task)6 QName (javax.xml.namespace.QName)6 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)5 ConnectorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType)4 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)4 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)3 PrismObjectDefinition (com.evolveum.midpoint.prism.PrismObjectDefinition)3 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 ConnectorConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType)3 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)2 EncryptionException (com.evolveum.midpoint.prism.crypto.EncryptionException)2