當前位置: 首頁>>代碼示例>>Java>>正文


Java ObserveResponse.getObservation方法代碼示例

本文整理匯總了Java中org.eclipse.leshan.core.response.ObserveResponse.getObservation方法的典型用法代碼示例。如果您正苦於以下問題:Java ObserveResponse.getObservation方法的具體用法?Java ObserveResponse.getObservation怎麽用?Java ObserveResponse.getObservation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.leshan.core.response.ObserveResponse的用法示例。


在下文中一共展示了ObserveResponse.getObservation方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: can_observe_resource

import org.eclipse.leshan.core.response.ObserveResponse; //導入方法依賴的package包/類
@Test
public void can_observe_resource() throws InterruptedException {
    TestObservationListener listener = new TestObservationListener();
    helper.server.getObservationService().addListener(listener);

    // observe device timezone
    ObserveResponse observeResponse = helper.server.send(helper.getCurrentRegistration(),
            new ObserveRequest(3, 0, 15));
    assertEquals(ResponseCode.CONTENT, observeResponse.getCode());
    assertNotNull(observeResponse.getCoapResponse());
    assertThat(observeResponse.getCoapResponse(), is(instanceOf(Response.class)));

    // an observation response should have been sent
    Observation observation = observeResponse.getObservation();
    assertEquals("/3/0/15", observation.getPath().toString());
    assertEquals(helper.getCurrentRegistration().getId(), observation.getRegistrationId());
    Set<Observation> observations = helper.server.getObservationService()
            .getObservations(helper.getCurrentRegistration());
    assertTrue("We should have only on observation", observations.size() == 1);
    assertTrue("New observation is not there", observations.contains(observation));

    // write device timezone
    LwM2mResponse writeResponse = helper.server.send(helper.getCurrentRegistration(),
            new WriteRequest(3, 0, 15, "Europe/Paris"));

    // verify result
    listener.waitForNotification(2000);
    assertEquals(ResponseCode.CHANGED, writeResponse.getCode());
    assertTrue(listener.receivedNotify().get());
    assertEquals(LwM2mSingleResource.newStringResource(15, "Europe/Paris"), listener.getResponse().getContent());
    assertNotNull(listener.getResponse().getCoapResponse());
    assertThat(listener.getResponse().getCoapResponse(), is(instanceOf(Response.class)));
}
 
開發者ID:eclipse,項目名稱:leshan,代碼行數:34,代碼來源:ObserveTest.java

示例2: can_observe_instance

import org.eclipse.leshan.core.response.ObserveResponse; //導入方法依賴的package包/類
@Test
public void can_observe_instance() throws InterruptedException {
    TestObservationListener listener = new TestObservationListener();
    helper.server.getObservationService().addListener(listener);

    // observe device timezone
    ObserveResponse observeResponse = helper.server.send(helper.getCurrentRegistration(), new ObserveRequest(3, 0));
    assertEquals(ResponseCode.CONTENT, observeResponse.getCode());
    assertNotNull(observeResponse.getCoapResponse());
    assertThat(observeResponse.getCoapResponse(), is(instanceOf(Response.class)));

    // an observation response should have been sent
    Observation observation = observeResponse.getObservation();
    assertEquals("/3/0", observation.getPath().toString());
    assertEquals(helper.getCurrentRegistration().getId(), observation.getRegistrationId());
    Set<Observation> observations = helper.server.getObservationService()
            .getObservations(helper.getCurrentRegistration());
    assertTrue("We should have only on observation", observations.size() == 1);
    assertTrue("New observation is not there", observations.contains(observation));

    // write device timezone
    LwM2mResponse writeResponse = helper.server.send(helper.getCurrentRegistration(),
            new WriteRequest(3, 0, 15, "Europe/Paris"));

    // verify result
    listener.waitForNotification(2000);
    assertEquals(ResponseCode.CHANGED, writeResponse.getCode());
    assertTrue(listener.receivedNotify().get());
    assertTrue(listener.getResponse().getContent() instanceof LwM2mObjectInstance);
    assertNotNull(listener.getResponse().getCoapResponse());
    assertThat(listener.getResponse().getCoapResponse(), is(instanceOf(Response.class)));

    // try to read the object instance for comparing
    ReadResponse readResp = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(3, 0));

    assertEquals(readResp.getContent(), listener.getResponse().getContent());
}
 
開發者ID:eclipse,項目名稱:leshan,代碼行數:38,代碼來源:ObserveTest.java

示例3: can_observe_object

import org.eclipse.leshan.core.response.ObserveResponse; //導入方法依賴的package包/類
@Test
public void can_observe_object() throws InterruptedException {
    TestObservationListener listener = new TestObservationListener();
    helper.server.getObservationService().addListener(listener);

    // observe device timezone
    ObserveResponse observeResponse = helper.server.send(helper.getCurrentRegistration(), new ObserveRequest(3));
    assertEquals(ResponseCode.CONTENT, observeResponse.getCode());
    assertNotNull(observeResponse.getCoapResponse());
    assertThat(observeResponse.getCoapResponse(), is(instanceOf(Response.class)));

    // an observation response should have been sent
    Observation observation = observeResponse.getObservation();
    assertEquals("/3", observation.getPath().toString());
    assertEquals(helper.getCurrentRegistration().getId(), observation.getRegistrationId());
    Set<Observation> observations = helper.server.getObservationService()
            .getObservations(helper.getCurrentRegistration());
    assertTrue("We should have only on observation", observations.size() == 1);
    assertTrue("New observation is not there", observations.contains(observation));

    // write device timezone
    LwM2mResponse writeResponse = helper.server.send(helper.getCurrentRegistration(),
            new WriteRequest(3, 0, 15, "Europe/Paris"));

    // verify result
    listener.waitForNotification(2000);
    assertEquals(ResponseCode.CHANGED, writeResponse.getCode());
    assertTrue(listener.receivedNotify().get());
    assertTrue(listener.getResponse().getContent() instanceof LwM2mObject);
    assertNotNull(listener.getResponse().getCoapResponse());
    assertThat(listener.getResponse().getCoapResponse(), is(instanceOf(Response.class)));

    // try to read the object for comparing
    ReadResponse readResp = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(3));

    assertEquals(readResp.getContent(), listener.getResponse().getContent());
}
 
開發者ID:eclipse,項目名稱:leshan,代碼行數:38,代碼來源:ObserveTest.java

示例4: can_handle_error_on_notification

import org.eclipse.leshan.core.response.ObserveResponse; //導入方法依賴的package包/類
@Test
public void can_handle_error_on_notification() throws InterruptedException {
    TestObservationListener listener = new TestObservationListener();
    helper.server.getObservationService().addListener(listener);

    // observe device timezone
    ObserveResponse observeResponse = helper.server.send(helper.getCurrentRegistration(),
            new ObserveRequest(3, 0, 15));
    assertEquals(ResponseCode.CONTENT, observeResponse.getCode());
    assertNotNull(observeResponse.getCoapResponse());
    assertThat(observeResponse.getCoapResponse(), is(instanceOf(Response.class)));

    // an observation response should have been sent
    Observation observation = observeResponse.getObservation();
    assertEquals("/3/0/15", observation.getPath().toString());
    assertEquals(helper.getCurrentRegistration().getId(), observation.getRegistrationId());
    Set<Observation> observations = helper.server.getObservationService()
            .getObservations(helper.getCurrentRegistration());
    assertTrue("We should have only on observation", observations.size() == 1);
    assertTrue("New observation is not there", observations.contains(observation));

    // *** HACK send a notification with unsupported content format *** //
    byte[] payload = LwM2mNodeJsonEncoder.encode(LwM2mSingleResource.newStringResource(15, "Paris"),
            new LwM2mPath("/3/0/15"), new LwM2mModel(helper.createObjectModels()),
            new DefaultLwM2mValueConverter());
    Response firstCoapResponse = (Response) observeResponse.getCoapResponse();
    sendNotification(getConnector(helper.client), payload, firstCoapResponse, 666); // 666 is not a supported //
                                                                                    // contentFormat.
    // *** Hack End *** //

    // verify result
    listener.waitForNotification(2000);
    assertTrue(listener.receivedNotify().get());
    assertNotNull(listener.getError());
}
 
開發者ID:eclipse,項目名稱:leshan,代碼行數:36,代碼來源:ObserveTest.java

示例5: can_observe_timestamped_resource

import org.eclipse.leshan.core.response.ObserveResponse; //導入方法依賴的package包/類
@Test
public void can_observe_timestamped_resource() throws InterruptedException {
    TestObservationListener listener = new TestObservationListener();
    helper.server.getObservationService().addListener(listener);

    // observe device timezone
    ObserveResponse observeResponse = helper.server.send(helper.getCurrentRegistration(),
            new ObserveRequest(3, 0, 15));
    assertEquals(ResponseCode.CONTENT, observeResponse.getCode());
    assertNotNull(observeResponse.getCoapResponse());
    assertThat(observeResponse.getCoapResponse(), is(instanceOf(Response.class)));

    // an observation response should have been sent
    Observation observation = observeResponse.getObservation();
    assertEquals("/3/0/15", observation.getPath().toString());
    assertEquals(helper.getCurrentRegistration().getId(), observation.getRegistrationId());
    Set<Observation> observations = helper.server.getObservationService()
            .getObservations(helper.getCurrentRegistration());
    assertTrue("We should have only on observation", observations.size() == 1);
    assertTrue("New observation is not there", observations.contains(observation));

    // *** HACK send time-stamped notification as Leshan client does not support it *** //
    // create time-stamped nodes
    TimestampedLwM2mNode mostRecentNode = new TimestampedLwM2mNode(System.currentTimeMillis(),
            LwM2mSingleResource.newStringResource(15, "Paris"));
    List<TimestampedLwM2mNode> timestampedNodes = new ArrayList<>();
    timestampedNodes.add(mostRecentNode);
    timestampedNodes.add(new TimestampedLwM2mNode(mostRecentNode.getTimestamp() - 2,
            LwM2mSingleResource.newStringResource(15, "Londres")));
    byte[] payload = LwM2mNodeJsonEncoder.encodeTimestampedData(timestampedNodes, new LwM2mPath("/3/0/15"),
            new LwM2mModel(helper.createObjectModels()), new DefaultLwM2mValueConverter());
    Response firstCoapResponse = (Response) observeResponse.getCoapResponse();
    sendNotification(getConnector(helper.client), payload, firstCoapResponse, ContentFormat.JSON_CODE);
    // *** Hack End *** //

    // verify result
    listener.waitForNotification(2000);
    assertTrue(listener.receivedNotify().get());
    assertEquals(mostRecentNode.getNode(), listener.getResponse().getContent());
    assertEquals(timestampedNodes, listener.getResponse().getTimestampedLwM2mNode());
    assertNotNull(listener.getResponse().getCoapResponse());
    assertThat(listener.getResponse().getCoapResponse(), is(instanceOf(Response.class)));
}
 
開發者ID:eclipse,項目名稱:leshan,代碼行數:44,代碼來源:ObserveTest.java

示例6: can_observe_timestamped_instance

import org.eclipse.leshan.core.response.ObserveResponse; //導入方法依賴的package包/類
@Test
public void can_observe_timestamped_instance() throws InterruptedException {
    TestObservationListener listener = new TestObservationListener();
    helper.server.getObservationService().addListener(listener);

    // observe device timezone
    ObserveResponse observeResponse = helper.server.send(helper.getCurrentRegistration(), new ObserveRequest(3, 0));
    assertEquals(ResponseCode.CONTENT, observeResponse.getCode());
    assertNotNull(observeResponse.getCoapResponse());
    assertThat(observeResponse.getCoapResponse(), is(instanceOf(Response.class)));

    // an observation response should have been sent
    Observation observation = observeResponse.getObservation();
    assertEquals("/3/0", observation.getPath().toString());
    assertEquals(helper.getCurrentRegistration().getId(), observation.getRegistrationId());
    Set<Observation> observations = helper.server.getObservationService()
            .getObservations(helper.getCurrentRegistration());
    assertTrue("We should have only on observation", observations.size() == 1);
    assertTrue("New observation is not there", observations.contains(observation));

    // *** HACK send time-stamped notification as Leshan client does not support it *** //
    // create time-stamped nodes
    TimestampedLwM2mNode mostRecentNode = new TimestampedLwM2mNode(System.currentTimeMillis(),
            new LwM2mObjectInstance(0, LwM2mSingleResource.newStringResource(15, "Paris")));
    List<TimestampedLwM2mNode> timestampedNodes = new ArrayList<>();
    timestampedNodes.add(mostRecentNode);
    timestampedNodes.add(new TimestampedLwM2mNode(mostRecentNode.getTimestamp() - 2,
            new LwM2mObjectInstance(0, LwM2mSingleResource.newStringResource(15, "Londres"))));
    byte[] payload = LwM2mNodeJsonEncoder.encodeTimestampedData(timestampedNodes, new LwM2mPath("/3/0"),
            new LwM2mModel(helper.createObjectModels()), new DefaultLwM2mValueConverter());
    Response firstCoapResponse = (Response) observeResponse.getCoapResponse();
    sendNotification(getConnector(helper.client), payload, firstCoapResponse, ContentFormat.JSON_CODE);
    // *** Hack End *** //

    // verify result
    listener.waitForNotification(2000);
    assertTrue(listener.receivedNotify().get());
    assertEquals(mostRecentNode.getNode(), listener.getResponse().getContent());
    assertEquals(timestampedNodes, listener.getResponse().getTimestampedLwM2mNode());
    assertNotNull(listener.getResponse().getCoapResponse());
    assertThat(listener.getResponse().getCoapResponse(), is(instanceOf(Response.class)));
}
 
開發者ID:eclipse,項目名稱:leshan,代碼行數:43,代碼來源:ObserveTest.java

示例7: can_observe_timestamped_object

import org.eclipse.leshan.core.response.ObserveResponse; //導入方法依賴的package包/類
@Test
public void can_observe_timestamped_object() throws InterruptedException {
    TestObservationListener listener = new TestObservationListener();
    helper.server.getObservationService().addListener(listener);

    // observe device timezone
    ObserveResponse observeResponse = helper.server.send(helper.getCurrentRegistration(), new ObserveRequest(3));
    assertEquals(ResponseCode.CONTENT, observeResponse.getCode());
    assertNotNull(observeResponse.getCoapResponse());
    assertThat(observeResponse.getCoapResponse(), is(instanceOf(Response.class)));

    // an observation response should have been sent
    Observation observation = observeResponse.getObservation();
    assertEquals("/3", observation.getPath().toString());
    assertEquals(helper.getCurrentRegistration().getId(), observation.getRegistrationId());
    Set<Observation> observations = helper.server.getObservationService()
            .getObservations(helper.getCurrentRegistration());
    assertTrue("We should have only on observation", observations.size() == 1);
    assertTrue("New observation is not there", observations.contains(observation));

    // *** HACK send time-stamped notification as Leshan client does not support it *** //
    // create time-stamped nodes
    TimestampedLwM2mNode mostRecentNode = new TimestampedLwM2mNode(System.currentTimeMillis(),
            new LwM2mObject(3, new LwM2mObjectInstance(0, LwM2mSingleResource.newStringResource(15, "Paris"))));
    List<TimestampedLwM2mNode> timestampedNodes = new ArrayList<>();
    timestampedNodes.add(mostRecentNode);
    timestampedNodes.add(new TimestampedLwM2mNode(mostRecentNode.getTimestamp() - 2,
            new LwM2mObject(3, new LwM2mObjectInstance(0, LwM2mSingleResource.newStringResource(15, "Londres")))));
    byte[] payload = LwM2mNodeJsonEncoder.encodeTimestampedData(timestampedNodes, new LwM2mPath("/3"),
            new LwM2mModel(helper.createObjectModels()), new DefaultLwM2mValueConverter());

    Response firstCoapResponse = (Response) observeResponse.getCoapResponse();
    sendNotification(getConnector(helper.client), payload, firstCoapResponse, ContentFormat.JSON_CODE);
    // *** Hack End *** //

    // verify result
    listener.waitForNotification(2000);
    assertTrue(listener.receivedNotify().get());
    assertEquals(mostRecentNode.getNode(), listener.getResponse().getContent());
    assertEquals(timestampedNodes, listener.getResponse().getTimestampedLwM2mNode());
    assertNotNull(listener.getResponse().getCoapResponse());
    assertThat(listener.getResponse().getCoapResponse(), is(instanceOf(Response.class)));
}
 
開發者ID:eclipse,項目名稱:leshan,代碼行數:44,代碼來源:ObserveTest.java


注:本文中的org.eclipse.leshan.core.response.ObserveResponse.getObservation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。