package com.lingniu.ingest.inbound.xinda;

import com.lingniu.ingest.api.annotation.EventEmit;
import com.lingniu.ingest.api.annotation.MessageMapping;
import com.lingniu.ingest.api.event.VehicleEvent;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Method;

import static org.assertj.core.api.Assertions.assertThat;

class XindaPushRealtimeHandlerTest {

    @Test
    void declares0300AsAlarmHandler() throws Exception {
        Method method = XindaPushRealtimeHandler.class.getMethod("onAlarm", XindaPushMessage.class);

        assertThat(method.getAnnotation(MessageMapping.class).command()).containsExactly(0x0300);
        assertThat(method.getAnnotation(EventEmit.class).value()).containsExactly(VehicleEvent.Alarm.class);
    }

    @Test
    void alarmHandlerEmitsAlarmEvent() {
        XindaPushRealtimeHandler handler = new XindaPushRealtimeHandler(new XindaPushEventMapper());

        assertThat(handler.onAlarm(new XindaPushMessage("0300", "{\"alarmType\":\"HYDROGEN_LEAK\"}")))
                .singleElement()
                .isInstanceOf(VehicleEvent.Alarm.class);
    }
}
