001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify
008: * it under the terms of the GNU General Public License as published by
009: * the Free Software Foundation; either version 2 of the License, or
010: * (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc.,59 Temple Place, Suite 330, Boston, MA 02111-1307
020: * USA
021: *
022: *
023: * $ID$
024: */
025: package com.bostechcorp.cbesb.common.mdl;
026:
027: import java.io.File;
028:
029: import junit.framework.TestCase;
030:
031: import com.bostechcorp.cbesb.common.mdl.IFormatDefinition;
032: import com.bostechcorp.cbesb.common.mdl.IMDLDocument;
033: import com.bostechcorp.cbesb.common.mdl.IVariableFormatDefinition;
034: import com.bostechcorp.cbesb.common.mdl.MDLParser;
035: import com.bostechcorp.cbesb.common.mdl.impl.MDLDocumentImpl;
036:
037: /**
038: * test variableFormatDefinition
039: *
040: */
041: public class TestVariableFormatDefinition extends TestCase {
042:
043: File mdlFile = new File("target/test-data/in/group1.mdl");
044:
045: File mdlFile2 = new File("target/test-data/in/delimiterRef.mdl");
046:
047: IMDLDocument mdlDoc = new MDLDocumentImpl();
048:
049: IMDLDocument mdlDoc2 = new MDLDocumentImpl();
050:
051: protected void setUp() throws Exception {
052: super .setUp();
053:
054: mdlDoc = MDLParser.load(mdlFile);
055: mdlDoc2 = MDLParser.load(mdlFile2);
056: }
057:
058: protected void tearDown() throws Exception {
059: super .tearDown();
060: }
061:
062: /**
063: * An element or message definition defined as variable
064: * has one ore more sub-elements that are separated by a delimiter.
065: * If a Definition contains multiple variable elements that all share the
066: * same delimiter, escape character, etc, then those properties can be
067: * defined at the global level and referenced in all of the element
068: * definitions rather than defining the same delimiter character separately
069: *
070: */
071: public void testGetAndSetDelimiter() {
072: IFormatDefinition formatDef = mdlDoc.getAllMessageDefinitions()[0]
073: .getFormatDefinition();
074: IVariableFormatDefinition vFormatDef = (IVariableFormatDefinition) formatDef;
075: // get delimiter or delimiterRef
076: // variableFormatDefinition must has a delimiter or delimiterRef
077: if (vFormatDef.getDelimiter() == null) {
078: String delimiterRef = vFormatDef.getDelimiterRef();
079: assertNotNull(delimiterRef);
080: } else {
081: String delimiter = vFormatDef.getDelimiter();
082: assertNotNull(delimiter);
083: assertEquals("\r", delimiter);
084:
085: }
086: if (vFormatDef.getDelimiter() != null) {
087: // set delimiter
088: vFormatDef.setDelimiter("XDelimiter");
089: assertEquals("XDelimiter", vFormatDef.getDelimiter());
090: }
091: }
092:
093: public void testGetAndSetDelimiterRef() {
094: IFormatDefinition formatDef = mdlDoc2
095: .getAllMessageDefinitions()[0].getFormatDefinition();
096: IVariableFormatDefinition vFormatDef = (IVariableFormatDefinition) formatDef;
097: if (vFormatDef.getDelimiter() == null) {
098: String delimiterRef = vFormatDef.getDelimiterRef();
099: assertNotNull(delimiterRef);
100: assertEquals(",", mdlDoc2.getProperty(delimiterRef)
101: .getValue());
102:
103: // set delimiterRef
104: vFormatDef.setDelimiterRef("XDelimiterRef");
105: assertEquals("XDelimiter", vFormatDef.getDelimiterRef());
106: }
107: }
108:
109: public void testGetAndSetEsacpeChar() {
110: IFormatDefinition formatDef = mdlDoc.getAllMessageDefinitions()[0]
111: .getFormatDefinition();
112: IVariableFormatDefinition vFormatDef = (IVariableFormatDefinition) formatDef;
113: //get escapeChar
114: char escapeChar = vFormatDef.getEscapeChar();
115: assertEquals('\\', escapeChar);
116: //set escapeChar
117: vFormatDef.setEscapeChar('/');
118: assertEquals('/', vFormatDef.getEscapeChar());
119: }
120:
121: public void testGetAndSetEscapeCharDef() {
122: IFormatDefinition formatDef = mdlDoc2
123: .getAllMessageDefinitions()[0].getFormatDefinition();
124: IVariableFormatDefinition vFormatDef = (IVariableFormatDefinition) formatDef;
125: String escapeCharRef = vFormatDef.getEscapeCharRef();
126: assertEquals("XescapeChar", escapeCharRef);
127: assertEquals("\\", mdlDoc2.getProperty(escapeCharRef)
128: .getValue());
129: }
130:
131: public void testGetAndSetQuoteChar() {
132: IFormatDefinition formatDef = mdlDoc.getAllMessageDefinitions()[0]
133: .getFormatDefinition();
134: IVariableFormatDefinition vFormatDef = (IVariableFormatDefinition) formatDef;
135: char quoteChar = vFormatDef.getQuoteChar();
136: //if a messageDefinition has no quoteChar tag
137: //then the quoteChar of this message is set to 0
138: assertEquals(0, quoteChar);
139:
140: vFormatDef.setQuoteChar('q');
141: assertEquals('q', vFormatDef.getQuoteChar());
142: }
143:
144: public void testGetAndSetQuoteCharRef() {
145: IFormatDefinition formatDef = mdlDoc2
146: .getAllMessageDefinitions()[0].getFormatDefinition();
147: IVariableFormatDefinition vFormatDef = (IVariableFormatDefinition) formatDef;
148: String quoteCharRef = vFormatDef.getQuoteCharRef();
149: assertEquals("XquoteChar", quoteCharRef);
150: //set quoteCharRef
151: vFormatDef.setQuoteCharRef("qR");
152: assertEquals("qR", vFormatDef.getQuoteCharRef());
153: }
154:
155: public void testGetAndSetIDMethod() {
156: IFormatDefinition formatDef = mdlDoc.getAllMessageDefinitions()[0]
157: .getFormatDefinition();
158: IVariableFormatDefinition vFormatDef = (IVariableFormatDefinition) formatDef;
159: byte idMethod = vFormatDef.getIDMethod();
160: //1 means idMethod is set to tag
161: assertEquals(1, idMethod);
162: int tagLength = vFormatDef.getTagLength();
163: assertEquals(3, tagLength);
164:
165: vFormatDef.setIDMethod((byte) 0);
166: assertEquals(0, vFormatDef.getIDMethod());
167: }
168: }
|