Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/composer-cucumber-steps/features/assets.feature
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,17 @@ Feature: Asset steps
| assetId |
| 1 |
And I should get an error matching /the asset with ID .* exists/

Scenario: I should handle all primitive types in tables for assets
When I add the following asset of type org.acme.sample.SampleComplexAsset
| assetId | booleanField | dateTimeField | doubleField | integerField | longField |
| abc | true | 1970-01-01T00:00:00Z | 3.14159 | 13 | 999999999 |
Then I should have the following assets of type org.acme.sample.SampleComplexAsset
| assetId | booleanField | dateTimeField | doubleField | integerField | longField |
| abc | true | 1970-01-01T00:00:00Z | 3.14159 | 13 | 999999999 |

Scenario: I should get an error for non-primitive types in a table
When I add the following asset of type org.acme.sample.SampleComplexAsset
| assetId | booleanField | dateTimeField | doubleField | integerField | longField | arrayField |
| abc | true | 1970-01-01T00:00:00Z | 3.14159 | 13 | 999999999 | banana |
Then I should get an error matching /arrayField/
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ asset SampleAsset identified by assetId {
o String value
}

asset SampleComplexAsset identified by assetId {
o String assetId
o Boolean booleanField
o DateTime dateTimeField
o Double doubleField
o Integer integerField
o Long longField
o String[] arrayField optional
}

participant SampleParticipant identified by participantId {
o String participantId
o String firstName
Expand Down
30 changes: 27 additions & 3 deletions packages/composer-cucumber-steps/lib/composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,19 +586,43 @@ class Composer {
resource = this.factory.newResource(namespace, name, identifier);
}
properties.forEach((property) => {
if (typeof row[property.getName()] === 'undefined') {
const propertyName = property.getName();
const propertyValue = row[propertyName];
if (typeof propertyValue === 'undefined') {
return;
} else if (property instanceof RelationshipDeclaration) {
resource[property.getName()] = this.factory.newRelationship(property.getNamespace(), property.getType(), row[property.getName()]);
resource[propertyName] = this.factory.newRelationship(property.getNamespace(), property.getType(), propertyValue);
} else {
resource[property.getName()] = row[property.getName()];
resource[propertyName] = this.convertValueToType(propertyValue, property.getType());
}
});
return resource;
});
return resources;
}

/**
* Convert a property value string into a specific type.
* @param {String} value - property value.
* @param {String} type - model type.
* @return {*} correctly typed value.
*/
convertValueToType(value, type) {
switch(type) {
case 'Boolean':
return new Boolean(value).valueOf();
case 'DateTime':
return new Date(value);
case 'Double':
return Number.parseFloat(value);
case 'Integer':
case 'Long':
return Number.parseInt(value);
default:
return value;
}
}

/**
* Compare two resources for equality, and throw an exception if they do not match.
* @param {Resource} actualResource The actual resource.
Expand Down