Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
Fixing isDeprecated transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandor Torok committed Aug 27, 2018
1 parent 89e452e commit 36e55d0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 29 deletions.
2 changes: 1 addition & 1 deletion tme/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type BasicConcept struct {
AuthorityValue string `json:"authorityValue,omitempty"`
Aliases []string `json:"aliases,omitempty"`
IsAuthor bool `json:"isAuthor,omitempty"`
IsDeprecated *bool `json:"isDeprecated,omitempty"`
IsDeprecated bool `json:"isDeprecated,omitempty"`
}

type ConceptUUID struct {
Expand Down
8 changes: 6 additions & 2 deletions tme/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

var (
GetAllConceptsResult string = "{\"uuid\":\"14fa0405-c625-3061-a1a0-a00643fc073f\",\"prefLabel\":\"Fred\",\"type\":\"Topic\",\"authority\":\"TME\",\"authorityValue\":\"ZnJlZA==-VG9waWNz\",\"isDeprecated\":false}\n{\"uuid\":\"c0e2b109-2212-35c1-8645-2a13bc2cc3db\",\"prefLabel\":\"Bob\",\"type\":\"Topic\",\"authority\":\"TME\",\"authorityValue\":\"Ym9i-VG9waWNz\",\"isDeprecated\":false}\n"
GetAllConceptsResult string = "{\"uuid\":\"14fa0405-c625-3061-a1a0-a00643fc073f\",\"prefLabel\":\"Fred\",\"type\":\"Topic\",\"authority\":\"TME\",\"authorityValue\":\"ZnJlZA==-VG9waWNz\"}\n{\"uuid\":\"c0e2b109-2212-35c1-8645-2a13bc2cc3db\",\"prefLabel\":\"Bob\",\"type\":\"Topic\",\"authority\":\"TME\",\"authorityValue\":\"Ym9i-VG9waWNz\"}\n"
GetConceptUUIDsResult string = "{\"uuid\":\"14fa0405-c625-3061-a1a0-a00643fc073f\"}\n{\"uuid\":\"c0e2b109-2212-35c1-8645-2a13bc2cc3db\"}\n"
RepoSleepDuration time.Duration = 5 * time.Second
)
Expand Down Expand Up @@ -99,7 +99,11 @@ func createTestTmeService(repos map[string]tmereader.Repository, httpClient http
}

func TestServiceImpl_GetCount(t *testing.T) {
repo := &mockTmeRepo{terms: []Term{{CanonicalName: "Bob", RawID: "bob", Enabled: pTrueValue}, {CanonicalName: "Fred", RawID: "fred", Enabled: pTrueValue}}}
bob := Term{CanonicalName: "Bob", RawID: "bob", Enabled: new(bool)}
*bob.Enabled = true
fred := Term{CanonicalName: "Fred", RawID: "fred", Enabled: new(bool)}
*fred.Enabled = true
repo := &mockTmeRepo{terms: []Term{bob, fred}}
repos := map[string]tmereader.Repository{
"topics": repo,
}
Expand Down
17 changes: 5 additions & 12 deletions tme/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ import (

const financialTimesBrandUuid = "dbb0bdae-1f0c-11e4-b0cb-b2227cce2b54"

var trueValue = true
var falseValue = false
var pTrueValue = &trueValue
var pFalseValue = &falseValue

type Transformer struct {
}

Expand All @@ -31,7 +26,7 @@ func (*Transformer) UnMarshallTaxonomy(contents []byte) ([]interface{}, error) {
for i, d := range taxonomy.TermsC {
if d.Enabled == nil {
d.Enabled = new(bool)
d.Enabled = pTrueValue
*d.Enabled = true
}
interfaces[i] = d
}
Expand All @@ -40,7 +35,7 @@ func (*Transformer) UnMarshallTaxonomy(contents []byte) ([]interface{}, error) {
for i, d := range taxonomy.TermsT {
if d.Enabled == nil {
d.Enabled = new(bool)
d.Enabled = pTrueValue
*d.Enabled = true
}
interfaces[i] = d
}
Expand Down Expand Up @@ -74,12 +69,10 @@ func transformConcept(tmeTerm Term, endpoint string) *BasicConcept {
Authority: "TME",
AuthorityValue: identifier,
Aliases: aliasList,
IsDeprecated: pFalseValue,
IsDeprecated: false,
}
if tmeTerm.Enabled == pFalseValue {
log.Infof("id %s enabled %v", generatedUUID, tmeTerm.Enabled)
basicConcept.IsDeprecated = pTrueValue
log.Infof("id %s deprecated %v", generatedUUID, basicConcept.IsDeprecated)
if tmeTerm.Enabled != nil && *tmeTerm.Enabled == false {
basicConcept.IsDeprecated = true
}
if (EndpointTypeMappings[endpoint]["taxonomy"].(string)) == "Brands" {
basicConcept.ParentUUIDs = []string{financialTimesBrandUuid}
Expand Down
33 changes: 19 additions & 14 deletions tme/transformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,26 @@ func TestTransformer_transformConcept(t *testing.T) {
expectedAuthValue string
expectedAliases []string
expectedIsAuthor bool
expectedIsDeprecated *bool
expectedIsDeprecated bool
}

//Tme terms
exampleGenre := Term{CanonicalName: "NewGenre", RawID: "newGenre"}
examplePersonWithAliases := Term{CanonicalName: "John Smith", RawID: "johnSmith", Aliases: aliases{Alias: []alias{{Name: "Johnny Boy"}, {Name: "Smithy"}}}}
examplePersonWithoutAliases := Term{CanonicalName: "Jane Doe", RawID: "janeDoe"}
exampleBrand := Term{CanonicalName: "NewBrand", RawID: "newBrand"}
exampleAuthor := Term{CanonicalName: "Author McAuthorface", RawID: "mcAuthorFace", Aliases: aliases{Alias: []alias{{Name: "John"}, {Name: "Bob"}}}, Enabled: pTrueValue}
exampleDeprecatedGenre := Term{CanonicalName: "OldGenre", RawID: "oldGenre", Enabled: pFalseValue}
exampleAuthor := Term{CanonicalName: "Author McAuthorface", RawID: "mcAuthorFace", Aliases: aliases{Alias: []alias{{Name: "John"}, {Name: "Bob"}}}, Enabled: new(bool)}
*exampleAuthor.Enabled = true
exampleDeprecatedGenre := Term{CanonicalName: "OldGenre", RawID: "oldGenre", Enabled: new(bool)}
*exampleDeprecatedGenre.Enabled = false

//Scenarios
genreTest := testStruct{testName: "genreTest", testTerm: exampleGenre, endpoint: "genres", expectedUuid: "7c80229b-3ad4-3bee-bb7a-45eaafe3f83a", expectedType: "Genre", expectedPrefLabel: "NewGenre", expectedAliases: []string{}, expectedParentUuid: "", expectedAuthority: "TME", expectedAuthValue: "bmV3R2VucmU=-R2VucmVz", expectedIsAuthor: false, expectedIsDeprecated: pFalseValue}
personWithAliases := testStruct{testName: "personWithAliases", testTerm: examplePersonWithAliases, endpoint: "people", expectedUuid: "05d18aac-9d8e-35d6-9a50-a950fc10aa0e", expectedType: "Person", expectedPrefLabel: "John Smith", expectedAliases: []string{"Johnny Boy", "Smithy"}, expectedParentUuid: "", expectedAuthority: "TME", expectedAuthValue: "am9oblNtaXRo-UE4=", expectedIsAuthor: false, expectedIsDeprecated: pFalseValue}
personNoAliases := testStruct{testName: "personNoAliases", testTerm: examplePersonWithoutAliases, endpoint: "people", expectedUuid: "ee34e2fd-f363-339b-aa25-191483cb909e", expectedType: "Person", expectedPrefLabel: "Jane Doe", expectedAliases: []string{}, expectedParentUuid: "", expectedAuthority: "TME", expectedAuthValue: "amFuZURvZQ==-UE4=", expectedIsAuthor: false, expectedIsDeprecated: pFalseValue}
brandTest := testStruct{testName: "brandTest", testTerm: exampleBrand, endpoint: "brands", expectedUuid: "dcb6cc7c-0e5b-3537-8c98-5405a52484f3", expectedType: "Brand", expectedPrefLabel: "NewBrand", expectedAliases: []string{}, expectedParentUuid: financialTimesBrandUuid, expectedAuthority: "TME", expectedAuthValue: "bmV3QnJhbmQ=-QnJhbmRz", expectedIsAuthor: false, expectedIsDeprecated: pFalseValue}
authorTest := testStruct{testName: "authorTest", testTerm: exampleAuthor, endpoint: "authors", expectedUuid: "829f073f-6666-338f-abd6-d69c37f2e5d0", expectedType: "Person", expectedPrefLabel: "Author McAuthorface", expectedAliases: []string{"John", "Bob"}, expectedParentUuid: "", expectedAuthority: "TME", expectedAuthValue: "bWNBdXRob3JGYWNl-QXV0aG9ycw==", expectedIsAuthor: true, expectedIsDeprecated: pFalseValue}
deprecatedGenreTest := testStruct{testName: "deprecatedGenreTest", testTerm: exampleDeprecatedGenre, endpoint: "genres", expectedUuid: "0f2b2e49-74a2-3357-ba22-80a353922dab", expectedType: "Genre", expectedPrefLabel: "OldGenre", expectedAliases: []string{}, expectedParentUuid: "", expectedAuthority: "TME", expectedAuthValue: "b2xkR2VucmU=-R2VucmVz", expectedIsAuthor: false, expectedIsDeprecated: pTrueValue}
genreTest := testStruct{testName: "genreTest", testTerm: exampleGenre, endpoint: "genres", expectedUuid: "7c80229b-3ad4-3bee-bb7a-45eaafe3f83a", expectedType: "Genre", expectedPrefLabel: "NewGenre", expectedAliases: []string{}, expectedParentUuid: "", expectedAuthority: "TME", expectedAuthValue: "bmV3R2VucmU=-R2VucmVz", expectedIsAuthor: false, expectedIsDeprecated: false}
personWithAliases := testStruct{testName: "personWithAliases", testTerm: examplePersonWithAliases, endpoint: "people", expectedUuid: "05d18aac-9d8e-35d6-9a50-a950fc10aa0e", expectedType: "Person", expectedPrefLabel: "John Smith", expectedAliases: []string{"Johnny Boy", "Smithy"}, expectedParentUuid: "", expectedAuthority: "TME", expectedAuthValue: "am9oblNtaXRo-UE4=", expectedIsAuthor: false, expectedIsDeprecated: false}
personNoAliases := testStruct{testName: "personNoAliases", testTerm: examplePersonWithoutAliases, endpoint: "people", expectedUuid: "ee34e2fd-f363-339b-aa25-191483cb909e", expectedType: "Person", expectedPrefLabel: "Jane Doe", expectedAliases: []string{}, expectedParentUuid: "", expectedAuthority: "TME", expectedAuthValue: "amFuZURvZQ==-UE4=", expectedIsAuthor: false, expectedIsDeprecated: false}
brandTest := testStruct{testName: "brandTest", testTerm: exampleBrand, endpoint: "brands", expectedUuid: "dcb6cc7c-0e5b-3537-8c98-5405a52484f3", expectedType: "Brand", expectedPrefLabel: "NewBrand", expectedAliases: []string{}, expectedParentUuid: financialTimesBrandUuid, expectedAuthority: "TME", expectedAuthValue: "bmV3QnJhbmQ=-QnJhbmRz", expectedIsAuthor: false, expectedIsDeprecated: false}
authorTest := testStruct{testName: "authorTest", testTerm: exampleAuthor, endpoint: "authors", expectedUuid: "829f073f-6666-338f-abd6-d69c37f2e5d0", expectedType: "Person", expectedPrefLabel: "Author McAuthorface", expectedAliases: []string{"John", "Bob"}, expectedParentUuid: "", expectedAuthority: "TME", expectedAuthValue: "bWNBdXRob3JGYWNl-QXV0aG9ycw==", expectedIsAuthor: true, expectedIsDeprecated: false}
deprecatedGenreTest := testStruct{testName: "deprecatedGenreTest", testTerm: exampleDeprecatedGenre, endpoint: "genres", expectedUuid: "0f2b2e49-74a2-3357-ba22-80a353922dab", expectedType: "Genre", expectedPrefLabel: "OldGenre", expectedAliases: []string{}, expectedParentUuid: "", expectedAuthority: "TME", expectedAuthValue: "b2xkR2VucmU=-R2VucmVz", expectedIsAuthor: false, expectedIsDeprecated: true}

testScenarios := []testStruct{genreTest, personWithAliases, personNoAliases, brandTest, authorTest, deprecatedGenreTest}

Expand All @@ -61,7 +63,6 @@ func TestTransformer_transformConcept(t *testing.T) {
}

func TestTransformer_UnMarshallTaxonomy(t *testing.T) {

t.Run("Test terms XML", func(t *testing.T) {
content, err := ioutil.ReadFile("../test-data/terms.xml")
if err != nil {
Expand All @@ -71,11 +72,14 @@ func TestTransformer_UnMarshallTaxonomy(t *testing.T) {
iFace, err := tr.UnMarshallTaxonomy(content)
assert.Equal(t, "A term", iFace[0].(Term).CanonicalName)
assert.Equal(t, "Nstein_GL_AFTM_GL_123456", iFace[0].(Term).RawID)
assert.Equal(t, pTrueValue, iFace[0].(Term).Enabled)
assert.NotNil(t, iFace[0].(Term).Enabled)
assert.True(t, *iFace[0].(Term).Enabled)
assert.Equal(t, "Nstein_GL_AFTM_GL_111", iFace[1].(Term).RawID)
assert.Equal(t, pTrueValue, iFace[1].(Term).Enabled)
assert.NotNil(t, iFace[1].(Term).Enabled)
assert.True(t, *iFace[1].(Term).Enabled)
assert.Equal(t, "Nstein_GL_AFTM_GL_9493", iFace[2].(Term).RawID)
assert.Equal(t, pFalseValue, iFace[2].(Term).Enabled)
assert.NotNil(t, iFace[2].(Term).Enabled)
assert.False(t, *iFace[2].(Term).Enabled)
})

t.Run("Test categories XML", func(t *testing.T) {
Expand Down Expand Up @@ -117,6 +121,7 @@ func TestTransformer_UnMarshallTermEnabledDefault(t *testing.T) {
tr := Transformer{}
term, err := tr.UnMarshallTerm(content)
assert.Equal(t, "'Ar'ara", term.(Term).CanonicalName)
assert.Equal(t, pTrueValue, term.(Term).Enabled)
assert.NotNil(t, term.(Term).Enabled)
assert.True(t, *term.(Term).Enabled)
})
}

0 comments on commit 36e55d0

Please sign in to comment.