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,1003 +0,0 @@
1
- module Occi
2
- describe Collection do
3
-
4
- context 'initialization' do
5
- let(:collection){ collection = Occi::Collection.new }
6
-
7
- context 'with base objects' do
8
- before(:each) {
9
- collection.kinds << "http://schemas.ogf.org/occi/infrastructure#compute"
10
- collection.mixins << "http://example.com/occi/tags#my_mixin"
11
- collection.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#start"
12
- collection.action = Occi::Core::ActionInstance.new
13
- collection.resources << Occi::Core::Resource.new
14
- collection.links << Occi::Core::Link.new
15
- }
16
-
17
- it 'calssifies kind correctly' do
18
- expect(collection.kinds.first).to be_kind_of Occi::Core::Kind
19
- end
20
-
21
- it 'calssifies mixin correctly' do
22
- expect(collection.mixins.first).to be_kind_of Occi::Core::Mixin
23
- end
24
-
25
- it 'calssifies action correctly' do
26
- expect(collection.actions.first).to be_kind_of Occi::Core::Action
27
- end
28
-
29
- it 'calssifies resource correctly' do
30
- expect(collection.resources.first).to be_kind_of Occi::Core::Resource
31
- end
32
-
33
- it 'calssifies link correctly' do
34
- expect(collection.links.first).to be_kind_of Occi::Core::Link
35
- end
36
-
37
- it 'calssifies action instance correctly' do
38
- expect(collection.action).to be_kind_of Occi::Core::ActionInstance
39
- end
40
- end
41
- end
42
-
43
- context '#model' do
44
- let(:collection){ collection = Occi::Collection.new }
45
- it 'registers a model' do
46
- expect(collection.model).to be_kind_of Occi::Model
47
- end
48
- end
49
-
50
- context '#resources' do
51
- let(:collection){ collection = Occi::Collection.new }
52
- it 'can create a new OCCI Resource' do
53
- collection.resources.create 'http://schemas.ogf.org/occi/core#resource'
54
- expect(collection.resources.first).to be_kind_of Occi::Core::Resource
55
- end
56
- end
57
-
58
- context '#check' do
59
- let(:collection){ collection = Occi::Collection.new }
60
-
61
- it 'checks against model without failure' do
62
- collection.resources.create 'http://schemas.ogf.org/occi/core#resource'
63
- expect{ collection.check }.to_not raise_error
64
- end
65
-
66
- it 'does not raise an error for unknown categories by default' do
67
- collection.kinds << Occi::Core::Kind.new('http://example.org/test/stuff#', 'here')
68
- expect { collection.check }.to_not raise_error
69
- end
70
-
71
- it 'raises an error for unknown categories when requested' do
72
- collection.kinds << Occi::Core::Kind.new('http://example.org/test/stuff#', 'here')
73
- expect { collection.check(true) }.to raise_error
74
- end
75
-
76
- end
77
-
78
- context '#get_related_to' do
79
- let(:collection){ collection = Occi::Collection.new }
80
- before(:each){
81
- collection.kinds << Occi::Core::Resource.kind
82
- collection.kinds << Occi::Core::Link.kind
83
- }
84
- it 'gets Entity as a related kind' do
85
- expect(collection.get_related_to(Occi::Core::Entity.kind)).to eql collection
86
- expect(collection.get_related_to(Occi::Core::Entity.kind.type_identifier)).to eql collection
87
- end
88
-
89
- it 'gets Resource as a related kind' do
90
- expect(collection.get_related_to(Occi::Core::Resource.kind).kinds.first).to eql Occi::Core::Resource.kind
91
- expect(collection.get_related_to(Occi::Core::Resource.kind.type_identifier).kinds.first).to eql Occi::Core::Resource.kind
92
- end
93
-
94
- it 'gets Link as a related kind' do
95
- expect(collection.get_related_to(Occi::Core::Link.kind).kinds.first).to eql Occi::Core::Link.kind
96
- expect(collection.get_related_to(Occi::Core::Link.kind.type_identifier).kinds.first).to eql Occi::Core::Link.kind
97
- end
98
-
99
- it 'fails loudly when no category is given' do
100
- expect { collection.get_related_to("") } .to raise_error RuntimeError
101
- expect { collection.get_related_to(nil) } .to raise_error RuntimeError
102
- end
103
- end
104
-
105
- context '#merge' do
106
- let(:collection){ collection = Occi::Collection.new }
107
- before(:each) {
108
- collection.kinds << "http://schemas.ogf.org/occi/infrastructure#compute"
109
- collection.mixins << "http://example.com/occi/tags#my_mixin"
110
- collection.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#start"
111
- collection.action = Occi::Core::ActionInstance.new
112
- collection.resources << Occi::Core::Resource.new
113
- collection.links << Occi::Core::Link.new
114
- }
115
- context 'two fully initiated collections' do
116
- let(:action){ Occi::Core::Action.new scheme='http://schemas.ogf.org/occi/core/entity/action#', term='testaction', title='testaction action' }
117
- let(:coll2){
118
- coll2 = Occi::Collection.new
119
- coll2.kinds << "http://schemas.ogf.org/occi/infrastructure#storage"
120
- coll2.mixins << "http://example.com/occi/tags#another_mixin"
121
- coll2.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#stop"
122
- coll2.action = Occi::Core::ActionInstance.new action
123
- coll2.resources << Occi::Core::Resource.new
124
- coll2.links << Occi::Core::Link.new
125
- coll2
126
- }
127
- let(:merged){ collection.merge(coll2, collection) }
128
-
129
- context 'resulting collection' do
130
- it 'has the correct number of kinds' do
131
- expect(merged.kinds.count).to eql 2
132
- end
133
-
134
- it 'has the correct number of mixins' do
135
- expect(merged.mixins.count).to eql 2
136
- end
137
-
138
- it 'has the correct number of actions' do
139
- expect(merged.actions.count).to eql 2
140
- end
141
-
142
- it 'has the correct number of resources' do
143
- expect(merged.resources.count).to eql 2
144
- end
145
-
146
- it 'has the correct number of links' do
147
- expect(merged.links.count).to eql 2
148
- end
149
-
150
- it 'inherits action from the other collection' do
151
- expect(merged.action.action.term).to eql "testaction"
152
- end
153
-
154
- it 'does not inherit action from first collection' do
155
- expect(merged.action.action.term).to_not eql "action_instance"
156
- end
157
-
158
- it 'holds kinds from first collection' do
159
- expect(collection.kinds.subset?(merged.kinds)).to eql true
160
- end
161
-
162
- it 'holds mixins from first collection' do
163
- expect(collection.mixins.subset?(merged.mixins)).to eql true
164
- end
165
-
166
- it 'holds actions from first collection' do
167
- expect(collection.actions.subset?(merged.actions)).to eql true
168
- end
169
-
170
- it 'holds resources from first collection' do
171
- expect(collection.resources.subset?(merged.resources)).to eql true
172
- end
173
-
174
- it 'holds links from first collection' do
175
- expect(collection.links.subset?(merged.links)).to eql true
176
- end
177
-
178
- it 'holds kinds from other collection' do
179
- expect(coll2.kinds.subset?(merged.kinds)).to eql true
180
- end
181
-
182
- it 'holds mixins from other collection' do
183
- expect(coll2.mixins.subset?(merged.mixins)).to eql true
184
- end
185
-
186
- it 'holds actions from other collection' do
187
- expect(coll2.actions.subset?(merged.actions)).to eql true
188
- end
189
-
190
- it 'holds resources from other collection' do
191
- expect(coll2.resources.subset?(merged.resources)).to eql true
192
- end
193
-
194
- it 'holds links from other collection' do
195
- expect(coll2.links.subset?(merged.links)).to eql true
196
- end
197
-
198
- it 'does not replace first collection' do
199
- expect(merged).to_not eql collection
200
- end
201
- end
202
-
203
- context 'first original' do
204
- it 'kept the correct number of kinds' do
205
- expect(collection.kinds.count).to eql 1
206
- end
207
-
208
- it 'kept the correct number of mixins' do
209
- expect(collection.mixins.count).to eql 1
210
- end
211
-
212
- it 'kept the correct number of actions' do
213
- expect(collection.actions.count).to eql 1
214
- end
215
-
216
- it 'kept the correct number of resources' do
217
- expect(collection.resources.count).to eql 1
218
- end
219
-
220
- it 'kept the correct number of links' do
221
- expect(collection.links.count).to eql 1
222
- end
223
- end
224
-
225
- context 'second original' do
226
- it 'kept the correct number of kinds' do
227
- expect(coll2.kinds.count).to eql 1
228
- end
229
-
230
- it 'kept the correct number of mixins' do
231
- expect(coll2.mixins.count).to eql 1
232
- end
233
-
234
- it 'kept the correct number of actions' do
235
- expect(coll2.actions.count).to eql 1
236
- end
237
-
238
- it 'kept the correct number of resources' do
239
- expect(coll2.resources.count).to eql 1
240
- end
241
-
242
- it 'kept the correct number of links' do
243
- expect(coll2.links.count).to eql 1
244
- end
245
- end
246
- end
247
-
248
- it 'copes with an empty collection' do
249
- emptycol = Occi::Collection.new
250
- expect{merged = collection.merge(emptycol, collection)}.to_not raise_error
251
- end
252
-
253
- it 'copes with both collections empty' do
254
- empty1 = Occi::Collection.new
255
- empty2 = Occi::Collection.new
256
- expect{merged = collection.merge(empty1, empty2)}.to_not raise_error
257
- end
258
-
259
- end
260
-
261
- context '#merge!' do
262
- let(:collection){ collection = Occi::Collection.new
263
- collection.kinds << "http://schemas.ogf.org/occi/infrastructure#compute"
264
- collection.mixins << "http://example.com/occi/tags#my_mixin"
265
- collection.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#start"
266
- collection.action = Occi::Core::ActionInstance.new
267
- collection.resources << Occi::Core::Resource.new
268
- collection.links << Occi::Core::Link.new
269
- collection
270
- }
271
- context 'two fully initiated collections' do
272
- let(:action){ Occi::Core::Action.new scheme='http://schemas.ogf.org/occi/core/entity/action#', term='testaction', title='testaction action' }
273
- let(:coll2){
274
- coll2 = Occi::Collection.new
275
- coll2.kinds << "http://schemas.ogf.org/occi/infrastructure#storage"
276
- coll2.mixins << "http://example.com/occi/tags#another_mixin"
277
- coll2.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#stop"
278
- coll2.action = Occi::Core::ActionInstance.new action
279
- coll2.resources << Occi::Core::Resource.new
280
- coll2.links << Occi::Core::Link.new
281
- coll2
282
- }
283
- before(:each) { collection.merge!(coll2) }
284
- context 'resulting collection' do
285
- it 'has the correct number of kinds' do
286
- expect(collection.kinds.count).to eql 2
287
- end
288
-
289
- it 'has the correct number of mixins' do
290
- expect(collection.mixins.count).to eql 2
291
- end
292
-
293
- it 'has the correct number of actions' do
294
- expect(collection.actions.count).to eql 2
295
- end
296
-
297
- it 'has the correct number of resources' do
298
- expect(collection.resources.count).to eql 2
299
- end
300
-
301
- it 'has the correct number of links' do
302
- expect(collection.links.count).to eql 2
303
- end
304
-
305
- it 'inherits action from the other collection' do
306
- expect(collection.action.action.term).to eql "testaction"
307
- end
308
-
309
- it 'does not inherit action from first collection' do
310
- expect(collection.action.action.term).to_not eql "action_instance"
311
- end
312
-
313
- it 'holds kinds from other collection' do
314
- expect(coll2.kinds.subset?(collection.kinds)).to eql true
315
- end
316
-
317
- it 'holds mixins from other collection' do
318
- expect(coll2.mixins.subset?(collection.mixins)).to eql true
319
- end
320
-
321
- it 'holds actions from other collection' do
322
- expect(coll2.actions.subset?(collection.actions)).to eql true
323
- end
324
-
325
- it 'holds resources from other collection' do
326
- expect(coll2.resources.subset?(collection.resources)).to eql true
327
- end
328
-
329
- it 'holds links from other collection' do
330
- expect(coll2.links.subset?(collection.links)).to eql true
331
- end
332
- end
333
-
334
- context 'the other collection' do
335
- it 'kept the correct number of kinds' do
336
- expect(coll2.kinds.count).to eql 1
337
- end
338
-
339
- it 'kept the correct number of mixins' do
340
- expect(coll2.mixins.count).to eql 1
341
- end
342
-
343
- it 'kept the correct number of actions' do
344
- expect(coll2.actions.count).to eql 1
345
- end
346
-
347
- it 'kept the correct number of resources' do
348
- expect(coll2.resources.count).to eql 1
349
- end
350
-
351
- it 'kept the correct number of links' do
352
- expect(coll2.links.count).to eql 1
353
- end
354
- end
355
- end
356
- it 'copes with other collection empty' do
357
- emptycol = Occi::Collection.new
358
- expect{ collection.merge!(emptycol) }.to_not raise_error
359
- end
360
-
361
- it 'copes with self empty' do
362
- emptycol = Occi::Collection.new
363
- expect{ emptycol.merge!(collection) }.to_not raise_error
364
- end
365
-
366
- it 'copes with both collections empty' do
367
- empty1 = Occi::Collection.new
368
- empty2 = Occi::Collection.new
369
- expect{ empty1.merge(empty2) }.to_not raise_error
370
- end
371
-
372
- it 'combines two empty sets into another empty one' do
373
- empty1 = Occi::Collection.new
374
- empty2 = Occi::Collection.new
375
- empty1.merge(empty2)
376
- expect(empty1.empty?).to eql true
377
- end
378
-
379
- end
380
-
381
- context '#intersect' do
382
- let(:collection){ collection = Occi::Collection.new }
383
- before(:each) {
384
- collection.kinds << "http://schemas.ogf.org/occi/infrastructure#compute"
385
- collection.kinds << "http://schemas.ogf.org/occi/infrastructure#network"
386
- collection.mixins << "http://example.com/occi/tags#my_mixin"
387
- collection.mixins << "http://example.com/occi/tags#still_another_mixin"
388
- collection.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#start"
389
- collection.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#restart"
390
- collection.action = Occi::Core::ActionInstance.new
391
- collection.resources << Occi::Core::Resource.new
392
- collection.resources << Occi::Core::Resource.new
393
- collection.links << Occi::Core::Link.new
394
- collection.links << Occi::Core::Link.new
395
- }
396
- context 'two fully initiated collections' do
397
- let(:action){ Occi::Core::Action.new scheme='http://schemas.ogf.org/occi/core/entity/action#', term='testaction', title='testaction action' }
398
- let(:coll2){
399
- coll2 = Occi::Collection.new
400
- coll2.kinds << "http://schemas.ogf.org/occi/infrastructure#storage"
401
- coll2.kinds << "http://schemas.ogf.org/occi/infrastructure#compute"
402
- coll2.mixins << "http://example.com/occi/tags#another_mixin"
403
- coll2.mixins << "http://example.com/occi/tags#my_mixin"
404
- coll2.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#stop"
405
- coll2.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#restart"
406
- coll2.action = Occi::Core::ActionInstance.new action
407
- coll2.resources << Occi::Core::Resource.new
408
- coll2.resources << collection.resources.first
409
- coll2.links << Occi::Core::Link.new
410
- coll2.links << collection.resources.first
411
- coll2
412
- }
413
- let(:isection){ collection.intersect(coll2, collection) }
414
-
415
- context 'resulting collection' do
416
- it 'has the correct number of kinds' do
417
- expect(isection.kinds.count).to eql 1
418
- end
419
-
420
- it 'has the correct number of mixins' do
421
- expect(isection.mixins.count).to eql 1
422
- end
423
-
424
- it 'has the correct number of actions' do
425
- expect(isection.actions.count).to eql 1
426
- end
427
-
428
- it 'has the correct number of resources' do
429
- expect(isection.resources.count).to eql 1
430
- end
431
-
432
- it 'has the correct number of links' do
433
- expect(isection.links.count).to eql 1
434
- end
435
-
436
- it 'does not include unequal actions' do
437
- expect(isection.action.blank?).to eql true
438
- end
439
-
440
- it 'holds kinds from first collection' do
441
- expect(isection.kinds.subset?(collection.kinds)).to eql true
442
- end
443
-
444
- it 'holds mixins from first collection' do
445
- expect(isection.mixins.subset?(collection.mixins)).to eql true
446
- end
447
-
448
- it 'holds actions from first collection' do
449
- expect(isection.actions.subset?(collection.actions)).to eql true
450
- end
451
-
452
- it 'holds resources from first collection' do
453
- expect(isection.resources.subset?(collection.resources)).to eql true
454
- end
455
-
456
- it 'holds links from first collection' do
457
- expect(isection.links.subset?(collection.links)).to eql true
458
- end
459
-
460
- it 'holds kinds from other collection' do
461
- expect(isection.kinds.subset?(coll2.kinds)).to eql true
462
- end
463
-
464
- it 'holds mixins from other collection' do
465
- expect(isection.mixins.subset?(coll2.mixins)).to eql true
466
- end
467
-
468
- it 'holds actions from other collection' do
469
- expect(isection.actions.subset?(coll2.actions)).to eql true
470
- end
471
-
472
- it 'holds resources from other collection' do
473
- expect(isection.resources.subset?(coll2.resources)).to eql true
474
- end
475
-
476
- it 'holds links from other collection' do
477
- expect(isection.links.subset?(coll2.links)).to eql true
478
- end
479
-
480
- it 'does not replace first collection' do
481
- expect(coll2.links.subset?(collection.links)).to_not eql true
482
- end
483
- end
484
-
485
- context 'first original' do
486
- it 'kept the correct number of kinds' do
487
- expect(collection.kinds.count).to eql 2
488
- end
489
-
490
- it 'kept the correct number of mixins' do
491
- expect(collection.mixins.count).to eql 2
492
- end
493
-
494
- it 'kept the correct number of actions' do
495
- expect(collection.actions.count).to eql 2
496
- end
497
-
498
- it 'kept the correct number of resources' do
499
- expect(collection.resources.count).to eql 2
500
- end
501
-
502
- it 'kept the correct number of links' do
503
- expect(collection.links.count).to eql 2
504
- end
505
- end
506
-
507
- context 'second original' do
508
- it 'kept the correct number of kinds' do
509
- expect(coll2.kinds.count).to eql 2
510
- end
511
-
512
- it 'kept the correct number of mixins' do
513
- expect(coll2.mixins.count).to eql 2
514
- end
515
-
516
- it 'kept the correct number of actions' do
517
- expect(coll2.actions.count).to eql 2
518
- end
519
-
520
- it 'kept the correct number of resources' do
521
- expect(coll2.resources.count).to eql 2
522
- end
523
-
524
- it 'kept the correct number of links' do
525
- expect(coll2.links.count).to eql 2
526
- end
527
- end
528
- end
529
-
530
- it 'copes with an empty collection' do
531
- emptycol = Occi::Collection.new
532
- expect{ isection = collection.intersect(emptycol, collection)}.to_not raise_error
533
- end
534
-
535
- it 'copes with both collections empty' do
536
- empty1 = Occi::Collection.new
537
- empty2 = Occi::Collection.new
538
- expect{ isection = collection.intersect(empty1, empty2)}.to_not raise_error
539
- end
540
- end
541
- context '#intersect!' do
542
- let(:collection){
543
- collection = Occi::Collection.new
544
- collection.kinds << "http://schemas.ogf.org/occi/infrastructure#compute"
545
- collection.kinds << "http://schemas.ogf.org/occi/infrastructure#network"
546
- collection.mixins << "http://example.com/occi/tags#my_mixin"
547
- collection.mixins << "http://example.com/occi/tags#still_another_mixin"
548
- collection.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#start"
549
- collection.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#restart"
550
- collection.action = Occi::Core::ActionInstance.new
551
- collection.resources << Occi::Core::Resource.new
552
- collection.resources << Occi::Core::Resource.new
553
- collection.links << Occi::Core::Link.new
554
- collection.links << Occi::Core::Link.new
555
- collection }
556
- context 'two fully initiated collections' do
557
- let(:action){ Occi::Core::Action.new scheme='http://schemas.ogf.org/occi/core/entity/action#', term='testaction', title='testaction action' }
558
- let(:coll2){
559
- coll2 = Occi::Collection.new
560
- coll2.kinds << "http://schemas.ogf.org/occi/infrastructure#storage"
561
- coll2.kinds << "http://schemas.ogf.org/occi/infrastructure#compute"
562
- coll2.mixins << "http://example.com/occi/tags#another_mixin"
563
- coll2.mixins << "http://example.com/occi/tags#my_mixin"
564
- coll2.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#stop"
565
- coll2.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#restart"
566
- coll2.action = Occi::Core::ActionInstance.new action
567
- coll2.resources << Occi::Core::Resource.new
568
- coll2.resources << collection.resources.first
569
- coll2.links << Occi::Core::Link.new
570
- coll2.links << collection.resources.first
571
- coll2
572
- }
573
- before(:each){ collection.intersect!(coll2) }
574
-
575
- context 'resulting collection' do
576
- it 'has the correct number of kinds' do
577
- expect(collection.kinds.count).to eql 1
578
- end
579
-
580
- it 'has the correct number of mixins' do
581
- expect(collection.mixins.count).to eql 1
582
- end
583
-
584
- it 'has the correct number of actions' do
585
- expect(collection.actions.count).to eql 1
586
- end
587
-
588
- it 'has the correct number of resources' do
589
- expect(collection.resources.count).to eql 1
590
- end
591
-
592
- it 'has the correct number of links' do
593
- expect(collection.links.count).to eql 1
594
- end
595
-
596
- it 'does not include unequal actions' do
597
- expect(collection.action.blank?).to eql true
598
- end
599
-
600
- it 'holds kinds from first collection' do
601
- expect(collection.kinds.subset?(collection.kinds)).to eql true
602
- end
603
-
604
- it 'holds mixins from first collection' do
605
- expect(collection.mixins.subset?(collection.mixins)).to eql true
606
- end
607
-
608
- it 'holds actions from first collection' do
609
- expect(collection.actions.subset?(collection.actions)).to eql true
610
- end
611
-
612
- it 'holds resources from first collection' do
613
- expect(collection.resources.subset?(collection.resources)).to eql true
614
- end
615
-
616
- it 'holds links from first collection' do
617
- expect(collection.links.subset?(collection.links)).to eql true
618
- end
619
-
620
- it 'holds kinds from other collection' do
621
- expect(collection.kinds.subset?(coll2.kinds)).to eql true
622
- end
623
-
624
- it 'holds mixins from other collection' do
625
- expect(collection.mixins.subset?(coll2.mixins)).to eql true
626
- end
627
-
628
- it 'holds actions from other collection' do
629
- expect(collection.actions.subset?(coll2.actions)).to eql true
630
- end
631
-
632
- it 'holds resources from other collection' do
633
- expect(collection.resources.subset?(coll2.resources)).to eql true
634
- end
635
-
636
- it 'holds links from other collection' do
637
- expect(collection.links.subset?(coll2.links)).to eql true
638
- end
639
- end
640
-
641
- context 'second original' do
642
- it 'kept the correct number of kinds' do
643
- expect(coll2.kinds.count).to eql 2
644
- end
645
-
646
- it 'kept the correct number of mixins' do
647
- expect(coll2.mixins.count).to eql 2
648
- end
649
-
650
- it 'kept the correct number of actions' do
651
- expect(coll2.actions.count).to eql 2
652
- end
653
-
654
- it 'kept the correct number of resources' do
655
- expect(coll2.resources.count).to eql 2
656
- end
657
-
658
- it 'kept the correct number of links' do
659
- expect(coll2.links.count).to eql 2
660
- end
661
- end
662
- end
663
-
664
- context 'collections with no intersection' do
665
- let(:action){ Occi::Core::Action.new scheme='http://schemas.ogf.org/occi/core/entity/action#', term='testaction', title='testaction action' }
666
- let(:uniq1) {
667
- uniq1 = Occi::Collection.new
668
- uniq1.kinds << "http://schemas.ogf.org/occi/infrastructure#compute"
669
- uniq1.mixins << "http://example.com/occi/tags#my_mixin"
670
- uniq1.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#start"
671
- uniq1.action = Occi::Core::ActionInstance.new
672
- uniq1.resources << Occi::Core::Resource.new
673
- uniq1.links << Occi::Core::Link.new
674
- uniq1
675
- }
676
- let(:uniq2) {
677
- uniq2 = Occi::Collection.new
678
- uniq2.kinds << "http://schemas.ogf.org/occi/infrastructure#storage"
679
- uniq2.mixins << "http://example.com/occi/tags#another_mixin"
680
- uniq2.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#stop"
681
- uniq2.action = Occi::Core::ActionInstance.new action
682
- uniq2.resources << Occi::Core::Resource.new
683
- uniq2.links << Occi::Core::Link.new
684
- uniq2
685
- }
686
- it 'works with both collections populated' do
687
- uniq1.intersect!(uniq2)
688
- expect(uniq1.empty?).to eql true
689
- end
690
-
691
- it 'works with both collections empty' do
692
- empty1 = Occi::Collection.new
693
- empty2 = Occi::Collection.new
694
-
695
- empty1.intersect!(empty2)
696
- expect(empty1.empty?).to eql true
697
- end
698
-
699
- it 'works with first collection empty' do
700
- empty = Occi::Collection.new
701
-
702
- uniq1.intersect!(empty)
703
- expect(empty.empty?).to eql true
704
- end
705
-
706
- it 'works with second collection empty' do
707
- empty = Occi::Collection.new
708
-
709
- empty.intersect!(uniq2)
710
- expect(empty.empty?).to eql true
711
- end
712
- end
713
- end
714
-
715
- context '#get_by_...' do
716
- let(:collection){ collection = Occi::Collection.new
717
- collection.kinds << "http://schemas.ogf.org/occi/infrastructure#compute"
718
- collection.mixins << "http://example.com/occi/tags#my_mixin"
719
- collection.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#start"
720
- collection.action = Occi::Core::ActionInstance.new
721
- collection.resources << Occi::Core::Resource.new
722
- collection.links << Occi::Core::Link.new
723
- collection
724
- }
725
-
726
- context '#get_by_id' do
727
- it 'finds entity by id' do
728
- expect(collection.get_by_id(collection.links.first.id)).to eql collection.links.first
729
- end
730
-
731
- it 'finds category by id' do
732
- expect(collection.get_by_id("http://example.com/occi/tags#my_mixin")).to eql collection.mixins.first
733
- end
734
-
735
- it 'fails gracefully' do
736
- expect(collection.get_by_id("ID.notexist")).to eql nil
737
- end
738
-
739
- it 'fails loudly when no id is given' do
740
- expect { collection.get_by_id("") } .to raise_error RuntimeError
741
- expect { collection.get_by_id(nil) } .to raise_error RuntimeError
742
- end
743
-
744
- end
745
-
746
- context '#get_by_location' do
747
- it 'finds category by location' do
748
- expect(collection.get_by_location("/mixin/my_mixin/")).to eql collection.mixins.first
749
- end
750
-
751
- it 'finds category by instance location' do
752
- expect(collection.get_by_location("/compute/1")).to eql collection.kinds.first
753
- end
754
-
755
- it 'fails gracefully' do
756
- expect(collection.get_by_location("/notexist/")).to eql nil
757
- end
758
-
759
- it 'fails loudly when no location is given' do
760
- expect { collection.get_by_location("") } .to raise_error RuntimeError
761
- expect { collection.get_by_location(nil) } .to raise_error RuntimeError
762
- end
763
- end
764
- end
765
-
766
- context '#empty?' do
767
- let(:collection){ Occi::Collection.new }
768
- it 'returns true for empty collection' do
769
- expect(collection.empty?).to eql true
770
- end
771
-
772
- it 'does returns false for non-empty kinds' do
773
- collection.kinds << "http://schemas.ogf.org/occi/infrastructure#compute"
774
- expect(collection.empty?).to eql false
775
- end
776
-
777
- it 'does returns false for non-empty mixnis' do
778
- collection.mixins << "http://example.com/occi/tags#my_mixin"
779
- expect(collection.empty?).to eql false
780
- end
781
-
782
- it 'does returns false for non-empty actions' do
783
- collection.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#start"
784
- expect(collection.empty?).to eql false
785
- end
786
-
787
- it 'does returns false for non-empty action' do
788
- collection.action = Occi::Core::ActionInstance.new
789
- expect(collection.empty?).to eql false
790
- end
791
-
792
- it 'does returns false for non-empty resources' do
793
- collection.resources << Occi::Core::Resource.new
794
- expect(collection.empty?).to eql false
795
- end
796
-
797
- it 'does returns false for non-empty links' do
798
- collection.links << Occi::Core::Link.new
799
- expect(collection.empty?).to eql false
800
- end
801
- end
802
-
803
- context '#as_json' do
804
- it 'renders JSON correctly for a simple collection' do
805
- collection = Occi::Collection.new
806
- collection.kinds << "http://schemas.ogf.org/occi/infrastructure#compute"
807
- collection.mixins << "http://example.com/occi/tags#my_mixin"
808
- collection.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#start"
809
- collection.action = Occi::Core::ActionInstance.new
810
- collection.resources << Occi::Core::Resource.new
811
- collection.links << Occi::Core::Link.new
812
- expected = "{\"actions\":[{\"scheme\":\"http://schemas.ogf.org/occi/infrastructure/compute/action#\",\"term\":\"start\",\"attributes\":{}}],\"kinds\":[{\"parent\":\"http://schemas.ogf.org/occi/core#resource\",\"related\":[\"http://schemas.ogf.org/occi/core#resource\"],\"actions\":[\"http://schemas.ogf.org/occi/infrastructure/compute/action#start\",\"http://schemas.ogf.org/occi/infrastructure/compute/action#stop\",\"http://schemas.ogf.org/occi/infrastructure/compute/action#restart\",\"http://schemas.ogf.org/occi/infrastructure/compute/action#suspend\"],\"location\":\"/compute/\",\"scheme\":\"http://schemas.ogf.org/occi/infrastructure#\",\"term\":\"compute\",\"title\":\"compute resource\",\"attributes\":{\"occi\":{\"core\":{\"id\":{\"type\":\"string\",\"required\":true,\"mutable\":false,\"pattern\":\"[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}\"},\"title\":{\"type\":\"string\",\"required\":false,\"mutable\":true,\"pattern\":\".*\"},\"summary\":{\"type\":\"string\",\"required\":false,\"mutable\":true,\"pattern\":\".*\"}},\"compute\":{\"architecture\":{\"type\":\"string\",\"required\":false,\"mutable\":true,\"pattern\":\"x86|x64\"},\"cores\":{\"type\":\"number\",\"required\":false,\"mutable\":true,\"pattern\":\".*\"},\"hostname\":{\"type\":\"string\",\"required\":false,\"mutable\":true,\"pattern\":\"(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\\\-]*[a-zA-Z0-9])\\\\.)*\"},\"memory\":{\"type\":\"number\",\"required\":false,\"mutable\":true,\"pattern\":\".*\"},\"speed\":{\"type\":\"number\",\"required\":false,\"mutable\":true,\"pattern\":\".*\"},\"state\":{\"default\":\"inactive\",\"type\":\"string\",\"required\":false,\"mutable\":false,\"pattern\":\"inactive|active|suspended|error\"}}}}}],\"links\":[{\"kind\":\"http://schemas.ogf.org/occi/core#link\",\"attributes\":{\"occi\":{\"core\":{\"id\":\"#{collection.links.first.id}\"}}},\"id\":\"#{collection.links.first.id}\",\"rel\":\"http://schemas.ogf.org/occi/core#link\"}],\"mixins\":[{\"location\":\"/mixin/my_mixin/\",\"scheme\":\"http://example.com/occi/tags#\",\"term\":\"my_mixin\",\"attributes\":{}}],\"resources\":[{\"kind\":\"http://schemas.ogf.org/occi/core#resource\",\"attributes\":{\"occi\":{\"core\":{\"id\":\"#{collection.resources.first.id}\"}}},\"id\":\"#{collection.resources.first.id}\"}]}"
813
-
814
- hash=Hashie::Mash.new(JSON.parse(expected))
815
- expect(collection.as_json).to eql(hash)
816
- end
817
-
818
- it 'renders JSON for an empty collection' do
819
- collection = Occi::Collection.new
820
- hash=Hashie::Mash.new
821
- expect(collection.as_json).to eql(hash)
822
- end
823
-
824
- it 'renders JSON for a collection with no resources' do
825
- collection = Occi::Collection.new
826
- collection.kinds << "http://schemas.ogf.org/occi/infrastructure#compute"
827
- collection.mixins << "http://example.com/occi/tags#my_mixin"
828
- collection.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#start"
829
- collection.action = Occi::Core::ActionInstance.new
830
- collection.links << Occi::Core::Link.new
831
- expected = "{\"actions\":[{\"scheme\":\"http://schemas.ogf.org/occi/infrastructure/compute/action#\",\"term\":\"start\",\"attributes\":{}}],\"kinds\":[{\"parent\":\"http://schemas.ogf.org/occi/core#resource\",\"related\":[\"http://schemas.ogf.org/occi/core#resource\"],\"actions\":[\"http://schemas.ogf.org/occi/infrastructure/compute/action#start\",\"http://schemas.ogf.org/occi/infrastructure/compute/action#stop\",\"http://schemas.ogf.org/occi/infrastructure/compute/action#restart\",\"http://schemas.ogf.org/occi/infrastructure/compute/action#suspend\"],\"location\":\"/compute/\",\"scheme\":\"http://schemas.ogf.org/occi/infrastructure#\",\"term\":\"compute\",\"title\":\"compute resource\",\"attributes\":{\"occi\":{\"core\":{\"id\":{\"type\":\"string\",\"required\":true,\"mutable\":false,\"pattern\":\"[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}\"},\"title\":{\"type\":\"string\",\"required\":false,\"mutable\":true,\"pattern\":\".*\"},\"summary\":{\"type\":\"string\",\"required\":false,\"mutable\":true,\"pattern\":\".*\"}},\"compute\":{\"architecture\":{\"type\":\"string\",\"required\":false,\"mutable\":true,\"pattern\":\"x86|x64\"},\"cores\":{\"type\":\"number\",\"required\":false,\"mutable\":true,\"pattern\":\".*\"},\"hostname\":{\"type\":\"string\",\"required\":false,\"mutable\":true,\"pattern\":\"(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\\\-]*[a-zA-Z0-9])\\\\.)*\"},\"memory\":{\"type\":\"number\",\"required\":false,\"mutable\":true,\"pattern\":\".*\"},\"speed\":{\"type\":\"number\",\"required\":false,\"mutable\":true,\"pattern\":\".*\"},\"state\":{\"default\":\"inactive\",\"type\":\"string\",\"required\":false,\"mutable\":false,\"pattern\":\"inactive|active|suspended|error\"}}}}}],\"links\":[{\"kind\":\"http://schemas.ogf.org/occi/core#link\",\"attributes\":{\"occi\":{\"core\":{\"id\":\"#{collection.links.first.id}\"}}},\"id\":\"#{collection.links.first.id}\",\"rel\":\"http://schemas.ogf.org/occi/core#link\"}],\"mixins\":[{\"location\":\"/mixin/my_mixin/\",\"scheme\":\"http://example.com/occi/tags#\",\"term\":\"my_mixin\",\"attributes\":{}}]}"
832
-
833
- hash=Hashie::Mash.new(JSON.parse(expected))
834
- expect(collection.as_json).to eql(hash)
835
- end
836
- end
837
-
838
- context '#to_text' do
839
- let(:collection){ Occi::Collection.new }
840
- it 'renders text correctly for a simple collection' do
841
- collection.kinds << "http://schemas.ogf.org/occi/infrastructure#compute"
842
- collection.mixins << "http://example.com/occi/tags#my_mixin"
843
- collection.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#start"
844
- collection.action = Occi::Core::ActionInstance.new
845
- collection.resources << Occi::Core::Resource.new
846
- collection.links << Occi::Core::Link.new
847
-
848
- expected = "Category: compute;scheme=\"http://schemas.ogf.org/occi/infrastructure#\";class=\"kind\";title=\"compute resource\";rel=\"http://schemas.ogf.org/occi/core#resource\";location=\"/compute/\";attributes=\"occi.core.id{immutable required} occi.core.title occi.core.summary occi.compute.architecture occi.compute.cores occi.compute.hostname occi.compute.memory occi.compute.speed occi.compute.state{immutable}\";actions=\"http://schemas.ogf.org/occi/infrastructure/compute/action#start http://schemas.ogf.org/occi/infrastructure/compute/action#stop http://schemas.ogf.org/occi/infrastructure/compute/action#restart http://schemas.ogf.org/occi/infrastructure/compute/action#suspend\"\nCategory: my_mixin;scheme=\"http://example.com/occi/tags#\";class=\"mixin\";location=\"/mixin/my_mixin/\"\nCategory: start;scheme=\"http://schemas.ogf.org/occi/infrastructure/compute/action#\";class=\"action\"\nCategory: resource;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"kind\";location=\"/resource/\";title=\"resource\"\nX-OCCI-Attribute: occi.core.id=\"#{collection.resources.first.id}\"Link: <>;rel=\"http://schemas.ogf.org/occi/core#link\";self=\"/link/#{collection.links.first.id}\";category=\"http://schemas.ogf.org/occi/core#link\";occi.core.id=\"#{collection.links.first.id}\"Category: action_instance;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"action\""
849
- expect(collection.to_text).to eql(expected)
850
- end
851
-
852
- it 'renders text correctly for an empty collection' do
853
- expected = ''
854
- expect(collection.to_text).to eql(expected)
855
- end
856
-
857
- it 'renders text correctly, kinds only' do
858
- collection.kinds << "http://schemas.ogf.org/occi/infrastructure#compute"
859
- expected = "Category: compute;scheme=\"http://schemas.ogf.org/occi/infrastructure#\";class=\"kind\";title=\"compute resource\";rel=\"http://schemas.ogf.org/occi/core#resource\";location=\"/compute/\";attributes=\"occi.core.id{immutable required} occi.core.title occi.core.summary occi.compute.architecture occi.compute.cores occi.compute.hostname occi.compute.memory occi.compute.speed occi.compute.state{immutable}\";actions=\"http://schemas.ogf.org/occi/infrastructure/compute/action#start http://schemas.ogf.org/occi/infrastructure/compute/action#stop http://schemas.ogf.org/occi/infrastructure/compute/action#restart http://schemas.ogf.org/occi/infrastructure/compute/action#suspend\"\n"
860
- expect(collection.to_text).to eql(expected)
861
- end
862
-
863
- it 'renders text correctly, mixins only' do
864
- collection.mixins << "http://example.com/occi/tags#my_mixin"
865
- expected = "Category: my_mixin;scheme=\"http://example.com/occi/tags#\";class=\"mixin\";location=\"/mixin/my_mixin/\"\n"
866
- expect(collection.to_text).to eql(expected)
867
- end
868
-
869
- it 'renders text correctly, actions only' do
870
- collection.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#start"
871
- collection.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#restart"
872
- collection.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#stop"
873
- expected = "Category: start;scheme=\"http://schemas.ogf.org/occi/infrastructure/compute/action#\";class=\"action\"\nCategory: restart;scheme=\"http://schemas.ogf.org/occi/infrastructure/compute/action#\";class=\"action\"\nCategory: stop;scheme=\"http://schemas.ogf.org/occi/infrastructure/compute/action#\";class=\"action\"\n"
874
- expect(collection.to_text).to eql(expected)
875
- end
876
-
877
- it 'renders text correctly, action instance only' do
878
- action = Occi::Core::Action.new scheme='http://schemas.ogf.org/occi/core/entity/action#', term='testaction', title='testaction action'
879
- collection.action = Occi::Core::ActionInstance.new action
880
- expected = "Category: testaction;scheme=\"http://schemas.ogf.org/occi/core/entity/action#\";class=\"action\""
881
- expect(collection.to_text).to eql(expected)
882
- end
883
-
884
- it 'renders text correctly, resources only' do
885
- collection.resources << Occi::Core::Resource.new
886
- expected = "Category: resource;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"kind\";location=\"/resource/\";title=\"resource\"\nX-OCCI-Attribute: occi.core.id=\"#{collection.resources.first.id}\""
887
- expect(collection.to_text).to eql(expected)
888
- end
889
-
890
- it 'renders text correctly, links only' do
891
- collection.links << Occi::Core::Link.new
892
- expected = "Category: link;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"kind\";location=\"/link/\";title=\"link\"\nX-OCCI-Attribute: occi.core.id=\"#{collection.links.first.id}\""
893
- expect(collection.to_text).to eql(expected)
894
- end
895
-
896
- end
897
-
898
- context '#to_header' do
899
- let(:collection){ Occi::Collection.new }
900
- it 'renders header correctly for a simple collection' do
901
- collection.kinds << "http://schemas.ogf.org/occi/infrastructure#compute"
902
- collection.mixins << "http://example.com/occi/tags#my_mixin"
903
- collection.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#start"
904
- collection.action = Occi::Core::ActionInstance.new
905
- collection.resources << Occi::Core::Resource.new
906
- collection.links << Occi::Core::Link.new
907
-
908
- expected=Hashie::Mash.new
909
- expected["Category"] = "compute;scheme=\"http://schemas.ogf.org/occi/infrastructure#\";class=\"kind\";title=\"compute resource\";rel=\"http://schemas.ogf.org/occi/core#resource\";location=\"/compute/\";attributes=\"occi.core.id{immutable required} occi.core.title occi.core.summary occi.compute.architecture occi.compute.cores occi.compute.hostname occi.compute.memory occi.compute.speed occi.compute.state{immutable}\";actions=\"http://schemas.ogf.org/occi/infrastructure/compute/action#start http://schemas.ogf.org/occi/infrastructure/compute/action#stop http://schemas.ogf.org/occi/infrastructure/compute/action#restart http://schemas.ogf.org/occi/infrastructure/compute/action#suspend\",my_mixin;scheme=\"http://example.com/occi/tags#\";class=\"mixin\";location=\"/mixin/my_mixin/\",start;scheme=\"http://schemas.ogf.org/occi/infrastructure/compute/action#\";class=\"action\",resource;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"kind\";location=\"/resource/\";title=\"resource\",action_instance;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"action\""
910
- expected["Link"] = "<>;rel=\"http://schemas.ogf.org/occi/core#link\";self=\"/link/#{collection.links.first.id}\";category=\"http://schemas.ogf.org/occi/core#link\";occi.core.id=\"#{collection.links.first.id}\""
911
- expected["X-OCCI-Attribute"] = "occi.core.id=\"#{collection.resources.first.id}\""
912
- expect(collection.to_header).to eql(expected)
913
- end
914
-
915
- it 'renders text correctly for an empty collection' do
916
- expected=Hashie::Mash.new
917
- expect(collection.to_header).to eql(expected)
918
- end
919
-
920
- it 'renders text correctly, kinds only' do
921
- collection.kinds << "http://schemas.ogf.org/occi/infrastructure#compute"
922
- expected=Hashie::Mash.new
923
- expected["Category"] = "compute;scheme=\"http://schemas.ogf.org/occi/infrastructure#\";class=\"kind\";title=\"compute resource\";rel=\"http://schemas.ogf.org/occi/core#resource\";location=\"/compute/\";attributes=\"occi.core.id{immutable required} occi.core.title occi.core.summary occi.compute.architecture occi.compute.cores occi.compute.hostname occi.compute.memory occi.compute.speed occi.compute.state{immutable}\";actions=\"http://schemas.ogf.org/occi/infrastructure/compute/action#start http://schemas.ogf.org/occi/infrastructure/compute/action#stop http://schemas.ogf.org/occi/infrastructure/compute/action#restart http://schemas.ogf.org/occi/infrastructure/compute/action#suspend\""
924
- expect(collection.to_header).to eql(expected)
925
- end
926
-
927
- it 'renders text correctly, mixins only' do
928
- collection.mixins << "http://example.com/occi/tags#my_mixin"
929
- expected=Hashie::Mash.new
930
- expected["Category"] = "my_mixin;scheme=\"http://example.com/occi/tags#\";class=\"mixin\";location=\"/mixin/my_mixin/\""
931
- expect(collection.to_header).to eql(expected)
932
- end
933
-
934
- it 'renders text correctly, actions only' do
935
- collection.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#start"
936
- collection.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#restart"
937
- collection.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#stop"
938
- expected=Hashie::Mash.new
939
- expected["Category"] = "start;scheme=\"http://schemas.ogf.org/occi/infrastructure/compute/action#\";class=\"action\",restart;scheme=\"http://schemas.ogf.org/occi/infrastructure/compute/action#\";class=\"action\",stop;scheme=\"http://schemas.ogf.org/occi/infrastructure/compute/action#\";class=\"action\""
940
- expect(collection.to_header).to eql(expected)
941
- end
942
-
943
- it 'renders text correctly, action instance only' do
944
- action = Occi::Core::Action.new scheme='http://schemas.ogf.org/occi/core/entity/action#', term='testaction', title='testaction action'
945
- collection.action = Occi::Core::ActionInstance.new action
946
- expected=Hashie::Mash.new
947
- expected["Category"] = "testaction;scheme=\"http://schemas.ogf.org/occi/core/entity/action#\";class=\"action\""
948
- expect(collection.to_header).to eql(expected)
949
- end
950
-
951
- it 'renders text correctly, resources only' do
952
- collection.resources << Occi::Core::Resource.new
953
- expected=Hashie::Mash.new
954
- expected["Category"] = "resource;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"kind\";location=\"/resource/\";title=\"resource\""
955
- expected["X-OCCI-Attribute"] = "occi.core.id=\"#{collection.resources.first.id}\""
956
- expect(collection.to_header).to eql(expected)
957
- end
958
-
959
- it 'renders text correctly, links only' do
960
- collection.links << Occi::Core::Link.new
961
- expected=Hashie::Mash.new
962
- expected["Category"] = "link;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"kind\";location=\"/link/\";title=\"link\""
963
- expected["X-OCCI-Attribute"] = "occi.core.id=\"#{collection.links.first.id}\""
964
- expect(collection.to_header).to eql(expected)
965
- end
966
-
967
- end
968
-
969
- context '.header_merge' do
970
- let(:mash1){ mash1 = Hashie::Mash.new
971
- mash1['a'] = 'a'
972
- mash1['b'] = 'b'
973
- mash1
974
- }
975
- let(:second){ second = Hashie::Mash.new
976
- second['a'] = 'd'
977
- second['c'] = 'c'
978
- second
979
- }
980
- it 'merges two mashes correctly' do
981
- Occi::Collection.header_merge(mash1, second)
982
-
983
- expected = Hashie::Mash.new
984
- expected['a'] = 'a,d'
985
- expected['b'] = 'b'
986
- expected['c'] = 'c'
987
- expect(mash1).to eql expected
988
- end
989
-
990
- it 'merges two mashes correctly with custom separator' do
991
- Occi::Collection.header_merge(mash1, second, ' : ')
992
-
993
- expected = Hashie::Mash.new
994
- expected['a'] = 'a : d'
995
- expected['b'] = 'b'
996
- expected['c'] = 'c'
997
- expect(mash1).to eql expected
998
- end
999
-
1000
- end
1001
-
1002
- end
1003
- end