Skip to content

Commit e8052f0

Browse files
committed
Merge pull request #550 from swagger-api/feature/ios-templates
added command-line tests
2 parents b36f3c9 + be373f8 commit e8052f0

File tree

9 files changed

+376
-41
lines changed

9 files changed

+376
-41
lines changed

pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,19 @@
277277
</plugins>
278278
</build>
279279
</profile>
280+
<profile>
281+
<!-- Samples -->
282+
<id>samples</id>
283+
<activation>
284+
<property>
285+
<name>env</name>
286+
<value>samples</value>
287+
</property>
288+
</activation>
289+
<modules>
290+
<module>samples/client/petstore/objc</module>
291+
</modules>
292+
</profile>
280293
</profiles>
281294
<modules>
282295
<module>modules/swagger-codegen</module>

samples/client/petstore/objc/PetstoreClient/PetstoreClient.xcodeproj/project.pbxproj

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
EA6699BD1811D2FB00A70D03 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA6699991811D2FA00A70D03 /* Foundation.framework */; };
2323
EA6699BE1811D2FB00A70D03 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA66999D1811D2FA00A70D03 /* UIKit.framework */; };
2424
EA6699C61811D2FB00A70D03 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = EA6699C41811D2FB00A70D03 /* InfoPlist.strings */; };
25-
EA6699C81811D2FB00A70D03 /* PetstoreClientTests.m in Sources */ = {isa = PBXBuildFile; fileRef = EA6699C71811D2FB00A70D03 /* PetstoreClientTests.m */; };
25+
EA6699C81811D2FB00A70D03 /* PetApiTest.m in Sources */ = {isa = PBXBuildFile; fileRef = EA6699C71811D2FB00A70D03 /* PetApiTest.m */; };
26+
EA8CD3ED1AC2763600C47D0B /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA8CD3EC1AC2763600C47D0B /* SenTestingKit.framework */; };
2627
EAEA85E41811D3AE00F06E69 /* SWGApiClient.m in Sources */ = {isa = PBXBuildFile; fileRef = EAEA85CD1811D3AE00F06E69 /* SWGApiClient.m */; };
2728
EAEA85E51811D3AE00F06E69 /* SWGCategory.m in Sources */ = {isa = PBXBuildFile; fileRef = EAEA85CF1811D3AE00F06E69 /* SWGCategory.m */; };
2829
EAEA85E61811D3AE00F06E69 /* SWGDate.m in Sources */ = {isa = PBXBuildFile; fileRef = EAEA85D11811D3AE00F06E69 /* SWGDate.m */; };
@@ -73,7 +74,9 @@
7374
EA6699BB1811D2FB00A70D03 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; };
7475
EA6699C31811D2FB00A70D03 /* PetstoreClientTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "PetstoreClientTests-Info.plist"; sourceTree = "<group>"; };
7576
EA6699C51811D2FB00A70D03 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
76-
EA6699C71811D2FB00A70D03 /* PetstoreClientTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PetstoreClientTests.m; sourceTree = "<group>"; };
77+
EA6699C71811D2FB00A70D03 /* PetApiTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PetApiTest.m; sourceTree = "<group>"; };
78+
EA8CD3EB1AC274BE00C47D0B /* PetApiTest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PetApiTest.h; sourceTree = "<group>"; };
79+
EA8CD3EC1AC2763600C47D0B /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; };
7780
EAEA85CC1811D3AE00F06E69 /* SWGApiClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWGApiClient.h; sourceTree = "<group>"; };
7881
EAEA85CD1811D3AE00F06E69 /* SWGApiClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SWGApiClient.m; sourceTree = "<group>"; };
7982
EAEA85CE1811D3AE00F06E69 /* SWGCategory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWGCategory.h; sourceTree = "<group>"; };
@@ -120,6 +123,7 @@
120123
isa = PBXFrameworksBuildPhase;
121124
buildActionMask = 2147483647;
122125
files = (
126+
EA8CD3ED1AC2763600C47D0B /* SenTestingKit.framework in Frameworks */,
123127
EAEA85F11811D8F100F06E69 /* libPods.a in Frameworks */,
124128
EA6699BC1811D2FB00A70D03 /* XCTest.framework in Frameworks */,
125129
EA6699BE1811D2FB00A70D03 /* UIKit.framework in Frameworks */,
@@ -163,6 +167,7 @@
163167
EA6699981811D2FA00A70D03 /* Frameworks */ = {
164168
isa = PBXGroup;
165169
children = (
170+
EA8CD3EC1AC2763600C47D0B /* SenTestingKit.framework */,
166171
EAEA85F01811D8F100F06E69 /* libPods.a */,
167172
EA6699991811D2FA00A70D03 /* Foundation.framework */,
168173
EA66999B1811D2FA00A70D03 /* CoreGraphics.framework */,
@@ -203,7 +208,8 @@
203208
EA6699C11811D2FB00A70D03 /* PetstoreClientTests */ = {
204209
isa = PBXGroup;
205210
children = (
206-
EA6699C71811D2FB00A70D03 /* PetstoreClientTests.m */,
211+
EA8CD3EB1AC274BE00C47D0B /* PetApiTest.h */,
212+
EA6699C71811D2FB00A70D03 /* PetApiTest.m */,
207213
EA6699C21811D2FB00A70D03 /* Supporting Files */,
208214
);
209215
path = PetstoreClientTests;
@@ -409,7 +415,7 @@
409415
isa = PBXSourcesBuildPhase;
410416
buildActionMask = 2147483647;
411417
files = (
412-
EA6699C81811D2FB00A70D03 /* PetstoreClientTests.m in Sources */,
418+
EA6699C81811D2FB00A70D03 /* PetApiTest.m in Sources */,
413419
);
414420
runOnlyForDeploymentPostprocessing = 0;
415421
};

samples/client/petstore/objc/PetstoreClient/PetstoreClient.xcodeproj/xcuserdata/tony.xcuserdatad/xcschemes/PetstoreClient.xcscheme

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
ignoresPersistentStateOnLaunch = "NO"
5959
debugDocumentVersioning = "YES"
6060
allowLocationSimulation = "YES">
61-
<BuildableProductRunnable>
61+
<BuildableProductRunnable
62+
runnableDebuggingMode = "0">
6263
<BuildableReference
6364
BuildableIdentifier = "primary"
6465
BlueprintIdentifier = "EA6699951811D2FA00A70D03"
@@ -76,7 +77,8 @@
7677
useCustomWorkingDirectory = "NO"
7778
buildConfiguration = "Release"
7879
debugDocumentVersioning = "YES">
79-
<BuildableProductRunnable>
80+
<BuildableProductRunnable
81+
runnableDebuggingMode = "0">
8082
<BuildableReference
8183
BuildableIdentifier = "primary"
8284
BlueprintIdentifier = "EA6699951811D2FA00A70D03"

samples/client/petstore/objc/PetstoreClient/PetstoreClient/ViewController.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ - (void)viewDidLoad
2121
// Do any additional setup after loading the view, typically from a nib.
2222

2323
SWGPetApi * api = [[SWGPetApi alloc] init];
24-
24+
/*
2525
[api getPetByIdWithCompletionBlock:@10 completionHandler:^(SWGPet *output, NSError *error) {
2626
NSLog(@"%@", [output asDictionary]);
2727
[output set_id:@101];
@@ -52,6 +52,7 @@ - (void)viewDidLoad
5252
// }
5353
// }
5454
];
55+
*/
5556
}
5657

5758
- (void)didReceiveMemoryWarning
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#import <XCTest/XCTest.h>
2+
#import "SWGPetApi.h"
3+
4+
@interface PetApiTest : XCTestCase {
5+
@private
6+
SWGPetApi * api;
7+
}
8+
9+
@end
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
#import "PetApiTest.h"
2+
#import "SWGFile.h"
3+
4+
@implementation PetApiTest
5+
6+
- (void)setUp {
7+
[super setUp];
8+
api = [[SWGPetApi alloc ]init];
9+
// [[SWGApiClient sharedClientFromPool]setLoggingEnabled:true];
10+
[SWGPetApi setBasePath:@"http://localhost:8002/api"];
11+
}
12+
13+
- (void)tearDown {
14+
[super tearDown];
15+
}
16+
17+
- (void)testGetPetById {
18+
XCTestExpectation *expectation = [self expectationWithDescription:@"testGetPetById"];
19+
[api getPetByIdWithCompletionBlock:@1 completionHandler:^(SWGPet *output, NSError *error) {
20+
if(error){
21+
XCTFail(@"got error %@", error);
22+
}
23+
if(output){
24+
XCTAssertNotNil([output _id], @"token was nil");
25+
}
26+
[expectation fulfill];
27+
}];
28+
[self waitForExpectationsWithTimeout:2.0 handler:nil];
29+
}
30+
31+
- (void) testAddPet {
32+
XCTestExpectation *expectation = [self expectationWithDescription:@"testAddPet"];
33+
34+
SWGPet * petToAdd = [[SWGPet alloc] init];
35+
[petToAdd set_id:@1000];
36+
NSMutableArray* tags = [[NSMutableArray alloc] init];
37+
for(int i = 0; i < 5; i++){
38+
SWGTag * tag = [[SWGTag alloc] init];
39+
[tag set_id:[NSNumber numberWithInt:i]];
40+
[tag setName:[NSString stringWithFormat:@"tag-%d", i]];
41+
[tags addObject:tag];
42+
}
43+
[petToAdd setTags:tags];
44+
[petToAdd setStatus:@"lost"];
45+
46+
SWGCategory * category = [[SWGCategory alloc] init];
47+
[category setName:@"sold"];
48+
[petToAdd setCategory:category];
49+
[petToAdd setName:@"dragon"];
50+
51+
NSMutableArray* photos = [[NSMutableArray alloc] init];
52+
for(int i = 0; i < 10; i++){
53+
NSString * url = [NSString stringWithFormat:@"http://foo.com/photo/%d", i];
54+
[photos addObject:url];
55+
}
56+
[petToAdd setPhotoUrls:photos];
57+
58+
[api addPetWithCompletionBlock:petToAdd completionHandler:^(NSError *error) {
59+
if(error){
60+
XCTFail(@"got error %@", error);
61+
}
62+
[expectation fulfill];
63+
}];
64+
65+
[self waitForExpectationsWithTimeout:2.0 handler:nil];
66+
}
67+
68+
- (void) testUpdatePet {
69+
XCTestExpectation *expectation = [self expectationWithDescription:@"testUpdatePet"];
70+
SWGPet * petToAdd = [[SWGPet alloc] init];
71+
[petToAdd set_id:[NSNumber numberWithInt:1000]];
72+
NSMutableArray* tags = [[NSMutableArray alloc] init];
73+
for(int i = 0; i < 5; i++){
74+
SWGTag * tag = [[SWGTag alloc] init];
75+
[tag set_id:[NSNumber numberWithInt:i]];
76+
[tag setName:[NSString stringWithFormat:@"tag-%d", i]];
77+
[tags addObject:tag];
78+
}
79+
[petToAdd setTags:tags];
80+
[petToAdd setStatus:@"lost"];
81+
82+
SWGCategory * category = [[SWGCategory alloc] init];
83+
[category setName:@"sold"];
84+
[petToAdd setCategory:category];
85+
[petToAdd setName:@"dragon"];
86+
87+
NSMutableArray* photos = [[NSMutableArray alloc] init];
88+
for(int i = 0; i < 10; i++){
89+
NSString * url = [NSString stringWithFormat:@"http://foo.com/photo/%d", i];
90+
[photos addObject:url];
91+
}
92+
[petToAdd setPhotoUrls:photos];
93+
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
94+
95+
static bool hasResponse = false;
96+
[api addPetWithCompletionBlock:petToAdd completionHandler:^(NSError *error) {
97+
if(error) {
98+
XCTFail(@"got error %@", error);
99+
}
100+
else {
101+
[api getPetByIdWithCompletionBlock:[NSString stringWithFormat:@"%@",[petToAdd _id]] completionHandler:^(SWGPet *output, NSError *error) {
102+
if(error) {
103+
XCTFail(@"got error %@", error);
104+
}
105+
if(output == nil){
106+
NSLog(@"failed to fetch pet");
107+
}
108+
else {
109+
SWGPet* pet = [[SWGPet alloc] initWithValues:[output asDictionary]];
110+
NSLog(@"got the pet");
111+
112+
[pet setName:@"programmer"];
113+
[pet setStatus:@"confused"];
114+
115+
[api updatePetWithCompletionBlock:pet
116+
completionHandler:^(NSError *error) {
117+
if(error) {
118+
XCTFail(@"got error %@", error);
119+
}
120+
[api getPetByIdWithCompletionBlock:@1000 completionHandler:^(SWGPet *output, NSError *error) {
121+
if(error) {
122+
XCTFail(@"got error %@", error);
123+
}
124+
if(output == nil){
125+
NSLog(@"failed to fetch pet");
126+
}
127+
else {
128+
SWGPet* pet = [[SWGPet alloc] initWithValues:[output asDictionary]];
129+
XCTAssertNotNil([pet _id], @"pet was nil");
130+
XCTAssertEqualObjects([pet name], @"programmer", @"pet name was not updated");
131+
XCTAssertEqualObjects([pet status], @"confused", @"pet status was not updated");
132+
}
133+
[expectation fulfill];
134+
135+
}];
136+
}];
137+
}
138+
}];
139+
}
140+
}];
141+
[self waitForExpectationsWithTimeout:2.0 handler:nil];
142+
}
143+
144+
- (void)testGetPetByStatus {
145+
XCTestExpectation *expectation = [self expectationWithDescription:@"testGetPetByStatus"];
146+
static NSMutableArray* pets = nil;
147+
static NSError * gError = nil;
148+
[api findPetsByStatusWithCompletionBlock:@"available" completionHandler:^(NSArray *output, NSError *error) {
149+
if(error) {
150+
gError = error;
151+
}
152+
if(output == nil){
153+
NSLog(@"failed to fetch pets");
154+
}
155+
else {
156+
pets = [[NSMutableArray alloc]init];
157+
for(SWGPet* pet in output) {
158+
[pets addObject:[[SWGPet alloc] initWithValues:[pet asDictionary]]];
159+
}
160+
}
161+
}];
162+
[self waitForExpectationsWithTimeout:2.0 handler:nil];
163+
}
164+
165+
- (void)testGetPetByTags {
166+
XCTestExpectation *expectation = [self expectationWithDescription:@"testGetPetByTags"];
167+
[api findPetsByTagsWithCompletionBlock:@"tag1,tag2" completionHandler:^(NSArray *output, NSError *error) {
168+
if(error){
169+
XCTFail(@"got error %@", error);
170+
}
171+
if(output){
172+
for(SWGPet * pet in output) {
173+
bool hasTag = false;
174+
for(SWGTag * tag in [pet tags]){
175+
if([[tag name] isEqualToString:@"tag1"] || [[tag name] isEqualToString:@"tag2"])
176+
hasTag = true;
177+
}
178+
if(!hasTag)
179+
XCTFail(@"failed to find tag in pet");
180+
}
181+
}
182+
[expectation fulfill];
183+
}];
184+
[self waitForExpectationsWithTimeout:2.0 handler:nil];
185+
}
186+
@end

samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/PetstoreClientTests.m

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<project>
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>de.felixschulze.my-project</groupId>
4+
<artifactId>PetstoreClient</artifactId>
5+
<packaging>xcode</packaging>
6+
<version>1.0-SNAPSHOT</version>
7+
<name>Swagger Petstore Client</name>
8+
<build>
9+
<plugins>
10+
<plugin>
11+
<groupId>de.felixschulze.maven.plugins.xcode</groupId>
12+
<artifactId>xcode-maven-plugin</artifactId>
13+
<version>1.2</version>
14+
<configuration>
15+
<xcodeProject>PetstoreClient.xcodeproj</xcodeProject>
16+
<xcodeTarget>PetstoreClient</xcodeTarget>
17+
<xcodeConfiguration>Debug</xcodeConfiguration>
18+
<xcodeSdk>iphoneos</xcodeSdk>
19+
</configuration>
20+
<extensions>true</extensions>
21+
</plugin>
22+
</plugins>
23+
</build>
24+
</project>

0 commit comments

Comments
 (0)