-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
0000728: Lookup table router should throw an exception when the route…
…r expression is invalid. Modified the LookupTableDataRouter to validate Lookup Table expressions. Created unit tests to test validating Lookup Table router expressions.
- Loading branch information
Showing
2 changed files
with
140 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
symmetric-core/src/test/java/org/jumpmind/symmetric/route/LookupTableDataRouterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package org.jumpmind.symmetric.route; | ||
|
||
import junit.framework.Assert; | ||
|
||
import org.jumpmind.symmetric.SyntaxParsingException; | ||
import org.junit.Test; | ||
|
||
public class LookupTableDataRouterTest { | ||
|
||
@Test | ||
public void testValidExpression() { | ||
LookupTableDataRouter router = new LookupTableDataRouter(); | ||
|
||
boolean valid = true; | ||
try { | ||
router.parse("LOOKUP_TABLE=STORE\r\n" + | ||
"KEY_COLUMN=BRAND_ID\r\n" + | ||
"LOOKUP_KEY_COLUMN=BRAND_ID\r\n" + | ||
"EXTERNAL_ID_COLUMN=STORE_ID"); | ||
} catch(SyntaxParsingException ex) { | ||
valid = false; | ||
} | ||
|
||
Assert.assertEquals(true, valid); | ||
} | ||
|
||
@Test | ||
public void testExpressionWithoutNewLines() { | ||
LookupTableDataRouter router = new LookupTableDataRouter(); | ||
|
||
boolean valid = true; | ||
try { | ||
router.parse("LOOKUP_TABLE=STORE KEY_COLUMN=BRAND_ID " + | ||
"LOOKUP_KEY_COLUMN=BRAND_ID EXTERNAL_ID_COLUMN=STORE_ID"); | ||
} catch(SyntaxParsingException ex) { | ||
valid = false; | ||
} | ||
|
||
Assert.assertEquals(false, valid); | ||
} | ||
|
||
@Test | ||
public void testMissingEqualSign() { | ||
LookupTableDataRouter router = new LookupTableDataRouter(); | ||
|
||
boolean valid = true; | ||
try { | ||
router.parse("LOOKUP_TABLE=STORE\r\n" + | ||
"KEY_COLUMNBRAND_ID\r\n" + // <-- Missing Equal | ||
"LOOKUP_KEY_COLUMN=BRAND_ID\r\n" + | ||
"EXTERNAL_ID_COLUMN=STORE_ID"); | ||
} catch(SyntaxParsingException ex) { | ||
valid = false; | ||
} | ||
|
||
Assert.assertEquals(false, valid); | ||
} | ||
|
||
@Test | ||
public void testBadKey() { | ||
LookupTableDataRouter router = new LookupTableDataRouter(); | ||
|
||
boolean valid = true; | ||
try { | ||
router.parse("LOOKUP_TAB=STORE\r\n" + // <-- Should be LOOKUP_TABLE | ||
"KEY_COLUMN=BRAND_ID\r\n" + | ||
"LOOKUP_KEY_COLUMN=BRAND_ID\r\n" + | ||
"EXTERNAL_ID_COLUMN=STORE_ID"); | ||
} catch(SyntaxParsingException ex) { | ||
valid = false; | ||
} | ||
|
||
Assert.assertEquals(false, valid); | ||
} | ||
|
||
@Test | ||
public void testDoubleLine() { | ||
LookupTableDataRouter router = new LookupTableDataRouter(); | ||
|
||
boolean valid = true; | ||
try { | ||
router.parse("LOOKUP_TABLE=STORE\r\n" + | ||
"LOOKUP_TABLE=STORE\r\n" + // <-- Duplicate | ||
"KEY_COLUMN=BRAND_ID\r\n" + | ||
"LOOKUP_KEY_COLUMN=BRAND_ID\r\n" + | ||
"EXTERNAL_ID_COLUMN=STORE_ID"); | ||
} catch(SyntaxParsingException ex) { | ||
valid = false; | ||
} | ||
|
||
Assert.assertEquals(false, valid); | ||
} | ||
} |