Skip to content

Commit

Permalink
Add validation for empty predicate
Browse files Browse the repository at this point in the history
Empty predicate won't be defaulted to "MENTIONS" predicate anymore.
The commit also updates the unit tests to match the new behavior.
  • Loading branch information
ivanruski committed Mar 22, 2021
1 parent 6657bfd commit c59ecb0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
4 changes: 0 additions & 4 deletions annotations/cypher.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,6 @@ func createAnnotationRelationship(relation string) (statement string) {
}

func getRelationshipFromPredicate(predicate string) (string, error) {
if predicate == "" {
return relations["mentions"], nil
}

r, ok := relations[predicate]
if !ok {
return "", UnsupportedPredicateErr
Expand Down
1 change: 1 addition & 0 deletions annotations/cypher_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ func TestWriteAndReadMultipleAnnotations(t *testing.T) {
"http://www.ft.com/ontology/core/Thing",
"http://www.ft.com/ontology/concept/Concept",
},
Predicate: "mentions",
},
Provenances: []Provenance{
{
Expand Down
17 changes: 16 additions & 1 deletion annotations/cypher_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package annotations

import (
"errors"
"fmt"
"testing"

Expand Down Expand Up @@ -99,16 +100,30 @@ func TestCreateAnnotationQueryWithPredicate(t *testing.T) {
}
}

func TestCreateAnnotationQueryWithoutPredicate(t *testing.T) {
assert := assert.New(t)
logger.InitDefaultLogger("annotations-rw")
annotation := exampleConcept(oldConceptUUID)
annotation.Thing.Predicate = ""

_, err := createAnnotationQuery(contentUUID, annotation, v2PlatformVersion, v2AnnotationLifecycle)
assert.True(errors.Is(err, UnsupportedPredicateErr), "Creating annotation without predicate is not allowed.")
}

func TestGetRelationshipFromPredicate(t *testing.T) {
var tests = []struct {
predicate string
relationship string
}{
{"mentions", "MENTIONS"},
{"isClassifiedBy", "IS_CLASSIFIED_BY"},
{"", "MENTIONS"},
{"implicitlyClassifiedBy", "IMPLICITLY_CLASSIFIED_BY"},
{"about", "ABOUT"},
{"isPrimarilyClassifiedBy", "IS_PRIMARILY_CLASSIFIED_BY"},
{"majorMentions", "MAJOR_MENTIONS"},
{"hasAuthor", "HAS_AUTHOR"},
{"hasContributor", "HAS_CONTRIBUTOR"},
{"hasDisplayTag", "HAS_DISPLAY_TAG"},
{"hasBrand", "HAS_BRAND"},
}

Expand Down
8 changes: 6 additions & 2 deletions annotations/example_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ var (
"http://www.ft.com/ontology/organisation/Organisation",
"http://www.ft.com/ontology/core/Thing",
"http://www.ft.com/ontology/concept/Concept",
}},
},
Predicate: "mentions",
},
Provenances: []Provenance{
{
Scores: []Score{
Expand Down Expand Up @@ -192,7 +194,9 @@ func exampleConcept(uuid string) Annotation {
"http://www.ft.com/ontology/organisation/Organisation",
"http://www.ft.com/ontology/core/Thing",
"http://www.ft.com/ontology/concept/Concept",
}},
},
Predicate: "mentions",
},
Provenances: []Provenance{
{
Scores: []Score{
Expand Down

0 comments on commit c59ecb0

Please sign in to comment.