Skip to content

Commit

Permalink
Add some test about LwM2mObservationStore.remove()
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Jan 26, 2023
1 parent 233c209 commit dbe5aa2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Expand Up @@ -18,6 +18,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.net.InetAddress;
Expand Down Expand Up @@ -159,6 +160,24 @@ public void get_composite_observation_from_request() {
assertEquals(examplePaths, observation.getPaths());
}

@Test
public void remove_observation() {
// given
givenASimpleRegistration(lifetime);
store.addRegistration(registration);

org.eclipse.californium.core.observe.Observation observationToStore = prepareCoapObservationOnSingle("/1/2/3");
observationStore.put(aToken, observationToStore);

// when
observationStore.remove(aToken);

// then
Observation leshanObservation = store.getObservation(registrationId,
new ObservationIdentifier(aToken.getBytes()));
assertNull(leshanObservation);
}

private void givenASimpleRegistration(Long lifetime) {
Registration.Builder builder = new Registration.Builder(registrationId, ep, Identity.unsecure(address, port),
EndpointUriUtil.createUri("coap://localhost:5683"));
Expand Down
Expand Up @@ -17,6 +17,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.net.InetAddress;
Expand Down Expand Up @@ -159,6 +160,24 @@ public void get_composite_observation_from_request() {
assertEquals(examplePaths, observation.getPaths());
}

@Test
public void remove_observation() {
// given
givenASimpleRegistration(lifetime);
store.addRegistration(registration);

org.eclipse.californium.core.observe.Observation observationToStore = prepareCoapCompositeObservation();
observationStore.put(exampleToken, observationToStore);

// when
observationStore.remove(exampleToken);

// then
Observation leshanObservation = store.getObservation(registrationId,
new ObservationIdentifier(exampleToken.getBytes()));
assertNull(leshanObservation);
}

private org.eclipse.californium.core.observe.Observation prepareCoapObservation() {
ObserveRequest observeRequest = new ObserveRequest(null, examplePath);

Expand Down

0 comments on commit dbe5aa2

Please sign in to comment.