CRCRHandler extends AbstractChainOfResponsibilityHandler { @Override public void handleRequest(Object inputData, int rowNum) { if (conflictingRowNumbers.size() == 0) { handleRequest(); } } CRCRHandler(HandlerParameter handlerParameter); @Override void handleRequest(Object inputData, int rowNum); @Override void handleRequest(); @Override CRCRHandler getSuccessor(); @Override AbstractChainOfResponsibilityHandler linkSuccessor(AbstractChainOfResponsibilityHandler nextHandler); SurvivedResult getSurvivedRowNum(); boolean isValidResult(); Object getLongestResult(Object result); Object getNonDuplicatedResult(Object result); boolean isMissionCompleted();  }
@Test public void testHandleRequestObjectInt() { Column col1 = new Column("city1", "String"); Column col2 = new Column("city2", "String"); List<Column> columns = new ArrayList<>(); columns.add(col1); columns.add(col2); DataSet dataset = new DataSet(columns); Record record1 = new Record(); record1.setId(1); Attribute att1 = new Attribute(record1, col1, "value1"); Attribute att2 = new Attribute(record1, col2, "value2"); record1.putAttribute("city1", att1); record1.putAttribute("city2", att2); col1.putAttribute(record1, att1); col2.putAttribute(record1, att2); dataset.getRecordList().add(record1); record1 = new Record(); record1.setId(2); att1 = new Attribute(record1, col1, "value3"); att2 = new Attribute(record1, col2, "value4"); record1.putAttribute("city1", att1); record1.putAttribute("city2", att2); col1.putAttribute(record1, att1); col2.putAttribute(record1, att2); dataset.getRecordList().add(record1); List<Integer> conflictRowNum = new ArrayList<>(); conflictRowNum.add(0); dataset.getConflictDataMap().get().put("city2", conflictRowNum); ISurvivorshipAction action = RuleDefinition.Function.MostCommon.getAction(); Column refColumn = col1; Column tarColumn = col2; String ruleName = "rule1"; String expression = null; boolean isIgnoreBlank = false; String fillColumn = "city2"; boolean isDealDup = false; Map<String, Integer> columnIndexMap = new HashMap<>(); columnIndexMap.put("city1", 0); columnIndexMap.put("city2", 1); List<HashSet<String>> conflictList = dataset.getConflictList(); HashSet hashSet = new HashSet(); hashSet.add("city1"); hashSet.add("city2"); conflictList.add(hashSet); hashSet = new HashSet(); hashSet.add("city1"); hashSet.add("city2"); conflictList.add(hashSet); FunctionParameter functionParameter = new FunctionParameter(action, expression, isIgnoreBlank, isDealDup); HandlerParameter handlerParameter = new HandlerParameter(dataset, refColumn, tarColumn, ruleName, columnIndexMap, fillColumn, functionParameter); CRCRHandler crcrHandler = new CRCRHandler(handlerParameter); DataSet subDataset = null; for (int index = 0; index < 5; index++) { crcrHandler.handleRequest(null, index); if (index == 0) { subDataset = crcrHandler.getHandlerParameter().getDataset(); Assert.assertNotEquals("subDataset should be create so that dataset should different with subDataset", dataset, subDataset); } else { Assert.assertEquals("crcrHandler only should be execute one time so that dataset will not change agian", subDataset, crcrHandler.getHandlerParameter().getDataset()); } } }
@Test public void testHandleRequest() { HandlerParameter handlerParameter = createHandlerParameter(null); CRCRHandler crcrHandler = new CRCRHandler(handlerParameter); crcrHandler.handleRequest(); Assert.assertEquals("The record of dataset is empty so that no subDataset generated", handlerParameter.getDataset(), crcrHandler.getHandlerParameter().getDataset()); }