Skip to content

Commit

Permalink
fix(controller): the event request could not be deserialized
Browse files Browse the repository at this point in the history
  • Loading branch information
jialeicui committed Dec 20, 2023
1 parent 807d59f commit 727a4c1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.springframework.validation.annotation.Validated;

@Data
@Validated
@SuperBuilder
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class EventRequest extends Event {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ai.starwhale.mlops.api.protocol.event;


import static org.junit.jupiter.api.Assertions.assertEquals;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;

class EventRequestTest {
@Test
public void testDeserialization() throws JsonProcessingException {
String json =
"{\"eventType\":\"INFO\",\"source\":\"CLIENT\",\"relatedResource\":{\"eventResourceType\":\"JOB\",\"id\":1},\"message\":\"foo\",\"data\":\"bar\"}";
var objMapper = new ObjectMapper();
var event = objMapper.readValue(json, EventRequest.class);
assertEquals(event.getEventType(), Event.EventType.INFO);
assertEquals(event.getSource(), Event.EventSource.CLIENT);
assertEquals(event.getRelatedResource().getEventResourceType(), Event.EventResourceType.JOB);
assertEquals(event.getRelatedResource().getId(), 1L);
assertEquals(event.getMessage(), "foo");
assertEquals(event.getData(), "bar");
}
}

0 comments on commit 727a4c1

Please sign in to comment.