Updated tests.
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/891e0f27 Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/891e0f27 Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/891e0f27 Branch: refs/heads/master Commit: 891e0f277d28c0b6d73b615c473e3212e88d7cf0 Parents: 47f86a9 Author: Robert Walsh <rjwalsh1...@gmail.com> Authored: Thu Feb 18 12:57:04 2016 -0600 Committer: Robert Walsh <rjwalsh1...@gmail.com> Committed: Thu Feb 18 12:57:04 2016 -0600 ---------------------------------------------------------------------- sdks/swift/Tests/ASSET_Tests.swift | 102 ++++++++++++++++-- sdks/swift/Tests/AUTH_Tests.swift | 71 +++++++++++-- sdks/swift/Tests/CONNECTION_Tests.swift | 11 +- sdks/swift/Tests/ClientCreationTests.swift | 23 ---- sdks/swift/Tests/GET_Tests.swift | 24 +++-- sdks/swift/Tests/PUT_Tests.swift | 28 +++-- sdks/swift/Tests/TestAssets/UsergridGuy.jpg | Bin 0 -> 12981 bytes sdks/swift/Tests/User_Tests.swift | 128 ++++++++++++++++++++--- 8 files changed, 322 insertions(+), 65 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/usergrid/blob/891e0f27/sdks/swift/Tests/ASSET_Tests.swift ---------------------------------------------------------------------- diff --git a/sdks/swift/Tests/ASSET_Tests.swift b/sdks/swift/Tests/ASSET_Tests.swift index ad383ca..2a7c540 100644 --- a/sdks/swift/Tests/ASSET_Tests.swift +++ b/sdks/swift/Tests/ASSET_Tests.swift @@ -31,7 +31,8 @@ class ASSET_Tests: XCTestCase { static let collectionName = "books" static let entityUUID = "f4078aca-2fb1-11e5-8eb2-e13f8369aad1" - static let imageLocation = "TestAssets/test.png" + static let pngLocation = "TestAssets/test.png" + static let jpgLocation = "TestAssets/UsergridGuy.jpg" static let imageName = "test" override func setUp() { @@ -48,6 +49,33 @@ class ASSET_Tests: XCTestCase { return (NSBundle(forClass: object_getClass(self)).resourcePath! as NSString).stringByAppendingPathComponent(fileLocation) } + func test_ASSET_INIT() { + var filePath = self.getFullPathOfFile(ASSET_Tests.pngLocation) + var image = UIImage(contentsOfFile: filePath) + var asset = UsergridAsset(filename:ASSET_Tests.imageName,image: image!) + XCTAssertNotNil(asset) + XCTAssertNotNil(asset!.data) + XCTAssertNotNil(asset!.filename) + XCTAssertEqual(asset!.contentType, UsergridImageContentType.Png.stringValue) + XCTAssertTrue(asset!.contentLength > 0) + + asset = UsergridAsset(filename:ASSET_Tests.imageName, fileURL: NSURL(fileURLWithPath: filePath)) + XCTAssertNotNil(asset) + XCTAssertNotNil(asset!.data) + XCTAssertNotNil(asset!.filename) + XCTAssertEqual(asset!.contentType, UsergridImageContentType.Png.stringValue) + XCTAssertTrue(asset!.contentLength > 0) + + filePath = self.getFullPathOfFile(ASSET_Tests.jpgLocation) + image = UIImage(contentsOfFile: filePath) + asset = UsergridAsset(filename:nil,image: image!, imageContentType:.Jpeg) + XCTAssertNotNil(asset) + XCTAssertNotNil(asset!.data) + XCTAssertEqual(asset!.filename,UsergridAsset.DEFAULT_FILE_NAME) + XCTAssertEqual(asset!.contentType, UsergridImageContentType.Jpeg.stringValue) + XCTAssertTrue(asset!.contentLength > 0) + } + func test_IMAGE_UPLOAD() { let getExpect = self.expectationWithDescription("\(__FUNCTION__)") let uploadProgress : UsergridAssetRequestProgress = { (bytes,expected) in @@ -58,25 +86,42 @@ class ASSET_Tests: XCTestCase { } Usergrid.GET(ASSET_Tests.collectionName, uuidOrName:ASSET_Tests.entityUUID) { (response) in + XCTAssertTrue(NSThread.isMainThread()) + let entity = response.first! XCTAssertNotNil(entity) XCTAssertFalse(entity.isUser) - let imagePath = self.getFullPathOfFile(ASSET_Tests.imageLocation) + let imagePath = self.getFullPathOfFile(ASSET_Tests.pngLocation) XCTAssertNotNil(imagePath) let localImage = UIImage(contentsOfFile: imagePath) XCTAssertNotNil(localImage) - let asset = UsergridAsset(fileName:ASSET_Tests.imageName,image: localImage!) + let asset = UsergridAsset(filename:ASSET_Tests.imageName,image: localImage!) XCTAssertNotNil(asset) - entity.uploadAsset(asset!, progress:uploadProgress) { (response, uploadedAsset, error) -> Void in - XCTAssertNotNil(asset) - XCTAssertNil(error) + entity.uploadAsset(asset!, progress:uploadProgress) { uploadedAsset,response in + XCTAssertTrue(NSThread.isMainThread()) XCTAssertTrue(response.ok) + XCTAssertNil(response.error) + + XCTAssertNotNil(asset) + XCTAssertNotNil(uploadedAsset) + XCTAssertEqual(uploadedAsset!, asset!) + + XCTAssertTrue(entity.hasAsset) + XCTAssertNotNil(entity.fileMetaData) + XCTAssertNotNil(entity.fileMetaData!.eTag) + XCTAssertNotNil(entity.fileMetaData!.checkSum) + XCTAssertNotNil(entity.fileMetaData!.contentType) + XCTAssertNotNil(entity.fileMetaData!.lastModifiedDate) + XCTAssertEqual(entity.asset!.contentLength, entity.fileMetaData!.contentLength) + XCTAssertEqual(entity.asset!.contentType, entity.fileMetaData!.contentType) + entity.downloadAsset(UsergridImageContentType.Png.stringValue, progress:downloadProgress) { (downloadedAsset, error) -> Void in + XCTAssertTrue(NSThread.isMainThread()) XCTAssertNotNil(downloadedAsset) XCTAssertNil(error) let downloadedImage = UIImage(data: downloadedAsset!.data) @@ -86,6 +131,49 @@ class ASSET_Tests: XCTestCase { } } } - self.waitForExpectationsWithTimeout(10, handler: nil) + self.waitForExpectationsWithTimeout(100, handler: nil) + } + + func test_FILE_META_DATA_NSCODING() { + let fileMetaDataDict = ["content-type":"image/png", + "etag":"dfa7421ea4f35d33e12ba93979a46b7e", + "checkSum":"dfa7421ea4f35d33e12ba93979a46b7e", + "content-length":1417896, + "last-modified":1455728898545] + + let fileMetaData = UsergridFileMetaData(fileMetaDataJSON:fileMetaDataDict) + + let fileMetaDataCodingData = NSKeyedArchiver.archivedDataWithRootObject(fileMetaData) + let newInstanceFromData = NSKeyedUnarchiver.unarchiveObjectWithData(fileMetaDataCodingData) as? UsergridFileMetaData + XCTAssertNotNil(newInstanceFromData) + + if let newInstance = newInstanceFromData { + XCTAssertEqual(fileMetaData.eTag,newInstance.eTag) + XCTAssertEqual(fileMetaData.checkSum,newInstance.checkSum) + XCTAssertEqual(fileMetaData.contentType,newInstance.contentType) + XCTAssertEqual(fileMetaData.contentLength,newInstance.contentLength) + XCTAssertEqual(fileMetaData.lastModifiedDate,newInstance.lastModifiedDate) + } + } + + func test_ASSET_NSCODING() { + let imagePath = self.getFullPathOfFile(ASSET_Tests.pngLocation) + let asset = UsergridAsset(filename:ASSET_Tests.imageName,fileURL: NSURL(fileURLWithPath: imagePath)) + XCTAssertNotNil(asset) + + if let originalAsset = asset { + let assetCodingData = NSKeyedArchiver.archivedDataWithRootObject(originalAsset) + let newInstanceFromData = NSKeyedUnarchiver.unarchiveObjectWithData(assetCodingData) as? UsergridAsset + + XCTAssertNotNil(newInstanceFromData) + + if let newInstance = newInstanceFromData { + XCTAssertEqual(originalAsset.filename,newInstance.filename) + XCTAssertEqual(originalAsset.data,newInstance.data) + XCTAssertEqual(originalAsset.originalLocation,newInstance.originalLocation) + XCTAssertEqual(originalAsset.contentType,newInstance.contentType) + XCTAssertEqual(originalAsset.contentLength,newInstance.contentLength) + } + } } } http://git-wip-us.apache.org/repos/asf/usergrid/blob/891e0f27/sdks/swift/Tests/AUTH_Tests.swift ---------------------------------------------------------------------- diff --git a/sdks/swift/Tests/AUTH_Tests.swift b/sdks/swift/Tests/AUTH_Tests.swift index 3ae21bc..ca96e59 100644 --- a/sdks/swift/Tests/AUTH_Tests.swift +++ b/sdks/swift/Tests/AUTH_Tests.swift @@ -29,12 +29,16 @@ import XCTest class AUTH_Tests: XCTestCase { - let clientAuth = UsergridAppAuth(clientId: "b3U6THNcevskEeOQZLcUROUUVA", clientSecret: "b3U6RZHYznP28xieBzQPackFPmmnevU") + var appAuth: UsergridAppAuth! + var userAuth: UsergridUserAuth! + private static let collectionName = "publicevent" private static let entityUUID = "fa015eaa-fe1c-11e3-b94b-63b29addea01" override func setUp() { super.setUp() + appAuth = UsergridAppAuth(clientId: "b3U6THNcevskEeOQZLcUROUUVA", clientSecret: "b3U6RZHYznP28xieBzQPackFPmmnevU") + userAuth = UsergridUserAuth(username: "username", password: "password") Usergrid.initSharedInstance(orgId:ClientCreationTests.orgId, appId: "sdk.demo") } @@ -47,8 +51,8 @@ class AUTH_Tests: XCTestCase { let authExpect = self.expectationWithDescription("\(__FUNCTION__)") Usergrid.authFallback = .App - Usergrid.authenticateApp(clientAuth) { auth,error in - + Usergrid.authenticateApp(appAuth) { auth,error in + XCTAssertTrue(NSThread.isMainThread()) XCTAssertNil(error) XCTAssertNotNil(Usergrid.appAuth) @@ -56,9 +60,10 @@ class AUTH_Tests: XCTestCase { XCTAssertNotNil(appAuth.accessToken) XCTAssertNotNil(appAuth.expiry) + XCTAssertNotNil(appAuth.isValid) Usergrid.GET(AUTH_Tests.collectionName) { (response) in - + XCTAssertTrue(NSThread.isMainThread()) XCTAssertNotNil(response) XCTAssertTrue(response.hasNextPage) XCTAssertEqual(response.entities!.count, 10) @@ -66,10 +71,62 @@ class AUTH_Tests: XCTestCase { authExpect.fulfill() } - } else { - authExpect.fulfill() } } - self.waitForExpectationsWithTimeout(20, handler: nil) + self.waitForExpectationsWithTimeout(100, handler: nil) + } + + func test_DESTROY_AUTH() { + let auth = UsergridAuth(accessToken: "YWMt91Q2YtWaEeW_Ki2uDueMEwAAAVMUTVSPeOdX-oradxdqirEFz5cPU3GWybs") + + XCTAssertTrue(auth.isValid) + XCTAssertNotNil(auth.accessToken) + XCTAssertNil(auth.expiry) + + auth.destroy() + + XCTAssertFalse(auth.isValid) + XCTAssertNil(auth.accessToken) + XCTAssertNil(auth.expiry) + } + + func test_APP_AUTH_NSCODING() { + + appAuth.accessToken = "YWMt91Q2YtWaEeW_Ki2uDueMEwAAAVMUTVSPeOdX-oradxdqirEFz5cPU3GWybs" + appAuth.expiry = NSDate.distantFuture() + + let authCodingData = NSKeyedArchiver.archivedDataWithRootObject(appAuth) + let newInstanceFromData = NSKeyedUnarchiver.unarchiveObjectWithData(authCodingData) as? UsergridAppAuth + + XCTAssertNotNil(newInstanceFromData) + + if let newInstance = newInstanceFromData { + XCTAssertTrue(appAuth.isValid) + XCTAssertTrue(newInstance.isValid) + XCTAssertEqual(appAuth.clientId,newInstance.clientId) + XCTAssertEqual(appAuth.accessToken,newInstance.accessToken) + XCTAssertEqual(appAuth.expiry,newInstance.expiry) + } + } + + func test_USER_AUTH_NSCODING() { + + userAuth.accessToken = "YWMt91Q2YtWaEeW_Ki2uDueMEwAAAVMUTVSPeOdX-oradxdqirEFz5cPU3GWybs" + userAuth.expiry = NSDate.distantFuture() + + let authCodingData = NSKeyedArchiver.archivedDataWithRootObject(userAuth) + let newInstanceFromData = NSKeyedUnarchiver.unarchiveObjectWithData(authCodingData) as? UsergridUserAuth + + XCTAssertNotNil(newInstanceFromData) + + if let newInstance = newInstanceFromData { + XCTAssertTrue(userAuth.isValid) + XCTAssertTrue(newInstance.isValid) + XCTAssertEqual(userAuth.username,newInstance.username) + XCTAssertEqual(userAuth.accessToken,newInstance.accessToken) + XCTAssertEqual(userAuth.expiry,newInstance.expiry) + } } + + } http://git-wip-us.apache.org/repos/asf/usergrid/blob/891e0f27/sdks/swift/Tests/CONNECTION_Tests.swift ---------------------------------------------------------------------- diff --git a/sdks/swift/Tests/CONNECTION_Tests.swift b/sdks/swift/Tests/CONNECTION_Tests.swift index 544b7c5..8eb9f94 100644 --- a/sdks/swift/Tests/CONNECTION_Tests.swift +++ b/sdks/swift/Tests/CONNECTION_Tests.swift @@ -47,6 +47,7 @@ class CONNECTION_Tests: XCTestCase { let authExpect = self.expectationWithDescription("\(__FUNCTION__)") Usergrid.authFallback = .App Usergrid.authenticateApp(clientAuth) { auth,error in + XCTAssertTrue(NSThread.isMainThread()) XCTAssertNil(error) XCTAssertNotNil(Usergrid.appAuth) @@ -56,7 +57,7 @@ class CONNECTION_Tests: XCTestCase { XCTAssertNotNil(appAuth.expiry) Usergrid.GET(CONNECTION_Tests.collectionName) { (response) in - + XCTAssertTrue(NSThread.isMainThread()) XCTAssertNotNil(response) XCTAssertTrue(response.ok) XCTAssertTrue(response.hasNextPage) @@ -67,18 +68,26 @@ class CONNECTION_Tests: XCTestCase { XCTAssertEqual(entity.type, CONNECTION_Tests.collectionName) entity.connect("likes", toEntity: entityToConnect) { (response) -> Void in + XCTAssertTrue(NSThread.isMainThread()) XCTAssertNotNil(response) XCTAssertTrue(response.ok) + entity.getConnections(.Out, relationship: "likes", query:nil) { (response) -> Void in + XCTAssertTrue(NSThread.isMainThread()) XCTAssertNotNil(response) XCTAssertTrue(response.ok) + let connectedEntity = response.first! XCTAssertNotNil(connectedEntity) XCTAssertEqual(connectedEntity.uuidOrName, entityToConnect.uuidOrName) + entity.disconnect("likes", fromEntity: connectedEntity) { (response) -> Void in + XCTAssertTrue(NSThread.isMainThread()) XCTAssertNotNil(response) XCTAssertTrue(response.ok) + entity.getConnections(.Out, relationship: "likes", query:nil) { (response) -> Void in + XCTAssertTrue(NSThread.isMainThread()) XCTAssertNotNil(response) XCTAssertTrue(response.ok) authExpect.fulfill() http://git-wip-us.apache.org/repos/asf/usergrid/blob/891e0f27/sdks/swift/Tests/ClientCreationTests.swift ---------------------------------------------------------------------- diff --git a/sdks/swift/Tests/ClientCreationTests.swift b/sdks/swift/Tests/ClientCreationTests.swift index 0fe0dbe..c7e57a4 100644 --- a/sdks/swift/Tests/ClientCreationTests.swift +++ b/sdks/swift/Tests/ClientCreationTests.swift @@ -32,21 +32,6 @@ class ClientCreationTests: XCTestCase { static let orgId = "rwalsh" static let appId = "sandbox" - static let otherInstanceID = "otherInstanceID" - static let otherAppID = "otherAppID" - static let otherOrgID = "otherOrgID" - static let otherBaseURL = "http://www.something.com" - static let otherAppAuth = UsergridAppAuth(clientId: "alkdjflsdf", clientSecret: "alkdjflsdf") - - static let otherConfiguration = UsergridClientConfig(orgId: ClientCreationTests.otherOrgID, - appId: ClientCreationTests.otherAppID, - baseUrl: ClientCreationTests.otherBaseURL, - authFallback: .App, - persistCurrentUserInKeychain: true, - appAuth: ClientCreationTests.otherAppAuth) - - let otherClient = UsergridClient(configuration: ClientCreationTests.otherConfiguration) - override func setUp() { super.setUp() Usergrid.initSharedInstance(orgId:ClientCreationTests.orgId, appId: ClientCreationTests.appId) @@ -60,8 +45,6 @@ class ClientCreationTests: XCTestCase { func test_INSTANCE_POINTERS() { XCTAssertNotNil(Usergrid.sharedInstance) - XCTAssertNotNil(otherClient) - XCTAssertFalse(otherClient === Usergrid.sharedInstance) } func test_CLIENT_PROPERTIES() { @@ -73,12 +56,6 @@ class ClientCreationTests: XCTestCase { XCTAssertEqual(Usergrid.clientAppURL, "\(UsergridClient.DEFAULT_BASE_URL)/\(ClientCreationTests.orgId)/\(ClientCreationTests.appId)" ) XCTAssertNil(Usergrid.currentUser) XCTAssertNil(Usergrid.userAuth) - - XCTAssertEqual(otherClient.appId, ClientCreationTests.otherAppID) - XCTAssertEqual(otherClient.orgId, ClientCreationTests.otherOrgID) - XCTAssertEqual(otherClient.authFallback, UsergridAuthFallback.App) - XCTAssertEqual(otherClient.baseUrl, ClientCreationTests.otherBaseURL) - XCTAssertNil(otherClient.currentUser) } func test_CLIENT_NSCODING() { http://git-wip-us.apache.org/repos/asf/usergrid/blob/891e0f27/sdks/swift/Tests/GET_Tests.swift ---------------------------------------------------------------------- diff --git a/sdks/swift/Tests/GET_Tests.swift b/sdks/swift/Tests/GET_Tests.swift index 999b22a..efb899e 100644 --- a/sdks/swift/Tests/GET_Tests.swift +++ b/sdks/swift/Tests/GET_Tests.swift @@ -29,18 +29,26 @@ import XCTest class GET_Tests: XCTestCase { - let usergridClientInstance = UsergridClient(orgId:ClientCreationTests.orgId, appId: ClientCreationTests.appId) - static let collectionName = "books" static let entityUUID = "f4078aca-2fb1-11e5-8eb2-e13f8369aad1" let query = UsergridQuery(GET_Tests.collectionName).fromString("select * where title = 'The Sun Also Rises' or title = 'The Old Man and the Sea'") + override func setUp() { + super.setUp() + Usergrid.initSharedInstance(orgId:ClientCreationTests.orgId, appId: ClientCreationTests.appId) + } + + override func tearDown() { + Usergrid._sharedClient = nil + super.tearDown() + } func test_GET_WITHOUT_QUERY() { let getExpect = self.expectationWithDescription("\(__FUNCTION__)") - usergridClientInstance.GET(GET_Tests.collectionName) { (response) in + Usergrid.GET(GET_Tests.collectionName) { (response) in + XCTAssertTrue(NSThread.isMainThread()) XCTAssertNotNil(response) XCTAssertTrue(response.ok) XCTAssertTrue(response.hasNextPage) @@ -53,7 +61,8 @@ class GET_Tests: XCTestCase { func test_GET_WITH_QUERY() { let getExpect = self.expectationWithDescription("\(__FUNCTION__)") - usergridClientInstance.GET(self.query) { (response) in + Usergrid.GET(self.query) { (response) in + XCTAssertTrue(NSThread.isMainThread()) XCTAssertNotNil(response) XCTAssertTrue(response.ok) XCTAssertEqual(response.count, 3) @@ -65,7 +74,8 @@ class GET_Tests: XCTestCase { func test_GET_WITH_UUID() { let getExpect = self.expectationWithDescription("\(__FUNCTION__)") - usergridClientInstance.GET(GET_Tests.collectionName, uuidOrName:GET_Tests.entityUUID) { (response) in + Usergrid.GET(GET_Tests.collectionName, uuidOrName:GET_Tests.entityUUID) { (response) in + XCTAssertTrue(NSThread.isMainThread()) XCTAssertNotNil(response) XCTAssertTrue(response.ok) let entity = response.first! @@ -81,13 +91,15 @@ class GET_Tests: XCTestCase { func test_GET_NEXT_PAGE_WITH_NO_QUERY() { let getExpect = self.expectationWithDescription("\(__FUNCTION__)") - usergridClientInstance.GET(GET_Tests.collectionName) { (response) in + Usergrid.GET(GET_Tests.collectionName) { (response) in + XCTAssertTrue(NSThread.isMainThread()) XCTAssertNotNil(response) XCTAssertTrue(response.ok) XCTAssertTrue(response.hasNextPage) XCTAssertEqual(response.count, 10) response.loadNextPage() { (nextPageResponse) in + XCTAssertTrue(NSThread.isMainThread()) XCTAssertTrue(nextPageResponse.ok) XCTAssertNotNil(nextPageResponse) XCTAssertFalse(nextPageResponse.hasNextPage) http://git-wip-us.apache.org/repos/asf/usergrid/blob/891e0f27/sdks/swift/Tests/PUT_Tests.swift ---------------------------------------------------------------------- diff --git a/sdks/swift/Tests/PUT_Tests.swift b/sdks/swift/Tests/PUT_Tests.swift index 26f3260..c9562e3 100644 --- a/sdks/swift/Tests/PUT_Tests.swift +++ b/sdks/swift/Tests/PUT_Tests.swift @@ -29,8 +29,6 @@ import XCTest class PUT_Tests: XCTestCase { - let client = UsergridClient(orgId:ClientCreationTests.orgId, appId: ClientCreationTests.appId) - let query = UsergridQuery(PUT_Tests.collectionName) .eq("title", value: "The Sun Also Rises") .or() @@ -39,14 +37,24 @@ class PUT_Tests: XCTestCase { static let collectionName = "books" static let entityUUID = "f4078aca-2fb1-11e5-8eb2-e13f8369aad1" + override func setUp() { + super.setUp() + Usergrid.initSharedInstance(orgId:ClientCreationTests.orgId, appId: ClientCreationTests.appId) + } + + override func tearDown() { + Usergrid._sharedClient = nil + super.tearDown() + } + func test_PUT_BY_SPECIFYING_UUID_AS_PARAMETER() { let propertyNameToUpdate = "\(__FUNCTION__)" let propertiesNewValue = "\(propertyNameToUpdate)_VALUE" let putExpect = self.expectationWithDescription(propertyNameToUpdate) - client.PUT(PUT_Tests.collectionName, uuidOrName: PUT_Tests.entityUUID, jsonBody:[propertyNameToUpdate : propertiesNewValue]) { (response) in - + Usergrid.PUT(PUT_Tests.collectionName, uuidOrName: PUT_Tests.entityUUID, jsonBody:[propertyNameToUpdate : propertiesNewValue]) { (response) in + XCTAssertTrue(NSThread.isMainThread()) XCTAssertNotNil(response) XCTAssertTrue(response.ok) XCTAssertEqual(response.entities!.count, 1) @@ -71,7 +79,8 @@ class PUT_Tests: XCTestCase { let jsonDictToPut = [UsergridEntityProperties.UUID.stringValue : PUT_Tests.entityUUID, propertyNameToUpdate : propertiesNewValue] - client.PUT(PUT_Tests.collectionName, jsonBody: jsonDictToPut) { (response) in + Usergrid.PUT(PUT_Tests.collectionName, jsonBody: jsonDictToPut) { (response) in + XCTAssertTrue(NSThread.isMainThread()) XCTAssertNotNil(response) XCTAssertTrue(response.ok) XCTAssertEqual(response.entities!.count, 1) @@ -93,7 +102,8 @@ class PUT_Tests: XCTestCase { let propertiesNewValue = "\(propertyNameToUpdate)_VALUE" let putExpect = self.expectationWithDescription(propertyNameToUpdate) - client.GET(PUT_Tests.collectionName, uuidOrName: PUT_Tests.entityUUID) { (getResponse) in + Usergrid.GET(PUT_Tests.collectionName, uuidOrName: PUT_Tests.entityUUID) { (getResponse) in + XCTAssertTrue(NSThread.isMainThread()) XCTAssertNotNil(getResponse) XCTAssertTrue(getResponse.ok) XCTAssertEqual(getResponse.entities!.count, 1) @@ -105,7 +115,8 @@ class PUT_Tests: XCTestCase { responseEntity[propertyNameToUpdate] = propertiesNewValue - self.client.PUT(responseEntity) { (putResponse) in + Usergrid.PUT(responseEntity) { (putResponse) in + XCTAssertTrue(NSThread.isMainThread()) XCTAssertNotNil(putResponse) XCTAssertTrue(putResponse.ok) XCTAssertEqual(putResponse.entities!.count, 1) @@ -128,7 +139,8 @@ class PUT_Tests: XCTestCase { let propertiesNewValue = "\(propertyNameToUpdate)_VALUE" let putExpect = self.expectationWithDescription(propertyNameToUpdate) - client.PUT(self.query, jsonBody: [propertyNameToUpdate : propertiesNewValue]) { (putResponse) in + Usergrid.PUT(self.query, jsonBody: [propertyNameToUpdate : propertiesNewValue]) { (putResponse) in + XCTAssertTrue(NSThread.isMainThread()) XCTAssertNotNil(putResponse) XCTAssertTrue(putResponse.ok) XCTAssertEqual(putResponse.entities!.count, 3) http://git-wip-us.apache.org/repos/asf/usergrid/blob/891e0f27/sdks/swift/Tests/TestAssets/UsergridGuy.jpg ---------------------------------------------------------------------- diff --git a/sdks/swift/Tests/TestAssets/UsergridGuy.jpg b/sdks/swift/Tests/TestAssets/UsergridGuy.jpg new file mode 100644 index 0000000..035dd7b Binary files /dev/null and b/sdks/swift/Tests/TestAssets/UsergridGuy.jpg differ http://git-wip-us.apache.org/repos/asf/usergrid/blob/891e0f27/sdks/swift/Tests/User_Tests.swift ---------------------------------------------------------------------- diff --git a/sdks/swift/Tests/User_Tests.swift b/sdks/swift/Tests/User_Tests.swift index 845b087..663e322 100644 --- a/sdks/swift/Tests/User_Tests.swift +++ b/sdks/swift/Tests/User_Tests.swift @@ -30,7 +30,6 @@ import CoreLocation class User_Tests: XCTestCase { - let userWithNoName = UsergridUser() var user: UsergridUser! static let name = "Robert Walsh" @@ -50,7 +49,7 @@ class User_Tests: XCTestCase { Usergrid.persistCurrentUserInKeychain = false user = UsergridUser(name:"a_bogus_name", email:User_Tests.email, username:User_Tests.username, password:User_Tests.password) - user["name"] = User_Tests.name + user.name = User_Tests.name user.age = User_Tests.age user.location = CLLocation(latitude: -90, longitude: 100) user.picture = User_Tests.picture @@ -63,6 +62,61 @@ class User_Tests: XCTestCase { super.tearDown() } + func test_USER_INIT() { + user = UsergridUser(email: User_Tests.email, password: User_Tests.password) + XCTAssertNotNil(user) + XCTAssertNotNil(user.email) + XCTAssertNotNil(user.password) + XCTAssertEqual(user.email!, User_Tests.email) + XCTAssertEqual(user.usernameOrEmail!, User_Tests.email) + XCTAssertEqual(user.password!, User_Tests.password) + XCTAssertFalse(user.activated) + XCTAssertFalse(user.disabled) + + user = UsergridUser(name: User_Tests.name, propertyDict: ["password":User_Tests.password]) + XCTAssertNotNil(user) + XCTAssertNotNil(user.name) + XCTAssertNotNil(user.password) + XCTAssertEqual(user.name!, User_Tests.name) + XCTAssertEqual(user.password!, User_Tests.password) + XCTAssertFalse(user.activated) + XCTAssertFalse(user.disabled) + + user = UsergridUser(name:User_Tests.name, email: User_Tests.email, password: User_Tests.password) + XCTAssertNotNil(user) + XCTAssertNotNil(user.name) + XCTAssertNotNil(user.email) + XCTAssertNotNil(user.password) + XCTAssertEqual(user.name!, User_Tests.name) + XCTAssertEqual(user.email!, User_Tests.email) + XCTAssertEqual(user.usernameOrEmail!, User_Tests.email) + XCTAssertEqual(user.password!, User_Tests.password) + XCTAssertFalse(user.activated) + XCTAssertFalse(user.disabled) + + user = UsergridUser(username: User_Tests.username, password: User_Tests.password) + XCTAssertNotNil(user) + XCTAssertNotNil(user.username) + XCTAssertNotNil(user.password) + XCTAssertEqual(user.username!, User_Tests.username) + XCTAssertEqual(user.usernameOrEmail!, User_Tests.username) + XCTAssertEqual(user.password!, User_Tests.password) + XCTAssertFalse(user.activated) + XCTAssertFalse(user.disabled) + + user = UsergridUser(name: User_Tests.name, username: User_Tests.username, password: User_Tests.password) + XCTAssertNotNil(user) + XCTAssertNotNil(user.name) + XCTAssertNotNil(user.username) + XCTAssertNotNil(user.password) + XCTAssertEqual(user.name!, User_Tests.name) + XCTAssertEqual(user.username!, User_Tests.username) + XCTAssertEqual(user.usernameOrEmail!, User_Tests.username) + XCTAssertEqual(user.password!, User_Tests.password) + XCTAssertFalse(user.activated) + XCTAssertFalse(user.disabled) + } + func test_USERS_AND_PROPERTIES_NOT_NIL() { XCTAssertNotNil(user) XCTAssertNotNil(user.name) @@ -73,9 +127,6 @@ class User_Tests: XCTestCase { XCTAssertNotNil(user.picture) XCTAssertNotNil(user.activated) XCTAssertNotNil(user.disabled) - - XCTAssertNotNil(userWithNoName) - XCTAssertNil(userWithNoName.name) } func test_USER_PROPERTIES_WITH_HELPERS() { @@ -104,7 +155,8 @@ class User_Tests: XCTestCase { } func deleteUser(expectation:XCTestExpectation) { - self.user.remove() { (removeResponse) in + self.user.remove() { removeResponse in + XCTAssertTrue(NSThread.isMainThread()) XCTAssertNotNil(removeResponse) XCTAssertTrue(removeResponse.ok) XCTAssertNotNil(removeResponse.user) @@ -118,6 +170,7 @@ class User_Tests: XCTestCase { let userExpect = self.expectationWithDescription("\(__FUNCTION__)") user.save() { (createResponse) in + XCTAssertTrue(NSThread.isMainThread()) XCTAssertNotNil(createResponse) XCTAssertTrue(createResponse.ok) XCTAssertNotNil(createResponse.user) @@ -147,12 +200,14 @@ class User_Tests: XCTestCase { func test_AUTHENTICATE_USER() { let userExpect = self.expectationWithDescription("\(__FUNCTION__)") - UsergridUser.checkAvailable(user.email!,username: user.username) { error,available in + UsergridUser.checkAvailable(user.email, username: user.username) { error,available in + XCTAssertTrue(NSThread.isMainThread()) XCTAssertNil(error) XCTAssertTrue(available) self.user.create() { (createResponse) in + XCTAssertTrue(NSThread.isMainThread()) XCTAssertNotNil(createResponse) XCTAssertTrue(createResponse.ok) XCTAssertNotNil(createResponse.user) @@ -160,28 +215,33 @@ class User_Tests: XCTestCase { XCTAssertNotNil(self.user.uuid) self.user.login(self.user.username!, password:User_Tests.password) { (auth, loggedInUser, error) -> Void in - + XCTAssertTrue(NSThread.isMainThread()) XCTAssertNil(error) XCTAssertNotNil(auth) XCTAssertNotNil(loggedInUser) XCTAssertEqual(auth, self.user.auth!) Usergrid.authenticateUser(self.user.auth!) { auth,currentUser,error in - + XCTAssertTrue(NSThread.isMainThread()) XCTAssertNil(error) XCTAssertNotNil(auth) - XCTAssertNotNil(loggedInUser) XCTAssertEqual(auth, self.user.auth!) + + XCTAssertNotNil(currentUser) XCTAssertNotNil(Usergrid.currentUser) + XCTAssertEqual(currentUser, Usergrid.currentUser!) - self.user.reauthenticate() { auth, user, error in + self.user.reauthenticate() { auth, reauthedUser, error in + XCTAssertTrue(NSThread.isMainThread()) XCTAssertNil(error) XCTAssertNotNil(auth) - XCTAssertNotNil(loggedInUser) XCTAssertEqual(auth, self.user.auth!) + + XCTAssertNotNil(reauthedUser) XCTAssertNotNil(Usergrid.currentUser) self.user.logout() { response in + XCTAssertTrue(NSThread.isMainThread()) XCTAssertNotNil(response) XCTAssertTrue(response.ok) XCTAssertNil(response.error) @@ -200,6 +260,7 @@ class User_Tests: XCTestCase { let userExpect = self.expectationWithDescription("\(__FUNCTION__)") user.create() { (createResponse) in + XCTAssertTrue(NSThread.isMainThread()) XCTAssertNotNil(createResponse) XCTAssertTrue(createResponse.ok) XCTAssertNotNil(createResponse.user) @@ -207,17 +268,19 @@ class User_Tests: XCTestCase { XCTAssertNotNil(self.user.uuid) self.user.login(self.user.username!, password:User_Tests.password) { (auth, loggedInUser, error) -> Void in - + XCTAssertTrue(NSThread.isMainThread()) XCTAssertNil(error) XCTAssertNotNil(auth) XCTAssertNotNil(loggedInUser) XCTAssertEqual(auth, self.user.auth!) self.user.resetPassword(User_Tests.password, new: User_Tests.resetPassword) { error,didSucceed in + XCTAssertTrue(NSThread.isMainThread()) XCTAssertTrue(didSucceed) XCTAssertNil(error) self.user.login(self.user.username!, password:User_Tests.resetPassword) { (auth, loggedInUser, error) -> Void in + XCTAssertTrue(NSThread.isMainThread()) XCTAssertNil(error) XCTAssertNotNil(auth) XCTAssertNotNil(loggedInUser) @@ -269,6 +332,45 @@ class User_Tests: XCTestCase { self.waitForExpectationsWithTimeout(100, handler: nil) } + func test_DEVICE_CONNECT_FAIL() { + let userExpect = self.expectationWithDescription("\(__FUNCTION__)") + + user.create() { createResponse in + XCTAssertNotNil(createResponse) + XCTAssertTrue(createResponse.ok) + XCTAssertNotNil(createResponse.user) + XCTAssertNotNil(createResponse.users) + XCTAssertNotNil(self.user.uuid) + + self.user.connectToDevice() { connectResponse in + XCTAssertNotNil(connectResponse) + XCTAssertTrue(connectResponse.ok) + XCTAssertNil(connectResponse.error) + + self.user.getConnectedDevice() { getConnectedDeviceResponse in + XCTAssertNotNil(getConnectedDeviceResponse) + XCTAssertTrue(getConnectedDeviceResponse.ok) + XCTAssertNil(getConnectedDeviceResponse.error) + XCTAssertNotNil(getConnectedDeviceResponse.entity) + + if let responseEntity = getConnectedDeviceResponse.entity { + XCTAssertTrue(responseEntity is UsergridDevice) + } + + self.user.disconnectFromDevice() { disconnectResponse in + XCTAssertNotNil(disconnectResponse) + XCTAssertTrue(disconnectResponse.ok) + XCTAssertNil(disconnectResponse.error) + + self.deleteUser(userExpect) + } + } + } + } + self.waitForExpectationsWithTimeout(100, handler: nil) + } + + func test_USER_NSCODING() { let userData = NSKeyedArchiver.archivedDataWithRootObject(user) let newInstanceFromData = NSKeyedUnarchiver.unarchiveObjectWithData(userData) as? UsergridUser