Search in sources :

Example 91 with NonStrictExpectations

use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.

the class DeviceMethodTest method invokeThrowOnGetUrlMethodFailed.

/* Tests_SRS_DEVICEMETHOD_21_008: [The invoke shall build the Method URL `{iot hub}/twins/{device id}/methods/` by calling getUrlMethod.] */
@Test(expected = IllegalArgumentException.class)
public void invokeThrowOnGetUrlMethodFailed(@Mocked final MethodParser methodParser) throws Exception {
    // arrange
    DeviceMethod testMethod = DeviceMethod.createFromConnectionString(STANDARD_CONNECTIONSTRING);
    new NonStrictExpectations() {

        {
            methodParser.toJson();
            result = STANDARD_JSON;
            IotHubConnectionString.getUrlMethod(anyString, STANDARD_DEVICEID);
            result = new IllegalArgumentException();
        }
    };
    // act
    testMethod.invoke(STANDARD_DEVICEID, STANDARD_METHODNAME, STANDARD_TIMEOUT_SECONDS, STANDARD_TIMEOUT_SECONDS, STANDARD_PAYLOAD_MAP);
}
Also used : DeviceMethod(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethod) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 92 with NonStrictExpectations

use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.

the class BaseDeviceTest method constructor_create_symmetrickey.

// Tests_SRS_SERVICE_SDK_JAVA_BASEDEVICE_12_005: [If the input symmetric key is empty, the constructor shall create
// a new SymmetricKey instance using AES encryption and store it into a member variable]
@Test
public void constructor_create_symmetrickey() throws NoSuchAlgorithmException {
    // Arrange
    String encryptionMethod = "AES";
    String deviceId = "xxx-device";
    new NonStrictExpectations() {

        {
            SymmetricKey symmetricKey = new SymmetricKey();
            KeyGenerator.getInstance(encryptionMethod);
        }
    };
    // Act
    BaseDevice device = Deencapsulation.newInstance(BaseDevice.class, deviceId, SymmetricKey.class);
    // Assert
    assertNotEquals(device.getSymmetricKey(), null);
}
Also used : SymmetricKey(com.microsoft.azure.sdk.iot.service.auth.SymmetricKey) NonStrictExpectations(mockit.NonStrictExpectations) BaseDevice(com.microsoft.azure.sdk.iot.service.BaseDevice) Test(org.junit.Test)

Example 93 with NonStrictExpectations

use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.

the class X509CertificatesTest method constructorStorePrimaryAndSecondaryCertsSucceed.

/* SRS_X509_CERTIFICATES_21_003: [If the secondary certificate is not null or empty, the constructor shall create a new instance of the X509CertificateWithInfo using the provided secondary certificate, and store it as the secondary Certificate.] */
@Test
public void constructorStorePrimaryAndSecondaryCertsSucceed(@Mocked final X509CertificateWithInfo mockedX509CertificateWithInfo) throws IllegalArgumentException {
    // arrange
    new NonStrictExpectations() {

        {
            Deencapsulation.newInstance(X509CertificateWithInfo.class, new Class[] { String.class }, PUBLIC_CERTIFICATE_STRING);
            result = mockedX509CertificateWithInfo;
            times = 2;
        }
    };
    // act
    X509Certificates x509Certificates = Deencapsulation.newInstance(X509Certificates.class, new Class[] { String.class, String.class }, PUBLIC_CERTIFICATE_STRING, PUBLIC_CERTIFICATE_STRING);
    // assert
    assertNotNull(Deencapsulation.getField(x509Certificates, "primary"));
    assertNotNull(Deencapsulation.getField(x509Certificates, "secondary"));
}
Also used : X509Certificates(com.microsoft.azure.sdk.iot.provisioning.service.configs.X509Certificates) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 94 with NonStrictExpectations

use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.

the class X509CertificatesTest method constructorStorePrimaryCertSucceed.

/* SRS_X509_CERTIFICATES_21_002: [The constructor shall create a new instance of the X509CertificateWithInfo using the provided primary certificate, and store is as the primary Certificate.] */
/* SRS_X509_CERTIFICATES_21_003: [If the secondary certificate is not null or empty, the constructor shall create a new instance of the X509CertificateWithInfo using the provided secondary certificate, and store it as the secondary Certificate.] */
@Test
public void constructorStorePrimaryCertSucceed(@Mocked final X509CertificateWithInfo mockedX509CertificateWithInfo) throws IllegalArgumentException {
    // arrange
    new NonStrictExpectations() {

        {
            Deencapsulation.newInstance(X509CertificateWithInfo.class, new Class[] { String.class }, PUBLIC_CERTIFICATE_STRING);
            result = mockedX509CertificateWithInfo;
            times = 1;
        }
    };
    // act
    X509Certificates x509Certificates = Deencapsulation.newInstance(X509Certificates.class, new Class[] { String.class, String.class }, PUBLIC_CERTIFICATE_STRING, null);
    // assert
    assertNotNull(Deencapsulation.getField(x509Certificates, "primary"));
    assertNull(Deencapsulation.getField(x509Certificates, "secondary"));
}
Also used : X509Certificates(com.microsoft.azure.sdk.iot.provisioning.service.configs.X509Certificates) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 95 with NonStrictExpectations

use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.

the class ProvisioningServiceClientTest method getEnrollmentGroupSucceed.

/* SRS_PROVISIONING_SERVICE_CLIENT_21_017: [The getEnrollmentGroup shall retrieve the enrollmentGroup information for the provided enrollmentGroupId by calling the get in the enrollmentGroupManager.] */
@Test
public void getEnrollmentGroupSucceed(@Mocked final EnrollmentGroup mockedEnrollmentGroup) throws ProvisioningServiceClientException {
    // arrange
    final String enrollmentGroupId = "valid-enrollmentGroupId";
    ProvisioningServiceClient provisioningServiceClient = createClient();
    new NonStrictExpectations() {

        {
            Deencapsulation.invoke(mockedEnrollmentGroupManager, "get", enrollmentGroupId);
            result = mockedEnrollmentGroup;
            times = 1;
        }
    };
    // act
    EnrollmentGroup result = provisioningServiceClient.getEnrollmentGroup(enrollmentGroupId);
    // assert
    assertNotNull(result);
}
Also used : ProvisioningConnectionString(com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Aggregations

NonStrictExpectations (mockit.NonStrictExpectations)476 Test (org.junit.Test)470 Verifications (mockit.Verifications)154 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)77 IOException (java.io.IOException)64 HttpConnection (com.microsoft.azure.sdk.iot.service.transport.http.HttpConnection)51 HttpMethod (com.microsoft.azure.sdk.iot.service.transport.http.HttpMethod)51 DeviceTwin (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin)47 MessageProperty (com.microsoft.azure.sdk.iot.device.MessageProperty)32 HttpsSingleMessage (com.microsoft.azure.sdk.iot.device.transport.https.HttpsSingleMessage)31 HttpConnection (com.microsoft.azure.sdk.iot.deps.transport.http.HttpConnection)26 HttpMethod (com.microsoft.azure.sdk.iot.deps.transport.http.HttpMethod)26 HttpsConnection (com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection)26 HttpsMethod (com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod)26 HashMap (java.util.HashMap)26 JobClient (com.microsoft.azure.sdk.iot.service.jobs.JobClient)25 IotHubConnectionString (com.microsoft.azure.sdk.iot.device.IotHubConnectionString)17 Date (java.util.Date)16 HashSet (java.util.HashSet)16 Query (com.microsoft.azure.sdk.iot.service.devicetwin.Query)15