Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ public Integer doCall() throws Exception {
rows = rows.stream()
.filter(
r -> r.name.equalsIgnoreCase(filterName)
|| r.description.toLowerCase(Locale.ROOT).contains(filterName)
|| r.label.toLowerCase(Locale.ROOT).contains(filterName))
|| (r.description != null
&& r.description.toLowerCase(Locale.ROOT).contains(filterName))
|| (r.label != null && r.label.toLowerCase(Locale.ROOT).contains(filterName)))
.collect(Collectors.toList());
}
if (sinceBefore != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.dsl.jbang.core.commands.catalog;

import org.apache.camel.dsl.jbang.core.commands.CamelCommandBaseTestSupport;
import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
import org.apache.camel.dsl.jbang.core.commands.MavenResolverMixin;
import org.apache.camel.util.json.JsonArray;
import org.apache.camel.util.json.JsonObject;
import org.apache.camel.util.json.Jsoner;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

class CatalogComponentTest extends CamelCommandBaseTestSupport {

@Test
void shouldListComponentsFromCatalog() throws Exception {
CatalogComponent command = createCommand();

int exit = command.doCall();

assertEquals(0, exit);
assertTrue(printer.getOutput().contains("kafka"),
"default listing should include the kafka component, was: " + printer.getOutput());
}

@Test
void shouldNarrowToFilteredComponent() throws Exception {
CatalogComponent command = createCommand();
command.filterName = "kafka";

int exit = command.doCall();

assertEquals(0, exit);
String out = printer.getOutput();
assertTrue(out.contains("kafka"), "filtered listing should include kafka, was: " + out);
assertFalse(out.contains("timer"), "filtered listing should exclude unrelated components, was: " + out);
}

@Test
void shouldRenderJsonOutput() throws Exception {
CatalogComponent command = createCommand();
command.filterName = "kafka";
command.jsonOutput = true;

int exit = command.doCall();

assertEquals(0, exit);
JsonArray rows = (JsonArray) Jsoner.deserialize(printer.getOutput());
assertTrue(rows.stream()
.map(JsonObject.class::cast)
.anyMatch(row -> "kafka".equals(row.getString("name"))),
"JSON output should contain a row with name kafka, was: " + printer.getOutput());
}

@Test
void shouldSuggestSimilarWhenFilterHasNoMatch() throws Exception {
CatalogComponent command = createCommand();
command.filterName = "kafkaa";

int exit = command.doCall();

assertEquals(0, exit);
String out = printer.getOutput();
assertTrue(out.contains("No results for filter: kafkaa"),
"should report no results for an unknown filter, was: " + out);
assertTrue(out.contains("camel doc kafkaa"),
"should suggest the doc command for the filter, was: " + out);
}

private CatalogComponent createCommand() {
CatalogComponent command = new CatalogComponent(new CamelJBangMain().withPrinter(printer));
// options are normally defaulted by picocli; set them as we construct the command directly
command.sort = "name";
command.mavenResolver = new MavenResolverMixin();
return command;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.dsl.jbang.core.commands.catalog;

import org.apache.camel.dsl.jbang.core.commands.CamelCommandBaseTestSupport;
import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
import org.apache.camel.dsl.jbang.core.commands.MavenResolverMixin;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

class CatalogDataFormatTest extends CamelCommandBaseTestSupport {

@Test
void shouldListDataFormatsFromCatalog() throws Exception {
CatalogDataFormat command = createCommand();

int exit = command.doCall();

assertEquals(0, exit);
assertTrue(printer.getOutput().contains("jaxb"),
"default listing should include the jaxb data format, was: " + printer.getOutput());
}

@Test
void shouldNarrowToFilteredDataFormat() throws Exception {
CatalogDataFormat command = createCommand();
command.filterName = "jaxb";

int exit = command.doCall();

assertEquals(0, exit);
String out = printer.getOutput();
assertTrue(out.contains("jaxb"), "filtered listing should include jaxb, was: " + out);
assertFalse(out.contains("csv"), "filtered listing should exclude unrelated data formats, was: " + out);
}

private CatalogDataFormat createCommand() {
CatalogDataFormat command = new CatalogDataFormat(new CamelJBangMain().withPrinter(printer));
// options are normally defaulted by picocli; set them as we construct the command directly
command.sort = "name";
command.mavenResolver = new MavenResolverMixin();
return command;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.dsl.jbang.core.commands.catalog;

import org.apache.camel.dsl.jbang.core.commands.CamelCommandBaseTestSupport;
import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
import org.apache.camel.dsl.jbang.core.commands.MavenResolverMixin;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

class CatalogDevConsoleTest extends CamelCommandBaseTestSupport {

@Test
void shouldListDevConsolesFromCatalog() throws Exception {
CatalogDevConsole command = createCommand();

int exit = command.doCall();

assertEquals(0, exit);
assertTrue(printer.getOutput().contains("context"),
"default listing should include the context dev-console, was: " + printer.getOutput());
}

@Test
void shouldNarrowToFilteredDevConsole() throws Exception {
CatalogDevConsole command = createCommand();
command.filterName = "context";

int exit = command.doCall();

assertEquals(0, exit);
String out = printer.getOutput();
assertTrue(out.contains("context"), "filtered listing should include context, was: " + out);
assertFalse(out.contains("gc"), "filtered listing should exclude unrelated dev-consoles, was: " + out);
}

private CatalogDevConsole createCommand() {
CatalogDevConsole command = new CatalogDevConsole(new CamelJBangMain().withPrinter(printer));
// options are normally defaulted by picocli; set them as we construct the command directly
command.sort = "name";
command.mavenResolver = new MavenResolverMixin();
return command;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.dsl.jbang.core.commands.catalog;

import org.apache.camel.dsl.jbang.core.commands.CamelCommandBaseTestSupport;
import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
import org.apache.camel.dsl.jbang.core.commands.MavenResolverMixin;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

class CatalogLanguageTest extends CamelCommandBaseTestSupport {

@Test
void shouldListLanguagesFromCatalog() throws Exception {
CatalogLanguage command = createCommand();

int exit = command.doCall();

assertEquals(0, exit);
assertTrue(printer.getOutput().contains("simple"),
"default listing should include the simple language, was: " + printer.getOutput());
}

@Test
void shouldNarrowToFilteredLanguage() throws Exception {
CatalogLanguage command = createCommand();
command.filterName = "simple";

int exit = command.doCall();

assertEquals(0, exit);
String out = printer.getOutput();
assertTrue(out.contains("simple"), "filtered listing should include simple, was: " + out);
assertFalse(out.contains("xpath"), "filtered listing should exclude unrelated languages, was: " + out);
}

private CatalogLanguage createCommand() {
CatalogLanguage command = new CatalogLanguage(new CamelJBangMain().withPrinter(printer));
// options are normally defaulted by picocli; set them as we construct the command directly
command.sort = "name";
command.mavenResolver = new MavenResolverMixin();
return command;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.dsl.jbang.core.commands.catalog;

import org.apache.camel.dsl.jbang.core.commands.CamelCommandBaseTestSupport;
import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
import org.apache.camel.dsl.jbang.core.commands.MavenResolverMixin;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

class CatalogOtherTest extends CamelCommandBaseTestSupport {

@Test
void shouldListOtherArtifactsFromCatalog() throws Exception {
CatalogOther command = createCommand();

int exit = command.doCall();

assertEquals(0, exit);
assertTrue(printer.getOutput().contains("cli-connector"),
"default listing should include the cli-connector artifact, was: " + printer.getOutput());
}

@Test
void shouldNarrowToFilteredArtifact() throws Exception {
CatalogOther command = createCommand();
command.filterName = "cli-connector";

int exit = command.doCall();

assertEquals(0, exit);
String out = printer.getOutput();
assertTrue(out.contains("cli-connector"), "filtered listing should include cli-connector, was: " + out);
assertFalse(out.contains("cloudevents"), "filtered listing should exclude unrelated artifacts, was: " + out);
}

private CatalogOther createCommand() {
CatalogOther command = new CatalogOther(new CamelJBangMain().withPrinter(printer));
// options are normally defaulted by picocli; set them as we construct the command directly
command.sort = "name";
command.mavenResolver = new MavenResolverMixin();
return command;
}
}
Loading
Loading