Skip to content

Commit

Permalink
Add test about CoreLink SingleResource and ResourceInstance equals
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Nov 9, 2023
1 parent c87d1e0 commit 5b5aa70
Showing 1 changed file with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@
import java.util.HashMap;
import java.util.Map;

import org.eclipse.leshan.core.link.DefaultLinkParser;
import org.eclipse.leshan.core.link.Link;
import org.eclipse.leshan.core.link.LinkParseException;
import org.eclipse.leshan.core.link.LinkParser;
import org.eclipse.leshan.core.model.ResourceModel.Type;
import org.junit.jupiter.api.Test;

public class LwM2MResourceTest {

private final LinkParser linkParser = new DefaultLinkParser();

@Test
public void two_identical_strings_are_equal() {
assertEquals(LwM2mSingleResource.newStringResource(10, "hello"),
Expand Down Expand Up @@ -55,6 +61,36 @@ public void two_non_identical_opaques_are_not_equal() {
LwM2mSingleResource.newBinaryResource(10, "hello".getBytes()));
}

@Test
public void two_identical_corelink_are_equal() throws LinkParseException {
assertEquals(
LwM2mSingleResource.newCoreLinkResource(10, linkParser.parseCoreLinkFormat(
"</>;rt=\"oma.lwm2m\";ct=\"60 110 112 1542 1543 11542 11543\",</1/0>,</2>,</3/0>,</3442/0>"
.getBytes())),
LwM2mSingleResource.newCoreLinkResource(10, linkParser.parseCoreLinkFormat(
"</>;rt=\"oma.lwm2m\";ct=\"60 110 112 1542 1543 11542 11543\",</1/0>,</2>,</3/0>,</3442/0>"
.getBytes())));
}

@Test
public void two_non_identical_corelink_are_not_equal() throws LinkParseException {
assertNotEquals(
LwM2mSingleResource.newCoreLinkResource(10, linkParser.parseCoreLinkFormat(
"</>;rt=\"oma.lwm2m\";ct=\"60 110 112 1542 1543 11542 11543\",</1/0>,</2>,</3/0>,</3442/0>"
.getBytes())),
LwM2mSingleResource.newCoreLinkResource(10, linkParser.parseCoreLinkFormat(
"</>;rt=\"oma.lwm2m\";ct=\"60 110 112 1542 1543 11542 11543\",</1/0>,</2>,</3/0>,</3333/0>"
.getBytes())));

assertNotEquals(
LwM2mSingleResource.newCoreLinkResource(11, linkParser.parseCoreLinkFormat(
"</>;rt=\"oma.lwm2m\";ct=\"60 110 112 1542 1543 11542 11543\",</1/0>,</2>,</3/0>,</3442/0>"
.getBytes())),
LwM2mSingleResource.newCoreLinkResource(10, linkParser.parseCoreLinkFormat(
"</>;rt=\"oma.lwm2m\";ct=\"60 110 112 1542 1543 11542 11543\",</1/0>,</2>,</3/0>,</3442/0>"
.getBytes())));
}

@Test
public void two_string_and_binary_are_not_equal() {
assertNotEquals(LwM2mSingleResource.newStringResource(10, "hello"),
Expand Down Expand Up @@ -109,6 +145,42 @@ public void two_non_identical_multiple_opaques_are_not_equal() {
LwM2mMultipleResource.newBinaryResource(10, values1));
}

@Test
public void two_identical_multiple_corelink_are_equal() throws LinkParseException {
Map<Integer, Link[]> values1 = new HashMap<>();
values1.put(0,
linkParser.parseCoreLinkFormat(
"</>;rt=\"oma.lwm2m\";ct=\"60 110 112 1542 1543 11542 11543\",</1/0>,</2>,</3/0>,</3442/0>"
.getBytes()));
Map<Integer, Link[]> values2 = new HashMap<>();
values2.put(0,
linkParser.parseCoreLinkFormat(
"</>;rt=\"oma.lwm2m\";ct=\"60 110 112 1542 1543 11542 11543\",</1/0>,</2>,</3/0>,</3442/0>"
.getBytes()));

assertEquals(LwM2mMultipleResource.newCoreLinkResource(10, values1),
LwM2mMultipleResource.newCoreLinkResource(10, values2));
}

@Test
public void two_non_identical_multiple_corelink_are_not_equal() throws LinkParseException {
Map<Integer, Link[]> values1 = new HashMap<>();
values1.put(0,
linkParser.parseCoreLinkFormat(
"</>;rt=\"oma.lwm2m\";ct=\"60 110 112 1542 1543 11542 11543\",</1/0>,</2>,</3/0>,</3442/0>"
.getBytes()));
Map<Integer, Link[]> values2 = new HashMap<>();
values2.put(0,
linkParser.parseCoreLinkFormat(
"</>;rt=\"oma.lwm2m\";ct=\"60 110 112 1542 1543 11542 11543\",</1/0>,</2>,</3/0>,</3333/0>"
.getBytes()));

assertNotEquals(LwM2mMultipleResource.newCoreLinkResource(10, values1),
LwM2mMultipleResource.newCoreLinkResource(10, values2));
assertNotEquals(LwM2mMultipleResource.newCoreLinkResource(11, values1),
LwM2mMultipleResource.newCoreLinkResource(10, values1));
}

@Test
public void two_multiple_string_and_multiple_binary_are_not_equal() {
Map<Integer, String> values1 = new HashMap<>();
Expand Down

0 comments on commit 5b5aa70

Please sign in to comment.