<commit_before>package gldapo
import gldapo.schema.annotation.GldapoSchemaFilter
import gldapo.schema.annotation.GldapoNamingAttribute

public class ReplaceIntegrationTest extends AbstractGldapoIntegrationTest
{
    def schemaClasses = [ReplaceIntegrationTestPerson]

    void testReplace() {
        
        importEntry(cn: "replaceme", """
            objectclass: top
            objectclass: person
            sn: replaceme
        """)
        
        def e = ReplaceIntegrationTestPerson.find(filter: "(cn=replaceme)")
        assertNotNull(e)
        assertEquals("replaceme", e.sn)
        
        def p = new ReplaceIntegrationTestPerson()
        p.objectclass = ["top", "person"]
        p.cn = "replaceme"
        p.sn = "replaced"
        p.replace("cn=replaceme")
        
        def e2 = ReplaceIntegrationTestPerson.find(filter: "(cn=replaceme)")
        assertNotNull(e2)
        assertEquals("replaced", e2.sn)
    }
    
    void testReplaceUsingNamingAttributeAndParent() {
        
        importEntry(cn: "replaceusingnaming", """
            objectclass: top
            objectclass: person
            sn: replaceme
        """)
    
        def p = new ReplaceIntegrationTestPerson(
            sn: "replaced",
            objectclass: ["top", "person"]
        )

        p.replace("replaceusingnaming", null)

        assertEqualsLdif("cn=replaceusingnaming", """
            objectClass: top
            objectClass: person
            cn: replaceusingnaming
            sn: replaced
        """)

        importEntry(ou: "replaceSub", """
            objectclass: top
            objectclass: organizationalUnit
        """)
        
        p.replace("replaceusingnaming", "ou=replaceSub")
        
        p = new ReplaceIntegrationTestPerson(
            sn: "replacedBelow",
            objectclass: ["top", "person"]
        )

        p.replace("replaceusingnaming", "ou=replaceSub")
        
        assertEqualsLdif("cn=replaceusingnaming,ou=replaceSub", """
            objectClass: top
            objectClass: person
            cn: replaceusingnaming
            sn: replacedBelow
        """)
        
        assertEquals("cn=replaceusingnaming, ou=replaceSub", p.rdn as String)
    }
}

@GldapoSchemaFilter("(objectclass=person)")
class ReplaceIntegrationTestPerson {
    Set<String> objectclass
    String sn
    @GldapoNamingAttribute
    String cn<commit_msg>• Refactored replace(String,Object) tests into two different tests<commit_after>package gldapo
import gldapo.schema.annotation.GldapoSchemaFilter
import gldapo.schema.annotation.GldapoNamingAttribute

public class ReplaceIntegrationTest extends AbstractGldapoIntegrationTest
{
    def schemaClasses = [ReplaceIntegrationTestPerson]

    void testReplace() {
        
        importEntry(cn: "replaceme", """
            objectclass: top
            objectclass: person
            sn: replaceme
        """)
        
        def e = ReplaceIntegrationTestPerson.find(filter: "(cn=replaceme)")
        assertNotNull(e)
        assertEquals("replaceme", e.sn)
        
        def p = new ReplaceIntegrationTestPerson()
        p.objectclass = ["top", "person"]
        p.cn = "replaceme"
        p.sn = "replaced"
        p.replace("cn=replaceme")
        
        def e2 = ReplaceIntegrationTestPerson.find(filter: "(cn=replaceme)")
        assertNotNull(e2)
        assertEquals("replaced", e2.sn)
    }
    
    void testReplaceUsingNamingAttribute() {
        importEntry(cn: "replaceusingnaming", """
            objectclass: top
            objectclass: person
            sn: replaceme
        """)
    
        def p = new ReplaceIntegrationTestPerson(
            sn: "replaced",
            objectclass: ["top", "person"]
        )

        p.replace("replaceusingnaming", null)

        assertEqualsLdif("cn=replaceusingnaming", """
            objectClass: top
            objectClass: person
            cn: replaceusingnaming
            sn: replaced
        """)
    }

    void testReplaceUsingNamingAttributeAndParent() {

        importEntry(ou: "replaceSub", """
            objectclass: top
            objectclass: organizationalUnit
        """)

        importEntry(cn: "replaceusingnaming,ou=replaceSub", """
            objectclass: top
            objectclass: person
            sn: replaceme
        """)
        
        def p = new ReplaceIntegrationTestPerson(
            sn: "replacedBelow",
            objectclass: ["top", "person"]
        )

        p.replace("replaceusingnaming", "ou=replaceSub")
        
        assertEqualsLdif("cn=replaceusingnaming,ou=replaceSub", """
            objectClass: top
            objectClass: person
            cn: replaceusingnaming
            sn: replacedBelow
        """)
        
        assertEquals("cn=replaceusingnaming, ou=replaceSub", p.rdn as String)
    }
}

@GldapoSchemaFilter("(objectclass=person)")
class ReplaceIntegrationTestPerson {
    Set<String> objectclass
    String sn
    @GldapoNamingAttribute
    String cn
{'fraction_non_alphanumeric': 0.09759012148974308, 'fraction_numerical': 0.0011949810794662419, 'mean_word_length': 2.134831460674157, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '250679', 'n_tokens_mistral': 1415, 'n_tokens_neox': 1354, 'n_words': 259}