コード例 #1
0
  @Test
  public void testParametricMethod() throws Exception {
    final ProjectDataModelOracle projectLoader =
        ProjectDataModelOracleBuilder.newProjectOracleBuilder()
            .addClass(Purchase.class, new HashMap<String, FactBuilder>())
            .build();

    final PackageDataModelOracle packageLoader =
        PackageDataModelOracleBuilder.newPackageOracleBuilder(
                "org.kie.workbench.common.widgets.client.datamodel.testclasses")
            .setProjectOracle(projectLoader)
            .build();

    // Emulate server-to-client conversions
    final MockAsyncPackageDataModelOracleImpl oracle = new MockAsyncPackageDataModelOracleImpl();
    final Caller<IncrementalDataModelService> service =
        new MockIncrementalDataModelServiceCaller(packageLoader);
    oracle.setService(service);

    final PackageDataModelOracleBaselinePayload dataModel =
        new PackageDataModelOracleBaselinePayload();
    dataModel.setPackageName(packageLoader.getPackageName());
    dataModel.setModelFields(packageLoader.getProjectModelFields());
    dataModel.setFieldParametersType(packageLoader.getProjectFieldParametersType());
    PackageDataModelOracleTestUtils.populateDataModelOracle(
        mock(Path.class), new MockHasImports(), oracle, dataModel);

    assertNotNull(oracle);

    assertEquals(
        "Product", oracle.getParametricFieldType("Purchase", "customerPurchased(Integer)"));
  }
コード例 #2
0
  @Test
  public void testPackageDMOParametricReturnTypes() throws Exception {
    final Map<String, FactBuilder> discoveredFieldFactBuilders = new HashMap<String, FactBuilder>();
    final ProjectDataModelOracle projectLoader =
        ProjectDataModelOracleBuilder.newProjectOracleBuilder()
            .addClass(Purchase.class, discoveredFieldFactBuilders)
            .addClass(Product.class, discoveredFieldFactBuilders)
            .build();

    final PackageDataModelOracle packageLoader =
        PackageDataModelOracleBuilder.newPackageOracleBuilder(
                "org.kie.workbench.common.widgets.client.datamodel.testclasses")
            .setProjectOracle(projectLoader)
            .build();

    // Emulate server-to-client conversions
    final MockAsyncPackageDataModelOracleImpl oracle = new MockAsyncPackageDataModelOracleImpl();
    final Caller<IncrementalDataModelService> service =
        new MockIncrementalDataModelServiceCaller(packageLoader);
    oracle.setService(service);

    final PackageDataModelOracleBaselinePayload dataModel =
        new PackageDataModelOracleBaselinePayload();
    dataModel.setPackageName(packageLoader.getPackageName());
    dataModel.setModelFields(packageLoader.getProjectModelFields());
    dataModel.setFieldParametersType(packageLoader.getProjectFieldParametersType());
    PackageDataModelOracleTestUtils.populateDataModelOracle(
        mock(Path.class), new MockHasImports(), oracle, dataModel);

    assertNotNull(oracle);

    assertEquals(3, oracle.getFactTypes().length);

    List<String> list = Arrays.asList(oracle.getFactTypes());

    assertTrue(list.contains("Purchase"));
    assertTrue(list.contains("Product"));

    assertEquals("java.util.Collection", oracle.getFieldClassName("Purchase", "items"));
    assertEquals(DataType.TYPE_COLLECTION, oracle.getFieldType("Purchase", "items"));
    assertEquals("Product", oracle.getParametricFieldType("Purchase", "items"));
  }