use of io.syndesis.common.model.extension.Extension in project syndesis by syndesisio.
the class ExtensionDataManagerTest method shouldGetCorrectDataByExtensionId.
@Test
public void shouldGetCorrectDataByExtensionId() throws IOException {
final DataManager dataManager = mock(DataManager.class);
final FileDAO extensionDataAccess = mock(FileDAO.class);
final FileDataManager extensionDataManager = new FileDataManager(dataManager, extensionDataAccess);
String sampleBinaryData = "Hello";
Extension sampleMetadata = new Extension.Builder().id("1234").status(Extension.Status.Installed).extensionId("extensionId").description("Description").build();
when(extensionDataAccess.read("/extensions/1234")).thenReturn(new ByteArrayInputStream(sampleBinaryData.getBytes(StandardCharsets.UTF_8)));
when(dataManager.fetchIdsByPropertyValue(Extension.class, "extensionId", "extensionId", "status", Extension.Status.Installed.name())).thenReturn(Collections.singleton("1234"));
when(dataManager.fetch(Extension.class, "1234")).thenReturn(sampleMetadata);
assertThat(extensionDataManager.getExtensionMetadata("extensionId")).isEqualTo(sampleMetadata);
assertThat(IOUtils.toString(extensionDataManager.getExtensionBinaryFile("extensionId"), StandardCharsets.UTF_8)).isEqualTo(sampleBinaryData);
}
use of io.syndesis.common.model.extension.Extension in project syndesis by syndesisio.
the class GenerateMetadataMojo method tryImportingPartialJSON.
/**
* Loads a partial metadata json file, if configured at Maven Plugin level.
* @throws MojoExecutionException
*/
protected void tryImportingPartialJSON() throws MojoExecutionException {
File template;
if (StringUtils.isNotEmpty(source)) {
template = new File(source);
} else {
template = new File(metadataDestination);
}
if (template.exists()) {
try {
JsonNode tree = Json.reader().readTree(Files.newBufferedReader(template.toPath(), StandardCharsets.UTF_8));
Extension extension = ExtensionConverter.getDefault().toInternalExtension(tree);
getLog().info("Loaded base partial metadata configuration file: " + source);
actions.clear();
for (Action action : extension.getActions()) {
action.getId().ifPresent(id -> actions.put(id, action));
}
extensionBuilder = extensionBuilder.createFrom(extension);
extensionBuilder.actions(Collections.emptySet());
} catch (IOException e) {
throw new MojoExecutionException("Invalid input json: " + source, e);
}
}
}
use of io.syndesis.common.model.extension.Extension in project syndesis by syndesisio.
the class IntegrationResourceManager method collectDependencies.
/**
* Collect dependencies.
*/
default Collection<Dependency> collectDependencies(Collection<? extends Step> steps, boolean resolveExtensionTags) {
final List<Dependency> dependencies = new ArrayList<>();
for (Step step : steps) {
step.getAction().filter(WithDependencies.class::isInstance).map(WithDependencies.class::cast).map(WithDependencies::getDependencies).ifPresent(dependencies::addAll);
List<Dependency> connectorDependencies = step.getConnection().flatMap(Connection::getConnector).map(WithDependencies::getDependencies).orElse(Collections.emptyList());
dependencies.addAll(connectorDependencies);
List<Dependency> lookedUpConnectorDependecies = step.getConnection().filter(c -> !c.getConnector().isPresent()).map(Connection::getConnectorId).flatMap(this::loadConnector).map(WithDependencies::getDependencies).orElse(Collections.emptyList());
dependencies.addAll(lookedUpConnectorDependecies);
// Connector extension
Stream.concat(connectorDependencies.stream(), lookedUpConnectorDependecies.stream()).filter(Dependency::isExtension).map(Dependency::getId).map(this::loadExtension).filter(Optional::isPresent).map(Optional::get).map(Extension::getDependencies).forEach(dependencies::addAll);
// Step extension
step.getExtension().map(WithDependencies::getDependencies).ifPresent(dependencies::addAll);
step.getExtension().map(Extension::getExtensionId).map(Dependency::extension).ifPresent(dependencies::add);
}
if (resolveExtensionTags) {
return dependencies.stream().flatMap(dep -> {
if (dep.isExtensionTag()) {
List<Extension> extensions = this.loadExtensionsByTag(dep.getId());
Stream<Dependency> extensionDependency = extensions.stream().map(ext -> Dependency.extension(ext.getExtensionId()));
Stream<Dependency> transitive = extensions.stream().map(Extension::getDependencies).flatMap(Collection::stream);
return Stream.concat(extensionDependency, transitive);
} else {
return Stream.of(dep);
}
}).collect(Collectors.toCollection(ArrayList::new));
} else {
return dependencies;
}
}
use of io.syndesis.common.model.extension.Extension in project syndesis by syndesisio.
the class ExtensionSchemaValidationTest method validateStepExtensionTest.
@Test
public void validateStepExtensionTest() throws ProcessingException, IOException {
String syndesisExtensionSchema = "/syndesis/syndesis-extension-definition-schema.json";
JsonSchema schema = JsonSchemaFactory.byDefault().getJsonSchema("resource:" + syndesisExtensionSchema);
ExtensionConverter converter = new DefaultExtensionConverter();
Extension extension = new Extension.Builder().extensionId("my-extension").name("Name").description("Description").uses(OptionalInt.empty()).version("1.0.0").schemaVersion(ExtensionConverter.getCurrentSchemaVersion()).addAction(new StepAction.Builder().id("action-1").name("action-1-name").description("Action 1 Description").pattern(Action.Pattern.From).descriptor(new StepDescriptor.Builder().entrypoint("direct:hello").kind(StepAction.Kind.ENDPOINT).build()).build()).build();
JsonNode tree = converter.toPublicExtension(extension);
ProcessingReport report = schema.validate(tree);
assertFalse(report.toString(), report.iterator().hasNext());
Extension extensionClone = converter.toInternalExtension(tree);
assertEquals(extensionClone, extension);
}
Aggregations