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);
}
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));
}
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();
}
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));
}
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);
}
Aggregations