allthingssecurity commented on code in PR #27642: URL: https://github.com/apache/camel/pull/27642#discussion_r4236660850
########## components/camel-ldif/src/test/java/org/apache/camel/component/ldif/LdifModDnTest.java: ########## @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.ldif; + +import java.lang.reflect.Proxy; +import java.util.ArrayList; +import java.util.List; + +import org.apache.camel.BindToRegistry; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.test.junit6.CamelTestSupport; +import org.apache.directory.api.ldap.model.name.Dn; +import org.apache.directory.api.ldap.model.name.Rdn; +import org.apache.directory.ldap.client.api.LdapConnection; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * RFC 2849: "modrdn" and "moddn" are the same change type. The entry gets the new RDN, and moves under the new superior + * only when "newsuperior" is given. The connection is a stub that records the resulting DN, so this test needs no LDAP + * server. + */ +class LdifModDnTest extends CamelTestSupport { + + private final List<String> renames = new ArrayList<>(); + + @BindToRegistry("conn") + private final LdapConnection conn = (LdapConnection) Proxy.newProxyInstance( + LdapConnection.class.getClassLoader(), new Class<?>[] { LdapConnection.class }, + (proxy, method, args) -> { + switch (method.getName()) { + case "rename" -> { + Dn dn = (Dn) args[0]; + renames.add(new Dn((Rdn) args[1], dn.getParent()) + " deleteOldRdn=" + args[2]); + } + case "moveAndRename" -> + renames.add(args[1] + " deleteOldRdn=" + args[2]); + case "move" -> renames.add(new Dn(((Dn) args[0]).getRdn(), (Dn) args[1]) + " deleteOldRdn=true"); Review Comment: Done in 71879abfdd: the `move` branch is gone, the default branch records the method name (shown in the assertion message), and the proxy answers `hashCode`/`equals`/`toString` by identity. Recording surfaced the producer's `close()` call, which is now an explicit expected no-op. _Claude Code on behalf of allthingssecurity_ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
