Skip to content

Commit

Permalink
addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
galiri committed Jun 28, 2018
1 parent 1f56c24 commit 61d0f96
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 28 deletions.
10 changes: 4 additions & 6 deletions annotations/augmenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (a *annotationAugmenter) AugmentAnnotations(ctx context.Context, canonicalA
ctx = tidUtils.TransactionAwareContext(ctx, tid)
}

uuids:= getConceptUUIDs(canonicalAnnotations)
uuids := getConceptUUIDs(canonicalAnnotations)

concepts, err := a.conceptSearchApi.SearchConcepts(ctx, uuids)

Expand Down Expand Up @@ -64,7 +64,7 @@ func (a *annotationAugmenter) AugmentAnnotations(ctx context.Context, canonicalA
return augmentedAnnotations, nil
}

func getConceptUUIDs(canonicalAnnotations []Annotation) ([]string) {
func getConceptUUIDs(canonicalAnnotations []Annotation) []string {
conceptUUIDs := make(map[string]struct{})
var empty struct{}
var keys []string
Expand All @@ -74,12 +74,10 @@ func getConceptUUIDs(canonicalAnnotations []Annotation) ([]string) {
conceptUUIDs[conceptUUID] = empty
}
}
for k,_:= range conceptUUIDs{
keys=append(keys, k)
for k := range conceptUUIDs {
keys = append(keys, k)

}


return keys
}

Expand Down
34 changes: 12 additions & 22 deletions annotations/augmenter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ var expectedAugmentedAnnotations = []Annotation{
},
}


var testMultiCanonicalizedAnnotations = []Annotation{

{
Expand All @@ -105,10 +104,9 @@ var testMultiCanonicalizedAnnotations = []Annotation{
Predicate: "http://www.ft.com/ontology/hasDisplayTag",
ConceptId: "http://www.ft.com/thing/b224ad07-c818-3ad6-94af-a4d351dbb619",
},

}

var expectedMulitPredicateAugmentedAnnotations = []Annotation{
var expectedMultiPredicateAugmentedAnnotations = []Annotation{
{
Predicate: "http://www.ft.com/ontology/hasDisplayTag",
ConceptId: "http://www.ft.com/thing/b224ad07-c818-3ad6-94af-a4d351dbb619",
Expand All @@ -126,14 +124,13 @@ var expectedMulitPredicateAugmentedAnnotations = []Annotation{
PrefLabel: "Economic Indicators",
IsFTAuthor: false,
},

}

var testMultiPredicateConceptIDs = []string{
"b224ad07-c818-3ad6-94af-a4d351dbb619",
}

var testMultiPredicteConcept= map[string]concept.Concept{
var testMultiPredicateConcept = map[string]concept.Concept{
"b224ad07-c818-3ad6-94af-a4d351dbb619": {
ID: "http://www.ft.com/thing/b224ad07-c818-3ad6-94af-a4d351dbb619",
ApiUrl: "http://api.ft.com/things/b224ad07-c818-3ad6-94af-a4d351dbb619",
Expand All @@ -144,7 +141,7 @@ var testMultiPredicteConcept= map[string]concept.Concept{

func TestAugmentAnnotations(t *testing.T) {
matcher := mock.MatchedBy(func(l1 []string) bool {
return assert.ElementsMatch(t, l1,testConceptIDs)
return assert.ElementsMatch(t, l1, testConceptIDs)
})

conceptsSearchAPI := new(ConceptSearchAPIMock)
Expand All @@ -158,40 +155,33 @@ func TestAugmentAnnotations(t *testing.T) {

assert.NoError(t, err)
assert.Equal(t, len(expectedAugmentedAnnotations), len(annotations))
for _, expected := range expectedAugmentedAnnotations {
assert.Contains(t, annotations, expected)
}

assert.ElementsMatch(t, annotations, expectedAugmentedAnnotations)
conceptsSearchAPI.AssertExpectations(t)
}


func TestAugmentAnnotationsMultiPredicatePerConcept(t *testing.T) {
matcher := mock.MatchedBy(func(l1 []string) bool {
return assert.ElementsMatch(t, l1,testMultiPredicateConceptIDs)
return assert.ElementsMatch(t, l1, testMultiPredicateConceptIDs)
})

conceptsSearchAPI := new(ConceptSearchAPIMock)
ctx := tidUtils.TransactionAwareContext(context.Background(), tidUtils.NewTransactionID())
conceptsSearchAPI.
On("SearchConcepts", ctx, matcher).
Return(testMultiPredicteConcept, nil)
Return(testMultiPredicateConcept, nil)
a := NewAugmenter(conceptsSearchAPI)

annotations, err := a.AugmentAnnotations(ctx, testMultiCanonicalizedAnnotations)

assert.NoError(t, err)
assert.Equal(t, len(expectedMulitPredicateAugmentedAnnotations), len(annotations))
for _, expected := range expectedMulitPredicateAugmentedAnnotations {
assert.Contains(t, annotations, expected)
}

assert.Equal(t, len(expectedMultiPredicateAugmentedAnnotations), len(annotations))
assert.ElementsMatch(t, annotations, expectedMultiPredicateAugmentedAnnotations)
conceptsSearchAPI.AssertExpectations(t)
}

func TestAugmentAnnotationsArrayShouldNotBeNull(t *testing.T) {
matcher := mock.MatchedBy(func(l1 []string) bool {
return assert.ElementsMatch(t, l1,testConceptIDs)
return assert.ElementsMatch(t, l1, testConceptIDs)
})
conceptsSearchAPI := new(ConceptSearchAPIMock)
ctx := tidUtils.TransactionAwareContext(context.Background(), tidUtils.NewTransactionID())
Expand All @@ -210,7 +200,7 @@ func TestAugmentAnnotationsArrayShouldNotBeNull(t *testing.T) {

func TestAugmentAnnotationsMissingTransactionID(t *testing.T) {
matcher := mock.MatchedBy(func(l1 []string) bool {
return assert.ElementsMatch(t, l1,testConceptIDs)
return assert.ElementsMatch(t, l1, testConceptIDs)
})
hook := logTest.NewGlobal()
conceptsSearchAPI := new(ConceptSearchAPIMock)
Expand Down Expand Up @@ -238,7 +228,7 @@ func TestAugmentAnnotationsMissingTransactionID(t *testing.T) {

func TestAugmentAnnotationsConceptSearchError(t *testing.T) {
matcher := mock.MatchedBy(func(l1 []string) bool {
return assert.ElementsMatch(t, l1,testConceptIDs)
return assert.ElementsMatch(t, l1, testConceptIDs)
})
conceptsSearchAPI := new(ConceptSearchAPIMock)
ctx := tidUtils.TransactionAwareContext(context.Background(), tidUtils.NewTransactionID())
Expand All @@ -256,7 +246,7 @@ func TestAugmentAnnotationsConceptSearchError(t *testing.T) {

func TestAugmentAnnotationsWithInvalidConceptID(t *testing.T) {
matcher := mock.MatchedBy(func(l1 []string) bool {
return assert.ElementsMatch(t, l1,testConceptIDs)
return assert.ElementsMatch(t, l1, testConceptIDs)
})
conceptsSearchAPI := new(ConceptSearchAPIMock)
ctx := tidUtils.TransactionAwareContext(context.Background(), tidUtils.NewTransactionID())
Expand Down

0 comments on commit 61d0f96

Please sign in to comment.