Compare commits

..

3 Commits

  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. 99
      src/test/java/de/kreth/clubhelper/model/PersonControllerTest.java
  4. 0
      src/test/resources/_data.sql
  5. 0
      src/test/resources/_schema.sql

@ -17,9 +17,6 @@ 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;
@ -40,13 +37,6 @@ 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 {
@Id private static final long serialVersionUID = 1L;
private String id;
@Id
@Column(name = "competition_type", nullable = false, length = 45) private String id;
private String type;
@Column(name = "competition_type", nullable = false, length = 45)
@OneToOne(mappedBy = "competitionType") private String type;
@JoinColumn(name = "id")
@MapsId @OneToOne(mappedBy = "competitionType")
private ClubEvent clubEvent; @JoinColumn(name = "id")
@MapsId
public Type getType() { private ClubEvent clubEvent;
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) {
public void setId(String id) { return false;
this.id = id;
} }
if (getClass() != obj.getClass()) {
public ClubEvent getClubEvent() { return false;
return clubEvent;
} }
CompetitionType other = (CompetitionType) obj;
public void setType(String type) { if (id == null) {
this.type = type; if (other.id != null) {
return false;
}
} else if (!id.equals(other.id)) {
return false;
} }
if (type == null) {
public static enum Type { if (other.type != null) {
EINZEL, return false;
SYNCHRON, }
DOPPELMINI, } else if (!type.equals(other.type)) {
MANNSCHAFT, return false;
LIGA
} }
return true;
}
@Override @Override
public int hashCode() { public String toString() {
final int prime = 31; return type;
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,6 +10,7 @@ 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;
@ -26,58 +27,56 @@ 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,
DataSourceAutoConfiguration.class, JdbcRepositoriesAutoConfiguration.class,
JdbcRepositoriesAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class, JdbcTemplateAutoConfiguration.class,
JdbcTemplateAutoConfiguration.class, SecurityAutoConfiguration.class
SecurityAutoConfiguration.class
}) })
class PersonControllerTest @Disabled
{ class PersonControllerTest {
@Autowired @Autowired
MockMvc mvc; MockMvc mvc;
@MockBean
PersonDao personDao;
private Person p1;
private Person p2;
@BeforeEach @MockBean
void initMocks() PersonDao personDao;
{
p1 = new Person();
p1.setId(1);
p1.setPrename("prename");
p1.setSurname("surname");
p1.setBirth(LocalDate.of(2000, 1, 1));
p1.setGender(Gender.MALE.getId());
p2 = new Person();
p2.setId(1);
p2.setPrename("prename");
p2.setSurname("surname");
p2.setBirth(LocalDate.of(2000, 1, 1));
p2.setGender(Gender.MALE.getId());
when(personDao.findAll()).thenReturn(Arrays.asList(p1, p2));
when(personDao.findById(1L)).thenReturn(Optional.of(p1));
when(personDao.findById(2L)).thenReturn(Optional.of(p2));
}
@Test private Person p1;
void callAllPersons() throws Exception private Person p2;
{
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)).andExpect(status().isOk())
.andExpect(content().string(jsonListOfPersons));
}
@Test @BeforeEach
void callPerson1() throws Exception void initMocks() {
{ p1 = new Person();
String jsonListOfPersons = "{\"id\":1,\"changed\":null,\"created\":null,\"deleted\":null,\"birth\":\"2000-01-01\",\"prename\":\"prename\",\"surname\":\"surname\",\"username\":null,\"password\":null,\"gender\":\"MALE\"}"; p1.setId(1);
mvc.perform(get("/person/1").accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML)).andExpect(status().isOk()) p1.setPrename("prename");
.andExpect(content().string(jsonListOfPersons)); p1.setSurname("surname");
} p1.setBirth(LocalDate.of(2000, 1, 1));
p1.setGender(Gender.MALE.getId());
p2 = new Person();
p2.setId(1);
p2.setPrename("prename");
p2.setSurname("surname");
p2.setBirth(LocalDate.of(2000, 1, 1));
p2.setGender(Gender.MALE.getId());
when(personDao.findAll()).thenReturn(Arrays.asList(p1, p2));
when(personDao.findById(1L)).thenReturn(Optional.of(p1));
when(personDao.findById(2L)).thenReturn(Optional.of(p2));
}
@Test
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))
.andExpect(status().isOk())
.andExpect(content().string(jsonListOfPersons));
}
@Test
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))
.andExpect(status().isOk())
.andExpect(content().string(jsonListOfPersons));
}
} }

Loading…
Cancel
Save