LookupTableDataRouter extends AbstractDataRouter implements IDataRouter, IBuiltInExtensionPoint { public Map<String, String> parse(String routerExpression) throws SyntaxParsingException { boolean valid = true; Map<String, String> params = new HashMap<String, String>(); if (!StringUtils.isBlank(routerExpression)) { String[] expTokens = routerExpression.split("\\s"); if (expTokens != null) { for (String t : expTokens) { if (!StringUtils.isBlank(t)) { String[] tokens = t.split("="); if (tokens.length == 2 && !params.containsKey(tokens[0].trim())) { params.put(tokens[0].trim(), tokens[1].trim()); } else { valid = false; break; } } } if (!valid || params.size() < 4 || params.size() > 5 || !params.containsKey(PARAM_LOOKUP_TABLE) || !params.containsKey(PARAM_KEY_COLUMN) || !params.containsKey(PARAM_MAPPED_KEY_COLUMN) || !params.containsKey(PARAM_EXTERNAL_ID_COLUMN)) { log.warn("The provided lookup table router expression was invalid. The full expression is " + routerExpression + "."); throw new SyntaxParsingException("The provided lookup table router expression was invalid. The full expression is " + routerExpression + "."); } } } else { log.warn("The provided lookup table router expression is empty"); } return params; } LookupTableDataRouter(ISymmetricDialect symmetricDialect);  LookupTableDataRouter(); Set<String> routeToNodes(SimpleRouterContext routingContext, DataMetaData dataMetaData,
            Set<Node> nodes, boolean initialLoad, boolean initialLoadSelectUsed, TriggerRouter triggerRouter); Map<String, String> parse(String routerExpression); final static String PARAM_LOOKUP_TABLE; final static String PARAM_KEY_COLUMN; final static String PARAM_MAPPED_KEY_COLUMN; final static String PARAM_EXTERNAL_ID_COLUMN; final static String PARAM_ALL_NODES_VALUE; }
@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; } 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; } assertEquals(true, 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" + "LOOKUP_KEY_COLUMN=BRAND_ID\r\n" + "EXTERNAL_ID_COLUMN=STORE_ID"); } catch(SyntaxParsingException ex) { valid = false; } assertEquals(false, valid); }
@Test public void testBadKey() { LookupTableDataRouter router = new LookupTableDataRouter(); boolean valid = true; try { router.parse("LOOKUP_TAB=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; } 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" + "KEY_COLUMN=BRAND_ID\r\n" + "LOOKUP_KEY_COLUMN=BRAND_ID\r\n" + "EXTERNAL_ID_COLUMN=STORE_ID"); } catch(SyntaxParsingException ex) { valid = false; } assertEquals(false, valid); }
@Test public void testMissingLine() { LookupTableDataRouter router = new LookupTableDataRouter(); boolean valid = true; try { router.parse("LOOKUP_TABLE=STORE\r\n" + "LOOKUP_KEY_COLUMN=BRAND_ID\r\n" + "EXTERNAL_ID_COLUMN=STORE_ID"); } catch(SyntaxParsingException ex) { valid = false; } assertEquals(false, valid); }