tests: Coap client destroy on processAfterTest at AbstractCoapIntegrationTest
This commit is contained in:
parent
ac2844b51f
commit
9ee0d87687
@ -52,6 +52,16 @@ import static org.junit.Assert.assertNotNull;
|
||||
@Slf4j
|
||||
public abstract class AbstractCoapIntegrationTest extends AbstractTransportIntegrationTest {
|
||||
|
||||
protected CoapClient client;
|
||||
|
||||
@Override
|
||||
protected void processAfterTest() throws Exception {
|
||||
if (client != null) {
|
||||
client.shutdown();
|
||||
}
|
||||
super.processAfterTest();
|
||||
}
|
||||
|
||||
protected void processBeforeTest(String deviceName, CoapDeviceType coapDeviceType, TransportPayloadType payloadType) throws Exception {
|
||||
this.processBeforeTest(deviceName, coapDeviceType, payloadType, null, null, null, null, null, null, DeviceProfileProvisionType.DISABLED);
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ public abstract class AbstractCoapAttributesRequestIntegrationTest extends Abstr
|
||||
|
||||
String keys = "attribute1,attribute2,attribute3,attribute4,attribute5";
|
||||
String featureTokenUrl = getFeatureTokenUrl(accessToken, FeatureType.ATTRIBUTES) + "?clientKeys=" + keys + "&sharedKeys=" + keys;
|
||||
CoapClient client = getCoapClient(featureTokenUrl);
|
||||
client = getCoapClient(featureTokenUrl);
|
||||
|
||||
CoapResponse getAttributesResponse = client.setTimeout(CLIENT_REQUEST_TIMEOUT).get();
|
||||
validateResponse(getAttributesResponse);
|
||||
@ -83,7 +83,7 @@ public abstract class AbstractCoapAttributesRequestIntegrationTest extends Abstr
|
||||
|
||||
protected void postAttributes() throws Exception {
|
||||
doPostAsync("/api/plugins/telemetry/DEVICE/" + savedDevice.getId().getId() + "/attributes/SHARED_SCOPE", POST_ATTRIBUTES_PAYLOAD, String.class, status().isOk());
|
||||
CoapClient client = getCoapClient(FeatureType.ATTRIBUTES);
|
||||
client = getCoapClient(FeatureType.ATTRIBUTES);
|
||||
CoapResponse coapResponse = client.setTimeout(CLIENT_REQUEST_TIMEOUT).post(POST_ATTRIBUTES_PAYLOAD.getBytes(), MediaTypeRegistry.APPLICATION_JSON);
|
||||
assertEquals(CoAP.ResponseCode.CREATED, coapResponse.getCode());
|
||||
}
|
||||
|
||||
@ -21,7 +21,6 @@ import com.google.protobuf.DynamicMessage;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import com.squareup.wire.schema.internal.parser.ProtoFileElement;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.californium.core.CoapClient;
|
||||
import org.eclipse.californium.core.CoapResponse;
|
||||
import org.eclipse.californium.core.coap.CoAP;
|
||||
import org.eclipse.californium.core.coap.MediaTypeRegistry;
|
||||
@ -124,7 +123,7 @@ public abstract class AbstractCoapAttributesRequestProtoIntegrationTest extends
|
||||
.setField(postAttributesMsgDescriptor.findFieldByName("attribute5"), jsonObject)
|
||||
.build();
|
||||
byte[] payload = postAttributesMsg.toByteArray();
|
||||
CoapClient client = getCoapClient(FeatureType.ATTRIBUTES);
|
||||
client = getCoapClient(FeatureType.ATTRIBUTES);
|
||||
CoapResponse coapResponse = client.setTimeout(CLIENT_REQUEST_TIMEOUT).post(payload, MediaTypeRegistry.APPLICATION_JSON);
|
||||
assertEquals(CoAP.ResponseCode.CREATED, coapResponse.getCode());
|
||||
}
|
||||
|
||||
@ -71,7 +71,7 @@ public abstract class AbstractCoapAttributesUpdatesIntegrationTest extends Abstr
|
||||
if (!emptyCurrentStateNotification) {
|
||||
doPostAsync("/api/plugins/telemetry/DEVICE/" + savedDevice.getId().getId() + "/attributes/SHARED_SCOPE", POST_ATTRIBUTES_PAYLOAD_ON_CURRENT_STATE_NOTIFICATION, String.class, status().isOk());
|
||||
}
|
||||
CoapClient client = getCoapClient(FeatureType.ATTRIBUTES);
|
||||
client = getCoapClient(FeatureType.ATTRIBUTES);
|
||||
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
TestCoapCallback callback = new TestCoapCallback(latch);
|
||||
|
||||
@ -90,7 +90,7 @@ public abstract class AbstractCoapClaimDeviceTest extends AbstractCoapIntegratio
|
||||
|
||||
protected void processTestClaimingDevice(boolean emptyPayload) throws Exception {
|
||||
log.warn("[testClaimingDevice] Device: {}, Transport type: {}", savedDevice.getName(), savedDevice.getType());
|
||||
CoapClient client = getCoapClient(FeatureType.CLAIM);
|
||||
client = getCoapClient(FeatureType.CLAIM);
|
||||
byte[] payloadBytes;
|
||||
byte[] failurePayloadBytes;
|
||||
if (emptyPayload) {
|
||||
|
||||
@ -49,7 +49,7 @@ public abstract class AbstractCoapClaimProtoDeviceTest extends AbstractCoapClaim
|
||||
|
||||
@Override
|
||||
protected void processTestClaimingDevice(boolean emptyPayload) throws Exception {
|
||||
CoapClient client = getCoapClient(FeatureType.CLAIM);
|
||||
client = getCoapClient(FeatureType.CLAIM);
|
||||
byte[] payloadBytes;
|
||||
if (emptyPayload) {
|
||||
TransportApiProtos.ClaimDevice claimDevice = getClaimDevice(0, emptyPayload);
|
||||
|
||||
@ -180,7 +180,7 @@ public abstract class AbstractCoapProvisionJsonDeviceTest extends AbstractCoapIn
|
||||
|
||||
private CoapResponse createCoapClientAndPublish(String deviceCredentials) throws Exception {
|
||||
String provisionRequestMsg = createTestProvisionMessage(deviceCredentials);
|
||||
CoapClient client = getCoapClient(FeatureType.PROVISION);
|
||||
client = getCoapClient(FeatureType.PROVISION);
|
||||
return postProvision(client, provisionRequestMsg.getBytes());
|
||||
}
|
||||
|
||||
|
||||
@ -176,7 +176,7 @@ public abstract class AbstractCoapProvisionProtoDeviceTest extends AbstractCoapI
|
||||
}
|
||||
|
||||
private CoapResponse createCoapClientAndPublish(byte[] provisionRequestMsg) throws Exception {
|
||||
CoapClient client = getCoapClient(FeatureType.PROVISION);
|
||||
client = getCoapClient(FeatureType.PROVISION);
|
||||
return postProvision(client, provisionRequestMsg);
|
||||
}
|
||||
|
||||
|
||||
@ -54,7 +54,7 @@ public abstract class AbstractCoapServerSideRpcIntegrationTest extends AbstractC
|
||||
}
|
||||
|
||||
protected void processOneWayRpcTest() throws Exception {
|
||||
CoapClient client = getCoapClient(FeatureType.RPC);
|
||||
client = getCoapClient(FeatureType.RPC);
|
||||
client.useCONs();
|
||||
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
@ -82,7 +82,7 @@ public abstract class AbstractCoapServerSideRpcIntegrationTest extends AbstractC
|
||||
}
|
||||
|
||||
protected void processTwoWayRpcTest(String expectedResponseResult) throws Exception {
|
||||
CoapClient client = getCoapClient(FeatureType.RPC);
|
||||
client = getCoapClient(FeatureType.RPC);
|
||||
client.useCONs();
|
||||
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
|
||||
@ -69,7 +69,7 @@ public abstract class AbstractCoapAttributesIntegrationTest extends AbstractCoap
|
||||
}
|
||||
|
||||
protected void processAttributesTest(List<String> expectedKeys, byte[] payload, boolean presenceFieldsTest) throws Exception {
|
||||
CoapClient client = getCoapClient(FeatureType.ATTRIBUTES);
|
||||
client = getCoapClient(FeatureType.ATTRIBUTES);
|
||||
|
||||
postAttributes(client, payload);
|
||||
|
||||
|
||||
@ -71,8 +71,8 @@ public abstract class AbstractCoapTimeseriesIntegrationTest extends AbstractCoap
|
||||
}
|
||||
|
||||
protected void processTestPostTelemetry(byte[] payloadBytes, List<String> expectedKeys, boolean withTs, boolean presenceFieldsTest) throws Exception {
|
||||
CoapClient coapClient = getCoapClient(FeatureType.TELEMETRY);
|
||||
postTelemetry(coapClient, payloadBytes);
|
||||
client = getCoapClient(FeatureType.TELEMETRY);
|
||||
postTelemetry(client, payloadBytes);
|
||||
|
||||
String deviceId = savedDevice.getId().getId().toString();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user