Commit ce6eb3778d8c5bd3e8ac54895c7c8ac1863494b9
1 parent
84a5fcce
Bug fixes with logging and gateway API
Showing
5 changed files
with
26 additions
and
20 deletions
... | ... | @@ -22,6 +22,7 @@ import io.jsonwebtoken.Claims; |
22 | 22 | import io.jsonwebtoken.Header; |
23 | 23 | import io.jsonwebtoken.Jwt; |
24 | 24 | import io.jsonwebtoken.Jwts; |
25 | +import lombok.extern.slf4j.Slf4j; | |
25 | 26 | import org.apache.commons.lang3.StringUtils; |
26 | 27 | import org.hamcrest.Matcher; |
27 | 28 | import org.junit.After; |
... | ... | @@ -85,6 +86,7 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppC |
85 | 86 | @ComponentScan({"org.thingsboard.server"}) |
86 | 87 | @WebAppConfiguration |
87 | 88 | @SpringBootTest |
89 | +@Slf4j | |
88 | 90 | public abstract class AbstractControllerTest { |
89 | 91 | |
90 | 92 | protected static final String TEST_TENANT_NAME = "TEST TENANT"; |
... | ... | @@ -130,6 +132,7 @@ public abstract class AbstractControllerTest { |
130 | 132 | |
131 | 133 | @Before |
132 | 134 | public void setup() throws Exception { |
135 | + log.info("Executing setup"); | |
133 | 136 | if (this.mockMvc == null) { |
134 | 137 | this.mockMvc = webAppContextSetup(webApplicationContext) |
135 | 138 | .apply(springSecurity()).build(); |
... | ... | @@ -163,13 +166,16 @@ public abstract class AbstractControllerTest { |
163 | 166 | createUserAndLogin(customerUser, CUSTOMER_USER_PASSWORD); |
164 | 167 | |
165 | 168 | logout(); |
169 | + log.info("Executed setup"); | |
166 | 170 | } |
167 | 171 | |
168 | 172 | @After |
169 | 173 | public void teardown() throws Exception { |
174 | + log.info("Executing teardown"); | |
170 | 175 | loginSysAdmin(); |
171 | 176 | doDelete("/api/tenant/"+tenantId.getId().toString()) |
172 | 177 | .andExpect(status().isOk()); |
178 | + log.info("Executed teardown"); | |
173 | 179 | } |
174 | 180 | |
175 | 181 | protected void loginSysAdmin() throws Exception { | ... | ... |
... | ... | @@ -15,19 +15,14 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.controller; |
17 | 17 | |
18 | -import static org.hamcrest.Matchers.containsString; | |
19 | -import static org.hamcrest.Matchers.is; | |
20 | -import static org.hamcrest.Matchers.notNullValue; | |
21 | -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | |
22 | -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | |
23 | -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | |
24 | - | |
25 | -import org.thingsboard.server.common.data.AdminSettings; | |
26 | -import org.junit.Test; | |
27 | - | |
28 | 18 | import com.fasterxml.jackson.databind.JsonNode; |
29 | -import com.fasterxml.jackson.databind.ObjectMapper; | |
30 | 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
20 | +import org.junit.Test; | |
21 | +import org.thingsboard.server.common.data.AdminSettings; | |
22 | + | |
23 | +import static org.hamcrest.Matchers.*; | |
24 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | |
25 | + | |
31 | 26 | |
32 | 27 | public abstract class BaseAdminControllerTest extends AbstractControllerTest { |
33 | 28 | ... | ... |
... | ... | @@ -7,8 +7,9 @@ |
7 | 7 | </encoder> |
8 | 8 | </appender> |
9 | 9 | |
10 | - <logger name="org.thingsboard.server" level="WARN"/> | |
10 | + <logger name="org.thingsboard.server" level="INFO"/> | |
11 | 11 | <logger name="org.springframework" level="WARN"/> |
12 | + <logger name="org.springframework.boot.test" level="DEBUG"/> | |
12 | 13 | <logger name="org.apache.cassandra" level="WARN"/> |
13 | 14 | <logger name="org.cassandraunit" level="INFO"/> |
14 | 15 | ... | ... |
... | ... | @@ -37,7 +37,7 @@ |
37 | 37 | <json-path.version>2.2.0</json-path.version> |
38 | 38 | <junit.version>4.12</junit.version> |
39 | 39 | <slf4j.version>1.7.7</slf4j.version> |
40 | - <logback.version>1.1.7</logback.version> | |
40 | + <logback.version>1.2.3</logback.version> | |
41 | 41 | <mockito.version>1.9.5</mockito.version> |
42 | 42 | <rat.version>0.10</rat.version> |
43 | 43 | <cassandra.version>3.0.0</cassandra.version> | ... | ... |
... | ... | @@ -55,6 +55,7 @@ import static org.thingsboard.server.transport.mqtt.adaptors.JsonMqttAdaptor.val |
55 | 55 | @Slf4j |
56 | 56 | public class GatewaySessionCtx { |
57 | 57 | |
58 | + private static final String DEFAULT_DEVICE_TYPE = "default"; | |
58 | 59 | private final Device gateway; |
59 | 60 | private final SessionId gatewaySessionId; |
60 | 61 | private final SessionMsgProcessor processor; |
... | ... | @@ -78,6 +79,11 @@ public class GatewaySessionCtx { |
78 | 79 | JsonElement json = getJson(msg); |
79 | 80 | String deviceName = checkDeviceName(getDeviceName(json)); |
80 | 81 | String deviceType = getDeviceType(json); |
82 | + onDeviceConnect(deviceName, deviceType); | |
83 | + ack(msg); | |
84 | + } | |
85 | + | |
86 | + private void onDeviceConnect(String deviceName, String deviceType) { | |
81 | 87 | if (!devices.containsKey(deviceName)) { |
82 | 88 | Optional<Device> deviceOpt = deviceService.findDeviceByTenantIdAndName(gateway.getTenantId(), deviceName); |
83 | 89 | Device device = deviceOpt.orElseGet(() -> { |
... | ... | @@ -95,7 +101,6 @@ public class GatewaySessionCtx { |
95 | 101 | processor.process(new BasicToDeviceActorSessionMsg(device, new BasicAdaptorToSessionActorMsg(ctx, new AttributesSubscribeMsg()))); |
96 | 102 | processor.process(new BasicToDeviceActorSessionMsg(device, new BasicAdaptorToSessionActorMsg(ctx, new RpcSubscribeMsg()))); |
97 | 103 | } |
98 | - ack(msg); | |
99 | 104 | } |
100 | 105 | |
101 | 106 | public void onDeviceDisconnect(MqttPublishMessage msg) throws AdaptorException { |
... | ... | @@ -205,10 +210,9 @@ public class GatewaySessionCtx { |
205 | 210 | private String checkDeviceConnected(String deviceName) { |
206 | 211 | if (!devices.containsKey(deviceName)) { |
207 | 212 | log.debug("[{}] Missing device [{}] for the gateway session", gatewaySessionId, deviceName); |
208 | - throw new RuntimeException("Device " + deviceName + " is not connected!"); | |
209 | - } else { | |
210 | - return deviceName; | |
213 | + onDeviceConnect(deviceName, DEFAULT_DEVICE_TYPE); | |
211 | 214 | } |
215 | + return deviceName; | |
212 | 216 | } |
213 | 217 | |
214 | 218 | private String checkDeviceName(String deviceName) { |
... | ... | @@ -225,7 +229,7 @@ public class GatewaySessionCtx { |
225 | 229 | |
226 | 230 | private String getDeviceType(JsonElement json) throws AdaptorException { |
227 | 231 | JsonElement type = json.getAsJsonObject().get("type"); |
228 | - return type == null ? "default" : type.getAsString(); | |
232 | + return type == null ? DEFAULT_DEVICE_TYPE : type.getAsString(); | |
229 | 233 | } |
230 | 234 | |
231 | 235 | private JsonElement getJson(MqttPublishMessage mqttMsg) throws AdaptorException { |
... | ... | @@ -236,7 +240,7 @@ public class GatewaySessionCtx { |
236 | 240 | return processor; |
237 | 241 | } |
238 | 242 | |
239 | - protected DeviceAuthService getAuthService() { | |
243 | + DeviceAuthService getAuthService() { | |
240 | 244 | return authService; |
241 | 245 | } |
242 | 246 | |
... | ... | @@ -250,7 +254,7 @@ public class GatewaySessionCtx { |
250 | 254 | } |
251 | 255 | } |
252 | 256 | |
253 | - protected void writeAndFlush(MqttMessage mqttMessage) { | |
257 | + void writeAndFlush(MqttMessage mqttMessage) { | |
254 | 258 | channel.writeAndFlush(mqttMessage); |
255 | 259 | } |
256 | 260 | ... | ... |