Ejemplo n.º 1
0
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")
}
Ejemplo n.º 2
0
func (suite *ApiDeclarationSuite) TestAddSubApi() {
	api := parser.NewApiDeclaration()

	suite.operation.Path = "/customer/get{id}"
	suite.operation2.Path = "/customer/get{id}"
	suite.operation3.Path = "/order/get"

	api.AddSubApi(suite.operation)
	assert.Len(suite.T(), api.Apis, 1, "Api was not added")
	api.AddSubApi(suite.operation2)
	assert.Len(suite.T(), api.Apis, 1, "Api path should be unique")
	api.AddSubApi(suite.operation3)
	assert.Len(suite.T(), api.Apis, 2, "Second Api was not added")
}
Ejemplo n.º 3
0
func (suite *ApiDeclarationSuite) TestAddProducesTypes() {
	api := parser.NewApiDeclaration()

	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)

	api.AddProducesTypes(suite.operation)
	assert.Len(suite.T(), api.Produces, 1, "Produced type was not added")
	api.AddProducesTypes(suite.operation2)
	assert.Len(suite.T(), api.Produces, 1, "Produced type should be unique")
	api.AddProducesTypes(suite.operation3)
	assert.Len(suite.T(), api.Produces, 2, "Second produced type was not added")

	expected := []string{parser.ContentTypeXml, parser.ContentTypeJson}
	assert.Equal(suite.T(), api.Produces, expected, "Produced types not added correctly")
}
Ejemplo n.º 4
0
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")
}
Ejemplo n.º 5
0
func (suite *ApiDeclarationSuite) TestNewApi() {
	assert.NotNil(suite.T(), parser.NewApiDeclaration(), "Can no create new api description instance")
}