Exemplo n.º 1
0
    async def test_type_attribute_proj(self):
        """Test resolving a type attribute with a replace as foreign key operation"""
        test_name = 'test_type_attribute_proj'
        entity_name = 'Person'
        corpus = ProjectionTestUtils.get_corpus(test_name, self.tests_subpath)
        corpus = ProjectionTestUtils.get_corpus(test_name, self.tests_subpath)

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(
                self, corpus, test_name, self.tests_subpath, entity_name,
                res_opt)

        entity = await corpus.fetch_object_async(
            'local:/{}.cdm.json/{}'.format(entity_name, entity_name))
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(
            corpus, entity, ['referenceOnly'])

        # Original set of attributes: ["name", "age", "address", "phoneNumber", "email"]
        # Replace as foreign key applied to "address", replace with "addressId"
        self.assertEqual(5, len(resolved_entity.attributes))
        self.assertEqual('name', resolved_entity.attributes[0].name)
        self.assertEqual('age', resolved_entity.attributes[1].name)
        self.assertEqual('addressId', resolved_entity.attributes[2].name)
        self.assertEqual('phoneNumber', resolved_entity.attributes[3].name)
        self.assertEqual('email', resolved_entity.attributes[4].name)
Exemplo n.º 2
0
    async def test_nested_proj(self):
        """Nested projections with AddAttributeGroup"""
        test_name = 'test_nested_proj'
        entity_name = 'NewPerson'
        corpus = ProjectionTestUtils.get_local_corpus(
            self.tests_subpath, test_name)  # type: CdmCorpusDefinition

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(
                self, corpus, test_name, self.tests_subpath, entity_name,
                res_opt)

        entity = await corpus.fetch_object_async(
            'local:/{0}.cdm.json/{0}'.format(entity_name)
        )  # type: CdmEntityDefinition
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(
            corpus, entity, [])

        # Original set of attributes: ['name', 'age', 'address', 'phoneNumber', 'email']
        outer_att_group = ProjectionTestUtils.validate_attribute_group(
            self, resolved_entity.attributes,
            'OuterAttributeGroup')  # type: CdmAttributeGroupDefinition
        inner_att_group = ProjectionTestUtils.validate_attribute_group(
            self, outer_att_group.members, 'InnerAttributeGroup')

        self.assertEqual(5, len(inner_att_group.members))
        self.assertEqual('name', inner_att_group.members[0].name)
        self.assertEqual('age', inner_att_group.members[1].name)
        self.assertEqual('address', inner_att_group.members[2].name)
        self.assertEqual('phoneNumber', inner_att_group.members[3].name)
        self.assertEqual('email', inner_att_group.members[4].name)
    async def test_entity_proj_using_object_model(self):
        """Test for creating a projection with an AddAttributeGroup operation on an entity definition using the object model"""
        test_name = 'test_entity_proj_using_object_model'
        corpus = ProjectionTestUtils.get_corpus(test_name, self.tests_subpath)
        local_root = corpus.storage.fetch_root_folder('local')

        # Create an entity
        entity = ProjectionTestUtils.create_entity(corpus, local_root)  # type: CdmEntityDefinition

        # Create a projection
        projection = ProjectionTestUtils.create_projection(corpus, local_root)  # type: CdmProjection

        # Create an AddAttributeGroup operation
        add_att_group_op = corpus.make_object(CdmObjectType.OPERATION_ADD_ATTRIBUTE_GROUP_DEF)  # type: CdmOperationAddAttributeGroup
        add_att_group_op.attribute_group_name = 'PersonAttributeGroup'
        projection.operations.append(add_att_group_op)

        # Create an entity reference to hold this projection
        projection_entity_ref = corpus.make_object(CdmObjectType.ENTITY_REF, None)  # type: CdmEntityReference
        projection_entity_ref.explicit_reference = projection

        # Set the entity's ExtendEntity to be the projection
        entity.extends_entity = projection_entity_ref

        # Resolve the entity
        resolved_entity = await entity.create_resolved_entity_async('Resolved_{}.cdm.json'.format(entity.entity_name), None, local_root)

        # Verify correctness of the resolved attributes after running the AddAttributeGroup operation
        # Original set of attributes: ['id', 'name', 'value', 'date']
        att_group_definition = self.validate_attribute_group(resolved_entity.attributes, 'PersonAttributeGroup')
        self.assertEqual(4, len(att_group_definition.members))
        self.assertEqual('id', att_group_definition.members[0].name)
        self.assertEqual('name', att_group_definition.members[1].name)
        self.assertEqual('value', att_group_definition.members[2].name)
        self.assertEqual('date', att_group_definition.members[3].name)
Exemplo n.º 4
0
    async def test_nested_proj_using_object_model(self):
        """Test for creating nested projections with ExcludeAttributes operations using the object model"""
        corpus = ProjectionTestUtils.get_local_corpus(
            self.tests_subpath, 'test_nested_proj_using_object_model')
        corpus.storage.mount(
            'local',
            LocalAdapter(
                TestHelper.get_actual_output_folder_path(
                    self.tests_subpath,
                    'test_nested_proj_using_object_model')))
        local_root = corpus.storage.fetch_root_folder('local')

        # Create an entity
        entity = ProjectionTestUtils.create_entity(corpus, local_root)

        # Create a projection
        projection = ProjectionTestUtils.create_projection(corpus, local_root)

        # Create an ExcludeAttributes operation
        exclude_attrs_op = corpus.make_object(
            CdmObjectType.OPERATION_EXCLUDE_ATTRIBUTES_DEF)
        exclude_attrs_op.exclude_attributes = ['id', 'date']
        projection.operations.append(exclude_attrs_op)

        # Create an entity reference to hold this projection
        projection_entity_ref = corpus.make_object(CdmObjectType.ENTITY_REF,
                                                   None)
        projection_entity_ref.explicit_reference = projection

        # Create another projection that uses the previous projection as its source
        projection2 = corpus.make_object(CdmObjectType.PROJECTION_DEF)
        projection2.source = projection_entity_ref

        # Create an ExcludeAttributes operation
        exclude_attrs_op2 = corpus.make_object(
            CdmObjectType.OPERATION_EXCLUDE_ATTRIBUTES_DEF)
        exclude_attrs_op2.exclude_attributes = ['value']
        projection2.operations.append(exclude_attrs_op2)

        # Create an entity reference to hold this projection
        projection_entity_ref2 = corpus.make_object(CdmObjectType.ENTITY_REF,
                                                    None)
        projection_entity_ref2.explicit_reference = projection2

        # Create an entity attribute that contains this projection and add this to the entity
        entity_attribute = corpus.make_object(
            CdmObjectType.ENTITY_ATTRIBUTE_DEF, 'TestEntityAttribute')
        entity_attribute.entity = projection_entity_ref2
        entity.attributes.append(entity_attribute)

        # Resolve the entity
        resolved_entity = await entity.create_resolved_entity_async(
            'Resolved_{}.cdm.json'.format(entity.entity_name), None,
            local_root)

        # Verify correctness of the resolved attributes after running the ExcludeAttributes operations
        # Original set of attributes: ['id', 'name', 'value', 'date']
        # Excluded attributes: ['id', 'date'], ['value']
        self.assertEqual(1, len(resolved_entity.attributes))
        self.assertEqual('name', resolved_entity.attributes[0].name)
Exemplo n.º 5
0
    async def test_combine_ops_proj(self):
        """Test AddAttributeGroup and IncludeAttributes operations in the same projection"""
        test_name = 'test_combine_ops_proj'
        entity_name = 'NewPerson'
        corpus = ProjectionTestUtils.get_local_corpus(
            self.tests_subpath, test_name)  # type: CdmCorpusDefinition

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(
                self, corpus, test_name, self.tests_subpath, entity_name,
                res_opt)

        entity = await corpus.fetch_object_async(
            'local:/{0}.cdm.json/{0}'.format(entity_name)
        )  # type: CdmEntityDefinition
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(
            corpus, entity, [])

        # Original set of attributes: ['name', 'age', 'address', 'phoneNumber', 'email']
        # Included attributes: ['age', 'phoneNumber']
        att_group_definition = ProjectionTestUtils.validate_attribute_group(
            self, resolved_entity.attributes, 'PersonAttributeGroup', 3)
        self.assertEqual(5, len(att_group_definition.members))
        self.assertEqual('name', att_group_definition.members[0].name)
        self.assertEqual('age', att_group_definition.members[1].name)
        self.assertEqual('address', att_group_definition.members[2].name)
        self.assertEqual('phoneNumber', att_group_definition.members[3].name)
        self.assertEqual('email', att_group_definition.members[4].name)

        # Check the attributes coming from the IncludeAttribute operation
        self.assertEqual('age', resolved_entity.attributes[1].name)
        self.assertEqual('phoneNumber', resolved_entity.attributes[2].name)
Exemplo n.º 6
0
    async def test_type_attribute_proj(self):
        """Test resolving a type attribute with an add attribute group operation"""
        test_name = 'test_type_attribute_proj'
        entity_name = 'Person'
        corpus = ProjectionTestUtils.get_local_corpus(
            self.tests_subpath, test_name)  # type: CdmCorpusDefinition

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(
                self, corpus, test_name, self.tests_subpath, entity_name,
                res_opt)

        entity = await corpus.fetch_object_async(
            'local:/{0}.cdm.json/{0}'.format(entity_name)
        )  # type: CdmEntityDefinition
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(
            corpus, entity, [])

        # Original set of attributes: ['name', 'age', 'address', 'phoneNumber', 'email']
        self.assertEqual(5, len(resolved_entity.attributes))
        self.assertEqual('name', resolved_entity.attributes[0].name)
        self.assertEqual('age', resolved_entity.attributes[1].name)
        att_group_definition = ProjectionTestUtils.validate_attribute_group(
            self, resolved_entity.attributes, 'AddressAttributeGroup', 5, 2)
        self.assertEqual('address', att_group_definition.members[0].name)
        self.assertEqual('phoneNumber', resolved_entity.attributes[3].name)
        self.assertEqual('email', resolved_entity.attributes[4].name)
Exemplo n.º 7
0
    async def test_entity_attribute(self):
        """Test resolving an entity attribute using resolution guidance"""
        test_name = 'test_entity_attribute'
        entity_name = 'NewPerson'
        corpus = ProjectionTestUtils.get_local_corpus(
            self.tests_subpath, test_name)  # type: CdmCorpusDefinition

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(
                self, corpus, test_name, self.tests_subpath, entity_name,
                res_opt)

        entity = await corpus.fetch_object_async(
            'local:/{0}.cdm.json/{0}'.format(entity_name)
        )  # type: CdmEntityDefinition
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(
            corpus, entity, ['structured'])

        # Original set of attributes: ['name', 'age', 'address', 'phoneNumber', 'email']
        att_group_definition = ProjectionTestUtils.validate_attribute_group(
            self, resolved_entity.attributes, 'PersonInfo')
        self.assertEqual(5, len(att_group_definition.members))
        self.assertEqual('name', att_group_definition.members[0].name)
        self.assertEqual('age', att_group_definition.members[1].name)
        self.assertEqual('address', att_group_definition.members[2].name)
        self.assertEqual('phoneNumber', att_group_definition.members[3].name)
        self.assertEqual('email', att_group_definition.members[4].name)
Exemplo n.º 8
0
    async def test_conditional_proj_using_object_model(self):
        """Test for creating a projection with an AddCountAttribute operation and a condition using the object model"""
        corpus = ProjectionTestUtils.get_local_corpus(self.tests_subpath, 'test_conditional_proj_using_object_model')
        corpus.storage.mount('local', LocalAdapter(TestHelper.get_actual_output_folder_path(self.tests_subpath, 'test_conditional_proj_using_object_model')))
        local_root = corpus.storage.fetch_root_folder('local')

        # Create an entity
        entity = ProjectionTestUtils.create_entity(corpus, local_root)

        # Create a projection with a condition that states the operation should only execute when the resolution directive is 'referenceOnly'
        projection = ProjectionTestUtils.create_projection(corpus, local_root)
        projection.condition = 'referenceOnly==True'

        # Create an AddCountAttribute operation
        add_count_attr_op = corpus.make_object(CdmObjectType.OPERATION_ADD_COUNT_ATTRIBUTE_DEF)
        add_count_attr_op.count_attribute = corpus.make_object(CdmObjectType.TYPE_ATTRIBUTE_DEF, 'testCount')
        add_count_attr_op.count_attribute.data_type = corpus.make_ref(CdmObjectType.DATA_TYPE_REF, 'integer', True)
        projection.operations.append(add_count_attr_op)

        # Create an entity reference to hold this projection
        projection_entity_ref = corpus.make_object(CdmObjectType.ENTITY_REF, None)
        projection_entity_ref.explicit_reference = projection

        # Create an entity attribute that contains this projection and add this to the entity
        entity_attribute = corpus.make_object(CdmObjectType.ENTITY_ATTRIBUTE_DEF, 'TestEntityAttribute')
        entity_attribute.entity = projection_entity_ref
        entity.attributes.append(entity_attribute)

        # Create resolution options with the 'referenceOnly' directive
        res_opt = ResolveOptions(entity.in_document)
        res_opt.directives = AttributeResolutionDirectiveSet(set(['referenceOnly']))

        # Resolve the entity with 'referenceOnly'
        resolved_entity_with_reference_only = await entity.create_resolved_entity_async('Resolved_{}.cdm.json'.format(entity.entity_name), res_opt, local_root)

        # Verify correctness of the resolved attributes after running the AddCountAttribute operation
        # Original set of attributes: ["id", "name", "value", "date"]
        # Count attribute: "testCount"
        self.assertEqual(5, len(resolved_entity_with_reference_only.attributes))
        self.assertEqual('id', resolved_entity_with_reference_only.attributes[0].name)
        self.assertEqual('name', resolved_entity_with_reference_only.attributes[1].name)
        self.assertEqual('value', resolved_entity_with_reference_only.attributes[2].name)
        self.assertEqual('date', resolved_entity_with_reference_only.attributes[3].name)
        self.assertEqual('testCount', resolved_entity_with_reference_only.attributes[4].name)
        self.assertIsNotNone(resolved_entity_with_reference_only.attributes[4].applied_traits.item('is.linkedEntity.array.count'))

        # Now resolve the entity with the 'structured' directive
        res_opt.directives = AttributeResolutionDirectiveSet(set(['structured']))
        resolved_entity_with_structured = await entity.create_resolved_entity_async('Resolved_{}.cdm.json'.format(entity.entity_name), res_opt, local_root)

        # Verify correctness of the resolved attributes after running the AddCountAttribute operation
        # Original set of attributes: ["id", "name", "value", "date"]
        # No Count attribute added, condition was false
        self.assertEqual(4, len(resolved_entity_with_structured.attributes))
        self.assertEqual('id', resolved_entity_with_structured.attributes[0].name)
        self.assertEqual('name', resolved_entity_with_structured.attributes[1].name)
        self.assertEqual('value', resolved_entity_with_structured.attributes[2].name)
        self.assertEqual('date', resolved_entity_with_structured.attributes[3].name)
Exemplo n.º 9
0
    async def test_entity_attribute(self):
        """Test map type on an entity attribute"""
        test_name = 'test_entity_attribute'
        entity_name = 'ThreeMusketeers'
        corpus = ProjectionTestUtils.get_local_corpus(self.tests_subpath, test_name)  # type: CdmCorpusDefinition

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(self, corpus, test_name, self.tests_subpath, entity_name, res_opt)

        entity = await corpus.fetch_object_async('local:/{0}.cdm.json/{0}'.format(entity_name))  # type: CdmEntityDefinition
        non_structured_resolved_entity = await ProjectionTestUtils.get_resolved_entity(corpus, entity, [ ])

        # Original set of attributes: ["name", "age", "address"]
        # in non-structured form
        # addArtifactAttribute : { "key" , "insertAtTop": true }
        # Expand 1...3;
        # renameAttributes = { {a}_{o}_key, apply to "key" }
        # renameAttributes = { {a}_{m}_{o}_value, apply to "name", "age", "address" }
        # alterTraits = { indicates.expansionInfo.mapKey(expansionName: "{a}", ordinal: "{o}") , apply to "key" , "argumentsContainWildcards" : true }
        # alterTraits = { has.expansionInfo.mapValue(expansionName: "{a}", ordinal: "{o}", memberAttribute: "{mo}") , apply to "name", "age", "address"  , "argumentsContainWildcards" : true }
        # addArtifactAttribute : "personCount"
        # alterTraits = { indicates.expansionInfo.count(expansionName: "{a}") , apply to "personCount" , "argumentsContainWildcards" : true }
        self.assertEqual(13, len(non_structured_resolved_entity.attributes))
        self.validate_attribute_trait(non_structured_resolved_entity.attributes[0], 'key_1_key', 1, 'ThreePeople', is_key=True)
        self.validate_attribute_trait(non_structured_resolved_entity.attributes[1], 'ThreePeople_name_1_value', 1, 'ThreePeople', 'name')
        self.validate_attribute_trait(non_structured_resolved_entity.attributes[2], 'ThreePeople_age_1_value', 1, 'ThreePeople', 'age')
        self.validate_attribute_trait(non_structured_resolved_entity.attributes[3], 'ThreePeople_address_1_value', 1, 'ThreePeople', 'address')
        self.validate_attribute_trait(non_structured_resolved_entity.attributes[4], 'key_2_key', 2, 'ThreePeople', is_key=True)
        self.validate_attribute_trait(non_structured_resolved_entity.attributes[5], 'ThreePeople_name_2_value', 2, 'ThreePeople', 'name')
        self.validate_attribute_trait(non_structured_resolved_entity.attributes[6], 'ThreePeople_age_2_value', 2, 'ThreePeople', 'age')
        self.validate_attribute_trait(non_structured_resolved_entity.attributes[7], 'ThreePeople_address_2_value', 2, 'ThreePeople', 'address')
        self.validate_attribute_trait(non_structured_resolved_entity.attributes[8], 'key_3_key', 3, 'ThreePeople', is_key=True)
        self.validate_attribute_trait(non_structured_resolved_entity.attributes[9], 'ThreePeople_name_3_value', 3, 'ThreePeople', 'name')
        self.validate_attribute_trait(non_structured_resolved_entity.attributes[10], 'ThreePeople_age_3_value', 3, 'ThreePeople', 'age')
        self.validate_attribute_trait(non_structured_resolved_entity.attributes[11], 'ThreePeople_address_3_value', 3, 'ThreePeople', 'address')
        self.assertEqual("personCount", (non_structured_resolved_entity.attributes[12]).name)
        self.assertEqual("indicates.expansionInfo.count", non_structured_resolved_entity.attributes[12].applied_traits[1].named_reference)
        self.assertEqual("ThreePeople", non_structured_resolved_entity.attributes[12].applied_traits[1].arguments[0].value)

        # Original set of attributes: ["name", "age", "address"]
        # in structured form
        # addAttributeGroup: favorite people
        # alterTraits = { is.dataFormat.mapValue }
        # addArtifactAttribute : { "favorite People Key" (with trait "is.dataFormat.mapKey") , "insertAtTop": true }
        # addAttributeGroup: favorite People Group
        # alterTraits = { is.dataFormat.map }
        structured_resolved_entity = await ProjectionTestUtils.get_resolved_entity(corpus, entity, [ 'structured' ])
        self.assertEqual(1, len(structured_resolved_entity.attributes))
        att_group_definition = ProjectionTestUtils.validate_attribute_group(self, structured_resolved_entity.attributes, 'favorite People Group')  # type: CdmAttributeGroupDefinition
        self.assertIsNotNone(att_group_definition.exhibits_traits.item('is.dataFormat.map'))
        self.assertEqual("favorite People Key", att_group_definition.members[0].name)
        self.assertIsNotNone(att_group_definition.members[0].applied_traits.item('is.dataFormat.mapKey'))
        self.assertEqual(CdmObjectType.ATTRIBUTE_GROUP_REF, att_group_definition.members[1].object_type)
        inner_att_group_ref = att_group_definition.members[1]  # type: CdmAttributeGroupReference
        self.assertIsNotNone(inner_att_group_ref.explicit_reference)
        inner_att_group_definition = inner_att_group_ref.explicit_reference  # type: CdmAttributeGroupDefinition
        self.assertEqual('favorite people', inner_att_group_definition.attribute_group_name)
        self.assertIsNotNone(inner_att_group_definition.exhibits_traits.item('is.dataFormat.mapValue'))
Exemplo n.º 10
0
    async def test_entity_attribute_proj_using_object_model(self):
        """Test for creating a projection with an AddTypeAttribute operation on an entity attribute using the object model"""
        corpus = ProjectionTestUtils.get_local_corpus(
            self.tests_subpath,
            'test_entity_attribute_proj_using_object_model')
        corpus.storage.mount(
            'local',
            LocalAdapter(
                TestHelper.get_actual_output_folder_path(
                    self.tests_subpath,
                    'test_entity_attribute_proj_using_object_model')))
        local_root = corpus.storage.fetch_root_folder('local')

        # Create an entity
        entity = ProjectionTestUtils.create_entity(corpus, local_root)

        # Create a projection
        projection = ProjectionTestUtils.create_projection(corpus, local_root)

        # Create an AddTypeAttribute operation
        add_type_attr_op = corpus.make_object(
            CdmObjectType.OPERATION_ADD_TYPE_ATTRIBUTE_DEF)
        add_type_attr_op.type_attribute = corpus.make_object(
            CdmObjectType.TYPE_ATTRIBUTE_DEF, 'testType')
        add_type_attr_op.type_attribute.data_type = corpus.make_ref(
            CdmObjectType.DATA_TYPE_REF, 'entityName', True)
        projection.operations.append(add_type_attr_op)

        # Create an entity reference to hold this projection
        projection_entity_ref = corpus.make_object(CdmObjectType.ENTITY_REF,
                                                   None)
        projection_entity_ref.explicit_reference = projection

        # Create an entity attribute that contains this projection and add this to the entity
        entity_attribute = corpus.make_object(
            CdmObjectType.ENTITY_ATTRIBUTE_DEF, 'TestEntityAttribute')
        entity_attribute.entity = projection_entity_ref
        entity.attributes.append(entity_attribute)

        # Resolve the entity
        resolved_entity = await entity.create_resolved_entity_async(
            'Resolved_{}.cdm.json'.format(entity.entity_name), None,
            local_root)

        # Verify correctness of the resolved attributes after running the AddTypeAttribute operation
        # Original set of attributes: ["id", "name", "value", "date"]
        # Type attribute: "testType"
        self.assertEqual(5, len(resolved_entity.attributes))
        self.assertEqual('id', resolved_entity.attributes[0].name)
        self.assertEqual('name', resolved_entity.attributes[1].name)
        self.assertEqual('value', resolved_entity.attributes[2].name)
        self.assertEqual('date', resolved_entity.attributes[3].name)
        self.assertEqual('testType', resolved_entity.attributes[4].name)
        self.assertEqual(
            'is.linkedEntity.name',
            resolved_entity.attributes[4].applied_traits[4].named_reference)
    async def test_conditional_proj_using_object_model(self):
        """Test for creating a projection with an AddAttributeGroup operation and a condition using the object model"""
        test_name = 'test_conditional_proj_using_object_model'
        corpus = ProjectionTestUtils.get_corpus(test_name, self.tests_subpath)
        local_root = corpus.storage.fetch_root_folder('local')

        # Create an entity.
        entity = ProjectionTestUtils.create_entity(corpus, local_root)

        # Create a projection with a condition that states the operation should only execute when the resolution directive is 'structured'.
        projection = ProjectionTestUtils.create_projection(corpus, local_root)
        projection.condition = 'structured==true'

        # Create an AddAttributeGroup operation
        add_att_group_op = corpus.make_object(CdmObjectType.OPERATION_ADD_ATTRIBUTE_GROUP_DEF)
        add_att_group_op.attribute_group_name = 'PersonAttributeGroup'
        projection.operations.append(add_att_group_op)

        # Create an entity reference to hold this projection.
        projection_entity_ref = corpus.make_object(CdmObjectType.ENTITY_REF, None)  # type: CdmEntityReference
        projection_entity_ref.explicit_reference = projection

        # Create an entity attribute that contains this projection and add this to the entity.
        entity_attribute = corpus.make_object(CdmObjectType.ENTITY_ATTRIBUTE_DEF, 'TestEntityAttribute')  # type: CdmEntityAttributeDefinition
        entity_attribute.entity = projection_entity_ref
        entity.attributes.append(entity_attribute)

        # Create resolution options with the 'referenceOnly' directive.
        res_opt = ResolveOptions(entity.in_document)
        res_opt.directives = AttributeResolutionDirectiveSet({'referenceOnly'})

        # Resolve the entity with 'referenceOnly'
        resolved_entity_with_reference_only = await entity.create_resolved_entity_async('Resolved_{}.cdm.json'.format(entity.entity_name), res_opt, local_root)

        # Verify correctness of the resolved attributes after running the AddAttributeGroup operation
        # Original set of attributes: ['id', 'name', 'value', 'date']
        # Condition not met, keep attributes in flat list
        self.assertEqual(4, len(resolved_entity_with_reference_only.attributes))
        self.assertEqual('id', resolved_entity_with_reference_only.attributes[0].name)
        self.assertEqual('name', resolved_entity_with_reference_only.attributes[1].name)
        self.assertEqual('value', resolved_entity_with_reference_only.attributes[2].name)
        self.assertEqual('date', resolved_entity_with_reference_only.attributes[3].name)

        # Now resolve the entity with the 'structured' directive
        res_opt.directives = AttributeResolutionDirectiveSet({'structured'})
        resolved_entity_with_structured = await entity.create_resolved_entity_async('Resolved_{}.cdm.json'.format(entity.entity_name), res_opt, local_root)

        # Verify correctness of the resolved attributes after running the AddAttributeGroup operation
        # Original set of attributes: ['id', 'name', 'value', 'date']
        # Condition met, put all attributes in an attribute group
        att_group_definition = self.validate_attribute_group(resolved_entity_with_structured.attributes, 'PersonAttributeGroup')
        self.assertEqual(4, len(att_group_definition.members))
        self.assertEqual('id', att_group_definition.members[0].name)
        self.assertEqual('name', att_group_definition.members[1].name)
        self.assertEqual('value', att_group_definition.members[2].name)
        self.assertEqual('date', att_group_definition.members[3].name)
Exemplo n.º 12
0
    async def test_entity_attribute_proj_using_object_model(self):
        """Test for creating a projection with an ArrayExpansion operation on an entity attribute using the object model"""
        corpus = TestHelper.get_local_corpus(self.tests_subpath, 'test_entity_attribute_proj_using_object_model')
        corpus.storage.mount('local', LocalAdapter(TestHelper.get_actual_output_folder_path(self.tests_subpath, 'test_entity_attribute_proj_using_object_model')))
        local_root = corpus.storage.fetch_root_folder('local')

        # Create an entity
        entity = ProjectionTestUtils.create_entity(corpus, local_root)

        # Create a projection
        projection = ProjectionTestUtils.create_projection(corpus, local_root)

        # Create an ArrayExpansion operation
        array_expansion_op = corpus.make_object(CdmObjectType.OPERATION_ARRAY_EXPANSION_DEF)
        array_expansion_op.start_ordinal = 1
        array_expansion_op.end_ordinal = 2
        projection.operations.append(array_expansion_op)

        # Create an entity reference to hold this projection
        projection_entity_ref = corpus.make_object(CdmObjectType.ENTITY_REF, None)
        projection_entity_ref.explicit_reference = projection

        # Create another projection that does a rename so that we can see the expanded attributes in the final resolved entity
        projection2 = corpus.make_object(CdmObjectType.PROJECTION_DEF)
        projection2.source = projection_entity_ref

        # Create a RenameAttributes operation
        rename_attrs_op = corpus.make_object(CdmObjectType.OPERATION_RENAME_ATTRIBUTES_DEF)
        rename_attrs_op.rename_format = '{m}{o}'
        projection2.operations.append(rename_attrs_op)

        # Create an entity reference to hold this projection
        projection_entity_ref2 = corpus.make_object(CdmObjectType.ENTITY_REF, None)
        projection_entity_ref2.explicit_reference = projection2

        # Create an entity attribute that contains this projection and add this to the entity
        entity_attribute = corpus.make_object(CdmObjectType.ENTITY_ATTRIBUTE_DEF, 'TestEntityAttribute')
        entity_attribute.entity = projection_entity_ref2
        entity.attributes.append(entity_attribute)

        # Resolve the entity
        resolved_entity = await entity.create_resolved_entity_async('Resolved_{}.cdm.json'.format(entity.entity_name), None, local_root)

        # Verify correctness of the resolved attributes after running the projections
        # Original set of attributes: ["id", "name", "value", "date"]
        # Expand 1...2, renameFormat = {m}{o}
        self.assertEqual(8, len(resolved_entity.attributes))
        self.assertEqual('id1', resolved_entity.attributes[0].name)
        self.assertEqual('name1', resolved_entity.attributes[1].name)
        self.assertEqual('value1', resolved_entity.attributes[2].name)
        self.assertEqual('date1', resolved_entity.attributes[3].name)
        self.assertEqual('id2', resolved_entity.attributes[4].name)
        self.assertEqual('name2', resolved_entity.attributes[5].name)
        self.assertEqual('value2', resolved_entity.attributes[6].name)
        self.assertEqual('date2', resolved_entity.attributes[7].name)
Exemplo n.º 13
0
    async def test_conditional_proj(self):
        """AddTypeAttribute with a condition"""
        test_name = 'test_conditional_proj'
        entity_name = 'Customer'
        corpus = ProjectionTestUtils.get_local_corpus(self.tests_subpath,
                                                      test_name)

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(
                self, corpus, test_name, self.tests_subpath, entity_name,
                res_opt)

        entity = await corpus.fetch_object_async(
            'local:/{}.cdm.json/{}'.format(entity_name, entity_name))
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(
            corpus, entity, [])

        # Original set of attributes: ["emailId", "address", "isPrimary", "phoneId", "number", "socialId", "account"]
        # Merge ["emailId, "phoneId, "socialId"] into "contactId", type attribute: "contactType"
        # Condition for projection containing AddTypeAttribute is false, so no Type attribute is created
        self.assertEqual(5, len(resolved_entity.attributes))
        self.assertEqual('address', resolved_entity.attributes[0].name)
        self.assertEqual('isPrimary', resolved_entity.attributes[1].name)
        self.assertEqual('number', resolved_entity.attributes[2].name)
        self.assertEqual('account', resolved_entity.attributes[3].name)
        self.assertEqual('contactId', resolved_entity.attributes[4].name)
Exemplo n.º 14
0
    async def test_combine_ops_proj(self):
        """AddTypeAttribute with other operations in the same projection"""
        test_name = 'test_combine_ops_proj'
        entity_name = 'Customer'
        corpus = ProjectionTestUtils.get_local_corpus(self.tests_subpath,
                                                      test_name)

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(
                self, corpus, test_name, self.tests_subpath, entity_name,
                res_opt)

        entity = await corpus.fetch_object_async(
            'local:/{}.cdm.json/{}'.format(entity_name, entity_name))
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(
            corpus, entity, [])

        # Original set of attributes: ["emailId", "address", "isPrimary", "phoneId", "number", "socialId", "account"]
        # Type attribute: "someType", rename "address" to "homeAddress"
        self.assertEqual(9, len(resolved_entity.attributes))
        self.assertEqual('emailId', resolved_entity.attributes[0].name)
        self.assertEqual('address', resolved_entity.attributes[1].name)
        self.assertEqual('isPrimary', resolved_entity.attributes[2].name)
        self.assertEqual('phoneId', resolved_entity.attributes[3].name)
        self.assertEqual('number', resolved_entity.attributes[4].name)
        self.assertEqual('socialId', resolved_entity.attributes[5].name)
        self.assertEqual('account', resolved_entity.attributes[6].name)
        self.assertEqual('someType', resolved_entity.attributes[7].name)
        self.assertEqual(
            'is.linkedEntity.name',
            resolved_entity.attributes[7].applied_traits[4].named_reference)
        self.assertEqual('homeAddress', resolved_entity.attributes[8].name)
Exemplo n.º 15
0
    async def test_combine_ops_nested_proj(self):
        """Nested projections with AddTypeAttribute and other operations"""
        test_name = 'test_combine_ops_nested_proj'
        entity_name = 'Customer'
        corpus = ProjectionTestUtils.get_local_corpus(self.tests_subpath,
                                                      test_name)

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(
                self, corpus, test_name, self.tests_subpath, entity_name,
                res_opt)

        entity = await corpus.fetch_object_async(
            'local:/{}.cdm.json/{}'.format(entity_name, entity_name))
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(
            corpus, entity, [])

        # Original set of attributes: ["emailId", "address", "isPrimary", "phoneId", "number", "socialId", "account"]
        # Merge ["emailId, "phoneId, "socialId"] into "contactId", type attribute: "contactType",
        # rename ["contactId", "isPrimary"] as "new_{m}", include ["contactId", "new_isPrimary", "contactType"]
        self.assertEqual(3, len(resolved_entity.attributes))
        self.assertEqual('new_contactId', resolved_entity.attributes[0].name)
        self.assertEqual('new_isPrimary', resolved_entity.attributes[1].name)
        self.assertEqual('contactType', resolved_entity.attributes[2].name)
        self.assertEqual(
            'is.linkedEntity.name',
            resolved_entity.attributes[2].applied_traits[4].named_reference)
Exemplo n.º 16
0
    async def test_extends_entity(self):
        """SelectedTypeAttribute on an entity definition"""
        test_name = 'test_extends_entity'
        entity_name = 'Customer'
        corpus = ProjectionTestUtils.get_local_corpus(self.tests_subpath,
                                                      test_name)

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(
                self, corpus, test_name, self.tests_subpath, entity_name,
                res_opt)

        entity = await corpus.fetch_object_async(
            'local:/{}.cdm.json/{}'.format(entity_name, entity_name))
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(
            corpus, entity, [])

        # Original set of attributes: ["emailId", "address", "isPrimary", "phoneId", "number", "socialId", "account"]
        # Type attribute: "someType" (using extendsEntityResolutionGuidance)
        self.assertEqual(8, len(resolved_entity.attributes))
        self.assertEqual('emailId', resolved_entity.attributes[0].name)
        self.assertEqual('address', resolved_entity.attributes[1].name)
        self.assertEqual('isPrimary', resolved_entity.attributes[2].name)
        self.assertEqual('phoneId', resolved_entity.attributes[3].name)
        self.assertEqual('number', resolved_entity.attributes[4].name)
        self.assertEqual('socialId', resolved_entity.attributes[5].name)
        self.assertEqual('account', resolved_entity.attributes[6].name)
        self.assertEqual('someType', resolved_entity.attributes[7].name)
        self.assertEqual(
            'is.linkedEntity.name',
            resolved_entity.attributes[7].applied_traits[4].named_reference)
Exemplo n.º 17
0
    async def test_add_type_with_combine_proj(self):
        """AddTypeAttribute on an entity attribute (after a CombineAttributes)"""
        test_name = 'test_add_type_with_combine_proj'
        entity_name = 'Customer'
        corpus = ProjectionTestUtils.get_local_corpus(self.tests_subpath,
                                                      test_name)

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(
                self, corpus, test_name, self.tests_subpath, entity_name,
                res_opt)

        entity = await corpus.fetch_object_async(
            'local:/{}.cdm.json/{}'.format(entity_name, entity_name))
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(
            corpus, entity, [])

        # Original set of attributes: ["emailId", "address", "isPrimary", "phoneId", "number", "socialId", "account"]
        # Merge ["emailId, "phoneId, "socialId"] into "contactId", type attribute: "contactType"
        self.assertEqual(6, len(resolved_entity.attributes))
        self.assertEqual('address', resolved_entity.attributes[0].name)
        self.assertEqual('isPrimary', resolved_entity.attributes[1].name)
        self.assertEqual('number', resolved_entity.attributes[2].name)
        self.assertEqual('account', resolved_entity.attributes[3].name)
        self.assertEqual('contactId', resolved_entity.attributes[4].name)
        self.assertEqual('contactType', resolved_entity.attributes[5].name)
        self.assertEqual(
            'is.linkedEntity.name',
            resolved_entity.attributes[5].applied_traits[4].named_reference)
Exemplo n.º 18
0
    async def test_group(self):
        """Expansion on an entity with an attribute group"""
        test_name = 'test_group'
        entity_name = 'ThreeMusketeers'
        corpus = ProjectionTestUtils.get_corpus(test_name, self.tests_subpath)

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(self, corpus, test_name, self.tests_subpath, entity_name, res_opt)

        entity = await corpus.fetch_object_async('local:/{}.cdm.json/{}'.format(entity_name, entity_name))
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(corpus, entity, [])

        # Original set of attributes: ["name", "age", "address"]
        # Expand 1...3, renameFormat = {m}{o}
        self.assertEqual(10, len(resolved_entity.attributes))
        self.assertEqual('count', resolved_entity.attributes[0].name)
        self.assertEqual('name1', resolved_entity.attributes[1].name)
        self.assertEqual('age1', resolved_entity.attributes[2].name)
        self.assertEqual('address1', resolved_entity.attributes[3].name)
        self.assertEqual('name2', resolved_entity.attributes[4].name)
        self.assertEqual('age2', resolved_entity.attributes[5].name)
        self.assertEqual('address2', resolved_entity.attributes[6].name)
        self.assertEqual('name3', resolved_entity.attributes[7].name)
        self.assertEqual('age3', resolved_entity.attributes[8].name)
        self.assertEqual('address3', resolved_entity.attributes[9].name)
    async def test_conditional_proj(self):
        """ExcludeAttributes with a condition"""
        test_name = 'test_conditional_proj'
        entity_name = 'NewPerson'
        corpus = ProjectionTestUtils.get_corpus(test_name, self.tests_subpath)

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(
                self, corpus, test_name, self.tests_subpath, entity_name,
                res_opt)

        entity = await corpus.fetch_object_async(
            'local:/{}.cdm.json/{}'.format(entity_name, entity_name))
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(
            corpus, entity, ['referenceOnly'])

        # Original set of attributes: ['name', 'age', 'address', 'phoneNumber', 'email']
        # Excluded attributes: ['address', 'phoneNumber', 'email']
        self.assertEqual(2, len(resolved_entity.attributes))
        self.assertEqual('name', resolved_entity.attributes[0].name)
        self.assertEqual('age', resolved_entity.attributes[1].name)

        resolved_entity2 = await ProjectionTestUtils.get_resolved_entity(
            corpus, entity, [])

        # Original set of attributes: ['name', 'age', 'address', 'phoneNumber', 'email']
        # Excluded attributes: none, condition was false
        self.assertEqual(5, len(resolved_entity2.attributes))
        self.assertEqual('name', resolved_entity2.attributes[0].name)
        self.assertEqual('age', resolved_entity2.attributes[1].name)
        self.assertEqual('address', resolved_entity2.attributes[2].name)
        self.assertEqual('phoneNumber', resolved_entity2.attributes[3].name)
        self.assertEqual('email', resolved_entity2.attributes[4].name)
Exemplo n.º 20
0
    async def test_array_source(self):
        """
        Expansion on an array source
        NOTE: This is not supported in resolution guidance due to ordinals from a previous resolution guidance
        not being removed for the next resolution guidance, resulting in ordinals being skipped over in the new
        resolution guidance as it thinks it has already done that round
        """
        test_name = 'test_array_source'
        entity_name = 'FriendGroup'
        corpus = ProjectionTestUtils.get_corpus(test_name, self.tests_subpath)

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(self, corpus, test_name, self.tests_subpath, entity_name, res_opt)

        entity = await corpus.fetch_object_async('local:/{}.cdm.json/{}'.format(entity_name, entity_name))
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(corpus, entity, [])

        # Original set of attributes: ["personCount", "name1", "age1", "address1", "name2", "age2", "address2"]
        # Expand 1...2, renameFormat = {m}_{o}
        # Since resolution guidance doesn't support doing an expansion on an array source, we end up with the
        # following result where it skips expanding attributes with the same ordinal (ex. name1_1, name2_2)
        self.assertEqual(9, len(resolved_entity.attributes))
        self.assertEqual('count_', resolved_entity.attributes[0].name)
        self.assertEqual('personCount_1', resolved_entity.attributes[1].name)
        self.assertEqual('name2_1', resolved_entity.attributes[2].name)
        self.assertEqual('age2_1', resolved_entity.attributes[3].name)
        self.assertEqual('address2_1', resolved_entity.attributes[4].name)
        self.assertEqual('personCount_2', resolved_entity.attributes[5].name)
        self.assertEqual('name1_2', resolved_entity.attributes[6].name)
        self.assertEqual('age1_2', resolved_entity.attributes[7].name)
        self.assertEqual('address1_2', resolved_entity.attributes[8].name)
Exemplo n.º 21
0
    async def test_array_source_proj(self):
        """ArrayExpansion on an array source"""
        test_name = 'test_array_source_proj'
        entity_name = 'FriendGroup'
        corpus = ProjectionTestUtils.get_corpus(test_name, self.tests_subpath)

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(self, corpus, test_name, self.tests_subpath, entity_name, res_opt)

        entity = await corpus.fetch_object_async('local:/{}.cdm.json/{}'.format(entity_name, entity_name))
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(corpus, entity, [])

        # Original set of attributes: ["personCount", "name1", "age1", "address1", "name2", "age2", "address2"]
        # Expand 1...2, renameFormat = {m}_{o}
        self.assertEqual(14, len(resolved_entity.attributes))
        self.assertEqual('personCount_1', resolved_entity.attributes[0].name)
        self.assertEqual('name1_1', resolved_entity.attributes[1].name)
        self.assertEqual('age1_1', resolved_entity.attributes[2].name)
        self.assertEqual('address1_1', resolved_entity.attributes[3].name)
        self.assertEqual('name2_1', resolved_entity.attributes[4].name)
        self.assertEqual('age2_1', resolved_entity.attributes[5].name)
        self.assertEqual('address2_1', resolved_entity.attributes[6].name)
        self.assertEqual('personCount_2', resolved_entity.attributes[7].name)
        self.assertEqual('name1_2', resolved_entity.attributes[8].name)
        self.assertEqual('age1_2', resolved_entity.attributes[9].name)
        self.assertEqual('address1_2', resolved_entity.attributes[10].name)
        self.assertEqual('name2_2', resolved_entity.attributes[11].name)
        self.assertEqual('age2_2', resolved_entity.attributes[12].name)
        self.assertEqual('address2_2', resolved_entity.attributes[13].name)
Exemplo n.º 22
0
    async def test_polymorphic_proj(self):
        """ArrayExpansion on a polymorphic source"""
        test_name = 'test_polymorphic_proj'
        entity_name = 'BusinessPerson'
        corpus = ProjectionTestUtils.get_corpus(test_name, self.tests_subpath)

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(self, corpus, test_name, self.tests_subpath, entity_name, res_opt)

        entity = await corpus.fetch_object_async('local:/{}.cdm.json/{}'.format(entity_name, entity_name))
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(corpus, entity, [])

        # Original set of attributes: ["emailId", "address", "isPrimary", "phoneId", "number"]
        # Expand 1...2, renameFormat = {m}{o}
        self.assertEqual(10, len(resolved_entity.attributes))
        self.assertEqual('emailId1', resolved_entity.attributes[0].name)
        self.assertEqual('address1', resolved_entity.attributes[1].name)
        self.assertEqual('isPrimary1', resolved_entity.attributes[2].name)
        self.assertEqual('phoneId1', resolved_entity.attributes[3].name)
        self.assertEqual('number1', resolved_entity.attributes[4].name)
        self.assertEqual('emailId2', resolved_entity.attributes[5].name)
        self.assertEqual('address2', resolved_entity.attributes[6].name)
        self.assertEqual('isPrimary2', resolved_entity.attributes[7].name)
        self.assertEqual('phoneId2', resolved_entity.attributes[8].name)
        self.assertEqual('number2', resolved_entity.attributes[9].name)
    async def test_EA_name_proj(self):
        """
        ExcludeAttributes with an entity attribute name on an inline entity reference that contains entity attributes
        This is testing that, for the case of the structured directive, we can filter using the name of an entity attribute
        in the inline entity reference to exclude the entire entity attribute group
        """
        test_name = 'test_EA_name_proj'
        entity_name = 'NewPerson'
        corpus = ProjectionTestUtils.get_corpus(test_name, self.tests_subpath)

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(
                self, corpus, test_name, self.tests_subpath, entity_name,
                res_opt)

        entity = await corpus.fetch_object_async(
            'local:/{}.cdm.json/{}'.format(entity_name, entity_name))
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(
            corpus, entity, ['structured'])

        # Original set of attributes: ['name', 'age', 'address', 'phoneNumber', 'email', 'title', 'company', 'tenure']
        # Excluded attributes: ['OccupationInfo'] (name of entity attribute that contains 'title', 'company', 'tenure')
        self.assertEqual(
            1, len(resolved_entity.attributes)
        )  # attribute group created because of structured directive
        att_group = resolved_entity.attributes[0].explicit_reference
        self.assertEqual(5, len(att_group.members))
        self.assertEqual('name', att_group.members[0].name)
        self.assertEqual('age', att_group.members[1].name)
        self.assertEqual('address', att_group.members[2].name)
        self.assertEqual('phoneNumber', att_group.members[3].name)
        self.assertEqual('email', att_group.members[4].name)
    async def test_type_attribute_proj(self):
        """Test resolving a type attribute with an add supporting attribute operation"""
        test_name = 'test_type_attribute_proj'
        entity_name = 'NewPerson'
        corpus = ProjectionTestUtils.get_local_corpus(
            self.tests_subpath, test_name)  # type: CdmCorpusDefinition

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(
                self, corpus, test_name, self.tests_subpath, entity_name,
                res_opt)

        entity = await corpus.fetch_object_async(
            'local:/{0}.cdm.json/{0}'.format(entity_name)
        )  # type: CdmEntityDefinition
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(
            corpus, entity, ['referenceOnly'])  # type: CdmEntityDefinition

        # Original set of attributes: ["PersonInfo"]
        self.assertEqual(2, len(resolved_entity.attributes))
        self.assertEqual('PersonInfo', resolved_entity.attributes[0].name)
        supporting_attribute = resolved_entity.attributes[
            1]  # type: CdmTypeAttributeDefinition
        self.assertEqual('PersonInfo_display', supporting_attribute.name)
        self.validate_in_support_of_attribute(supporting_attribute,
                                              'PersonInfo', False)
    async def test_extends_entity_proj(self):
        """addSupportingAttribute on an entity definition"""
        test_name = 'test_extends_entity_proj'
        entity_name = 'NewPerson'
        corpus = ProjectionTestUtils.get_local_corpus(
            self.tests_subpath, test_name)  # type: CdmCorpusDefinition

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(
                self, corpus, test_name, self.tests_subpath, entity_name,
                res_opt)

        entity = await corpus.fetch_object_async(
            'local:/{0}.cdm.json/{0}'.format(entity_name)
        )  # type: CdmEntityDefinition
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(
            corpus, entity, [])  # type: CdmEntityDefinition

        # Original set of attributes: ['name', 'age', 'address', 'phoneNumber', 'email']
        # Supporting attribute: 'PersonInfo_display' (using extendsEntityResolutionGuidance)
        self.assertEqual(6, len(resolved_entity.attributes))
        self.assertEqual('name', resolved_entity.attributes[0].name)
        self.assertEqual('age', resolved_entity.attributes[1].name)
        self.assertEqual('address', resolved_entity.attributes[2].name)
        self.assertEqual('phoneNumber', resolved_entity.attributes[3].name)
        self.assertEqual('email', resolved_entity.attributes[4].name)
        self.assertEqual('PersonInfo_display',
                         resolved_entity.attributes[5].name)
        self.validate_in_support_of_attribute(resolved_entity.attributes[5],
                                              'email')
Exemplo n.º 26
0
    async def test_nested_proj(self):
        """Nested projections with ArrayExpansion"""
        test_name = 'test_nested_proj'
        entity_name = 'ThreeMusketeers'
        corpus = ProjectionTestUtils.get_corpus(test_name, self.tests_subpath)

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(self, corpus, test_name, self.tests_subpath, entity_name, res_opt)

        entity = await corpus.fetch_object_async('local:/{}.cdm.json/{}'.format(entity_name, entity_name))
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(corpus, entity, [])

        # Original set of attributes: ["name", "age", "address"]
        # Expand 1...3 and then 1...2, renameFormat = {m}_{o}
        self.assertEqual(18, len(resolved_entity.attributes))
        self.assertEqual('name_1_1', resolved_entity.attributes[0].name)
        self.assertEqual('age_1_1', resolved_entity.attributes[1].name)
        self.assertEqual('address_1_1', resolved_entity.attributes[2].name)
        self.assertEqual('name_2_1', resolved_entity.attributes[3].name)
        self.assertEqual('age_2_1', resolved_entity.attributes[4].name)
        self.assertEqual('address_2_1', resolved_entity.attributes[5].name)
        self.assertEqual('name_3_1', resolved_entity.attributes[6].name)
        self.assertEqual('age_3_1', resolved_entity.attributes[7].name)
        self.assertEqual('address_3_1', resolved_entity.attributes[8].name)
        self.assertEqual('name_1_2', resolved_entity.attributes[9].name)
        self.assertEqual('age_1_2', resolved_entity.attributes[10].name)
        self.assertEqual('address_1_2', resolved_entity.attributes[11].name)
        self.assertEqual('name_2_2', resolved_entity.attributes[12].name)
        self.assertEqual('age_2_2', resolved_entity.attributes[13].name)
        self.assertEqual('address_2_2', resolved_entity.attributes[14].name)
        self.assertEqual('name_3_2', resolved_entity.attributes[15].name)
        self.assertEqual('age_3_2', resolved_entity.attributes[16].name)
        self.assertEqual('address_3_2', resolved_entity.attributes[17].name)
    async def test_nested_proj(self):
        """Nested replaceAsForeignKey with addSupporingAttribute"""
        test_name = 'test_nested_proj'
        entity_name = 'NewPerson'
        corpus = ProjectionTestUtils.get_local_corpus(
            self.tests_subpath, test_name)  # type: CdmCorpusDefinition

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(
                self, corpus, test_name, self.tests_subpath, entity_name,
                res_opt)

        entity = await corpus.fetch_object_async(
            'local:/{0}.cdm.json/{0}'.format(entity_name)
        )  # type: CdmEntityDefinition
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(
            corpus, entity, ['referenceOnly'])  # type: CdmEntityDefinition

        # Original set of attributes: ['name', 'age', 'address', 'phoneNumber', 'email']
        self.assertEqual(2, len(resolved_entity.attributes))
        self.assertEqual('personId', resolved_entity.attributes[0].name)
        self.assertEqual('PersonInfo_display',
                         resolved_entity.attributes[1].name)
        self.validate_in_support_of_attribute(resolved_entity.attributes[1],
                                              'personId')
Exemplo n.º 28
0
    async def test_negative_start_ordinal(self):
        """Start and end ordinals of -2...2"""
        test_name = 'test_negative_start_ordinal'
        entity_name = 'ThreeMusketeers'
        corpus = ProjectionTestUtils.get_corpus(test_name, self.tests_subpath)

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(self, corpus, test_name, self.tests_subpath, entity_name, res_opt)

        entity = await corpus.fetch_object_async('local:/{}.cdm.json/{}'.format(entity_name, entity_name))
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(corpus, entity, [])

        # Original set of attributes: ["name", "age", "address"]
        # Expand -2...2, renameFormat = {m}{o}
        # Since we don't allow negative ordinals, output should be 0...2
        self.assertEqual(9, len(resolved_entity.attributes))
        self.assertEqual('name0', resolved_entity.attributes[0].name)
        self.assertEqual('age0', resolved_entity.attributes[1].name)
        self.assertEqual('address0', resolved_entity.attributes[2].name)
        self.assertEqual('name1', resolved_entity.attributes[3].name)
        self.assertEqual('age1', resolved_entity.attributes[4].name)
        self.assertEqual('address1', resolved_entity.attributes[5].name)
        self.assertEqual('name2', resolved_entity.attributes[6].name)
        self.assertEqual('age2', resolved_entity.attributes[7].name)
        self.assertEqual('address2', resolved_entity.attributes[8].name)
    async def test_combine_ops_proj(self):
        """AddSupportingAttribute with replaceAsForeignKey operation in the same projection"""
        test_name = 'test_combine_ops_proj'
        entity_name = 'NewPerson'
        corpus = ProjectionTestUtils.get_local_corpus(
            self.tests_subpath, test_name)  # type: CdmCorpusDefinition

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(
                self, corpus, test_name, self.tests_subpath, entity_name,
                res_opt)

        entity = await corpus.fetch_object_async(
            'local:/{0}.cdm.json/{0}'.format(entity_name)
        )  # type: CdmEntityDefinition
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(
            corpus, entity, [])  # type: CdmEntityDefinition

        # Original set of attributes: ['name', 'age', 'address', 'phoneNumber', 'email']
        # Supporting attribute: 'PersonInfo_display', rename 'address' to 'homeAddress'
        self.assertEqual(7, len(resolved_entity.attributes))
        self.assertEqual('name', resolved_entity.attributes[0].name)
        self.assertEqual('age', resolved_entity.attributes[1].name)
        self.assertEqual('homeAddress', resolved_entity.attributes[2].name)
        self.assertEqual('phoneNumber', resolved_entity.attributes[3].name)
        self.assertEqual('email', resolved_entity.attributes[4].name)
        self.assertEqual('address', resolved_entity.attributes[5].name)
        self.assertEqual('PersonInfo_display',
                         resolved_entity.attributes[6].name)
        self.validate_in_support_of_attribute(resolved_entity.attributes[6],
                                              'email')
Exemplo n.º 30
0
    async def test_start_GT_end_ordinal(self):
        """Start ordinal greater than end ordinal"""
        test_name = 'test_start_GT_end_ordinal'
        entity_name = 'ThreeMusketeers'
        corpus = ProjectionTestUtils.get_corpus(test_name, self.tests_subpath)

        # A warning should be logged when startOrdinal > endOrdinal
        def callback(level: 'CdmStatusLevel', message: str):
            if message.find('startOrdinal 2 should not be greater than endOrdinal 0') == -1:
                self.fail('Some unexpected failure - {}!'.format(message))
        corpus.set_event_callback(callback, CdmStatusLevel.WARNING)

        for res_opt in self.res_opts_combinations:
            await ProjectionTestUtils.load_entity_for_resolution_option_and_save(self, corpus, test_name, self.tests_subpath, entity_name, res_opt)

        entity = await corpus.fetch_object_async('local:/{}.cdm.json/{}'.format(entity_name, entity_name))
        resolved_entity = await ProjectionTestUtils.get_resolved_entity(corpus, entity, [])

        # Original set of attributes: ["name", "age", "address"]
        # Expand 2...0, renameFormat = {m}{o}
        # No array expansion happens here so the input just passes through
        self.assertEqual(3, len(resolved_entity.attributes))
        self.assertEqual('name', resolved_entity.attributes[0].name)
        self.assertEqual('age', resolved_entity.attributes[1].name)
        self.assertEqual('address', resolved_entity.attributes[2].name)