private void testGetCodeOwnersWithDebug()

in javatests/com/google/gerrit/plugins/codeowners/acceptance/api/AbstractGetCodeOwnersForPathIT.java [1507:1592]


  private void testGetCodeOwnersWithDebug() throws Exception {
    TestAccount globalOwner =
        accountCreator.create("global_owner", "global.owner@example.com", "Global Owner", null);

    skipTestIfImportsNotSupportedByCodeOwnersBackend();

    TestAccount user2 = accountCreator.user2();

    CodeOwnerConfig.Key rootKey =
        codeOwnerConfigOperations
            .newCodeOwnerConfig()
            .project(project)
            .branch("master")
            .folderPath("/")
            .addCodeOwnerEmail(admin.email())
            .create();

    String nonExistingEmail = "non-existing@example.com";
    CodeOwnerConfig.Key fooKey =
        codeOwnerConfigOperations
            .newCodeOwnerConfig()
            .project(project)
            .branch("master")
            .folderPath("/foo/")
            .addCodeOwnerEmail(nonExistingEmail)
            .create();

    Project.NameKey nonExistingProject = Project.nameKey("non-existing");
    CodeOwnerConfigReference nonResolvableCodeOwnerConfigReference =
        CodeOwnerConfigReference.builder(
                CodeOwnerConfigImportMode.GLOBAL_CODE_OWNER_SETS_ONLY,
                codeOwnerConfigOperations
                    .codeOwnerConfig(CodeOwnerConfig.Key.create(nonExistingProject, "master", "/"))
                    .getFilePath())
            .setProject(nonExistingProject)
            .build();

    CodeOwnerConfig.Key fooBarKey =
        codeOwnerConfigOperations
            .newCodeOwnerConfig()
            .project(project)
            .branch("master")
            .folderPath("/foo/bar/")
            .addImport(nonResolvableCodeOwnerConfigReference)
            .addCodeOwnerSet(
                CodeOwnerSet.builder()
                    .addPathExpression(testPathExpressions.matchFileType("md"))
                    .addCodeOwnerEmail(user.email())
                    .build())
            .addCodeOwnerSet(
                CodeOwnerSet.builder()
                    .addPathExpression(testPathExpressions.matchFileType("txt"))
                    .addCodeOwnerEmail(user2.email())
                    .build())
            .create();

    String path = "/foo/bar/baz.md";
    CodeOwnersInfo codeOwnersInfo =
        queryCodeOwners(getCodeOwnersApi().query().withDebug(/* debug= */ true), path);
    assertThat(codeOwnersInfo)
        .hasCodeOwnersThat()
        .comparingElementsUsing(hasAccountId())
        .containsExactly(user.id(), admin.id(), globalOwner.id())
        .inOrder();
    assertThat(codeOwnersInfo)
        .hasDebugLogsThatContainAllOf(
            String.format("resolve code owners for %s from code owner config %s", path, fooBarKey),
            "per-file code owner set with path expressions [*.md] matches",
            String.format(
                "The import of %s:master:/%s in %s:master:/foo/bar/%s cannot be resolved:"
                    + " project %s not found",
                nonExistingProject.get(),
                getCodeOwnerConfigFileName(),
                project.get(),
                getCodeOwnerConfigFileName(),
                nonExistingProject.get()),
            String.format("resolved email %s to account %d", user.email(), user.id().get()),
            String.format("resolve code owners for %s from code owner config %s", path, fooKey),
            String.format(
                "cannot resolve code owner email %s: no account with this email exists",
                nonExistingEmail),
            String.format("resolve code owners for %s from code owner config %s", path, rootKey),
            String.format("resolved email %s to account %d", admin.email(), admin.id().get()),
            "resolve global code owners",
            String.format("resolved email %s to account %d", admin.email(), admin.id().get()));
  }