コード例 #1
0
  @Test
  public void updateTlvResource() throws Exception {
    epContainer.putEndpoints(
        new EndpointDescription[] {
          new EndpointDescription(
              "dev-02",
              null,
              false,
              new ResourceInfo[] {new ResourceInfo("/tlv", null, null, null, null)})
        });

    epContainer.updateResource(
        ResourcePath.of("dev-02", "/tlv"),
        mockEndpointResponse(createResourceTLV(), 200, TLV.CT_APPLICATION_LWM2M_TLV));
    assertEquals(
        epContainer.getEndpointResourceValues("dev-02").get(ResourcePath.of("dev-02", "/tlv")),
        new ResourceValue(
            "\t/0\t\t\tARM\r\n\t/1\t\t\tmbed\r\n\t/6/0\t\t\t0x01\r\n\t/6/1\t\t\t0x14",
            false,
            200,
            null,
            TLV.CT_APPLICATION_LWM2M_TLV,
            0,
            false));

    epContainer.updateResource(
        ResourcePath.of("dev-02", "/tlv"),
        mockEndpointResponse(createObjectInstanceTLV(), 200, TLV.CT_APPLICATION_LWM2M_TLV));
    assertEquals(
        epContainer.getEndpointResourceValues("dev-02").get(ResourcePath.of("dev-02", "/tlv")),
        new ResourceValue(
            "\t/0/0\t\t\t0x03\r\n"
                + "\t/0/2/1\t\t\t0xe0\r\n"
                + "\t/0/2/2\t\t\t0x80\r\n"
                + "\t/0/3\t\t\t0x01\r\n"
                + "\t/1/0\t\t\t0x04\r\n"
                + "\t/1/2/1\t\t\t0x80\r\n"
                + "\t/1/2/2\t\t\t0xe0\r\n"
                + "\t/1/3\t\t\t0x02",
            false,
            200,
            null,
            TLV.CT_APPLICATION_LWM2M_TLV,
            0,
            false));
  }
コード例 #2
0
  @Test
  public void updateResource() throws Exception {
    epContainer.putEndpoints(
        new EndpointDescription[] {
          new EndpointDescription(
              "dev-01",
              null,
              false,
              new ResourceInfo[] {new ResourceInfo("/temp", null, null, null, null)})
        });

    assertTrue(epContainer.updateResource(ResourcePath.of("dev-01", "/temp"), true));
    assertTrue(
        epContainer
            .getEndpointResourceValues("dev-01")
            .get(ResourcePath.of("dev-01", "/temp"))
            .isWaitingForResponse());

    // again same resource
    assertFalse(epContainer.updateResource(ResourcePath.of("dev-01", "/temp"), true));
    assertTrue(
        epContainer
            .getEndpointResourceValues("dev-01")
            .get(ResourcePath.of("dev-01", "/temp"))
            .isWaitingForResponse());

    epContainer.updateResource(
        ResourcePath.of("dev-01", "/temp"), mockEndpointResponse("25 C", 200));
    assertEquals(
        epContainer.getEndpointResourceValues("dev-01").get(ResourcePath.of("dev-01", "/temp")),
        new ResourceValue("25 C", false, 200, null, null, 0, false));

    epContainer.updateResource(ResourcePath.of("dev-01", "/temp"), "Some error");
    assertEquals(
        epContainer.getEndpointResourceValues("dev-01").get(ResourcePath.of("dev-01", "/temp")),
        new ResourceValue(null, false, 0, "Some error", null, 0, false));

    epContainer.updateResource(
        ResourcePath.of("dev-01", "/temp"),
        new ResourceNotification("endpoint1", null, null, null, new byte[] {2, 3, 4}, 0, 0));
    assertEquals(
        epContainer.getEndpointResourceValues("dev-01").get(ResourcePath.of("dev-01", "/temp")),
        new ResourceValue(Utf8String.from(new byte[] {2, 3, 4}), false, 200, null, null, 0, true));
  }