func (suite *ApiDeclarationSuite) TestAddModel() { api := parser.NewApiDeclaration() m1 := parser.NewModel(suite.parser) m1.Id = "test.SuperStruct" m2 := parser.NewModel(suite.parser) m2.Id = "test.SuperStruct" m3 := parser.NewModel(suite.parser) m3.Id = "test.SuperStruct2" suite.operation.Models = append(suite.operation.Models, m1) suite.operation2.Models = append(suite.operation2.Models, m2) suite.operation3.Models = append(suite.operation3.Models, m3) api.AddModels(suite.operation) assert.Len(suite.T(), api.Models, 1, "Model was not added") api.AddModels(suite.operation2) assert.Len(suite.T(), api.Models, 1, "Model should be unique") api.AddModels(suite.operation3) assert.Len(suite.T(), api.Models, 2, "Second model was not added") expected := map[string]*parser.Model{ m1.Id: m1, m3.Id: m3, } assert.Equal(suite.T(), api.Models, expected, "Models not added correctly") }
func (suite *ModelSuite) TestSimpleStructure() { m := parser.NewModel(suite.parser) err, innerModels := m.ParseModel("SimpleStructure", ExamplePackageName, suite.knownModelNames) assert.Nil(suite.T(), err, "Can not parse SimpleStructure definition") assert.Len(suite.T(), innerModels, 0, "Can not parse SimpleStructure definition") assert.True(suite.T(), strings.HasSuffix(m.Id, "SimpleStructure"), "Can not parse SimpleStructuredefinition") assert.Len(suite.T(), m.Required, 0, "Can not parse SimpleStructure definition") assert.Len(suite.T(), m.Properties, 2, "Can not parse SimpleStructure definition") }
func (suite *ApiDeclarationSuite) TestAddOperation() { api := parser.NewApiDeclaration() m1 := parser.NewModel(suite.parser) m1.Id = "test.SuperStruct" m2 := parser.NewModel(suite.parser) m2.Id = "test.SuperStruct" m3 := parser.NewModel(suite.parser) m3.Id = "test.SuperStruct2" suite.operation.Models = append(suite.operation.Models, m1) suite.operation2.Models = append(suite.operation2.Models, m2) suite.operation3.Models = append(suite.operation3.Models, m3) suite.operation.Path = "/customer/get{id}" suite.operation2.Path = "/customer/get{id}" suite.operation3.Path = "/order/get" suite.operation.Produces = append(suite.operation.Produces, parser.ContentTypeXml) suite.operation2.Produces = append(suite.operation2.Produces, parser.ContentTypeXml) suite.operation3.Produces = append(suite.operation3.Produces, parser.ContentTypeJson) suite.operation.Consumes = append(suite.operation.Consumes, parser.ContentTypeXml) suite.operation2.Consumes = append(suite.operation2.Consumes, parser.ContentTypeXml) suite.operation3.Consumes = append(suite.operation3.Consumes, parser.ContentTypeJson) api.AddOperation(suite.operation) api.AddOperation(suite.operation2) api.AddOperation(suite.operation3) assert.Len(suite.T(), api.Apis, 2, "Second Api was not added") expected := map[string]*parser.Model{ m1.Id: m1, m3.Id: m3, } assert.Equal(suite.T(), api.Models, expected, "Models not added correctly") assert.Len(suite.T(), api.Produces, 2, "Second produced type was not added") assert.Len(suite.T(), api.Consumes, 2, "Second consumed type was not added") }
func (suite *ModelSuite) TestSimpleStructureWithAnnotations() { m := parser.NewModel(suite.parser) err, innerModels := m.ParseModel("SimpleStructureWithAnnotations", ExamplePackageName, suite.knownModelNames) assert.Nil(suite.T(), err, "Can not parse SimpleStructureWithAnnotations definition") assert.Len(suite.T(), innerModels, 0, "Can not parse SimpleStructureWithAnnotations definition") assert.True(suite.T(), strings.HasSuffix(m.Id, "SimpleStructureWithAnnotations"), "Can not parse SimpleStructureWithAnnotations") assert.Len(suite.T(), m.Required, 1, "Can not parse SimpleStructureWithAnnotations definition(%#v)", m.Properties) assert.Len(suite.T(), m.Properties, 2, "Can not parse SimpleStructureWithAnnotations definition") assert.Equal(suite.T(), m.Properties["id"].Type, "int", "Can not parse SimpleStructureWithAnnotations definition") assert.Equal(suite.T(), m.Properties["Name"].Type, "string", "Can not parse SimpleStructureWithAnnotations definition") }
func (suite *ModelSuite) TestStructureWithSlice() { m := parser.NewModel(suite.parser) err, innerModels := m.ParseModel("StructureWithSlice", ExamplePackageName, suite.knownModelNames) assert.Nil(suite.T(), err, "Can not parse StructureWithSlice definition") assert.Len(suite.T(), innerModels, 0, "Can not parse StructureWithSlice definition") assert.True(suite.T(), strings.HasSuffix(m.Id, "StructureWithSlice"), "Can not parse StructureWithSlice") assert.Len(suite.T(), m.Required, 0, "Can not parse StructureWithSlice definition(%#v)", m.Properties) assert.Len(suite.T(), m.Properties, 2, "Can not parse StructureWithSlice definition") assert.Equal(suite.T(), m.Properties["Id"].Type, "int", "Can not parse StructureWithSlice definition") assert.Equal(suite.T(), m.Properties["Name"].Type, "array", "Can not parse StructureWithSlice definition") assert.Equal(suite.T(), m.Properties["Name"].Items.Type, "byte", "Can not parse StructureWithSlice definition") }
func (suite *ModelSuite) TestNewModel() { assert.NotNil(suite.T(), parser.NewModel(suite.parser), "Can not create new model instance") }