gnodet-bot commented on code in PR #31284:
URL: https://github.com/apache/camel/pull/31284#discussion_r4773301527


##########
components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2ConfigurationTest.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * 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.olingo2;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.http.HttpHost;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
+
+/**
+ * Unit tests for bugs fixed in CAMEL-27977:
+ * <ul>
+ * <li>equals() ignored most fields due to missing parentheses in ternary 
chain</li>
+ * <li>createOlingo2App() unconditionally overwrote the component-level 
apiProxy</li>
+ * <li>httpClientBuilder was never read in createOlingo2App()</li>
+ * </ul>
+ */
+class Olingo2ConfigurationTest {
+
+    // 
-------------------------------------------------------------------------
+    // Bug 1: equals() ignored most fields
+    // 
-------------------------------------------------------------------------
+
+    @Test
+    void equalsReturnsTrueForIdenticalConfigurations() {
+        Olingo2Configuration a = baseConfig("http://example.org/svc";);
+        Olingo2Configuration b = baseConfig("http://example.org/svc";);
+        assertEquals(a, b, "Configurations with the same fields must be 
equal");
+    }
+
+    @Test
+    void equalsReturnsFalseWhenServiceUriDiffers() {
+        Olingo2Configuration a = baseConfig("http://host-a.org/svc";);
+        Olingo2Configuration b = baseConfig("http://host-b.org/svc";);
+        assertNotEquals(a, b, "Configurations with different serviceUri must 
not be equal");
+    }
+
+    @Test
+    void equalsReturnsFalseWhenContentTypeDiffers() {
+        Olingo2Configuration a = baseConfig("http://example.org/svc";);
+        a.setContentType("application/json;charset=utf-8");
+        Olingo2Configuration b = baseConfig("http://example.org/svc";);
+        b.setContentType("application/atom+xml");
+        assertNotEquals(a, b, "Configurations with different contentType must 
not be equal");
+    }
+
+    @Test
+    void equalsReturnsFalseWhenProxyDiffers() {
+        Olingo2Configuration a = baseConfig("http://example.org/svc";);
+        Olingo2Configuration b = baseConfig("http://example.org/svc";);
+        b.setProxy(new HttpHost("proxy.example.org", 8080));
+        assertNotEquals(a, b, "Configurations with different proxy must not be 
equal");
+    }
+
+    @Test
+    void equalsReturnsFalseWhenConnectTimeoutDiffers() {
+        Olingo2Configuration a = baseConfig("http://example.org/svc";);
+        Olingo2Configuration b = baseConfig("http://example.org/svc";);
+        b.setConnectTimeout(99_000);
+        assertNotEquals(a, b, "Configurations with different connectTimeout 
must not be equal");
+    }
+
+    @Test
+    void equalsReturnsFalseWhenSocketTimeoutDiffers() {
+        Olingo2Configuration a = baseConfig("http://example.org/svc";);
+        Olingo2Configuration b = baseConfig("http://example.org/svc";);
+        b.setSocketTimeout(99_000);
+        assertNotEquals(a, b, "Configurations with different socketTimeout 
must not be equal");
+    }
+
+    @Test
+    void equalsHandlesNullServiceUri() {
+        Olingo2Configuration a = new Olingo2Configuration();
+        Olingo2Configuration b = new Olingo2Configuration();
+        // Both have null serviceUri — must not throw NPE and must be equal
+        assertEquals(a, b, "Two default configurations with null serviceUri 
must be equal");
+    }
+
+    @Test
+    void equalsReturnsFalseWhenOnlyOneHasNullServiceUri() {
+        Olingo2Configuration a = new Olingo2Configuration();
+        Olingo2Configuration b = baseConfig("http://example.org/svc";);
+        assertNotEquals(a, b, "Config with null serviceUri must not equal one 
with a non-null serviceUri");
+    }
+
+    // 
-------------------------------------------------------------------------
+    // Bug 2: createOlingo2App() must NOT overwrite the shared apiProxy
+    // 
-------------------------------------------------------------------------
+
+    @Test
+    void endpointSpecificProxyDoesNotReplaceSharedProxy() throws Exception {
+        try (CamelContext context = new DefaultCamelContext()) {
+            context.start();
+
+            Olingo2Component component = new Olingo2Component(context);
+            component.init();
+
+            Olingo2Configuration sharedConfig = 
baseConfig("http://shared.example.org/svc";);
+            component.setConfiguration(sharedConfig);
+
+            // First call with the shared configuration — creates the shared 
apiProxy
+            Olingo2AppWrapper sharedProxy = 
component.createApiProxy(sharedConfig);
+
+            // Second call with a *different* configuration — must return a 
different wrapper
+            Olingo2Configuration endpointConfig = 
baseConfig("http://endpoint.example.org/svc";);
+            Olingo2AppWrapper endpointProxy = 
component.createApiProxy(endpointConfig);
+
+            assertNotSame(sharedProxy, endpointProxy,
+                    "Endpoint-specific proxy must be distinct from the shared 
proxy");
+
+            // After the endpoint-specific call the shared proxy must be 
unchanged
+            Olingo2AppWrapper sharedProxyAgain = 
component.createApiProxy(sharedConfig);
+            assertSame(sharedProxy, sharedProxyAgain,
+                    "The shared proxy must not be replaced by an 
endpoint-specific createOlingo2App() call");
+
+            component.closeApiProxy(sharedProxy);
+            component.closeApiProxy(endpointProxy);
+        }
+    }
+
+    // 
-------------------------------------------------------------------------
+    // helpers
+    // 
-------------------------------------------------------------------------
+
+    private static Olingo2Configuration baseConfig(String serviceUri) {
+        Olingo2Configuration cfg = new Olingo2Configuration();
+        cfg.setServiceUri(serviceUri);
+        return cfg;
+    }
+
+    /** Negated assertEquals — JUnit 5 has no 
assertNotEquals(Object,Object,String) for nulls. */
+    private static void assertNotEquals(Object a, Object b, String message) {

Review Comment:
   **[low]** The javadoc says `"JUnit 5 has no 
assertNotEquals(Object,Object,String) for nulls"` but that's incorrect. 
`Assertions.assertNotEquals(Object, Object, String)` exists in JUnit 5 and uses 
`Objects.equals` internally, so it handles nulls correctly. This helper can be 
replaced with the standard import:
   
   ```suggestion
   // (remove this method and add: import static 
org.junit.jupiter.api.Assertions.assertNotEquals;)
   ```



-- 
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]

Reply via email to