Program: 13499
Project: 13499
Buggy source:
public void testDitaKeyspaceConstruction() throws Exception {
  Element resourceElement=null;
  URI resourceUri=null;
  DitaKeySpace keySpace;
  KeyAccessOptions keyAccessOptions=new KeyAccessOptions();
  DitaKeyDefinitionContext keydefContext=dlmService.registerRootMap(rootMap);
  assertNotNull(keydefContext);
  DitaKeyDefinitionContext candKeydefContext=dlmService.getKeyDefinitionContext(rootMap);
  assertEquals(keydefContext,candKeydefContext);
  keySpace=dlmService.getKeySpace(keyAccessOptions,keydefContext);
  assertNotNull(keySpace);
  assertEquals(rootMap.getDocumentURI(),keySpace.getRootMap(keyAccessOptions).getDocumentURI());
  dlmService.unRegisterKeySpace(keydefContext);
  keySpace=dlmService.getKeySpace(keyAccessOptions,keydefContext);
  assertNull("String_Node_Str",keySpace);
  keydefContext=dlmService.registerRootMap(rootMap);
  assertNotNull(keydefContext);
  dlmService.markKeySpaceOutOfDate(keydefContext);
  assertNotNull(keydefContext);
  assertTrue(keydefContext.isOutOfDate());
  KeyReportOptions reportOptions=new KeyReportOptions();
  KeySpaceReporter reporter=new TextKeySpaceReporter(System.out);
  reporter.report(keyAccessOptions,dlmService.getKeySpace(keyAccessOptions,keydefContext),reportOptions);
  reportOptions.setSortByMap(true);
  reporter.report(keyAccessOptions,dlmService.getKeySpace(keyAccessOptions,keydefContext),reportOptions);
  reportOptions.setSortByMap(false);
  reportOptions.setAllKeys(true);
  reporter.report(keyAccessOptions,dlmService.getKeySpace(keyAccessOptions,keydefContext),reportOptions);
  Set<String> keys=dlmService.getKeys(keyAccessOptions,keydefContext);
  assertNotNull(keys);
  assertEquals(keyCount,keys.size());
  keySpace=dlmService.getKeySpace(keyAccessOptions,keydefContext);
  assertNotNull(keySpace);
  assertEquals(keyCount,keySpace.size());
  Document candDoc=keySpace.getRootMap(keyAccessOptions);
  assertEquals(candDoc.getDocumentURI(),rootMap.getDocumentURI());
  Set<DitaKeyDefinition> keyDefSet=dlmService.getEffectiveKeyDefinitions(keyAccessOptions,keydefContext);
  List<DitaKeyDefinition> keyDefList=null;
  assertNotNull("String_Node_Str",keyDefSet);
  assertEquals(keyCount,keyDefSet.size());
  DitaKeyDefinition keyDef=dlmService.getKeyDefinition(keyAccessOptions,keydefContext,key01);
  assertNotNull("String_Node_Str",keyDef);
  String rootMapId=keyDef.getBaseUri().toURL().toExternalForm();
  assertNotNull(rootMapId);
  assertEquals(rootMap.getDocumentURI(),rootMapId);
  keyDefSet=dlmService.getEffectiveKeyDefinitionsForKey(keyAccessOptions,key01);
  assertNotNull("String_Node_Str",keyDefSet);
  assertEquals(1,keyDefSet.size());
  keyDefList=dlmService.getAllKeyDefinitionsForKey(keyAccessOptions,key01);
  assertNotNull("String_Node_Str",keyDefList);
  assertEquals(5,keyDefList.size());
  keyDef=dlmService.getKeyDefinition(keyAccessOptions,keydefContext,key01);
  assertNotNull(keyDef);
  assertEquals(key01,keyDef.getKey());
  KeyAccessOptions kaoNotWindows=new KeyAccessOptions();
  kaoNotWindows.addExclusion("String_Node_Str","String_Node_Str");
  KeyAccessOptions kaoNotOsx=new KeyAccessOptions();
  kaoNotOsx.addExclusion("String_Node_Str","String_Node_Str");
  KeyAccessOptions kaoNotOsxOrWin=new KeyAccessOptions();
  kaoNotOsxOrWin.addExclusion("String_Node_Str","String_Node_Str");
  kaoNotOsxOrWin.addExclusion("String_Node_Str","String_Node_Str");
  DitaKeyDefinition keyDefOsx=dlmService.getKeyDefinition(kaoNotWindows,keydefContext,key01);
  assertNotNull(keyDefOsx);
  assertEquals(keyDefOsx,keyDef);
  assertTrue(keyDefOsx.getDitaPropsSpec().equals(keyDef.getDitaPropsSpec()));
  DitaKeyDefinition keyDefWindows=dlmService.getKeyDefinition(kaoNotOsx,keydefContext,key01);
  assertFalse(keyDefOsx.equals(keyDefWindows));
  assertFalse(keyDefOsx.getDitaPropsSpec().equals(keyDefWindows.getDitaPropsSpec()));
  keyDefList=dlmService.getAllKeyDefinitionsForKey(keyAccessOptions,keydefContext,key01);
  assertNotNull(keyDefList);
  assertEquals(5,keyDefList.size());
  DitaResource res;
  DitaElementResource elemRes;
  URL resUrl;
  res=dlmService.getResource(keyAccessOptions,keydefContext,key01);
  assertNotNull(res);
  assertTrue("String_Node_Str",res instanceof DitaElementResource);
  elemRes=(DitaElementResource)res;
  Element resElem=elemRes.getElement();
  assertNotNull("String_Node_Str",resElem);
  resUrl=res.getUrl();
  assertNotNull("String_Node_Str",resUrl);
  res=dlmService.getResource(keyAccessOptions,keydefContext,key02);
  assertNotNull(res);
  assertFalse("String_Node_Str",res instanceof DitaElementResource);
  resUrl=res.getUrl();
  assertNotNull(resUrl);
  assertTrue(dlmService.isKeyDefined(key01));
  assertTrue(dlmService.isKeyDefined(key01,keydefContext));
  assertFalse(dlmService.isKeyDefined("String_Node_Str"));
  assertFalse(dlmService.isKeyDefined("String_Node_Str",keydefContext));
}

Fixed version (ground truth):
public void testDitaKeyspaceConstruction() throws Exception {
  Element resourceElement=null;
  URI resourceUri=null;
  DitaKeySpace keySpace;
  KeyAccessOptions keyAccessOptions=new KeyAccessOptions();
  DitaKeyDefinitionContext keydefContext=dlmService.registerRootMap(rootMap);
  assertNotNull(keydefContext);
  DitaKeyDefinitionContext candKeydefContext=dlmService.getKeyDefinitionContext(rootMap);
  assertEquals(keydefContext,candKeydefContext);
  keySpace=dlmService.getKeySpace(keyAccessOptions,keydefContext);
  assertNotNull(keySpace);
  assertEquals(rootMap.getDocumentURI(),keySpace.getRootMap(keyAccessOptions).getDocumentURI());
  dlmService.unRegisterKeySpace(keydefContext);
  keySpace=dlmService.getKeySpace(keyAccessOptions,keydefContext);
  assertNull("String_Node_Str",keySpace);
  keydefContext=dlmService.registerRootMap(rootMap);
  assertNotNull(keydefContext);
  dlmService.markKeySpaceOutOfDate(keydefContext);
  assertNotNull(keydefContext);
  assertTrue(keydefContext.isOutOfDate());
  KeyReportOptions reportOptions=new KeyReportOptions();
  KeySpaceReporter reporter=new TextKeySpaceReporter();
  reporter.setPrintStream(System.out);
  reporter.report(keyAccessOptions,dlmService.getKeySpace(keyAccessOptions,keydefContext),reportOptions);
  reportOptions.setSortByMap(true);
  reporter.report(keyAccessOptions,dlmService.getKeySpace(keyAccessOptions,keydefContext),reportOptions);
  reportOptions.setSortByMap(false);
  reportOptions.setAllKeys(true);
  reporter.report(keyAccessOptions,dlmService.getKeySpace(keyAccessOptions,keydefContext),reportOptions);
  Set<String> keys=dlmService.getKeys(keyAccessOptions,keydefContext);
  assertNotNull(keys);
  assertEquals(keyCount,keys.size());
  keySpace=dlmService.getKeySpace(keyAccessOptions,keydefContext);
  assertNotNull(keySpace);
  assertEquals(keyCount,keySpace.size());
  Document candDoc=keySpace.getRootMap(keyAccessOptions);
  assertEquals(candDoc.getDocumentURI(),rootMap.getDocumentURI());
  Set<DitaKeyDefinition> keyDefSet=dlmService.getEffectiveKeyDefinitions(keyAccessOptions,keydefContext);
  List<DitaKeyDefinition> keyDefList=null;
  assertNotNull("String_Node_Str",keyDefSet);
  assertEquals(keyCount,keyDefSet.size());
  DitaKeyDefinition keyDef=dlmService.getKeyDefinition(keyAccessOptions,keydefContext,key01);
  assertNotNull("String_Node_Str",keyDef);
  String rootMapId=keyDef.getBaseUri().toURL().toExternalForm();
  assertNotNull(rootMapId);
  assertEquals(rootMap.getDocumentURI(),rootMapId);
  keyDefSet=dlmService.getEffectiveKeyDefinitionsForKey(keyAccessOptions,key01);
  assertNotNull("String_Node_Str",keyDefSet);
  assertEquals(1,keyDefSet.size());
  keyDefList=dlmService.getAllKeyDefinitionsForKey(keyAccessOptions,key01);
  assertNotNull("String_Node_Str",keyDefList);
  assertEquals(5,keyDefList.size());
  keyDef=dlmService.getKeyDefinition(keyAccessOptions,keydefContext,key01);
  assertNotNull(keyDef);
  assertEquals(key01,keyDef.getKey());
  KeyAccessOptions kaoNotWindows=new KeyAccessOptions();
  kaoNotWindows.addExclusion("String_Node_Str","String_Node_Str");
  KeyAccessOptions kaoNotOsx=new KeyAccessOptions();
  kaoNotOsx.addExclusion("String_Node_Str","String_Node_Str");
  KeyAccessOptions kaoNotOsxOrWin=new KeyAccessOptions();
  kaoNotOsxOrWin.addExclusion("String_Node_Str","String_Node_Str");
  kaoNotOsxOrWin.addExclusion("String_Node_Str","String_Node_Str");
  DitaKeyDefinition keyDefOsx=dlmService.getKeyDefinition(kaoNotWindows,keydefContext,key01);
  assertNotNull(keyDefOsx);
  assertEquals(keyDefOsx,keyDef);
  assertTrue(keyDefOsx.getDitaPropsSpec().equals(keyDef.getDitaPropsSpec()));
  DitaKeyDefinition keyDefWindows=dlmService.getKeyDefinition(kaoNotOsx,keydefContext,key01);
  assertFalse(keyDefOsx.equals(keyDefWindows));
  assertFalse(keyDefOsx.getDitaPropsSpec().equals(keyDefWindows.getDitaPropsSpec()));
  keyDefList=dlmService.getAllKeyDefinitionsForKey(keyAccessOptions,keydefContext,key01);
  assertNotNull(keyDefList);
  assertEquals(5,keyDefList.size());
  DitaResource res;
  DitaElementResource elemRes;
  URL resUrl;
  res=dlmService.getResource(keyAccessOptions,keydefContext,key01);
  assertNotNull(res);
  assertTrue("String_Node_Str",res instanceof DitaElementResource);
  elemRes=(DitaElementResource)res;
  Element resElem=elemRes.getElement();
  assertNotNull("String_Node_Str",resElem);
  resUrl=res.getUrl();
  assertNotNull("String_Node_Str",resUrl);
  res=dlmService.getResource(keyAccessOptions,keydefContext,key02);
  assertNotNull(res);
  assertFalse("String_Node_Str",res instanceof DitaElementResource);
  resUrl=res.getUrl();
  assertNotNull(resUrl);
  assertTrue(dlmService.isKeyDefined(key01));
  assertTrue(dlmService.isKeyDefined(key01,keydefContext));
  assertFalse(dlmService.isKeyDefined("String_Node_Str"));
  assertFalse(dlmService.isKeyDefined("String_Node_Str",keydefContext));
}