diff --git a/openbis-ipad/BisKit/Classes/CISDOBIpadEntity.h b/openbis-ipad/BisKit/Classes/CISDOBIpadEntity.h index fa8a7ee0a6b09f821a4dd249dd873b58f4c48074..a59e17b519f2dd2b249d3dac3920f9a10ef8e91b 100644 --- a/openbis-ipad/BisKit/Classes/CISDOBIpadEntity.h +++ b/openbis-ipad/BisKit/Classes/CISDOBIpadEntity.h @@ -25,6 +25,10 @@ #import <CoreData/CoreData.h> +/** + * \brief A persistent version of an entity from the iPad server. + */ +@class CISDOBIpadRawEntity; @interface CISDOBIpadEntity : NSManagedObject @property (nonatomic, retain) NSString * summaryHeader; @@ -35,4 +39,8 @@ @property (nonatomic, retain) NSString * entityType; @property (nonatomic, retain) NSString * propertiesJson; +// Actions +//! Take the values from the raw entity. +- (void)initializeFromRawEntity:(CISDOBIpadRawEntity *)rawEntity; + @end diff --git a/openbis-ipad/BisKit/Classes/CISDOBIpadEntity.m b/openbis-ipad/BisKit/Classes/CISDOBIpadEntity.m index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..857b36ab01934ba44b1d248c342940a1b4414249 100644 --- a/openbis-ipad/BisKit/Classes/CISDOBIpadEntity.m +++ b/openbis-ipad/BisKit/Classes/CISDOBIpadEntity.m @@ -0,0 +1,49 @@ +/* + * Copyright 2012 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// CISDOBIpadEntity.m +// BisMac +// +// Created by Ramakrishnan Chandrasekhar on 10/1/12. +// +// + +#import "CISDOBIpadEntity.h" +#import "CISDOBIpadService.h" + + +@implementation CISDOBIpadEntity + +@dynamic summaryHeader; +@dynamic summary; +@dynamic identifier; +@dynamic permId; +@dynamic entityKind; +@dynamic entityType; +@dynamic propertiesJson; + +- (void)initializeFromRawEntity:(CISDOBIpadRawEntity *)rawEntity +{ + self.summaryHeader = rawEntity.summaryHeader; + self.summary = rawEntity.summary; + self.identifier = rawEntity.identifier; + self.permId = rawEntity.permId; + self.entityKind = rawEntity.entityKind; + self.entityType = rawEntity.entityType; + self.propertiesJson = rawEntity.properties; +} + +@end diff --git a/openbis-ipad/BisKit/Classes/persistent-data-model.xcdatamodeld/persistent-data-model.xcdatamodel/contents b/openbis-ipad/BisKit/Classes/persistent-data-model.xcdatamodeld/persistent-data-model.xcdatamodel/contents index daa1decc9a6941fdbb9d96d76ecf36d50932a917..fd3c08da241eae987aa220afaf94983a70262fbd 100644 --- a/openbis-ipad/BisKit/Classes/persistent-data-model.xcdatamodeld/persistent-data-model.xcdatamodel/contents +++ b/openbis-ipad/BisKit/Classes/persistent-data-model.xcdatamodeld/persistent-data-model.xcdatamodel/contents @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <model name="" userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="1810" systemVersion="11G56" minimumToolsVersion="Xcode 4.3" macOSVersion="Automatic" iOSVersion="Automatic"> - <entity name="CISDOBIpadEntity" representedClassName="CIDOBIpadEntity" syncable="YES"> + <entity name="CISDOBIpadEntity" representedClassName="CISDOBIpadEntity" syncable="YES"> <attribute name="entityKind" optional="YES" attributeType="String" syncable="YES"/> <attribute name="entityType" optional="YES" attributeType="String" syncable="YES"/> <attribute name="identifier" optional="YES" attributeType="String" syncable="YES"/> @@ -10,6 +10,6 @@ <attribute name="summaryHeader" optional="YES" attributeType="String" syncable="YES"/> </entity> <elements> - <element name="CISDOBIpadEntity" positionX="0" positionY="0" width="0" height="0"/> + <element name="CISDOBIpadEntity" positionX="160" positionY="192" width="128" height="150"/> </elements> </model> \ No newline at end of file diff --git a/openbis-ipad/BisKit/Tests/CISDOBIpadEntityTest.h b/openbis-ipad/BisKit/Tests/CISDOBIpadEntityTest.h index 388b95780a2c216f4d9597b5ea8e01fe50d213d4..84306dd23c08afc2f4bbaf8e4aab46be84752dff 100644 --- a/openbis-ipad/BisKit/Tests/CISDOBIpadEntityTest.h +++ b/openbis-ipad/BisKit/Tests/CISDOBIpadEntityTest.h @@ -20,11 +20,11 @@ // Created by Ramakrishnan Chandrasekhar on 10/2/12. // -#import <SenTestingKit/SenTestingKit.h> +#import "CISDOBAsyncTest.h" // Test the persistence of iPad entities. @class CISDOBIpadService; -@interface CISDOBIpadEntityTest : SenTestCase +@interface CISDOBIpadEntityTest : CISDOBAsyncTest @property(strong) CISDOBIpadService *service; @property(strong) NSURL *databaseUrl; diff --git a/openbis-ipad/BisKit/Tests/CISDOBIpadEntityTest.m b/openbis-ipad/BisKit/Tests/CISDOBIpadEntityTest.m index 74e04e8b2f0add05d6dcc0d29cc0b78a1769e51c..6e5be38c660ed01ca4a1986dd999ff27a9dca0bb 100644 --- a/openbis-ipad/BisKit/Tests/CISDOBIpadEntityTest.m +++ b/openbis-ipad/BisKit/Tests/CISDOBIpadEntityTest.m @@ -27,13 +27,10 @@ NSManagedObjectContext* GetDatabaseManagedObjectContext(NSURL* storeURL, NSError** error) { - NSManagedObjectModel* mom = [NSManagedObjectModel mergedModelFromBundles: nil]; - // Explicitly specify which db schema we want to use -// NSBundle* bundle = [NSBundle bundleForClass: [CISDOBIpadEntity class]]; -// NSString* momPath = [bundle pathForResource: @"persistent-data-model" ofType: @"mom"]; -// NSLog(@"Mom %@", momPath); -// NSManagedObjectModel* mom = [[NSManagedObjectModel alloc] initWithContentsOfURL: [NSURL fileURLWithPath: momPath]]; + NSBundle* bundle = [NSBundle bundleForClass: [CISDOBIpadEntity class]]; + NSString* momPath = [bundle pathForResource: @"persistent-data-model" ofType: @"momd"]; + NSManagedObjectModel* mom = [[NSManagedObjectModel alloc] initWithContentsOfURL: [NSURL fileURLWithPath: momPath]]; NSManagedObjectContext* moc = [[NSManagedObjectContext alloc] init]; NSPersistentStoreCoordinator* coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: mom]; @@ -76,4 +73,55 @@ NSManagedObjectContext* GetDatabaseManagedObjectContext(NSURL* storeURL, NSError [super tearDown]; } +- (void)configureAndRunCallSynchronously:(CISDOBAsyncCall *)call +{ + [self configureCall: call]; + + // The ipad service may make multiple calls, so take that into account. + int waitTime = ((int) _service.connection.timeoutInterval) * 2; + [self waitSeconds: waitTime forCallToComplete: call]; +} + +- (void)checkPersistRawEntities:(NSArray *)rawEntities +{ + STAssertTrue([rawEntities count] > 0, @"The Pad service should have returned some entities."); + + for (CISDOBIpadRawEntity *rawEntity in rawEntities) { + // Create new entities in the moc, and store them. + CISDOBIpadEntity *entity = [NSEntityDescription insertNewObjectForEntityForName: @"CISDOBIpadEntity" inManagedObjectContext: _moc]; + [entity initializeFromRawEntity: rawEntity]; + } + + NSError *error; + STAssertTrue([_moc save: &error], @"Could not save data %@", error); +} + +- (void)checkEntityCardnalityEquals:(NSUInteger)count +{ + NSError* error; + NSFetchRequest* request = [[NSFetchRequest alloc] init]; + NSEntityDescription* entity = [NSEntityDescription entityForName: @"CISDOBIpadEntity" inManagedObjectContext: _moc]; + [request setEntity: entity]; + NSArray* elements = [_moc executeFetchRequest: request error: &error]; + STAssertEquals([elements count], count, @"%llu in db != %llu from server", [elements count], count); +} + +- (void)testPersistEntities +{ + CISDOBAsyncCall *call; + call = [_service loginUser: GetDefaultUserName() password: GetDefaultUserPassword()]; + [self configureAndRunCallSynchronously: call]; + + call = [_service listAllEntities]; + [self configureAndRunCallSynchronously: call]; + + STAssertNotNil(_callResult, @"The iPad service should have returned some entities."); + + // Check that we can persist the entities + [self checkPersistRawEntities: _callResult]; + + // Check that the cardnality is equal + [self checkEntityCardnalityEquals: [_callResult count]]; +} + @end diff --git a/openbis-ipad/BisMac.xcodeproj/project.xcworkspace/xcuserdata/cramakri.xcuserdatad/UserInterfaceState.xcuserstate b/openbis-ipad/BisMac.xcodeproj/project.xcworkspace/xcuserdata/cramakri.xcuserdatad/UserInterfaceState.xcuserstate index add5679d22386a29d2166225a01779345dd9feda..03b31361b207009517a16a5db9ac875a6056b7e3 100644 Binary files a/openbis-ipad/BisMac.xcodeproj/project.xcworkspace/xcuserdata/cramakri.xcuserdatad/UserInterfaceState.xcuserstate and b/openbis-ipad/BisMac.xcodeproj/project.xcworkspace/xcuserdata/cramakri.xcuserdatad/UserInterfaceState.xcuserstate differ