@Test public void testSelfImportSelf() { ConfigKeyPath tag = SingleLinkedListConfigKeyPath.ROOT.createChild("tag"); ConfigStore mockConfigStore = mock(ConfigStore.class, Mockito.RETURNS_SMART_NULLS); when(mockConfigStore.getCurrentVersion()).thenReturn(version); addConfigStoreChildren(mockConfigStore, version, SingleLinkedListConfigKeyPath.ROOT, tag); // self import self addConfigStoreImports(mockConfigStore, version, tag, tag); ConfigStoreBackedTopology csTopology = new ConfigStoreBackedTopology(mockConfigStore, this.version); InMemoryTopology inMemory = new InMemoryTopology(csTopology); try { inMemory.getImportsRecursively(tag); Assert.fail("Did not catch expected CircularDependencyException"); } catch (CircularDependencyException e) { Assert.assertTrue(e.getMessage().indexOf("/tag") > 0); } }
@Test public void testSelfImportChild() { ConfigKeyPath tag = SingleLinkedListConfigKeyPath.ROOT.createChild("tag"); ConfigKeyPath highPriorityTag = tag.createChild("highPriorityTag"); ConfigStore mockConfigStore = mock(ConfigStore.class, Mockito.RETURNS_SMART_NULLS); when(mockConfigStore.getCurrentVersion()).thenReturn(version); addConfigStoreChildren(mockConfigStore, version, SingleLinkedListConfigKeyPath.ROOT, tag); addConfigStoreChildren(mockConfigStore, version, tag, highPriorityTag); // parent import direct child addConfigStoreImports(mockConfigStore, version, tag, highPriorityTag); ConfigStoreBackedTopology csTopology = new ConfigStoreBackedTopology(mockConfigStore, this.version); InMemoryTopology inMemory = new InMemoryTopology(csTopology); try { inMemory.getImportsRecursively(tag); Assert.fail("Did not catch expected CircularDependencyException"); } catch (CircularDependencyException e) { Assert.assertTrue(e.getMessage().indexOf("/tag/highPriorityTag") > 0 && e.getMessage().indexOf("/tag ") > 0); } }
@Test public void testSelfImportDescendant() { ConfigKeyPath tag = SingleLinkedListConfigKeyPath.ROOT.createChild("tag"); ConfigKeyPath highPriorityTag = tag.createChild("highPriorityTag"); ConfigKeyPath nertzHighPriorityTag = highPriorityTag.createChild("nertzHighPriorityTag"); ConfigStore mockConfigStore = mock(ConfigStore.class, Mockito.RETURNS_SMART_NULLS); when(mockConfigStore.getCurrentVersion()).thenReturn(version); addConfigStoreChildren(mockConfigStore, version, SingleLinkedListConfigKeyPath.ROOT, tag); addConfigStoreChildren(mockConfigStore, version, tag, highPriorityTag); addConfigStoreChildren(mockConfigStore, version, highPriorityTag, nertzHighPriorityTag); // self import descendant // formed the loop /tag -> /tag/highPriorityTag/nertzHighPriorityTag -> /tag/highPriorityTag -> /tag addConfigStoreImports(mockConfigStore, version, tag, nertzHighPriorityTag); ConfigStoreBackedTopology csTopology = new ConfigStoreBackedTopology(mockConfigStore, this.version); InMemoryTopology inMemory = new InMemoryTopology(csTopology); try { inMemory.getImportsRecursively(tag); Assert.fail("Did not catch expected CircularDependencyException"); } catch (CircularDependencyException e) { Assert.assertTrue(e.getMessage().indexOf("/tag/highPriorityTag/nertzHighPriorityTag") > 0 && e.getMessage().indexOf("/tag/highPriorityTag ") > 0 && e.getMessage().indexOf("/tag ") > 0); } }
@Test public void testSelfIndirectlyImportDescendant() { ConfigKeyPath tag = SingleLinkedListConfigKeyPath.ROOT.createChild("tag"); ConfigKeyPath highPriorityTag = tag.createChild("highPriorityTag"); ConfigKeyPath nertzHighPriorityTag = highPriorityTag.createChild("nertzHighPriorityTag"); ConfigKeyPath tag2 = SingleLinkedListConfigKeyPath.ROOT.createChild("tag2"); ConfigStore mockConfigStore = mock(ConfigStore.class, Mockito.RETURNS_SMART_NULLS); when(mockConfigStore.getCurrentVersion()).thenReturn(version); addConfigStoreChildren(mockConfigStore, version, SingleLinkedListConfigKeyPath.ROOT, tag, tag2); addConfigStoreChildren(mockConfigStore, version, tag, highPriorityTag); addConfigStoreChildren(mockConfigStore, version, highPriorityTag, nertzHighPriorityTag); // self import descendant // formed the loop /tag -> /tag2 -> /tag/highPriorityTag/nertzHighPriorityTag -> /tag/highPriorityTag -> /tag addConfigStoreImports(mockConfigStore, version, tag, tag2); addConfigStoreImports(mockConfigStore, version, tag2, nertzHighPriorityTag); ConfigStoreBackedTopology csTopology = new ConfigStoreBackedTopology(mockConfigStore, this.version); InMemoryTopology inMemory = new InMemoryTopology(csTopology); try { inMemory.getImportsRecursively(tag); Assert.fail("Did not catch expected CircularDependencyException"); } catch (CircularDependencyException e) { Assert.assertTrue(e.getMessage().indexOf("/tag/highPriorityTag/nertzHighPriorityTag") > 0 && e.getMessage().indexOf("/tag/highPriorityTag ") > 0 && e.getMessage().indexOf("/tag ") > 0 && e.getMessage().indexOf("/tag2 ") > 0); } }
@Test public void testLoops() { ConfigKeyPath tag = SingleLinkedListConfigKeyPath.ROOT.createChild("tag"); ConfigKeyPath subTag1 = tag.createChild("subTag1"); ConfigKeyPath subTag2 = tag.createChild("subTag2"); ConfigKeyPath subTag3 = tag.createChild("subTag3"); ConfigStore mockConfigStore = mock(ConfigStore.class, Mockito.RETURNS_SMART_NULLS); when(mockConfigStore.getCurrentVersion()).thenReturn(version); addConfigStoreChildren(mockConfigStore, version, SingleLinkedListConfigKeyPath.ROOT, tag); addConfigStoreChildren(mockConfigStore, version, tag, subTag1, subTag2, subTag3); // self import descendant // formed loop /tag/subTag1 -> /tag/subTag2 -> /tag/subTag3 -> /tag/subTag1 addConfigStoreImports(mockConfigStore, version, subTag1, subTag2); addConfigStoreImports(mockConfigStore, version, subTag2, subTag3); addConfigStoreImports(mockConfigStore, version, subTag3, subTag1); ConfigStoreBackedTopology csTopology = new ConfigStoreBackedTopology(mockConfigStore, this.version); InMemoryTopology inMemory = new InMemoryTopology(csTopology); try { inMemory.getImportsRecursively(subTag1); Assert.fail("Did not catch expected CircularDependencyException"); } catch (CircularDependencyException e) { Assert.assertTrue(e.getMessage().indexOf("/tag/subTag1") > 0 && e.getMessage().indexOf("/tag/subTag2") > 0 && e.getMessage().indexOf("/tag/subTag3") > 0); } }