Skip to content

Commit

Permalink
Use LwM2m Test Object (3442) in our test (instead of home made one)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed May 31, 2022
1 parent faec24d commit 491a51c
Show file tree
Hide file tree
Showing 25 changed files with 897 additions and 223 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@
public class LwM2mTestObject extends SimpleInstanceEnabler {
private static final Logger LOG = LoggerFactory.getLogger(LwM2mTestObject.class);

public static final String INITIAL_STRING_VALUE = "initial value";
public static final Long INITIAL_INTEGER_VALUE = 64l;
public static final ULong INITIAL_UNSIGNED_INTEGER_VALUE = ULong.valueOf("9223372036854775808");
public static final Double INITIAL_FLOAT_VALUE = 3.14159d;
public static final Boolean INITIAL_BOOLEAN_VALUE = true;
public static final byte[] INITIAL_OPAQUE_VALUE = Hex.decodeHex("0123456789ABCDEF".toCharArray());
public static final Date INITIAL_TIME_VALUE = new Date(946684800000l);
public static final ObjectLink INITIAL_OBJLINK_VALUE = new ObjectLink(3, 0);

private Random random = new Random(System.currentTimeMillis());

public LwM2mTestObject() {
Expand All @@ -59,26 +68,24 @@ public LwM2mTestObject() {
initialValues.put(6, Collections.EMPTY_MAP);

// single
initialValues.put(110, "initial value");
initialValues.put(120, 64l);
initialValues.put(125, ULong.valueOf("9223372036854775808"));
initialValues.put(130, 3.14159d);
initialValues.put(140, true);
initialValues.put(150, Hex.decodeHex("0123456789ABCDEF".toCharArray()));
initialValues.put(160, new Date(946684800000l));
initialValues.put(170, new ObjectLink(3, 0));
initialValues.put(110, INITIAL_STRING_VALUE);
initialValues.put(120, INITIAL_INTEGER_VALUE);
initialValues.put(125, INITIAL_UNSIGNED_INTEGER_VALUE);
initialValues.put(130, INITIAL_FLOAT_VALUE);
initialValues.put(140, INITIAL_BOOLEAN_VALUE);
initialValues.put(150, INITIAL_OPAQUE_VALUE);
initialValues.put(160, INITIAL_TIME_VALUE);
initialValues.put(170, INITIAL_OBJLINK_VALUE);

// multi
initialValues.put(1110, LwM2mResourceInstance.newStringInstance(0, "initial value"));
initialValues.put(1120, LwM2mResourceInstance.newIntegerInstance(0, 64l));
initialValues.put(1125,
LwM2mResourceInstance.newUnsignedIntegerInstance(0, ULong.valueOf("9223372036854775808")));
initialValues.put(1130, LwM2mResourceInstance.newFloatInstance(0, 3.14159d));
initialValues.put(1140, LwM2mResourceInstance.newBooleanInstance(0, true));
initialValues.put(1150,
LwM2mResourceInstance.newBinaryInstance(0, Hex.decodeHex("0123456789ABCDEF".toCharArray())));
initialValues.put(1160, LwM2mResourceInstance.newDateInstance(0, new Date(946684800000l)));
initialValues.put(1170, LwM2mResourceInstance.newObjectLinkInstance(0, new ObjectLink(3, 0)));
initialValues.put(1110, LwM2mResourceInstance.newStringInstance(0, INITIAL_STRING_VALUE));
initialValues.put(1120, LwM2mResourceInstance.newIntegerInstance(0, INITIAL_INTEGER_VALUE));
initialValues.put(1125, LwM2mResourceInstance.newUnsignedIntegerInstance(0, INITIAL_UNSIGNED_INTEGER_VALUE));
initialValues.put(1130, LwM2mResourceInstance.newFloatInstance(0, INITIAL_FLOAT_VALUE));
initialValues.put(1140, LwM2mResourceInstance.newBooleanInstance(0, INITIAL_BOOLEAN_VALUE));
initialValues.put(1150, LwM2mResourceInstance.newBinaryInstance(0, INITIAL_OPAQUE_VALUE));
initialValues.put(1160, LwM2mResourceInstance.newDateInstance(0, INITIAL_TIME_VALUE));
initialValues.put(1170, LwM2mResourceInstance.newObjectLinkInstance(0, INITIAL_OBJLINK_VALUE));
}

private void clearValues() {
Expand Down
11 changes: 11 additions & 0 deletions leshan-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ Contributors:
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<!-- some test code is reused in integration-tests -->
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public interface LwM2mId {
public static final int SRV_LIFETIME = 1;
public static final int SRV_BINDING = 7;

/* ACCESS CONTROL RESOURCES */
public static final int ACL_OBJECT_ID = 0;
public static final int ACL_OBJECT_INSTANCE_ID = 1;
public static final int ACL_ACL = 2;
public static final int ACL_ACCESS_CONTROL_OWNER = 3;

/* DEVICE RESOURCES */

public static final int DVC_SUPPORTED_BINDING = 16;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.io.IOException;

import org.eclipse.leshan.core.util.TestObjectLoader;
import org.junit.Test;

public class ValidateModelsTest {
Expand All @@ -25,4 +26,9 @@ public class ValidateModelsTest {
public void validate_embedded_models() throws InvalidModelException, InvalidDDFFileException, IOException {
ObjectLoader.loadDdfResources("/models/", ObjectLoader.ddfpaths, true);
}

@Test
public void validate_test_models() throws InvalidModelException, InvalidDDFFileException, IOException {
ObjectLoader.loadDdfResources("/models/", TestObjectLoader.ddfpaths, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import org.eclipse.leshan.core.json.LwM2mJsonException;
import org.eclipse.leshan.core.model.LwM2mModel;
import org.eclipse.leshan.core.model.ObjectLoader;
import org.eclipse.leshan.core.model.ObjectModel;
import org.eclipse.leshan.core.model.ResourceModel;
import org.eclipse.leshan.core.model.ResourceModel.Operations;
Expand All @@ -50,6 +49,7 @@
import org.eclipse.leshan.core.tlv.Tlv.TlvType;
import org.eclipse.leshan.core.tlv.TlvEncoder;
import org.eclipse.leshan.core.util.Hex;
import org.eclipse.leshan.core.util.TestObjectLoader;
import org.eclipse.leshan.core.util.datatype.ULong;
import org.junit.Assert;
import org.junit.BeforeClass;
Expand All @@ -66,7 +66,7 @@ public class LwM2mNodeDecoderTest {
@BeforeClass
public static void loadModel() {
// load default object
List<ObjectModel> objects = ObjectLoader.loadDefault();
List<ObjectModel> objects = TestObjectLoader.loadAllDefault();

// add object 65 from the LWM2M v1.0.1 specification (figure 28)
List<ResourceModel> resForObj65 = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*******************************************************************************
* Copyright (c) 2022 Sierra Wireless and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v20.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.html.
*
* Contributors:
* Sierra Wireless - initial API and implementation
*******************************************************************************/
package org.eclipse.leshan.core.util;

public interface TestLwM2mId {
static final int TEST_OBJECT = 3442;

/* TEST RESOURCES */
static final int RESET_VALUES = 0;
static final int RANDOMIZE_VALUES = 1;
static final int CLEAR_VALUES = 2;

static final int STRING_VALUE = 110;
static final int INTEGER_VALUE = 120;
static final int UNSIGNED_INTEGER_VALUE = 125;
static final int FLOAT_VALUE = 130;
static final int BOOLEAN_VALUE = 140;
static final int OPAQUE_VALUE = 150;
static final int TIME_VALUE = 160;
static final int OBJLINK_VALUE = 170;
static final int CORELNK_VALUE = 180;

static final int MULTIPLE_STRING_VALUE = 1110;
static final int MULTIPLE_INTEGER_VALUE = 1120;
static final int MULTIPLE_UNSIGNED_INTEGER_VALUE = 1125;
static final int MULTIPLE_FLOAT_VALUE = 1130;
static final int MULTIPLE_BOOLEAN_VALUE = 1140;
static final int MULTIPLE_OPAQUE_VALUE = 1150;
static final int MULTIPLE_TIME_VALUE = 1160;
static final int MULTIPLE_OBJLINK_VALUE = 1170;
static final int MULTIPLE_CORELNK_VALUE = 1180;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (c) 2022 Sierra Wireless and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v20.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.html.
*
* Contributors:
* Sierra Wireless - initial API and implementation
*******************************************************************************/
package org.eclipse.leshan.core.util;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.leshan.core.model.ObjectLoader;
import org.eclipse.leshan.core.model.ObjectModel;

public class TestObjectLoader {

public static final String[] ddfpaths = new String[] { "3441.xml", "3442.xml" };

public static List<ObjectModel> loadAllDefault() {
List<ObjectModel> result = new ArrayList<>();
try {
// add default models
result.addAll(ObjectLoader.loadAllDefault());
// add test models
result.addAll(ObjectLoader.loadDdfResources("/models/", ddfpaths));
} catch (Exception e) {
throw new IllegalStateException("Unable to load models", e);
}
return result;
}
}
Loading

0 comments on commit 491a51c

Please sign in to comment.