chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1425870 [10/13] - in /chemistry/objectivecmis/trunk: ./ ObjectiveCMIS.xcodeproj/ ObjectiveCMIS.xcodeproj/project.xcworkspace/ ObjectiveCMIS/ ObjectiveCMIS/Bindings/ ObjectiveCMIS/Bindings/AtomPub/ ObjectiveCMIS/Bindings/AtomPub/AtomPubPars...
Date Wed, 26 Dec 2012 10:48:37 GMT
Added: chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISObjectConverter.m
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISObjectConverter.m?rev=1425870&view=auto
==============================================================================
--- chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISObjectConverter.m (added)
+++ chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISObjectConverter.m Wed Dec 26 10:48:33
2012
@@ -0,0 +1,361 @@
+/*
+    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.
+ */
+
+#import <Foundation/Foundation.h>
+#import "CMISObjectConverter.h"
+#import "CMISDocument.h"
+#import "CMISFolder.h"
+#import "CMISTypeDefinition.h"
+#import "CMISErrors.h"
+#import "CMISPropertyDefinition.h"
+#import "CMISSession.h"
+#import "CMISConstants.h"
+#import "CMISDateUtil.h"
+
+@interface CMISObjectConverter ()
+@property (nonatomic, weak) CMISSession *session;
+@end
+
+@implementation CMISObjectConverter
+
+@synthesize session = _session;
+
+- (id)initWithSession:(CMISSession *)session
+{
+    self = [super init];
+    if (self)
+    {
+        self.session = session;
+    }
+    
+    return self;
+}
+
+- (CMISObject *)convertObject:(CMISObjectData *)objectData
+{
+    CMISObject *object = nil;
+    
+    if (objectData.baseType == CMISBaseTypeDocument)
+    {
+        object = [[CMISDocument alloc] initWithObjectData:objectData withSession:self.session];
+    }
+    else if (objectData.baseType == CMISBaseTypeFolder)
+    {
+        object = [[CMISFolder alloc] initWithObjectData:objectData withSession:self.session];
+    }
+    
+    return object;
+}
+
+- (CMISCollection *)convertObjects:(NSArray *)objects
+{
+    NSMutableArray *items = [[NSMutableArray alloc] initWithCapacity:[objects count]];
+    
+    for (CMISObjectData *object in objects) 
+    {
+        [items addObject:[self convertObject:object]];
+    }
+    
+    // create the collection
+    CMISCollection *collection = [[CMISCollection alloc] initWithItems:items];
+    
+    return collection;
+}
+
+
+- (void)convertProperties:(NSDictionary *)properties 
+          forObjectTypeId:(NSString *)objectTypeId 
+          completionBlock:(void (^)(CMISProperties *convertedProperties, NSError *error))completionBlock
+{
+    [self internalNormalConvertProperties:properties objectTypeId:objectTypeId completionBlock:completionBlock];
+}
+
+
+- (void)internalNormalConvertProperties:(NSDictionary *)properties 
+                         typeDefinition:(CMISTypeDefinition *)typeDefinition 
+                        completionBlock:(void (^)(CMISProperties *convertedProperties, NSError
*error))completionBlock
+{
+    CMISProperties *convertedProperties = [[CMISProperties alloc] init];
+    for (NSString *propertyId in properties) {
+        id propertyValue = [properties objectForKey:propertyId];
+        // If the value is already a CMISPropertyData, we don't need to do anything
+        if ([propertyValue isKindOfClass:[CMISPropertyData class]])
+        {
+            [convertedProperties addProperty:(CMISPropertyData *)propertyValue];
+        }
+        else
+        {
+            // Convert to CMISPropertyData based on the string
+            CMISPropertyDefinition *propertyDefinition = [typeDefinition propertyDefinitionForId:propertyId];
+            
+            if (propertyDefinition == nil)
+            {
+                NSError *error = [CMISErrors createCMISErrorWithCode:kCMISErrorCodeInvalidArgument
+                                             withDetailedDescription:[NSString stringWithFormat:@"Invalid
property '%@' for this object type", propertyId]];
+                completionBlock(nil, error);
+                return;
+            }
+            
+            Class expectedType = nil;
+            BOOL validType = YES;
+            
+            switch (propertyDefinition.propertyType)
+            {
+                case(CMISPropertyTypeString):
+                {
+                    expectedType = [NSString class];
+                    if ([propertyValue isKindOfClass:expectedType]) {
+                        [convertedProperties addProperty:[CMISPropertyData createPropertyForId:propertyId
withStringValue:propertyValue]];
+                    } else if ([propertyValue isKindOfClass:[NSArray class]]) {
+                        for (id propertyValueItemValue in propertyValue) {
+                            if (![propertyValueItemValue isKindOfClass:expectedType]) {
+                                validType = NO;
+                                break;
+                            }
+                        }
+                        if (validType) {
+                            [convertedProperties addProperty:[CMISPropertyData createPropertyForId:propertyId
withArrayValue:propertyValue type:propertyDefinition.propertyType]];
+                        }
+                    } else {
+                        validType = NO;
+                    }
+                    break;
+                }
+                case(CMISPropertyTypeBoolean):
+                {
+                    expectedType = [NSNumber class];
+                    if ([propertyValue isKindOfClass:expectedType]) {
+                        BOOL boolValue = ((NSNumber *) propertyValue).boolValue;
+                        [convertedProperties addProperty:[CMISPropertyData createPropertyForId:propertyId
withBoolValue:boolValue]];
+                    } else if ([propertyValue isKindOfClass:[NSArray class]]) {
+                        for (id propertyValueItemValue in propertyValue) {
+                            if (![propertyValueItemValue isKindOfClass:expectedType]) {
+                                validType = NO;
+                                break;
+                            }
+                        }
+                        if (validType) {
+                            [convertedProperties addProperty:[CMISPropertyData createPropertyForId:propertyId
withArrayValue:propertyValue type:propertyDefinition.propertyType]];
+                        }
+                    } else {
+                        validType = NO;
+                    }
+                    break;
+                }
+                case(CMISPropertyTypeInteger):
+                {
+                    expectedType = [NSNumber class];
+                    if ([propertyValue isKindOfClass:expectedType]) {
+                        NSInteger intValue = ((NSNumber *) propertyValue).integerValue;
+                        [convertedProperties addProperty:[CMISPropertyData createPropertyForId:propertyId
withIntegerValue:intValue]];
+                    } else if ([propertyValue isKindOfClass:[NSArray class]]) {
+                        for (id propertyValueItemValue in propertyValue) {
+                            if (![propertyValueItemValue isKindOfClass:expectedType]) {
+                                validType = NO;
+                                break;
+                            }
+                        }
+                        if (validType) {
+                            [convertedProperties addProperty:[CMISPropertyData createPropertyForId:propertyId
withArrayValue:propertyValue type:propertyDefinition.propertyType]];
+                        }
+                    } else {
+                        validType = NO;
+                    }
+                    break;
+                }
+                case(CMISPropertyTypeDecimal):
+                {
+                    expectedType = [NSNumber class];
+                    if ([propertyValue isKindOfClass:expectedType]) {
+                        [convertedProperties addProperty:[CMISPropertyData createPropertyForId:propertyId
withDecimalValue:propertyValue]];
+                    } else if ([propertyValue isKindOfClass:[NSArray class]]) {
+                        for (id propertyValueItemValue in propertyValue) {
+                            if (![propertyValueItemValue isKindOfClass:expectedType]) {
+                                validType = NO;
+                                break;
+                            }
+                        }
+                        if (validType) {
+                            [convertedProperties addProperty:[CMISPropertyData createPropertyForId:propertyId
withArrayValue:propertyValue type:propertyDefinition.propertyType]];
+                        }
+                    } else {
+                        validType = NO;
+                    }
+                    break;
+                }
+                case(CMISPropertyTypeId):
+                {
+                    expectedType = [NSString class];
+                    if ([propertyValue isKindOfClass:expectedType]) {
+                        [convertedProperties addProperty:[CMISPropertyData createPropertyForId:propertyId
withIdValue:propertyValue]];
+                    } else if ([propertyValue isKindOfClass:[NSArray class]]) {
+                        for (id propertyValueItemValue in propertyValue) {
+                            if (![propertyValueItemValue isKindOfClass:expectedType]) {
+                                validType = NO;
+                                break;
+                            }
+                        }
+                        if (validType) {
+                            [convertedProperties addProperty:[CMISPropertyData createPropertyForId:propertyId
withArrayValue:propertyValue type:propertyDefinition.propertyType]];
+                        }
+                    } else {
+                        validType = NO;
+                    }
+                    break;
+                }
+                case(CMISPropertyTypeDateTime):
+                {
+                    if ([propertyValue isKindOfClass:[NSString class]]) {
+                        propertyValue = [CMISDateUtil dateFromString:propertyValue];
+                    }
+                    expectedType = [NSDate class];
+                    if ([propertyValue isKindOfClass:expectedType]) {
+                        [convertedProperties addProperty:[CMISPropertyData createPropertyForId:propertyId
withDateTimeValue:propertyValue]];
+                    } else if ([propertyValue isKindOfClass:[NSArray class]]) {
+                        for (__strong id propertyValueItemValue in propertyValue) {
+                            if ([propertyValueItemValue isKindOfClass:[NSString class]])
{
+                                propertyValueItemValue = [CMISDateUtil dateFromString:propertyValueItemValue];
+                            }
+                            if (![propertyValueItemValue isKindOfClass:expectedType]) {
+                                validType = NO;
+                                break;
+                            }
+                        }
+                        if (validType) {
+                            [convertedProperties addProperty:[CMISPropertyData createPropertyForId:propertyId
withArrayValue:propertyValue type:propertyDefinition.propertyType]];
+                        }
+                    } else {
+                        validType = NO;
+                    }
+                    break;
+                }
+                case(CMISPropertyTypeUri):
+                {
+                    if ([propertyValue isKindOfClass:[NSString class]]) {
+                        propertyValue = [NSURL URLWithString:propertyValue];
+                    }
+                    expectedType = [NSURL class];
+                    if ([propertyValue isKindOfClass:expectedType]) {
+                        [convertedProperties addProperty:[CMISPropertyData createPropertyForId:propertyId
withUriValue:propertyValue]];
+                    } else if ([propertyValue isKindOfClass:[NSArray class]]) {
+                        for (__strong id propertyValueItemValue in propertyValue) {
+                            if ([propertyValueItemValue isKindOfClass:[NSString class]])
{
+                                propertyValueItemValue = [NSURL URLWithString:propertyValueItemValue];
+                            }
+                            if (![propertyValueItemValue isKindOfClass:expectedType]) {
+                                validType = NO;
+                                break;
+                            }
+                        }
+                        if (validType) {
+                            [convertedProperties addProperty:[CMISPropertyData createPropertyForId:propertyId
withArrayValue:propertyValue type:propertyDefinition.propertyType]];
+                        }
+                    } else {
+                        validType = NO;
+                    }
+                    break;
+                }
+                case(CMISPropertyTypeHtml):
+                {
+                    expectedType = [NSString class];
+                    if ([propertyValue isKindOfClass:expectedType]) {
+                        [convertedProperties addProperty:[CMISPropertyData createPropertyForId:propertyId
withHtmlValue:propertyValue]];
+                    } else if ([propertyValue isKindOfClass:[NSArray class]]) {
+                        for (id propertyValueItemValue in propertyValue) {
+                            if (![propertyValueItemValue isKindOfClass:expectedType]) {
+                                validType = NO;
+                                break;
+                            }
+                        }
+                        if (validType) {
+                            [convertedProperties addProperty:[CMISPropertyData createPropertyForId:propertyId
withArrayValue:propertyValue type:propertyDefinition.propertyType]];
+                        }
+                    } else {
+                        validType = NO;
+                    }
+                    break;
+                }
+                default:
+                {
+                    NSError *error = [CMISErrors createCMISErrorWithCode:kCMISErrorCodeInvalidArgument
+                                                 withDetailedDescription:[NSString stringWithFormat:@"Unsupported:
cannot convert property type %d", propertyDefinition.propertyType]];
+                    completionBlock(nil, error);
+                    return;
+                }
+            }
+            
+            if (!validType) {
+                NSError *error = [CMISErrors createCMISErrorWithCode:kCMISErrorCodeInvalidArgument
+                                             withDetailedDescription:[NSString stringWithFormat:@"Property
value for %@ should be of type '%@'", propertyId, expectedType]];
+                completionBlock(nil, error);
+                return;
+            }
+        }
+    }
+    
+    completionBlock(convertedProperties, nil);
+}
+
+
+- (void)internalNormalConvertProperties:(NSDictionary *)properties
+                           objectTypeId:(NSString *)objectTypeId
+                        completionBlock:(void (^)(CMISProperties *convertedProperties, NSError
*error))completionBlock
+
+{
+    // Validate params
+    if (!properties)
+    {
+        completionBlock(nil, nil);
+        return;
+    }
+
+    BOOL onlyPropertyData = YES;
+    for (id propertyValue in properties.objectEnumerator) {
+        if (![propertyValue isKindOfClass:[CMISPropertyData class]]) {
+            if ([propertyValue isKindOfClass:[NSArray class]]) {
+                for (id propertyValueItemValue in propertyValue) {
+                    if (![propertyValueItemValue isKindOfClass:[CMISPropertyData class]])
{
+                        onlyPropertyData = NO;
+                        break;
+                    }
+                }
+            } else {
+                onlyPropertyData = NO;
+            }
+            break;
+        }
+    }
+    
+    // Convert properties
+    if (onlyPropertyData) {
+        [self internalNormalConvertProperties:properties
+                               typeDefinition:nil // not needed because all properties are
of type CMISPropertyData
+                              completionBlock:completionBlock];
+        
+    } else {
+        [self.session.binding.repositoryService
+         retrieveTypeDefinition:objectTypeId
+         completionBlock:^(CMISTypeDefinition *typeDefinition, NSError *error) {
+             if (error) {
+                 completionBlock(nil, [CMISErrors cmisError:error withCMISErrorCode:kCMISErrorCodeRuntime]);
+             } else {
+                 [self internalNormalConvertProperties:properties
+                                        typeDefinition:typeDefinition
+                                       completionBlock:completionBlock];
+             }
+         }];
+    }
+}
+
+@end

Propchange: chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISObjectConverter.m
------------------------------------------------------------------------------
    svn:eol-style = native

Added: chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISStringInOutParameter.h
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISStringInOutParameter.h?rev=1425870&view=auto
==============================================================================
--- chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISStringInOutParameter.h (added)
+++ chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISStringInOutParameter.h Wed Dec 26
10:48:33 2012
@@ -0,0 +1,31 @@
+/*
+    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.
+ */
+
+#import <Foundation/Foundation.h>
+
+/**
+ * Simple wrapper class for parameters that are needed as input for a
+ * certain operation, but which can also change as a result of executing
+ * that operation.
+ *
+ * Used for example for operations with multiple return results.
+ */
+@interface CMISStringInOutParameter : NSObject
+
+@property (nonatomic, strong) NSString *inParameter;
+@property (nonatomic, strong) NSString *outParameter;
+
++ (CMISStringInOutParameter *)inOutParameterUsingInParameter:(NSString *)inParameter;
+
+@end
\ No newline at end of file

Propchange: chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISStringInOutParameter.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISStringInOutParameter.m
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISStringInOutParameter.m?rev=1425870&view=auto
==============================================================================
--- chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISStringInOutParameter.m (added)
+++ chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISStringInOutParameter.m Wed Dec 26
10:48:33 2012
@@ -0,0 +1,31 @@
+/*
+    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.
+ */
+
+#import "CMISStringInOutParameter.h"
+
+
+@implementation CMISStringInOutParameter
+
+@synthesize inParameter = _inParameter;
+@synthesize outParameter = _outParameter;
+
++ (CMISStringInOutParameter *)inOutParameterUsingInParameter:(NSString *)inParameter
+{
+    CMISStringInOutParameter *result = [[CMISStringInOutParameter alloc] init];
+    result.inParameter = inParameter;
+    return result;
+}
+
+
+@end
\ No newline at end of file

Propchange: chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISStringInOutParameter.m
------------------------------------------------------------------------------
    svn:eol-style = native

Added: chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISURLUtil.h
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISURLUtil.h?rev=1425870&view=auto
==============================================================================
--- chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISURLUtil.h (added)
+++ chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISURLUtil.h Wed Dec 26 10:48:33 2012
@@ -0,0 +1,23 @@
+/*
+    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.
+ */
+#import <Foundation/Foundation.h>
+
+
+@interface CMISURLUtil : NSObject
+
++ (NSString *)urlStringByAppendingParameter:(NSString *)parameterName withValue:(NSString
*)parameterValue toUrlString:(NSString *)urlString;
+
++ (NSURL *)urlStringByAppendingParameter:(NSString *)parameterName withValue:(NSString *)parameterValue
toUrl:(NSURL *)url;
+
+@end
\ No newline at end of file

Propchange: chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISURLUtil.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISURLUtil.m
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISURLUtil.m?rev=1425870&view=auto
==============================================================================
--- chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISURLUtil.m (added)
+++ chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISURLUtil.m Wed Dec 26 10:48:33 2012
@@ -0,0 +1,52 @@
+/*
+    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.
+ */
+#import <Foundation/Foundation.h>
+#import "CMISURLUtil.h"
+
+
+@implementation CMISURLUtil
+
++ (NSString *)urlStringByAppendingParameter:(NSString *)parameterName withValue:(NSString
*)parameterValue toUrlString:(NSString *)urlString
+{
+    if (parameterName == nil || parameterValue == nil)
+    {
+        return urlString;
+    }
+
+    NSMutableString *result = [NSMutableString stringWithString:urlString];
+
+    // Append '?' if not yet in url, else append ampersand
+    if ([result rangeOfString:@"?"].location == NSNotFound)
+    {
+        [result appendString:@"?"];
+    }
+    else
+    {
+        [result appendString:@"&"];
+    }
+
+    // Append param
+    [result appendString:parameterName];
+    [result appendString:@"="];
+    [result appendString:[parameterValue stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
+
+    return result;
+}
+
++ (NSURL *)urlStringByAppendingParameter:(NSString *)parameterName withValue:(NSString *)parameterValue
toUrl:(NSURL *)url
+{
+    return [NSURL URLWithString:[CMISURLUtil urlStringByAppendingParameter:parameterName
withValue:parameterValue toUrlString:[url absoluteString]]];
+}
+
+@end
\ No newline at end of file

Propchange: chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISURLUtil.m
------------------------------------------------------------------------------
    svn:eol-style = native

Added: chemistry/objectivecmis/trunk/ObjectiveCMISTests/CMISBaseTest.h
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/trunk/ObjectiveCMISTests/CMISBaseTest.h?rev=1425870&view=auto
==============================================================================
--- chemistry/objectivecmis/trunk/ObjectiveCMISTests/CMISBaseTest.h (added)
+++ chemistry/objectivecmis/trunk/ObjectiveCMISTests/CMISBaseTest.h Wed Dec 26 10:48:33 2012
@@ -0,0 +1,55 @@
+/*
+    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.
+ */
+#import <Foundation/Foundation.h>
+#import <SenTestingKit/SenTestingKit.h>
+#import "CMISDocument.h"
+
+@class CMISFolder;
+@class CMISSession;
+@class CMISSessionParameters;
+
+typedef void (^CMISTestBlock)(void);
+
+@interface CMISBaseTest : SenTestCase
+
+@property (nonatomic, strong) CMISSessionParameters *parameters;
+@property (nonatomic, strong) CMISSession *session;
+@property (nonatomic, strong) CMISFolder *rootFolder;
+@property BOOL testCompleted;
+
+#pragma mark Running the test
+
+- (void) runTest:(CMISTestBlock)testBlock;
+- (void) runTest:(CMISTestBlock)testBlock withExtraSessionParameters:(NSDictionary *)extraSessionParameters;
+
+#pragma mark Configuration of cmis parameters
+
+// Subclasses can override this. The parameter key-value pairs will be added to the
+// session parameters before construction of the cmis session.
+- (NSDictionary *)customCmisParameters;
+
+#pragma mark Helper Methods
+
+- (void)retrieveVersionedTestDocumentWithCompletionBlock:(void (^)(CMISDocument *document))completionBlock;
+
+- (void)uploadTestFileWithCompletionBlock:(void (^)(CMISDocument *document))completionBlock;
+
+- (void)deleteDocumentAndVerify:(CMISDocument *)document completionBlock:(void (^)(void))completionBlock;
+
+- (void)waitForCompletion:(NSTimeInterval)timeoutSecs;
+
+- (NSDateFormatter *)testDateFormatter;
+
+- (NSString *)stringFromCurrentDate;
+@end
\ No newline at end of file

Propchange: chemistry/objectivecmis/trunk/ObjectiveCMISTests/CMISBaseTest.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: chemistry/objectivecmis/trunk/ObjectiveCMISTests/CMISBaseTest.m
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/trunk/ObjectiveCMISTests/CMISBaseTest.m?rev=1425870&view=auto
==============================================================================
--- chemistry/objectivecmis/trunk/ObjectiveCMISTests/CMISBaseTest.m (added)
+++ chemistry/objectivecmis/trunk/ObjectiveCMISTests/CMISBaseTest.m Wed Dec 26 10:48:33 2012
@@ -0,0 +1,211 @@
+/*
+    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.
+ */
+#import "CMISBaseTest.h"
+#import "CMISFolder.h"
+#import "CMISSession.h"
+#import "CMISConstants.h"
+
+
+@implementation CMISBaseTest
+
+@synthesize parameters = _parameters;
+@synthesize session = _session;
+@synthesize rootFolder = _rootFolder;
+@synthesize testCompleted = _testCompleted;
+
+
+- (void) runTest:(CMISTestBlock)testBlock
+{
+    [self runTest:testBlock withExtraSessionParameters:nil];
+}
+
+- (void) runTest:(CMISTestBlock)testBlock withExtraSessionParameters:(NSDictionary *)extraSessionParameters
+{
+    NSBundle *bundle = [NSBundle bundleForClass:[self class]];
+    STAssertNotNil(bundle, @"Bundle is nil!");
+
+    NSString *envsPListPath = [bundle pathForResource:@"env-cfg" ofType:@"plist"];
+    STAssertNotNil(envsPListPath, @"envsPListPath is nil!");
+
+    NSDictionary *environmentsDict = [[NSDictionary alloc] initWithContentsOfFile:envsPListPath];
+    STAssertNotNil(environmentsDict, @"environmentsDict is nil!");
+
+    NSArray *environmentArray = [environmentsDict objectForKey:@"environments"];
+    STAssertNotNil(environmentArray, @"environmentArray is nil!");
+
+    for (NSDictionary *envDict in environmentArray)
+    {
+        NSString *url = [envDict valueForKey:@"url"];
+        NSString *repositoryId = [envDict valueForKey:@"repositoryId"];
+        NSString *username = [envDict valueForKey:@"username"];
+        NSString *password = [envDict valueForKey:@"password"];
+
+        self.testCompleted = NO;
+        [self setupCmisSession:url repositoryId:repositoryId username:username password:password
extraSessionParameters:extraSessionParameters completionBlock:^{
+            self.testCompleted = NO;
+            
+            log(@">------------------- Running test against %@ -------------------<",
url);
+            
+            testBlock();
+        }];
+        [self waitForCompletion:90];
+    }
+}
+
+- (void)setupCmisSession:(NSString *)url repositoryId:(NSString *)repositoryId username:(NSString
*)username
+                  password:(NSString *)password extraSessionParameters:(NSDictionary *)extraSessionParameters
+         completionBlock:(void (^)(void))completionBlock
+{
+    self.parameters = [[CMISSessionParameters alloc] initWithBindingType:CMISBindingTypeAtomPub];
+    self.parameters.username = username;
+    self.parameters.password = password;
+    self.parameters.atomPubUrl = [NSURL URLWithString:url];
+    self.parameters.repositoryId = repositoryId;
+
+    // Extra cmis params could be provided as method parameter
+    if (extraSessionParameters != nil)
+    {
+        for (id extraSessionParamKey in extraSessionParameters)
+        {
+            [self.parameters setObject:[extraSessionParameters objectForKey:extraSessionParamKey]
forKey:extraSessionParamKey];
+        }
+    }
+
+    // Or, extra cmis parameters could be provided by overriding a base method
+    NSDictionary *customParameters = [self customCmisParameters];
+    if (customParameters)
+    {
+        for (id customParamKey in customParameters)
+        {
+            [self.parameters setObject:[customParameters objectForKey:customParamKey] forKey:customParamKey];
+        }
+    }
+    [CMISSession connectWithSessionParameters:self.parameters completionBlock:^(CMISSession
*session, NSError *error){
+        if (nil == session)
+        {
+
+        }
+        else
+        {
+            self.session = session;
+            STAssertTrue(self.session.isAuthenticated, @"Session should be authenticated");
+            [self.session retrieveRootFolderWithCompletionBlock:^(CMISFolder *rootFolder,
NSError *error) {
+                self.rootFolder = rootFolder;
+                STAssertNil(error, @"Error while retrieving root folder: %@", [error description]);
+                STAssertNotNil(self.rootFolder, @"rootFolder object should not be nil");
+                
+                completionBlock();
+            }];
+        }
+    }];
+
+}
+
+- (NSDictionary *)customCmisParameters
+{
+    // Ment to be overridden.
+    return nil;
+}
+
+#pragma mark Helper Methods
+
+- (void)retrieveVersionedTestDocumentWithCompletionBlock:(void (^)(CMISDocument *document))completionBlock
+{
+    [self.session retrieveObjectByPath:@"/ios-test/versioned-quote.txt" completionBlock:^(CMISObject
*object, NSError *error) {
+        CMISDocument *document = (CMISDocument *)object;
+        STAssertNotNil(document, @"Did not find test document for versioning test");
+        STAssertTrue(document.isLatestVersion, @"Should have 'true' for the property 'isLatestVersion");
+        STAssertFalse(document.isLatestMajorVersion, @"Should have 'false' for the property
'isLatestMajorVersion"); // the latest version is a minor one
+        STAssertFalse(document.isMajorVersion, @"Should have 'false' for the property 'isMajorVersion");
+        
+        completionBlock(document);
+    }];
+}
+
+- (void)uploadTestFileWithCompletionBlock:(void (^)(CMISDocument *document))completionBlock
+{
+    // Set properties on test file
+    NSString *filePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"test_file.txt"
ofType:nil];
+    NSString *documentName = [NSString stringWithFormat:@"test_file_%@.txt", [self stringFromCurrentDate]];
+    NSMutableDictionary *documentProperties = [NSMutableDictionary dictionary];
+    [documentProperties setObject:documentName forKey:kCMISPropertyName];
+    [documentProperties setObject:kCMISPropertyObjectTypeIdValueDocument forKey:kCMISPropertyObjectTypeId];
+
+    // Upload test file
+    __block long long previousUploadedBytes = -1;
+    __block NSString *objectId = nil;
+    [self.rootFolder createDocumentFromFilePath:filePath
+            withMimeType:@"text/plain"
+            withProperties:documentProperties
+            completionBlock: ^ (NSString *newObjectId, NSError *error)
+            {
+                if (newObjectId) {
+                    objectId = newObjectId;
+                    
+                    [self.session retrieveObject:objectId completionBlock:^(CMISObject *object,
NSError *error) {
+                        CMISDocument *document = (CMISDocument *)object;
+                        STAssertNil(error, @"Got error while creating document: %@", [error
description]);
+                        STAssertNotNil(objectId, @"Object id received should be non-nil");
+                        STAssertNotNil(document, @"Retrieved document should not be nil");
+                        completionBlock(document);
+                    }];
+                } else {
+                    STAssertNotNil(error, @"Object id should not be nil");
+                    STAssertNil(error, @"Got error while uploading document: %@", [error
description]);
+                }
+            }
+            progressBlock: ^ (unsigned long long uploadedBytes, unsigned long long totalBytes)
+            {
+                STAssertTrue((long long)uploadedBytes > previousUploadedBytes, @"no progress");
+                previousUploadedBytes = uploadedBytes;
+            }];
+
+}
+
+- (void)waitForCompletion:(NSTimeInterval)timeoutSecs
+{
+    NSDate *timeoutDate = [NSDate dateWithTimeIntervalSinceNow:timeoutSecs];
+    do
+    {
+        [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:timeoutDate];
+    } while (!self.testCompleted && [timeoutDate timeIntervalSinceNow] > 0);
+
+    STAssertTrue(self.testCompleted, @"Test did not complete within %d seconds", (int)timeoutSecs);
+
+    self.testCompleted = NO;
+}
+
+- (void)deleteDocumentAndVerify:(CMISDocument *)document completionBlock:(void (^)(void))completionBlock
+{
+    [document deleteAllVersionsWithCompletionBlock:^(BOOL documentDeleted, NSError *error)
{
+        STAssertNil(error, @"Error while deleting created document: %@", [error description]);
+        STAssertTrue(documentDeleted, @"Document was not deleted");
+        completionBlock();
+    }];
+}
+
+- (NSDateFormatter *)testDateFormatter
+{
+    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
+    [formatter setDateFormat: @"yyyy-MM-dd'T'HH-mm-ss-Z'"];
+    return formatter;
+}
+
+- (NSString *)stringFromCurrentDate
+{
+    return [[self testDateFormatter] stringFromDate:[NSDate date]];
+}
+
+
+@end
\ No newline at end of file

Propchange: chemistry/objectivecmis/trunk/ObjectiveCMISTests/CMISBaseTest.m
------------------------------------------------------------------------------
    svn:eol-style = native

Added: chemistry/objectivecmis/trunk/ObjectiveCMISTests/ObjectiveCMISTests+Environment.h
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/trunk/ObjectiveCMISTests/ObjectiveCMISTests%2BEnvironment.h?rev=1425870&view=auto
==============================================================================
--- chemistry/objectivecmis/trunk/ObjectiveCMISTests/ObjectiveCMISTests+Environment.h (added)
+++ chemistry/objectivecmis/trunk/ObjectiveCMISTests/ObjectiveCMISTests+Environment.h Wed
Dec 26 10:48:33 2012
@@ -0,0 +1,43 @@
+/*
+    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.
+ */
+
+#import "ObjectiveCMISTests.h"
+
+/*
+ To take advantage of your environment values for test, set the environment.plist keys shown
below in your environment.plist file, which can be located at the given path:
+ 
+    ~/.MacOSX/environment.plist
+ 
+ If it does not exist, create one.  For the environment values to take, you will then need
to log out and log back in (also applies if you update).
+ 
+ ObjectiveCMISTestUsername ->   environment.plist Key: OBJECTIVE_CMIS_TEST_USERNAME
+ ObjectiveCMISTestPassword ->   environment.plist Key: OBJECTIVE_CMIS_TEST_PASSWORD
+ ObjectiveCMISTestAtomPubUrl -> environment.plist Key: OBJECTIVE_CMIS_TEST_ATOMPUB_URL
+ ObjectiveCMISTestRepoId  ->    environment.plist Key: OBJECTIVE_CMIS_TEST_REPOID
+ 
+ The keys on the left can be found in the ObjectiveCMISTests-Info.plist.
+ */
+
+extern NSString * const kCMISTestUsernameKey;
+extern NSString * const kCMISTestPasswordKey;
+extern NSString * const kCMISTestAtomPubUrlKey;
+extern NSString * const kCMISTestRepoIdKey;
+
+
+@interface ObjectiveCMISTests (Environment)
+
+// Fetches and provides the environemnt value for the key provided.  If no value is found,
the default value is returned.
+- (NSString *)environmentStringForKey:(NSString *)envKey defaultValue:(NSString *)defaultValue;
+
+@end

Propchange: chemistry/objectivecmis/trunk/ObjectiveCMISTests/ObjectiveCMISTests+Environment.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: chemistry/objectivecmis/trunk/ObjectiveCMISTests/ObjectiveCMISTests+Environment.m
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/trunk/ObjectiveCMISTests/ObjectiveCMISTests%2BEnvironment.m?rev=1425870&view=auto
==============================================================================
--- chemistry/objectivecmis/trunk/ObjectiveCMISTests/ObjectiveCMISTests+Environment.m (added)
+++ chemistry/objectivecmis/trunk/ObjectiveCMISTests/ObjectiveCMISTests+Environment.m Wed
Dec 26 10:48:33 2012
@@ -0,0 +1,44 @@
+/*
+    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.
+ */
+
+#import "ObjectiveCMISTests+Environment.h"
+
+NSString * const kCMISTestUsernameKey = @"ObjectiveCMISTestUsername";
+NSString * const kCMISTestPasswordKey = @"ObjectiveCMISTestPassword";
+NSString * const kCMISTestAtomPubUrlKey = @"ObjectiveCMISTestAtomPubUrl";
+NSString * const kCMISTestRepoIdKey = @"ObjectiveCMISTestRepoId";
+
+@implementation ObjectiveCMISTests (Environment)
+
+- (NSString *)environmentStringForKey:(NSString *)envKey defaultValue:(NSString *)defaultValue
+{
+//    if (YES) return defaultValue;
+    
+    NSBundle *bundle = [NSBundle bundleForClass:[self class]];
+    NSString *envValue = [bundle objectForInfoDictionaryKey:envKey];
+    if ((nil == envValue) || ([envValue length] == 0))
+    {
+        return defaultValue;
+    }
+    
+    if ([defaultValue hasSuffix:@"/service/api/cmis"]) 
+    {
+        //        envValue = @"http://127.0.0.1:8080/alfresco/cmisatom";
+    }
+    
+    return envValue;
+}
+
+
+@end

Propchange: chemistry/objectivecmis/trunk/ObjectiveCMISTests/ObjectiveCMISTests+Environment.m
------------------------------------------------------------------------------
    svn:eol-style = native

Added: chemistry/objectivecmis/trunk/ObjectiveCMISTests/ObjectiveCMISTests-Info.plist
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/trunk/ObjectiveCMISTests/ObjectiveCMISTests-Info.plist?rev=1425870&view=auto
==============================================================================
--- chemistry/objectivecmis/trunk/ObjectiveCMISTests/ObjectiveCMISTests-Info.plist (added)
+++ chemistry/objectivecmis/trunk/ObjectiveCMISTests/ObjectiveCMISTests-Info.plist Wed Dec
26 10:48:33 2012
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>CFBundleDevelopmentRegion</key>
+	<string>en</string>
+	<key>CFBundleExecutable</key>
+	<string>${EXECUTABLE_NAME}</string>
+	<key>CFBundleIdentifier</key>
+	<string>org.apache.chemistry.${PRODUCT_NAME:rfc1034identifier}</string>
+	<key>CFBundleInfoDictionaryVersion</key>
+	<string>6.0</string>
+	<key>CFBundlePackageType</key>
+	<string>BNDL</string>
+	<key>CFBundleShortVersionString</key>
+	<string>1.0</string>
+	<key>CFBundleSignature</key>
+	<string>????</string>
+	<key>CFBundleVersion</key>
+	<string>1</string>
+	<key>ObjectiveCMISTestUsername</key>
+	<string>${OBJECTIVE_CMIS_TEST_USERNAME}</string>
+	<key>ObjectiveCMISTestPassword</key>
+	<string>${OBJECTIVE_CMIS_TEST_PASSWORD}</string>
+	<key>ObjectiveCMISTestAtomPubUrl</key>
+	<string>${OBJECTIVE_CMIS_TEST_ATOMPUB_URL}</string>
+	<key>ObjectiveCMISTestRepoId</key>
+	<string>${OBJECTIVE_CMIS_TEST_REPOID}</string>
+</dict>
+</plist>

Added: chemistry/objectivecmis/trunk/ObjectiveCMISTests/ObjectiveCMISTests.h
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/trunk/ObjectiveCMISTests/ObjectiveCMISTests.h?rev=1425870&view=auto
==============================================================================
--- chemistry/objectivecmis/trunk/ObjectiveCMISTests/ObjectiveCMISTests.h (added)
+++ chemistry/objectivecmis/trunk/ObjectiveCMISTests/ObjectiveCMISTests.h Wed Dec 26 10:48:33
2012
@@ -0,0 +1,21 @@
+/*
+    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.
+ */
+#import <SenTestingKit/SenTestingKit.h>
+#import "CMISSessionParameters.h"
+#import "CMISBaseTest.h"
+
+@interface ObjectiveCMISTests : CMISBaseTest
+
+
+@end

Propchange: chemistry/objectivecmis/trunk/ObjectiveCMISTests/ObjectiveCMISTests.h
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message