Removed BaseEntity. More use of builders.
This commit is contained in:
parent
3dc6e6e10b
commit
cc4a728ffc
@ -22,6 +22,12 @@ import java.util.Set;
|
||||
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
|
||||
public class Observation extends BaseEntity implements Serializable {
|
||||
|
||||
@NonNull
|
||||
@JsonProperty
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long id;
|
||||
|
||||
@JsonProperty
|
||||
@ManyToOne
|
||||
@JoinColumn(name="site_id", nullable=false)
|
||||
|
@ -1,25 +1,27 @@
|
||||
package uk.co.neviyn.Observations.core;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.Set;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@EqualsAndHashCode
|
||||
@ToString(callSuper = true)
|
||||
@Entity
|
||||
@Table(name = "SITE")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
|
||||
public class Site extends BaseEntity implements Serializable {
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public class Site implements Serializable {
|
||||
|
||||
@NonNull
|
||||
@JsonProperty
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long id;
|
||||
|
||||
@NonNull
|
||||
@JsonProperty
|
||||
@ -33,8 +35,4 @@ public class Site extends BaseEntity implements Serializable {
|
||||
@OneToMany(mappedBy = "site")
|
||||
private Set<Observation> observations;
|
||||
|
||||
public Site(long id, String name) {
|
||||
super(id);
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,27 @@
|
||||
package uk.co.neviyn.Observations.core;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.Set;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode
|
||||
@ToString
|
||||
@Entity
|
||||
@Table(name = "TUTOR")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
|
||||
public class Tutor extends BaseEntity implements Serializable {
|
||||
public class Tutor implements Serializable {
|
||||
|
||||
@NonNull
|
||||
@JsonProperty
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long id;
|
||||
|
||||
@NonNull
|
||||
@JsonProperty
|
||||
|
@ -25,7 +25,7 @@ public class SiteResource {
|
||||
@POST
|
||||
@UnitOfWork
|
||||
public Site add(@Auth User user, String name) {
|
||||
return dao.persist(new Site(name));
|
||||
return dao.persist(Site.builder().name(name).build());
|
||||
}
|
||||
|
||||
@Path("/all")
|
||||
|
@ -9,15 +9,16 @@ import org.junit.Test;
|
||||
import java.util.Collections;
|
||||
|
||||
import static io.dropwizard.testing.FixtureHelpers.fixture;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@Slf4j
|
||||
public class ObservationTest {
|
||||
private static final ObjectMapper mapper = Jackson.newObjectMapper();
|
||||
|
||||
private final Observation observation = new Observation(null, null, "Just a test observation", TrainingType.INITIAL, 1, 2, 3,
|
||||
4, 5, Collections.singletonList(new ObservationEntry("MONITORING", 5, "some", "another sum")), DateTime.parse("2018-09-18T00:00:00.000Z")
|
||||
);
|
||||
private final Observation observation = Observation.builder().observed("Just a test observation").type(TrainingType.INITIAL)
|
||||
.monitoring(1).control(2).conservatism(3).teamwork(4).knowledge(5)
|
||||
.observations(Collections.singletonList(new ObservationEntry("MONITORING", 5, "some", "another sum")))
|
||||
.date(DateTime.parse("2018-09-18T00:00:00.000Z")).build();
|
||||
|
||||
@Test
|
||||
public void serializesToJson() throws Exception {
|
||||
|
@ -1,14 +1,14 @@
|
||||
package uk.co.neviyn.Observations.dao;
|
||||
|
||||
import io.dropwizard.testing.junit.DAOTestRule;
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import uk.co.neviyn.Observations.api.AverageStats;
|
||||
import uk.co.neviyn.Observations.core.*;
|
||||
import uk.co.neviyn.Observations.core.Observation;
|
||||
import uk.co.neviyn.Observations.core.ObservationEntry;
|
||||
import uk.co.neviyn.Observations.core.Site;
|
||||
import uk.co.neviyn.Observations.core.TrainingType;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@ -20,11 +20,12 @@ public class ObservationDaoTest extends DaoTestBase {
|
||||
private ObservationDao dao;
|
||||
private SiteDao siteDao;
|
||||
|
||||
private final Site site = new Site("Test site");
|
||||
private final Site site = Site.builder().name("Test site").build();
|
||||
|
||||
private final Observation observation = new Observation(site, null, "Just a test observation", TrainingType.INITIAL, 1, 2, 3,
|
||||
4, 5, Collections.singletonList(new ObservationEntry("MONITORING", 5, "some", "another sum")), DateTime.parse("2018-09-18T00:00:00.000Z")
|
||||
);
|
||||
private final Observation observation = Observation.builder().observed("Just a test observation").type(TrainingType.INITIAL)
|
||||
.site(site).monitoring(1).control(2).conservatism(3).teamwork(4).knowledge(5)
|
||||
.observations(Collections.singletonList(new ObservationEntry("MONITORING", 5, "some", "another sum")))
|
||||
.date(DateTime.parse("2018-09-18T00:00:00.000Z")).build();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@ -97,7 +98,7 @@ public class ObservationDaoTest extends DaoTestBase {
|
||||
|
||||
|
||||
Observation hiddenEntity = SerializationUtils.clone(observation);
|
||||
Site hiddenSite = new Site("Area 51");
|
||||
Site hiddenSite = Site.builder().name("Area 51").build();
|
||||
hiddenEntity.setSite(hiddenSite);
|
||||
testRule.inTransaction(() -> {
|
||||
dao.persist(observation);
|
||||
|
@ -1,10 +1,11 @@
|
||||
package uk.co.neviyn.Observations.dao;
|
||||
|
||||
import java.util.List;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import uk.co.neviyn.Observations.core.Site;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class SiteDaoTest extends DaoTestBase{
|
||||
@ -19,9 +20,9 @@ public class SiteDaoTest extends DaoTestBase{
|
||||
@Test
|
||||
public void listAll() {
|
||||
testRule.inTransaction(() -> {
|
||||
dao.persist(new Site("Site A"));
|
||||
dao.persist(new Site("Site B"));
|
||||
dao.persist(new Site("Site C"));
|
||||
dao.persist(Site.builder().name("Site A").build());
|
||||
dao.persist(Site.builder().name("Site B").build());
|
||||
dao.persist(Site.builder().name("Site C").build());
|
||||
});
|
||||
List<Site> result = dao.listAll();
|
||||
assertNotNull(result);
|
||||
@ -37,7 +38,7 @@ public class SiteDaoTest extends DaoTestBase{
|
||||
|
||||
@Test
|
||||
public void persistAndGet() {
|
||||
Site insert = testRule.inTransaction(() -> dao.persist(new Site("Test Site")));
|
||||
Site insert = testRule.inTransaction(() -> dao.persist(Site.builder().name("Test Site").build()));
|
||||
assertNotNull(insert);
|
||||
assertTrue(insert.getId() > 0);
|
||||
assertNotNull(dao.get(insert.getId()));
|
||||
|
@ -1,19 +1,19 @@
|
||||
package uk.co.neviyn.Observations.dao;
|
||||
|
||||
import java.util.List;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import uk.co.neviyn.Observations.core.Observation;
|
||||
import uk.co.neviyn.Observations.core.Site;
|
||||
import uk.co.neviyn.Observations.core.Tutor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class TutorDaoTest extends DaoTestBase{
|
||||
|
||||
private TutorDao dao;
|
||||
private SiteDao siteDao;
|
||||
private final Site site = new Site("Test site");
|
||||
private final Site site = Site.builder().name("Test site").build();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@ -25,9 +25,9 @@ public class TutorDaoTest extends DaoTestBase{
|
||||
@Test
|
||||
public void listAll() {
|
||||
testRule.inTransaction(() -> {
|
||||
dao.persist(new Tutor("Mr Test", site, null));
|
||||
dao.persist(new Tutor("Mr Test2", site, null));
|
||||
dao.persist(new Tutor("Mr Test3", site, null));
|
||||
dao.persist(Tutor.builder().name("Mr Test").site(site).build());
|
||||
dao.persist(Tutor.builder().name("Mr Test2").site(site).build());
|
||||
dao.persist(Tutor.builder().name("Mr Test3").site(site).build());
|
||||
});
|
||||
List<Tutor> result = dao.listAll();
|
||||
assertNotNull(result);
|
||||
@ -43,7 +43,7 @@ public class TutorDaoTest extends DaoTestBase{
|
||||
|
||||
@Test
|
||||
public void persistAndGet() {
|
||||
Tutor insert = testRule.inTransaction(() -> dao.persist(new Tutor("Mr Test", site, null)));
|
||||
Tutor insert = testRule.inTransaction(() -> dao.persist(Tutor.builder().name("Mr Test").site(site).build()));
|
||||
assertNotNull(insert);
|
||||
assertTrue(insert.getId() > 0);
|
||||
assertNotNull(dao.get(insert.getId()));
|
||||
|
Loading…
Reference in New Issue
Block a user