Skip to content

Commit

Permalink
Merge pull request #10 from cisco-open/hh-telephony
Browse files Browse the repository at this point in the history
Support Telephony Items
  • Loading branch information
hughwphamill authored Jul 18, 2023
2 parents d8b0f3d + e870a1e commit 5ec139c
Show file tree
Hide file tree
Showing 17 changed files with 388 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tbclient/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,3 +525,34 @@ type Documentation struct {
Uid string `json:"uid,omitempty"`
DocumentationUrl string `json:"documentationUrl"`
}

// Telephony

type InventoryTelephonyItem struct {
Id string `json:"id"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
}

type inventoryTelephonyItemCollection struct {
Data []InventoryTelephonyItem `json:"inventoryTelephonyItems"`
}

func (t inventoryTelephonyItemCollection) getData() []InventoryTelephonyItem {
return t.Data
}

type TelephonyItem struct {
Uid string `json:"uid,omitempty"`
Name string `json:"name,omitempty"`
InventoryTelephonyItem *InventoryTelephonyItem `json:"inventoryTelephonyItem"`
Topology *Topology `json:"topology"`
}

type telephonyItemCollection struct {
Data []TelephonyItem `json:"telephonyItems"`
}

func (t telephonyItemCollection) getData() []TelephonyItem {
return t.Data
}
67 changes: 67 additions & 0 deletions tbclient/tbclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,19 @@ var documentation = Documentation{
DocumentationUrl: "http://www.google.com",
}

var inventoryTelephonyItem = InventoryTelephonyItem{
Id: "1",
Name: "PSTN Services",
Description: "PSTN Services (VCube)",
}

var telephonyItem = TelephonyItem{
Uid: "lontelephonyitem1",
Name: "PSTN Services",
InventoryTelephonyItem: &inventoryTelephonyItem,
Topology: &Topology{Uid: lonTopology.Uid},
}

func (suite *ContractTestSuite) SetupSuite() {
suite.docker = startWiremock(suite)
suite.tbClient = createTbClient(suite)
Expand Down Expand Up @@ -1313,6 +1326,49 @@ func (suite *ContractTestSuite) TestUpdateDocumentation() {
suite.Equal(expectedDocumentation, *actualDocumentation)
}

func (suite *ContractTestSuite) TestGetAllTelephonyItems() {

// When
telephonyItems, err := suite.tbClient.GetAllTelephonyItems(lonTopology.Uid)
suite.handleError(err)

// Then
suite.Equal(1, len(telephonyItems))
suite.Equal(telephonyItems[0], telephonyItem)
suite.Contains(telephonyItems, telephonyItem)
}

func (suite *ContractTestSuite) TestCreateTelephonyItem() {

// Given
// Match contract
inputTelephonyItem := TelephonyItem{
InventoryTelephonyItem: &InventoryTelephonyItem{Id: inventoryTelephonyItem.Id},
Topology: &Topology{Uid: "rtptopology"},
}

// When
actualTelephonyItem, err := suite.tbClient.CreateTelephonyItem(inputTelephonyItem)
suite.handleError(err)

// Then
// Match contracts
expectedTelephonyItem := telephonyItem
expectedTelephonyItem.Uid = "newtelephonyitem"
expectedTelephonyItem.Topology = inputTelephonyItem.Topology
suite.Equal(expectedTelephonyItem, *actualTelephonyItem)
}

func (suite *ContractTestSuite) TestDeleteTelephonyItem() {

// When
err := suite.tbClient.DeleteTelephonyItem(telephonyItem.Uid)
suite.handleError(err)

// Then
suite.Nil(err)
}

// Inventory Tests

func (suite *ContractTestSuite) TestGetAllOsFamilies() {
Expand Down Expand Up @@ -1425,6 +1481,17 @@ func (suite *ContractTestSuite) TestGetAllInventorySrvProtocols() {
suite.Contains(inventorySrvProtocols, inventorySrvProtocol)
}

func (suite *ContractTestSuite) TestGetAllInventoryTelephonyItems() {

// When
inventoryTelephonyItems, err := suite.tbClient.GetAllInventoryTelephonyItems(lonTopology.Uid)
suite.handleError(err)

// Then
suite.Equal(1, len(inventoryTelephonyItems))
suite.Contains(inventoryTelephonyItems, inventoryTelephonyItem)
}

func TestContractTestSuite(t *testing.T) {
suite.Run(t, new(ContractTestSuite))
}
Expand Down
43 changes: 43 additions & 0 deletions tbclient/telephony.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2023 Cisco Systems, Inc. and its affiliates
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//
// SPDX-License-Identifier: MPL-2.0

package tbclient

func (c *Client) getInventoryTelephonyService(topologyUid string) *collectionService[InventoryTelephonyItem, inventoryTelephonyItemCollection] {
return &collectionService[InventoryTelephonyItem, inventoryTelephonyItemCollection]{
client: c,
resourcePath: "/inventory-telephony-items",
topologyUid: topologyUid,
}
}

func (c *Client) getTelephonyItemService(topologyUid string) *resourceService[TelephonyItem, telephonyItemCollection] {
return &resourceService[TelephonyItem, telephonyItemCollection]{
collectionService[TelephonyItem, telephonyItemCollection]{
client: c,
resourcePath: "/telephony-items",
topologyUid: topologyUid,
},
}
}

func (c *Client) GetAllInventoryTelephonyItems(topologyUid string) ([]InventoryTelephonyItem, error) {
return c.getInventoryTelephonyService(topologyUid).getAll()
}

func (c *Client) GetAllTelephonyItems(topologyUid string) ([]TelephonyItem, error) {
return c.getTelephonyItemService(topologyUid).getAll()
}

func (c *Client) CreateTelephonyItem(telephonyItem TelephonyItem) (*TelephonyItem, error) {
return c.getTelephonyItemService("").create(telephonyItem)
}

func (c *Client) DeleteTelephonyItem(uid string) error {
return c.getTelephonyItemService("").delete(uid)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"id" : "1f566c32-001c-4781-97d6-c7811210f0da",
"request" : {
"urlPath" : "/telephony-items",
"method" : "POST",
"headers" : {
"Content-Type" : {
"contains" : "application/json"
}
},
"bodyPatterns" : [ {
"matchesJsonPath" : "$.['inventoryTelephonyItem'][?(@.['id'] == 'notfound')]"
}, {
"matchesJsonPath" : "$.['topology'][?(@.['uid'] == 'rtptopology')]"
} ]
},
"response" : {
"status" : 400,
"body" : "[{\"logref\":\"GURCFMVPSICDZQWHNJJY\",\"message\":\"The requested dCloud Telephony resource 'notfound' was not found\",\"links\":[]}]",
"headers" : {
"Content-Type" : "application/vnd.error+json"
},
"transformers" : [ "response-template", "spring-cloud-contract" ]
},
"uuid" : "1f566c32-001c-4781-97d6-c7811210f0da"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"id" : "11b6660d-a691-46c6-bb0f-ca4fe2ae7f6a",
"request" : {
"urlPath" : "/telephony-items",
"method" : "POST",
"headers" : {
"Content-Type" : {
"contains" : "application/json"
}
},
"bodyPatterns" : [ {
"matchesJsonPath" : "$.['inventoryTelephonyItem'][?(@.['id'] == '1')]"
}, {
"matchesJsonPath" : "$.['topology'][?(@.['uid'] == 'rtptopology')]"
} ]
},
"response" : {
"status" : 201,
"body" : "{\"uid\":\"newtelephonyitem\",\"name\":\"PSTN Services\",\"inventoryTelephonyItem\":{\"id\":\"{{{jsonPath request.body '$.inventoryTelephonyItem.id'}}}\",\"name\":\"PSTN Services\",\"description\":\"PSTN Services (VCube)\"},\"topology\":{\"uid\":\"{{{jsonPath request.body '$.topology.uid'}}}\"},\"_links\":{\"self\":{\"href\":\"http://localhost{{{request.url}}}/newtelephonyitem\"},\"topology\":{\"href\":\"http://localhost/topologies/{{{jsonPath request.body '$.topology.uid'}}}\"},\"delete\":{\"href\":\"http://localhost{{{request.url}}}/newtelephonyitem\"}}}",
"headers" : {
"Content-Type" : "application/json",
"ETag" : "FIX_ETAG_FOR_TESTS"
},
"transformers" : [ "response-template", "spring-cloud-contract" ]
},
"uuid" : "11b6660d-a691-46c6-bb0f-ca4fe2ae7f6a"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"id" : "58e1c934-f053-4c77-970c-6ebf408777bc",
"request" : {
"urlPath" : "/telephony-items",
"method" : "POST",
"headers" : {
"Content-Type" : {
"contains" : "application/json"
}
},
"bodyPatterns" : [ {
"matchesJsonPath" : "$.['inventoryTelephonyItem'][?(@.['id'] == '1')]"
}, {
"matchesJsonPath" : "$.['topology'][?(@.['uid'] == 'noreader')]"
} ]
},
"response" : {
"status" : 503,
"body" : "[{\"logref\":\"ZCYSJESBKVUKPDRSOTFZ\",\"message\":\"Connectivity to the SNG V2 Reader service has not been configured\",\"links\":[]}]",
"headers" : {
"Content-Type" : "application/vnd.error+json"
},
"transformers" : [ "response-template", "spring-cloud-contract" ]
},
"uuid" : "58e1c934-f053-4c77-970c-6ebf408777bc"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"id" : "448e3d73-75d1-4ce1-86f1-160dfce37e35",
"request" : {
"urlPath" : "/telephony-items/notfound",
"method" : "DELETE"
},
"response" : {
"status" : 404,
"transformers" : [ "response-template", "spring-cloud-contract" ]
},
"uuid" : "448e3d73-75d1-4ce1-86f1-160dfce37e35"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"id" : "c86f46e6-a3ac-4360-8861-47a556ed4164",
"request" : {
"urlPath" : "/telephony-items/lontelephonyitem1",
"method" : "DELETE"
},
"response" : {
"status" : 204,
"transformers" : [ "response-template", "spring-cloud-contract" ]
},
"uuid" : "c86f46e6-a3ac-4360-8861-47a556ed4164"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"id" : "c0d4fc0e-1809-4be9-a986-738300f9cefe",
"request" : {
"urlPath" : "/topologies/lontopology/inventory-telephony-items",
"method" : "GET"
},
"response" : {
"status" : 200,
"body" : "{\"_embedded\":{\"inventoryTelephonyItems\":[{\"id\":\"1\",\"name\":\"PSTN Services\",\"description\":\"PSTN Services (VCube)\"}]},\"_links\":{\"self\":{\"href\":\"http://localhost{{{request.url}}}\"}}}",
"headers" : {
"Content-Type" : "application/json"
},
"transformers" : [ "response-template", "spring-cloud-contract" ]
},
"uuid" : "c0d4fc0e-1809-4be9-a986-738300f9cefe"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"id" : "a2a4de75-efd1-4f55-8234-d197904afcb6",
"request" : {
"urlPath" : "/topologies/noreader/inventory-telephony-items",
"method" : "GET"
},
"response" : {
"status" : 503,
"body" : "[{\"logref\":\"LHNSNITENRLVTVQBMZWQ\",\"message\":\"Connectivity to the SNG V2 Reader service has not been configured\",\"links\":[]}]",
"headers" : {
"Content-Type" : "application/vnd.error+json"
},
"transformers" : [ "response-template", "spring-cloud-contract" ]
},
"uuid" : "a2a4de75-efd1-4f55-8234-d197904afcb6"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"id" : "acddc6a2-286d-4687-84ba-97d16f6394f2",
"request" : {
"urlPath" : "/topologies/rtptopology/inventory-telephony-items",
"method" : "GET"
},
"response" : {
"status" : 200,
"body" : "{\"_embedded\":{\"inventoryTelephonyItems\":[{\"id\":\"1\",\"name\":\"PSTN Services\",\"description\":\"PSTN Services (VCube)\"}]},\"_links\":{\"self\":{\"href\":\"http://localhost{{{request.url}}}\"}}}",
"headers" : {
"Content-Type" : "application/json"
},
"transformers" : [ "response-template", "spring-cloud-contract" ]
},
"uuid" : "acddc6a2-286d-4687-84ba-97d16f6394f2"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"id" : "0439e77e-3a42-4ca6-95a5-4a1309b85821",
"request" : {
"urlPath" : "/topologies/notfound/inventory-telephony-items",
"method" : "GET"
},
"response" : {
"status" : 404,
"body" : "[{\"logref\":\"EWWJZWAWYUSMGDHVNGVN\",\"message\":\"The requested Topology resource was not found\",\"links\":[]}]",
"headers" : {
"Content-Type" : "application/vnd.error+json"
},
"transformers" : [ "response-template", "spring-cloud-contract" ]
},
"uuid" : "0439e77e-3a42-4ca6-95a5-4a1309b85821"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"id" : "61433472-b693-4163-b1f9-e4a4ef29856d",
"request" : {
"urlPath" : "/topologies/rtptopology/telephony-items",
"method" : "GET"
},
"response" : {
"status" : 200,
"body" : "{\"_embedded\":{\"telephonyItems\":[]},\"_links\":{\"self\":{\"href\":\"http://localhost/topologies/rtptopology/telephony-items\"}}}",
"headers" : {
"Content-Type" : "application/json"
},
"transformers" : [ "response-template", "spring-cloud-contract" ]
},
"uuid" : "61433472-b693-4163-b1f9-e4a4ef29856d"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"id" : "7d8a79f0-d169-4f28-9e70-d634aa841d43",
"request" : {
"urlPath" : "/topologies/noreader/telephony-items",
"method" : "GET"
},
"response" : {
"status" : 503,
"body" : "[{\"logref\":\"XKQSUJIVCGVEGQTMSKFW\",\"message\":\"Connectivity to the SNG V2 Reader service has not been configured\",\"links\":[]}]",
"headers" : {
"Content-Type" : "application/vnd.error+json"
},
"transformers" : [ "response-template", "spring-cloud-contract" ]
},
"uuid" : "7d8a79f0-d169-4f28-9e70-d634aa841d43"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"id" : "f9ec35f1-8cff-47ee-8478-f2c3b3e6c702",
"request" : {
"urlPath" : "/topologies/lontopology/telephony-items",
"method" : "GET"
},
"response" : {
"status" : 200,
"body" : "{\"_embedded\":{\"telephonyItems\":[{\"uid\":\"lontelephonyitem1\",\"name\":\"PSTN Services\",\"inventoryTelephonyItem\":{\"id\":\"1\",\"name\":\"PSTN Services\",\"description\":\"PSTN Services (VCube)\"},\"topology\":{\"uid\":\"lontopology\"},\"_links\":{\"self\":{\"href\":\"http://localhost/telephony-items/lontelephonyitem1\"},\"delete\":{\"href\":\"http://localhost/telephony-items/lontelephonyitem1\"},\"topology\":{\"href\":\"http://localhost/topologies/lontopology\"}}}]},\"_links\":{\"self\":{\"href\":\"http://localhost/topologies/lontopology/telephony-items\"}}}",
"headers" : {
"Content-Type" : "application/json"
},
"transformers" : [ "response-template", "spring-cloud-contract" ]
},
"uuid" : "f9ec35f1-8cff-47ee-8478-f2c3b3e6c702"
}
Loading

0 comments on commit 5ec139c

Please sign in to comment.