forked from loafle/openapi-generator-original
added command-line tests
This commit is contained in:
parent
56104566fc
commit
ceffa10ab7
13
pom.xml
13
pom.xml
@ -277,6 +277,19 @@
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<!-- Samples -->
|
||||
<id>samples</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>env</name>
|
||||
<value>samples</value>
|
||||
</property>
|
||||
</activation>
|
||||
<modules>
|
||||
<module>samples/client/petstore/objc</module>
|
||||
</modules>
|
||||
</profile>
|
||||
</profiles>
|
||||
<modules>
|
||||
<module>modules/swagger-codegen</module>
|
||||
|
@ -22,7 +22,8 @@
|
||||
EA6699BD1811D2FB00A70D03 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA6699991811D2FA00A70D03 /* Foundation.framework */; };
|
||||
EA6699BE1811D2FB00A70D03 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA66999D1811D2FA00A70D03 /* UIKit.framework */; };
|
||||
EA6699C61811D2FB00A70D03 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = EA6699C41811D2FB00A70D03 /* InfoPlist.strings */; };
|
||||
EA6699C81811D2FB00A70D03 /* PetstoreClientTests.m in Sources */ = {isa = PBXBuildFile; fileRef = EA6699C71811D2FB00A70D03 /* PetstoreClientTests.m */; };
|
||||
EA6699C81811D2FB00A70D03 /* PetApiTest.m in Sources */ = {isa = PBXBuildFile; fileRef = EA6699C71811D2FB00A70D03 /* PetApiTest.m */; };
|
||||
EA8CD3ED1AC2763600C47D0B /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA8CD3EC1AC2763600C47D0B /* SenTestingKit.framework */; };
|
||||
EAEA85E41811D3AE00F06E69 /* SWGApiClient.m in Sources */ = {isa = PBXBuildFile; fileRef = EAEA85CD1811D3AE00F06E69 /* SWGApiClient.m */; };
|
||||
EAEA85E51811D3AE00F06E69 /* SWGCategory.m in Sources */ = {isa = PBXBuildFile; fileRef = EAEA85CF1811D3AE00F06E69 /* SWGCategory.m */; };
|
||||
EAEA85E61811D3AE00F06E69 /* SWGDate.m in Sources */ = {isa = PBXBuildFile; fileRef = EAEA85D11811D3AE00F06E69 /* SWGDate.m */; };
|
||||
@ -73,7 +74,9 @@
|
||||
EA6699BB1811D2FB00A70D03 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; };
|
||||
EA6699C31811D2FB00A70D03 /* PetstoreClientTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "PetstoreClientTests-Info.plist"; sourceTree = "<group>"; };
|
||||
EA6699C51811D2FB00A70D03 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
|
||||
EA6699C71811D2FB00A70D03 /* PetstoreClientTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PetstoreClientTests.m; sourceTree = "<group>"; };
|
||||
EA6699C71811D2FB00A70D03 /* PetApiTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PetApiTest.m; sourceTree = "<group>"; };
|
||||
EA8CD3EB1AC274BE00C47D0B /* PetApiTest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PetApiTest.h; sourceTree = "<group>"; };
|
||||
EA8CD3EC1AC2763600C47D0B /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; };
|
||||
EAEA85CC1811D3AE00F06E69 /* SWGApiClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWGApiClient.h; sourceTree = "<group>"; };
|
||||
EAEA85CD1811D3AE00F06E69 /* SWGApiClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SWGApiClient.m; sourceTree = "<group>"; };
|
||||
EAEA85CE1811D3AE00F06E69 /* SWGCategory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWGCategory.h; sourceTree = "<group>"; };
|
||||
@ -120,6 +123,7 @@
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
EA8CD3ED1AC2763600C47D0B /* SenTestingKit.framework in Frameworks */,
|
||||
EAEA85F11811D8F100F06E69 /* libPods.a in Frameworks */,
|
||||
EA6699BC1811D2FB00A70D03 /* XCTest.framework in Frameworks */,
|
||||
EA6699BE1811D2FB00A70D03 /* UIKit.framework in Frameworks */,
|
||||
@ -163,6 +167,7 @@
|
||||
EA6699981811D2FA00A70D03 /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
EA8CD3EC1AC2763600C47D0B /* SenTestingKit.framework */,
|
||||
EAEA85F01811D8F100F06E69 /* libPods.a */,
|
||||
EA6699991811D2FA00A70D03 /* Foundation.framework */,
|
||||
EA66999B1811D2FA00A70D03 /* CoreGraphics.framework */,
|
||||
@ -203,7 +208,8 @@
|
||||
EA6699C11811D2FB00A70D03 /* PetstoreClientTests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
EA6699C71811D2FB00A70D03 /* PetstoreClientTests.m */,
|
||||
EA8CD3EB1AC274BE00C47D0B /* PetApiTest.h */,
|
||||
EA6699C71811D2FB00A70D03 /* PetApiTest.m */,
|
||||
EA6699C21811D2FB00A70D03 /* Supporting Files */,
|
||||
);
|
||||
path = PetstoreClientTests;
|
||||
@ -409,7 +415,7 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
EA6699C81811D2FB00A70D03 /* PetstoreClientTests.m in Sources */,
|
||||
EA6699C81811D2FB00A70D03 /* PetApiTest.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -58,7 +58,8 @@
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable>
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "EA6699951811D2FA00A70D03"
|
||||
@ -76,7 +77,8 @@
|
||||
useCustomWorkingDirectory = "NO"
|
||||
buildConfiguration = "Release"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable>
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "EA6699951811D2FA00A70D03"
|
||||
|
@ -21,7 +21,7 @@
|
||||
// Do any additional setup after loading the view, typically from a nib.
|
||||
|
||||
SWGPetApi * api = [[SWGPetApi alloc] init];
|
||||
|
||||
/*
|
||||
[api getPetByIdWithCompletionBlock:@10 completionHandler:^(SWGPet *output, NSError *error) {
|
||||
NSLog(@"%@", [output asDictionary]);
|
||||
[output set_id:@101];
|
||||
@ -52,6 +52,7 @@
|
||||
// }
|
||||
// }
|
||||
];
|
||||
*/
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning
|
||||
|
@ -0,0 +1,9 @@
|
||||
#import <XCTest/XCTest.h>
|
||||
#import "SWGPetApi.h"
|
||||
|
||||
@interface PetApiTest : XCTestCase {
|
||||
@private
|
||||
SWGPetApi * api;
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,181 @@
|
||||
#import "PetApiTest.h"
|
||||
#import "SWGFile.h"
|
||||
|
||||
@implementation PetApiTest
|
||||
|
||||
- (void)setUp {
|
||||
[super setUp];
|
||||
api = [[SWGPetApi alloc ]init];
|
||||
[SWGPetApi setBasePath:@"http://localhost:8002/api"];
|
||||
}
|
||||
|
||||
- (void)tearDown {
|
||||
[super tearDown];
|
||||
}
|
||||
|
||||
- (void)testGetPetById {
|
||||
[api getPetByIdWithCompletionBlock:@1 completionHandler:^(SWGPet *output, NSError *error) {
|
||||
if(error){
|
||||
XCTFail(@"got error %@", error);
|
||||
}
|
||||
if(output){
|
||||
XCTAssertNotNil([output _id], @"token was nil");
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void) testAddPet {
|
||||
SWGPet * petToAdd = [[SWGPet alloc] init];
|
||||
[petToAdd set_id:@1000];
|
||||
NSMutableArray* tags = [[NSMutableArray alloc] init];
|
||||
for(int i = 0; i < 5; i++){
|
||||
SWGTag * tag = [[SWGTag alloc] init];
|
||||
[tag set_id:[NSNumber numberWithInt:i]];
|
||||
[tag setName:[NSString stringWithFormat:@"tag-%d", i]];
|
||||
[tags addObject:tag];
|
||||
}
|
||||
[petToAdd setTags:tags];
|
||||
[petToAdd setStatus:@"lost"];
|
||||
|
||||
SWGCategory * category = [[SWGCategory alloc] init];
|
||||
[category setName:@"sold"];
|
||||
[petToAdd setCategory:category];
|
||||
[petToAdd setName:@"dragon"];
|
||||
|
||||
NSMutableArray* photos = [[NSMutableArray alloc] init];
|
||||
for(int i = 0; i < 10; i++){
|
||||
NSString * url = [NSString stringWithFormat:@"http://foo.com/photo/%d", i];
|
||||
[photos addObject:url];
|
||||
}
|
||||
[petToAdd setPhotoUrls:photos];
|
||||
|
||||
[api addPetWithCompletionBlock:petToAdd completionHandler:^(NSError *error) {
|
||||
if(error){
|
||||
XCTFail(@"got error %@", error);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void) testUpdatePet {
|
||||
SWGPet * petToAdd = [[SWGPet alloc] init];
|
||||
[petToAdd set_id:[NSNumber numberWithInt:1000]];
|
||||
NSMutableArray* tags = [[NSMutableArray alloc] init];
|
||||
for(int i = 0; i < 5; i++){
|
||||
SWGTag * tag = [[SWGTag alloc] init];
|
||||
[tag set_id:[NSNumber numberWithInt:i]];
|
||||
[tag setName:[NSString stringWithFormat:@"tag-%d", i]];
|
||||
[tags addObject:tag];
|
||||
}
|
||||
[petToAdd setTags:tags];
|
||||
[petToAdd setStatus:@"lost"];
|
||||
|
||||
SWGCategory * category = [[SWGCategory alloc] init];
|
||||
[category setName:@"sold"];
|
||||
[petToAdd setCategory:category];
|
||||
[petToAdd setName:@"dragon"];
|
||||
|
||||
NSMutableArray* photos = [[NSMutableArray alloc] init];
|
||||
for(int i = 0; i < 10; i++){
|
||||
NSString * url = [NSString stringWithFormat:@"http://foo.com/photo/%d", i];
|
||||
[photos addObject:url];
|
||||
}
|
||||
[petToAdd setPhotoUrls:photos];
|
||||
|
||||
static bool hasResponse = false;
|
||||
[api addPetWithCompletionBlock:petToAdd completionHandler:^(NSError *error) {
|
||||
if(error) {
|
||||
XCTFail(@"got error %@", error);
|
||||
}
|
||||
else {
|
||||
[api getPetByIdWithCompletionBlock:[NSString stringWithFormat:@"%@",[petToAdd _id]] completionHandler:^(SWGPet *output, NSError *error) {
|
||||
if(error) {
|
||||
XCTFail(@"got error %@", error);
|
||||
}
|
||||
if(output == nil){
|
||||
NSLog(@"failed to fetch pet");
|
||||
}
|
||||
else {
|
||||
SWGPet* pet = [[SWGPet alloc] initWithValues:[output asDictionary]];
|
||||
NSLog(@"got the pet");
|
||||
|
||||
[pet setName:@"programmer"];
|
||||
[pet setStatus:@"confused"];
|
||||
|
||||
[api updatePetWithCompletionBlock:pet
|
||||
completionHandler:^(NSError *error) {
|
||||
if(error) {
|
||||
XCTFail(@"got error %@", error);
|
||||
}
|
||||
[api getPetByIdWithCompletionBlock:@1000 completionHandler:^(SWGPet *output, NSError *error) {
|
||||
if(error) {
|
||||
XCTFail(@"got error %@", error);
|
||||
}
|
||||
if(output == nil){
|
||||
NSLog(@"failed to fetch pet");
|
||||
}
|
||||
else {
|
||||
SWGPet* pet = [[SWGPet alloc] initWithValues:[output asDictionary]];
|
||||
XCTAssertNotNil([pet _id], @"pet was nil");
|
||||
XCTAssertEqualObjects([pet name], @"programmer", @"pet name was not updated");
|
||||
XCTAssertEqualObjects([pet status], @"confused", @"pet status was not updated");
|
||||
}
|
||||
}];
|
||||
}];
|
||||
}
|
||||
}];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testGetPetByStatus {
|
||||
bool done = false;
|
||||
static NSMutableArray* pets = nil;
|
||||
static NSError * gError = nil;
|
||||
[api findPetsByStatusWithCompletionBlock:@"available" completionHandler:^(NSArray *output, NSError *error) {
|
||||
if(error) {
|
||||
gError = error;
|
||||
}
|
||||
if(output == nil){
|
||||
NSLog(@"failed to fetch pets");
|
||||
}
|
||||
else {
|
||||
pets = [[NSMutableArray alloc]init];
|
||||
for(SWGPet* pet in output) {
|
||||
[pets addObject:[[SWGPet alloc] initWithValues:[pet asDictionary]]];
|
||||
}
|
||||
}
|
||||
}];
|
||||
NSDate * loopUntil = [NSDate dateWithTimeIntervalSinceNow:10];
|
||||
while(!done && [loopUntil timeIntervalSinceNow] > 0){
|
||||
if(gError){
|
||||
XCTFail(@"got error %@", gError);
|
||||
done = true;
|
||||
}
|
||||
if(pets){
|
||||
for(SWGPet * pet in pets) {
|
||||
XCTAssertEqualObjects([pet status], @"available", @"got invalid status for pets");
|
||||
}
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)testGetPetByTags {
|
||||
[api findPetsByTagsWithCompletionBlock:@"tag1,tag2" completionHandler:^(NSArray *output, NSError *error) {
|
||||
if(error){
|
||||
XCTFail(@"got error %@", error);
|
||||
}
|
||||
if(output){
|
||||
for(SWGPet * pet in output) {
|
||||
bool hasTag = false;
|
||||
for(SWGTag * tag in [pet tags]){
|
||||
if([[tag name] isEqualToString:@"tag1"] || [[tag name] isEqualToString:@"tag2"])
|
||||
hasTag = true;
|
||||
}
|
||||
if(!hasTag)
|
||||
XCTFail(@"failed to find tag in pet");
|
||||
}
|
||||
}
|
||||
}];
|
||||
}
|
||||
@end
|
@ -1,34 +0,0 @@
|
||||
//
|
||||
// PetstoreClientTests.m
|
||||
// PetstoreClientTests
|
||||
//
|
||||
// Created by Tony Tam on 10/18/13.
|
||||
// Copyright (c) 2013 Reverb. All rights reserved.
|
||||
//
|
||||
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
@interface PetstoreClientTests : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation PetstoreClientTests
|
||||
|
||||
- (void)setUp
|
||||
{
|
||||
[super setUp];
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
- (void)tearDown
|
||||
{
|
||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||
[super tearDown];
|
||||
}
|
||||
|
||||
- (void)testExample
|
||||
{
|
||||
XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__);
|
||||
}
|
||||
|
||||
@end
|
24
samples/client/petstore/objc/PetstoreClient/pom.xml
Normal file
24
samples/client/petstore/objc/PetstoreClient/pom.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.felixschulze.my-project</groupId>
|
||||
<artifactId>PetstoreClient</artifactId>
|
||||
<packaging>xcode</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>Swagger Petstore Client</name>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>de.felixschulze.maven.plugins.xcode</groupId>
|
||||
<artifactId>xcode-maven-plugin</artifactId>
|
||||
<version>1.2</version>
|
||||
<configuration>
|
||||
<xcodeProject>PetstoreClient.xcodeproj</xcodeProject>
|
||||
<xcodeTarget>PetstoreClient</xcodeTarget>
|
||||
<xcodeConfiguration>Debug</xcodeConfiguration>
|
||||
<xcodeSdk>iphoneos</xcodeSdk>
|
||||
</configuration>
|
||||
<extensions>true</extensions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
Loading…
x
Reference in New Issue
Block a user