diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/GsonTests.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/GsonTests.java new file mode 100644 index 0000000..dd48ae5 --- /dev/null +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/GsonTests.java @@ -0,0 +1,41 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.config; + +import static org.assertj.core.api.Assertions.assertThat; + +import ch.usi.inf.sa4.sanmarinoes.smarthut.dto.AutomationFastUpdateRequest; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.BooleanTrigger; +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import java.util.List; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +public class GsonTests { + + private final Gson gson = GsonConfig.gson(); + + @Test + public void testGson() { + BooleanTrigger b = new BooleanTrigger(); + b.setId(1L); + String json = gson.toJson(b); + JsonObject o = gson.fromJson(json, JsonObject.class); + assertThat(o.get("kind")).isNotNull(); + assertThat(o.get("kind").getAsString()).isEqualTo("booleanTrigger"); + + AutomationFastUpdateRequest a = new AutomationFastUpdateRequest(); + AutomationFastUpdateRequest.BooleanTriggerDTO bt = + new AutomationFastUpdateRequest.BooleanTriggerDTO(); + bt.setDeviceId(42L); + a.setTriggers(List.of(bt)); + + AutomationFastUpdateRequest a2 = + gson.fromJson(gson.toJson(a), AutomationFastUpdateRequest.class); + AutomationFastUpdateRequest.TriggerDTO t = a2.getTriggers().get(0); + + assertThat(t).isExactlyInstanceOf(AutomationFastUpdateRequest.BooleanTriggerDTO.class); + assertThat(t.getDeviceId()).isEqualTo(42L); + } +} diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/SpringFoxConfigTests.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/SpringFoxConfigTests.java new file mode 100644 index 0000000..9b9cba3 --- /dev/null +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/config/SpringFoxConfigTests.java @@ -0,0 +1,18 @@ +package ch.usi.inf.sa4.sanmarinoes.smarthut.config; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +public class SpringFoxConfigTests { + + private final SpringFoxConfig springFoxConfig = new SpringFoxConfig(); + + @Test + public void testApi() { + assertThat(springFoxConfig.api()).isNotNull(); + } +}