Skip to content

Commit

Permalink
Merge pull request #1 from OpenAPITools/master
Browse files Browse the repository at this point in the history
test
  • Loading branch information
Ghufz committed Apr 16, 2020
2 parents 3b94ce7 + 41664b3 commit 49f2b4b
Show file tree
Hide file tree
Showing 2,916 changed files with 110,893 additions and 24,038 deletions.
28 changes: 26 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,33 @@ after_success:
fi;
fi;
## docker: build and push openapi-generator-online to DockerHub
- if [ $DOCKER_HUB_USERNAME ]; then echo "$DOCKER_HUB_PASSWORD" | docker login --username=$DOCKER_HUB_USERNAME --password-stdin && docker build -t $DOCKER_GENERATOR_IMAGE_NAME ./modules/openapi-generator-online && if [ ! -z "$TRAVIS_TAG" ]; then docker tag $DOCKER_GENERATOR_IMAGE_NAME:latest $DOCKER_GENERATOR_IMAGE_NAME:$TRAVIS_TAG; fi && if [ ! -z "$TRAVIS_TAG" ] || [ "$TRAVIS_BRANCH" = "master" ]; then docker push $DOCKER_GENERATOR_IMAGE_NAME && echo "Pushed to $DOCKER_GENERATOR_IMAGE_NAME"; fi; fi
- if [ $DOCKER_HUB_USERNAME ]; then
echo "$DOCKER_HUB_PASSWORD" | docker login --username=$DOCKER_HUB_USERNAME --password-stdin;
export cli_version=$(\mvn -o org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version | grep -v '\[');
export build_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ");
docker build --label=org.opencontainers.image.created=$build_date --label=org.opencontainers.image.title=openapi-generator-online --label=org.opencontainers.image.revision=$TRAVIS_COMMIT --label=org.opencontainers.image.version=$cli_version -t $DOCKER_GENERATOR_IMAGE_NAME ./modules/openapi-generator-online;
if [ ! -z "$TRAVIS_TAG" ]; then
docker tag $DOCKER_GENERATOR_IMAGE_NAME:latest $DOCKER_GENERATOR_IMAGE_NAME:$TRAVIS_TAG;
fi;
if [ ! -z "$TRAVIS_TAG" ] || [ "$TRAVIS_BRANCH" = "master" ]; then
docker push $DOCKER_GENERATOR_IMAGE_NAME && echo "Pushed to $DOCKER_GENERATOR_IMAGE_NAME";
fi;
fi;
## docker: build cli image and push to Docker Hub
- if [ $DOCKER_HUB_USERNAME ]; then echo "$DOCKER_HUB_PASSWORD" | docker login --username=$DOCKER_HUB_USERNAME --password-stdin && cp docker-entrypoint.sh ./modules/openapi-generator-cli && docker build -t $DOCKER_CODEGEN_CLI_IMAGE_NAME ./modules/openapi-generator-cli && if [ ! -z "$TRAVIS_TAG" ]; then docker tag $DOCKER_CODEGEN_CLI_IMAGE_NAME:latest $DOCKER_CODEGEN_CLI_IMAGE_NAME:$TRAVIS_TAG; fi && if [ ! -z "$TRAVIS_TAG" ] || [ "$TRAVIS_BRANCH" = "master" ]; then docker push $DOCKER_CODEGEN_CLI_IMAGE_NAME && echo "Pushed to $DOCKER_CODEGEN_CLI_IMAGE_NAME"; fi; fi
- if [ $DOCKER_HUB_USERNAME ]; then
echo "$DOCKER_HUB_PASSWORD" | docker login --username=$DOCKER_HUB_USERNAME --password-stdin;
cp docker-entrypoint.sh ./modules/openapi-generator-cli;
export cli_version=$(\mvn -o org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version | grep -v '\[');
export build_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ");
docker build --label=org.opencontainers.image.created=$build_date --label=org.opencontainers.image.title=openapi-generator-cli --label=org.opencontainers.image.revision=$TRAVIS_COMMIT --label=org.opencontainers.image.version=$cli_version -t $DOCKER_CODEGEN_CLI_IMAGE_NAME ./modules/openapi-generator-cli;
if [ ! -z "$TRAVIS_TAG" ]; then
docker tag $DOCKER_CODEGEN_CLI_IMAGE_NAME:latest $DOCKER_CODEGEN_CLI_IMAGE_NAME:$TRAVIS_TAG;
fi;
if [ ! -z "$TRAVIS_TAG" ] || [ "$TRAVIS_BRANCH" = "master" ]; then
docker push $DOCKER_CODEGEN_CLI_IMAGE_NAME;
echo "Pushed to $DOCKER_CODEGEN_CLI_IMAGE_NAME";
fi;
fi;
## publish latest website, variables below are secure environment variables which are unavailable to PRs from forks.
- if [ "$TRAVIS_BRANCH" = "master" ] && [ -z $TRAVIS_TAG ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
cd website;
Expand Down
13 changes: 7 additions & 6 deletions CI/.drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ steps:
image: haskell:8.6.5
commands:
- (cd samples/client/petstore/haskell-http-client/ && stack --install-ghc --no-haddock-deps haddock --fast && stack test --fast)
# below dart tests moved to circle ci
# test Dart 2.x petstore client
- name: dart2x-test
image: google/dart
commands:
- (cd samples/client/petstore/dart-jaguar/openapi && pub get && pub run build_runner build --delete-conflicting-outputs)
- (cd samples/client/petstore/dart-jaguar/flutter_petstore/openapi && pub get && pub run build_runner build --delete-conflicting-outputs)
- (cd samples/client/petstore/dart2/petstore && pub get && pub run test)
#- name: dart2x-test
# image: google/dart
# commands:
# - (cd samples/client/petstore/dart-jaguar/openapi && pub get && pub run build_runner build --delete-conflicting-outputs)
# - (cd samples/client/petstore/dart-jaguar/flutter_petstore/openapi && pub get && pub run build_runner build --delete-conflicting-outputs)
# - (cd samples/client/petstore/dart2/petstore && pub get && pub run test)
# test Java 11 HTTP client
- name: java11-test
image: openjdk:11.0
Expand Down
31 changes: 12 additions & 19 deletions CI/bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ workflows:
mvn package -Dorg.slf4j.simpleLogger.defaultLogLevel=error
title: Build openapi-generator
- [email protected]:
title: Update Swift4 samples
title: Update Swift samples
inputs:
- content: |
#!/usr/bin/env bash
set -e
sh bin/swift4-all.sh
sh bin/swift5-all.sh
- [email protected]:
title: Run Swift4 tests
inputs:
Expand All @@ -49,15 +50,6 @@ workflows:
./samples/client/petstore/swift4/swift4_test_all.sh
./samples/client/test/swift4/swift4_test_all.sh
- [email protected]:
title: Update Swift5 samples
inputs:
- content: |
#!/usr/bin/env bash
set -e
sh bin/swift5-all.sh
- [email protected]:
title: Run Swift5 tests
inputs:
Expand All @@ -66,14 +58,15 @@ workflows:
set -e
./samples/client/petstore/swift5/swift5_test_all.sh
./samples/client/test/swift5/swift5_test_all.sh
- [email protected]:
title: Run all bin scripts
inputs:
- content: |-
#!/usr/bin/env bash
set -e
# comment out the following as it's causing timeout
# - [email protected]:
# title: Run all bin scripts
# inputs:
# - content: |-
# #!/usr/bin/env bash
#
# set -e
#
# ./bin/run-all-petstore

./bin/run-all-petstore
27 changes: 25 additions & 2 deletions CI/circle_parallel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,23 @@ NODE_INDEX=${CIRCLE_NODE_INDEX:-0}

set -e

function cleanup {
# Show logs of 'petstore.swagger' container to troubleshoot Unit Test failures, if any.
docker logs petstore.swagger # container name specified in circle.yml
}

trap cleanup EXIT

if [ "$NODE_INDEX" = "1" ]; then
echo "Running node $NODE_INDEX to test 'samples.circleci' defined in pom.xml ..."
#cp CI/pom.xml.circleci pom.xml
java -version
# Install golang version 1.14
go version
sudo mkdir /usr/local/go1.14
wget -c https://dl.google.com/go/go1.14.linux-amd64.tar.gz -O - | sudo tar -xz -C /usr/local/go1.14
export PATH="/usr/local/go1.14/go/bin:$PATH"
go version

mvn --quiet verify -Psamples.circleci -Dorg.slf4j.simpleLogger.defaultLogLevel=error
mvn --quiet javadoc:javadoc -Psamples.circleci -Dorg.slf4j.simpleLogger.defaultLogLevel=error

Expand Down Expand Up @@ -46,13 +59,23 @@ elif [ "$NODE_INDEX" = "2" ]; then
# install curl
sudo apt-get -y build-dep libcurl4-gnutls-dev
sudo apt-get -y install libcurl4-gnutls-dev

# run integration tests
mvn --quiet verify -Psamples.misc -Dorg.slf4j.simpleLogger.defaultLogLevel=error
else
echo "Running node $NODE_INDEX to test 'samples.circleci.jdk7' defined in pom.xml ..."
sudo update-java-alternatives -s java-1.7.0-openjdk-amd64
java -version
#cp CI/pom.xml.circleci.java7 pom.xml

# install dart2
sudo apt-get update
sudo apt-get install apt-transport-https
sudo sh -c 'wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -'
sudo sh -c 'wget -qO- https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list'
sudo apt-get update
sudo apt-get install dart
export PATH="$PATH:/usr/lib/dart/bin"

mvn --quiet verify -Psamples.circleci.jdk7 -Dorg.slf4j.simpleLogger.defaultLogLevel=error
fi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ OpenAPI Petstore
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
OpenAPI spec version: 1.0.0
The version of the OpenAPI document: 1.0.0
-->
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
Expand Down Expand Up @@ -47,16 +47,16 @@ OpenAPI spec version: 1.0.0
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml" />
<Reference Include="Newtonsoft.Json">
<HintPath Condition="Exists('$(SolutionDir)\packages')">$(SolutionDir)\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<HintPath Condition="Exists('..\packages')">..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<HintPath Condition="Exists('..\..\packages')">..\..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<HintPath Condition="Exists('..\..\vendor')">..\..\vendor\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<HintPath Condition="Exists('$(SolutionDir)\packages')">$(SolutionDir)\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<HintPath Condition="Exists('..\packages')">..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<HintPath Condition="Exists('..\..\packages')">..\..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<HintPath Condition="Exists('..\..\vendor')">..\..\vendor\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="JsonSubTypes">
<HintPath Condition="Exists('$(SolutionDir)\packages')">$(SolutionDir)\packages\JsonSubTypes.1.5.2\lib\net45\JsonSubTypes.dll</HintPath>
<HintPath Condition="Exists('..\packages')">..\packages\JsonSubTypes.1.5.2\lib\net45\JsonSubTypes.dll</HintPath>
<HintPath Condition="Exists('..\..\packages')">..\..\packages\JsonSubTypes.1.5.2\lib\net45\JsonSubTypes.dll</HintPath>
<HintPath Condition="Exists('..\..\vendor')">..\..\vendor\JsonSubTypes.1.5.2\lib\net45\JsonSubTypes.dll</HintPath>
<HintPath Condition="Exists('$(SolutionDir)\packages')">$(SolutionDir)\packages\JsonSubTypes.1.6.0\lib\net45\JsonSubTypes.dll</HintPath>
<HintPath Condition="Exists('..\packages')">..\packages\JsonSubTypes.1.6.0\lib\net45\JsonSubTypes.dll</HintPath>
<HintPath Condition="Exists('..\..\packages')">..\..\packages\JsonSubTypes.1.6.0\lib\net45\JsonSubTypes.dll</HintPath>
<HintPath Condition="Exists('..\..\vendor')">..\..\vendor\JsonSubTypes.1.6.0\lib\net45\JsonSubTypes.dll</HintPath>
</Reference>
<Reference Include="RestSharp">
<HintPath Condition="Exists('$(SolutionDir)\packages')">$(SolutionDir)\packages\RestSharp.105.1.0\lib\net45\RestSharp.dll</HintPath>
Expand All @@ -72,7 +72,8 @@ OpenAPI spec version: 1.0.0
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="**\*.cs" Exclude="obj\**" />
<Compile Include="**\*.cs"
Exclude="obj\**"/>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.junit.*;

Expand All @@ -42,20 +45,24 @@
public class PetApiTest {

private PetApi api = new PetApi();
private static final Logger LOG = LoggerFactory.getLogger(PetApiTest.class);
// In the circle.yml file, /etc/host is configured with an entry to resolve petstore.swagger.io to 127.0.0.1
private static String basePath = "http://petstore.swagger.io:80/v2";

@Before
public void setup() {
// setup authentication
ApiKeyAuth apiKeyAuth = (ApiKeyAuth) api.getApiClient().getAuthentication("api_key");
apiKeyAuth.setApiKey("special-key");
api.getApiClient().setBasePath(basePath);
}

@Test
public void testApiClient() {
// the default api client is used
assertEquals(Configuration.getDefaultApiClient(), api.getApiClient());
assertNotNull(api.getApiClient());
assertEquals("http://petstore.swagger.io:80/v2", api.getApiClient().getBasePath());
assertEquals(basePath, api.getApiClient().getBasePath());
assertFalse(api.getApiClient().isDebugging());

ApiClient oldClient = api.getApiClient();
Expand All @@ -74,7 +81,7 @@ public void testApiClient() {
// set api client via setter method
api.setApiClient(oldClient);
assertNotNull(api.getApiClient());
assertEquals("http://petstore.swagger.io:80/v2", api.getApiClient().getBasePath());
assertEquals(basePath, api.getApiClient().getBasePath());
assertFalse(api.getApiClient().isDebugging());
}

Expand All @@ -85,6 +92,7 @@ public void testCreateAndGetPet() throws Exception {

Pet fetched = api.getPetById(pet.getId());
assertPetMatches(pet, fetched);
api.deletePet(pet.getId(), null);
}

@Test
Expand All @@ -98,6 +106,7 @@ public void testCreateAndGetPetWithHttpInfo() throws Exception {
Pet fetched = resp.getData();

assertPetMatches(pet, fetched);
api.deletePet(pet.getId(), null);
}

@Test
Expand Down Expand Up @@ -144,6 +153,7 @@ public void onDownloadProgress(long bytesRead, long contentLength, boolean done)
}
} while (result.isEmpty());
assertPetMatches(pet, fetched);
api.deletePet(pet.getId(), null);
}

@Test
Expand Down Expand Up @@ -197,6 +207,7 @@ public void onDownloadProgress(long bytesRead, long contentLength, boolean done)
assertEquals(404, exception.getCode());
assertEquals("Not Found", exception.getMessage());
assertEquals("application/json", exception.getResponseHeaders().get("Content-Type").get(0));
api.deletePet(pet.getId(), null);
}

@Test
Expand Down Expand Up @@ -255,26 +266,31 @@ public void testCreateAndGetMultiplePetsAsync() throws Exception {
final ApiException exception = getCallback3.getException();
assertNotNull(exception);
assertEquals(404, exception.getCode());
api.deletePet(pet1.getId(), null);
api.deletePet(pet2.getId(), null);
}


@Test
public void testUpdatePet() throws Exception {
Pet pet = createPet();
api.addPet(pet);
pet.setName("programmer");

api.updatePet(pet);

Pet fetched = api.getPetById(pet.getId());
assertPetMatches(pet, fetched);
api.deletePet(pet.getId(), null);
}

@Test
public void testFindPetsByStatus() throws Exception {
assertEquals(basePath, api.getApiClient().getBasePath());
Pet pet = createPet();
api.addPet(pet);
pet.setName("programmer");
pet.setStatus(Pet.StatusEnum.PENDING);

api.updatePet(pet);

List<Pet> pets = api.findPetsByStatus(Arrays.asList("pending"));
Expand Down Expand Up @@ -335,6 +351,7 @@ public void testUpdatePetWithForm() throws Exception {
Pet updated = api.getPetById(fetched.getId());

assertEquals(updated.getName(), "furt");
api.deletePet(pet.getId(), null);
}

@Test
Expand All @@ -343,12 +360,13 @@ public void testDeletePet() throws Exception {
api.addPet(pet);

Pet fetched = api.getPetById(pet.getId());
api.deletePet(fetched.getId(), null);
api.deletePet(pet.getId(), null);

try {
fetched = api.getPetById(fetched.getId());
fail("expected an error");
} catch (ApiException e) {
LOG.info("Code: {}. Message: {}", e.getCode(), e.getMessage());
assertEquals(404, e.getCode());
}
}
Expand All @@ -364,6 +382,7 @@ public void testUploadFile() throws Exception {
writer.close();

api.uploadFile(pet.getId(), "a test file", new File(file.getAbsolutePath()));
api.deletePet(pet.getId(), null);
}

@Test
Expand Down Expand Up @@ -396,7 +415,7 @@ public void testEqualsAndHashCode() {

private Pet createPet() {
Pet pet = new Pet();
pet.setId(1234567L);
pet.setId(ThreadLocalRandom.current().nextLong(Long.MAX_VALUE));
pet.setName("gorilla");

Category category = new Category();
Expand Down
7 changes: 6 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ To test the templates, please perform the following:
(`git add -A` if added files with new test cases)
- For new test cases, please add to the [Fake Petstore spec](https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml)

To start the CI tests, you can run `mvn verify -Psamples` (assuming you've all the required tools installed to run tests for different languages) or you can leverage http://travis-ci.org to run the CI tests by adding your own openapi-generator repository.
To start the CI tests, you can:
- Run `mvn verify -Psamples`, assuming you have all the required tools installed to run tests for different languages.
- Leverage http://travis-ci.org to run the CI tests by adding your own openapi-generator repository.
- Run some of the CI tests in your local workspace.

See [OpenAPI Tools wiki](https://github.com/OpenAPITools/openapi-generator/wiki/Integration-Tests) for more information about the integration tests.

### Tips
- Smaller changes are easier to review
Expand Down
Loading

0 comments on commit 49f2b4b

Please sign in to comment.