From adabfc8e9ca71dd7eef4039e4d31eb0ac6838f90 Mon Sep 17 00:00:00 2001 From: Sonja Happ Date: Tue, 20 Oct 2020 15:27:36 +0200 Subject: [PATCH] Transform Properties into StartParameterScheme --- database/models.go | 4 +- doc/api/docs.go | 10 +- doc/api/swagger.json | 8 +- doc/api/swagger.yaml | 8 +- helper/test_data.go | 4 +- routes/component-configuration/config_test.go | 54 ++--- routes/infrastructure-component/ic_test.go | 184 +++++++++--------- .../infrastructure-component/ic_validators.go | 46 ++--- routes/signal/signal_test.go | 36 ++-- 9 files changed, 177 insertions(+), 177 deletions(-) diff --git a/database/models.go b/database/models.go index 83852b8..1bb61e4 100644 --- a/database/models.go +++ b/database/models.go @@ -138,8 +138,8 @@ type InfrastructureComponent struct { Location string `json:"location" gorm:"default:''"` // Description of the IC Description string `json:"description" gorm:"default:''"` - // Properties of IC as JSON string - Properties postgres.Jsonb `json:"properties"` + // JSON scheme of start parameters for IC + StartParameterScheme postgres.Jsonb `json:"startparameterscheme"` // ComponentConfigurations in which the IC is used ComponentConfigurations []ComponentConfiguration `json:"-" gorm:"foreignkey:ICID"` } diff --git a/doc/api/docs.go b/doc/api/docs.go index becdbf9..e5d15c6 100644 --- a/doc/api/docs.go +++ b/doc/api/docs.go @@ -1,6 +1,6 @@ // GENERATED BY THE COMMAND ABOVE; DO NOT EDIT // This file was generated by swaggo/swag at -// 2020-10-20 12:56:57.842992188 +0200 CEST m=+0.084567298 +// 2020-10-20 15:23:51.266197121 +0200 CEST m=+0.098130845 package docs @@ -3000,8 +3000,8 @@ var doc = `{ "description": "Name of the IC", "type": "string" }, - "properties": { - "description": "Properties of IC as JSON string", + "startparameterscheme": { + "description": "JSON scheme of start parameters for IC", "type": "string" }, "state": { @@ -3397,7 +3397,7 @@ var doc = `{ "Name": { "type": "string" }, - "Properties": { + "StartParameterScheme": { "type": "string" }, "State": { @@ -3432,7 +3432,7 @@ var doc = `{ "Name": { "type": "string" }, - "Properties": { + "StartParameterScheme": { "type": "string" }, "State": { diff --git a/doc/api/swagger.json b/doc/api/swagger.json index 74f22a7..5bbbc4a 100644 --- a/doc/api/swagger.json +++ b/doc/api/swagger.json @@ -2983,8 +2983,8 @@ "description": "Name of the IC", "type": "string" }, - "properties": { - "description": "Properties of IC as JSON string", + "startparameterscheme": { + "description": "JSON scheme of start parameters for IC", "type": "string" }, "state": { @@ -3380,7 +3380,7 @@ "Name": { "type": "string" }, - "Properties": { + "StartParameterScheme": { "type": "string" }, "State": { @@ -3415,7 +3415,7 @@ "Name": { "type": "string" }, - "Properties": { + "StartParameterScheme": { "type": "string" }, "State": { diff --git a/doc/api/swagger.yaml b/doc/api/swagger.yaml index b1c2b74..c59428e 100644 --- a/doc/api/swagger.yaml +++ b/doc/api/swagger.yaml @@ -163,8 +163,8 @@ definitions: name: description: Name of the IC type: string - properties: - description: Properties of IC as JSON string + startparameterscheme: + description: JSON scheme of start parameters for IC type: string state: description: State of the IC @@ -431,7 +431,7 @@ definitions: type: string Name: type: string - Properties: + StartParameterScheme: type: string State: type: string @@ -459,7 +459,7 @@ definitions: type: string Name: type: string - Properties: + StartParameterScheme: type: string State: type: string diff --git a/helper/test_data.go b/helper/test_data.go index 60a050b..32ef8fc 100644 --- a/helper/test_data.go +++ b/helper/test_data.go @@ -102,7 +102,7 @@ var ICA = database.InfrastructureComponent{ Location: "ACS Laboratory", Description: "This is a test description", //StateUpdateAt: time.Now().Format(time.RFC1123), - Properties: postgres.Jsonb{propertiesA}, + StartParameterScheme: postgres.Jsonb{propertiesA}, } var ICB = database.InfrastructureComponent{ @@ -117,7 +117,7 @@ var ICB = database.InfrastructureComponent{ Location: "k8s", Description: "A signal generator for testing purposes", //StateUpdateAt: time.Now().Format(time.RFC1123), - Properties: postgres.Jsonb{propertiesB}, + StartParameterScheme: postgres.Jsonb{propertiesB}, } // Scenarios diff --git a/routes/component-configuration/config_test.go b/routes/component-configuration/config_test.go index 08571f1..065136d 100644 --- a/routes/component-configuration/config_test.go +++ b/routes/component-configuration/config_test.go @@ -49,15 +49,15 @@ type ConfigRequest struct { } type ICRequest struct { - UUID string `json:"uuid,omitempty"` - WebsocketURL string `json:"websocketurl,omitempty"` - Type string `json:"type,omitempty"` - Name string `json:"name,omitempty"` - Category string `json:"category,omitempty"` - State string `json:"state,omitempty"` - Location string `json:"location,omitempty"` - Description string `json:"description,omitempty"` - Properties postgres.Jsonb `json:"properties,omitempty"` + UUID string `json:"uuid,omitempty"` + WebsocketURL string `json:"websocketurl,omitempty"` + Type string `json:"type,omitempty"` + Name string `json:"name,omitempty"` + Category string `json:"category,omitempty"` + State string `json:"state,omitempty"` + Location string `json:"location,omitempty"` + Description string `json:"description,omitempty"` + StartParameterScheme postgres.Jsonb `json:"startparameterscheme,omitempty"` } type ScenarioRequest struct { @@ -74,15 +74,15 @@ func addScenarioAndIC() (scenarioID uint, ICID uint) { // POST $newICA newICA := ICRequest{ - UUID: helper.ICA.UUID, - WebsocketURL: helper.ICA.WebsocketURL, - Type: helper.ICA.Type, - Name: helper.ICA.Name, - Category: helper.ICA.Category, - State: helper.ICA.State, - Location: helper.ICA.Location, - Description: helper.ICA.Description, - Properties: helper.ICA.Properties, + UUID: helper.ICA.UUID, + WebsocketURL: helper.ICA.WebsocketURL, + Type: helper.ICA.Type, + Name: helper.ICA.Name, + Category: helper.ICA.Category, + State: helper.ICA.State, + Location: helper.ICA.Location, + Description: helper.ICA.Description, + StartParameterScheme: helper.ICA.StartParameterScheme, } _, resp, _ := helper.TestEndpoint(router, token, "/api/ic", "POST", helper.KeyModels{"ic": newICA}) @@ -92,15 +92,15 @@ func addScenarioAndIC() (scenarioID uint, ICID uint) { // POST a second IC to change to that IC during testing newICB := ICRequest{ - UUID: helper.ICB.UUID, - WebsocketURL: helper.ICB.WebsocketURL, - Type: helper.ICB.Type, - Name: helper.ICB.Name, - Category: helper.ICB.Category, - State: helper.ICB.State, - Location: helper.ICB.Location, - Description: helper.ICB.Description, - Properties: helper.ICB.Properties, + UUID: helper.ICB.UUID, + WebsocketURL: helper.ICB.WebsocketURL, + Type: helper.ICB.Type, + Name: helper.ICB.Name, + Category: helper.ICB.Category, + State: helper.ICB.State, + Location: helper.ICB.Location, + Description: helper.ICB.Description, + StartParameterScheme: helper.ICB.StartParameterScheme, } _, resp, _ = helper.TestEndpoint(router, token, "/api/ic", "POST", helper.KeyModels{"ic": newICB}) diff --git a/routes/infrastructure-component/ic_test.go b/routes/infrastructure-component/ic_test.go index 79cc91c..a475082 100644 --- a/routes/infrastructure-component/ic_test.go +++ b/routes/infrastructure-component/ic_test.go @@ -39,16 +39,16 @@ import ( var router *gin.Engine type ICRequest struct { - UUID string `json:"uuid,omitempty"` - WebsocketURL string `json:"websocketurl,omitempty"` - APIURL string `json:"apiurl,omitempty"` - Type string `json:"type,omitempty"` - Name string `json:"name,omitempty"` - Category string `json:"category,omitempty"` - State string `json:"state,omitempty"` - Location string `json:"location,omitempty"` - Description string `json:"description,omitempty"` - Properties postgres.Jsonb `json:"properties,omitempty"` + UUID string `json:"uuid,omitempty"` + WebsocketURL string `json:"websocketurl,omitempty"` + APIURL string `json:"apiurl,omitempty"` + Type string `json:"type,omitempty"` + Name string `json:"name,omitempty"` + Category string `json:"category,omitempty"` + State string `json:"state,omitempty"` + Location string `json:"location,omitempty"` + Description string `json:"description,omitempty"` + StartParameterScheme postgres.Jsonb `json:"startparameterscheme,omitempty"` } func TestMain(m *testing.M) { @@ -102,16 +102,16 @@ func TestAddICAsAdmin(t *testing.T) { // test POST ic/ $newIC newIC := ICRequest{ - UUID: helper.ICA.UUID, - WebsocketURL: helper.ICA.WebsocketURL, - APIURL: helper.ICB.APIURL, - Type: helper.ICA.Type, - Name: helper.ICA.Name, - Category: helper.ICA.Category, - State: helper.ICA.State, - Location: helper.ICA.Location, - Description: helper.ICA.Description, - Properties: helper.ICA.Properties, + UUID: helper.ICA.UUID, + WebsocketURL: helper.ICA.WebsocketURL, + APIURL: helper.ICB.APIURL, + Type: helper.ICA.Type, + Name: helper.ICA.Name, + Category: helper.ICA.Category, + State: helper.ICA.State, + Location: helper.ICA.Location, + Description: helper.ICA.Description, + StartParameterScheme: helper.ICA.StartParameterScheme, } code, resp, err = helper.TestEndpoint(router, token, "/api/ic", "POST", helper.KeyModels{"ic": newIC}) @@ -157,15 +157,15 @@ func TestAddICAsUser(t *testing.T) { // test POST ic/ $newIC newIC := ICRequest{ - UUID: helper.ICA.UUID, - WebsocketURL: helper.ICA.WebsocketURL, - Type: helper.ICA.Type, - Name: helper.ICA.Name, - Category: helper.ICA.Category, - State: helper.ICA.State, - Location: helper.ICA.Location, - Description: helper.ICA.Description, - Properties: helper.ICA.Properties, + UUID: helper.ICA.UUID, + WebsocketURL: helper.ICA.WebsocketURL, + Type: helper.ICA.Type, + Name: helper.ICA.Name, + Category: helper.ICA.Category, + State: helper.ICA.State, + Location: helper.ICA.Location, + Description: helper.ICA.Description, + StartParameterScheme: helper.ICA.StartParameterScheme, } // This should fail with unprocessable entity 422 error code @@ -188,15 +188,15 @@ func TestUpdateICAsAdmin(t *testing.T) { // test POST ic/ $newIC newIC := ICRequest{ - UUID: helper.ICA.UUID, - WebsocketURL: helper.ICA.WebsocketURL, - Type: helper.ICA.Type, - Name: helper.ICA.Name, - Category: helper.ICA.Category, - State: helper.ICA.State, - Location: helper.ICA.Location, - Description: helper.ICA.Description, - Properties: helper.ICA.Properties, + UUID: helper.ICA.UUID, + WebsocketURL: helper.ICA.WebsocketURL, + Type: helper.ICA.Type, + Name: helper.ICA.Name, + Category: helper.ICA.Category, + State: helper.ICA.State, + Location: helper.ICA.Location, + Description: helper.ICA.Description, + StartParameterScheme: helper.ICA.StartParameterScheme, } code, resp, err := helper.TestEndpoint(router, token, "/api/ic", "POST", helper.KeyModels{"ic": newIC}) @@ -254,15 +254,15 @@ func TestUpdateICAsUser(t *testing.T) { // test POST ic/ $newIC newIC := ICRequest{ - UUID: helper.ICA.UUID, - WebsocketURL: helper.ICA.WebsocketURL, - Type: helper.ICA.Type, - Name: helper.ICA.Name, - Category: helper.ICA.Category, - State: helper.ICA.State, - Location: helper.ICA.Location, - Description: helper.ICA.Description, - Properties: helper.ICA.Properties, + UUID: helper.ICA.UUID, + WebsocketURL: helper.ICA.WebsocketURL, + Type: helper.ICA.Type, + Name: helper.ICA.Name, + Category: helper.ICA.Category, + State: helper.ICA.State, + Location: helper.ICA.Location, + Description: helper.ICA.Description, + StartParameterScheme: helper.ICA.StartParameterScheme, } code, resp, err := helper.TestEndpoint(router, token, "/api/ic", "POST", helper.KeyModels{"ic": newIC}) @@ -300,15 +300,15 @@ func TestDeleteICAsAdmin(t *testing.T) { // test POST ic/ $newIC newIC := ICRequest{ - UUID: helper.ICA.UUID, - WebsocketURL: helper.ICA.WebsocketURL, - Type: helper.ICA.Type, - Name: helper.ICA.Name, - Category: helper.ICA.Category, - State: helper.ICA.State, - Location: helper.ICA.Location, - Description: helper.ICA.Description, - Properties: helper.ICA.Properties, + UUID: helper.ICA.UUID, + WebsocketURL: helper.ICA.WebsocketURL, + Type: helper.ICA.Type, + Name: helper.ICA.Name, + Category: helper.ICA.Category, + State: helper.ICA.State, + Location: helper.ICA.Location, + Description: helper.ICA.Description, + StartParameterScheme: helper.ICA.StartParameterScheme, } code, resp, err := helper.TestEndpoint(router, token, "/api/ic", "POST", helper.KeyModels{"ic": newIC}) @@ -354,15 +354,15 @@ func TestDeleteICAsUser(t *testing.T) { // test POST ic/ $newIC newIC := ICRequest{ - UUID: helper.ICA.UUID, - WebsocketURL: helper.ICA.WebsocketURL, - Type: helper.ICA.Type, - Name: helper.ICA.Name, - Category: helper.ICA.Category, - State: helper.ICA.State, - Location: helper.ICA.Location, - Description: helper.ICA.Description, - Properties: helper.ICA.Properties, + UUID: helper.ICA.UUID, + WebsocketURL: helper.ICA.WebsocketURL, + Type: helper.ICA.Type, + Name: helper.ICA.Name, + Category: helper.ICA.Category, + State: helper.ICA.State, + Location: helper.ICA.Location, + Description: helper.ICA.Description, + StartParameterScheme: helper.ICA.StartParameterScheme, } code, resp, err := helper.TestEndpoint(router, token, "/api/ic", "POST", helper.KeyModels{"ic": newIC}) @@ -404,15 +404,15 @@ func TestGetAllICs(t *testing.T) { // test POST ic/ $newICA newICA := ICRequest{ - UUID: helper.ICA.UUID, - WebsocketURL: helper.ICA.WebsocketURL, - Type: helper.ICA.Type, - Name: helper.ICA.Name, - Category: helper.ICA.Category, - State: helper.ICA.State, - Location: helper.ICA.Location, - Description: helper.ICA.Description, - Properties: helper.ICA.Properties, + UUID: helper.ICA.UUID, + WebsocketURL: helper.ICA.WebsocketURL, + Type: helper.ICA.Type, + Name: helper.ICA.Name, + Category: helper.ICA.Category, + State: helper.ICA.State, + Location: helper.ICA.Location, + Description: helper.ICA.Description, + StartParameterScheme: helper.ICA.StartParameterScheme, } code, resp, err := helper.TestEndpoint(router, token, "/api/ic", "POST", helper.KeyModels{"ic": newICA}) @@ -421,15 +421,15 @@ func TestGetAllICs(t *testing.T) { // test POST ic/ $newICB newICB := ICRequest{ - UUID: helper.ICB.UUID, - WebsocketURL: helper.ICB.WebsocketURL, - Type: helper.ICB.Type, - Name: helper.ICB.Name, - Category: helper.ICB.Category, - State: helper.ICB.State, - Location: helper.ICB.Location, - Description: helper.ICB.Description, - Properties: helper.ICB.Properties, + UUID: helper.ICB.UUID, + WebsocketURL: helper.ICB.WebsocketURL, + Type: helper.ICB.Type, + Name: helper.ICB.Name, + Category: helper.ICB.Category, + State: helper.ICB.State, + Location: helper.ICB.Location, + Description: helper.ICB.Description, + StartParameterScheme: helper.ICB.StartParameterScheme, } code, resp, err = helper.TestEndpoint(router, token, "/api/ic", "POST", helper.KeyModels{"ic": newICB}) @@ -468,15 +468,15 @@ func TestGetConfigsOfIC(t *testing.T) { // test POST ic/ $newICA newICA := ICRequest{ - UUID: helper.ICA.UUID, - WebsocketURL: helper.ICA.WebsocketURL, - Type: helper.ICA.Type, - Name: helper.ICA.Name, - Category: helper.ICA.Category, - State: helper.ICA.State, - Location: helper.ICA.Location, - Description: helper.ICA.Description, - Properties: helper.ICA.Properties, + UUID: helper.ICA.UUID, + WebsocketURL: helper.ICA.WebsocketURL, + Type: helper.ICA.Type, + Name: helper.ICA.Name, + Category: helper.ICA.Category, + State: helper.ICA.State, + Location: helper.ICA.Location, + Description: helper.ICA.Description, + StartParameterScheme: helper.ICA.StartParameterScheme, } code, resp, err := helper.TestEndpoint(router, token, "/api/ic", "POST", helper.KeyModels{"ic": newICA}) diff --git a/routes/infrastructure-component/ic_validators.go b/routes/infrastructure-component/ic_validators.go index 248baaf..7aefd54 100644 --- a/routes/infrastructure-component/ic_validators.go +++ b/routes/infrastructure-component/ic_validators.go @@ -32,29 +32,29 @@ import ( var validate *validator.Validate type validNewIC struct { - UUID string `form:"UUID" validate:"required"` - WebsocketURL string `form:"WebsocketURL" validate:"omitempty"` - APIURL string `form:"APIURL" validate:"omitempty"` - Type string `form:"Type" validate:"required"` - Name string `form:"Name" validate:"required"` - Category string `form:"Category" validate:"required"` - Properties postgres.Jsonb `form:"Properties" validate:"omitempty"` - State string `form:"State" validate:"omitempty"` - Location string `form:"Location" validate:"omitempty"` - Description string `form:"Description" validate:"omitempty"` + UUID string `form:"UUID" validate:"required"` + WebsocketURL string `form:"WebsocketURL" validate:"omitempty"` + APIURL string `form:"APIURL" validate:"omitempty"` + Type string `form:"Type" validate:"required"` + Name string `form:"Name" validate:"required"` + Category string `form:"Category" validate:"required"` + StartParameterScheme postgres.Jsonb `form:"StartParameterScheme" validate:"omitempty"` + State string `form:"State" validate:"omitempty"` + Location string `form:"Location" validate:"omitempty"` + Description string `form:"Description" validate:"omitempty"` } type validUpdatedIC struct { - UUID string `form:"UUID" validate:"omitempty"` - WebsocketURL string `form:"WebsocketURL" validate:"omitempty"` - APIURL string `form:"APIURL" validate:"omitempty"` - Type string `form:"Type" validate:"omitempty"` - Name string `form:"Name" validate:"omitempty"` - Category string `form:"Category" validate:"omitempty"` - Properties postgres.Jsonb `form:"Properties" validate:"omitempty"` - State string `form:"State" validate:"omitempty"` - Location string `form:"Location" validate:"omitempty"` - Description string `form:"Description" validate:"omitempty"` + UUID string `form:"UUID" validate:"omitempty"` + WebsocketURL string `form:"WebsocketURL" validate:"omitempty"` + APIURL string `form:"APIURL" validate:"omitempty"` + Type string `form:"Type" validate:"omitempty"` + Name string `form:"Name" validate:"omitempty"` + Category string `form:"Category" validate:"omitempty"` + StartParameterScheme postgres.Jsonb `form:"StartParameterScheme" validate:"omitempty"` + State string `form:"State" validate:"omitempty"` + Location string `form:"Location" validate:"omitempty"` + Description string `form:"Description" validate:"omitempty"` } type AddICRequest struct { @@ -88,7 +88,7 @@ func (r *AddICRequest) CreateIC() InfrastructureComponent { s.Category = r.InfrastructureComponent.Category s.Location = r.InfrastructureComponent.Location s.Description = r.InfrastructureComponent.Description - s.Properties = r.InfrastructureComponent.Properties + s.StartParameterScheme = r.InfrastructureComponent.StartParameterScheme if r.InfrastructureComponent.State != "" { s.State = r.InfrastructureComponent.State } else { @@ -147,11 +147,11 @@ func (r *UpdateICRequest) UpdatedIC(oldIC InfrastructureComponent) Infrastructur var emptyJson postgres.Jsonb // Serialize empty json and params emptyJson_ser, _ := json.Marshal(emptyJson) - startParams_ser, _ := json.Marshal(r.InfrastructureComponent.Properties) + startParams_ser, _ := json.Marshal(r.InfrastructureComponent.StartParameterScheme) opts := jsondiff.DefaultConsoleOptions() diff, _ := jsondiff.Compare(emptyJson_ser, startParams_ser, &opts) if diff.String() != "FullMatch" { - s.Properties = r.InfrastructureComponent.Properties + s.StartParameterScheme = r.InfrastructureComponent.StartParameterScheme } return s diff --git a/routes/signal/signal_test.go b/routes/signal/signal_test.go index 5840ba9..bdc5e46 100644 --- a/routes/signal/signal_test.go +++ b/routes/signal/signal_test.go @@ -56,15 +56,15 @@ type ConfigRequest struct { } type ICRequest struct { - UUID string `json:"uuid,omitempty"` - WebsocketURL string `json:"websocketurl,omitempty"` - Type string `json:"type,omitempty"` - Name string `json:"name,omitempty"` - Category string `json:"category,omitempty"` - State string `json:"state,omitempty"` - Location string `json:"location,omitempty"` - Description string `json:"description,omitempty"` - Properties postgres.Jsonb `json:"properties,omitempty"` + UUID string `json:"uuid,omitempty"` + WebsocketURL string `json:"websocketurl,omitempty"` + Type string `json:"type,omitempty"` + Name string `json:"name,omitempty"` + Category string `json:"category,omitempty"` + State string `json:"state,omitempty"` + Location string `json:"location,omitempty"` + Description string `json:"description,omitempty"` + StartParameterScheme postgres.Jsonb `json:"startparameterscheme,omitempty"` } type ScenarioRequest struct { @@ -81,15 +81,15 @@ func addScenarioAndICAndConfig() (scenarioID uint, ICID uint, configID uint) { // POST $newICA newICA := ICRequest{ - UUID: helper.ICA.UUID, - WebsocketURL: helper.ICA.WebsocketURL, - Type: helper.ICA.Type, - Name: helper.ICA.Name, - Category: helper.ICA.Category, - State: helper.ICA.State, - Location: helper.ICA.Location, - Description: helper.ICA.Description, - Properties: helper.ICA.Properties, + UUID: helper.ICA.UUID, + WebsocketURL: helper.ICA.WebsocketURL, + Type: helper.ICA.Type, + Name: helper.ICA.Name, + Category: helper.ICA.Category, + State: helper.ICA.State, + Location: helper.ICA.Location, + Description: helper.ICA.Description, + StartParameterScheme: helper.ICA.StartParameterScheme, } _, resp, _ := helper.TestEndpoint(router, token, "/api/ic", "POST", helper.KeyModels{"ic": newICA})