@Test
  public void duplicateStackServiceReposAreDiscarded() throws Exception {
    StackModule sm = createStackModule("FooBar",
        "2.4",
        // stack repos
        Optional.of(Lists.newArrayList(repoInfo("StackRepoA", "1.1.1", "http://repos.org/stackrepoA"),
            repoInfo("StackRepoB", "2.2.2", "http://repos.org/stackrepoB"))),

        // stack service repos
        // These two should be preserved. even though duplicates, the contents are the same
        Lists.newArrayList(repoInfo("serviceRepoA", "1.0.0", "http://bar.org/1_0_0")),
        Lists.newArrayList(repoInfo("serviceRepoA", "1.0.0", "http://bar.org/1_0_0")),
        // These should be dropped as the names are the same but contents are different
        Lists.newArrayList(repoInfo("serviceRepoB", "1.2.1", "http://bar.org/1_1_1")),
        Lists.newArrayList(repoInfo("serviceRepoB", "1.2.3", "http://bar.org/1_1_1")),
        // The first one should be dropped (overrides a stack repo), the rest only generates warnings (duplicate urls)
        Lists.newArrayList(repoInfo("StackRepoA", "2.0.0", "http://repos.org/stackrepoA_200"),
            repoInfo("ShouldBeJustAWarning1", "3.1.1", "http://repos.org/stackrepoA"),
            repoInfo("ShouldBeJustAWarning2", "1.0.0", "http://bar.org/1_0_0")));
    List<RepositoryInfo> repos = sm.getModuleInfo().getRepositories();

    Set<String> repoIds = getIds(repos);
    assertEquals("Unexpected number of repos. Each repo should be added only once", repoIds.size(), repos.size());
    assertEquals("Unexpected repositories",
        ImmutableSet.of("StackRepoA:1.1.1",
          "StackRepoB:2.2.2",
          "serviceRepoA:1.0.0",
          "ShouldBeJustAWarning1:3.1.1",
          "ShouldBeJustAWarning2:1.0.0"), repoIds);
  }
If more add-on services define the same repo, the duplicate repo definitions should be disregarded.
@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/stack/StackModuleTest.java