Skip to content

Commit 3862dd6

Browse files
committed
added nodejs tests for CDATA
1 parent 49e780c commit 3862dd6

File tree

3 files changed

+52
-14
lines changed

3 files changed

+52
-14
lines changed

nodejs/tests/basic/tests/One/Mappings.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ module.exports.One = One;
55
One.ValueType = new Jsonix.Model.ClassInfo({
66
name : "One.ValueType"
77
});
8+
One.ValueAsCDATAType = new Jsonix.Model.ClassInfo({
9+
name : "One.ValueAsCDATAType"
10+
});
811
One.AnyAttributeType = new Jsonix.Model.ClassInfo({
912
name : "One.AnyAttributeType"
1013
});
@@ -37,6 +40,11 @@ One.ValueType.properties = [ new Jsonix.Model.ValuePropertyInfo({
3740
name : "value",
3841
typeInfo : Jsonix.Schema.XSD.String.INSTANCE
3942
}) ];
43+
One.ValueAsCDATAType.properties = [ new Jsonix.Model.ValuePropertyInfo({
44+
name : "value",
45+
typeInfo : Jsonix.Schema.XSD.String.INSTANCE,
46+
asCDATA: true
47+
}) ];
4048
One.AnyAttributeType.properties = [ new Jsonix.Model.AnyAttributePropertyInfo({
4149
name : "attributes"
4250
}) ];
@@ -213,7 +221,7 @@ One.AnyElementType.properties = [ new Jsonix.Model.AttributePropertyInfo({
213221
}) ];
214222

215223
One.SimpleTypesType.properties = [
216-
//
224+
//
217225
new Jsonix.Model.ElementPropertyInfo({
218226
name : "date",
219227
typeInfo : Jsonix.Schema.XSD.DateAsDate.INSTANCE
@@ -305,6 +313,9 @@ One.ElementMapType.properties = [ new Jsonix.Model.ElementMapPropertyInfo({
305313
One.elementInfos = [ {
306314
elementName : new Jsonix.XML.QName('value'),
307315
typeInfo : One.ValueType
316+
}, {
317+
elementName : new Jsonix.XML.QName('valueAsCDATA'),
318+
typeInfo : One.ValueAsCDATAType
308319
}, {
309320
elementName : new Jsonix.XML.QName('anyAttribute'),
310321
typeInfo : One.AnyAttributeType

nodejs/tests/basic/tests/Two/Mappings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,4 @@ var org_hisrc_jsonix_tests_two = {
110110
if (typeof require === 'function') {
111111
module.exports.org_hisrc_jsonix_tests_two = org_hisrc_jsonix_tests_two;
112112
module.exports.org_hisrc_jsonix_tests_two_CustomValueClass = org_hisrc_jsonix_tests_two_CustomValueClass;
113-
}
113+
}

nodejs/tests/basic/tests/one.js

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ module.exports =
8181
test.equal('c', result.value.attributes['{urn:c}c']);
8282
test.done();
8383
},
84-
84+
8585
"MarhshalAttributeType" : function(test) {
8686
var context = new Jsonix.Context([ One ], {
8787
namespacePrefixes : {}
@@ -125,7 +125,7 @@ module.exports =
125125
test.equal('test', result.value.attribute);
126126
test.done();
127127
},
128-
128+
129129
"MarhshalElementType" : function(test) {
130130
var context = new Jsonix.Context([ One ]);
131131
var marshaller = context.createMarshaller();
@@ -145,7 +145,7 @@ module.exports =
145145
test.ok(serializedNode.length > 5);
146146
test.done();
147147
},
148-
148+
149149
"UnmarhshalElementType" : function(test) {
150150
var context = new Jsonix.Context([ One ]);
151151
var unmarshaller = context.createUnmarshaller();
@@ -190,7 +190,7 @@ module.exports =
190190
test.equal('f', result.value.items[2]);
191191
test.done();
192192
},
193-
193+
194194
"MarhshalElementsType" : function(test) {
195195
var context = new Jsonix.Context([ One ]);
196196
var marshaller = context.createMarshaller();
@@ -226,7 +226,7 @@ module.exports =
226226
test.ok(serializedNode.length > 5);
227227
test.done();
228228
},
229-
229+
230230
"UnmarhshalElementsType" : function(test) {
231231
var context = new Jsonix.Context([ One ]);
232232
var unmarshaller = context.createUnmarshaller();
@@ -282,7 +282,7 @@ module.exports =
282282
console.log(marshaller.marshalString(result));
283283
test.done();
284284
},
285-
285+
286286
"MarhshalElementRefType" : function(test) {
287287
var context = new Jsonix.Context([ One, Two ], {
288288
namespacePrefixes : {
@@ -390,7 +390,7 @@ module.exports =
390390
test.equal('twelve', result.value.mix[2]);
391391
test.done();
392392
},
393-
393+
394394
"UnmarshalElementRefsType" : function(test) {
395395
var context = new Jsonix.Context([ One ]);
396396
var unmarshaller = context.createUnmarshaller();
@@ -495,15 +495,15 @@ module.exports =
495495
}
496496
}, 'three', Jsonix.DOM.parse('<node>four</node>').documentElement ]
497497
}
498-
498+
499499
};
500500
var node = marshaller.marshalDocument(value);
501501
var serializedNode = Jsonix.DOM.serialize(node);
502502
console.log(serializedNode);
503503
test.ok(serializedNode.length > 5);
504504
test.done();
505505
},
506-
506+
507507
"UnmarhshalAnyElementType" : function(test) {
508508
var context = new Jsonix.Context([ One, Two ]);
509509
var unmarshaller = context.createUnmarshaller();
@@ -561,7 +561,7 @@ module.exports =
561561
test.ok(serializedNode.length > 5);
562562
test.done();
563563
},
564-
564+
565565
"UnmarhshalSimpleTypesType" : function(test) {
566566
var context = new Jsonix.Context([ One ]);
567567
var unmarshaller = context.createUnmarshaller();
@@ -598,7 +598,7 @@ module.exports =
598598
test.equal(1.1, result.value['double']);
599599
test.equal(2, result.value.integer);
600600
test.equal('three', result.value.string);
601-
601+
602602
//
603603
test.equal(2000, result.value.dates[0].getFullYear());
604604
test.equal(2001, result.value.dates[1].getFullYear());
@@ -614,7 +614,7 @@ module.exports =
614614
test.equal(7, result.value.doublesList[2][1]);
615615
test.done();
616616
},
617-
617+
618618
"UnmarhshalMapElementType" : function(test) {
619619
var context = new Jsonix.Context([ One ]);
620620
var unmarshaller = context.createUnmarshaller();
@@ -727,5 +727,32 @@ module.exports =
727727
test.equal('string', result.name.localPart);
728728
test.equal('text', result.value);
729729
test.done();
730+
},
731+
"MarshalCDATAValueType" : function(test)
732+
{
733+
var context = new Jsonix.Context([ One ]);
734+
var marshaller = context.createMarshaller();
735+
var value = {
736+
name : {
737+
localPart : "valueAsCDATA"
738+
},
739+
value : {
740+
value : 'test<>?\'"&'
741+
}
742+
};
743+
var result = marshaller.marshalString(value);
744+
console.log(result);
745+
test.ok(result === '<valueAsCDATA><![CDATA[test<>?\'"&]]></valueAsCDATA>');
746+
test.done();
747+
},
748+
"UnmarshalCDATAValueType": function (test)
749+
{
750+
var context = new Jsonix.Context([ One ]);
751+
var unmarshaller = context.createUnmarshaller();
752+
var text = '<valueAsCDATA><![CDATA[test<>?\'"&]]></valueAsCDATA>';
753+
var result = unmarshaller.unmarshalString(text);
754+
test.equal('string', result.name.localPart);
755+
test.equal('text', result.value);
756+
test.done();
730757
}
731758
};

0 commit comments

Comments
 (0)