Skip to content

Commit

Permalink
Merge pull request #19 from cfcosta/middleware-api-endpoints
Browse files Browse the repository at this point in the history
Middleware API Endpoints
  • Loading branch information
abellotti authored Sep 20, 2017
2 parents ef8a010 + d9ef130 commit 02f47ff
Show file tree
Hide file tree
Showing 12 changed files with 496 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/controllers/api/middleware_datasources_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Api
class MiddlewareDatasourcesController < BaseController
end
end
4 changes: 4 additions & 0 deletions app/controllers/api/middleware_deployments_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Api
class MiddlewareDeploymentsController < BaseController
end
end
4 changes: 4 additions & 0 deletions app/controllers/api/middleware_domains_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Api
class MiddlewareDomainsController < BaseController
end
end
4 changes: 4 additions & 0 deletions app/controllers/api/middleware_messagings_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Api
class MiddlewareMessagingsController < BaseController
end
end
4 changes: 4 additions & 0 deletions app/controllers/api/middleware_servers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Api
class MiddlewareServersController < BaseController
end
end
85 changes: 85 additions & 0 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,91 @@
:get:
- :name: read
:identifier: metrics_view
:middleware_datasources:
:description: Middleware Datasources
:klass: MiddlewareDatasource
:options:
- :collection
:verbs: *gp
:collection_actions:
:get:
- :name: read
:identifier: middleware_datasource_show_list
:post:
- :name: query
:identifier: middleware_datasource_show_list
:resource_actions:
:get:
- :name: read
:identifier: middleware_datasource_show
:middleware_deployments:
:description: Middleware Deployments
:klass: MiddlewareDeployment
:options:
- :collection
:verbs: *gp
:collection_actions:
:get:
- :name: read
:identifier: middleware_deployment_show_list
:post:
- :name: query
:identifier: middleware_deployment_show_list
:resource_actions:
:get:
- :name: read
:identifier: middleware_deployment_show
:middleware_domains:
:description: Middleware Domains
:klass: MiddlewareDomain
:options:
- :collection
:verbs: *gp
:collection_actions:
:get:
- :name: read
:identifier: middleware_domain_show_list
:post:
- :name: query
:identifier: middleware_domain_show_list
:resource_actions:
:get:
- :name: read
:identifier: middleware_domain_show
:middleware_messagings:
:description: Middleware Messagings
:klass: MiddlewareMessaging
:options:
- :collection
:verbs: *gp
:collection_actions:
:get:
- :name: read
:identifier: middleware_messaging_show_list
:post:
- :name: query
:identifier: middleware_messaging_show_list
:resource_actions:
:get:
- :name: read
:identifier: middleware_messaging_show
:middleware_servers:
:description: Middleware Servers
:klass: MiddlewareServer
:options:
- :collection
:verbs: *gp
:collection_actions:
:get:
- :name: read
:identifier: middleware_server_show_list
:post:
- :name: query
:identifier: middleware_server_show_list
:resource_actions:
:get:
- :name: read
:identifier: middleware_server_show
:network_routers:
:description: Network_Routers
:identifier: network_router
Expand Down
50 changes: 50 additions & 0 deletions spec/requests/collections_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,31 @@ def test_collection_bulk_query(collection, collection_url, klass, id = nil)
test_collection_query(:hosts, api_hosts_url, Host, :guid)
end

it "query Middleware Datasources" do
FactoryGirl.create(:middleware_datasource)
test_collection_query(:middleware_datasources, api_middleware_datasources_url, MiddlewareDatasource)
end

it "query Middleware Deployments" do
FactoryGirl.create(:middleware_deployment)
test_collection_query(:middleware_deployments, api_middleware_deployments_url, MiddlewareDeployment)
end

it "query Middleware Domains" do
FactoryGirl.create(:middleware_domain)
test_collection_query(:middleware_domains, api_middleware_domains_url, MiddlewareDomain)
end

it "query Middleware Messagings" do
FactoryGirl.create(:middleware_messaging)
test_collection_query(:middleware_messagings, api_middleware_messagings_url, MiddlewareMessaging)
end

it "query Middleware Servers" do
FactoryGirl.create(:middleware_server)
test_collection_query(:middleware_servers, api_middleware_servers_url, MiddlewareServer)
end

it "query Pictures" do
FactoryGirl.create(:picture)
test_collection_query(:pictures, api_pictures_url, Picture)
Expand Down Expand Up @@ -406,6 +431,31 @@ def test_collection_bulk_query(collection, collection_url, klass, id = nil)
test_collection_bulk_query(:hosts, api_hosts_url, Host)
end

it "bulk query MiddlewareDatasources" do
FactoryGirl.create(:middleware_datasource)
test_collection_bulk_query(:middleware_datasources, api_middleware_datasources_url, MiddlewareDatasource)
end

it "bulk query MiddlewareDeployments" do
FactoryGirl.create(:middleware_deployment)
test_collection_bulk_query(:middleware_deployments, api_middleware_deployments_url, MiddlewareDeployment)
end

it "bulk query MiddlewareDomains" do
FactoryGirl.create(:middleware_domain)
test_collection_bulk_query(:middleware_domains, api_middleware_domains_url, MiddlewareDomain)
end

it "bulk query MiddlewareMessaging" do
FactoryGirl.create(:middleware_messaging)
test_collection_bulk_query(:middleware_messagings, api_middleware_messagings_url, MiddlewareMessaging)
end

it "bulk query MiddlewareServer" do
FactoryGirl.create(:middleware_server)
test_collection_bulk_query(:middleware_servers, api_middleware_servers_url, MiddlewareServer)
end

it 'bulk query NetworkRouters' do
FactoryGirl.create(:network_router)
test_collection_bulk_query(:network_routers, api_network_routers_url, NetworkRouter)
Expand Down
67 changes: 67 additions & 0 deletions spec/requests/middleware_datasources_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
describe 'Middleware Datasources API' do
let(:datasource) { FactoryGirl.create(:middleware_datasource) }

describe '/' do
it 'forbids access without an appropriate role' do
api_basic_authorize

get api_middleware_datasources_url

expect(response).to have_http_status(:forbidden)
end

it 'returns an empty listing of datasources' do
api_basic_authorize collection_action_identifier(:middleware_datasources, :read, :get)

get api_middleware_datasources_url

expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(
'name' => 'middleware_datasources',
'count' => 0,
'resources' => [],
'subcount' => 0
)
end

it 'returns a listing of datasources' do
datasource

api_basic_authorize collection_action_identifier(:middleware_datasources, :read, :get)

get api_middleware_datasources_url

expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(
'name' => 'middleware_datasources',
'count' => 1,
'resources' => [{
'href' => api_middleware_datasource_url(nil, datasource)
}],
'subcount' => 1
)
end
end

describe '/:id' do
it 'forbids access to a datasource without an appropriate role' do
api_basic_authorize

get api_middleware_datasource_url(nil, datasource)

expect(response).to have_http_status(:forbidden)
end

it 'returns the attributes of one datasource' do
api_basic_authorize action_identifier(:middleware_datasources, :read, :resource_actions, :get)

get api_middleware_datasource_url(nil, datasource)

expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(
'id' => datasource.id.to_s,
'href' => api_middleware_datasource_url(nil, datasource)
)
end
end
end
69 changes: 69 additions & 0 deletions spec/requests/middleware_deployments_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
describe 'Middleware Deployments API' do
let(:deployment) { FactoryGirl.create(:middleware_deployment) }

describe '/' do
it 'forbids access without an appropriate role' do
api_basic_authorize

get api_middleware_deployments_url

expect(response).to have_http_status(:forbidden)
end

it 'returns an empty listing of deployments' do
api_basic_authorize collection_action_identifier(:middleware_deployments, :read, :get)

get api_middleware_deployments_url

expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(
'name' => 'middleware_deployments',
'count' => 0,
'resources' => [],
'subcount' => 0
)
end

it 'returns a a listing of deployments' do
deployment

api_basic_authorize collection_action_identifier(:middleware_deployments, :read, :get)

get api_middleware_deployments_url

expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(
'name' => 'middleware_deployments',
'count' => 1,
'resources' => [{
'href' => api_middleware_deployment_url(nil, deployment)
}],
'subcount' => 1
)
end
end

describe '/:id' do
it 'forbids access to a deployment without an appropriate role' do
api_basic_authorize

get api_middleware_deployment_url(nil, deployment)

expect(response).to have_http_status(:forbidden)
end

it 'returns the attributes of one deployment' do
api_basic_authorize action_identifier(:middleware_deployments, :read, :resource_actions, :get)

get api_middleware_deployment_url(nil, deployment)

expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(
'id' => deployment.id.to_s,
'ems_id' => deployment.ems_id.to_s,
'href' => api_middleware_deployment_url(nil, deployment),
'name' => deployment.name
)
end
end
end
68 changes: 68 additions & 0 deletions spec/requests/middleware_domains_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
describe 'Middleware Domains API' do
let(:domain) { FactoryGirl.create :middleware_domain }

describe '/' do
it 'forbids access without an appropriate role' do
api_basic_authorize

get api_middleware_domains_url

expect(response).to have_http_status(:forbidden)
end

it 'returns an empty listing of domains' do
api_basic_authorize collection_action_identifier(:middleware_domains, :read, :get)

get api_middleware_domains_url

expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(
'name' => 'middleware_domains',
'count' => 0,
'resources' => [],
'subcount' => 0
)
end

it 'returns a listing of domains' do
domain

api_basic_authorize collection_action_identifier(:middleware_domains, :read, :get)

get api_middleware_domains_url

expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(
'name' => 'middleware_domains',
'count' => 1,
'resources' => [{
'href' => api_middleware_domain_url(nil, domain)
}],
'subcount' => 1
)
end
end

describe '/:id' do
it 'forbids access to a domain without an appropriate role' do
api_basic_authorize

get api_middleware_domain_url(nil, domain)

expect(response).to have_http_status(:forbidden)
end

it 'returns the attributes of one domain' do
api_basic_authorize action_identifier(:middleware_domains, :read, :resource_actions, :get)

get api_middleware_domain_url(nil, domain)

expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(
'id' => domain.id.to_s,
'href' => api_middleware_domain_url(nil, domain),
'name' => domain.name
)
end
end
end
Loading

0 comments on commit 02f47ff

Please sign in to comment.