Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Salesforce : Expand producer test coverage #2998

Merged
merged 2 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.camel.quarkus.component.salesforce;

import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;

Expand All @@ -36,14 +38,23 @@

import org.apache.camel.CamelContext;
import org.apache.camel.ConsumerTemplate;
import org.apache.camel.Exchange;
import org.apache.camel.FluentProducerTemplate;
import org.apache.camel.component.salesforce.SalesforceEndpointConfig;
import org.apache.camel.component.salesforce.api.dto.CreateSObjectResult;
import org.apache.camel.component.salesforce.api.dto.GlobalObjects;
import org.apache.camel.component.salesforce.api.dto.Limits;
import org.apache.camel.component.salesforce.api.dto.RestResources;
import org.apache.camel.component.salesforce.api.dto.SObjectBasicInfo;
import org.apache.camel.component.salesforce.api.dto.SObjectDescription;
import org.apache.camel.component.salesforce.api.dto.Version;
import org.apache.camel.component.salesforce.api.dto.bulk.ContentType;
import org.apache.camel.component.salesforce.api.dto.bulk.JobInfo;
import org.apache.camel.component.salesforce.api.dto.bulk.OperationEnum;
import org.apache.camel.component.salesforce.api.utils.QueryHelper;
import org.apache.camel.quarkus.component.salesforce.generated.Account;
import org.apache.camel.quarkus.component.salesforce.generated.QueryRecordsAccount;
import org.apache.camel.quarkus.component.salesforce.model.GlobalObjectsAndHeaders;
import org.apache.camel.spi.RouteController;

@Path("/salesforce")
Expand Down Expand Up @@ -80,6 +91,19 @@ public Account getAccount() {
return request.getRecords().get(0);
}

@Path("/account/query")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Account getAccountByQueryHelper() {
String generatedQuery = QueryHelper.queryToFetchAllFieldsOf(new Account());
QueryRecordsAccount request = template
.toF("salesforce:query?sObjectQuery=%s LIMIT 1&sObjectClass=%s",
generatedQuery,
QueryRecordsAccount.class.getName())
.request(QueryRecordsAccount.class);
return request.getRecords().get(0);
}

@Path("/account")
@POST
@Consumes(MediaType.TEXT_PLAIN)
Expand Down Expand Up @@ -108,6 +132,17 @@ public Response deleteAccount(@PathParam("id") String accountId) {
return Response.noContent().build();
}

@Path("/account/{id}")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Account getAccountById(@PathParam("id") String accountId) {
Account account = template
.to("salesforce:getSObjectWithId?sObjectName=Account&sObjectIdName=Id&sObjectClass=" + Account.class.getName())
.withBody(accountId)
.request(Account.class);
return account;
}

@Path("/bulk")
@POST
@Produces(MediaType.APPLICATION_JSON)
Expand Down Expand Up @@ -165,4 +200,53 @@ private JsonObject jobInfoToJsonObject(JobInfo jobInfo) {
objectBuilder.add("state", jobInfo.getState().value().toUpperCase(Locale.US));
return objectBuilder.build();
}

@Path("sobjects/force-limit")
@GET
@Produces(MediaType.APPLICATION_JSON)
public GlobalObjectsAndHeaders getSObjectsWithForceLimitInfo() {
// Testing producer with headers
Exchange exchange = template.to("salesforce:getGlobalObjects")
.withHeader("Sforce-Limit-Info", Collections.singletonList("api-usage")).send();
GlobalObjectsAndHeaders objectsAndHeaders = new GlobalObjectsAndHeaders(
exchange.getMessage().getBody(GlobalObjects.class))
.withHeader("Sforce-Limit-Info", exchange.getMessage().getHeader("Sforce-Limit-Info", String.class));
return objectsAndHeaders;
}

@Path("versions")
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<Version> getListVersions() {
return template.to("salesforce:getVersions").request(List.class);
}

@Path("resources")
@GET
@Produces(MediaType.APPLICATION_JSON)
public RestResources getListResources() {
return template.to("salesforce:getResources").request(RestResources.class);
}

@Path("basic-info/account")
@GET
public SObjectBasicInfo getAccountBasicInfo() {
return template.to("salesforce:getBasicInfo?sObjectName=Account")
.request(SObjectBasicInfo.class);
}

@Path("describe/account")
@GET
public SObjectDescription getAccountDescription() {
return template.to("salesforce:getDescription?sObjectName=Account")
.request(SObjectDescription.class);
}

@Path("limits")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Limits getLimits() {
return template.to("salesforce:limits").request(Limits.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,8 @@
import javax.annotation.Generated;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
import org.apache.camel.component.salesforce.api.MultiSelectPicklistConverter;
import org.apache.camel.component.salesforce.api.MultiSelectPicklistDeserializer;
import org.apache.camel.component.salesforce.api.MultiSelectPicklistSerializer;
import org.apache.camel.component.salesforce.api.PicklistEnumConverter;
import org.apache.camel.component.salesforce.api.dto.AbstractDescribedSObjectBase;
import org.apache.camel.component.salesforce.api.dto.SObjectDescription;
Expand Down Expand Up @@ -634,6 +629,18 @@ public void setDandbCompanyId(String DandbCompanyId) {
this.DandbCompanyId = DandbCompanyId;
}

private String OperatingHoursId;

@JsonProperty("OperatingHoursId")
public String getOperatingHoursId() {
return this.OperatingHoursId;
}

@JsonProperty("OperatingHoursId")
public void setOperatingHoursId(String OperatingHoursId) {
this.OperatingHoursId = OperatingHoursId;
}

@XStreamConverter(PicklistEnumConverter.class)
private Account_CustomerPriorityEnum CustomerPriority__c;

Expand Down Expand Up @@ -722,21 +729,6 @@ public void setSLAExpirationDate__c(java.time.LocalDate SLAExpirationDate__c) {
this.SLAExpirationDate__c = SLAExpirationDate__c;
}

@XStreamConverter(MultiSelectPicklistConverter.class)
private Account_MyMultiselectEnum[] MyMultiselect__c;

@JsonProperty("MyMultiselect__c")
@JsonSerialize(using = MultiSelectPicklistSerializer.class)
public Account_MyMultiselectEnum[] getMyMultiselect__c() {
return this.MyMultiselect__c;
}

@JsonProperty("MyMultiselect__c")
@JsonDeserialize(using = MultiSelectPicklistDeserializer.class)
public void setMyMultiselect__c(Account_MyMultiselectEnum[] MyMultiselect__c) {
this.MyMultiselect__c = MyMultiselect__c;
}

private QueryRecordsAccount ChildAccounts;

@JsonProperty("ChildAccounts")
Expand Down Expand Up @@ -934,29 +926,29 @@ private static SObjectDescription createSObjectDescription() {
final SObjectField sObjectField58 = createField("DandbCompanyId", "D&B Company ID", "reference", "tns:ID", 18, false,
true, false, false, false, false, false);
fields1.add(sObjectField58);
final SObjectField sObjectField59 = createField("CustomerPriority__c", "Customer Priority", "picklist", "xsd:string",
255, false, true, false, false, true, false, false);
final SObjectField sObjectField59 = createField("OperatingHoursId", "Operating Hour ID", "reference", "tns:ID", 18,
false, true, false, false, false, false, false);
fields1.add(sObjectField59);
final SObjectField sObjectField60 = createField("SLA__c", "SLA", "picklist", "xsd:string", 255, false, true, false,
false, true, false, false);
final SObjectField sObjectField60 = createField("CustomerPriority__c", "Customer Priority", "picklist", "xsd:string",
255, false, true, false, false, true, false, false);
fields1.add(sObjectField60);
final SObjectField sObjectField61 = createField("Active__c", "Active", "picklist", "xsd:string", 255, false, true,
false, false, true, false, false);
final SObjectField sObjectField61 = createField("SLA__c", "SLA", "picklist", "xsd:string", 255, false, true, false,
false, true, false, false);
fields1.add(sObjectField61);
final SObjectField sObjectField62 = createField("NumberofLocations__c", "Number of Locations", "double", "xsd:double",
0, false, true, false, false, true, false, false);
final SObjectField sObjectField62 = createField("Active__c", "Active", "picklist", "xsd:string", 255, false, true,
false, false, true, false, false);
fields1.add(sObjectField62);
final SObjectField sObjectField63 = createField("UpsellOpportunity__c", "Upsell Opportunity", "picklist", "xsd:string",
255, false, true, false, false, true, false, false);
final SObjectField sObjectField63 = createField("NumberofLocations__c", "Number of Locations", "double", "xsd:double",
0, false, true, false, false, true, false, false);
fields1.add(sObjectField63);
final SObjectField sObjectField64 = createField("SLASerialNumber__c", "SLA Serial Number", "string", "xsd:string", 10,
false, true, false, false, true, false, false);
final SObjectField sObjectField64 = createField("UpsellOpportunity__c", "Upsell Opportunity", "picklist", "xsd:string",
255, false, true, false, false, true, false, false);
fields1.add(sObjectField64);
final SObjectField sObjectField65 = createField("SLAExpirationDate__c", "SLA Expiration Date", "date", "xsd:date", 0,
final SObjectField sObjectField65 = createField("SLASerialNumber__c", "SLA Serial Number", "string", "xsd:string", 10,
false, true, false, false, true, false, false);
fields1.add(sObjectField65);
final SObjectField sObjectField66 = createField("MyMultiselect__c", "MyMultiselect", "multipicklist", "xsd:string",
4099, false, true, false, false, true, false, false);
final SObjectField sObjectField66 = createField("SLAExpirationDate__c", "SLA Expiration Date", "date", "xsd:date", 0,
false, true, false, false, true, false, false);
fields1.add(sObjectField66);

description.setLabel("Account");
Expand All @@ -966,7 +958,6 @@ private static SObjectDescription createSObjectDescription() {
final SObjectDescriptionUrls sObjectDescriptionUrls1 = new SObjectDescriptionUrls();
sObjectDescriptionUrls1.setApprovalLayouts("/services/data/v50.0/sobjects/Account/describe/approvalLayouts");
sObjectDescriptionUrls1.setCompactLayouts("/services/data/v50.0/sobjects/Account/describe/compactLayouts");
sObjectDescriptionUrls1.setDefaultValues("/services/data/v50.0/sobjects/Account/defaultValues?recordTypeId&fields");
sObjectDescriptionUrls1.setDescribe("/services/data/v50.0/sobjects/Account/describe");
sObjectDescriptionUrls1.setLayouts("/services/data/v50.0/sobjects/Account/describe/layouts");
sObjectDescriptionUrls1.setListviews("/services/data/v50.0/sobjects/Account/listviews");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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.quarkus.component.salesforce.model;

import java.util.HashMap;
import java.util.Map;

import org.apache.camel.component.salesforce.api.dto.GlobalObjects;

public class GlobalObjectsAndHeaders {
private GlobalObjects globalObjects;
private Map<String, String> headers;

public GlobalObjectsAndHeaders() {
}

public GlobalObjectsAndHeaders(GlobalObjects globalObjects) {
this.globalObjects = globalObjects;
}

public GlobalObjects getGlobalObjects() {
return globalObjects;
}

public void setGlobalObjects(GlobalObjects globalObjects) {
this.globalObjects = globalObjects;
}

public GlobalObjectsAndHeaders withHeader(String key, String value) {
if (headers == null) {
headers = new HashMap<>();
}
headers.put(key, value);
return this;
}

public Map<String, String> getHeaders() {
return headers;
}

public void setHeaders(Map<String, String> headers) {
this.headers = headers;
}

public String getHeader(String key) {
return headers != null ? headers.get(key) : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
*/
package org.apache.camel.quarkus.component.salesforce;

import io.quarkus.test.junit.NativeImageTest;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;

@EnabledIfEnvironmentVariable(named = "SALESFORCE_USERNAME", matches = ".+")
@EnabledIfEnvironmentVariable(named = "SALESFORCE_PASSWORD", matches = ".+")
@EnabledIfEnvironmentVariable(named = "SALESFORCE_CLIENTID", matches = ".+")
@EnabledIfEnvironmentVariable(named = "SALESFORCE_CLIENTSECRET", matches = ".+")
@NativeImageTest
public class SalesforceIntegrationIT extends SalesforceIntegrationTest {
}