camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zregv...@apache.org
Subject camel git commit: CAMEL-11629: Cleanup SalesforceComponentVerifie...
Date Mon, 14 Aug 2017 20:08:34 GMT
Repository: camel
Updated Branches:
  refs/heads/master 7c3dba855 -> d51365105


CAMEL-11629: Cleanup SalesforceComponentVerifie...

...rTest

Splits the SalesforceComponentVerifier test into integration
(connectivity) and unit test (parameter). The integration test now
relies on `LoginConfigHelper` that reads its configuration from
`salesforce-test-login.properties`.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d5136510
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d5136510
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d5136510

Branch: refs/heads/master
Commit: d513651050a633e136832b5709fb1f5f4ab6512a
Parents: 7c3dba8
Author: Zoran Regvart <zregvart@apache.org>
Authored: Mon Aug 14 22:04:43 2017 +0200
Committer: Zoran Regvart <zregvart@apache.org>
Committed: Mon Aug 14 22:05:11 2017 +0200

----------------------------------------------------------------------
 ...mponentVerifierExtensionIntegrationTest.java | 137 +++++++++++++++++++
 ...alesforceComponentVerifierExtensionTest.java | 104 +-------------
 2 files changed, 141 insertions(+), 100 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/d5136510/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/SalesforceComponentVerifierExtensionIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/SalesforceComponentVerifierExtensionIntegrationTest.java
b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/SalesforceComponentVerifierExtensionIntegrationTest.java
new file mode 100644
index 0000000..f85024d
--- /dev/null
+++ b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/SalesforceComponentVerifierExtensionIntegrationTest.java
@@ -0,0 +1,137 @@
+/**
+ * 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.salesforce;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.Component;
+import org.apache.camel.ComponentVerifier;
+import org.apache.camel.component.extension.ComponentVerifierExtension;
+import org.apache.camel.component.salesforce.api.SalesforceException;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class SalesforceComponentVerifierExtensionIntegrationTest extends CamelTestSupport
{
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    // *********************************
+    // Helpers
+    // *********************************
+
+    protected Map<String, Object> getParameters() {
+        SalesforceLoginConfig loginConfig = LoginConfigHelper.getLoginConfig();
+
+        HashMap<String, Object> parameters = new HashMap<>();
+        parameters.put("clientId", loginConfig.getClientId());
+        parameters.put("clientSecret", loginConfig.getClientSecret());
+        parameters.put("userName", loginConfig.getUserName());
+        parameters.put("password", loginConfig.getPassword());
+
+        return parameters;
+    }
+
+    public static String getSystemPropertyOrEnvVar(String systemProperty) {
+        String answer = System.getProperty(systemProperty);
+        if (ObjectHelper.isEmpty(answer)) {
+            String envProperty = systemProperty.toUpperCase().replaceAll("[.-]", "_");
+            answer = System.getenv(envProperty);
+        }
+
+        return answer;
+    }
+
+    protected ComponentVerifierExtension getExtension() {
+        Component component = context().getComponent("salesforce");
+        ComponentVerifierExtension verifier = component.getExtension(ComponentVerifierExtension.class)
+            .orElseThrow(IllegalStateException::new);
+
+        return verifier;
+    }
+
+    // *********************************
+    // Connectivity validation
+    // *********************************
+
+    @Test
+    public void testConnectivity() {
+        Map<String, Object> parameters = getParameters();
+        ComponentVerifierExtension.Result result = getExtension().verify(ComponentVerifierExtension.Scope.CONNECTIVITY,
+            parameters);
+
+        Assert.assertEquals(ComponentVerifierExtension.Result.Status.OK, result.getStatus());
+    }
+
+    @Test
+    public void testConnectivityWithWrongUserName() {
+        Map<String, Object> parameters = getParameters();
+        parameters.put("userName", "not-a-salesforce-user");
+
+        ComponentVerifierExtension.Result result = getExtension().verify(ComponentVerifierExtension.Scope.CONNECTIVITY,
+            parameters);
+
+        Assert.assertEquals(ComponentVerifierExtension.Result.Status.ERROR, result.getStatus());
+        Assert.assertEquals(2, result.getErrors().size());
+
+        // Exception
+        Assert.assertEquals(ComponentVerifierExtension.VerificationError.StandardCode.EXCEPTION,
+            result.getErrors().get(0).getCode());
+        Assert.assertNotNull(result.getErrors().get(0).getDetails()
+            .get(ComponentVerifierExtension.VerificationError.ExceptionAttribute.EXCEPTION_INSTANCE));
+        Assert.assertTrue(result.getErrors().get(0).getDetails().get(
+            ComponentVerifierExtension.VerificationError.ExceptionAttribute.EXCEPTION_INSTANCE)
instanceof SalesforceException);
+        Assert.assertEquals(400, result.getErrors().get(0).getDetails()
+            .get(ComponentVerifierExtension.VerificationError.HttpAttribute.HTTP_CODE));
+
+        // Salesforce Error
+        Assert.assertEquals("invalid_grant", result.getErrors().get(1).getDetail("salesforce_code"));
+    }
+
+    @Test
+    public void testConnectivityWithWrongSecrets() {
+        Map<String, Object> parameters = getParameters();
+        parameters.put("clientId", "wrong-client-id");
+        parameters.put("clientSecret", "wrong-client-secret");
+
+        ComponentVerifierExtension.Result result = getExtension().verify(ComponentVerifierExtension.Scope.CONNECTIVITY,
+            parameters);
+
+        Assert.assertEquals(ComponentVerifier.Result.Status.ERROR, result.getStatus());
+
+        Assert.assertEquals(ComponentVerifier.Result.Status.ERROR, result.getStatus());
+        Assert.assertEquals(2, result.getErrors().size());
+
+        // Exception
+        Assert.assertEquals(ComponentVerifierExtension.VerificationError.StandardCode.EXCEPTION,
+            result.getErrors().get(0).getCode());
+        Assert.assertNotNull(result.getErrors().get(0).getDetails()
+            .get(ComponentVerifierExtension.VerificationError.ExceptionAttribute.EXCEPTION_INSTANCE));
+        Assert.assertTrue(result.getErrors().get(0).getDetails().get(
+            ComponentVerifierExtension.VerificationError.ExceptionAttribute.EXCEPTION_INSTANCE)
instanceof SalesforceException);
+        Assert.assertEquals(400,
+            result.getErrors().get(0).getDetails().get(ComponentVerifier.VerificationError.HttpAttribute.HTTP_CODE));
+
+        // Salesforce Error
+        Assert.assertEquals("invalid_client_id", result.getErrors().get(1).getDetail("salesforce_code"));
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/d5136510/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/SalesforceComponentVerifierExtensionTest.java
----------------------------------------------------------------------
diff --git a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/SalesforceComponentVerifierExtensionTest.java
b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/SalesforceComponentVerifierExtensionTest.java
index bf7ed2a..eeda330 100644
--- a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/SalesforceComponentVerifierExtensionTest.java
+++ b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/SalesforceComponentVerifierExtensionTest.java
@@ -20,59 +20,18 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.camel.Component;
-import org.apache.camel.ComponentVerifier;
 import org.apache.camel.component.extension.ComponentVerifierExtension;
-import org.apache.camel.component.salesforce.api.SalesforceException;
 import org.apache.camel.test.junit4.CamelTestSupport;
-import org.apache.camel.util.ObjectHelper;
 import org.junit.Assert;
-import org.junit.Assume;
 import org.junit.Test;
 
 public class SalesforceComponentVerifierExtensionTest extends CamelTestSupport {
-    private static final String CLIENT_ID = getSystemPropertyOrEnvVar("salesforce.clientid");
-    private static final String CLIENT_SECRET = getSystemPropertyOrEnvVar("salesforce.clientsecret");
-    private static final String USERNAME = getSystemPropertyOrEnvVar("salesforce.userName");
-    private static final String PASSWORD = getSystemPropertyOrEnvVar("salesforce.password");
-
-    @Override
-    protected void doPreSetup() throws Exception {
-        Assume.assumeNotNull(CLIENT_ID);
-        Assume.assumeNotNull(CLIENT_SECRET);
-        Assume.assumeNotNull(USERNAME);
-        Assume.assumeNotNull(PASSWORD);
-    }
 
     @Override
     public boolean isUseRouteBuilder() {
         return false;
     }
 
-    // *********************************
-    // Helpers
-    // *********************************
-
-    protected Map<String, Object> getParameters() {
-        HashMap<String, Object> parameters = new HashMap<>();
-        parameters.put("clientId", CLIENT_ID);
-        parameters.put("clientSecret", CLIENT_SECRET);
-        parameters.put("userName", USERNAME);
-        parameters.put("password", PASSWORD);
-
-
-        return parameters;
-    }
-
-    public static String getSystemPropertyOrEnvVar(String systemProperty) {
-        String answer = System.getProperty(systemProperty);
-        if (ObjectHelper.isEmpty(answer)) {
-            String envProperty = systemProperty.toUpperCase().replaceAll("[.-]", "_");
-            answer = System.getenv(envProperty);
-        }
-
-        return answer;
-    }
-
     protected ComponentVerifierExtension getExtension() {
         Component component = context().getComponent("salesforce");
         ComponentVerifierExtension verifier = component.getExtension(ComponentVerifierExtension.class).orElseThrow(IllegalStateException::new);
@@ -99,7 +58,7 @@ public class SalesforceComponentVerifierExtensionTest extends CamelTestSupport
{
 
     @Test
     public void testRefreshTokenParameters() {
-        Map<String, Object> parameters = getParameters();
+        Map<String, Object> parameters = new HashMap<>();
         parameters.put("clientId", "clientId");
         parameters.put("clientSecret", "clientSecret");
         parameters.put("refreshToken", "refreshToken");
@@ -121,63 +80,8 @@ public class SalesforceComponentVerifierExtensionTest extends CamelTestSupport
{
         Assert.assertEquals(ComponentVerifierExtension.Result.Status.ERROR, result.getStatus());
         Assert.assertEquals(3, result.getErrors().size());
 
-        Assert.assertEquals(ComponentVerifierExtension.VerificationError.StandardCode.INCOMPLETE_PARAMETER_GROUP,
result.getErrors().get(0).getCode());
-        Assert.assertEquals(ComponentVerifierExtension.VerificationError.StandardCode.INCOMPLETE_PARAMETER_GROUP,
result.getErrors().get(1).getCode());
-        Assert.assertEquals(ComponentVerifierExtension.VerificationError.StandardCode.INCOMPLETE_PARAMETER_GROUP,
result.getErrors().get(2).getCode());
-    }
-
-    // *********************************
-    // Connectivity validation
-    // *********************************
-
-    @Test
-    public void testConnectivity() {
-        Map<String, Object> parameters = getParameters();
-        ComponentVerifierExtension.Result result = getExtension().verify(ComponentVerifierExtension.Scope.CONNECTIVITY,
parameters);
-
-        Assert.assertEquals(ComponentVerifierExtension.Result.Status.OK, result.getStatus());
-    }
-
-    @Test
-    public void testConnectivityWithWrongUserName() {
-        Map<String, Object> parameters = getParameters();
-        parameters.put("userName", "not-a-salesforce-user");
-
-        ComponentVerifierExtension.Result result = getExtension().verify(ComponentVerifierExtension.Scope.CONNECTIVITY,
parameters);
-
-        Assert.assertEquals(ComponentVerifierExtension.Result.Status.ERROR, result.getStatus());
-        Assert.assertEquals(2, result.getErrors().size());
-
-        // Exception
-        Assert.assertEquals(ComponentVerifierExtension.VerificationError.StandardCode.EXCEPTION,
result.getErrors().get(0).getCode());
-        Assert.assertNotNull(result.getErrors().get(0).getDetails().get(ComponentVerifierExtension.VerificationError.ExceptionAttribute.EXCEPTION_INSTANCE));
-        Assert.assertTrue(result.getErrors().get(0).getDetails().get(ComponentVerifierExtension.VerificationError.ExceptionAttribute.EXCEPTION_INSTANCE)
instanceof SalesforceException);
-        Assert.assertEquals(400, result.getErrors().get(0).getDetails().get(ComponentVerifierExtension.VerificationError.HttpAttribute.HTTP_CODE));
-
-        // Salesforce Error
-        Assert.assertEquals("invalid_grant", result.getErrors().get(1).getDetail("salesforce_code"));
-    }
-
-    @Test
-    public void testConnectivityWithWrongSecrets() {
-        Map<String, Object> parameters = getParameters();
-        parameters.put("clientId", "wrong-client-id");
-        parameters.put("clientSecret", "wrong-client-secret");
-
-        ComponentVerifierExtension.Result result = getExtension().verify(ComponentVerifierExtension.Scope.CONNECTIVITY,
parameters);
-
-        Assert.assertEquals(ComponentVerifier.Result.Status.ERROR, result.getStatus());
-
-        Assert.assertEquals(ComponentVerifier.Result.Status.ERROR, result.getStatus());
-        Assert.assertEquals(2, result.getErrors().size());
-
-        // Exception
-        Assert.assertEquals(ComponentVerifierExtension.VerificationError.StandardCode.EXCEPTION,
result.getErrors().get(0).getCode());
-        Assert.assertNotNull(result.getErrors().get(0).getDetails().get(ComponentVerifierExtension.VerificationError.ExceptionAttribute.EXCEPTION_INSTANCE));
-        Assert.assertTrue(result.getErrors().get(0).getDetails().get(ComponentVerifierExtension.VerificationError.ExceptionAttribute.EXCEPTION_INSTANCE)
instanceof SalesforceException);
-        Assert.assertEquals(400, result.getErrors().get(0).getDetails().get(ComponentVerifier.VerificationError.HttpAttribute.HTTP_CODE));
-
-        // Salesforce Error
-        Assert.assertEquals("invalid_client_id", result.getErrors().get(1).getDetail("salesforce_code"));
+        Assert.assertEquals(ComponentVerifierExtension.VerificationError.StandardCode.ILLEGAL_PARAMETER_GROUP_COMBINATION,
result.getErrors().get(0).getCode());
+        Assert.assertEquals(ComponentVerifierExtension.VerificationError.StandardCode.ILLEGAL_PARAMETER_GROUP_COMBINATION,
result.getErrors().get(1).getCode());
+        Assert.assertEquals(ComponentVerifierExtension.VerificationError.StandardCode.ILLEGAL_PARAMETER_GROUP_COMBINATION,
result.getErrors().get(2).getCode());
     }
 }


Mime
View raw message