Skip to content

Commit 1c2c36a

Browse files
authored
Merge pull request #12 from emnify/endpoint-creation-allow-passing-activate
fix: Allow passing "activate" on endpoint creation
2 parents a298eb5 + 9e39ee7 commit 1c2c36a

2 files changed

Lines changed: 52 additions & 2 deletions

File tree

api/src/main/java/com/emnify/sdk/model/Sim.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public class Sim {
5353
@SerializedName(SERIALIZED_NAME_IMSI)
5454
private String imsi;
5555

56+
public static final String SERIALIZED_NAME_ACTIVATE = "activate";
57+
@SerializedName(SERIALIZED_NAME_ACTIVATE)
58+
private Boolean activate;
59+
5660

5761
public Sim id(Integer id) {
5862

@@ -145,6 +149,29 @@ public void setImsi(String imsi) {
145149
}
146150

147151

152+
public Sim activate(Boolean activate) {
153+
154+
this.activate = activate;
155+
return this;
156+
}
157+
158+
/**
159+
* Whether the SIM is activated when it is assigned to the endpoint. Defaults to true server-side, so pass false to assign the SIM without activating it. Left null the property is omitted from the request.
160+
* @return activate
161+
**/
162+
@javax.annotation.Nullable
163+
@ApiModelProperty(value = "Whether the SIM is activated when it is assigned to the endpoint. Defaults to true server-side, so pass false to assign the SIM without activating it.")
164+
165+
public Boolean getActivate() {
166+
return activate;
167+
}
168+
169+
170+
public void setActivate(Boolean activate) {
171+
this.activate = activate;
172+
}
173+
174+
148175
@Override
149176
public boolean equals(Object o) {
150177
if (this == o) {
@@ -157,12 +184,13 @@ public boolean equals(Object o) {
157184
return Objects.equals(this.id, sim.id) &&
158185
Objects.equals(this.iccid, sim.iccid) &&
159186
Objects.equals(this.msisdn, sim.msisdn) &&
160-
Objects.equals(this.imsi, sim.imsi);
187+
Objects.equals(this.imsi, sim.imsi) &&
188+
Objects.equals(this.activate, sim.activate);
161189
}
162190

163191
@Override
164192
public int hashCode() {
165-
return Objects.hash(id, iccid, msisdn, imsi);
193+
return Objects.hash(id, iccid, msisdn, imsi, activate);
166194
}
167195

168196
@Override
@@ -173,6 +201,7 @@ public String toString() {
173201
sb.append(" iccid: ").append(toIndentedString(iccid)).append("\n");
174202
sb.append(" msisdn: ").append(toIndentedString(msisdn)).append("\n");
175203
sb.append(" imsi: ").append(toIndentedString(imsi)).append("\n");
204+
sb.append(" activate: ").append(toIndentedString(activate)).append("\n");
176205
sb.append("}");
177206
return sb.toString();
178207
}

api/src/test/java/com/emnify/sdk/model/SimTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
package com.emnify.sdk.model;
2323

24+
import com.emnify.sdk.JSON;
25+
import com.google.gson.Gson;
2426
import com.google.gson.TypeAdapter;
2527
import com.google.gson.annotations.JsonAdapter;
2628
import com.google.gson.annotations.SerializedName;
@@ -80,4 +82,23 @@ public void imsiTest() {
8082
// TODO: test imsi
8183
}
8284

85+
/**
86+
* Test that the property 'activate' reaches the request body.
87+
*
88+
* The API activates an assigned SIM by default, so a client that cannot
89+
* send activate=false cannot assign a SIM without activating (and billing)
90+
* it. Serialization goes through the same Gson instance ApiClient uses.
91+
*/
92+
@Test
93+
public void activateIsSerializedTest() {
94+
Gson gson = JSON.createGson().create();
95+
96+
Assert.assertEquals("{\"id\":250,\"activate\":false}",
97+
gson.toJson(new Sim().id(250).activate(false)));
98+
Assert.assertEquals("{\"id\":250,\"activate\":true}",
99+
gson.toJson(new Sim().id(250).activate(true)));
100+
// left unset the property is omitted, so the API default applies
101+
Assert.assertEquals("{\"id\":250}", gson.toJson(new Sim().id(250)));
102+
}
103+
83104
}

0 commit comments

Comments
 (0)