Skip to content

Commit

Permalink
METAMODEL-95: Fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
harel-e authored and kaspersorensen committed Nov 11, 2014
1 parent a2f9711 commit fff3a93
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* [METAMODEL-74] - Fixed bug related to skipping blank values when applying an aggregate function (SUM, AVG etc.)
* [METAMODEL-76] - Query parser improved to handle filters without spaces inbetween operator and operands.
* [METAMODEL-92] - For JSON, MongoDB and CouchDB: Made it possible to specify column names referring nested fields such as "name.first" or "addresses[0].city".
* [METAMODEL-95] - Fixed a critical bug in the Salesforce.com module which caused all number values to be interpreted as '1'.

### Apache MetaModel 4.2.0-incubating

Expand Down
1 change: 1 addition & 0 deletions example-metamodel-integrationtest-configuration.properties
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
#salesforce.username=
#salesforce.password=
#salesforce.securityToken=
#salesforce.endpoint=https://test.salesforce.com

# ---------------------------
# SugarCRM module properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private Object convert(Object value, ColumnType columnType) {
return BooleanComparator.toBoolean(value);
}
if (columnType.isNumber()) {
return NumberComparator.toNumber(columnType.isNumber());
return NumberComparator.toNumber(value);
}
if (columnType.isTimeBased()) {
final SimpleDateFormat dateFormat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;

import org.apache.metamodel.UpdateCallback;
import org.apache.metamodel.UpdateScript;
Expand All @@ -51,7 +49,7 @@ public void testQueryStrangeRecord() throws Exception {
System.err.println(getInvalidConfigurationMessage());
return;
}
SalesforceDataContext dc = new SalesforceDataContext(getUsername(), getPassword(), getSecurityToken());
SalesforceDataContext dc = getSalesforceDataContext();

Column[] timeColumns = dc.getDefaultSchema().getTableByName("Contact").getTimeBasedColumns();
assertEquals(
Expand All @@ -73,6 +71,10 @@ public void testQueryStrangeRecord() throws Exception {
ds.close();
}

private SalesforceDataContext getSalesforceDataContext() {
return new SalesforceDataContext(getEndpoint(), getUsername(), getPassword(), getSecurityToken());
}

public void testInvalidLoginException() throws Exception {
try {
new SalesforceDataContext("foo", "bar", "baz");
Expand Down Expand Up @@ -113,7 +115,7 @@ public void testGetSchema() throws Exception {
return;
}

SalesforceDataContext dc = new SalesforceDataContext(getUsername(), getPassword(), getSecurityToken());
SalesforceDataContext dc = getSalesforceDataContext();

Schema schema = dc.getDefaultSchema();

Expand Down Expand Up @@ -152,7 +154,7 @@ public void testConversionOfTypes() throws Exception {
return;
}

SalesforceDataContext dc = new SalesforceDataContext(getUsername(), getPassword(), getSecurityToken());
SalesforceDataContext dc = getSalesforceDataContext();

runConversionTest(dc, "Account");
runConversionTest(dc, "Contact");
Expand Down Expand Up @@ -188,7 +190,7 @@ public void testQuery() throws Exception {
return;
}

SalesforceDataContext dc = new SalesforceDataContext(getUsername(), getPassword(), getSecurityToken());
SalesforceDataContext dc = getSalesforceDataContext();

DataSet ds;

Expand Down Expand Up @@ -225,7 +227,7 @@ public void testInsertUpdateAndDelete() throws Exception {
return;
}

SalesforceDataContext dc = new SalesforceDataContext(getUsername(), getPassword(), getSecurityToken());
SalesforceDataContext dc = getSalesforceDataContext();

final String tableName = "Account";
final String insertedName = "MetaModel TESTER contact";
Expand Down Expand Up @@ -303,7 +305,7 @@ public void testInsertInContactsWithBirthdate() throws Exception {
return;
}

SalesforceDataContext dc = new SalesforceDataContext(getUsername(), getPassword(), getSecurityToken());
SalesforceDataContext dc = getSalesforceDataContext();

final String tableName = "Contact";
final String firstName = "MetaModelJohn";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* 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.metamodel.salesforce;

import com.sforce.soap.partner.QueryResult;
import com.sforce.ws.ConnectionException;
import com.sforce.ws.bind.TypeMapper;
import com.sforce.ws.parser.PullParserException;
import com.sforce.ws.parser.XmlInputStream;
import org.apache.metamodel.data.Row;
import org.apache.metamodel.schema.Column;
import org.apache.metamodel.schema.ColumnType;
import org.apache.metamodel.schema.MutableColumn;
import org.junit.Test;

import java.io.IOException;
import java.util.List;

import static org.junit.Assert.assertEquals;

public class SalesforceDataSetTest {

@Test
public void testQuery() throws Exception {
QueryResult qr = queryResult("/result/double-value.xml");
MutableColumn version = new MutableColumn("Version", ColumnType.DOUBLE);

SalesforceDataSet dataSet = new SalesforceDataSet(new Column[] { version }, qr, null);
List<Row> rows = dataSet.toRows();

assertEquals(5386.21, rows.get(0).getValue(version));
assertEquals(53.0, rows.get(1).getValue(version));

dataSet.close();
}

private QueryResult queryResult(String input) throws PullParserException, IOException, ConnectionException {
QueryResult queryResult = new QueryResult();
XmlInputStream in = new XmlInputStream();
in.setInput(getClass().getResourceAsStream(input), "UTF-8");
queryResult.load(in, new TypeMapper());
return queryResult;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.FileReader;
import java.util.Properties;

import com.sforce.soap.partner.Connector;
import junit.framework.TestCase;

/**
Expand All @@ -33,6 +34,7 @@ public abstract class SalesforceTestCase extends TestCase {
private String _username;
private String _password;
private String _securityToken;
private String _endpoint;
private boolean _configured;

@Override
Expand All @@ -46,7 +48,8 @@ protected void setUp() throws Exception {
_username = properties.getProperty("salesforce.username");
_password = properties.getProperty("salesforce.password");
_securityToken = properties.getProperty("salesforce.securityToken");

_endpoint = properties.getProperty("salesforce.endpoint", Connector.END_POINT);

_configured = (_username != null && !_username.isEmpty());
} else {
_configured = false;
Expand Down Expand Up @@ -78,4 +81,9 @@ public String getPassword() {
public String getSecurityToken() {
return _securityToken;
}

public String getEndpoint() {
return _endpoint;
}

}
18 changes: 18 additions & 0 deletions salesforce/src/test/resources/result/double-value.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<n1:queryResponse xmlns:n1="urn:partner.soap.sforce.com">
<n1:done>true</n1:done>
<n1:queryLocator n2:nil="true"
xmlns:n2="http://www.w3.org/2001/XMLSchema-instance" />
<n1:records>
<n3:type n4:type="string" xmlns:n3="urn:sobject.partner.soap.sforce.com"
xmlns:n4="http://www.w3.org/2001/XMLSchema-instance">Application</n3:type>
<n5:Version n6:type="string" xmlns:n5="urn:sobject.partner.soap.sforce.com"
xmlns:n6="http://www.w3.org/2001/XMLSchema-instance">5386.21</n5:Version>
</n1:records>
<n1:records>
<n7:type n8:type="string" xmlns:n7="urn:sobject.partner.soap.sforce.com"
xmlns:n8="http://www.w3.org/2001/XMLSchema-instance">Application</n7:type>
<n9:Version n10:type="string" xmlns:n9="urn:sobject.partner.soap.sforce.com"
xmlns:n10="http://www.w3.org/2001/XMLSchema-instance">53.0</n9:Version>
</n1:records>
<n1:size>2</n1:size>
</n1:queryResponse>

0 comments on commit fff3a93

Please sign in to comment.