-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Create sub schemas for each top properties (#144)
Fixes: #138
- Loading branch information
1 parent
b5090ef
commit 40efd4a
Showing
7 changed files
with
257 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...s/camel-catalog/assembly/src/test/java/io/kaoto/camelcatalog/CamelCatalogTestSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package io.kaoto.camelcatalog; | ||
|
||
import com.fasterxml.jackson.core.JsonFactory; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | ||
|
||
import java.nio.file.Paths; | ||
|
||
public class CamelCatalogTestSupport { | ||
protected static final ObjectMapper jsonMapper = new ObjectMapper(); | ||
protected static final ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory()); | ||
protected static final JsonFactory jsonFactory = new JsonFactory(); | ||
|
||
private static ObjectNode index = null; | ||
|
||
protected ObjectNode getIndex() throws Exception { | ||
if (CamelCatalogTestSupport.index == null) { | ||
var path = Paths.get("..").resolve("dist").resolve("index.json"); | ||
CamelCatalogTestSupport.index = (ObjectNode) jsonMapper.readTree(path.toFile()); | ||
} | ||
return CamelCatalogTestSupport.index; | ||
} | ||
|
||
protected ObjectNode getSchema(String name) throws Exception { | ||
var index = getIndex(); | ||
for (JsonNode schema : index.withArray("schemas")) { | ||
var fileName = schema.get("file").asText(); | ||
var tokens = fileName.split("-"); | ||
if ("camelYamlDsl".equals(tokens[0]) && name.isEmpty() && tokens[1].matches("\\d+.*")) { | ||
return (ObjectNode) jsonMapper.readTree(Paths.get("..").resolve("dist").resolve(fileName).toFile()); | ||
} else if ("camelYamlDsl".equals(tokens[0]) && tokens[1].equals(name)) { | ||
return (ObjectNode) jsonMapper.readTree(Paths.get("..").resolve("dist").resolve(fileName).toFile()); | ||
} | ||
} | ||
return null; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...es/camel-catalog/assembly/src/test/java/io/kaoto/camelcatalog/CamelYamlDslSchemaTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.kaoto.camelcatalog; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class CamelYamlDslSchemaTest extends CamelCatalogTestSupport { | ||
|
||
@Test | ||
public void testRootSchema() throws Exception { | ||
var rootSchema = getSchema(""); | ||
assertEquals(rootSchema.get("type").asText(), "array"); | ||
var definitions = rootSchema.withObject("/items").withObject("/definitions"); | ||
assertTrue(definitions.has("org.apache.camel.model.ProcessorDefinition")); | ||
} | ||
|
||
@Test | ||
public void testBeans() throws Exception { | ||
var beansSchema = getSchema("beans"); | ||
assertEquals(beansSchema.get("type").asText(), "array"); | ||
var definitions = beansSchema.withObject("/definitions"); | ||
assertEquals(1, definitions.size()); | ||
assertTrue(definitions.has("org.apache.camel.model.app.RegistryBeanDefinition")); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
packages/camel-catalog/assembly/src/test/java/io/kaoto/camelcatalog/IndexTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package io.kaoto.camelcatalog; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class IndexTest extends CamelCatalogTestSupport { | ||
|
||
@Test | ||
public void test() throws Exception { | ||
var index = getIndex(); | ||
assertTrue(index.has("catalogs")); | ||
var catalogs = index.withObject("/catalogs"); | ||
assertTrue(catalogs.has("models")); | ||
assertTrue(catalogs.has("components")); | ||
assertTrue(catalogs.has("languages")); | ||
assertTrue(catalogs.has("kamelets")); | ||
assertTrue(catalogs.has("dataformats")); | ||
assertTrue(index.has("schemas")); | ||
var schemas = index.withArray("/schemas"); | ||
List<String> props = new ArrayList<>(); | ||
List<String> crds = new ArrayList<>(); | ||
schemas.forEach(schema -> { | ||
var tokens = schema.get("file").asText().split("-"); | ||
if ("camelYamlDsl".equals(tokens[0]) && !tokens[1].matches("^\\d+.*")) { | ||
props.add(tokens[1]); | ||
} else if ("crd".equals(tokens[0])) { | ||
crds.add(tokens[2]); | ||
} | ||
}); | ||
assertTrue(props.contains("beans")); | ||
assertTrue(props.contains("errorHandler")); | ||
assertTrue(props.contains("from")); | ||
assertTrue(props.contains("intercept")); | ||
assertTrue(props.contains("interceptFrom")); | ||
assertTrue(props.contains("interceptSendToEndpoint")); | ||
assertTrue(props.contains("onCompletion")); | ||
assertTrue(props.contains("onException")); | ||
assertTrue(props.contains("rest")); | ||
assertTrue(props.contains("restConfiguration")); | ||
assertTrue(props.contains("route")); | ||
assertTrue(props.contains("routeConfiguration")); | ||
assertTrue(props.contains("routeTemplate")); | ||
assertTrue(props.contains("templatedRoute")); | ||
assertTrue(crds.contains("integrations")); | ||
assertTrue(crds.contains("kamelets")); | ||
assertTrue(crds.contains("kameletbindings")); | ||
assertTrue(crds.contains("pipes")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters