use of mockit.Verifications in project azure-iot-sdk-java by Azure.
the class ProvisioningAmqpOperationsTest method openOpensAmqpConnectionSynchronouslyWithoutSaslHandler.
// SRS_ProvisioningAmqpOperations_34_020: [If the provided sasl handler is null, this function shall open the underlying amqpConnection synchronously.]
@Test
public void openOpensAmqpConnectionSynchronouslyWithoutSaslHandler() throws ProvisioningDeviceClientException, IOException {
// arrange
ProvisioningAmqpOperations provisioningAmqpOperations = new ProvisioningAmqpOperations(TEST_SCOPE_ID, TEST_HOST_NAME);
// act
provisioningAmqpOperations.open(TEST_REGISTRATION_ID, mockedSSLContext, null, false);
// assert
new Verifications() {
{
mockedAmqpConnection.open();
times = 1;
mockedAmqpConnection.openAmqpAsync();
times = 0;
}
};
}
use of mockit.Verifications in project azure-iot-sdk-java by Azure.
the class ProvisioningAmqpOperationsTest method closeSucceeds.
// SRS_ProvisioningAmqpOperations_07_007: [If amqpConnection is null, this method shall do nothing.]
// SRS_ProvisioningAmqpOperations_07_008: [This method shall call close on amqpConnection.]
@Test
public void closeSucceeds() throws ProvisioningDeviceClientException, IOException {
// arrange
ProvisioningAmqpOperations provisioningAmqpOperations = new ProvisioningAmqpOperations(TEST_SCOPE_ID, TEST_HOST_NAME);
new NonStrictExpectations() {
{
mockedAmqpConnection.setListener((AmqpListener) any);
mockedAmqpConnection.open();
}
};
provisioningAmqpOperations.open(TEST_REGISTRATION_ID, mockedSSLContext, null, false);
// act
provisioningAmqpOperations.close();
// assert
new Verifications() {
{
mockedAmqpConnection.close();
times = 1;
}
};
}
use of mockit.Verifications in project azure-iot-sdk-java by Azure.
the class SecurityProviderTpmTest method getRegistrationIdSucceeds.
// SRS_SecurityClientTpm_25_001: [ This method shall retrieve the EnrollmentKey from the implementation of this abstract class. ]
// SRS_SecurityClientTpm_25_002: [ This method shall hash the EnrollmentKey using SHA-256. ]
// SRS_SecurityClientTpm_25_003: [ This method shall convert the resultant hash to Base32 to convert all the data to be case agnostic and remove "=" from the string. ]
@Test
public void getRegistrationIdSucceeds() throws SecurityProviderException, EncoderException {
// arrange
SecurityProviderTpm securityClientTpm = new SecurityProviderTPMTestImpl(ENROLLMENT_KEY);
// act
String actualRegistrationId = securityClientTpm.getRegistrationId();
// assert
assertNotNull(actualRegistrationId);
assertEquals(actualRegistrationId, actualRegistrationId.toLowerCase());
assertFalse(actualRegistrationId.contains("="));
new Verifications() {
{
mockedMessageDigest.digest(ENROLLMENT_KEY);
times = 1;
mockedBase32.encode((byte[]) any);
times = 1;
}
};
}
use of mockit.Verifications in project azure-iot-sdk-java by Azure.
the class JobClientTest method getJobCreateURL.
/* Tests_SRS_JOBCLIENT_21_025: [The getJob shall create a URL for Jobs using the iotHubConnectionString.] */
@Test
public void getJobCreateURL() throws IOException, IotHubException {
// arrange
final String connectionString = "testString";
final String jobId = "validJobId";
JobClient testJobClient = null;
new NonStrictExpectations() {
{
IotHubConnectionStringBuilder.createIotHubConnectionString(connectionString);
result = mockedIotHubConnectionString;
IotHubConnectionString.getUrlJobs(anyString, jobId);
result = mockedURL;
DeviceOperations.request(anyString, mockedURL, HttpMethod.GET, new byte[] {}, (String) any, anyInt, anyInt, (Proxy) any);
result = mockedHttpResponse;
Deencapsulation.newInstance(JobResult.class, new Class[] { byte[].class }, (byte[]) any);
result = mockedJobResult;
}
};
try {
testJobClient = JobClient.createFromConnectionString(connectionString);
} catch (IllegalArgumentException e) {
assertTrue("Test did not run because createFromConnectionString failed to create new instance of the JobClient", true);
}
// act
testJobClient.getJob(jobId);
// assert
new Verifications() {
{
IotHubConnectionString.getUrlJobs(anyString, jobId);
times = 1;
}
};
}
use of mockit.Verifications in project azure-iot-sdk-java by Azure.
the class JobClientTest method queryDeviceJobSucceeds.
// Tests_SRS_JOBCLIENT_25_039: [The queryDeviceJob shall create a query object for the type DEVICE_JOB.]
// Tests_SRS_JOBCLIENT_25_040: [The queryDeviceJob shall send a query request on the query object using Query URL, HTTP POST method and wait for the response by calling sendQueryRequest.]
@Test
public void queryDeviceJobSucceeds(@Mocked Query mockedQuery) throws IotHubException, IOException {
// arrange
final String connectionString = "testString";
JobClient testJobClient = JobClient.createFromConnectionString(connectionString);
new Expectations() {
{
Deencapsulation.newInstance(Query.class, new Class[] { String.class, Integer.class, QueryType.class }, anyString, anyInt, QueryType.DEVICE_JOB);
result = mockedQuery;
}
};
// act
testJobClient.queryDeviceJob(VALID_SQL_QUERY);
// assert
new Verifications() {
{
mockedQuery.sendQueryRequest((TokenCredentialCache) any, (AzureSasCredential) any, (IotHubConnectionString) any, (URL) any, HttpMethod.POST, anyInt, anyInt, (Proxy) any);
times = 1;
}
};
}
Aggregations