public void createNamespace(Namespace namespace, Map<String, String> metadata) {
    checkNamespaceIsValid(namespace);
    getRef().checkMutable();
    ContentKey key = ContentKey.of(namespace.levels());
    org.projectnessie.model.Namespace content =
        org.projectnessie.model.Namespace.of(key.getElements(), metadata);
    try {
      Content existing = api.getContent().reference(getReference()).key(key).get().get(key);
      if (existing != null) {
        throw namespaceAlreadyExists(key, existing, null);
      }
      try {
        commitRetry("create namespace " + key, Operation.Put.of(key, content));
      } catch (NessieReferenceConflictException e) {
        Optional<Conflict> conflict =
            NessieUtil.extractSingleConflict(
                e,
                EnumSet.of(
                    Conflict.ConflictType.KEY_EXISTS, Conflict.ConflictType.NAMESPACE_ABSENT));
        if (conflict.isPresent()) {
          switch (conflict.get().conflictType()) {
            case KEY_EXISTS:
              Content conflicting = withReference(api.getContent()).key(key).get().get(key);
              throw namespaceAlreadyExists(key, conflicting, e);
            case NAMESPACE_ABSENT:
              throw new NoSuchNamespaceException(
                  e,
                  "Cannot create namespace '%s': parent namespace '%s' does not exist",
                  namespace,
                  conflict.get().key());
          }
        }
        throw new RuntimeException(
            String.format("Cannot create namespace '%s': %s", namespace, e.getMessage()));
      }
    } catch (NessieNotFoundException e) {
      throw new RuntimeException(
          String.format(
              "Cannot create namespace '%s': ref '%s' is no longer valid.",
              namespace, getRef().getName()),
          e);
    } catch (BaseNessieClientServerException e) {
      throw new RuntimeException(
          String.format("Cannot create namespace '%s': %s", namespace, e.getMessage()), e);
    }
  }
@Test
  public void testCreateNamespace() throws NessieConflictException, NessieNotFoundException {
    String branch = "createNamespaceBranch";
    createBranch(branch);
    Map<String, String> catalogOptions =
        Map.of(
            CatalogProperties.USER, "iceberg-user",
            CatalogProperties.APP_ID, "iceberg-nessie");
    NessieIcebergClient client = new NessieIcebergClient(api, branch, null, catalogOptions);

    client.createNamespace(Namespace.of("a"), Map.of());
    assertThat(client.listNamespaces(Namespace.of("a"))).isNotNull();

    List<LogResponse.LogEntry> entries = api.getCommitLog().refName(branch).get().getLogEntries();
    assertThat(entries)
        .isNotEmpty()
        .first()
        .extracting(LogResponse.LogEntry::getCommitMeta)
        .extracting(CommitMeta::getMessage, CommitMeta::getAuthor, CommitMeta::getProperties)
        .containsExactly(
            "create namespace a",
            "iceberg-user",
            ImmutableMap.of(
                "application-type", "iceberg",
                "app-id", "iceberg-nessie"));
  }