Skip to content

Commit

Permalink
fix serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Borislav Kavalov committed Jun 18, 2024
1 parent 0791b5b commit e89d89f
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 18 deletions.
7 changes: 7 additions & 0 deletions backend/src/main/java/bg/kidsground/domain/AgeGroup.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package bg.kidsground.domain;

import com.fasterxml.jackson.annotation.JsonValue;

public enum AgeGroup {

ZERO_TO_THREE("zero_to_three"),
Expand All @@ -12,4 +14,9 @@ public enum AgeGroup {
AgeGroup(String value) {
this.value = value;
}

@JsonValue
public String getValue() {
return value;
}
}
7 changes: 7 additions & 0 deletions backend/src/main/java/bg/kidsground/domain/Environment.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package bg.kidsground.domain;

import com.fasterxml.jackson.annotation.JsonValue;

public enum Environment {

BOULEVARD("boulevard"),
Expand All @@ -11,4 +13,9 @@ public enum Environment {
Environment(final String value){
this.value = value;
}

@JsonValue
public String getValue() {
return value;
}
}
7 changes: 7 additions & 0 deletions backend/src/main/java/bg/kidsground/domain/FloorType.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package bg.kidsground.domain;

import com.fasterxml.jackson.annotation.JsonValue;

public enum FloorType {
ASPHALT("asphalt"),
GRASS("grass"),
Expand All @@ -12,4 +14,9 @@ public enum FloorType {
FloorType(String value) {
this.value = value;
}

@JsonValue
public String getValue() {
return value;
}
}
23 changes: 7 additions & 16 deletions backend/src/main/java/bg/kidsground/domain/Playground.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,39 +35,30 @@ public class Playground {
private FloorType floorType;

@JsonProperty("shade_type")
@Enumerated(EnumType.STRING)
private ShadeType shadeType;

@JsonProperty("environment")
private String environment;
@Enumerated(EnumType.STRING)
private Environment environment;

@JsonProperty("transport")
@ElementCollection
private List<String> transport;

@JsonProperty("toys")
@ElementCollection
private List<String> toys;

@JsonProperty("facilities")
@ElementCollection
private List<String> facilities;

@JsonProperty("image_links")
@ElementCollection
private List<String> imageLinks;

@JsonProperty("coordinates")
private Coordinates coordinates;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
7 changes: 7 additions & 0 deletions backend/src/main/java/bg/kidsground/domain/ShadeType.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package bg.kidsground.domain;

import com.fasterxml.jackson.annotation.JsonValue;

public enum ShadeType {

TREES("trees"),
Expand All @@ -11,4 +13,9 @@ public enum ShadeType {
ShadeType(String value) {
this.value = value;
}

@JsonValue
public String getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package bg.kidsground.controller;

import bg.kidsground.constants.AppRestEndpoints;
import bg.kidsground.domain.AgeGroup;
import bg.kidsground.domain.Coordinates;
import bg.kidsground.domain.Environment;
import bg.kidsground.domain.FloorType;
import bg.kidsground.domain.Playground;
import bg.kidsground.domain.ShadeType;
import bg.kidsground.service.PlaygroundService;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -13,6 +18,7 @@
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

import java.util.List;
import java.util.NoSuchElementException;

import static org.mockito.ArgumentMatchers.any;
Expand All @@ -39,8 +45,9 @@ void setUp() {

@Test
public void testSavePlayground() throws Exception {
Playground playground = new Playground(); // You need to create a Playground object here with appropriate data
Playground playground = new Playground();
playground.setName("Test Playground");
playground.setAgeGroup(AgeGroup.THREE_TO_SIX);
ObjectMapper objectMapper = new ObjectMapper();
String playgroundJson = objectMapper.writeValueAsString(playground);

Expand All @@ -59,14 +66,34 @@ public void testGetPlaygroundById() throws Exception {
Playground playground = new Playground(); // You need to create a Playground object here with appropriate data
playground.setId(id);
playground.setName(name);
playground.setAgeGroup(AgeGroup.THREE_TO_SIX);
playground.setCoordinates(Coordinates.builder().latitude(10.2).longitude(20.1).build());
playground.setFacilities(List.of("пързалка", "люлка"));
playground.setFloorType(FloorType.RUBBER);
playground.setEnvironment(Environment.APARTMENTS);
playground.setHasFence(true);
playground.setToys(List.of("конче"));
playground.setImageLinks(List.of("https://example.com/image"));
playground.setShadeType(ShadeType.TREES);

when(playgroundService.getById(id)).thenReturn(playground);

mockMvc.perform(get(AppRestEndpoints.V1.Playground.By.ID, id))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.id").value(id))
.andExpect(jsonPath("$.name").value(name));
.andExpect(jsonPath("$.name").value(name))
.andExpect(jsonPath("$.age_group").value("three_to_six"))
.andExpect(jsonPath("$.coordinates.lat").value(10.2))
.andExpect(jsonPath("$.coordinates.lng").value(20.1))
.andExpect(jsonPath("$.facilities[0]").value("пързалка"))
.andExpect(jsonPath("$.facilities[1]").value("люлка"))
.andExpect(jsonPath("$.toys[0]").value("конче"))
.andExpect(jsonPath("$.image_links").value("https://example.com/image"))
.andExpect(jsonPath("$.floor_type").value("rubber"))
.andExpect(jsonPath("$.shade_type").value("trees"))
.andExpect(jsonPath("$.has_fence").value(true))
.andExpect(jsonPath("$.environment").value("apartments"));

verify(playgroundService).getById(id);
}
Expand Down

0 comments on commit e89d89f

Please sign in to comment.