{
    "sourceFile": "examples/advanced-rust-project/tests/test_rdf_integration.rs",
    "activeCommit": 0,
    "commits": [
        {
            "activePatchIndex": 0,
            "patches": [
                {
                    "date": 1760245074730,
                    "content": "Index: \n===================================================================\n--- \n+++ \n"
                }
            ],
            "date": 1760245074730,
            "name": "Commit-0",
            "content": "//! Tests for RDF/SPARQL integration\n//! \n//! These tests validate the RDF domain model and SPARQL queries\n//! used in the advanced Rust project example.\n\nuse std::collections::HashMap;\nuse serde_json::json;\n\n#[tokio::test]\nasync fn test_domain_model_entities() {\n    // Test that all required entities are defined\n    let domain_content = include_str!(\"../../data/domain.ttl\");\n    \n    let required_entities = [\n        \"ex:User\",\n        \"ex:Product\", \n        \"ex:Order\",\n        \"ex:Category\",\n        \"ex:Profile\",\n        \"ex:Review\",\n        \"ex:OrderItem\",\n    ];\n    \n    for entity in required_entities {\n        assert!(\n            domain_content.contains(&format!(\"{} a ex:Entity\", entity)),\n            \"Entity {} not found in domain model\",\n            entity\n        );\n    }\n}\n\n#[tokio::test]\nasync fn test_domain_model_properties() {\n    // Test that all required properties are defined\n    let domain_content = include_str!(\"../../data/domain.ttl\");\n    \n    let required_properties = [\n        \"ex:userId\",\n        \"ex:email\",\n        \"ex:name\",\n        \"ex:createdAt\",\n        \"ex:productId\",\n        \"ex:description\",\n        \"ex:price\",\n        \"ex:category\",\n        \"ex:orderId\",\n        \"ex:totalAmount\",\n        \"ex:status\",\n        \"ex:categoryId\",\n    ];\n    \n    for property in required_properties {\n        assert!(\n            domain_content.contains(&format!(\"{} a ex:Property\", property)),\n            \"Property {} not found in domain model\",\n            property\n        );\n    }\n}\n\n#[tokio::test]\nasync fn test_domain_model_relationships() {\n    // Test that all required relationships are defined\n    let domain_content = include_str!(\"../../data/domain.ttl\");\n    \n    let required_relationships = [\n        \"ex:hasProfile\",\n        \"ex:hasOrders\",\n        \"ex:hasReviews\",\n        \"ex:hasOrderItems\",\n        \"ex:belongsToUser\",\n        \"ex:hasProducts\",\n        \"ex:belongsToCategory\",\n    ];\n    \n    for relationship in required_relationships {\n        assert!(\n            domain_content.contains(&format!(\"{} a ex:Relationship\", relationship)),\n            \"Relationship {} not found in domain model\",\n            relationship\n        );\n    }\n}\n\n#[tokio::test]\nasync fn test_api_endpoints() {\n    // Test that all API endpoints are defined\n    let domain_content = include_str!(\"../../data/domain.ttl\");\n    \n    let required_endpoints = [\n        \"ex:UserAPI\",\n        \"ex:ProductAPI\",\n        \"ex:OrderAPI\",\n    ];\n    \n    for endpoint in required_endpoints {\n        assert!(\n            domain_content.contains(&format!(\"{} a ex:APIEndpoint\", endpoint)),\n            \"API endpoint {} not found in domain model\",\n            endpoint\n        );\n    }\n    \n    // Test individual endpoint methods\n    let required_methods = [\n        \"ex:GetUsers\",\n        \"ex:GetUser\",\n        \"ex:CreateUser\",\n        \"ex:UpdateUser\",\n        \"ex:DeleteUser\",\n        \"ex:GetProducts\",\n        \"ex:GetProduct\",\n        \"ex:CreateProduct\",\n        \"ex:UpdateProduct\",\n        \"ex:DeleteProduct\",\n        \"ex:GetOrders\",\n        \"ex:GetOrder\",\n        \"ex:CreateOrder\",\n        \"ex:UpdateOrder\",\n        \"ex:CancelOrder\",\n    ];\n    \n    for method in required_methods {\n        assert!(\n            domain_content.contains(&format!(\"{} a ex:Endpoint\", method)),\n            \"Endpoint method {} not found in domain model\",\n            method\n        );\n    }\n}\n\n#[tokio::test]\nasync fn test_database_schema() {\n    // Test that all database tables are defined\n    let domain_content = include_str!(\"../../data/domain.ttl\");\n    \n    let required_tables = [\n        \"ex:UsersTable\",\n        \"ex:ProductsTable\",\n        \"ex:OrdersTable\",\n        \"ex:CategoriesTable\",\n    ];\n    \n    for table in required_tables {\n        assert!(\n            domain_content.contains(&format!(\"{} a ex:Table\", table)),\n            \"Table {} not found in domain model\",\n            table\n        );\n    }\n    \n    // Test table columns\n    let required_columns = [\n        \"ex:UserIdColumn\",\n        \"ex:EmailColumn\",\n        \"ex:NameColumn\",\n        \"ex:CreatedAtColumn\",\n        \"ex:ProductIdColumn\",\n        \"ex:DescriptionColumn\",\n        \"ex:PriceColumn\",\n        \"ex:CategoryIdColumn\",\n        \"ex:OrderIdColumn\",\n        \"ex:TotalAmountColumn\",\n        \"ex:StatusColumn\",\n    ];\n    \n    for column in required_columns {\n        assert!(\n            domain_content.contains(&format!(\"{} a ex:Column\", column)),\n            \"Column {} not found in domain model\",\n            column\n        );\n    }\n}\n\n#[tokio::test]\nasync fn test_sparql_queries_in_templates() {\n    // Test that SPARQL queries in templates are valid\n    let templates = [\n        (\"rust-service.tmpl\", include_str!(\"../../templates/rust-service.tmpl\")),\n        (\"api-endpoint.tmpl\", include_str!(\"../../templates/api-endpoint.tmpl\")),\n        (\"database-schema.tmpl\", include_str!(\"../../templates/database-schema.tmpl\")),\n        (\"documentation.tmpl\", include_str!(\"../../templates/documentation.tmpl\")),\n    ];\n    \n    for (template_name, template_content) in templates {\n        // Check for SPARQL query definitions\n        assert!(\n            template_content.contains(\"sparql:\"),\n            \"Template {} missing SPARQL queries\",\n            template_name\n        );\n        \n        // Check for specific SPARQL queries\n        let required_queries = [\n            \"find_entities\",\n            \"find_properties\",\n            \"find_relationships\",\n            \"find_endpoints\",\n            \"find_tables\",\n            \"find_columns\",\n        ];\n        \n        for query in required_queries {\n            assert!(\n                template_content.contains(&format!(\"{}:\", query)),\n                \"Template {} missing SPARQL query: {}\",\n                template_name,\n                query\n            );\n        }\n    }\n}\n\n#[tokio::test]\nasync fn test_sparql_query_syntax() {\n    // Test that SPARQL queries have valid syntax\n    let domain_content = include_str!(\"../../data/domain.ttl\");\n    \n    // Extract SPARQL queries from templates\n    let templates = [\n        include_str!(\"../../templates/rust-service.tmpl\"),\n        include_str!(\"../../templates/api-endpoint.tmpl\"),\n        include_str!(\"../../templates/database-schema.tmpl\"),\n        include_str!(\"../../templates/documentation.tmpl\"),\n    ];\n    \n    for template_content in templates {\n        // Find SPARQL query sections\n        let lines: Vec<&str> = template_content.lines().collect();\n        let mut in_sparql_section = false;\n        \n        for line in lines {\n            if line.trim().starts_with(\"sparql:\") {\n                in_sparql_section = true;\n                continue;\n            }\n            \n            if in_sparql_section {\n                if line.trim().starts_with(\"-\") || line.trim().is_empty() {\n                    continue;\n                }\n                \n                if line.trim().starts_with(\"---\") {\n                    break;\n                }\n                \n                // Validate SPARQL query syntax\n                if line.contains(\"SELECT\") {\n                    assert!(\n                        line.contains(\"WHERE\"),\n                        \"SPARQL query missing WHERE clause: {}\",\n                        line\n                    );\n                }\n                \n                if line.contains(\"WHERE\") {\n                    assert!(\n                        line.contains(\"{\"),\n                        \"SPARQL query missing opening brace: {}\",\n                        line\n                    );\n                }\n            }\n        }\n    }\n}\n\n#[tokio::test]\nasync fn test_rdf_prefixes() {\n    // Test that RDF prefixes are properly defined\n    let domain_content = include_str!(\"../../data/domain.ttl\");\n    \n    let required_prefixes = [\n        \"@prefix ex:\",\n        \"@prefix rdf:\",\n        \"@prefix rdfs:\",\n        \"@prefix xsd:\",\n        \"@prefix owl:\",\n    ];\n    \n    for prefix in required_prefixes {\n        assert!(\n            domain_content.contains(prefix),\n            \"RDF prefix {} not found in domain model\",\n            prefix\n        );\n    }\n}\n\n#[tokio::test]\nasync fn test_rdf_base_iri() {\n    // Test that base IRI is properly defined\n    let domain_content = include_str!(\"../../data/domain.ttl\");\n    \n    assert!(\n        domain_content.contains(\"@base\"),\n        \"Base IRI not defined in domain model\"\n    );\n    \n    assert!(\n        domain_content.contains(\"http://example.org/advanced-rust-project/\"),\n        \"Base IRI not properly set in domain model\"\n    );\n}\n\n#[tokio::test]\nasync fn test_template_rdf_integration() {\n    // Test that templates properly integrate with RDF data\n    let templates = [\n        include_str!(\"../../templates/rust-service.tmpl\"),\n        include_str!(\"../../templates/api-endpoint.tmpl\"),\n        include_str!(\"../../templates/database-schema.tmpl\"),\n        include_str!(\"../../templates/documentation.tmpl\"),\n    ];\n    \n    for template_content in templates {\n        // Check for RDF integration\n        assert!(\n            template_content.contains(\"rdf:\"),\n            \"Template missing RDF integration\"\n        );\n        \n        assert!(\n            template_content.contains(\"prefixes:\"),\n            \"Template missing RDF prefixes\"\n        );\n        \n        assert!(\n            template_content.contains(\"base:\"),\n            \"Template missing RDF base IRI\"\n        );\n        \n        // Check for SPARQL results usage\n        assert!(\n            template_content.contains(\"sparql_results\"),\n            \"Template missing SPARQL results usage\"\n        );\n    }\n}\n\n#[tokio::test]\nasync fn test_sparql_helper_functions() {\n    // Test that SPARQL helper functions are used correctly\n    let templates = [\n        include_str!(\"../../templates/rust-service.tmpl\"),\n        include_str!(\"../../templates/api-endpoint.tmpl\"),\n        include_str!(\"../../templates/database-schema.tmpl\"),\n        include_str!(\"../../templates/documentation.tmpl\"),\n    ];\n    \n    for template_content in templates {\n        // Check for SPARQL helper functions\n        let helper_functions = [\n            \"sparql_count\",\n            \"sparql_first\",\n            \"sparql_values\",\n            \"sparql_empty\",\n            \"sparql_column\",\n            \"sparql_row\",\n        ];\n        \n        for helper in helper_functions {\n            if template_content.contains(helper) {\n                // Validate helper function usage\n                assert!(\n                    template_content.contains(&format!(\"results=sparql_results\")),\n                    \"SPARQL helper {} not properly used with results\",\n                    helper\n                );\n            }\n        }\n    }\n}\n\n#[tokio::test]\nasync fn test_rdf_data_consistency() {\n    // Test that RDF data is consistent across the domain model\n    let domain_content = include_str!(\"../../data/domain.ttl\");\n    \n    // Check that entities have properties\n    let entities = [\"ex:User\", \"ex:Product\", \"ex:Order\", \"ex:Category\"];\n    \n    for entity in entities {\n        assert!(\n            domain_content.contains(&format!(\"{} ex:hasProperty\", entity)),\n            \"Entity {} missing property definitions\",\n            entity\n        );\n    }\n    \n    // Check that entities have relationships\n    for entity in entities {\n        assert!(\n            domain_content.contains(&format!(\"{} ex:hasRelationship\", entity)),\n            \"Entity {} missing relationship definitions\",\n            entity\n        );\n    }\n    \n    // Check that properties have data types\n    let properties = [\"ex:userId\", \"ex:email\", \"ex:name\", \"ex:price\"];\n    \n    for property in properties {\n        assert!(\n            domain_content.contains(&format!(\"{} ex:dataType\", property)),\n            \"Property {} missing data type definition\",\n            property\n        );\n    }\n}\n\n#[tokio::test]\nasync fn test_sparql_query_coverage() {\n    // Test that SPARQL queries cover all necessary data\n    let domain_content = include_str!(\"../../data/domain.ttl\");\n    \n    // Check that templates query for all entity types\n    let templates = [\n        include_str!(\"../../templates/rust-service.tmpl\"),\n        include_str!(\"../../templates/api-endpoint.tmpl\"),\n        include_str!(\"../../templates/database-schema.tmpl\"),\n        include_str!(\"../../templates/documentation.tmpl\"),\n    ];\n    \n    for template_content in templates {\n        // Check for entity queries\n        assert!(\n            template_content.contains(\"SELECT ?entity WHERE { ?entity a ex:Entity }\"),\n            \"Template missing entity query\"\n        );\n        \n        // Check for property queries\n        assert!(\n            template_content.contains(\"SELECT ?property WHERE { ?property a ex:Property }\"),\n            \"Template missing property query\"\n        );\n        \n        // Check for relationship queries\n        assert!(\n            template_content.contains(\"SELECT ?rel WHERE { ?rel a ex:Relationship }\"),\n            \"Template missing relationship query\"\n        );\n    }\n}\n"
        }
    ]
}