@Test
  public void testUserProfileToJson() {
    InputStream is = this.getClass().getResourceAsStream("/json_test/user_profile_json.txt");

    Profile profile = JsonParser.parseProfile(is);
    String userProfileString = profile.toString();

    assertNotNull(userProfileString);
    assertTrue(userProfileString.contains("dashBoards"));
  }
Example #2
0
  @Test
  public void loadGzippedProfile() throws Exception {
    String expected = readTestUserProfile();

    clientPair.appClient.send("loadProfileGzipped");
    verify(clientPair.appClient.responseMock, timeout(500)).channelRead(any(), any());

    Profile profile = JsonParser.parseProfile(clientPair.appClient.getBody(), 1);
    profile.dashBoards[0].updatedAt = 0;
    assertEquals(expected, profile.toString());
  }
  @Test
  public void testUserProfileToJsonWithTimer() {
    InputStream is = this.getClass().getResourceAsStream("/json_test/user_profile_with_timer.txt");

    Profile profile = JsonParser.parseProfile(is);
    String userProfileString = profile.toString();

    assertNotNull(userProfileString);
    assertTrue(userProfileString.contains("dashBoards"));
    List<Timer> timers = getActiveTimerWidgets(profile);
    assertNotNull(timers);
    assertEquals(1, timers.size());
  }
Example #4
0
  @Test
  public void createBasicProfile() throws Exception {
    TestAppClient appClient = new TestAppClient("localhost", tcpAppPort, properties);

    appClient.start();

    appClient.send("register [email protected] 1");
    verify(appClient.responseMock, timeout(500)).channelRead(any(), eq(new ResponseMessage(1, OK)));

    appClient.send("login [email protected] 1 Android RC13");
    verify(appClient.responseMock, timeout(500)).channelRead(any(), eq(new ResponseMessage(2, OK)));

    appClient.send("createDash {\"id\":1, \"name\":\"test board\"}\"");
    verify(appClient.responseMock, timeout(500)).channelRead(any(), eq(new ResponseMessage(3, OK)));

    appClient.send(
        "createWidget 1\0{\"id\":1, \"x\":0, \"y\":0, \"label\":\"Some Text\", \"type\":\"BUTTON\", \"pinType\":\"DIGITAL\", \"pin\":1}");
    verify(appClient.responseMock, timeout(500)).channelRead(any(), eq(new ResponseMessage(4, OK)));

    appClient.reset();

    appClient.send("loadProfileGzipped");
    Profile profile = JsonParser.parseProfile(appClient.getBody(), 1);
    profile.dashBoards[0].updatedAt = 0;

    assertEquals(
        "{\"dashBoards\":[{\"id\":1,\"name\":\"test board\",\"createdAt\":0,\"updatedAt\":0,\"widgets\":[{\"type\":\"BUTTON\",\"id\":1,\"x\":0,\"y\":0,\"label\":\"Some Text\",\"pinType\":\"DIGITAL\",\"pin\":1,\"pwmMode\":false,\"rangeMappingOn\":false,\"min\":0,\"max\":0,\"pushMode\":false}],\"keepScreenOn\":false,\"isShared\":false,\"isActive\":false}]}",
        profile.toString());

    appClient.send("createWidget 1\0{\"id\":1,\"type\":\"BUTTON\"}");
    verify(appClient.responseMock, timeout(500))
        .channelRead(any(), eq(new ResponseMessage(2, NOT_ALLOWED)));

    appClient.send(
        "createWidget 1\0{\"id\":2, \"x\":2, \"y\":2, \"label\":\"Some Text 2\", \"type\":\"BUTTON\", \"pinType\":\"DIGITAL\", \"pin\":2}");
    verify(appClient.responseMock, timeout(500)).channelRead(any(), eq(new ResponseMessage(3, OK)));

    appClient.reset();

    appClient.send("loadProfileGzipped");
    profile = JsonParser.parseProfile(appClient.getBody(), 1);
    profile.dashBoards[0].updatedAt = 0;
    assertEquals(
        "{\"dashBoards\":[{\"id\":1,\"name\":\"test board\",\"createdAt\":0,\"updatedAt\":0,\"widgets\":[{\"type\":\"BUTTON\",\"id\":1,\"x\":0,\"y\":0,\"label\":\"Some Text\",\"pinType\":\"DIGITAL\",\"pin\":1,\"pwmMode\":false,\"rangeMappingOn\":false,\"min\":0,\"max\":0,\"pushMode\":false},{\"type\":\"BUTTON\",\"id\":2,\"x\":2,\"y\":2,\"label\":\"Some Text 2\",\"pinType\":\"DIGITAL\",\"pin\":2,\"pwmMode\":false,\"rangeMappingOn\":false,\"min\":0,\"max\":0,\"pushMode\":false}],\"keepScreenOn\":false,\"isShared\":false,\"isActive\":false}]}",
        profile.toString());

    appClient.send(
        "updateWidget 1\0{\"id\":2, \"x\":2, \"y\":2, \"label\":\"new label\", \"type\":\"BUTTON\", \"pinType\":\"DIGITAL\", \"pin\":3}\"");
    verify(appClient.responseMock, timeout(500)).channelRead(any(), eq(new ResponseMessage(2, OK)));

    appClient.reset();

    appClient.send("loadProfileGzipped");
    profile = JsonParser.parseProfile(appClient.getBody(), 1);
    profile.dashBoards[0].updatedAt = 0;
    assertEquals(
        "{\"dashBoards\":[{\"id\":1,\"name\":\"test board\",\"createdAt\":0,\"updatedAt\":0,\"widgets\":[{\"type\":\"BUTTON\",\"id\":1,\"x\":0,\"y\":0,\"label\":\"Some Text\",\"pinType\":\"DIGITAL\",\"pin\":1,\"pwmMode\":false,\"rangeMappingOn\":false,\"min\":0,\"max\":0,\"pushMode\":false},{\"type\":\"BUTTON\",\"id\":2,\"x\":2,\"y\":2,\"label\":\"new label\",\"pinType\":\"DIGITAL\",\"pin\":3,\"pwmMode\":false,\"rangeMappingOn\":false,\"min\":0,\"max\":0,\"pushMode\":false}],\"keepScreenOn\":false,\"isShared\":false,\"isActive\":false}]}",
        profile.toString());

    appClient.send("deleteWidget 1\0" + "3");
    verify(appClient.responseMock, timeout(500))
        .channelRead(any(), eq(new ResponseMessage(2, ILLEGAL_COMMAND)));

    appClient.send("deleteWidget 1\0" + "1");
    verify(appClient.responseMock, timeout(500)).channelRead(any(), eq(new ResponseMessage(3, OK)));

    appClient.send("deleteWidget 1\0" + "2");
    verify(appClient.responseMock, timeout(500)).channelRead(any(), eq(new ResponseMessage(4, OK)));

    appClient.reset();

    appClient.send("loadProfileGzipped");
    profile = JsonParser.parseProfile(appClient.getBody(), 1);
    profile.dashBoards[0].updatedAt = 0;
    assertEquals(
        "{\"dashBoards\":[{\"id\":1,\"name\":\"test board\",\"createdAt\":0,\"updatedAt\":0,\"keepScreenOn\":false,\"isShared\":false,\"isActive\":false}]}",
        profile.toString());
  }