-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Glad to see Macaulay Culkin is still alive and kickin.
- Loading branch information
1 parent
65ce328
commit fae83c6
Showing
14 changed files
with
155 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/dev/indoors/ringrats/serializer/MatchConfigDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package dev.indoors.ringrats.serializer; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import dev.indoors.ringrats.simulation.match.MatchConfiguration; | ||
import dev.indoors.ringrats.simulation.stipulation.Stipulation; | ||
import dev.indoors.ringrats.simulation.stipulation.StipulationFactory; | ||
import dev.indoors.ringrats.simulation.wrestler.Wrestler; | ||
|
||
import java.io.IOException; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class MatchConfigDeserializer extends JsonDeserializer<MatchConfiguration> { | ||
|
||
@Override | ||
public MatchConfiguration deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) | ||
throws IOException { | ||
JsonNode root = jsonParser.getCodec().readTree(jsonParser); | ||
ObjectMapper mapper = (ObjectMapper) jsonParser.getCodec(); | ||
|
||
Set<Wrestler> wrestlers = mapper.treeToValue(root.get("wrestlers"), mapper.getTypeFactory().constructCollectionType(HashSet.class, Wrestler.class)); | ||
|
||
Set<Stipulation> stipulations = new HashSet<>(); | ||
for (JsonNode stipNode : root.get("stipulations")) { | ||
Stipulation stipulation = StipulationFactory.getStipulation(stipNode.get("name").asText()); | ||
stipulations.add(stipulation); | ||
} | ||
|
||
return new MatchConfiguration(stipulations, wrestlers); | ||
} | ||
} |
23 changes: 0 additions & 23 deletions
23
src/main/java/dev/indoors/ringrats/serializer/StipulationDeserializer.java
This file was deleted.
Oops, something went wrong.
6 changes: 3 additions & 3 deletions
6
src/main/java/dev/indoors/ringrats/simulation/attribute/Attribute.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/java/dev/indoors/ringrats/simulation/wrestler/Health.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 18 additions & 6 deletions
24
src/test/java/dev/indoors/ringrats/service/SimulationServiceTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,37 @@ | ||
package dev.indoors.ringrats.service; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import dev.indoors.ringrats.service.impl.SimulationServiceImpl; | ||
import dev.indoors.ringrats.simulation.match.MatchConfiguration; | ||
import dev.indoors.ringrats.simulation.match.MatchResults; | ||
import dev.indoors.ringrats.util.MockMatchConfigurations; | ||
import dev.indoors.ringrats.util.MockWrestlers; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.core.io.ClassPathResource; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@SpringBootTest(args = {"-f", "examples/1v1-basic.json"}) | ||
@SpringBootTest | ||
public class SimulationServiceTests { | ||
|
||
@InjectMocks | ||
SimulationServiceImpl simService; | ||
|
||
@Autowired | ||
ObjectMapper mapper; | ||
|
||
@Test | ||
void firstTest() { | ||
MatchResults results = simService.simulateMatch(MockMatchConfigurations.basicOneFall(MockWrestlers.create("Wang Chung", "Dangerous Davey"))); | ||
void firstTest() throws IOException { | ||
ClassPathResource resource = new ClassPathResource("1v1-basic.json"); | ||
String json = new String(Files.readAllBytes(Paths.get(resource.getURI()))); | ||
MatchConfiguration config = mapper.readValue(json, MatchConfiguration.class); | ||
MatchResults results = simService.simulateMatch(config); | ||
assertThat(results).isNotNull(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters