use of com.microsoft.azure.sdk.iot.provisioning.device.ProvisioningDeviceClient in project azure-iot-sdk-java by Azure.
the class ProvisioningDeviceClientTest method registerSucceeds.
// SRS_ProvisioningDeviceClient_25_009: [ This method shall set the config with the callback. ]
// SRS_ProvisioningDeviceClient_25_010: [ This method shall start the executor with the ProvisioningTask. ]
@Test
public void registerSucceeds() throws ProvisioningDeviceClientException {
// arrange
ProvisioningDeviceClient testProvisioningDeviceClient = ProvisioningDeviceClient.create(END_POINT, SCOPE_ID, TEST_PROTOCOL, mockedSecurityProvider);
// act
testProvisioningDeviceClient.registerDevice(mockedRegistrationCB, null);
// assert
new Verifications() {
{
mockedProvisioningDeviceClientConfig.setRegistrationCallback((ProvisioningDeviceClientRegistrationCallback) any, any);
times = 1;
mockedExecutorService.submit((ProvisioningTask) any);
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.provisioning.device.ProvisioningDeviceClient in project azure-iot-sdk-java by Azure.
the class ProvisioningDeviceClientTest method constructorSucceeds.
// SRS_ProvisioningDeviceClient_25_005: [ The constructor shall create provisioningDeviceClientConfig and set all the provided values to it.. ]
// SRS_ProvisioningDeviceClient_25_006: [ The constructor shall create provisioningDeviceClientContract with the given config. ]
// SRS_ProvisioningDeviceClient_25_007: [ The constructor shall create an executor service with fixed thread pool of size 1. ]
@Test
public void constructorSucceeds() throws ProvisioningDeviceClientException {
// arrange
// act
ProvisioningDeviceClient testProvisioningDeviceClient = ProvisioningDeviceClient.create(END_POINT, SCOPE_ID, TEST_PROTOCOL, mockedSecurityProvider);
// assert
new Verifications() {
{
mockedProvisioningDeviceClientConfig.setProvisioningServiceGlobalEndpoint(END_POINT);
times = 1;
mockedProvisioningDeviceClientConfig.setIdScope(SCOPE_ID);
times = 1;
mockedProvisioningDeviceClientConfig.setSecurityProvider(mockedSecurityProvider);
times = 1;
mockedProvisioningDeviceClientConfig.setProtocol(TEST_PROTOCOL);
times = 1;
ProvisioningDeviceClientContract.createProvisioningContract((ProvisioningDeviceClientConfig) any);
times = 1;
Executors.newFixedThreadPool(1);
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.provisioning.device.ProvisioningDeviceClient in project azure-iot-sdk-java by Azure.
the class ProvisioningDeviceClientTest method registerThrowsOnNullCB.
// SRS_ProvisioningDeviceClient_25_008: [ This method shall throw IllegalArgumentException if provisioningDeviceClientRegistrationCallback is null. ]
@Test(expected = IllegalArgumentException.class)
public void registerThrowsOnNullCB() throws ProvisioningDeviceClientException {
// arrange
ProvisioningDeviceClient testProvisioningDeviceClient = ProvisioningDeviceClient.create(END_POINT, SCOPE_ID, TEST_PROTOCOL, mockedSecurityProvider);
// act
testProvisioningDeviceClient.registerDevice(null, null);
}
use of com.microsoft.azure.sdk.iot.provisioning.device.ProvisioningDeviceClient in project azure-iot-sdk-java by Azure.
the class ProvisioningDeviceClientTest method closeNowSucceeds.
// SRS_ProvisioningDeviceClient_25_011: [ This method shall check if executor is terminated and if not shall shutdown the executor. ]
@Test
public void closeNowSucceeds() throws ProvisioningDeviceClientException {
// arrange
new NonStrictExpectations() {
{
mockedExecutorService.isTerminated();
result = false;
}
};
ProvisioningDeviceClient testProvisioningDeviceClient = ProvisioningDeviceClient.create(END_POINT, SCOPE_ID, TEST_PROTOCOL, mockedSecurityProvider);
// act
testProvisioningDeviceClient.closeNow();
// assert
new Verifications() {
{
mockedExecutorService.shutdownNow();
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.provisioning.device.ProvisioningDeviceClient in project azure-iot-sdk-java by Azure.
the class ProvisioningTPMTests method provisioningTpmFlow.
@Test
public void provisioningTpmFlow() throws SecurityProviderException, ProvisioningServiceClientException, ProvisioningDeviceClientException, InterruptedException {
ProvisioningServiceClient provisioningServiceClient = ProvisioningServiceClient.createFromConnectionString(provisioningServiceConnectionString);
String registrationId = UUID.randomUUID().toString();
String provisionedDeviceId = "Some-Provisioned-Device-" + TPM + "-" + UUID.randomUUID().toString();
SecurityProvider securityProvider = new SecurityProviderTPMEmulator(registrationId);
Attestation attestation = new TpmAttestation(new String(encodeBase64(((SecurityProviderTpm) securityProvider).getEndorsementKey())));
IndividualEnrollment individualEnrollment = new IndividualEnrollment(registrationId, attestation);
individualEnrollment.setDeviceIdFinal(provisionedDeviceId);
provisioningServiceClient.createOrUpdateIndividualEnrollment(individualEnrollment);
ProvisioningDeviceClient provisioningDeviceClient = ProvisioningDeviceClient.create(provisioningServiceGlobalEndpoint, provisioningServiceIdScope, ProvisioningDeviceClientTransportProtocol.AMQPS, securityProvider);
AtomicBoolean registrationCompleted = new AtomicBoolean(false);
AtomicBoolean registrationCompletedSuccessfully = new AtomicBoolean(false);
provisioningDeviceClient.registerDevice((provisioningDeviceClientRegistrationResult, e, context) -> {
log.debug("Provisioning registration callback fired with result {}", provisioningDeviceClientRegistrationResult.getProvisioningDeviceClientStatus());
if (e != null) {
log.error("Provisioning registration callback fired with exception {}", e);
}
ProvisioningDeviceClientStatus status = provisioningDeviceClientRegistrationResult.getProvisioningDeviceClientStatus();
if (status == ProvisioningDeviceClientStatus.PROVISIONING_DEVICE_STATUS_ASSIGNED) {
registrationCompletedSuccessfully.set(true);
}
registrationCompleted.set(true);
}, null);
long startTime = System.currentTimeMillis();
while (!registrationCompleted.get()) {
Thread.sleep(200);
if (System.currentTimeMillis() - startTime > REGISTRATION_TIMEOUT_MILLISECONDS) {
fail("Timed out waiting for device registration to complete.");
}
}
assertTrue("Registration completed, but not successfully", registrationCompletedSuccessfully.get());
provisioningDeviceClient.closeNow();
}
Aggregations