diff --git a/packages/composer-cucumber-steps/features/assets.feature b/packages/composer-cucumber-steps/features/assets.feature index 2e182bd44e..de70080827 100644 --- a/packages/composer-cucumber-steps/features/assets.feature +++ b/packages/composer-cucumber-steps/features/assets.feature @@ -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/ diff --git a/packages/composer-cucumber-steps/features/basic-sample-network.bna b/packages/composer-cucumber-steps/features/basic-sample-network.bna index 72474fa195..6c3f2c7f7e 100644 Binary files a/packages/composer-cucumber-steps/features/basic-sample-network.bna and b/packages/composer-cucumber-steps/features/basic-sample-network.bna differ diff --git a/packages/composer-cucumber-steps/features/basic-sample-network/models/sample.cto b/packages/composer-cucumber-steps/features/basic-sample-network/models/sample.cto index d2f62c72a7..8358fe1dfe 100644 --- a/packages/composer-cucumber-steps/features/basic-sample-network/models/sample.cto +++ b/packages/composer-cucumber-steps/features/basic-sample-network/models/sample.cto @@ -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 diff --git a/packages/composer-cucumber-steps/lib/composer.js b/packages/composer-cucumber-steps/lib/composer.js index 77346a8ed2..3240c47032 100644 --- a/packages/composer-cucumber-steps/lib/composer.js +++ b/packages/composer-cucumber-steps/lib/composer.js @@ -586,12 +586,14 @@ 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; @@ -599,6 +601,28 @@ class Composer { 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.