Skip to content

Commit

Permalink
refactor: removed republish birth on modem detect option
Browse files Browse the repository at this point in the history
Signed-off-by: Marcello Martina <[email protected]>
  • Loading branch information
marcellorinaldo committed Aug 12, 2024
1 parent 4b14ce2 commit cb5b105
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,7 @@
required="true"
default="false"
description="Whether or not to republish the MQTT Birth Certificate on GPS lock event"/>

<AD id="republish.mqtt.birth.cert.on.modem.detect"
name="Republish Mqtt Birth Cert On Modem Detect"
type="Boolean"
cardinality="0"
required="true"
default="false"
description="Whether or not to republish the MQTT Birth Certificate on modem detection event. This functionality is currently not supported on devices configured to use NetworkManager, in this case the property value is ignored."/>"/>


<AD id="payload.encoding"
name="Payload Encoding"
type="String"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public class CloudConnectionManagerOptions {
private static final String DEVICE_CUSTOM_NAME = "device.custom-name";
private static final String ENCODE_GZIP = "encode.gzip";
private static final String REPUB_BIRTH_ON_GPS_LOCK = "republish.mqtt.birth.cert.on.gps.lock";
private static final String REPUB_BIRTH_ON_MODEM_DETECT = "republish.mqtt.birth.cert.on.modem.detect";
private static final String PAYLOAD_ENCODING = "payload.encoding";

private static final int LIFECYCLE_QOS = 1;
Expand Down Expand Up @@ -113,22 +112,6 @@ public boolean getRepubBirthCertOnGpsLock() {
return repubBirth;
}

/**
* Returns true if the current CloudService configuration
* specifies the cloud client should republish the MQTT birth
* certificate on modem detection events.
*
* @return a boolean value.
*/
public boolean getRepubBirthCertOnModemDetection() {
boolean repubBirth = false;
if (this.properties != null && this.properties.get(REPUB_BIRTH_ON_MODEM_DETECT) != null
&& this.properties.get(REPUB_BIRTH_ON_MODEM_DETECT) instanceof Boolean) {
repubBirth = (Boolean) this.properties.get(REPUB_BIRTH_ON_MODEM_DETECT);
}
return repubBirth;
}

/**
* This method parses the Cloud Service configuration and returns the selected cloud payload encoding.
* By default, this method returns {@link CloudPayloadEncoding} {@code KURA_PROTOBUF}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,7 @@
required="true"
default="false"
description="Whether or not to republish the MQTT Birth Certificate on GPS lock event"/>

<AD id="republish.mqtt.birth.cert.on.modem.detect"
name="Republish Mqtt Birth Cert On Modem Detect"
type="Boolean"
cardinality="0"
required="true"
default="false"
description="Whether or not to republish the MQTT Birth Certificate on modem detection event. This functionality is currently not supported on devices configured to use NetworkManager, in this case the property value is ignored."/>


<AD id="republish.mqtt.birth.cert.on.tamper.event"
name="Republish Mqtt Birth Cert On Tamper Event"
type="Boolean"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2023 Eurotech and/or its affiliates and others
* Copyright (c) 2011, 2024 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -37,7 +37,6 @@ public class CloudServiceOptions {
private static final String DEVICE_CUSTOM_NAME = "device.custom-name";
private static final String ENCODE_GZIP = "encode.gzip";
private static final String REPUB_BIRTH_ON_GPS_LOCK = "republish.mqtt.birth.cert.on.gps.lock";
private static final String REPUB_BIRTH_ON_MODEM_DETECT = "republish.mqtt.birth.cert.on.modem.detect";
private static final String REPUB_BIRTH_ON_TAMPER_EVENT = "republish.mqtt.birth.cert.on.tamper.event";
private static final String ENABLE_DFLT_SUBSCRIPTIONS = "enable.default.subscriptions";
private static final String PAYLOAD_ENCODING = "payload.encoding";
Expand Down Expand Up @@ -116,21 +115,6 @@ public boolean getRepubBirthCertOnGpsLock() {
return repubBirth;
}

/**
* Returns true if the current CloudService configuration
* specifies the cloud client should republish the MQTT birth
* certificate on modem detection events.
*
* @return a boolean value.
*/
public boolean getRepubBirthCertOnModemDetection() {
boolean repubBirth = false;
if (this.properties != null && this.properties.get(REPUB_BIRTH_ON_MODEM_DETECT) instanceof Boolean) {
repubBirth = (Boolean) this.properties.get(REPUB_BIRTH_ON_MODEM_DETECT);
}
return repubBirth;
}

public boolean getRepubBirthCertOnTamperEvent() {
boolean repubBirth = true;
if (this.properties != null && this.properties.get(REPUB_BIRTH_ON_TAMPER_EVENT) instanceof Boolean) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018, 2023 Eurotech and/or its affiliates and others
* Copyright (c) 2018, 2024 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -37,7 +37,6 @@ public class CloudServiceOptionsTest {
private static final String DEVICE_CUSTOM_NAME = "device.custom-name";
private static final String ENCODE_GZIP = "encode.gzip";
private static final String REPUB_BIRTH_ON_GPS_LOCK = "republish.mqtt.birth.cert.on.gps.lock";
private static final String REPUB_BIRTH_ON_MODEM_DETECT = "republish.mqtt.birth.cert.on.modem.detect";
private static final String ENABLE_DFLT_SUBSCRIPTIONS = "enable.default.subscriptions";
private static final String PAYLOAD_ENCODING = "payload.encoding";

Expand All @@ -52,7 +51,6 @@ public static void testSetup() {
properties.put(DEVICE_DISPLAY_NAME, "device-name");
properties.put(ENCODE_GZIP, true);
properties.put(REPUB_BIRTH_ON_GPS_LOCK, true);
properties.put(REPUB_BIRTH_ON_MODEM_DETECT, true);
properties.put(TOPIC_CONTROL_PREFIX, TEST_TOPIC_CONTROL_PREFIX);
properties.put(ENABLE_DFLT_SUBSCRIPTIONS, false);
properties.put(PAYLOAD_ENCODING, "simple-json");
Expand Down Expand Up @@ -248,46 +246,6 @@ public void testGetRepubBirthCertOnGpsLock() {
assertTrue(republish);
}

@Test
public void testGetRepubBirthCertOnModemDetectionNullProps() {
CloudServiceOptions options = new CloudServiceOptions(null, systemService);

boolean republish = options.getRepubBirthCertOnModemDetection();

assertFalse(republish);
}

@Test
public void testGetRepubBirthCertOnModemDetectionPropNull() {
Map<String, Object> properties = new HashMap<>();

CloudServiceOptions options = new CloudServiceOptions(properties, systemService);

boolean republish = options.getRepubBirthCertOnModemDetection();

assertFalse(republish);
}

@Test
public void testGetRepubBirthCertOnModemDetectionPropNotBoolean() {
Map<String, Object> properties = new HashMap<>();
properties.put(REPUB_BIRTH_ON_MODEM_DETECT, "invalid");

CloudServiceOptions options = new CloudServiceOptions(properties, systemService);

boolean republish = options.getRepubBirthCertOnModemDetection();

assertFalse(republish);
}

@Test
public void testGetRepubBirthCertOnModemDetection() {

boolean republish = options.getRepubBirthCertOnModemDetection();

assertTrue(republish);
}

@Test
public void testGetTopicControlPrefixNullProps() {
CloudServiceOptions options = new CloudServiceOptions(null, systemService);
Expand Down

0 comments on commit cb5b105

Please sign in to comment.