ClientDAO { public long createClient(String name, String user, String description, @Nullable URI spiffeId) { ClientsRecord r = dslContext.newRecord(CLIENTS); long now = OffsetDateTime.now().toEpochSecond(); long generatedId = rowHmacGenerator.getNextLongSecure(); String rowHmac = rowHmacGenerator.computeRowHmac( CLIENTS.getName(), List.of(name, generatedId)); String spiffeStr = null; if (spiffeId != null && !spiffeId.toASCIIString().isEmpty()) { spiffeStr = spiffeId.toASCIIString(); } r.setId(generatedId); r.setName(name); r.setCreatedby(user); r.setCreatedat(now); r.setUpdatedby(user); r.setUpdatedat(now); r.setLastseen(null); r.setDescription(description); r.setEnabled(true); r.setAutomationallowed(false); r.setSpiffeId(spiffeStr); r.setRowHmac(rowHmac); r.store(); return r.getId(); } private  ClientDAO(DSLContext dslContext, ClientMapper clientMapper,
      RowHmacGenerator rowHmacGenerator); long createClient(String name, String user, String description,
      @Nullable URI spiffeId); void deleteClient(Client client); void sawClient(Client client, @Nullable Principal principal); Optional<Client> getClientByName(String name); Optional<Client> getClientBySpiffeId(URI spiffeId); Optional<Client> getClientById(long id); ImmutableSet<Client> getClients();  }
@Test public void createClient() throws Exception { int before = tableSize(); clientDAO.createClient("newClient", "creator", "", new URI("spiffe: Client newClient = clientDAO.getClientByName("newClient").orElseThrow(RuntimeException::new); assertThat(tableSize()).isEqualTo(before + 1); assertThat(clientDAO.getClients()).containsOnly(client1, client2, newClient); assertThat(newClient.getCreatedBy()).isEqualTo("creator"); assertThat(newClient.getSpiffeId()).isEqualTo("spiffe: }
@Test public void createClientDropsEmptyStringSpiffeId() throws Exception { clientDAO.createClient("firstWithoutSpiffe", "creator2", "", new URI("")); clientDAO.createClient("secondWithoutSpiffe", "creator2", "", new URI("")); }