{"id":19838489,"url":"https://github.com/zapodot/embedded-ldap-junit","last_synced_at":"2025-10-23T16:35:35.047Z","repository":{"id":27929124,"uuid":"31421468","full_name":"zapodot/embedded-ldap-junit","owner":"zapodot","description":"A JUnit rule for running an embedded LDAP server in your JUnit test","archived":false,"fork":false,"pushed_at":"2024-10-10T00:37:34.000Z","size":178,"stargazers_count":34,"open_issues_count":14,"forks_count":12,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-29T16:09:56.769Z","etag":null,"topics":["java","junit-rule","ldap","ldap-server","testing","unbound"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zapodot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-02-27T13:55:49.000Z","updated_at":"2024-07-12T05:41:51.000Z","dependencies_parsed_at":"2024-12-16T10:25:17.651Z","dependency_job_id":null,"html_url":"https://github.com/zapodot/embedded-ldap-junit","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zapodot%2Fembedded-ldap-junit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zapodot%2Fembedded-ldap-junit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zapodot%2Fembedded-ldap-junit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zapodot%2Fembedded-ldap-junit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zapodot","download_url":"https://codeload.github.com/zapodot/embedded-ldap-junit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247369952,"owners_count":20927928,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","junit-rule","ldap","ldap-server","testing","unbound"],"created_at":"2024-11-12T12:17:56.229Z","updated_at":"2025-10-23T16:35:34.666Z","avatar_url":"https://github.com/zapodot.png","language":"Java","funding_links":[],"categories":["测试"],"sub_categories":[],"readme":"# embedded-ldap-junit\n[![Build Status](https://github.com/zapodot/embedded-ldap-junit/actions/workflows/maven.yml/badge.svg)](https://github.com/zapodot/embedded-ldap-junit/actions/workflows/maven.yml) [![codecov](https://codecov.io/gh/zapodot/embedded-ldap-junit/branch/master/graph/badge.svg?token=2jm8uT1bJg)](https://codecov.io/gh/zapodot/embedded-ldap-junit) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.zapodot/embedded-ldap-junit/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.zapodot/embedded-ldap-junit) [![Libraries.io for GitHub](https://img.shields.io/librariesio/github/zapodot/embedded-ldap-junit.svg)](https://libraries.io/github/zapodot/embedded-ldap-junit) [![GitHub](https://img.shields.io/github/license/zapodot/embedded-ldap-junit)](https://github.com/zapodot/embedded-ldap-junit/blob/master/LICENSE) [![Analytics](https://ga-beacon.appspot.com/UA-40926073-2/embedded-ldap-junit/README.md)](https://github.com/igrigorik/ga-beacon)\n\nA [JUnit Rule](//github.com/junit-team/junit/wiki/Rules) for running an embedded LDAP server in your JUnit test based on the wonderful [UnboundID LDAP SDK](https://www.ldap.com/unboundid-ldap-sdk-for-java). Inspired by the [Embedded Database JUnit Rule](//github.com/zapodot/embedded-db-junit).\n\n## Why?\n* you want to test your LDAP integration code without affecting your LDAP server\n* you are working with LDAP schema changes that you would like to test without changing the schema at the shared LDAP server\n* you are refactoring legacy code where LDAP calls are tightly coupled with your business logic and wants to start by testing the legacy code from the \"outside\" (as suggested by [Michael Feathers](http://www.informit.com/store/working-effectively-with-legacy-code-9780131177055?aid=15d186bd-1678-45e9-8ad3-fe53713e811b))\n    * for this exact reason most instances returned from the EmbeddedLdapRule is instrumented to suppress \"close\" calls so that your legacy code will not destroy the current Context/DirContext or LdapInterface\n    * **note**: if you used the new unsharedLdapConnection() method, the returned instance will not have this guarantee as it returns a instance of UnboundID LDAPConnection which is declared 'final'.\n\n## Status\nThis library is distributed through the [Sonatype OSS repo](https://oss.sonatype.org/) and should thus be widely available.\nJava 8 or higher is required. It has proven pretty useful for several users and should be considered safe for running tests for all kinds of LDAP integrating code.\n\n## Changelog\nSee [releases](//github.com/zapodot/embedded-ldap-junit/releases)\n\n## Usage\n\n### Add dependency\n#### Maven\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eorg.zapodot\u003c/groupId\u003e\n    \u003cartifactId\u003eembedded-ldap-junit\u003c/artifactId\u003e\n    \u003cversion\u003e0.9.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n### Add to Junit test\n```java\nimport com.unboundid.ldap.sdk.LDAPInterface;\nimport javax.naming.Context;\nimport javax.naming.NamingEnumeration;\n...\n\n@Rule\npublic EmbeddedLdapRule embeddedLdapRule = EmbeddedLdapRuleBuilder\n        .newInstance()\n        .usingDomainDsn(\"dc=example,dc=com\")\n        .importingLdifs(\"example.ldif\")\n        .build();\n\n@Test\npublic void testLdapInteface() throws Exception {\n    // Test using the UnboundID LDAP SDK directly\n    final LdapInterface ldapConnection = embeddedLdapRule.ldapConnection();\n    final SearchResult searchResult = ldapConnection.search(DOMAIN_DSN, SearchScope.SUB, \"(objectClass=person)\");\n    assertEquals(1, searchResult.getEntryCount());\n}\n\n@Test\npublic void testUnsharedLdapConnection() throws Exception {\n    // Test using the UnboundID LDAP SDK directly by using the UnboundID LDAPConnection type\n    final LDAPConnection ldapConnection = embeddedLdapRule.unsharedLdapConnection();\n    final SearchResult searchResult = ldapConnection.search(DOMAIN_DSN, SearchScope.SUB, \"(objectClass=person)\");\n    assertEquals(1, searchResult.getEntryCount());\n}\n\n@Test\npublic void testDirContext() throws Exception {\n\n    // Test using the good ol' JDNI-LDAP integration\n    final DirContext dirContext = embeddedLdapRule.dirContext();\n    final SearchControls searchControls = new SearchControls();\n    searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);\n    final NamingEnumeration\u003cjavax.naming.directory.SearchResult\u003e resultNamingEnumeration =\n            dirContext.search(DOMAIN_DSN, \"(objectClass=person)\", searchControls);\n    assertEquals(1, Iterators.size(Iterators.forEnumeration(resultNamingEnumeration)));\n}\n@Test\npublic void testContext() throws Exception {\n\n    // Another test using the good ol' JDNI-LDAP integration, this time with the Context interface\n    final Context context = embeddedLdapRule.context();\n    final Object user = context.lookup(\"cn=John Doe,ou=people,dc=example,dc=com\");\n    assertNotNull(user);\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzapodot%2Fembedded-ldap-junit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzapodot%2Fembedded-ldap-junit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzapodot%2Fembedded-ldap-junit/lists"}