feat: Add basic certificate models and repositories #8
7 changed files with 11 additions and 21 deletions
|
@ -19,9 +19,7 @@ public class Certificate {
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private String oid;
|
@Enumerated(EnumType.STRING)
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private CertificateType type;
|
private CertificateType type;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|
|
@ -4,6 +4,7 @@ import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import jakarta.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@ -12,8 +13,9 @@ import lombok.Setter;
|
||||||
public class User {
|
public class User {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.SEQUENCE)
|
@GeneratedValue(strategy = GenerationType.UUID)
|
||||||
private Long id;
|
@Setter(AccessLevel.NONE)
|
||||||
|
private String id;
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
private String username;
|
private String username;
|
||||||
|
|
|
@ -9,6 +9,7 @@ import lombok.Data;
|
||||||
public class CertificateRequest {
|
public class CertificateRequest {
|
||||||
|
|
||||||
@Builder.Default
|
@Builder.Default
|
||||||
|
@Deprecated
|
||||||
private String oid = UUID.randomUUID().toString();
|
private String oid = UUID.randomUUID().toString();
|
||||||
|
|
||||||
private RequestType type;
|
private RequestType type;
|
||||||
|
|
|
@ -5,6 +5,4 @@ import org.springframework.data.repository.CrudRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface CertificateRepository extends CrudRepository<Certificate, String> {
|
public interface CertificateRepository extends CrudRepository<Certificate, String> {}
|
||||||
Certificate findByOid(String oid);
|
|
||||||
}
|
|
||||||
|
|
|
@ -5,4 +5,4 @@ import org.springframework.data.repository.CrudRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface UserRepository extends CrudRepository<User, Long> {}
|
public interface UserRepository extends CrudRepository<User, String> {}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package de.mlessmann.certassist.repositories;
|
package de.mlessmann.certassist.repositories;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
import de.mlessmann.certassist.models.CertificateExtension;
|
import de.mlessmann.certassist.models.CertificateExtension;
|
||||||
import jakarta.transaction.Transactional;
|
import jakarta.transaction.Transactional;
|
||||||
|
|
|
@ -22,7 +22,6 @@ class CertificateRepositoryTest {
|
||||||
|
|
||||||
private Certificate getCertificate() {
|
private Certificate getCertificate() {
|
||||||
final Certificate certificate = new Certificate();
|
final Certificate certificate = new Certificate();
|
||||||
certificate.setOid("test");
|
|
||||||
certificate.setCommonName("test-cn");
|
certificate.setCommonName("test-cn");
|
||||||
certificate.setType(CertificateType.NORMAL_CERTIFICATE);
|
certificate.setType(CertificateType.NORMAL_CERTIFICATE);
|
||||||
certificate.setRequestedKeyLength(1);
|
certificate.setRequestedKeyLength(1);
|
||||||
|
@ -37,16 +36,9 @@ class CertificateRepositoryTest {
|
||||||
final Certificate certificate = getCertificate();
|
final Certificate certificate = getCertificate();
|
||||||
repository.save(certificate);
|
repository.save(certificate);
|
||||||
|
|
||||||
assertThat(repository.findById(certificate.getId()).orElseThrow().getOid()).isEqualTo("test");
|
Certificate foundCertificate = repository.findById(certificate.getId()).orElseThrow();
|
||||||
}
|
assertThat(foundCertificate.getCommonName()).isEqualTo("test-cn");
|
||||||
|
assertThat(foundCertificate.getType()).isEqualTo(CertificateType.NORMAL_CERTIFICATE);
|
||||||
@Test
|
|
||||||
@Transactional
|
|
||||||
void findCertificateByOid() {
|
|
||||||
final Certificate certificate = getCertificate();
|
|
||||||
repository.save(certificate);
|
|
||||||
|
|
||||||
assertThat(repository.findByOid("test").getCommonName()).isEqualTo("test-cn");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Add table
Reference in a new issue