01: /*
02: * ChainBuilder ESB
03: * Visual Enterprise Integration
04: *
05: * Copyright (C) 2006 Bostech Corporation
06: *
07: * This program is free software; you can redistribute it and/or modify
08: * it under the terms of the GNU General Public License as published by
09: * the Free Software Foundation; either version 2 of the License, or
10: * (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc.,59 Temple Place, Suite 330, Boston, MA 02111-1307
20: * USA
21: *
22: * $ID$
23: *
24: */
25: package com.bostechcorp.cbesb.common.mdl;
26:
27: import java.io.File;
28:
29: import junit.framework.TestCase;
30:
31: import com.bostechcorp.cbesb.common.mdl.IContentNode;
32: import com.bostechcorp.cbesb.common.mdl.IMDLDocument;
33: import com.bostechcorp.cbesb.common.mdl.IMessageDefinition;
34: import com.bostechcorp.cbesb.common.mdl.MDLParser;
35: import com.bostechcorp.cbesb.common.mdl.impl.MDLDocumentImpl;
36:
37: public class TestContentNode extends TestCase {
38: File mdlFile = new File(
39: "target/test-data/in/contentNodeAndGroup.mdl");
40:
41: IMDLDocument mdlDoc = new MDLDocumentImpl();
42:
43: protected void setUp() throws Exception {
44: super .setUp();
45: mdlDoc = MDLParser.load(mdlFile);
46: }
47:
48: protected void tearDown() throws Exception {
49: super .tearDown();
50: }
51:
52: /**
53: * test contentNode
54: * If a field is optional, minOccurs is set to 0. if it is
55: * required, it is set to 1. Default value is 1.
56: * If the element has no limit,
57: * then maxOccurs is set to "unbounded". The default value is 1.
58: */
59: int max;
60: int min;
61:
62: public void testContentNode() {
63: IMessageDefinition msgDef = mdlDoc.getAllMessageDefinitions()[0];
64: IContentNode cNode = msgDef.getChildren()[0];
65: max = cNode.getMaxOccurs();
66: min = cNode.getMinOccurs();
67: //maxOccurs and minOccurs have not been set
68: //they are default value
69: assertEquals(1, max);
70: assertEquals(1, min);
71:
72: IContentNode cNode2 = msgDef.getChildren()[1];
73: max = cNode2.getMaxOccurs();
74: min = cNode2.getMinOccurs();
75: //maxOccurs is set to "unbounded" and minOccurs is set to 0
76: assertEquals(-1, max);
77: assertEquals(0, min);
78:
79: IContentNode cNode3 = msgDef.getChildren()[2];
80: max = cNode3.getMaxOccurs();
81: min = cNode3.getMinOccurs();
82: //maxOccurs is set to 5
83: //minOccurs is set to 2
84: assertEquals(5, max);
85: assertEquals(2, min);
86:
87: }
88: }
|