Search in sources :

Example 51 with Expectations

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

the class AmqpSendTest method send_initializes_Reactor.

// Tests_SRS_SERVICE_SDK_JAVA_AMQPSEND_12_007: [The event handler shall initialize the Proton reactor object]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSEND_12_008: [The event handler shall start the Proton reactor object]
@Test
public void send_initializes_Reactor() throws Exception {
    // Arrange
    String hostName = "aaa";
    String userName = "bbb";
    String sasToken = "ccc";
    String deviceId = "deviceId";
    String content = "abcdefghijklmnopqrst";
    Message message = new Message(content);
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS;
    AmqpSend amqpSend = new AmqpSend(hostName, userName, sasToken, iotHubServiceClientProtocol);
    amqpSend.open();
    // Assert
    new Expectations() {

        {
            reactor = proton.reactor(amqpSend);
            reactor.run();
        }
    };
    // Act
    amqpSend.send(deviceId, message);
}
Also used : Expectations(mockit.Expectations) Message(com.microsoft.azure.sdk.iot.service.Message) AmqpSend(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 52 with Expectations

use of mockit.Expectations in project drill by apache.

the class ExpressionTest method testSchemaExpression.

@Test
public void testSchemaExpression(@Injectable final RecordBatch batch) throws Exception {
    final TypedFieldId tfid = new TypedFieldId(Types.optional(MinorType.BIGINT), false, 0);
    new Expectations() {

        {
            batch.getValueVectorId(new SchemaPath("alpha", ExpressionPosition.UNKNOWN));
            result = tfid;
        // batch.getValueVectorById(tfid); result = new Fixed4(null, null);
        }
    };
    System.out.println(getExpressionCode("1 + alpha", batch));
}
Also used : Expectations(mockit.Expectations) NonStrictExpectations(mockit.NonStrictExpectations) SchemaPath(org.apache.drill.common.expression.SchemaPath) TypedFieldId(org.apache.drill.exec.record.TypedFieldId) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Example 53 with Expectations

use of mockit.Expectations in project Payara by payara.

the class ContextManagerImplUnitTest method testGetContextUseOfContextMap_new.

/**
 * Verify the expected delegation to ContextMap by ContextManagerImpl on invocation of getContext.
 */
// @Test
public void testGetContextUseOfContextMap_new(@Mocked final ContextMap mockedContextMap) throws Exception {
    new Expectations() {

        // We expect ContextManagerImpl to call getScopeAwareContextMap, but
        // we also need that method to return a ContextMap instance so
        // we tell the mocking framework to return an instance.
        ContextMapHelper expectationsRefContextMapHelper;

        {
            expectationsRefContextMapHelper.getScopeAwareContextMap();
            returns(mockedContextMap, null);
        }

        // We expect ContextManagerImpl to then go ahead and use the
        // ContextMap - in particular to call get (from which we deliberately
        // return null) and the createViewCapable (from which we return null
        // which is in practice an exceptional condition (which will result
        // in a WARNING log message) but does fine for this test.
        ContextMap expectationsRefContextMap = mockedContextMap;

        {
            expectationsRefContextMap.get(WORK_CONTEXT_KEY);
            returns(null, null);
            expectationsRefContextMap.createViewCapable(WORK_CONTEXT_KEY);
            returns(null, null);
        }
    };
    ContextManagerImpl cmi = new ContextManagerImpl();
    Context ci = cmi.getContext();
}
Also used : Expectations(mockit.Expectations) Context(org.glassfish.diagnostics.context.Context) ContextMapHelper(org.glassfish.contextpropagation.spi.ContextMapHelper) ContextMap(org.glassfish.contextpropagation.ContextMap)

Example 54 with Expectations

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

the class SignatureTest method toStringReturnsCorrectString.

// Tests_SRS_SIGNATURE_11_005: [The function shall return the string representation of the signature.]
@Test
public void toStringReturnsCorrectString() {
    final String resourceUri = "test-resource-uri";
    final String deviceKey = "test-device-key";
    final long expiryTime = 101L;
    final String sigStr = "test-signature";
    new Expectations() {

        {
            // this should be the last step of the signature computation.
            SignatureHelper.encodeSignatureWebSafe(anyString);
            result = sigStr;
        }
    };
    Signature sig = new Signature(resourceUri, expiryTime, deviceKey);
    String testSigStr = sig.toString();
    final String expectedSigStr = sigStr;
    assertThat(testSigStr, is(expectedSigStr));
}
Also used : Expectations(mockit.Expectations) Signature(com.microsoft.azure.sdk.iot.device.auth.Signature) Test(org.junit.Test)

Example 55 with Expectations

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

the class AmqpReceiveHandlerTest method onConnectionBound_call_flow_and_init_ok_amqps.

// Tests_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_009: [The event handler shall set the SASL PLAIN authentication on the Transport using the given user name and sas token]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_010: [The event handler shall set ANONYMUS_PEER authentication mode on the domain of the Transport]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_018: [The event handler shall initialize WebSocket if the protocol is AMQP_WS]
@Test
public void onConnectionBound_call_flow_and_init_ok_amqps() {
    // Arrange
    final String hostName = "aaa";
    final String userName = "bbb";
    final String sasToken = "ccc";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS_WS;
    AmqpFeedbackReceivedHandler amqpReceiveHandler = new AmqpFeedbackReceivedHandler(hostName, userName, sasToken, iotHubServiceClientProtocol, null);
    // Assert
    new Expectations() {

        {
            event.getConnection();
            result = connection;
            connection.getTransport();
            result = transportInternal;
            new WebSocketImpl();
            result = webSocket;
            webSocket.configure(anyString, anyString, 0, anyString, null, null);
            transportInternal.addTransportLayer(webSocket);
            sasl.plain(anyString, anyString);
            Proton.sslDomain();
            result = sslDomain;
            sslDomain.init(SslDomain.Mode.CLIENT);
            sslDomain.setPeerAuthentication(SslDomain.VerifyMode.ANONYMOUS_PEER);
            transportInternal.ssl(sslDomain);
        }
    };
    // Act
    amqpReceiveHandler.onConnectionBound(event);
}
Also used : Expectations(mockit.Expectations) WebSocketImpl(com.microsoft.azure.sdk.iot.deps.ws.impl.WebSocketImpl) AmqpFeedbackReceivedHandler(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFeedbackReceivedHandler) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Aggregations

Expectations (mockit.Expectations)114 Test (org.junit.Test)98 IotHubServiceClientProtocol (com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol)60 FeedbackReceiver (com.microsoft.azure.sdk.iot.service.FeedbackReceiver)19 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)19 Test (org.testng.annotations.Test)14 AmqpSendHandler (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSendHandler)12 ByteBuffer (java.nio.ByteBuffer)12 ServiceClient (com.microsoft.azure.sdk.iot.service.ServiceClient)10 AmqpFeedbackReceivedHandler (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFeedbackReceivedHandler)6 AmqpReceive (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpReceive)5 URIEndpointObject (io.servicecomb.foundation.common.net.URIEndpointObject)5 FeedbackBatch (com.microsoft.azure.sdk.iot.service.FeedbackBatch)4 Message (com.microsoft.azure.sdk.iot.service.Message)4 AmqpSend (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSend)4 HeartbeatResponse (io.servicecomb.serviceregistry.api.response.HeartbeatResponse)4 WebSocketImpl (com.microsoft.azure.sdk.iot.deps.ws.impl.WebSocketImpl)3 Tools (com.microsoft.azure.sdk.iot.service.Tools)3 AmqpFileUploadNotificationReceive (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFileUploadNotificationReceive)3 Endpoint (io.servicecomb.core.Endpoint)3