Skip to content

Commit ceffa10

Browse files
committed
added command-line tests
1 parent 5610456 commit ceffa10

File tree

8 files changed

+243
-41
lines changed

8 files changed

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