Skip to content

Commit

Permalink
Legacy tests: Sandbox ClientOptions (#405)
Browse files Browse the repository at this point in the history
* Test suite: newSandboxApp

* Use of `newSandboxApp`

 - XCTestExpectation was created before the sandbox app request and the
timeout was easily exceeded

* Fix compiler warning.
  • Loading branch information
ricardopereira authored and tcard committed May 16, 2016
1 parent 6d4a884 commit c83fc68
Show file tree
Hide file tree
Showing 20 changed files with 2,989 additions and 3,702 deletions.
571 changes: 276 additions & 295 deletions Tests/ARTRealtimeAttachTest.m

Large diffs are not rendered by default.

640 changes: 300 additions & 340 deletions Tests/ARTRealtimeChannelHistoryTest.m

Large diffs are not rendered by default.

469 changes: 221 additions & 248 deletions Tests/ARTRealtimeChannelTest.m

Large diffs are not rendered by default.

403 changes: 190 additions & 213 deletions Tests/ARTRealtimeConnectTest.m

Large diffs are not rendered by default.

119 changes: 54 additions & 65 deletions Tests/ARTRealtimeCryptoTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,95 +19,84 @@
#import "ARTPaginatedResult.h"
#import "ARTChannelOptions.h"

@interface ARTRealtimeCryptoTest : XCTestCase {
ARTRealtime *_realtime;
}
@interface ARTRealtimeCryptoTest : XCTestCase

@end

@implementation ARTRealtimeCryptoTest

- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
if (_realtime) {
[ARTTestUtil removeAllChannels:_realtime];
[_realtime.connection close];
}
_realtime = nil;
}

- (void)testSendEncodedMessage {
__weak XCTestExpectation *exp = [self expectationWithDescription:@"testSendEncodedMessage"];
[ARTTestUtil testRealtime:^(ARTRealtime *realtime) {
_realtime = realtime;
ARTClientOptions *options = [ARTTestUtil newSandboxApp:self withDescription:__FUNCTION__];
__weak XCTestExpectation *expectation = [self expectationWithDescription:[NSString stringWithFormat:@"%s", __FUNCTION__]];
ARTRealtime *realtime = [[ARTRealtime alloc] initWithOptions:options];
NSData *ivSpec = [[NSData alloc] initWithBase64EncodedString:@"HO4cYSP8LybPYBPZPHQOtg==" options:0];
NSData *keySpec = [[NSData alloc] initWithBase64EncodedString:@"WUP6u0K7MXI5Zeo0VppPwg==" options:0];
ARTCipherParams *params =[[ARTCipherParams alloc] initWithAlgorithm:@"aes" key:keySpec iv:ivSpec];
ARTRealtimeChannel *channel = [realtime.channels get:@"test" options:[[ARTChannelOptions alloc] initWithCipher: params]];
XCTAssert(channel);
NSString *dataStr = @"someDataPayload";
NSData *dataPayload = [dataStr dataUsingEncoding:NSUTF8StringEncoding];
NSString *stringPayload = @"someString";

[channel publish:nil data:dataPayload callback:^(ARTErrorInfo *errorInfo) {
XCTAssertNil(errorInfo);
[channel publish:nil data:stringPayload callback:^(ARTErrorInfo *errorInfo) {
XCTAssertNil(errorInfo);
ARTRealtimeHistoryQuery *query = [[ARTRealtimeHistoryQuery alloc] init];
[channel history:query callback:^(ARTPaginatedResult *result, ARTErrorInfo *error) {
XCTAssert(!error);
XCTAssertFalse([result hasNext]);
NSArray *page = [result items];
XCTAssertTrue(page != nil);
XCTAssertEqual([page count], 2);
ARTMessage *stringMessage = [page objectAtIndex:0];
ARTMessage *dataMessage = [page objectAtIndex:1];
XCTAssertEqualObjects([dataMessage data], dataPayload);
XCTAssertEqualObjects([stringMessage data], stringPayload);
[expectation fulfill];
} error:nil];
}];
}];
[self waitForExpectationsWithTimeout:[ARTTestUtil timeout] handler:nil];
}

- (void)testSendEncodedMessageOnExistingChannel {
ARTClientOptions *options = [ARTTestUtil newSandboxApp:self withDescription:__FUNCTION__];
__weak XCTestExpectation *expectation = [self expectationWithDescription:[NSString stringWithFormat:@"%s", __FUNCTION__]];
NSString *channelName = @"channelName";
NSString *firstMessageText = @"firstMessage";
ARTRealtime *realtime = [[ARTRealtime alloc] initWithOptions:options];
ARTRealtimeChannel *channel = [realtime.channels get:channelName];
[channel publish:nil data:firstMessageText callback:^(ARTErrorInfo *errorInfo) {
XCTAssertNil(errorInfo);
NSData *ivSpec = [[NSData alloc] initWithBase64EncodedString:@"HO4cYSP8LybPYBPZPHQOtg==" options:0];
NSData *keySpec = [[NSData alloc] initWithBase64EncodedString:@"WUP6u0K7MXI5Zeo0VppPwg==" options:0];
ARTCipherParams *params =[[ARTCipherParams alloc] initWithAlgorithm:@"aes" key:keySpec iv:ivSpec];
ARTRealtimeChannel *channel = [realtime.channels get:@"test" options:[[ARTChannelOptions alloc] initWithCipher: params]];
XCTAssert(channel);
NSString *dataStr = @"someDataPayload";
NSData *dataPayload = [dataStr dataUsingEncoding:NSUTF8StringEncoding];
ARTRealtimeChannel *c = [realtime.channels get:channelName options:[[ARTChannelOptions alloc] initWithCipher:params]];
XCTAssert(c);
NSData *dataPayload = [@"someDataPayload" dataUsingEncoding:NSUTF8StringEncoding];
NSString *stringPayload = @"someString";

[channel publish:nil data:dataPayload callback:^(ARTErrorInfo *errorInfo) {
[c publish:nil data:dataPayload callback:^(ARTErrorInfo *errorInfo) {
XCTAssertNil(errorInfo);
[channel publish:nil data:stringPayload callback:^(ARTErrorInfo *errorInfo) {
[c publish:nil data:stringPayload callback:^(ARTErrorInfo *errorInfo) {
XCTAssertNil(errorInfo);
ARTRealtimeHistoryQuery *query = [[ARTRealtimeHistoryQuery alloc] init];
[channel history:query callback:^(ARTPaginatedResult *result, ARTErrorInfo *error) {
[c history:^(ARTPaginatedResult *result, ARTErrorInfo *error) {
XCTAssert(!error);
XCTAssertFalse([result hasNext]);
NSArray *page = [result items];
XCTAssertTrue(page != nil);
XCTAssertEqual([page count], 2);
XCTAssertEqual([page count], 3);
ARTMessage *stringMessage = [page objectAtIndex:0];
ARTMessage *dataMessage = [page objectAtIndex:1];
ARTMessage *firstMessage = [page objectAtIndex:2];
XCTAssertEqualObjects([dataMessage data], dataPayload);
XCTAssertEqualObjects([stringMessage data], stringPayload);
[exp fulfill];
} error:nil];
}];
}];
}];
[self waitForExpectationsWithTimeout:[ARTTestUtil timeout] handler:nil];
}

- (void)testSendEncodedMessageOnExistingChannel {
__weak XCTestExpectation *exp = [self expectationWithDescription:@"testSendEncodedMessageOnExistingChannel"];
NSString *channelName = @"channelName";
NSString *firstMessageText = @"firstMessage";
[ARTTestUtil testRealtime:^(ARTRealtime *realtime) {
_realtime = realtime;

ARTRealtimeChannel *channel = [realtime.channels get:channelName];
[channel publish:nil data:firstMessageText callback:^(ARTErrorInfo *errorInfo) {
XCTAssertNil(errorInfo);
NSData *ivSpec = [[NSData alloc] initWithBase64EncodedString:@"HO4cYSP8LybPYBPZPHQOtg==" options:0];
NSData *keySpec = [[NSData alloc] initWithBase64EncodedString:@"WUP6u0K7MXI5Zeo0VppPwg==" options:0];
ARTCipherParams *params =[[ARTCipherParams alloc] initWithAlgorithm:@"aes" key:keySpec iv:ivSpec];
ARTRealtimeChannel *c = [realtime.channels get:channelName options:[[ARTChannelOptions alloc] initWithCipher:params]];
XCTAssert(c);
NSData *dataPayload = [@"someDataPayload" dataUsingEncoding:NSUTF8StringEncoding];
NSString *stringPayload = @"someString";
[c publish:nil data:dataPayload callback:^(ARTErrorInfo *errorInfo) {
XCTAssertNil(errorInfo);
[c publish:nil data:stringPayload callback:^(ARTErrorInfo *errorInfo) {
XCTAssertNil(errorInfo);
[c history:^(ARTPaginatedResult *result, ARTErrorInfo *error) {
XCTAssert(!error);
XCTAssertFalse([result hasNext]);
NSArray *page = [result items];
XCTAssertTrue(page != nil);
XCTAssertEqual([page count], 3);
ARTMessage *stringMessage = [page objectAtIndex:0];
ARTMessage *dataMessage = [page objectAtIndex:1];
ARTMessage *firstMessage = [page objectAtIndex:2];
XCTAssertEqualObjects([dataMessage data], dataPayload);
XCTAssertEqualObjects([stringMessage data], stringPayload);
XCTAssertEqualObjects([firstMessage data], firstMessageText);
[exp fulfill];
}];
XCTAssertEqualObjects([firstMessage data], firstMessageText);
[expectation fulfill];
}];
}];
}];
Expand Down
145 changes: 63 additions & 82 deletions Tests/ARTRealtimeInitTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,125 +17,106 @@
#import "ARTLog.h"
#import "ARTEventEmitter.h"
#import "ARTAuth.h"
#import "ARTAuth+Private.h"
#import "ARTRealtime+Private.h"
#import "ARTDefault.h"

@interface ARTRealtimeInitTest : XCTestCase {
ARTRealtime *_realtime;
}
@interface ARTRealtimeInitTest : XCTestCase

@end

@implementation ARTRealtimeInitTest

- (void)tearDown {
if (_realtime) {
[ARTTestUtil removeAllChannels:_realtime];
[_realtime resetEventEmitter];
[_realtime close];
}
_realtime = nil;
[super tearDown];
}

- (void)getBaseOptions:(void (^)(ARTClientOptions *options)) cb {
[ARTTestUtil setupApp:[ARTTestUtil clientOptions] withDebug:NO callback:cb];
}

- (void)testInitWithOptions {
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"initWithOptions"];
[ARTTestUtil testRealtime:^(ARTRealtime *realtime) {
_realtime = realtime;
[realtime.connection on:^(ARTConnectionStateChange *stateChange) {
ARTRealtimeConnectionState state = stateChange.current;
if(state == ARTRealtimeConnected) {
[expectation fulfill];
}
else {
XCTAssertEqual(state, ARTRealtimeConnecting);
}
}];
ARTClientOptions *options = [ARTTestUtil newSandboxApp:self withDescription:__FUNCTION__];
__weak XCTestExpectation *expectation = [self expectationWithDescription:[NSString stringWithFormat:@"%s", __FUNCTION__]];
ARTRealtime *realtime = [[ARTRealtime alloc] initWithOptions:options];
[realtime.connection on:^(ARTConnectionStateChange *stateChange) {
ARTRealtimeConnectionState state = stateChange.current;
if(state == ARTRealtimeConnected) {
[expectation fulfill];
}
else {
XCTAssertEqual(state, ARTRealtimeConnecting);
}
}];
[self waitForExpectationsWithTimeout:[ARTTestUtil timeout] handler:nil];
}

- (void)testInitWithHost {
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"testInitWithHost"];
[self getBaseOptions:^(ARTClientOptions *options) {
options.environment = @"test";
ARTRealtime *realtime = [[ARTRealtime alloc] initWithOptions:options];
_realtime = realtime;
[realtime.connection on:^(ARTConnectionStateChange *stateChange) {
ARTRealtimeConnectionState state = stateChange.current;
if(state == ARTRealtimeFailed) {
[expectation fulfill];
}
else {
XCTAssertEqual(state, ARTRealtimeConnecting);
}
}];
ARTClientOptions *options = [ARTTestUtil newSandboxApp:self withDescription:__FUNCTION__];
__weak XCTestExpectation *expectation = [self expectationWithDescription:[NSString stringWithFormat:@"%s", __FUNCTION__]];
options.environment = @"test";
ARTRealtime *realtime = [[ARTRealtime alloc] initWithOptions:options];
[realtime.connection on:^(ARTConnectionStateChange *stateChange) {
ARTRealtimeConnectionState state = stateChange.current;
if(state == ARTRealtimeFailed) {
[expectation fulfill];
}
else {
XCTAssertEqual(state, ARTRealtimeConnecting);
}
}];
[self waitForExpectationsWithTimeout:[ARTTestUtil timeout] handler:nil];
}

- (void)testInitWithPort {
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"testInitWithPort"];
[self getBaseOptions:^(ARTClientOptions *options) {
options.tlsPort = 9998;
ARTRealtime *realtime = [[ARTRealtime alloc] initWithOptions:options];
_realtime = realtime;
[realtime.connection on:^(ARTConnectionStateChange *stateChange) {
ARTRealtimeConnectionState state = stateChange.current;
if(state == ARTRealtimeFailed) {
[expectation fulfill];
}
else {
XCTAssertEqual(state, ARTRealtimeConnecting);
}
}];
ARTClientOptions *options = [ARTTestUtil newSandboxApp:self withDescription:__FUNCTION__];
__weak XCTestExpectation *expectation = [self expectationWithDescription:[NSString stringWithFormat:@"%s", __FUNCTION__]];
options.tlsPort = 9998;
ARTRealtime *realtime = [[ARTRealtime alloc] initWithOptions:options];
[realtime.connection on:^(ARTConnectionStateChange *stateChange) {
ARTRealtimeConnectionState state = stateChange.current;
if(state == ARTRealtimeFailed) {
[expectation fulfill];
}
else {
XCTAssertEqual(state, ARTRealtimeConnecting);
}
}];
[self waitForExpectationsWithTimeout:[ARTTestUtil timeout]+[ARTDefault connectTimeout] handler:nil];
}

- (void)testInitWithKey {
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"testInitWithKey"];
[self getBaseOptions:^(ARTClientOptions *options) {
_realtime = [[ARTRealtime alloc] initWithKey:options.key];
if (_realtime.connection.state == ARTRealtimeConnecting) {
XCTAssertEqual(_realtime.auth.options.key, options.key);
[expectation fulfill];
}
}];
ARTClientOptions *options = [ARTTestUtil newSandboxApp:self withDescription:__FUNCTION__];
__weak XCTestExpectation *expectation = [self expectationWithDescription:[NSString stringWithFormat:@"%s", __FUNCTION__]];
ARTRealtime *realtime = [[ARTRealtime alloc] initWithKey:options.key];
if (realtime.connection.state == ARTRealtimeConnecting) {
XCTAssertEqual(realtime.auth.options.key, options.key);
[expectation fulfill];
}
[self waitForExpectationsWithTimeout:[ARTTestUtil timeout] handler:nil];
}

- (void)testInitAutoConnectDefault {
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"testInitAutoConnectDefault"];
[ARTTestUtil testRealtime:^(ARTRealtime *realtime) {
_realtime = realtime;
[realtime.connection on:^(ARTConnectionStateChange *stateChange) {
ARTRealtimeConnectionState state = stateChange.current;
if(state == ARTRealtimeConnected) {
[expectation fulfill];
}
}];
ARTClientOptions *options = [ARTTestUtil newSandboxApp:self withDescription:__FUNCTION__];
__weak XCTestExpectation *expectation = [self expectationWithDescription:[NSString stringWithFormat:@"%s", __FUNCTION__]];
ARTRealtime *realtime = [[ARTRealtime alloc] initWithOptions:options];
[realtime.connection on:^(ARTConnectionStateChange *stateChange) {
ARTRealtimeConnectionState state = stateChange.current;
if(state == ARTRealtimeConnected) {
[expectation fulfill];
}
}];
[self waitForExpectationsWithTimeout:[ARTTestUtil timeout] handler:nil];
}

- (void)testInitAutoConnectFalse {
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"testInitAutoConnectDefault"];
[ARTTestUtil setupApp:[ARTTestUtil clientOptions] callback:^(ARTClientOptions *options) {
options.autoConnect = false;
ARTRealtime *realtime = [[ARTRealtime alloc] initWithOptions:options];
_realtime = realtime;
[realtime.connection on:^(ARTConnectionStateChange *stateChange) {
ARTRealtimeConnectionState state = stateChange.current;
if(state == ARTRealtimeConnected) {
[expectation fulfill];
}
}];
[realtime connect];
ARTClientOptions *options = [ARTTestUtil newSandboxApp:self withDescription:__FUNCTION__];
__weak XCTestExpectation *expectation = [self expectationWithDescription:[NSString stringWithFormat:@"%s", __FUNCTION__]];
options.autoConnect = false;
ARTRealtime *realtime = [[ARTRealtime alloc] initWithOptions:options];
[realtime.connection on:^(ARTConnectionStateChange *stateChange) {
ARTRealtimeConnectionState state = stateChange.current;
if(state == ARTRealtimeConnected) {
[expectation fulfill];
}
}];
[realtime connect];
[self waitForExpectationsWithTimeout:[ARTTestUtil timeout] handler:nil];
}

Expand Down
Loading

0 comments on commit c83fc68

Please sign in to comment.