[MAGNOLIA-1452] testing: mock objects for content Created: 06/Apr/07  Updated: 23/Jan/13  Resolved: 05/Dec/07

Status: Closed
Project: Magnolia
Component/s: None
Affects Version/s: None
Fix Version/s: 3.1 M1

Type: Improvement Priority: Major
Reporter: Philipp Bärfuss Assignee: Philipp Bärfuss
Resolution: Fixed Votes: 0
Labels: None
Σ Remaining Estimate: Not Specified Remaining Estimate: Not Specified
Σ Time Spent: Not Specified Time Spent: Not Specified
Σ Original Estimate: Not Specified Original Estimate: Not Specified

Sub-Tasks:
Key
Summary
Type
Status
Assignee
MAGNOLIA-1924 MockContent: Add support for same-nam... Sub-task Closed  
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Date of First Response:

 Description   

I started to write mock Content, NodeData objects. They can be used for writing tests.

The goal is to write a util class transforming a properties file to a content structure.

This facilitates writing test (mainly for configuration and similar) a lot



 Comments   
Comment by Philipp Bracher [ 13/Apr/07 ]

I checked in first mock objects found in the package info.magnolia.test.mock

  • MockContent
  • MockNodeData
  • MockHierarchyManager
  • MockContext

Use the MockUtil to build a mock hierarchy easily.

MockUtil.initMockContext()
MockUtil.createHierarchyManager(properties)

The properties String or Stream you provide defines the node properties, types and uuids.

Here follows an example:

parent.type = mgnl:test
parent.uuid = 1
parent.prop1 = value1
parent.prop2 = value2
parent.prop3 = boolean:true

parent.sub1.type = mgnl:sub
parent.sub1.uuid = 2
parent.sub1.prop1 = sub1value1
parent.sub1.prop2 = sub1value2
parent.sub1.prop3 = boolean:true

parent.sub2.type = mgnl:sub
parent.sub2.uuid = 3
parent.sub2.prop1 = sub2value1
parent.sub2.prop2 = sub2value2
parent.sub2.prop3 = boolean:false

hm.getContent("/parent/sub1").getNodeData("prop3").getBoolean() --> true

Comment by Magnolia International [ 13/Apr/07 ]

I would say : check the testcases out for samples
(so we're sure it's up-to-date)

Comment by Magnolia International [ 13/Apr/07 ]

Added (very) basic MetaData support.
Also renamed the "special" uuid and type properties to @uuid and @type to avoid name clashes with actual properties.

Comment by Philipp Bracher [ 26/Apr/07 ]

You can set a workspace mock on the hierarchy manager. This is for example usefull where we use observation.

Comment by Philipp Bracher [ 05/Jun/07 ]

Added two things:

  • support of easier to read key format:
    /parent/sub@uuid=1
    /parent/sub.prop1=value
  • setting name (renaming) of mock content
Comment by Philipp Bracher [ 13/Jun/07 ]

Added support for binaries

Comment by Vivian Steller [ 05/Dec/07 ]

the MockContent class does not support adding multiple nodes with same name, so behaves differently in tests than the actual JCR implementation.
e.g. executing node.createContent("0", ...) twice should create something like:
/node/0
/node/00
Current implemenation stores those childnodes in a HashMap, thus executing the method call above overwrites the child node 0.

Comment by Vivian Steller [ 05/Dec/07 ]

from greg:
> it's not like the feature was unuseable - also it would maybe have side effects on existing tests so i'd rather fix this later

put last comment into MAGNOLIA-1924 (subtask), thus resolved this again. Sorry for this confusion.

Generated at Mon Feb 12 03:27:03 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.