Skip to content

Commit

Permalink
Fix apache#575: recognize hystrix automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaferraro committed Apr 12, 2019
1 parent 1fd3404 commit fb261a5
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
71 changes: 71 additions & 0 deletions pkg/metadata/metadata_dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,74 @@ func TestDependencies(t *testing.T) {
// assert all dependencies are found and sorted (removing duplicates)
assert.Equal(t, []string{"camel:core", "camel:http4", "camel:twitter"}, meta.Dependencies)
}

func TestJacksonDependency(t *testing.T) {
code := v1alpha1.SourceSpec{
DataSpec: v1alpha1.DataSpec{
Name: "Request.java",
Content: `
from("http4:test").unmarshal().json(JsonLibrary.Jackson).to("log:end");
`,
},
Language: v1alpha1.LanguageJavaSource,
}

catalog, err := test.DefaultCatalog()
assert.Nil(t, err)

meta := Extract(catalog, code)

// assert all dependencies are found and sorted (removing duplicates)
assert.Equal(t, []string{"camel:core", "camel:http4", "camel:jackson"}, meta.Dependencies)
}

func TestHystrixDependency(t *testing.T) {
code := v1alpha1.SourceSpec{
DataSpec: v1alpha1.DataSpec{
Name: "Request.groovy",
Content: `
from("http4:test")
.hystrix()
.to("log:end")
.onFallback()
.to("log:fallback")
`,
},
Language: v1alpha1.LanguageGroovy,
}

catalog, err := test.DefaultCatalog()
assert.Nil(t, err)

meta := Extract(catalog, code)

// assert all dependencies are found and sorted (removing duplicates)
assert.Equal(t, []string{"camel:core", "camel:http4", "camel:hystrix"}, meta.Dependencies)
}

func TestXMLHystrixDependency(t *testing.T) {
code := v1alpha1.SourceSpec{

DataSpec: v1alpha1.DataSpec{
Name: "routes.xml",
Content: `
<from uri="direct:ciao" />
<hystrix>
<to uri="log:info" />
<onFallback>
<to uri="kafka:topic" />
</onFallback>
</hystrix>
`,
},
Language: v1alpha1.LanguageXML,
}

catalog, err := test.DefaultCatalog()
assert.Nil(t, err)

meta := Extract(catalog, code)

// assert all dependencies are found and sorted (removing duplicates)
assert.Equal(t, []string{"camel:core", "camel:hystrix", "camel:kafka"}, meta.Dependencies)
}
2 changes: 2 additions & 0 deletions pkg/util/source/inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ var (

additionalDependencies = map[string]string{
".*JsonLibrary\\.Jackson.*": "camel:jackson",
".*\\.hystrix().*": "camel:hystrix",
".*<hystrix>.*": "camel:hystrix",
}
)

Expand Down

0 comments on commit fb261a5

Please sign in to comment.