Skip to content

Commit be373f8

Browse files
committed
fixed test errors
1 parent ceffa10 commit be373f8

File tree

2 files changed

+148
-15
lines changed

2 files changed

+148
-15
lines changed

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

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ @implementation PetApiTest
66
- (void)setUp {
77
[super setUp];
88
api = [[SWGPetApi alloc ]init];
9+
// [[SWGApiClient sharedClientFromPool]setLoggingEnabled:true];
910
[SWGPetApi setBasePath:@"http://localhost:8002/api"];
1011
}
1112

@@ -14,17 +15,22 @@ - (void)tearDown {
1415
}
1516

1617
- (void)testGetPetById {
18+
XCTestExpectation *expectation = [self expectationWithDescription:@"testGetPetById"];
1719
[api getPetByIdWithCompletionBlock:@1 completionHandler:^(SWGPet *output, NSError *error) {
1820
if(error){
1921
XCTFail(@"got error %@", error);
2022
}
2123
if(output){
2224
XCTAssertNotNil([output _id], @"token was nil");
2325
}
26+
[expectation fulfill];
2427
}];
28+
[self waitForExpectationsWithTimeout:2.0 handler:nil];
2529
}
2630

2731
- (void) testAddPet {
32+
XCTestExpectation *expectation = [self expectationWithDescription:@"testAddPet"];
33+
2834
SWGPet * petToAdd = [[SWGPet alloc] init];
2935
[petToAdd set_id:@1000];
3036
NSMutableArray* tags = [[NSMutableArray alloc] init];
@@ -53,10 +59,14 @@ - (void) testAddPet {
5359
if(error){
5460
XCTFail(@"got error %@", error);
5561
}
62+
[expectation fulfill];
5663
}];
64+
65+
[self waitForExpectationsWithTimeout:2.0 handler:nil];
5766
}
5867

5968
- (void) testUpdatePet {
69+
XCTestExpectation *expectation = [self expectationWithDescription:@"testUpdatePet"];
6070
SWGPet * petToAdd = [[SWGPet alloc] init];
6171
[petToAdd set_id:[NSNumber numberWithInt:1000]];
6272
NSMutableArray* tags = [[NSMutableArray alloc] init];
@@ -80,7 +90,8 @@ - (void) testUpdatePet {
8090
[photos addObject:url];
8191
}
8292
[petToAdd setPhotoUrls:photos];
83-
93+
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
94+
8495
static bool hasResponse = false;
8596
[api addPetWithCompletionBlock:petToAdd completionHandler:^(NSError *error) {
8697
if(error) {
@@ -119,16 +130,19 @@ - (void) testUpdatePet {
119130
XCTAssertEqualObjects([pet name], @"programmer", @"pet name was not updated");
120131
XCTAssertEqualObjects([pet status], @"confused", @"pet status was not updated");
121132
}
133+
[expectation fulfill];
134+
122135
}];
123136
}];
124137
}
125138
}];
126139
}
127140
}];
141+
[self waitForExpectationsWithTimeout:2.0 handler:nil];
128142
}
129143

130144
- (void)testGetPetByStatus {
131-
bool done = false;
145+
XCTestExpectation *expectation = [self expectationWithDescription:@"testGetPetByStatus"];
132146
static NSMutableArray* pets = nil;
133147
static NSError * gError = nil;
134148
[api findPetsByStatusWithCompletionBlock:@"available" completionHandler:^(NSArray *output, NSError *error) {
@@ -145,22 +159,11 @@ - (void)testGetPetByStatus {
145159
}
146160
}
147161
}];
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-
}
162+
[self waitForExpectationsWithTimeout:2.0 handler:nil];
161163
}
162164

163165
- (void)testGetPetByTags {
166+
XCTestExpectation *expectation = [self expectationWithDescription:@"testGetPetByTags"];
164167
[api findPetsByTagsWithCompletionBlock:@"tag1,tag2" completionHandler:^(NSArray *output, NSError *error) {
165168
if(error){
166169
XCTFail(@"got error %@", error);
@@ -176,6 +179,8 @@ - (void)testGetPetByTags {
176179
XCTFail(@"failed to find tag in pet");
177180
}
178181
}
182+
[expectation fulfill];
179183
}];
184+
[self waitForExpectationsWithTimeout:2.0 handler:nil];
180185
}
181186
@end
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<project>
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>de.felixschulze.my-project</groupId>
4+
<artifactId>PetstoreClient</artifactId>
5+
<packaging>pom</packaging>
6+
<version>1.0-SNAPSHOT</version>
7+
<name>Objective-C Swagger Petstore Client</name>
8+
<build>
9+
<plugins>
10+
<plugin>
11+
<artifactId>maven-dependency-plugin</artifactId>
12+
<executions>
13+
<execution>
14+
<phase>package</phase>
15+
<goals>
16+
<goal>copy-dependencies</goal>
17+
</goals>
18+
<configuration>
19+
<outputDirectory>${project.build.directory}</outputDirectory>
20+
</configuration>
21+
</execution>
22+
</executions>
23+
</plugin>
24+
<plugin>
25+
<groupId>org.mortbay.jetty</groupId>
26+
<artifactId>jetty-maven-plugin</artifactId>
27+
<version>${jetty-version}</version>
28+
<configuration>
29+
<useTestScope>true</useTestScope>
30+
<stopWait>15</stopWait>
31+
<war>${project.build.directory}/swagger-java-jersey-sample-app-${webapp-version}.war</war>
32+
<webAppConfig>
33+
<contextPath>/</contextPath>
34+
</webAppConfig>
35+
<stopPort>8079</stopPort>
36+
<stopKey>stopit</stopKey>
37+
<connectors>
38+
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
39+
<port>8002</port>
40+
<maxIdleTime>60000</maxIdleTime>
41+
<confidentialPort>8443</confidentialPort>
42+
</connector>
43+
</connectors>
44+
</configuration>
45+
<executions>
46+
<execution>
47+
<id>start-jetty</id>
48+
<phase>pre-integration-test</phase>
49+
<goals>
50+
<goal>run-war</goal>
51+
</goals>
52+
<configuration>
53+
<scanIntervalSeconds>0</scanIntervalSeconds>
54+
<daemon>true</daemon>
55+
</configuration>
56+
</execution>
57+
<execution>
58+
<id>stop-jetty</id>
59+
<phase>post-integration-test</phase>
60+
<goals>
61+
<goal>stop</goal>
62+
</goals>
63+
</execution>
64+
</executions>
65+
</plugin>
66+
<plugin>
67+
<groupId>org.codehaus.mojo</groupId>
68+
<artifactId>exec-maven-plugin</artifactId>
69+
<version>1.2.1</version>
70+
<executions>
71+
<execution>
72+
<id>install-pods</id>
73+
<phase>pre-integration-test</phase>
74+
<goals>
75+
<goal>exec</goal>
76+
</goals>
77+
<configuration>
78+
<executable>pod</executable>
79+
<arguments>
80+
<argument>install</argument>
81+
</arguments>
82+
</configuration>
83+
</execution>
84+
<execution>
85+
<id>xcodebuild-test</id>
86+
<phase>integration-test</phase>
87+
<goals>
88+
<goal>exec</goal>
89+
</goals>
90+
<configuration>
91+
<executable>xcodebuild</executable>
92+
<arguments>
93+
<argument>-workspace</argument>
94+
<argument>PetstoreClient.xcworkspace</argument>
95+
<argument>-scheme</argument>
96+
<argument>PetstoreClient</argument>
97+
<argument>test</argument>
98+
<argument>-destination</argument>
99+
<argument>platform=iOS Simulator,name=iPhone 6,OS=8.2</argument>
100+
</arguments>
101+
</configuration>
102+
</execution>
103+
</executions>
104+
</plugin>
105+
</plugins>
106+
</build>
107+
<dependencies>
108+
<dependency>
109+
<groupId>com.wordnik</groupId>
110+
<artifactId>swagger-java-jersey-sample-app</artifactId>
111+
<version>${webapp-version}</version>
112+
<type>war</type>
113+
<scope>test</scope>
114+
</dependency>
115+
<repositories>
116+
<repository>
117+
<id>sonatype-snapshots</id>
118+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
119+
<snapshots>
120+
<enabled>true</enabled>
121+
</snapshots>
122+
</repository>
123+
</repositories>
124+
<properties>
125+
<webapp-version>1.5.4-M1-SNAPSHOT</webapp-version>
126+
<jetty-version>8.1.11.v20130520</jetty-version>
127+
</properties>
128+
</project>

0 commit comments

Comments
 (0)