FRANotificationTest.m revision a3970d0ea62388e4ede01470a6436eb5c6c92353
2086N/A/*
2086N/A * The contents of this file are subject to the terms of the Common Development and
2086N/A * Distribution License (the License). You may not use this file except in compliance with the
2086N/A * License.
2086N/A *
2086N/A * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
2086N/A * specific language governing permission and limitations under the License.
2086N/A *
2086N/A * When distributing Covered Software, include this CDDL Header Notice in each file and include
2086N/A * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
2086N/A * Header, with the fields enclosed by brackets [] replaced by your own identifying
2086N/A * information: "Portions copyright [year] [name of copyright owner]".
2086N/A *
2086N/A * Copyright 2016 ForgeRock AS.
2086N/A */
2086N/A
2086N/A#import <Foundation/Foundation.h>
2086N/A#import <OCMock/OCMock.h>
2086N/A#import <XCTest/XCTest.h>
2086N/A
2086N/A#import "FRAIdentityDatabase.h"
2086N/A#import "FRAIdentityDatabaseSQLiteOperations.h"
2086N/A#import "FRANotification.h"
2086N/A
2086N/A@interface FRANotificationTest : XCTestCase
2086N/A
2086N/A@end
2086N/A
2086N/A@implementation FRANotificationTest {
2086N/A
2086N/A FRAIdentityDatabaseSQLiteOperations *mockSqlOperations;
2086N/A FRAIdentityDatabase *database;
2086N/A FRANotification* notification;
2086N/A id databaseObserverMock;
2086N/A
2086N/A}
2086N/A
2086N/A- (void)setUp {
2086N/A [super setUp];
2086N/A mockSqlOperations = OCMClassMock([FRAIdentityDatabaseSQLiteOperations class]);
2086N/A database = [[FRAIdentityDatabase alloc] initWithSqlOperations:mockSqlOperations];
2086N/A NSTimeInterval timeToLive = 120.0;
2086N/A notification = [[FRANotification alloc] initWithDatabase:database messageId:@"messageId" challenge:@"challenge" timeReceived:[NSDate date] timeToLive:timeToLive];
2086N/A databaseObserverMock = OCMObserverMock();
2086N/A}
2086N/A
- (void)tearDown {
[super tearDown];
}
- (void)testInitialStateOfNotification {
// Given
// When
// Then
XCTAssertEqual([notification isPending], YES);
XCTAssertEqual([notification isApproved], NO);
}
- (void)testShouldApproveNotification {
// Given
// When
[notification approve];
// Then
XCTAssertEqual([notification isPending], NO);
XCTAssertEqual([notification isApproved], YES);
}
- (void)testShouldDenyNotification {
// Given
// When
[notification deny];
// Then
XCTAssertEqual([notification isPending], NO);
XCTAssertEqual([notification isApproved], NO);
}
- (void)testSavedNotificationAutomaticallySavesItselfToDatabaseWhenApproved {
// Given
[database insertNotification:notification];
// When
[notification approve];
// Then
OCMVerify([mockSqlOperations updateNotification:notification]);
}
- (void)testSavedNotificationAutomaticallySavesItselfToDatabaseWhenDenied {
// Given
[database insertNotification:notification];
// When
[notification deny];
// Then
OCMVerify([mockSqlOperations updateNotification:notification]);
}
- (void)testBroadcastsOneChangeNotificationWhenNotificationUpdateIsAutomaticallySavedToDatabase {
// Given
[database insertNotification:notification];
[[NSNotificationCenter defaultCenter] addMockObserver:databaseObserverMock name:FRAIdentityDatabaseChangedNotification object:database];
[[databaseObserverMock expect] notificationWithName:FRAIdentityDatabaseChangedNotification object:database userInfo:[OCMArg any]];
// When
[notification approve];
// Then
OCMVerifyAll(databaseObserverMock);
}
@end