use of org.finos.legend.sdlc.protocol.pure.v1.EntityToPureConverter in project legend-sdlc by finos.
the class ServicesGenerationMojo method resolveServicesSpecification.
private static ResolvedServicesSpecification resolveServicesSpecification(ServicesSpecification servicesSpec) throws Exception {
Set<String> servicePaths = null;
if (servicesSpec.directories != null) {
try (EntityLoader directoriesLoader = EntityLoader.newEntityLoader(servicesSpec.directories)) {
EntityToPureConverter converter = new EntityToPureConverter();
servicePaths = directoriesLoader.getAllEntities().filter(e -> converter.fromEntityIfPossible(e).filter(s -> s instanceof Service).isPresent()).map(Entity::getPath).collect(Collectors.toSet());
}
}
if (servicesSpec.servicePaths != null) {
if (servicePaths == null) {
servicePaths = servicesSpec.servicePaths;
} else {
servicePaths.addAll(servicesSpec.servicePaths);
}
}
return new ResolvedServicesSpecification(servicePaths, servicesSpec.packages);
}
use of org.finos.legend.sdlc.protocol.pure.v1.EntityToPureConverter in project legend-sdlc by finos.
the class LegendSDLCTestSuiteBuilder method buildSuite.
public TestSuite buildSuite(String name, Collection<? extends Entity> entitiesForTesting, ClassLoader classLoader) {
Map<Class<? extends PackageableElement>, TestSuiteBuilder> testSuiteBuilders = getTestSuiteBuilderByTypeMap(MappingTestCase.class, ServiceTestCase.class);
TestSuite suite = new TestSuite();
suite.setName(name);
Set<String> entitiesForTestingPaths = entitiesForTesting.stream().map(Entity::getPath).collect(Collectors.toSet());
PureModelContextData pureModelContextData;
PureModel pureModel;
try (EntityLoader entityLoader = EntityLoader.newEntityLoader((classLoader == null) ? LegendSDLCTestSuiteBuilder.class.getClassLoader() : classLoader)) {
PureModelBuilder.PureModelWithContextData pureModelWithContextData = PureModelBuilder.newBuilder().withEntitiesIfPossible(entitiesForTesting).withEntitiesIfPossible(entityLoader.getAllEntities().filter(e -> !entitiesForTestingPaths.contains(e.getPath()))).build(classLoader);
pureModelContextData = pureModelWithContextData.getPureModelContextData();
pureModel = pureModelWithContextData.getPureModel();
} catch (Exception e) {
LOGGER.error("Error loading entities", e);
throw (e instanceof RuntimeException) ? (RuntimeException) e : new RuntimeException("Error loading entities", e);
}
EntityToPureConverter converter = new EntityToPureConverter();
entitiesForTesting.stream().map(e -> {
Optional<TestSuiteBuilder> optionalBuilder = converter.fromEntityIfPossible(e).map(element -> testSuiteBuilders.get(element.getClass()));
if (!optionalBuilder.isPresent()) {
return null;
}
TestSuiteBuilder builder = optionalBuilder.get();
LOGGER.debug("Building test suite for {} (classifier: {})", e.getPath(), e.getClassifierPath());
TestSuite eSuite = builder.build(pureModel, pureModelContextData, e);
LOGGER.debug("Test count for {}: {}", e.getPath(), (eSuite == null) ? 0 : eSuite.testCount());
return eSuite;
}).filter(Objects::nonNull).forEach(suite::addTest);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Entity test suite count: {}", suite.testCount());
LOGGER.debug("Entity test case count: {}", suite.countTestCases());
}
return suite;
}
Aggregations