Tests in the repo - virtserver - xero-api

I am exploring the xero java sdk on the github. I am examining the tests in the com.veersoft.api.client. Many tests have the following
new ApiClient("https://virtserver.swaggerhub.com/Xero/accounting/2.0.0",null,null,null);
What is that 'virtserver' url in the above api?

The virtserver is a virtual server on swaggerhub where we have our OpenAPI spec documents. We've mocked up API responses for endpoints and call those to test the models in the Java SDK.
https://app.swaggerhub.com/apis/Xero/accounting/2.0.0

Related

Executing Pre-steps with karate

In my current middleware integration project, We are using WSO2 API manager tool to manage the API life-cycle.
In test level to access an API I have to create an application and subscribe to the specific API. This can achieved by making a number of rest API requests. I decided to use karate to make these api requests too.
So that part is the pre-steps for my karate test-suite (Or whatever karate tests I execute).
Is there a way to lock down these steps to run before whatever the karate tests I will be executing?
Yes there is, look for karate.callSingle(): https://github.com/intuit/karate#hooks
var result = karate.callSingle('classpath:demo/headers/common-noheaders.feature', config);

Versioning with WebAPI .Net Core does not work as expected

I am trying to introduce URL versioning into my .Net Core WebAPI application. I am also using Swagger web tools for ease of use for users.
Now, while trying to introduce versioning into my application, I referenced the docs here: https://github.com/Microsoft/aspnet-api-versioning/wiki/New-Services-Quick-Start#aspnet-core
Now, I made following code changes into my code:
Startup.cs/ConfigureServices I added code below:
services.AddApiVersioning(options => {
options.AssumeDefaultVersionWhenUnspecified = true;
});
Now, my controller annotations before any kind of versioning was added, looked like below:
[Produces("application/json")]
[Route("api/controllerName")]
and produces a URL which looks like something below:
http://localhost:12003/swagger/#!/Workspace/GetAll
Now, I added annotations below to enable api versioning:
. [ApiVersion("1.0")]
[Produces("application/json")]
[Route("api/v{version:apiVersion}/workspace")]
and now when I click on the same method listed in my swagger UI
the url looks like below:
http://localhost:12003/swagger/#!/controllername/ApiV_versionGetAll
While what I was expecting was something like:
http://localhost:12003/swagger/#!/controllername/V1.0/GetAll
Also on my swagger it is now asking me explicitly about entering version number. So I think my question boils down to two major points:
How I can I fix my URL? and what am I doing wrong?
Why is swagger now asking me to enter version number in API UI when I have explicitly stated that the version is going to be 1.0 in the annotation of the controller?
What you are missing is the complementary package for API versioning that supports an API version-aware API Explorer:
https://www.nuget.org/packages/Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer
Install-Package Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer
The API Explorer is how Swagger generators like Swashbuckle do all their work. The source and links are also available in the API versioning repo.
To achieve the result you want, you need to configure API version substitution in the URL:
services.AddMvcCore().AddVersionedApiExplorer( options => options.SubstituteApiVersionInUrl = true );
Note: that the call the AddMvcCore() is no longer required in API Versioning 3.0+
Documentation and samples are available in the official API versioning repo. I recommend reviewing the API Documentation wiki topic:
https://github.com/Microsoft/aspnet-api-versioning/wiki/API-Documentation
The accepted answer extends this package, which is fine as long as it stay up-to-date with the flavor of API versioning you are using. API Versioning always ships compatible API Explorer extensions on every release.
Setting up api versioning with swagger is indeed a tricky thing as it is lot's of pieces that need to be setup correctly.
Luckily for us, there's a great nuget packages called SwashbuckleAspNetVersioningShim which solves this in an excellent way.
Add it
Install-Package SwashbuckleAspNetVersioningShim -Version 2.2.1
Then follow the readme here

How to test Web Services with Elixir?

We have a couple of REST APIs that need to be tested. APIs are owned by some other team. Currently, we use Node.js with Ava to test our APIs.
We have recently started exploring Elixir as our scripting language. We would like to experiment with Elixir to test REST API. The question here is - how to test external web services/REST API with Elixir?
Every Google search around Elixir testing refers back to ExUnit which is basically for unit testing of Elixir apps. We don't have any app written in Elixir or in Phoenix.
All we want to do is to test API end-to-end. How to do that with Elixir? Which libraries to use? I know I can make network calls from my tests written in ExUnit and verify the API behavior, but not sure if it is the right way.
NOTE: We already have JMeter in place for load testing of API but we wish to keep functional testing separate from load testing due to complex workflows involved with API.
I think what you descried in the answer is the right way.
You can use ExUnit as the test running and reporting framework. In ExUnit you can do whatever you want, make network calls, even parse the DOM. For testing a REST API you can use HTTPoision and assert on status code and response body.
Create a new mix project
mix new api_test
Add HTTPoison dependency to mix.exs
...
defp deps do
[
{:httpoison, "~> 1.6"}
]
end
...
Run mix deps.get to get HTTPoison installed.
Add a test in test/api_test_test.exs
defmodule ApiTestTest do
use ExUnit.Case
doctest ApiTest
test "API alive" do
resp = HTTPoison.get!("https://api.github.com")
assert resp.status_code == 200
end
end
Run the tests with mix test from the project root.

Dynamically controlled swagger / openapi mock server for testing purposes

I'm looking for a project/tool that is able to get swagger / openapi specifications file as a parameter and generate a mock server that can be controlled programmatically via a REST API interface.
For example - if my API contains the following endpoint: "POST /v1/create"
and I have a swagger specs that describe that API, I would like my mock server to be executed in a way similar to:
mock-server -f swagger.yaml -p 8080
While the server runs, It will be possible to interact with it's own REST API (on some control interface via a different port) and change the behavior of the running swagger mock server - i.e: change response code, set response content etc'
I would like to use such mock-server as part of my system-tests suite to better verify my service behavior when interacting with other services - without the need to run those 'real' services.
I'm looking for something similar in spirit to Shopyify's ToxiProxy (https://github.com/Shopify/toxiproxy) but with the above capabilities.
Thanks!
Eldad
I know I'm a bit late to the party on this one, but for future searchers, MockLab now supports auto-generation of mock APIs from an imported Swagger definition and Swaggerhub webhooks.
More details here:
https://www.mocklab.io/blog/mocklab-now-supports-swagger-and-swaggerhub/
I believe Specmatic should help you with this.
mock-server -f swagger.yaml -p 8080
Specmatic works exactly this way. To start a mock server with an OpenAPI specification file we can run below command.
specmatic stub service.yaml --port 8080
Here is the documentation.
While the server runs, It will be possible to interact with it's own REST API (on some control interface via a different port) and change the behaviour of the running swagger mock server - i.e: change response code, set response content etc'
This is also supported. Specmatic has a http interface to which you can post the request and response mappings / expectations. We call this dynamic mocks. Here is the documentation.
Here is a video on this.
Disclosure: I am lead dev and CTO at Specmatic

How to test gRPC APIs?

I have been assigned to test a gRPC API (written in Golang) but I don't know how to go about testing it and I couldn't find any tutorials online for this type of testing. The only method that I can think of is to write unit tests to test the methods themselves but I would like to also test it with a client. For example, I have tested REST APIs in the past using JMeter as a client to send requests and verify the response data. Is there a method for testing gRPC APIs with a client or is unit testing the only way?
Well, I was in search for a client like Postman, then i found bloomrpc, which helps in calling grpc services. But i am not sure if it serves your purpose, if you are looking for a tool like jmeter.
If you are searching for a tool like Postman, there is also https://kreya.app. With it, you can call your gRPC services and view the responses.
Disclaimer: I'm one of the authors of Kreya.
Since you mentiond you've done testing before with JMeter, I assume that you're looking for an external test client that can call the gRPC service. There are several that you can use. The common ones are
BloomRPC
Kreya
Wombat
Fint
With those 4 clients, you can dynamically call gRPC services. However, if you are looking a test client that can also do load testing, Fint is the one you will need.
There can be two type of testing.
Testing just the implementation of the gRPC method by ignoring the networking
this question answers this aspect of the testing. By just writing the unit test for the RPC method
If you want to test both the implementation and the gRPC networking aspects as well then you need write the gRPC client for the service you want to test.
Here a code snippet about creating a gRPC client
// Set up a connection to the server.
conn, err := grpc.Dial(address, grpc.WithInsecure())
// Execute RPC you want to test
r, err := c.SayHello(context.Background(), &pb.HelloRequest{Name: name})
Check here for complete code example
Postman just published they have grpc in beta :
https://blog.postman.com/postman-now-supports-grpc/
I tested it just now and it worked perfectly for me 👍🏻🙂
You can also try this command line tool, evans, for testing gRPC
For anyone who stumbles upon this thread ...
All the previous answers have already provided good tools. We used BloomRPC & Kreya in our team (individual choices).
What I want to add is this gRPC Ecosystem Page. It contains a curated lists of all related tools. There are other GUI test tools (see GUI section), or Load testing, benchmarking tools (Testing)
https://github.com/grpc-ecosystem/awesome-grpc
PS : I'll be honest, I have not able to check all tools besides BloomRPC & Kreya.