package com.evsuite.abrp; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import org.junit.Test; /** The direct ABRP request and its answer — pure JVM, nothing is sent. */ public class AbrpApiTest { @Test public void credentialsGoInTheBodyEncoded() throws Exception { String body = AbrpApi.formBody("key+1", "tok&en", "{\"utc\":1790000000,\"soc\":80}"); assertEquals("api_key=key%2B1&token=tok%26en&tlm=%7B%22utc%22%3A1790000000%2C%22soc%22%3A80%7D", body); assertFalse(AbrpApi.SEND_URL.contains("?")); } @Test public void onlyAnOkStatusIsAccepted() { assertTrue(AbrpApi.accepted(new ServerHttp.Response(200, "{\"status\":\"ok\"}"))); assertFalse(AbrpApi.accepted(new ServerHttp.Response(200, "{\"status\":\"error\",\"errors\":[\"bad token\"]}"))); assertFalse(AbrpApi.accepted(new ServerHttp.Response(401, "{\"status\":\"ok\"}"))); assertFalse(AbrpApi.accepted(new ServerHttp.Response(200, "not json"))); } @Test public void credentialsMustLookLikeCredentials() { assertTrue(AbrpConfig.isPlausible("0a1b2c3d-4e5f-6789")); assertFalse(AbrpConfig.isPlausible("short")); assertFalse(AbrpConfig.isPlausible("has a space in it")); assertFalse(AbrpConfig.isPlausible(null)); } @Test public void theSampleTimeIsReadFromItsJson() { assertEquals(1790000000L, TelemetryUploader.utcOf("{\"utc\":1790000000,\"soc\":5}")); assertEquals(0L, TelemetryUploader.utcOf("garbage")); } }