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,374 +0,0 @@
1
- module Occi
2
- module Core
3
- describe Entity do
4
- let(:entity){
5
- entity = Occi::Core::Entity.new
6
- entity.id = 'baf1'
7
- entity
8
- }
9
- let(:testaction){ Occi::Core::Action.new scheme='http://schemas.ogf.org/occi/core/entity/action#', term='testaction', title='testaction action' }
10
-
11
- it "initializes itself successfully" do
12
- expect(entity).to be_kind_of Occi::Core::Entity
13
- end
14
-
15
- context 'initializiation of a subclass using a type identifier' do
16
- let(:type_identifier){ 'http://example.com/testnamespace#test' }
17
- let(:typed_entity){ Occi::Core::Entity.new type_identifier }
18
-
19
- it 'has the correct kind' do
20
- expect(typed_entity).to be_kind_of 'Com::Example::Testnamespace::Test'.constantize
21
- end
22
-
23
- it 'uses the right identifier' do
24
- expect(typed_entity.kind.type_identifier).to eq type_identifier
25
- end
26
-
27
- it 'relates to Entity' do
28
- expect(typed_entity.kind.related.first).to eq Occi::Core::Entity.kind
29
- end
30
- end
31
-
32
- context "initialization of a subclass using an OCCI Kind" do
33
- let(:kind){ Occi::Core::Resource.kind }
34
- let(:kind_entity){ Occi::Core::Entity.new kind }
35
-
36
- it 'has the correct kind' do
37
- expect(kind_entity).to be_kind_of Occi::Core::Resource
38
- end
39
-
40
- it 'uses the right identifier' do
41
- expect(kind_entity.kind.type_identifier).to eq Occi::Core::Resource.type_identifier
42
- end
43
-
44
- it 'relates to Entity' do
45
- expect(kind_entity.kind.related.first).to eq Occi::Core::Entity.kind
46
- end
47
- end
48
-
49
- context '#kind' do
50
- it 'accepts kind from string' do
51
- entity.kind = 'http://example.com/testnamespace#test'
52
- expect(entity.kind).to eql Com::Example::Testnamespace::Test
53
- end
54
-
55
- it 'accepts kind from class' do
56
- entity.kind = Com::Example::Testnamespace::Test
57
- expect(entity.kind).to eql Com::Example::Testnamespace::Test
58
- end
59
- end
60
-
61
- context '#mixins' do
62
- let(:mixin){ 'http://example.com/mynamespace#mymixin' }
63
-
64
- it "converts mixin type identifiers to objects if a mixin is added to the entities mixins" do
65
- entity.mixins << mixin
66
- expect(entity.mixins.first.to_s).to eq mixin
67
- end
68
- end
69
-
70
- context 'attributes' do
71
-
72
- context 'checking attribute validity' do
73
- before(:each) { Occi::Settings['compatibility']=false }
74
- after(:each) { Occi::Settings.reload! }
75
-
76
- it 'fails check with model missing' do
77
- expect { entity.check }.to raise_error
78
- end
79
-
80
- it 'runs check successfully with a model registered' do
81
- entity.model = Occi::Model.new
82
- entity.title = 'test'
83
- uuid = UUIDTools::UUID.random_create.to_s
84
- Occi::Settings['verify_attribute_pattern']=true
85
- expect { entity.id = uuid }.to_not raise_error
86
- end
87
-
88
- it 'rejects values not matching pattern' do
89
- entity.model = Occi::Model.new
90
- entity.id = 'id with spaces'
91
- Occi::Settings['verify_attribute_pattern']=true
92
- expect{ entity.id = 'id with spaces' }.to raise_error Occi::Errors::AttributeTypeError
93
- end
94
-
95
- end
96
-
97
- context '#location' do
98
- it 'can be set and read' do
99
- entity.location = 'TestLoc'
100
- expect(entity.location).to eq 'TestLoc'
101
- end
102
-
103
- it 'can be constructed from id' do
104
- entity.id = UUIDTools::UUID.random_create.to_s
105
- expect(entity.location).to eq '/entity/' + entity.id
106
- end
107
-
108
- it 'gets normalized to a relative path' do
109
- entity.location = 'http://example.org/entity/12'
110
- expect(entity.location).to eq '/entity/12'
111
- end
112
-
113
- it 'can be set to nil and default to /kind/id' do
114
- entity.location = nil
115
- expect(entity.location).to eq '/entity/baf1'
116
- end
117
-
118
- it 'will not duplicate slashes' do
119
- entity.id = '//baf1'
120
- expect(entity.location).to eq '/entity/baf1'
121
- end
122
-
123
- it 'will not duplicate kind location' do
124
- entity.id = '/entity/baf1'
125
- expect(entity.location).to eq '/entity/baf1'
126
- end
127
- end
128
-
129
- context '#title' do
130
- it 'can be set and read' do
131
- entity.title = 'TestTitle'
132
- expect(entity.title).to eq 'TestTitle'
133
- end
134
- end
135
- end
136
-
137
- context '#actions' do
138
- it 'can be populated through redirection' do
139
- entity.actions << testaction
140
- expect(entity.actions.count).to eq 1
141
- end
142
-
143
- it 'can be assigned through the setter method' do
144
- acts = Occi::Core::Actions.new
145
- acts << testaction
146
- entity.actions=acts
147
- expect(entity.actions.count).to eq 1
148
- end
149
- end
150
-
151
- context '#to_text' do
152
- it 'renders fresh instance in text correctly' do
153
- expected = %Q|Category: entity;scheme="http://schemas.ogf.org/occi/core#";class="kind";location="/entity/";title="entity"
154
- X-OCCI-Attribute: occi.core.id="baf1"|
155
- expect(entity.to_text).to eq(expected)
156
- end
157
-
158
- it 'renders instance with attributes in text correctly' do
159
- entity.actions << testaction
160
- entity.title = 'TestTitle'
161
- entity.location = '/TestLoc/1'
162
- entity.mixins << 'http://example.com/mynamespace#mymixin'
163
-
164
- expected = %Q|Category: entity;scheme="http://schemas.ogf.org/occi/core#";class="kind";location="/entity/";title="entity"
165
- Category: mymixin;scheme="http://example.com/mynamespace#";class="mixin";location="/mixin/mymixin/";title=""
166
- X-OCCI-Attribute: occi.core.id="baf1"
167
- X-OCCI-Attribute: occi.core.title="TestTitle"
168
- Link: </TestLoc/1?action=testaction>;rel="http://schemas.ogf.org/occi/core/entity/action#testaction"|
169
- expect(entity.to_text).to eq(expected)
170
- end
171
- end
172
-
173
- context '#to_header' do
174
- it 'renders fresh instance in HTTP Header correctly' do
175
- expected = Hashie::Mash.new
176
- expected['Category'] = 'entity;scheme="http://schemas.ogf.org/occi/core#";class="kind";location="/entity/";title="entity"'
177
- expected['X-OCCI-Attribute'] = 'occi.core.id="baf1"'
178
-
179
- expect(entity.to_header).to eql(expected)
180
- end
181
-
182
- it 'renders instance with attributes in HTTP Header correctly' do
183
- entity.actions << testaction
184
- entity.title = 'TestTitle'
185
- entity.location = '/TestLoc/1'
186
- entity.mixins << 'http://example.com/mynamespace#mymixin'
187
-
188
- expected = Hashie::Mash.new
189
- expected['Category'] = 'entity;scheme="http://schemas.ogf.org/occi/core#";class="kind";location="/entity/";title="entity",mymixin;scheme="http://example.com/mynamespace#";class="mixin";location="/mixin/mymixin/";title=""'
190
- expected['X-OCCI-Attribute'] = 'occi.core.id="baf1",occi.core.title="TestTitle"'
191
- expected['Link'] = '</TestLoc/1?action=testaction>;rel="http://schemas.ogf.org/occi/core/entity/action#testaction"'
192
-
193
- expect(entity.to_header).to eql(expected)
194
- end
195
- end
196
-
197
- context '#as_json' do
198
- it 'renders element as JSON' do
199
- entity.actions << testaction
200
-
201
- expected = Hashie::Mash.new JSON.parse('{"kind":"http://schemas.ogf.org/occi/core#entity","actions":["http://schemas.ogf.org/occi/core/entity/action#testaction"],"attributes":{"occi":{"core":{"id":"baf1"}}},"id":"baf1"}')
202
- expect(entity.as_json).to eql expected
203
- end
204
- end
205
-
206
- context '#check' do
207
- let(:defs){
208
- defs = Occi::Core::Attributes.new
209
- defs['occi.core.id'] = { :type=> 'string',
210
- :required => true }
211
- defs['numbertype'] = { :type => 'number',
212
- :default => 42,
213
- :mutable => true,
214
- :pattern => '^[0-9]+' }
215
- defs['stringtype'] = { :type => 'string',
216
- :pattern => '[adefltuv]+',
217
- :default => 'defaultvalue',
218
- :mutable => true }
219
- defs['booleantype'] = { :type => 'boolean',
220
- :default => true,
221
- :mutable => true}
222
- defs['booleantypefalse'] = { :type => 'boolean',
223
- :default => false,
224
- :mutable => true }
225
- defs['booleantypepattern'] = { :type => 'boolean',
226
- :default => true,
227
- :mutable => true,
228
- :pattern => true }
229
- defs }
230
- let(:kind){ Occi::Core::Kind.new 'http://schemas.ogf.org/occi/core#', 'testkind', 'Test Kind', defs }
231
- let(:model){ model = Occi::Model.new
232
- model.register(kind)
233
- model.register(defmixin)
234
- model }
235
- let(:defmixin){ defmixin = Occi::Core::Mixin.new 'http://schemas.ogf.org/occi/core#', 'testmixin'
236
- defmixin.attributes['mixinstring'] = { :type => 'string',
237
- :pattern => '.*',
238
- :default => 'mixdefault',
239
- :mutable => true }
240
- defmixin }
241
- let(:mixin){ Occi::Core::Mixin.new 'http://schemas.ogf.org/occi/core#', 'testmixin' }
242
- let(:undefmixin){ Occi::Core::Mixin.new 'http://schemas.ogf.org/occi/core#', 'fake_mixin' }
243
-
244
- let(:entity){ entity = Occi::Core::Entity.new(kind, [], defs)
245
- entity.model = model
246
- entity.mixins << mixin
247
- entity }
248
-
249
-
250
- before(:each){ Occi::Settings['compatibility']=false
251
- Occi::Settings['verify_attribute_pattern']=true }
252
- after(:each) { Occi::Settings.reload! }
253
-
254
- context 'unsupported types' do
255
- it 'refuses unsupported type' do
256
- expect{ entity.attributes['othertype'] = { :type => 'other', :default => 'defaultvalue' } }.to raise_exception(Occi::Errors::AttributePropertyTypeError)
257
- end
258
- end
259
-
260
- context 'defaults' do
261
- context 'setting defaults' do
262
- it 'sets numeric default' do
263
- entity.check(true)
264
- expect(entity.attributes['numbertype']).to eq 42
265
- end
266
- it 'sets string default' do
267
- entity.check(true)
268
- expect(entity.attributes['stringtype']).to eq 'defaultvalue'
269
- end
270
- it 'sets mixin string default' do
271
- entity.check(true)
272
- expect(entity.attributes['mixinstring']).to eq 'mixdefault'
273
- end
274
- it 'sets boolean default if true' do
275
- entity.check(true)
276
- expect(entity.attributes['booleantype']).to eq true
277
- end
278
- it 'sets boolean default if false' do
279
- entity.check(true)
280
- expect(entity.attributes['booleantypefalse']).to eq false
281
- end
282
- it 'can be checked twice in a row' do
283
- entity.check(true)
284
- expect{ entity.check(true) }.to_not raise_exception
285
- end
286
- it 'skips numeric default' do
287
- entity.attributes['numbertype'] = 12
288
- entity.check(true)
289
- expect(entity.attributes['numbertype']).to eq 12
290
- end
291
- it 'skips string default' do
292
- entity.attributes['stringtype'] = 'fault'
293
- entity.check(true)
294
- expect(entity.attributes['stringtype']).to eq 'fault'
295
- end
296
- it 'skips boolean default if true' do
297
- entity.attributes['booleantype'] = false
298
- entity.check(true)
299
- expect(entity.attributes['booleantype']).to eq false
300
- end
301
- it 'skips boolean default if false' do
302
- entity.attributes['booleantypefalse'] = true
303
- entity.check(true)
304
- expect(entity.attributes['booleantypefalse']).to eq true
305
- end
306
- end
307
-
308
- context 'patterns' do
309
- it 'checks string pattern' do
310
- expect{ entity.attributes['stringtype'] = 'bflmpsvz' }.to raise_exception(Occi::Errors::AttributeTypeError)
311
- end
312
- it 'checks numeric pattern' do
313
- expect{ entity.attributes['numbertype'] = -32 }.to raise_exception(Occi::Errors::AttributeTypeError)
314
- end
315
- it 'checks boolean pattern' do
316
- expect{ entity.attributes['booleantypepattern'] = false }.to raise_exception(Occi::Errors::AttributeTypeError)
317
- end
318
- end
319
- end
320
-
321
- context 'exceptions' do
322
- it 'raisees exception for missing model' do
323
- ent = Occi::Core::Entity.new(kind, [], defs)
324
- expect{ ent.check(true) }.to raise_exception ArgumentError
325
- end
326
-
327
- it 'raises exception for nonexistent kind' do
328
- ent = Occi::Core::Entity.new(kind, [], defs)
329
- mod = Occi::Model.new
330
- ent.model = mod
331
- expect{ ent.check(true) }.to raise_exception Occi::Errors::KindNotDefinedError
332
- end
333
-
334
- it 'raises expection for nonexistent mixins' do
335
- ent = Occi::Core::Entity.new(kind, [], defs)
336
- ent.model = model
337
- ent.mixins << undefmixin
338
- expect{ ent.check }.to raise_exception Occi::Errors::CategoryNotDefinedError
339
- end
340
- end
341
- end
342
-
343
- context '#attribute_properties' do
344
- it 'gets attribute properties' do
345
- properties = entity.attribute_properties
346
- expect(properties.occi.core.count).to eql 4
347
- end
348
- end
349
-
350
- context '#empty?' do
351
-
352
- it 'returns false for a new instance with defaults' do
353
- expect(entity.empty?).to be false
354
- end
355
-
356
- it 'returns true for an instance without a kind' do
357
- ent = entity.clone
358
- ent.kind = nil
359
-
360
- expect(ent.empty?).to be true
361
- end
362
-
363
- it 'returns true for an instance without an identifier' do
364
- ent = entity.clone
365
- ent.id = nil
366
-
367
- expect(ent.empty?).to be true
368
- end
369
-
370
- end
371
-
372
- end
373
- end
374
- end
@@ -1,182 +0,0 @@
1
- module Occi
2
- module Core
3
- describe Kind do
4
-
5
- describe '#get_class' do
6
-
7
- context 'OCCI Resource class' do
8
- let(:scheme){ 'http://schemas.ogf.org/occi/core' }
9
- let(:term){ 'resource' }
10
- let(:klass){ Occi::Core::Kind.get_class scheme, term }
11
-
12
- it 'gets OCCI Resource class by term term and scheme' do
13
- expect(klass).to be Occi::Core::Resource
14
- end
15
- it 'also gets the superclass' do
16
- expect(klass.superclass).to be Occi::Core::Entity
17
- #TODO: Possibly move this test to resource_spec?
18
- end
19
- end
20
-
21
- context 'non-predefined OCCI class' do
22
- let(:scheme){ 'http://example.com/occi' }
23
- let(:term){ 'test' }
24
- let(:related){ ['http://schemas.ogf.org/occi/core#resource'] }
25
- let(:klass){ Occi::Core::Kind.get_class scheme, term, related }
26
-
27
- it 'gets non predefined OCCI class by term, scheme and related class' do
28
- expect(klass).to be Com::Example::Occi::Test
29
- end
30
- it 'also gets the superclass' do
31
- expect(klass.superclass).to be Occi::Core::Resource
32
- #TODO: Possibly move this test to resource_spec?
33
- end
34
- end
35
-
36
- it 'does not get OCCI class by term and scheme if it relates to existing class not derived from OCCI Entity' do
37
- scheme = 'http://hashie/'
38
- term = 'mash'
39
- related = ['http://schemas.ogf.org/occi/core#resource']
40
- expect { Occi::Core::Kind.get_class scheme, term, related }.to raise_error
41
- end
42
-
43
- context 'in case of improper input' do
44
-
45
- it 'handles parent overriden with nil' do
46
- expect(Occi::Core::Kind.get_class 'http://schemas.ogf.org/occi/core', 'resource', nil).to eq Occi::Core::Resource
47
- end
48
-
49
- it 'copes with invalid characters in scheme' do
50
- expect{Occi::Core::Kind.get_class 'http://schemas ogf.org/occi/core', 'resource'}.to raise_error(URI::InvalidURIError)
51
- end
52
- it 'copes with non-URI-like structure of the scheme' do
53
- expect{Occi::Core::Kind.get_class 'doesnotexist', 'resource'}.to raise_error(StandardError)
54
- end
55
-
56
- context 'handling invalid characters in term' do
57
- after { Occi::Settings.reload! }
58
- it 'copes with compatibility on' do
59
- Occi::Settings['compatibility'] = true
60
- expect(Occi::Core::Kind.get_class 'http://schemas.ogf.org/occi/core', '# #resource$').to eq Occi::Core::Resource
61
- end
62
-
63
- it 'copes with compatibility off' do
64
- Occi::Settings['compatibility'] = false
65
- expect{Occi::Core::Kind.get_class 'http://schemas.ogf.org/occi/core', '# #resource$'}.to raise_error(ArgumentError)
66
- end
67
- end
68
-
69
- it 'handles nil scheme' do
70
- expect{Occi::Core::Kind.get_class nil, 'resource'}.to raise_error(ArgumentError)
71
- end
72
-
73
- it 'handles nil resource' do
74
- expect{Occi::Core::Kind.get_class 'http://schemas.ogf.org/occi/core', nil}.to raise_error(ArgumentError)
75
- end
76
-
77
- it 'copes with invalid parent' do
78
- expect{Occi::Core::Kind.get_class 'http://example.com/occi', 'test', 'http://s chemas.ogf.org/occi/core#resource'}.to raise_error(URI::InvalidURIError)
79
- end
80
-
81
- it 'copes with parent missing term' do
82
- expect{Occi::Core::Kind.get_class 'http://example.com/occi', 'test', 'http://s chemas.ogf.org/occi/core'}.to raise_error(ArgumentError)
83
- end
84
-
85
- end
86
-
87
- end
88
-
89
- describe '#location' do
90
- let(:kind) { Occi::Core::Kind.new }
91
-
92
- it 'gets normalized to a relative path' do
93
- kind.location = 'http://example.org/kind/'
94
- expect(kind.location).to eq '/kind/'
95
- end
96
-
97
- it 'can be set to nil' do
98
- kind.location = nil
99
- expect(kind.location).to be_nil
100
- end
101
-
102
- it 'raises an error when location does not start and end with a slash' do
103
- expect { kind.location = '/no_slash' }.to raise_error
104
- expect { kind.location = 'no_slash/' }.to raise_error
105
- end
106
-
107
- it 'raises an error when location contains spaces' do
108
- expect { kind.location = '/sla shes/' }.to raise_error
109
- end
110
-
111
- it 'can be set to an empty string' do
112
- expect { kind.location = '' }.not_to raise_error
113
- end
114
- end
115
-
116
- describe '#related_to?' do
117
- let(:base){ Occi::Core::Kind.new 'http://occi.test.case/core/kind', 'base' }
118
- let(:related){ Occi::Core::Kind.new 'http://occi.test.case/core/kind/base', 'related', 'title', Occi::Core::Attributes.new, base }
119
- let(:unrelated){ Occi::Core::Kind.new 'http://occi.test.case/core/kind', 'unrelated' }
120
-
121
- it 'recognizes existing relationship' do
122
- expect(related.related_to?(base)).to eq true
123
- end
124
-
125
- it 'does not give false positives on non-existent relationship' do
126
- expect(base.related_to?(unrelated)).to eq false
127
- end
128
-
129
- it 'recognizes transitive relationships' #do #TODO This test actually works, but fails because te feature is not yet implemented
130
- # grandchild = Occi::Core::Kind.new 'http://occi.test.case/core/kind/base', 'related', 'title', Occi::Core::Attributes.new, related
131
- # expect(grandchild.related_to?(base)).to eq true
132
- # end
133
- end
134
-
135
- describe '#as_json' do
136
- let(:kind){ Occi::Core::Kind.new }
137
-
138
- it 'renders JSON correctly from freshly initialized object' do
139
- expected = '{"location":"/kind/","term":"kind","scheme":"http://schemas.ogf.org/occi/core#","attributes":{}}'
140
- hash=Hashie::Mash.new(JSON.parse(expected))
141
- expect(kind.as_json).to eql(hash)
142
- end
143
-
144
- it 'renders JSON correctly with optional attributes' do
145
- kind.title = "test title"
146
- expected = '{"location":"/kind/","term":"kind","scheme":"http://schemas.ogf.org/occi/core#","title":"test title","attributes":{}}'
147
- hash=Hashie::Mash.new(JSON.parse(expected))
148
- expect(kind.as_json).to eql(hash)
149
- end
150
-
151
- it 'renders JSON correctly with special characters' do
152
- kind.title = "Some special characters @#\$%"
153
- expected = '{"location":"/kind/","term":"kind","scheme":"http://schemas.ogf.org/occi/core#","title":"Some special characters @#\$%","attributes":{}}'
154
- hash=Hashie::Mash.new(JSON.parse(expected))
155
- expect(kind.as_json).to eql(hash)
156
- end
157
-
158
- end
159
-
160
- describe '#to_string' do
161
- let(:kind){ Occi::Core::Kind.new }
162
-
163
- it 'produces a string correctly from freshly initialized object' do
164
- expected = ('scheme="http://schemas.ogf.org/occi/core#";class="kind";location="/kind/";kind').split(/;/)
165
- actual = kind.to_string.split(/;/)
166
- expect(actual).to match_array(expected)
167
- end
168
-
169
- it 'produces a string correctly with optional attributes' do
170
- kind.title = "test title"
171
- expected = ('scheme="http://schemas.ogf.org/occi/core#";class="kind";location="/kind/";kind;title="test title"').split(/;/)
172
- actual = kind.to_string.split(/;/)
173
- expect(actual).to match_array(expected)
174
- end
175
-
176
- # TODO: Optional attributes, special characters
177
-
178
- end
179
-
180
- end
181
- end
182
- end
@@ -1,52 +0,0 @@
1
- module Occi
2
- module Core
3
- describe Link do
4
- # XXX This is a poor man's spec file, by no means exhaustive
5
- # XXX So far it is only used to cover code otherwise not
6
- # XXX covered by calls from other specs
7
-
8
- context '#check' do
9
- let(:defs){
10
- defs = Occi::Core::Attributes.new
11
- defs['occi.core.id'] = { :type=> 'string', :required => true }
12
- defs['stringtype'] = { :type => 'string', :pattern => '[adefltuv]+',
13
- :default => 'defaultforlink', :mutable => true, :required => true }
14
- defs['stringtypeoptional'] = { :type => 'string', :pattern => '[adefltuv]+',
15
- :default => 'defaultforlink', :mutable => true, :required => false }
16
- defs }
17
-
18
- it 'sets default for required attribute' do
19
- link = Occi::Core::Link.new
20
- link.kind.attributes.merge!(defs)
21
- model = Occi::Model.new
22
- model.register(link.kind)
23
- link.model = model
24
- link.source = Occi::Core::Resource.new
25
-
26
- link.check
27
- expect(link.attributes['stringtype']).to eql 'defaultforlink'
28
- expect(link.attributes['stringtypeoptional']).to be_nil
29
- end
30
-
31
- it 'accepts the set_defaults flag' do
32
- link = Occi::Core::Link.new
33
- link.kind.attributes.merge!(defs)
34
- model = Occi::Model.new
35
- model.register(link.kind)
36
- link.model = model
37
- link.source = Occi::Core::Resource.new
38
-
39
- link.check(true)
40
- expect(link.attributes['stringtype']).to eql 'defaultforlink'
41
- expect(link.attributes['stringtypeoptional']).to eql 'defaultforlink'
42
- end
43
-
44
- it 'raises error if no relationship is set' do
45
- norel = Occi::Core::Link.new
46
- norel.instance_eval { @rel=nil }
47
- expect{ norel.check }.to raise_exception ArgumentError
48
- end
49
- end
50
- end
51
- end
52
- end