Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
test: Add tests for loading Step/ViewDef from git/file
Browse files Browse the repository at this point in the history
  • Loading branch information
mkralik3 committed Aug 3, 2023
1 parent c435f23 commit 328b72f
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package io.kaoto.backend.api.metadata.catalog;

import io.fabric8.kubernetes.client.KubernetesClient;
import io.kaoto.backend.model.configuration.Repository;
import io.kaoto.backend.model.step.Step;
import io.quarkus.test.junit.QuarkusTest;
import jakarta.enterprise.inject.Instance;
import jakarta.inject.Inject;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;

import java.util.Collection;
import java.util.List;
import java.util.Optional;

import static org.assertj.core.api.Assertions.assertThat;

@QuarkusTest
public class StepCatalogTest {
@Inject
private Instance<StepCatalogParser> stepCatalogParsers;
@Inject
private KubernetesClient kclient;
@Inject
private StepCatalog mainStepCatalog;

@ParameterizedTest
@CsvSource({"https://github.com/KaotoIO/camel-component-metadata.git,test-202308",
"https://github.com/apache/camel-kamelets.git,v3.21.0"})
void testParseFromGit(String repo, String tag) {
StepRepository stepRepository = new StepRepository(
Optional.empty(),
Optional.of(List.of(
new GitRepository(repo, tag, true, "all"))),
Optional.empty());
tryLoadSteps(stepRepository, repo + ":" + tag);
}

@ParameterizedTest
@ValueSource(strings = {
"https://github.com/KaotoIO/camel-component-metadata/archive/refs/tags/test-202308.zip",
"https://repo1.maven.org/maven2/org/apache/camel/kamelets/camel-kamelets/3.21.0/camel-kamelets-3.21.0.jar",
"resource://camel-component-metadata.zip",
"resource://camel-kamelets-3.21.0.jar",
"resource://camel-connectors-3.21.0.zip"
})
void testParseFromFile(String resource) {
StepRepository stepRepository = new StepRepository(
Optional.of(List.of(
new LocationRepository(resource, true, "all"))),
Optional.empty(),
Optional.empty());
tryLoadSteps(stepRepository, resource);
}

private void tryLoadSteps(StepRepository stepRepository, String resource) {
StepCatalog anotherStepCatalog = new StepCatalog();
anotherStepCatalog.setStepCatalogParsers(stepCatalogParsers);
anotherStepCatalog.setKclient(kclient);
anotherStepCatalog.setRepository(stepRepository);
anotherStepCatalog.loadParsers();
anotherStepCatalog.warmUpCatalog();
Collection<Step> steps = anotherStepCatalog.getReadOnlyCatalog().getAll();
assertThat(steps)
.isNotEmpty()
.as("Test that more than 50 steps was loaded from resource: " + resource)
.hasSizeGreaterThan(50)
.as("Test that catalog contains steps only from resource '" + resource +
"' and not from different resources.")
.hasSizeLessThan(mainStepCatalog.getReadOnlyCatalog().getAll().size());
}


// GitRepository implementation used for testing
private record GitRepository(String url, String tag, boolean ifNoCluster, String kind) implements Repository.Git {
}

// LocationRepository implementation used for testing
private record LocationRepository(String url, boolean ifNoCluster, String kind) implements Repository.Location {
}

// StepRepository implementation used for testing
private record StepRepository(Optional<List<Location>> jar, Optional<List<Git>> git,
Optional<List<Location>> localFolder) implements StepCatalog.StepRepository {
}
}
6 changes: 6 additions & 0 deletions catalog/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package io.kaoto.backend.api.metadata.catalog;

import io.kaoto.backend.model.configuration.Repository;
import io.kaoto.backend.model.view.ViewDefinition;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;

import java.util.Collection;
import java.util.List;
import java.util.Optional;

import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;

@QuarkusTest
public class ViewDefinitionCatalogTest {

private static final String REPO = "https://github.com/KaotoIO/kaoto-viewdefinition-catalog";
private static final String TAG = "test-202308";
private static final int EXPECTED_VIEW_DEFINITIONS = 13;


@Test
void testParseFromGit() {
ViewDefinitionRepository stepRepository = new ViewDefinitionRepository(
Optional.empty(),
Optional.of(List.of(
new GitRepository(REPO + ".git", TAG, true, "all"))),
Optional.empty());
tryLoadViewDefinitions(stepRepository);
}

@Test
void testParseFromFile() {
ViewDefinitionRepository stepRepository = new ViewDefinitionRepository(
Optional.of(List.of(new LocationRepository(REPO + "/archive/refs/tags/" + TAG + ".zip", true, "all"))),
Optional.empty(), Optional.empty());
tryLoadViewDefinitions(stepRepository);
}

private void tryLoadViewDefinitions(ViewDefinitionRepository viewDefinitionRepository) {
ViewDefinitionCatalog viewDefinitionCatalog = new ViewDefinitionCatalog();
viewDefinitionCatalog.setRepository(viewDefinitionRepository);
viewDefinitionCatalog.loadParsers();
viewDefinitionCatalog.warmUpCatalog();
Collection<ViewDefinition> allViews = viewDefinitionCatalog.getReadOnlyCatalog().getAll();
assertThat(allViews)
.isNotEmpty()
.hasSize(EXPECTED_VIEW_DEFINITIONS);
}

// GitRepository implementation used for testing
private record GitRepository(String url, String tag, boolean ifNoCluster, String kind) implements Repository.Git {
}

// LocationRepository implementation used for testing
private record LocationRepository(String url, boolean ifNoCluster, String kind) implements Repository.Location {
}

// StepRepository implementation used for testing
private record ViewDefinitionRepository(Optional<List<Location>> jar, Optional<List<Git>> git,
Optional<List<Location>> localFolder)
implements ViewDefinitionCatalog.ViewDefinitionRepository {
}

}

0 comments on commit 328b72f

Please sign in to comment.