Compare commits

..

No commits in common. '553e2b1551bc2441ae16a6cf0e3d84525e11f1d0' and 'b020eb3a628328a61b398aede8eb4ca3e8855e44' have entirely different histories.

  1. 10
      src/main/java/de/kreth/clubhelper/model/controller/AttendanceController.java
  2. 170
      src/main/java/de/kreth/clubhelper/model/data/CompetitionType.java
  3. 95
      src/test/java/de/kreth/clubhelper/model/PersonControllerTest.java
  4. 0
      src/test/resources/data.sql
  5. 0
      src/test/resources/schema.sql

@ -17,6 +17,9 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import de.kreth.clubhelper.model.dao.AttendanceDao; import de.kreth.clubhelper.model.dao.AttendanceDao;
import de.kreth.clubhelper.model.dao.PersonDao; import de.kreth.clubhelper.model.dao.PersonDao;
import de.kreth.clubhelper.model.data.Attendance; import de.kreth.clubhelper.model.data.Attendance;
@ -37,6 +40,13 @@ public class AttendanceController {
@ResponseBody @ResponseBody
public List<Attendance> getAttendencesOn(@PathVariable("date") @DateTimeFormat(iso = ISO.DATE) LocalDate date) { public List<Attendance> getAttendencesOn(@PathVariable("date") @DateTimeFormat(iso = ISO.DATE) LocalDate date) {
List<Attendance> findByOnDate = attendanceDao.findByOnDate(date); List<Attendance> findByOnDate = attendanceDao.findByOnDate(date);
ObjectMapper mapper = new ObjectMapper();
try {
String one = mapper.writeValueAsString(findByOnDate.get(0));
System.out.println(one);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return findByOnDate; return findByOnDate;
} }

@ -14,95 +14,95 @@ import javax.persistence.Table;
@Table(name = "clubevent_addon") @Table(name = "clubevent_addon")
public class CompetitionType implements Serializable { public class CompetitionType implements Serializable {
private static final long serialVersionUID = 1L; @Id
private String id;
@Id
private String id; @Column(name = "competition_type", nullable = false, length = 45)
private String type;
@Column(name = "competition_type", nullable = false, length = 45)
private String type; @OneToOne(mappedBy = "competitionType")
@JoinColumn(name = "id")
@OneToOne(mappedBy = "competitionType") @MapsId
@JoinColumn(name = "id") private ClubEvent clubEvent;
@MapsId
private ClubEvent clubEvent; public Type getType() {
return Type.valueOf(type);
public Type getType() { }
return Type.valueOf(type);
} public void setType(Type type) {
this.type = type.name();
public void setType(Type type) { }
this.type = type.name();
} public void setClubEvent(ClubEvent clubEvent) {
this.clubEvent = clubEvent;
public void setClubEvent(ClubEvent clubEvent) { }
this.clubEvent = clubEvent;
} public String getId() {
return id;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public ClubEvent getClubEvent() {
return clubEvent;
}
public void setType(String type) {
this.type = type;
}
public static enum Type {
EINZEL,
SYNCHRON,
DOPPELMINI,
MANNSCHAFT,
LIGA
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
} }
if (obj == null) {
return false; public void setId(String id) {
this.id = id;
} }
if (getClass() != obj.getClass()) {
return false; public ClubEvent getClubEvent() {
return clubEvent;
} }
CompetitionType other = (CompetitionType) obj;
if (id == null) { public void setType(String type) {
if (other.id != null) { this.type = type;
return false;
}
} else if (!id.equals(other.id)) {
return false;
} }
if (type == null) {
if (other.type != null) { public static enum Type {
return false; EINZEL,
} SYNCHRON,
} else if (!type.equals(other.type)) { DOPPELMINI,
return false; MANNSCHAFT,
LIGA
} }
return true;
}
@Override @Override
public String toString() { public int hashCode() {
return type; final int prime = 31;
} int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
CompetitionType other = (CompetitionType) obj;
if (id == null) {
if (other.id != null) {
return false;
}
}
else if (!id.equals(other.id)) {
return false;
}
if (type == null) {
if (other.type != null) {
return false;
}
}
else if (!type.equals(other.type)) {
return false;
}
return true;
}
@Override
public String toString() {
return type;
}
} }

@ -10,7 +10,6 @@ import java.util.Arrays;
import java.util.Optional; import java.util.Optional;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.data.jdbc.JdbcRepositoriesAutoConfiguration; import org.springframework.boot.autoconfigure.data.jdbc.JdbcRepositoriesAutoConfiguration;
@ -27,56 +26,58 @@ import de.kreth.clubhelper.model.dao.PersonDao;
import de.kreth.clubhelper.model.data.Gender; import de.kreth.clubhelper.model.data.Gender;
import de.kreth.clubhelper.model.data.Person; import de.kreth.clubhelper.model.data.Person;
@WebMvcTest(excludeAutoConfiguration = { @WebMvcTest(excludeAutoConfiguration =
DataSourceAutoConfiguration.class, {
JdbcRepositoriesAutoConfiguration.class, DataSourceAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class, JdbcRepositoriesAutoConfiguration.class,
JdbcTemplateAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class,
SecurityAutoConfiguration.class JdbcTemplateAutoConfiguration.class,
SecurityAutoConfiguration.class
}) })
@Disabled class PersonControllerTest
class PersonControllerTest { {
@Autowired @Autowired
MockMvc mvc; MockMvc mvc;
@MockBean @MockBean
PersonDao personDao; PersonDao personDao;
private Person p1; private Person p1;
private Person p2; private Person p2;
@BeforeEach @BeforeEach
void initMocks() { void initMocks()
p1 = new Person(); {
p1.setId(1); p1 = new Person();
p1.setPrename("prename"); p1.setId(1);
p1.setSurname("surname"); p1.setPrename("prename");
p1.setBirth(LocalDate.of(2000, 1, 1)); p1.setSurname("surname");
p1.setGender(Gender.MALE.getId()); p1.setBirth(LocalDate.of(2000, 1, 1));
p2 = new Person(); p1.setGender(Gender.MALE.getId());
p2.setId(1); p2 = new Person();
p2.setPrename("prename"); p2.setId(1);
p2.setSurname("surname"); p2.setPrename("prename");
p2.setBirth(LocalDate.of(2000, 1, 1)); p2.setSurname("surname");
p2.setGender(Gender.MALE.getId()); p2.setBirth(LocalDate.of(2000, 1, 1));
when(personDao.findAll()).thenReturn(Arrays.asList(p1, p2)); p2.setGender(Gender.MALE.getId());
when(personDao.findById(1L)).thenReturn(Optional.of(p1)); when(personDao.findAll()).thenReturn(Arrays.asList(p1, p2));
when(personDao.findById(2L)).thenReturn(Optional.of(p2)); when(personDao.findById(1L)).thenReturn(Optional.of(p1));
} when(personDao.findById(2L)).thenReturn(Optional.of(p2));
}
@Test @Test
void callAllPersons() throws Exception { void callAllPersons() throws Exception
String jsonListOfPersons = "[{\"id\":1,\"changed\":null,\"created\":null,\"deleted\":null,\"birth\":\"2000-01-01\",\"prename\":\"prename\",\"surname\":\"surname\",\"username\":null,\"password\":null,\"gender\":\"MALE\"},{\"id\":1,\"changed\":null,\"created\":null,\"deleted\":null,\"birth\":\"2000-01-01\",\"prename\":\"prename\",\"surname\":\"surname\",\"username\":null,\"password\":null,\"gender\":\"MALE\"}]"; {
mvc.perform(get("/person").accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML)) String jsonListOfPersons = "[{\"id\":1,\"changed\":null,\"created\":null,\"deleted\":null,\"birth\":\"2000-01-01\",\"prename\":\"prename\",\"surname\":\"surname\",\"username\":null,\"password\":null,\"gender\":\"MALE\"},{\"id\":1,\"changed\":null,\"created\":null,\"deleted\":null,\"birth\":\"2000-01-01\",\"prename\":\"prename\",\"surname\":\"surname\",\"username\":null,\"password\":null,\"gender\":\"MALE\"}]";
.andExpect(status().isOk()) mvc.perform(get("/person").accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML)).andExpect(status().isOk())
.andExpect(content().string(jsonListOfPersons)); .andExpect(content().string(jsonListOfPersons));
} }
@Test @Test
void callPerson1() throws Exception { void callPerson1() throws Exception
String jsonListOfPersons = "{\"id\":1,\"changed\":null,\"created\":null,\"deleted\":null,\"birth\":\"2000-01-01\",\"prename\":\"prename\",\"surname\":\"surname\",\"username\":null,\"password\":null,\"gender\":\"MALE\"}"; {
mvc.perform(get("/person/1").accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML)) String jsonListOfPersons = "{\"id\":1,\"changed\":null,\"created\":null,\"deleted\":null,\"birth\":\"2000-01-01\",\"prename\":\"prename\",\"surname\":\"surname\",\"username\":null,\"password\":null,\"gender\":\"MALE\"}";
.andExpect(status().isOk()) mvc.perform(get("/person/1").accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML)).andExpect(status().isOk())
.andExpect(content().string(jsonListOfPersons)); .andExpect(content().string(jsonListOfPersons));
} }
} }

Loading…
Cancel
Save