use of javax.enterprise.context.spi.CreationalContext in project kie-wb-common by kiegroup.
the class ModuleServiceImplResolvePackageValidTest method testResolvePackageWithKModuleFile.
@Test
public void testResolvePackageWithKModuleFile() throws Exception {
final Bean moduleServiceBean = (Bean) beanManager.getBeans(KieModuleService.class).iterator().next();
final CreationalContext cc = beanManager.createCreationalContext(moduleServiceBean);
final KieModuleService moduleService = (KieModuleService) beanManager.getReference(moduleServiceBean, KieModuleService.class, cc);
final URL testUrl = this.getClass().getResource("/ModuleBackendTestModuleStructureValid/src/main/resources/META-INF/kmodule.xml");
final org.uberfire.java.nio.file.Path nioTestPath = fs.getPath(testUrl.toURI());
final Path testPath = paths.convert(nioTestPath);
// Test a kModule.xml file resolves to a null package
final Package result = moduleService.resolvePackage(testPath);
assertNull(result);
}
use of javax.enterprise.context.spi.CreationalContext in project kie-wb-common by kiegroup.
the class PackageDataModelDeclaredTypesTest method testPackageDeclaredTypes.
@Test
public void testPackageDeclaredTypes() throws Exception {
final Bean dataModelServiceBean = (Bean) beanManager.getBeans(DataModelService.class).iterator().next();
final CreationalContext cc = beanManager.createCreationalContext(dataModelServiceBean);
final DataModelService dataModelService = (DataModelService) beanManager.getReference(dataModelServiceBean, DataModelService.class, cc);
final URL packageUrl = this.getClass().getResource("/DataModelBackendDeclaredTypesTest1/src/main/java/t1p1");
final org.uberfire.java.nio.file.Path nioPackagePath = fs.getPath(packageUrl.toURI());
final Path packagePath = paths.convert(nioPackagePath);
final PackageDataModelOracle packageLoader = dataModelService.getDataModel(packagePath);
// Emulate server-to-client conversions
final Caller<IncrementalDataModelService> service = new MockIncrementalDataModelServiceCaller(packageLoader);
final AsyncPackageDataModelOracle oracle = new AsyncPackageDataModelOracleImpl(service, validatorInstance);
final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
dataModel.setPackageName("t1p1");
dataModel.setModelFields(packageLoader.getModuleModelFields());
dataModel.setTypeSources(new HashMap<String, TypeSource>() {
{
put("t1p1.Bean1", TypeSource.JAVA_PROJECT);
put("t1p1.DRLBean", TypeSource.DECLARED);
put("t1p2.Bean2", TypeSource.JAVA_PROJECT);
put("java.lang.String", TypeSource.JAVA_PROJECT);
put("int", TypeSource.JAVA_PROJECT);
}
});
PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
assertNotNull(dataModel);
assertEquals(2, oracle.getFactTypes().length);
PackageDataModelOracleTestUtils.assertContains("Bean1", oracle.getFactTypes());
PackageDataModelOracleTestUtils.assertContains("DRLBean", oracle.getFactTypes());
assertEquals(2, oracle.getExternalFactTypes().length);
PackageDataModelOracleTestUtils.assertContains("t1p2.Bean2", oracle.getExternalFactTypes());
PackageDataModelOracleTestUtils.assertContains("java.lang.String", oracle.getExternalFactTypes());
oracle.getTypeSource("Bean1", new Callback<TypeSource>() {
@Override
public void callback(final TypeSource result) {
assertEquals(TypeSource.JAVA_PROJECT, result);
}
});
oracle.getTypeSource("DRLBean", new Callback<TypeSource>() {
@Override
public void callback(final TypeSource result) {
assertEquals(TypeSource.DECLARED, result);
}
});
}
use of javax.enterprise.context.spi.CreationalContext in project kie-wb-common by kiegroup.
the class PackageDataModelDeclaredTypesTest method setUp.
@Before
public void setUp() throws Exception {
// Bootstrap WELD container
StartMain startMain = new StartMain(new String[0]);
beanManager = startMain.go().getBeanManager();
// Instantiate Paths used in tests for Path conversion
final Bean pathsBean = (Bean) beanManager.getBeans(Paths.class).iterator().next();
final CreationalContext cc = beanManager.createCreationalContext(pathsBean);
paths = (Paths) beanManager.getReference(pathsBean, Paths.class, cc);
// Ensure URLs use the default:// scheme
fs.forceAsDefault();
}
use of javax.enterprise.context.spi.CreationalContext in project kie-wb-common by kiegroup.
the class PackageDataModelServiceTest method testModuleDataModelOracle.
@Test
public void testModuleDataModelOracle() throws Exception {
final Bean dataModelServiceBean = (Bean) beanManager.getBeans(DataModelService.class).iterator().next();
final CreationalContext cc = beanManager.createCreationalContext(dataModelServiceBean);
final DataModelService dataModelService = (DataModelService) beanManager.getReference(dataModelServiceBean, DataModelService.class, cc);
final URL packageUrl = this.getClass().getResource("/DataModelBackendTest1/src/main/java/t3p1");
final org.uberfire.java.nio.file.Path nioPackagePath = fs.getPath(packageUrl.toURI());
final Path packagePath = paths.convert(nioPackagePath);
final PackageDataModelOracle packageLoader = dataModelService.getDataModel(packagePath);
final ModuleDataModelOracle moduleLoader = dataModelService.getModuleDataModel(packagePath);
// Emulate server-to-client conversions
final Caller<IncrementalDataModelService> service = new MockIncrementalDataModelServiceCaller(packageLoader);
final AsyncPackageDataModelOracle oracle = new AsyncPackageDataModelOracleImpl(service, validatorInstance);
final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
dataModel.setModelFields(moduleLoader.getModuleModelFields());
PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
assertNotNull(oracle);
assertEquals(3, oracle.getAllFactTypes().length);
assertContains("t3p1.Bean1", oracle.getAllFactTypes());
assertContains("t3p2.Bean2", oracle.getAllFactTypes());
assertContains("java.lang.String", oracle.getAllFactTypes());
oracle.getFieldCompletions("t3p1.Bean1", new Callback<ModelField[]>() {
@Override
public void callback(final ModelField[] fields) {
assertEquals(3, fields.length);
assertContains("this", fields);
assertContains("field1", fields);
assertContains("field2", fields);
}
});
oracle.getFieldCompletions("t3p2.Bean2", new Callback<ModelField[]>() {
@Override
public void callback(final ModelField[] fields) {
assertEquals(2, fields.length);
assertContains("this", fields);
assertContains("field1", fields);
}
});
}
use of javax.enterprise.context.spi.CreationalContext in project kie-wb-common by kiegroup.
the class PackageDataModelServiceTest method testPackageDataModelOracle.
@Test
public void testPackageDataModelOracle() throws Exception {
final Bean dataModelServiceBean = (Bean) beanManager.getBeans(DataModelService.class).iterator().next();
final CreationalContext cc = beanManager.createCreationalContext(dataModelServiceBean);
final DataModelService dataModelService = (DataModelService) beanManager.getReference(dataModelServiceBean, DataModelService.class, cc);
final URL packageUrl = this.getClass().getResource("/DataModelBackendTest1/src/main/java/t3p1");
final org.uberfire.java.nio.file.Path nioPackagePath = fs.getPath(packageUrl.toURI());
final Path packagePath = paths.convert(nioPackagePath);
final PackageDataModelOracle packageLoader = dataModelService.getDataModel(packagePath);
// Emulate server-to-client conversions
final Caller<IncrementalDataModelService> service = new MockIncrementalDataModelServiceCaller(packageLoader);
final AsyncPackageDataModelOracle oracle = new AsyncPackageDataModelOracleImpl(service, validatorInstance);
final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
dataModel.setPackageName("t3p1");
dataModel.setModelFields(packageLoader.getModuleModelFields());
PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
assertNotNull(oracle);
assertEquals(3, oracle.getAllFactTypes().length);
assertContains("t3p1.Bean1", oracle.getAllFactTypes());
assertContains("t3p2.Bean2", oracle.getAllFactTypes());
assertContains("java.lang.String", oracle.getAllFactTypes());
assertEquals(1, oracle.getFactTypes().length);
assertContains("Bean1", oracle.getFactTypes());
oracle.getFieldCompletions("Bean1", new Callback<ModelField[]>() {
@Override
public void callback(final ModelField[] fields) {
assertEquals(3, fields.length);
assertContains("this", fields);
assertContains("field1", fields);
assertContains("field2", fields);
}
});
assertEquals(2, oracle.getExternalFactTypes().length);
assertContains("t3p2.Bean2", oracle.getExternalFactTypes());
assertContains("java.lang.String", oracle.getExternalFactTypes());
}
Aggregations