occi-core 4.3.6 → 5.0.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (359) hide show
  1. checksums.yaml +4 -4
  2. data/.fasterer.yml +3 -0
  3. data/.gitignore +9 -16
  4. data/.rspec +1 -1
  5. data/.rubocop.yml +69 -0
  6. data/.travis.yml +27 -0
  7. data/AUTHORS +8 -6
  8. data/CHANGELOG.md +0 -0
  9. data/Gemfile +1 -1
  10. data/LICENSE +1 -1
  11. data/README.md +25 -170
  12. data/Rakefile +25 -17
  13. data/examples/initialize_model.rb +10 -0
  14. data/examples/parse_action_instance_json.rb +15 -0
  15. data/examples/parse_action_instance_text.rb +15 -0
  16. data/examples/parse_categories_json.rb +15 -0
  17. data/examples/parse_categories_text.rb +15 -0
  18. data/examples/parse_instance_json.rb +15 -0
  19. data/examples/parse_instance_text.rb +15 -0
  20. data/examples/parse_model_json.rb +9 -0
  21. data/examples/parse_model_text.rb +9 -0
  22. data/examples/render_action_instance_json.rb +17 -0
  23. data/examples/render_action_instance_text.rb +17 -0
  24. data/examples/render_instance_json.rb +20 -0
  25. data/examples/render_instance_text.rb +20 -0
  26. data/examples/render_model_json.rb +12 -0
  27. data/examples/render_model_text.rb +12 -0
  28. data/examples/rendering/action_instance.json +6 -0
  29. data/examples/rendering/action_instance.txt +2 -0
  30. data/examples/rendering/categories.json +78 -0
  31. data/examples/rendering/categories.txt +4 -0
  32. data/examples/rendering/instance.json +70 -0
  33. data/examples/rendering/instance.txt +12 -0
  34. data/examples/rendering/model.alt.json +1716 -0
  35. data/examples/rendering/model.json +785 -0
  36. data/examples/rendering/model.txt +68 -0
  37. data/lib/occi/core/action.rb +12 -26
  38. data/lib/occi/core/action_instance.rb +109 -65
  39. data/lib/occi/core/attribute.rb +136 -0
  40. data/lib/occi/core/attribute_definition.rb +269 -0
  41. data/lib/occi/core/category.rb +110 -83
  42. data/lib/occi/core/collection.rb +255 -0
  43. data/lib/occi/core/constants.rb +14 -0
  44. data/lib/occi/core/entity.rb +301 -195
  45. data/lib/occi/core/errors/.gitkeep +0 -0
  46. data/lib/occi/core/errors/attribute_definition_error.rb +11 -0
  47. data/lib/occi/core/errors/attribute_validation_error.rb +13 -0
  48. data/lib/occi/core/errors/category_validation_error.rb +13 -0
  49. data/lib/occi/core/errors/collection_lookup_error.rb +11 -0
  50. data/lib/occi/core/errors/instance_validation_error.rb +13 -0
  51. data/lib/occi/core/errors/mandatory_argument_error.rb +11 -0
  52. data/lib/occi/core/errors/model_lookup_error.rb +11 -0
  53. data/lib/occi/core/errors/parser_error.rb +11 -0
  54. data/lib/occi/core/errors/parsing_error.rb +11 -0
  55. data/lib/occi/core/errors/renderer_error.rb +11 -0
  56. data/lib/occi/core/errors/rendering_error.rb +11 -0
  57. data/lib/occi/core/errors/validation_error.rb +11 -0
  58. data/lib/occi/core/errors.rb +9 -0
  59. data/lib/occi/core/helpers/.gitkeep +0 -0
  60. data/lib/occi/core/helpers/argument_validator.rb +27 -0
  61. data/lib/occi/core/helpers/attributes_accessor.rb +22 -0
  62. data/lib/occi/core/helpers/error_handler.rb +29 -0
  63. data/lib/occi/core/helpers/hash_dereferencer.rb +149 -0
  64. data/lib/occi/core/helpers/identifier_validator.rb +135 -0
  65. data/lib/occi/core/helpers/instance_attribute_resetter.rb +131 -0
  66. data/lib/occi/core/helpers/instance_attributes_accessor.rb +30 -0
  67. data/lib/occi/core/helpers/locatable.rb +40 -0
  68. data/lib/occi/core/helpers/parser_dereferencer.rb +96 -0
  69. data/lib/occi/core/helpers/raw_json_parser.rb +18 -0
  70. data/lib/occi/core/helpers/renderable.rb +93 -0
  71. data/lib/occi/core/helpers/yaml_summoner.rb +44 -0
  72. data/lib/occi/core/helpers.rb +13 -0
  73. data/lib/occi/core/instance_builder.rb +162 -0
  74. data/lib/occi/core/kind.rb +100 -132
  75. data/lib/occi/core/link.rb +47 -72
  76. data/lib/occi/core/mixin.rb +76 -61
  77. data/lib/occi/core/model.rb +341 -0
  78. data/lib/occi/core/parsers/.gitkeep +0 -0
  79. data/lib/occi/core/parsers/base_parser.rb +168 -0
  80. data/lib/occi/core/parsers/json/.gitkeep +0 -0
  81. data/lib/occi/core/parsers/json/action_instance.rb +36 -0
  82. data/lib/occi/core/parsers/json/category.rb +113 -0
  83. data/lib/occi/core/parsers/json/entity.rb +156 -0
  84. data/lib/occi/core/parsers/json/validator/.gitkeep +0 -0
  85. data/lib/occi/core/parsers/json/validator/action-instance.json +3 -0
  86. data/lib/occi/core/parsers/json/validator/entity-collection.json +3 -0
  87. data/lib/occi/core/parsers/json/validator/link-collection.json +3 -0
  88. data/lib/occi/core/parsers/json/validator/link.json +3 -0
  89. data/lib/occi/core/parsers/json/validator/locations.json +3 -0
  90. data/lib/occi/core/parsers/json/validator/mixin-collection.json +3 -0
  91. data/lib/occi/core/parsers/json/validator/model.json +3 -0
  92. data/lib/occi/core/parsers/json/validator/occi-schema.json +277 -0
  93. data/lib/occi/core/parsers/json/validator/resource-collection.json +3 -0
  94. data/lib/occi/core/parsers/json/validator/resource.json +3 -0
  95. data/lib/occi/core/parsers/json/validator.rb +87 -0
  96. data/lib/occi/core/parsers/json_parser.rb +128 -0
  97. data/lib/occi/core/parsers/text/.gitkeep +0 -0
  98. data/lib/occi/core/parsers/text/category.rb +183 -0
  99. data/lib/occi/core/parsers/text/constants.rb +89 -0
  100. data/lib/occi/core/parsers/text/entity.rb +257 -0
  101. data/lib/occi/core/parsers/text/location.rb +48 -0
  102. data/lib/occi/core/parsers/text_parser.rb +257 -0
  103. data/lib/occi/core/parsers.rb +18 -0
  104. data/lib/occi/core/renderer_factory.rb +213 -0
  105. data/lib/occi/core/renderers/.gitkeep +0 -0
  106. data/lib/occi/core/renderers/base_renderer.rb +81 -0
  107. data/lib/occi/core/renderers/json/.gitkeep +0 -0
  108. data/lib/occi/core/renderers/json/action_instance.rb +24 -0
  109. data/lib/occi/core/renderers/json/attributes.rb +50 -0
  110. data/lib/occi/core/renderers/json/base.rb +46 -0
  111. data/lib/occi/core/renderers/json/category.rb +85 -0
  112. data/lib/occi/core/renderers/json/collection.rb +52 -0
  113. data/lib/occi/core/renderers/json/instance.rb +39 -0
  114. data/lib/occi/core/renderers/json/link.rb +48 -0
  115. data/lib/occi/core/renderers/json/model.rb +26 -0
  116. data/lib/occi/core/renderers/json/resource.rb +27 -0
  117. data/lib/occi/core/renderers/json_renderer.rb +72 -0
  118. data/lib/occi/core/renderers/text/.gitkeep +0 -0
  119. data/lib/occi/core/renderers/text/action_instance.rb +36 -0
  120. data/lib/occi/core/renderers/text/attributes.rb +87 -0
  121. data/lib/occi/core/renderers/text/base.rb +82 -0
  122. data/lib/occi/core/renderers/text/category.rb +183 -0
  123. data/lib/occi/core/renderers/text/collection.rb +65 -0
  124. data/lib/occi/core/renderers/text/instance.rb +44 -0
  125. data/lib/occi/core/renderers/text/link.rb +40 -0
  126. data/lib/occi/core/renderers/text/model.rb +41 -0
  127. data/lib/occi/core/renderers/text/resource.rb +109 -0
  128. data/lib/occi/core/renderers/text_renderer.rb +72 -0
  129. data/lib/occi/core/renderers.rb +20 -0
  130. data/lib/occi/core/resource.rb +93 -57
  131. data/lib/occi/core/utils/.gitkeep +0 -0
  132. data/lib/occi/core/version.rb +17 -0
  133. data/lib/occi/core/warehouse/actions/.gitkeep +0 -0
  134. data/lib/occi/core/warehouse/actions/attributes/.gitkeep +0 -0
  135. data/lib/occi/core/warehouse/kinds/.gitkeep +0 -0
  136. data/lib/occi/core/warehouse/kinds/attributes/.gitkeep +0 -0
  137. data/lib/occi/core/warehouse/kinds/attributes/occi.core.id.yml +7 -0
  138. data/lib/occi/core/warehouse/kinds/attributes/occi.core.source.yml +7 -0
  139. data/lib/occi/core/warehouse/kinds/attributes/occi.core.summary.yml +7 -0
  140. data/lib/occi/core/warehouse/kinds/attributes/occi.core.target.yml +7 -0
  141. data/lib/occi/core/warehouse/kinds/attributes/occi.core.title.yml +7 -0
  142. data/lib/occi/core/warehouse/kinds/entity.yml +10 -0
  143. data/lib/occi/core/warehouse/kinds/link.yml +10 -0
  144. data/lib/occi/core/warehouse/kinds/resource.yml +9 -0
  145. data/lib/occi/core/warehouse/mixins/.gitkeep +0 -0
  146. data/lib/occi/core/warehouse/mixins/attributes/.gitkeep +0 -0
  147. data/lib/occi/core/warehouse.rb +115 -0
  148. data/lib/occi/core.rb +59 -23
  149. data/lib/occi/infrastructure/compute.rb +5 -122
  150. data/lib/occi/infrastructure/constants.rb +25 -0
  151. data/lib/occi/infrastructure/instance_builder.rb +24 -0
  152. data/lib/occi/infrastructure/mixins/.gitkeep +0 -0
  153. data/lib/occi/infrastructure/mixins/os_tpl.rb +19 -0
  154. data/lib/occi/infrastructure/mixins/resource_tpl.rb +19 -0
  155. data/lib/occi/infrastructure/mixins.rb +12 -0
  156. data/lib/occi/infrastructure/model.rb +27 -0
  157. data/lib/occi/infrastructure/network.rb +5 -104
  158. data/lib/occi/infrastructure/networkinterface.rb +5 -100
  159. data/lib/occi/infrastructure/storage.rb +5 -59
  160. data/lib/occi/infrastructure/storagelink.rb +5 -54
  161. data/lib/occi/infrastructure/version.rb +5 -0
  162. data/lib/occi/infrastructure/warehouse/actions/.gitkeep +0 -0
  163. data/lib/occi/infrastructure/warehouse/actions/attributes/.gitkeep +0 -0
  164. data/lib/occi/infrastructure/warehouse/actions/compute_restart.yml +12 -0
  165. data/lib/occi/infrastructure/warehouse/actions/compute_save.yml +19 -0
  166. data/lib/occi/infrastructure/warehouse/actions/compute_start.yml +4 -0
  167. data/lib/occi/infrastructure/warehouse/actions/compute_stop.yml +12 -0
  168. data/lib/occi/infrastructure/warehouse/actions/compute_suspend.yml +12 -0
  169. data/lib/occi/infrastructure/warehouse/actions/network_down.yml +4 -0
  170. data/lib/occi/infrastructure/warehouse/actions/network_up.yml +4 -0
  171. data/lib/occi/infrastructure/warehouse/actions/networkinterface_down.yml +4 -0
  172. data/lib/occi/infrastructure/warehouse/actions/networkinterface_up.yml +4 -0
  173. data/lib/occi/infrastructure/warehouse/actions/storage_backup.yml +4 -0
  174. data/lib/occi/infrastructure/warehouse/actions/storage_offline.yml +4 -0
  175. data/lib/occi/infrastructure/warehouse/actions/storage_online.yml +4 -0
  176. data/lib/occi/infrastructure/warehouse/actions/storage_resize.yml +12 -0
  177. data/lib/occi/infrastructure/warehouse/actions/storage_snapshot.yml +4 -0
  178. data/lib/occi/infrastructure/warehouse/actions/storagelink_offline.yml +4 -0
  179. data/lib/occi/infrastructure/warehouse/actions/storagelink_online.yml +4 -0
  180. data/lib/occi/infrastructure/warehouse/kinds/.gitkeep +0 -0
  181. data/lib/occi/infrastructure/warehouse/kinds/attributes/.gitkeep +0 -0
  182. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.compute.architecture.yml +7 -0
  183. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.compute.cores.yml +7 -0
  184. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.compute.hostname.yml +7 -0
  185. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.compute.memory.yml +7 -0
  186. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.compute.speed.yml +7 -0
  187. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.compute.state.yml +7 -0
  188. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.network.label.yml +7 -0
  189. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.network.state.yml +7 -0
  190. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.network.vlan.yml +7 -0
  191. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.networkinterface.interface.yml +7 -0
  192. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.networkinterface.mac.yml +7 -0
  193. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.networkinterface.state.yml +7 -0
  194. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.storage.size.yml +7 -0
  195. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.storage.state.yml +7 -0
  196. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.storagelink.deviceid.yml +7 -0
  197. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.storagelink.mountpoint.yml +7 -0
  198. data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.storagelink.state.yml +7 -0
  199. data/lib/occi/infrastructure/warehouse/kinds/compute.yml +19 -0
  200. data/lib/occi/infrastructure/warehouse/kinds/network.yml +13 -0
  201. data/lib/occi/infrastructure/warehouse/kinds/networkinterface.yml +13 -0
  202. data/lib/occi/infrastructure/warehouse/kinds/storage.yml +15 -0
  203. data/lib/occi/infrastructure/warehouse/kinds/storagelink.yml +13 -0
  204. data/lib/occi/infrastructure/warehouse/mixins/.gitkeep +0 -0
  205. data/lib/occi/infrastructure/warehouse/mixins/attributes/.gitkeep +0 -0
  206. data/lib/occi/infrastructure/warehouse/mixins/attributes/occi.network.address.yml +7 -0
  207. data/lib/occi/infrastructure/warehouse/mixins/attributes/occi.network.allocation.yml +7 -0
  208. data/lib/occi/infrastructure/warehouse/mixins/attributes/occi.network.gateway.yml +7 -0
  209. data/lib/occi/infrastructure/warehouse/mixins/attributes/occi.networkinterface.address.yml +7 -0
  210. data/lib/occi/infrastructure/warehouse/mixins/attributes/occi.networkinterface.allocation.yml +7 -0
  211. data/lib/occi/infrastructure/warehouse/mixins/attributes/occi.networkinterface.gateway.yml +7 -0
  212. data/lib/occi/infrastructure/warehouse/mixins/ipnetwork.yml +11 -0
  213. data/lib/occi/infrastructure/warehouse/mixins/ipnetworkinterface.yml +11 -0
  214. data/lib/occi/infrastructure/warehouse.rb +20 -0
  215. data/lib/occi/infrastructure-ext.rb +35 -0
  216. data/lib/occi/infrastructure.rb +34 -19
  217. data/lib/occi/infrastructure_ext/constants.rb +20 -0
  218. data/lib/occi/infrastructure_ext/instance_builder.rb +22 -0
  219. data/lib/occi/infrastructure_ext/ipreservation.rb +9 -0
  220. data/lib/occi/infrastructure_ext/mixins/.gitkeep +0 -0
  221. data/lib/occi/infrastructure_ext/mixins/availability_zone.rb +19 -0
  222. data/lib/occi/infrastructure_ext/mixins.rb +12 -0
  223. data/lib/occi/infrastructure_ext/model.rb +26 -0
  224. data/lib/occi/infrastructure_ext/securitygroup.rb +9 -0
  225. data/lib/occi/infrastructure_ext/securitygrouplink.rb +9 -0
  226. data/lib/occi/infrastructure_ext/version.rb +5 -0
  227. data/lib/occi/infrastructure_ext/warehouse/actions/.gitkeep +0 -0
  228. data/lib/occi/infrastructure_ext/warehouse/actions/attributes/.gitkeep +0 -0
  229. data/lib/occi/infrastructure_ext/warehouse/actions/ipreservation_down.yml +4 -0
  230. data/lib/occi/infrastructure_ext/warehouse/actions/ipreservation_up.yml +4 -0
  231. data/lib/occi/infrastructure_ext/warehouse/kinds/.gitkeep +0 -0
  232. data/lib/occi/infrastructure_ext/warehouse/kinds/attributes/.gitkeep +0 -0
  233. data/lib/occi/infrastructure_ext/warehouse/kinds/attributes/occi.ipreservation.address.yml +7 -0
  234. data/lib/occi/infrastructure_ext/warehouse/kinds/attributes/occi.ipreservation.state.yml +7 -0
  235. data/lib/occi/infrastructure_ext/warehouse/kinds/attributes/occi.ipreservation.used.yml +7 -0
  236. data/lib/occi/infrastructure_ext/warehouse/kinds/attributes/occi.securitygroup.rules.yml +7 -0
  237. data/lib/occi/infrastructure_ext/warehouse/kinds/attributes/occi.securitygroup.state.yml +7 -0
  238. data/lib/occi/infrastructure_ext/warehouse/kinds/attributes/occi.securitygrouplink.state.yml +7 -0
  239. data/lib/occi/infrastructure_ext/warehouse/kinds/ipreservation.yml +13 -0
  240. data/lib/occi/infrastructure_ext/warehouse/kinds/securitygroup.yml +9 -0
  241. data/lib/occi/infrastructure_ext/warehouse/kinds/securitygrouplink.yml +8 -0
  242. data/lib/occi/infrastructure_ext/warehouse/mixins/.gitkeep +0 -0
  243. data/lib/occi/infrastructure_ext/warehouse/mixins/attributes/.gitkeep +0 -0
  244. data/lib/occi/infrastructure_ext/warehouse.rb +20 -0
  245. data/lib/occi/monkey_island/boolean.rb +6 -0
  246. data/lib/occi/monkey_island/hash.rb +4 -0
  247. data/occi-core.gemspec +26 -26
  248. metadata +312 -243
  249. data/.yardopts +0 -1
  250. data/config/occi.yml +0 -4
  251. data/lib/occi/collection.rb +0 -265
  252. data/lib/occi/core/actions.rb +0 -21
  253. data/lib/occi/core/attributes.rb +0 -411
  254. data/lib/occi/core/categories.rb +0 -64
  255. data/lib/occi/core/dependencies.rb +0 -7
  256. data/lib/occi/core/entities.rb +0 -48
  257. data/lib/occi/core/kinds.rb +0 -22
  258. data/lib/occi/core/links.rb +0 -37
  259. data/lib/occi/core/mixins.rb +0 -37
  260. data/lib/occi/core/properties.rb +0 -108
  261. data/lib/occi/core/resources.rb +0 -14
  262. data/lib/occi/errors/attribute_definitions_converted_error.rb +0 -5
  263. data/lib/occi/errors/attribute_missing_error.rb +0 -5
  264. data/lib/occi/errors/attribute_name_invalid_error.rb +0 -5
  265. data/lib/occi/errors/attribute_not_defined_error.rb +0 -5
  266. data/lib/occi/errors/attribute_property_type_error.rb +0 -5
  267. data/lib/occi/errors/attribute_type_error.rb +0 -5
  268. data/lib/occi/errors/category_not_defined_error.rb +0 -5
  269. data/lib/occi/errors/kind_not_defined_error.rb +0 -5
  270. data/lib/occi/errors/parser_input_error.rb +0 -5
  271. data/lib/occi/errors/parser_type_error.rb +0 -5
  272. data/lib/occi/errors.rb +0 -1
  273. data/lib/occi/extensions/hashie.rb +0 -25
  274. data/lib/occi/helpers/comparators/action_instance.rb +0 -22
  275. data/lib/occi/helpers/comparators/attributes.rb +0 -22
  276. data/lib/occi/helpers/comparators/categories.rb +0 -22
  277. data/lib/occi/helpers/comparators/category.rb +0 -22
  278. data/lib/occi/helpers/comparators/collection.rb +0 -40
  279. data/lib/occi/helpers/comparators/entities.rb +0 -22
  280. data/lib/occi/helpers/comparators/entity.rb +0 -22
  281. data/lib/occi/helpers/comparators/properties.rb +0 -26
  282. data/lib/occi/helpers/comparators.rb +0 -1
  283. data/lib/occi/helpers/inspect.rb +0 -12
  284. data/lib/occi/infrastructure/network/ipnetwork.rb +0 -28
  285. data/lib/occi/infrastructure/networkinterface/ipnetworkinterface.rb +0 -28
  286. data/lib/occi/infrastructure/os_tpl.rb +0 -20
  287. data/lib/occi/infrastructure/resource_tpl.rb +0 -20
  288. data/lib/occi/log.rb +0 -71
  289. data/lib/occi/model.rb +0 -87
  290. data/lib/occi/parser/json.rb +0 -38
  291. data/lib/occi/parser/text/constants.rb +0 -89
  292. data/lib/occi/parser/text.rb +0 -280
  293. data/lib/occi/parser.rb +0 -144
  294. data/lib/occi/settings.rb +0 -10
  295. data/lib/occi/version.rb +0 -3
  296. data/lib/occi-core.rb +0 -53
  297. data/spec/helpers/to_plain.rb +0 -39
  298. data/spec/helpers/yaml_hash.rb +0 -32
  299. data/spec/occi/collection_samples/collection1.json +0 -1
  300. data/spec/occi/collection_samples/directory2/collection2.json +0 -1
  301. data/spec/occi/collection_spec.rb +0 -1003
  302. data/spec/occi/core/action_instance_spec.rb +0 -317
  303. data/spec/occi/core/action_spec.rb +0 -71
  304. data/spec/occi/core/attributes_spec.rb +0 -665
  305. data/spec/occi/core/categories_spec.rb +0 -28
  306. data/spec/occi/core/category_spec.rb +0 -216
  307. data/spec/occi/core/entities_spec.rb +0 -160
  308. data/spec/occi/core/entity_spec.rb +0 -374
  309. data/spec/occi/core/kind_spec.rb +0 -182
  310. data/spec/occi/core/link_spec.rb +0 -52
  311. data/spec/occi/core/links_spec.rb +0 -132
  312. data/spec/occi/core/mixin_spec.rb +0 -38
  313. data/spec/occi/core/mixins_spec.rb +0 -107
  314. data/spec/occi/core/properties_spec.rb +0 -171
  315. data/spec/occi/core/resource_spec.rb +0 -42
  316. data/spec/occi/core_spec.rb +0 -12
  317. data/spec/occi/infrastructure/compute_spec.rb +0 -229
  318. data/spec/occi/infrastructure/network_spec.rb +0 -96
  319. data/spec/occi/infrastructure/networkinterface_spec.rb +0 -96
  320. data/spec/occi/infrastructure/storage_spec.rb +0 -33
  321. data/spec/occi/infrastructure/storagelink_spec.rb +0 -45
  322. data/spec/occi/log_spec.rb +0 -117
  323. data/spec/occi/model_spec.rb +0 -256
  324. data/spec/occi/parser/json_samples/test.json +0 -49
  325. data/spec/occi/parser/text_samples/occi_categories.body_plain.expected +0 -2
  326. data/spec/occi/parser/text_samples/occi_categories.expected +0 -2
  327. data/spec/occi/parser/text_samples/occi_categories.parse_headers.expected +0 -2
  328. data/spec/occi/parser/text_samples/occi_categories.text +0 -2
  329. data/spec/occi/parser/text_samples/occi_compute_rocci_server.expected +0 -11
  330. data/spec/occi/parser/text_samples/occi_compute_rocci_server.text +0 -10
  331. data/spec/occi/parser/text_samples/occi_link_resource_instance.body_plain.expected +0 -7
  332. data/spec/occi/parser/text_samples/occi_link_resource_instance.expected +0 -7
  333. data/spec/occi/parser/text_samples/occi_link_resource_instance.parse.expected +0 -7
  334. data/spec/occi/parser/text_samples/occi_link_resource_instance.text +0 -7
  335. data/spec/occi/parser/text_samples/occi_link_simple.expected +0 -7
  336. data/spec/occi/parser/text_samples/occi_link_simple.text +0 -1
  337. data/spec/occi/parser/text_samples/occi_link_w_attributes.expected +0 -7
  338. data/spec/occi/parser/text_samples/occi_link_w_attributes.text +0 -7
  339. data/spec/occi/parser/text_samples/occi_link_w_category.expected +0 -7
  340. data/spec/occi/parser/text_samples/occi_link_w_category.text +0 -3
  341. data/spec/occi/parser/text_samples/occi_model_categories.expected +0 -3
  342. data/spec/occi/parser/text_samples/occi_model_rocci_server.text +0 -51
  343. data/spec/occi/parser/text_samples/occi_network_rocci_server.body_plain.expected +0 -11
  344. data/spec/occi/parser/text_samples/occi_network_rocci_server.expected +0 -11
  345. data/spec/occi/parser/text_samples/occi_network_rocci_server.resource.header.expected +0 -9
  346. data/spec/occi/parser/text_samples/occi_network_rocci_server.resource.rack.expected +0 -9
  347. data/spec/occi/parser/text_samples/occi_network_rocci_server.text +0 -11
  348. data/spec/occi/parser/text_samples/occi_resource_custom_class_w_attributes.parse.expected +0 -15
  349. data/spec/occi/parser/text_samples/occi_resource_custom_class_w_attributes.text +0 -15
  350. data/spec/occi/parser/text_samples/occi_resource_w_attributes.text +0 -11
  351. data/spec/occi/parser/text_samples/occi_resource_w_inline_links.expected +0 -1
  352. data/spec/occi/parser/text_samples/occi_resource_w_inline_links.text +0 -16
  353. data/spec/occi/parser/text_samples/occi_resource_w_inline_links_only.text +0 -13
  354. data/spec/occi/parser/text_samples/occi_storage_rocci_server.expected +0 -9
  355. data/spec/occi/parser/text_samples/occi_storage_rocci_server.text +0 -9
  356. data/spec/occi/parser/text_spec.rb +0 -320
  357. data/spec/occi/parser_spec.rb +0 -259
  358. data/spec/occi-core_spec.rb +0 -31
  359. data/spec/spec_helper.rb +0 -18
@@ -1,665 +0,0 @@
1
- module Occi
2
- module Core
3
- describe Attributes do
4
-
5
- context '#[]=' do
6
- let(:attributes){ Occi::Core::Attributes.new }
7
- it 'stores properties using hashes in hash notation' do
8
- attributes['test']={}
9
- expect(attributes['test']).to be_kind_of Occi::Core::Properties
10
- end
11
-
12
- it 'stores properties using hashes in dot notation' do
13
- attributes.test={}
14
- expect(attributes.test).to be_kind_of Occi::Core::Properties
15
- end
16
-
17
- it 'rejects keys starting with underscores' do
18
- expect{ attributes['_test']={} }.to raise_error(Occi::Errors::AttributeNameInvalidError)
19
- end
20
-
21
- it 'accepts keys with underscores in other positions' do
22
- expect{ attributes['t_est']={} }.to_not raise_error
23
- end
24
- end
25
-
26
- context '#remove' do
27
- it 'removes attributes' do
28
- attributes=Occi::Core::Attributes.new
29
- attributes['one.two']={}
30
- attributes['one.three']={}
31
-
32
- attr=Occi::Core::Attributes.new
33
- attr['one.two']={}
34
- attributes.remove attr
35
-
36
- expect(attributes['one.two']).to be_nil
37
- expect(attributes['one.three']).to be_kind_of Occi::Core::Properties
38
- end
39
- end
40
-
41
- context '#convert' do
42
- it 'converts properties to an empty attribute' do
43
- attributes=Occi::Core::Attributes.new
44
- attributes.test={}
45
-
46
- attr = attributes.convert
47
- expect(attributes.test).to be_kind_of Occi::Core::Properties
48
-
49
- expect(attr.test).to be_nil
50
- expect(attr._test).to be_kind_of Occi::Core::Properties
51
-
52
- attributes.convert!
53
- expect(attributes.test).to be_nil
54
- expect(attributes._test).to be_kind_of Occi::Core::Properties
55
- end
56
- end
57
-
58
- context 'comparators' do
59
- let(:attrs){
60
- attrs = Occi::Core::Attributes.new
61
- attrs['numbertype'] = { :type => 'number', :default => 42, :mutable => true, :pattern => '^[0-9]+' }
62
- attrs['stringtype'] = { :type => 'string', :pattern => '[adefltuv]+', :default => 'defaultvalue', :mutable => true }
63
- attrs['booleantype'] = { :type => 'boolean', :default => true, :mutable => true}
64
- attrs['booleantypefalse'] = { :type => 'boolean', :default => false, :mutable => true }
65
- attrs['booleantypepattern'] = { :type => 'boolean', :default => true, :mutable => true, :pattern => true }
66
- attrs }
67
- let(:clone){ clone = attrs.clone }
68
- let(:newattrs){
69
- newattrs = Occi::Core::Attributes.new
70
- newattrs['numbertype'] = { :type => 'number', :default => 42, :mutable => true, :pattern => '^[0-9]+' }
71
- newattrs['stringtype'] = { :type => 'string', :pattern => '[adefltuv]+', :default => 'defaultvalue', :mutable => true }
72
- newattrs['booleantype'] = { :type => 'boolean', :default => true, :mutable => true}
73
- newattrs['booleantypefalse'] = { :type => 'boolean', :default => false, :mutable => true }
74
- newattrs['booleantypepattern'] = { :type => 'boolean', :default => true, :mutable => true, :pattern => true }
75
- newattrs }
76
- let(:diffattrs){
77
- diffattrs = Occi::Core::Attributes.new
78
- diffattrs['numbertype'] = { :type => 'number', :default => 42, :mutable => true, :pattern => '^[0-9]+' }
79
- diffattrs['stringtype'] = { :type => 'string', :pattern => '[adefltuv]+', :default => 'anothervalue', :mutable => true } # <=
80
- diffattrs['booleantype'] = { :type => 'boolean', :default => true, :mutable => true}
81
- diffattrs['booleantypefalse'] = { :type => 'boolean', :default => false, :mutable => true }
82
- diffattrs['booleantypepattern'] = { :type => 'boolean', :default => true, :mutable => true, :pattern => true }
83
- diffattrs }
84
-
85
- context '#==' do
86
- it 'matches the same instance' do
87
- expect(attrs==attrs).to eql true
88
- end
89
-
90
- it 'matches a clone' do
91
- expect(attrs==clone).to eql true
92
- end
93
-
94
- it 'matches a new instance with the same content' do
95
- expect(attrs==newattrs).to eql true
96
- end
97
-
98
- it 'does not match nil' do
99
- expect(attrs==nil).to eql false
100
- end
101
-
102
- it 'does not match an instance with different content' do
103
- expect(attrs==diffattrs).to eql false
104
- end
105
- end
106
-
107
- context '#eql?' do
108
- it 'matches the same instance' do
109
- expect(attrs.eql?(attrs)).to eql true
110
- end
111
-
112
- it 'matches a clone' do
113
- expect(attrs.eql?(clone)).to eql true
114
- end
115
-
116
- it 'matches a new instance with the same content' do
117
- expect(attrs.eql?(newattrs)).to eql true
118
- end
119
-
120
- it 'does not match nil' do
121
- expect(attrs.eql?(nil)).to eql false
122
- end
123
-
124
- it 'does not match an instance with different content' do
125
- expect(attrs.eql?(diffattrs)).to eql false
126
- end
127
- end
128
-
129
- context '#equal?' do
130
- it 'matches the same instance' do
131
- expect(attrs.equal?(attrs)).to eql true
132
- end
133
-
134
- it 'does not match a clone' do
135
- expect(attrs.equal?(clone)).to eql false
136
- end
137
- end
138
-
139
- context '#hash' do
140
- it 'matches for the same instance' do
141
- expect(attrs.hash).to eql attrs.hash
142
- end
143
-
144
- it 'matches for a clone' do
145
- expect(attrs.hash).to eql clone.hash
146
- end
147
-
148
- it 'matches for a new instance with the same content' do
149
- expect(attrs.hash).to eql newattrs.hash
150
- end
151
-
152
- it 'does not match for an instance with different content' do
153
- expect(attrs.hash).to_not eql diffattrs.hash
154
- end
155
- end
156
- end
157
-
158
- context '#converted?' do
159
- let(:attrs){ attrs = Occi::Core::Attributes.new
160
- attrs['numbertype'] = { :type => 'number', :default => 42, :mutable => true, :pattern => '^[0-9]+' }
161
- attrs }
162
-
163
- it 'correctly reports uncoverted' do
164
- expect(attrs.converted?).to eql false
165
- end
166
-
167
- it 'correctly reports coverted' do
168
- expect(attrs.convert.converted?).to eql true
169
- end
170
- end
171
-
172
-
173
- context 'rendering' do
174
- let(:attrs){ attrs = Occi::Core::Attributes.new
175
- attrs['numbertype'] = { :type => 'number', :default => 42, :mutable => true, :pattern => '^[0-9]+' }
176
- attrs['stringtype'] = { :type => 'string', :pattern => '[adefltuv]+', :default => 'defaultvalue', :mutable => true }
177
- attrs['booleantype'] = { :type => 'boolean', :default => true, :mutable => true}
178
- attrs['booleantypefalse'] = { :type => 'boolean', :default => false, :mutable => true }
179
- attrs['booleantypepattern'] = { :type => 'boolean', :default => true, :mutable => true, :pattern => true }
180
- attrs.nest!.nested = { :type => 'number', :default => 42, :mutable => true, :pattern => '^[0-9]+' }
181
- attrs['properties'] = Occi::Core::Properties.new
182
- attrs.convert
183
- attrs['numbertype'] = 42
184
- attrs['stringtype'] = 'flute'
185
- attrs['booleantype'] = true
186
- attrs['booleantypefalse'] = false
187
- attrs['booleantypepattern'] = true
188
- attrs.nest!.nested = 11
189
- attrs['category'] = Occi::Core::Category.new
190
- attrs['properties'] = "prop"
191
- attrs['entity'] = Occi::Core::Entity.new
192
- attrs['entity'].id = "testid"
193
- attrs }
194
- let(:empty){ Occi::Core::Attributes.new.convert }
195
-
196
- context '.parse_properties' do
197
-
198
- it 'rejects unsuitable types' do
199
- string = String.new("Teststring")
200
- expect{ Occi::Core::Attributes.parse_properties(string) }.to raise_error(Occi::Errors::ParserInputError)
201
- end
202
-
203
- it 'parses a hashie Mash' do
204
- hash = { :nr => {} }
205
- hash[:nr][:type] = 'number'
206
- hash[:nr][:default] = 42
207
- hash[:nr][:mutable] = true
208
-
209
- expected = Occi::Core::Attributes.new
210
- expected['nr'] = { :type => 'number', :default => 42, :mutable => true }
211
- expected.convert
212
-
213
- attrs = Occi::Core::Attributes.parse_properties(hash)
214
- attrs.convert
215
-
216
- expect(attrs).to eql expected
217
- end
218
- end
219
-
220
- context '#to_string' do
221
- it 'renders attributes correctly' do
222
- expected = ";numbertype=42;stringtype=\"flute\";booleantype=true;booleantypefalse=false;booleantypepattern=true;nest.nested=11;properties=\"prop\";category=\"http://schemas.ogf.org/occi/core#category\";entity=\"/entity/testid\""
223
- expect(attrs.to_string).to eql expected
224
- end
225
-
226
- it 'copes with empty attributes' do
227
- expected = ""
228
- expect(empty.to_string).to eql expected
229
- end
230
-
231
- it 'copes with attribute values containing commas' do
232
- attrs['stringtype'] = "flute,magic"
233
- expected = ";numbertype=42;stringtype=\"flute,magic\";booleantype=true;booleantypefalse=false;booleantypepattern=true;nest.nested=11;properties=\"prop\";category=\"http://schemas.ogf.org/occi/core#category\";entity=\"/entity/testid\""
234
- expect(attrs.to_string).to eql expected
235
- end
236
- end
237
-
238
- context '#to_string_short' do
239
- let(:attrs_with_req_immut) {
240
- attrs = Occi::Core::Attributes.new
241
- attrs['immut_attr'] = { :mutable => false, :required => false }
242
- attrs['req_attr'] = { :mutable => true, :required => true }
243
- attrs['immut_req_attr'] = { :mutable => false, :required => true }
244
- attrs
245
- }
246
-
247
- it 'renders attributes correctly' do
248
- expected = ";attributes=\"numbertype stringtype booleantype booleantypefalse booleantypepattern nest.nested properties category entity\""
249
- expect(attrs.to_string_short).to eql expected
250
- end
251
-
252
- it 'copes with empty attributes' do
253
- expected = ""
254
- expect(empty.to_string_short).to eql expected
255
- end
256
-
257
- it 'renders attributes with properties correctly' do
258
- expected = ";attributes=\"immut_attr{immutable} req_attr{required} immut_req_attr{immutable required}\""
259
- expect(attrs_with_req_immut.to_string_short).to eql expected
260
- end
261
- end
262
-
263
- context '#to_text' do
264
- it 'renders attributes correctly' do
265
- expected = "\nX-OCCI-Attribute: numbertype=42\nX-OCCI-Attribute: stringtype=\"flute\"\nX-OCCI-Attribute: booleantype=true\nX-OCCI-Attribute: booleantypefalse=false\nX-OCCI-Attribute: booleantypepattern=true\nX-OCCI-Attribute: nest.nested=11\nX-OCCI-Attribute: properties=\"prop\"\nX-OCCI-Attribute: category=\"http://schemas.ogf.org/occi/core#category\"\nX-OCCI-Attribute: entity=\"/entity/testid\""
266
- expect(attrs.to_text).to eql expected
267
- end
268
-
269
- it 'copes with empty attributes' do
270
- expected = ""
271
- expect(empty.to_text).to eql expected
272
- end
273
- end
274
-
275
- context '#to_header' do
276
- it 'renders attributes correctly' do
277
- expected = "numbertype=42,stringtype=\"flute\",booleantype=true,booleantypefalse=false,booleantypepattern=true,nest.nested=11,properties=\"prop\",category=\"http://schemas.ogf.org/occi/core#category\",entity=\"/entity/testid\""
278
- expect(attrs.to_header).to eql expected
279
- end
280
-
281
- it 'copes with empty attributes' do
282
- expected = ""
283
- expect(empty.to_header).to eql expected
284
- end
285
- end
286
-
287
- context '#to_array' do
288
- it 'renders attributes correctly' do
289
- expected = ["numbertype=42","stringtype=\"flute\"","booleantype=true","booleantypefalse=false","booleantypepattern=true","nest.nested=11","properties=\"prop\"","category=\"http://schemas.ogf.org/occi/core#category\"","entity=\"/entity/testid\""]
290
- expect(attrs.to_array).to eql expected
291
- end
292
-
293
- it 'copes with empty attributes' do
294
- expect(empty.to_array).to be_empty
295
- end
296
- end
297
-
298
- context '#to_json' do
299
- it 'renders attributes correctly' do
300
- expected = '{"numbertype":42,"stringtype":"flute","booleantype":true,"booleantypefalse":false,"booleantypepattern":true,"nest":{"nested":11},"properties":"prop","category":"http://schemas.ogf.org/occi/core#category","entity":"/entity/testid"}'
301
- expect(attrs.to_json).to eql expected
302
- end
303
-
304
- it 'copes with empty attributes' do
305
- expected = "{}"
306
- expect(empty.to_json).to eql expected
307
- end
308
- end
309
-
310
- context '#as_json' do
311
- it 'renders attributes correctly' do
312
- expected = Hashie::Mash.new
313
- expected["booleantype"] = true
314
- expected["booleantypepattern"] = true
315
- expected["numbertype"] = 42
316
- expected["stringtype"] = "flute"
317
- expected["booleantypefalse"] = false
318
- expected.nest!.nested = 11
319
- expected["category"] = "http://schemas.ogf.org/occi/core#category"
320
- expected["properties"] = "prop"
321
- expected["entity"] = "/entity/testid"
322
-
323
- expect(attrs.as_json).to eql expected
324
- end
325
-
326
- it 'copes with empty attributes' do
327
- expected = Hashie::Mash.new
328
- expect(empty.as_json).to eql expected
329
- end
330
- end
331
- end
332
-
333
- context '.check!' do
334
- let(:attrs){ attrs = Occi::Core::Attributes.new }
335
-
336
- let(:defs){
337
- defs = Occi::Core::Attributes.new
338
- defs['numbertype'] = { :type => 'number',
339
- :default => 42,
340
- :mutable => true,
341
- :pattern => '^[0-9]+' }
342
- defs['stringtype'] = { :type => 'string',
343
- :pattern => '[adefltuv]+',
344
- :default => 'defaultvalue',
345
- :mutable => true }
346
- defs['booleantype'] = { :type => 'boolean',
347
- :default => true,
348
- :mutable => true}
349
- defs['booleantypefalse'] = { :type => 'boolean', #Regression test
350
- :default => false,
351
- :mutable => true }
352
- defs['booleantypepattern'] = { :type => 'boolean',
353
- :default => true,
354
- :mutable => true,
355
- :pattern => true }
356
- defs['nonmandatory'] = { :type => 'string',
357
- :mutable => true,
358
- :required => false }
359
- defs }
360
-
361
- context 'unsupported types and attributes' do
362
- before(:each){ Occi::Settings['compatibility']=false
363
- Occi::Settings['verify_attribute_pattern']=true }
364
- after(:each) { Occi::Settings.reload! }
365
- it 'refuses undefined attribute' do
366
- attrs['otherstring'] = { :type => 'string', :pattern => '[adefltuv]+', :default => 'defaultvalue', :mutable => true }
367
- expect{attrs.check! defs, true}.to raise_exception(Occi::Errors::AttributeNotDefinedError)
368
- end
369
-
370
- it 'refuses unsupported type' do
371
- expect{ defs['unsupported'] = { :type => 'float', :mutable => true } }.to raise_exception(Occi::Errors::AttributePropertyTypeError)
372
- end
373
- end
374
-
375
- context 'nonmandatory attributes' do
376
- it 'removes nil attribute' do
377
- attrs['nonmandatory'] = nil
378
- attrs.check!(defs, true)
379
- expect(attrs.key?('nonmandatory')).to eql false
380
- end
381
-
382
- it 'raises error for unknown attribute with non-nil value' do
383
- attrs['undefined'] = "undefined"
384
- expect{ attrs.check!(defs, true) }.to raise_error(Occi::Errors::AttributeNotDefinedError)
385
- end
386
- end
387
-
388
- context 'mandatory attributes' do
389
- it 'no value and no default, set_defaults true' do
390
- defs['nodefault'] = { :type => 'string', :mutable => true, :required => true }
391
- expect{ attrs.check!(defs, true) }.to raise_error(Occi::Errors::AttributeMissingError)
392
- end
393
-
394
- it 'no value and no default, set_defaults false' do
395
- defs['nodefault'] = { :type => 'string', :mutable => true, :required => true }
396
- expect{ attrs.check!(defs, false) }.to raise_error(Occi::Errors::AttributeMissingError)
397
- end
398
-
399
- it 'nil value and no default, set_defaults true' do
400
- defs['nodefault'] = { :type => 'string', :mutable => true, :required => true }
401
- attrs['nodefault'] = nil
402
- expect{ attrs.check!(defs, true) }.to raise_error(Occi::Errors::AttributeMissingError)
403
- end
404
-
405
- it 'nil value and no default, set_defaults false' do
406
- defs['nodefault'] = { :type => 'string', :mutable => true, :required => true }
407
- attrs['nodefault'] = nil
408
- expect{ attrs.check!(defs, false) }.to raise_error(Occi::Errors::AttributeMissingError)
409
- end
410
-
411
- end
412
-
413
- context 'unsupported attributes' do
414
- before(:each){ Occi::Settings['compatibility']=false
415
- Occi::Settings['verify_attribute_pattern']=true }
416
- after(:each) { Occi::Settings.reload! }
417
- it 'refuses attribute not mentioned in defs' do
418
- attrs['otherstring'] = { :type => 'string',
419
- :default => 'defaultvalue' }
420
- expect{attrs.check! defs, true}.to raise_exception(Occi::Errors::AttributeNotDefinedError)
421
- end
422
- end
423
-
424
- context 'defaults' do
425
- before(:each){ Occi::Settings['compatibility']=false
426
- Occi::Settings['verify_attribute_pattern']=true }
427
- after(:each) { Occi::Settings.reload! }
428
-
429
- context 'setting defaults' do
430
- it 'sets numeric default' do
431
- attrs.check! defs, true
432
- expect(attrs['numbertype']).to eq 42
433
- end
434
- it 'sets string default' do
435
- attrs.check! defs, true
436
- expect(attrs['stringtype']).to eq 'defaultvalue'
437
- end
438
- it 'sets boolean default if true' do
439
- attrs.check! defs, true
440
- expect(attrs['booleantype']).to eq true
441
- end
442
- it 'sets boolean default if false' do
443
- attrs.check! defs, true
444
- expect(attrs['booleantypefalse']).to eq false
445
- end
446
- it 'can be checked twice in a row' do
447
- attrs.check! defs, true
448
- expect{ attrs.check! defs, true }.to_not raise_exception
449
- end
450
- end
451
-
452
- context 'skipping defaults if already set' do
453
- it 'skips numeric default' do
454
- attrs['numbertype'] = 12
455
- attrs.check! defs, true
456
- expect(attrs['numbertype']).to eq 12
457
- end
458
- it 'skips string default' do
459
- attrs['stringtype'] = 'fault'
460
- attrs.check! defs, true
461
- expect(attrs['stringtype']).to eq 'fault'
462
- end
463
- it 'skips boolean default if true' do
464
- attrs['booleantype'] = false
465
- attrs.check! defs, true
466
- expect(attrs['booleantype']).to eq false
467
- end
468
- it 'skips boolean default if false' do
469
- attrs['booleantypefalse'] = true
470
- attrs.check! defs, true
471
- expect(attrs['booleantypefalse']).to eq true
472
- end
473
- end
474
-
475
- context 'skipping defaults if set_defaults is false' do
476
- it 'skips numeric default' do
477
- attrs.check! defs, false
478
- expect(attrs['numbertype']).to_not eq 42
479
- end
480
- it 'skips string default' do
481
- attrs.check! defs, false
482
- expect(attrs['stringtype']).to_not eq 'defaultvalue'
483
- end
484
- it 'skips boolean default if true' do
485
- attrs.check! defs, false
486
- expect(attrs['booleantype']).to_not eq true
487
- end
488
- it 'skips boolean default if false' do
489
- attrs.check! defs, false
490
- expect(attrs['booleantypefalse']).to_not eq false
491
- end
492
- end
493
-
494
- context 'patterns' do
495
- it 'checks string pattern' do
496
- attrs['stringtype'] = 'bflmpsvz'
497
- expect{attrs.check! defs, true}.to raise_exception(Occi::Errors::AttributeTypeError)
498
- end
499
- it 'checks numeric pattern' do
500
- attrs['numbertype'] = -32
501
- expect{attrs.check! defs, true}.to raise_exception(Occi::Errors::AttributeTypeError)
502
- end
503
- it 'checks boolean pattern' do # Possibly an overkill
504
- attrs['booleantypepattern'] = false
505
- expect{attrs.check! defs, true}.to raise_exception(Occi::Errors::AttributeTypeError)
506
- end
507
- end
508
- end
509
-
510
- context 'calling through #check' do
511
- before(:each){ Occi::Settings['compatibility']=false
512
- Occi::Settings['verify_attribute_pattern']=true }
513
- after(:each) { Occi::Settings.reload! }
514
-
515
- context 'setting defaults' do
516
- it 'sets numeric default' do
517
- as = attrs.check defs, true
518
- expect(as['numbertype']).to eq 42
519
- end
520
- it 'sets string default' do
521
- as = attrs.check defs, true
522
- expect(as['stringtype']).to eq 'defaultvalue'
523
- end
524
- it 'sets boolean default if true' do
525
- as = attrs.check defs, true
526
- expect(as['booleantype']).to eq true
527
- end
528
- it 'sets boolean default if false' do
529
- as = attrs.check defs, true
530
- expect(as['booleantypefalse']).to eq false
531
- end
532
- end
533
- end
534
-
535
- context 'converted definitions' do
536
- it 'succeeds for unconverted definitions' do
537
- expect{attrs.check! defs, true}.to_not raise_exception
538
- end
539
-
540
- it 'throws exception for converted definitions' do
541
- defs.convert!
542
- expect{attrs.check! defs, true}.to raise_exception(Occi::Errors::AttributeDefinitionsConvrertedError)
543
- end
544
- end
545
- end
546
-
547
-
548
- context '.validate_and_assign' do
549
- let(:attrs){
550
- attrs = Occi::Core::Attributes.new
551
- attrs['entity'] = {:type => 'string'}
552
- attrs['category'] = {:type => 'string'}
553
- attrs['numeric'] = {:type => 'number'}
554
- attrs['tr'] = {:type => 'boolean'}
555
- attrs['fal'] = {:type => 'boolean'}
556
- attrs.convert
557
- attrs}
558
-
559
- it 'correctly accepts Occi::Core::Attributes' do
560
- inattrs = attrs
561
- inattrs['numbertype'] = { :type => 'number', :default => 42, :mutable => true, :pattern => '^[0-9]+' }
562
- inattrs.convert
563
- inattrs['numbertype'] = 13
564
-
565
- attrs['numbertype'] = inattrs['numbertype']
566
- expect(attrs).to eql inattrs
567
- end
568
-
569
- it 'correctly accepts Occi::Core::Properties' do
570
- expected = attrs
571
- attrs['properties'] = Occi::Core::Properties.new
572
-
573
- expected['properties'] = { :type => 'string', :pattern => '.*', :mutable => false, :required => false }
574
- expected.convert
575
-
576
- expect(attrs).to eql expected
577
- end
578
-
579
- it 'correctly accepts Hash' do
580
- expected = attrs
581
- attrs['hash'] = { :type => 'string', :pattern => '.*', :mutable => false, :required => false }
582
-
583
- expected['hash'] = { :type => 'string', :pattern => '.*', :mutable => false, :required => false }
584
- expected.convert
585
-
586
- expect(attrs).to eql expected
587
- end
588
-
589
- it 'correctly accepts Occi::Core::Entity' do
590
- entity = Occi::Core::Entity.new
591
- attrs['entity'] = entity
592
-
593
- expect(attrs['entity']).to eql entity
594
- end
595
-
596
- it 'correctly accepts Occi::Core::Category' do
597
- category = Occi::Core::Category.new
598
- attrs['category'] = category
599
-
600
- expect(attrs['category']).to eql category
601
- end
602
-
603
- it 'correctly accepts String' do
604
- attrs['string'] = "teststring"
605
- expect(attrs['string']).to eql "teststring"
606
- end
607
-
608
- it 'correctly accepts Numeric' do
609
- attrs['numeric'] = 16
610
- expect(attrs['numeric']).to eql 16
611
- end
612
-
613
- it 'correctly accepts Numeric given as string' do
614
- attrs['numeric'] = '16'
615
- expect(attrs['numeric']).to eql 16
616
- end
617
-
618
- it 'correctly accepts floating point given as string' do
619
- attrs['numeric'] = '16.4'
620
- expect(attrs['numeric']).to eql 16.4
621
- end
622
-
623
- it 'correctly refuses empty Numeric value' do
624
- expect{ attrs['numeric'] = '' }.to raise_exception(Occi::Errors::AttributeTypeError)
625
- end
626
-
627
- it 'correctly refuses malformed Numeric value' do
628
- expect{ attrs['numeric'] = '1.b' }.to raise_exception(Occi::Errors::AttributeTypeError)
629
- expect{ attrs['numeric'] = '.b' }.to raise_exception(Occi::Errors::AttributeTypeError)
630
- expect{ attrs['numeric'] = 'b.1' }.to raise_exception(Occi::Errors::AttributeTypeError)
631
- end
632
-
633
- it 'correctly accepts TrueClass' do
634
- attrs['tr'] = true
635
- expect(attrs['tr']).to eql true
636
- end
637
-
638
- it 'correctly accepts TrueClass given as string' do
639
- attrs['tr'] = 'true'
640
- expect(attrs['tr']).to eql true
641
- end
642
-
643
- it 'correctly accepts FalseClass' do
644
- attrs['fal'] = false
645
- expect(attrs['fal']).to eql false
646
- end
647
-
648
- it 'correctly accepts FalseClass given as string' do
649
- attrs['fal'] = 'false'
650
- expect(attrs['fal']).to eql false
651
- end
652
-
653
- it 'correctly responds to NilClass' do
654
- attrs['nil'] = nil
655
- expect(attrs['nil']).to eql nil
656
- end
657
-
658
- it 'rejects unsupported types' do
659
- type = Occi::Log.new(nil)
660
- expect{ attrs['log'] = type }.to raise_error(Occi::Errors::AttributeTypeError)
661
- end
662
- end
663
- end
664
- end
665
- end
@@ -1,28 +0,0 @@
1
- module Occi
2
- module Core
3
- describe Categories do
4
-
5
- it "replaces an existing category instance when a model is added with the instance from the model" do
6
- categories = Occi::Core::Categories.new
7
- categories << Occi::Core::Resource.kind
8
- model = Occi::Model.new
9
- resource = model.get_by_id Occi::Core::Resource.type_identifier
10
- resource.location = '/new_location/'
11
- categories.model = model
12
- expect(categories.first.location).to eq '/new_location/'
13
- end
14
-
15
- it "replaces a category string when a model is added with the instance from the model" do
16
- categories = Occi::Core::Categories.new
17
- model = Occi::Model.new
18
- categories.model = model
19
- categories << Occi::Core::Resource.type_identifier
20
-
21
- resource = model.get_by_id Occi::Core::Resource.type_identifier
22
- resource.location = '/new_location/'
23
- expect(categories.first.location).to eq '/new_location/'
24
- end
25
-
26
- end
27
- end
28
- end