/**
   * Initialize the Kettle environment with settings from the provided configuration
   *
   * @param conf Configuration to configure Kettle environment with
   */
  private static void initKettleEnvironment(Configuration conf) throws KettleException {
    if (!KettleEnvironment.isInitialized()) {
      String kettleHome = getKettleHomeProperty(conf);
      String pluginDir = getPluginDirProperty(conf);
      System.setProperty("KETTLE_HOME", kettleHome);
      System.setProperty(Const.PLUGIN_BASE_FOLDERS_PROP, pluginDir);

      System.out.println(BaseMessages.getString(MRUtil.class, "KettleHome.Info", kettleHome));
      System.out.println(BaseMessages.getString(MRUtil.class, "PluginDirectory.Info", pluginDir));

      KettleEnvironment.init();
    }
  }
Ejemplo n.º 2
0
  public void test02_SelectFrom() throws Exception {
    KettleEnvironment.init();

    String sqlQuery =
        "SELECT Category, Country, products_sold as nr, sales_amount as sales FROM Service";

    SqlTransExecutor executor = new SqlTransExecutor(sqlQuery, getServices());

    final List<RowMetaAndData> rows = new ArrayList<RowMetaAndData>();

    // print the eventual result rows...
    //
    executor.executeQuery(
        new RowAdapter() {
          @Override
          public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row)
              throws KettleStepException {
            rows.add(new RowMetaAndData(rowMeta, row));
          }
        });

    // Now the generated transformation is waiting for input so we
    // can start the service transformation
    //
    executor.waitUntilFinished();

    assertEquals(8, rows.size());
  }
Ejemplo n.º 3
0
  /** Test case for injector step... also a show case on how to use injector. */
  public void testInjector() throws Exception {
    KettleEnvironment.init();

    //
    // Create a new transformation...
    //
    TransMeta transMeta = new TransMeta();
    transMeta.setName("injectortest");

    PluginRegistry registry = PluginRegistry.getInstance();

    //
    // create an injector step...
    //
    String injectorStepname = "injector step";
    InjectorMeta im = new InjectorMeta();

    // Set the information of the injector.

    String injectorPid = registry.getPluginId(StepPluginType.class, im);
    StepMeta injectorStep = new StepMeta(injectorPid, injectorStepname, (StepMetaInterface) im);
    transMeta.addStep(injectorStep);

    //
    // Create a dummy step
    //
    String dummyStepname = "dummy step";
    DummyTransMeta dm = new DummyTransMeta();

    String dummyPid = registry.getPluginId(StepPluginType.class, dm);
    StepMeta dummyStep = new StepMeta(dummyPid, dummyStepname, (StepMetaInterface) dm);
    transMeta.addStep(dummyStep);

    TransHopMeta hi = new TransHopMeta(injectorStep, dummyStep);
    transMeta.addTransHop(hi);

    // Now execute the transformation...
    Trans trans = new Trans(transMeta);

    trans.prepareExecution(null);

    StepInterface si = trans.getStepInterface(dummyStepname, 0);
    RowStepCollector rc = new RowStepCollector();
    si.addRowListener(rc);

    RowProducer rp = trans.addRowProducer(injectorStepname, 0);
    trans.startThreads();

    // add rows
    List<RowMetaAndData> inputList = createData();
    for (RowMetaAndData rm : inputList) {
      rp.putRow(rm.getRowMeta(), rm.getData());
    }
    rp.finished();

    trans.waitUntilFinished();

    List<RowMetaAndData> resultRows = rc.getRowsWritten();
    checkRows(resultRows, inputList);
  }
Ejemplo n.º 4
0
  public void test06_SelectFromGroupByOrderBy() throws Exception {
    KettleEnvironment.init();

    String sqlQuery =
        "SELECT Country, SUM(products_sold) as count, SUM(sales_amount) as sales FROM Service GROUP BY Country ORDER BY SUM(sales_amount) DESC";

    SqlTransExecutor executor = new SqlTransExecutor(sqlQuery, getServices());

    final List<RowMetaAndData> rows = new ArrayList<RowMetaAndData>();

    // collect the eventual result rows...
    //
    executor.executeQuery(
        new RowAdapter() {
          @Override
          public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row)
              throws KettleStepException {
            rows.add(new RowMetaAndData(rowMeta, row));
          }
        });

    // Now the generated transformation is waiting for input so we
    // can start the service transformation
    //
    executor.waitUntilFinished();

    assertEquals(4, rows.size());

    // Validate results...
    //
    int rowNr = 0;
    assertEquals("Germany", rows.get(rowNr).getString("Country", null));
    assertEquals(76, rows.get(rowNr).getInteger("count", -1));
    assertEquals(12697, Math.round(rows.get(rowNr).getNumber("sales", -1.0)));

    rowNr++;
    assertEquals("Great Britain", rows.get(rowNr).getString("Country", null));
    assertEquals(18, rows.get(rowNr).getInteger("count", -1));
    assertEquals(11657, Math.round(rows.get(rowNr).getNumber("sales", -1.0)));

    rowNr++;
    assertEquals("France", rows.get(rowNr).getString("Country", null));
    assertEquals(24, rows.get(rowNr).getInteger("count", -1));
    assertEquals(2021, Math.round(rows.get(rowNr).getNumber("sales", -1.0)));

    rowNr++;
    assertEquals("Belgium", rows.get(rowNr).getString("Country", null));
    assertEquals(10, rows.get(rowNr).getInteger("count", -1));
    assertEquals(780, Math.round(rows.get(rowNr).getNumber("sales", -1.0)));
  }
Ejemplo n.º 5
0
  public void test10_SelectFromGroupSumAlias() throws Exception {
    KettleEnvironment.init();

    String sqlQuery =
        "SELECT   Category, SUM(sales_amount) as \"Sales\"\nFROM     Service\nGROUP BY Category\nORDER BY SUM(sales_amount) DESC";

    SqlTransExecutor executor = new SqlTransExecutor(sqlQuery, getServices());

    final List<RowMetaAndData> rows = new ArrayList<RowMetaAndData>();

    // collect the eventual result rows...
    //
    executor.executeQuery(
        new RowAdapter() {
          @Override
          public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row)
              throws KettleStepException {
            rows.add(new RowMetaAndData(rowMeta, row));
          }
        });

    // Save to temp file for checking
    //
    File file = new File("/tmp/gen.ktr");
    FileOutputStream fos = new FileOutputStream(file);
    fos.write(org.pentaho.di.core.xml.XMLHandler.getXMLHeader().getBytes("UTF-8"));
    fos.write(executor.getGenTransMeta().getXML().getBytes("UTF-8"));
    fos.close();

    // Now the generated transformation is waiting for input so we
    // can start the service transformation
    //
    executor.waitUntilFinished();

    assertEquals(2, rows.size());

    // Validate results...
    //
    int rowNr = 0;
    assertEquals("A", rows.get(rowNr).getString("Category", null));
    assertEquals(19013, Math.round(rows.get(rowNr).getNumber("Sales", -1.0)));

    rowNr++;
    assertEquals("B", rows.get(rowNr).getString("Category", null));
    assertEquals(8142, Math.round(rows.get(rowNr).getNumber("Sales", -1.0)));
  }
Ejemplo n.º 6
0
  public void test09_SelectFromGroupMaxHaving() throws Exception {
    KettleEnvironment.init();

    String sqlQuery =
        "SELECT Country, MAX(products_sold) max_count FROM Service GROUP BY Country HAVING MAX(products_sold) > 10 ORDER BY max_count DESC";

    SqlTransExecutor executor = new SqlTransExecutor(sqlQuery, getServices());

    final List<RowMetaAndData> rows = new ArrayList<RowMetaAndData>();

    // collect the eventual result rows...
    //
    executor.executeQuery(
        new RowAdapter() {
          @Override
          public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row)
              throws KettleStepException {
            rows.add(new RowMetaAndData(rowMeta, row));
          }
        });

    // Save to temp file for checking
    //
    File file = new File("/tmp/gen.ktr");
    FileOutputStream fos = new FileOutputStream(file);
    fos.write(org.pentaho.di.core.xml.XMLHandler.getXMLHeader().getBytes("UTF-8"));
    fos.write(executor.getGenTransMeta().getXML().getBytes("UTF-8"));
    fos.close();

    // Now the generated transformation is waiting for input so we
    // can start the service transformation
    //
    executor.waitUntilFinished();

    assertEquals(2, rows.size());

    // Validate results...
    //
    int rowNr = 0;
    assertEquals("Germany", rows.get(rowNr).getString("Country", null));
    assertEquals(38, Math.round(rows.get(rowNr).getNumber("max_count", -1.0)));

    rowNr++;
    assertEquals("France", rows.get(rowNr).getString("Country", null));
    assertEquals(12, Math.round(rows.get(rowNr).getNumber("max_count", -1.0)));
  }
  @Before
  public void setUpLoadSave() throws Exception {
    KettleEnvironment.init();
    PluginRegistry.init(true);
    List<String> attributes =
        Arrays.asList(
            "inputSorted",
            "memoryPreservationActive",
            "usingSortedList",
            "usingIntegerPair",
            "keystream",
            "keylookup",
            "value",
            "valueName",
            "valueDefault",
            "valueDefaultType");

    FieldLoadSaveValidator<String[]> stringArrayLoadSaveValidator =
        new ArrayLoadSaveValidator<String>(new StringLoadSaveValidator(), 5);

    Map<String, FieldLoadSaveValidator<?>> attrValidatorMap =
        new HashMap<String, FieldLoadSaveValidator<?>>();
    attrValidatorMap.put("keystream", stringArrayLoadSaveValidator);
    attrValidatorMap.put("keylookup", stringArrayLoadSaveValidator);
    attrValidatorMap.put("value", stringArrayLoadSaveValidator);
    attrValidatorMap.put("valueName", stringArrayLoadSaveValidator);
    attrValidatorMap.put("valueDefault", stringArrayLoadSaveValidator);
    attrValidatorMap.put(
        "valueDefaultType", new PrimitiveIntArrayLoadSaveValidator(new IntLoadSaveValidator(7), 5));

    Map<String, FieldLoadSaveValidator<?>> typeValidatorMap =
        new HashMap<String, FieldLoadSaveValidator<?>>();

    loadSaveTester =
        new LoadSaveTester(
            testMetaClass,
            attributes,
            new ArrayList<String>(),
            new ArrayList<String>(),
            new HashMap<String, String>(),
            new HashMap<String, String>(),
            attrValidatorMap,
            typeValidatorMap,
            this);
  }
  @Before
  public void setUpLoadSave() throws Exception {
    KettleEnvironment.init();
    PluginRegistry.init(true);
    List<String> attributes =
        Arrays.asList(
            "transName",
            "fileName",
            "directoryPath",
            "allowingMultipleInputs",
            "allowingMultipleOutputs",
            "specificationMethod",
            "transObjectId",
            "inputMappings",
            "outputMappings",
            "mappingParameters");

    Map<String, FieldLoadSaveValidator<?>> attrValidatorMap =
        new HashMap<String, FieldLoadSaveValidator<?>>();
    attrValidatorMap.put(
        "specificationMethod", new ObjectLocationSpecificationMethodLoadSaveValidator());
    attrValidatorMap.put("transObjectId", new ObjectIdLoadSaveValidator());
    attrValidatorMap.put(
        "inputMappings",
        new ListLoadSaveValidator<MappingIODefinition>(
            new MappingIODefinitionLoadSaveValidator(), 5));
    attrValidatorMap.put(
        "outputMappings",
        new ListLoadSaveValidator<MappingIODefinition>(
            new MappingIODefinitionLoadSaveValidator(), 5));
    attrValidatorMap.put("mappingParameters", new MappingParametersLoadSaveValidator());

    Map<String, FieldLoadSaveValidator<?>> typeValidatorMap =
        new HashMap<String, FieldLoadSaveValidator<?>>();

    loadSaveTester =
        new LoadSaveTester(
            testMetaClass,
            attributes,
            new HashMap<String, String>(),
            new HashMap<String, String>(),
            attrValidatorMap,
            typeValidatorMap);
  }
  public static synchronized void initializePentahoSystem(String solutionPath) throws Exception {

    // this setting is useful only for running the integration tests from within IntelliJ
    // this same property is set for integration tests via the pom when running with mvn
    String folderPaths = "target/spoon/plugins";
    File f = new File(folderPaths);
    System.setProperty("KETTLE_PLUGIN_BASE_FOLDERS", f.getAbsolutePath());

    StandaloneApplicationContext appContext = new StandaloneApplicationContext(solutionPath, "");
    PentahoSystem.setSystemSettingsService(new PathBasedSystemSettings());
    if (solutionPath == null) {
      throw new MetaverseException(
          Messages.getString("ERROR.MetaverseInit.BadConfigPath", solutionPath));
    }

    try {
      ClassLoader cl = Thread.currentThread().getContextClassLoader();

      Thread.currentThread().setContextClassLoader(MetaverseUtil.class.getClassLoader());
      IPentahoObjectFactory pentahoObjectFactory = new StandaloneSpringPentahoObjectFactory();
      pentahoObjectFactory.init(solutionPath, PentahoSystem.getApplicationContext());
      PentahoSystem.registerObjectFactory(pentahoObjectFactory);

      // Restore context classloader
      Thread.currentThread().setContextClassLoader(cl);
    } catch (Exception e) {
      throw new MetaverseException(Messages.getString("ERROR.MetaverseInit.CouldNotInit"), e);
    }
    PentahoSystem.init(appContext);
    PentahoSessionHolder.setSession(new StandaloneSession());

    registerKettlePlugins();

    try {
      KettleEnvironment.init();
    } catch (KettleException e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 10
0
  public void test07_SelectFromGroupCountDistinct() throws Exception {
    KettleEnvironment.init();

    String sqlQuery =
        "SELECT Category, COUNT(DISTINCT Country) as \"Number of countries\" FROM Service GROUP BY Category ORDER BY COUNT(DISTINCT Country) DESC";

    SqlTransExecutor executor = new SqlTransExecutor(sqlQuery, getServices());

    final List<RowMetaAndData> rows = new ArrayList<RowMetaAndData>();

    // collect the eventual result rows...
    //
    executor.executeQuery(
        new RowAdapter() {
          @Override
          public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row)
              throws KettleStepException {
            rows.add(new RowMetaAndData(rowMeta, row));
          }
        });

    // Now the generated transformation is waiting for input so we
    // can start the service transformation
    //
    executor.waitUntilFinished();

    assertEquals(2, rows.size());

    // Validate results...
    //
    int rowNr = 0;
    assertEquals("A", rows.get(rowNr).getString("Category", null));
    assertEquals(4, rows.get(rowNr).getInteger("Number of countries", -1));

    rowNr++;
    assertEquals("B", rows.get(rowNr).getString("Category", null));
    assertEquals(4, rows.get(rowNr).getInteger("Number of countries", -1));
  }
Ejemplo n.º 11
0
  public void test03_SelectFromWhere() throws Exception {
    KettleEnvironment.init();

    String sqlQuery =
        "SELECT Category, Country, products_sold as nr, sales_amount as sales FROM Service WHERE Category = 'A'";

    SqlTransExecutor executor = new SqlTransExecutor(sqlQuery, getServices());

    final List<RowMetaAndData> rows = new ArrayList<RowMetaAndData>();

    // print the eventual result rows...
    //
    executor.executeQuery(
        new RowAdapter() {
          @Override
          public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row)
              throws KettleStepException {
            rows.add(new RowMetaAndData(rowMeta, row));
          }
        });

    // Now the generated transformation is waiting for input so we
    // can start the service transformation
    //
    executor.waitUntilFinished();

    // Save to temp file for checking
    //
    File file = new File("/tmp/gen.ktr");
    FileOutputStream fos = new FileOutputStream(file);
    fos.write(org.pentaho.di.core.xml.XMLHandler.getXMLHeader().getBytes("UTF-8"));
    fos.write(executor.getGenTransMeta().getXML().getBytes("UTF-8"));
    fos.close();

    assertEquals(4, rows.size());
  }
Ejemplo n.º 12
0
  public void test13_DistinctOrderFromPMD() throws Exception {
    KettleEnvironment.init();

    String sqlQuery =
        "SELECT DISTINCT            BT_SERVICE_SERVICE.Category AS COL0          ,BT_SERVICE_SERVICE.Country AS COL1 FROM            Service BT_SERVICE_SERVICE ORDER BY            COL0";

    SqlTransExecutor executor = new SqlTransExecutor(sqlQuery, getServices());

    final List<RowMetaAndData> rows = new ArrayList<RowMetaAndData>();

    // collect the eventual result rows...
    //
    executor.executeQuery(
        new RowAdapter() {
          @Override
          public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row)
              throws KettleStepException {
            rows.add(new RowMetaAndData(rowMeta, row));
          }
        });

    // Save to temp file for checking
    //
    File file = new File("/tmp/gen.ktr");
    FileOutputStream fos = new FileOutputStream(file);
    fos.write(org.pentaho.di.core.xml.XMLHandler.getXMLHeader().getBytes("UTF-8"));
    fos.write(executor.getGenTransMeta().getXML().getBytes("UTF-8"));
    fos.close();

    // Now the generated transformation is waiting for input so we
    // can start the service transformation
    //
    executor.waitUntilFinished();

    assertEquals(8, rows.size());
  }
Ejemplo n.º 13
0
  public void test11_NotSelectedHaving() throws Exception {
    KettleEnvironment.init();

    String sqlQuery =
        "select \"Service\".\"Category\" as \"c0\", \"Service\".\"Country\" as \"c1\" from \"Service\" as \"Service\" where (\"Service\".\"Category\" = 'A') group by \"Service\".\"Category\", \"Service\".\"Country\" having (NOT((sum(\"Service\".\"sales_amount\") is null)) OR NOT((sum(\"Service\".\"products_sold\") is null)) ) order by CASE WHEN \"Service\".\"Category\" IS NULL THEN 1 ELSE 0 END, \"Service\".\"Category\" ASC, CASE WHEN \"Service\".\"Country\" IS NULL THEN 1 ELSE 0 END";

    SqlTransExecutor executor = new SqlTransExecutor(sqlQuery, getServices());

    final List<RowMetaAndData> rows = new ArrayList<RowMetaAndData>();

    // collect the eventual result rows...
    //
    executor.executeQuery(
        new RowAdapter() {
          @Override
          public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row)
              throws KettleStepException {
            rows.add(new RowMetaAndData(rowMeta, row));
          }
        });

    // Save to temp file for checking
    //
    File file = new File("/tmp/gen.ktr");
    FileOutputStream fos = new FileOutputStream(file);
    fos.write(org.pentaho.di.core.xml.XMLHandler.getXMLHeader().getBytes("UTF-8"));
    fos.write(executor.getGenTransMeta().getXML().getBytes("UTF-8"));
    fos.close();

    // Now the generated transformation is waiting for input so we
    // can start the service transformation
    //
    executor.waitUntilFinished();

    assertEquals(4, rows.size());
  }
Ejemplo n.º 14
0
  /** Test case for Constant step. Row generator attached to a constant step. */
  public void testConstant1() throws Exception {
    KettleEnvironment.init();

    //
    // Create a new transformation...
    //
    TransMeta transMeta = new TransMeta();
    transMeta.setName("constanttest1");

    PluginRegistry registry = PluginRegistry.getInstance();

    //
    // create a row generator step...
    //
    String rowGeneratorStepname = "row generator step";
    RowGeneratorMeta rm = new RowGeneratorMeta();

    // Set the information of the row generator.
    String rowGeneratorPid = registry.getPluginId(StepPluginType.class, rm);
    StepMeta rowGeneratorStep =
        new StepMeta(rowGeneratorPid, rowGeneratorStepname, (StepMetaInterface) rm);
    transMeta.addStep(rowGeneratorStep);

    //
    // Generate 1 empty row
    //
    String fieldName[] = {};
    String type[] = {};
    String value[] = {};
    String fieldFormat[] = {};
    String group[] = {};
    String decimal[] = {};
    int intDummies[] = {};

    rm.setDefault();
    rm.setFieldName(fieldName);
    rm.setFieldType(type);
    rm.setValue(value);
    rm.setFieldLength(intDummies);
    rm.setFieldPrecision(intDummies);
    rm.setRowLimit("1");
    rm.setFieldFormat(fieldFormat);
    rm.setGroup(group);
    rm.setDecimal(decimal);

    //
    // Add constant step.
    //
    String constStepname1 = "constant 1";
    ConstantMeta cnst1 = new ConstantMeta();

    String fieldName1[] = {
      "boolean1",
      "boolean2",
      "boolean3",
      "boolean4",
      "boolean5",
      "boolean6",
      "boolean7",
      "string1",
      "string2",
      "string3",
      "integer1",
      "integer2",
      "integer3",
      "integer4",
      "number1",
      "number2",
      "number3",
      "number4",
    };
    String type1[] = {
      "boolean", "Boolean", "bOOLEAN", "BOOLEAN", "boolean", "boolean", "boolean", "string",
      "string", "String", "integer", "integer", "integer", "integer", "number", "number", "number",
      "number"
    };
    String value1[] = {
      "Y",
      "T",
      "a",
      "TRUE",
      "0",
      "9",
      "",
      "AAAAAAAAAAAAAA",
      "   ",
      "",
      "-100",
      "0",
      "212",
      "",
      "-100.2",
      "0.0",
      "212.23",
      ""
    };
    String fieldFormat1[] = {
      "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""
    };
    String group1[] = {"", "", "", "", "", "", "", "", "", "", "", "", "", "", ",", ",", ",", ","};
    String decimal1[] = {
      "", "", "", "", "", "", "", "", "", "", "", "", "", "", ".", ".", ".", "."
    };
    String currency[] = {"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""};
    int intDummies1[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

    cnst1.setFieldName(fieldName1);
    cnst1.setFieldType(type1);
    cnst1.setValue(value1);
    cnst1.setFieldLength(intDummies1);
    cnst1.setFieldPrecision(intDummies1);
    cnst1.setFieldFormat(fieldFormat1);
    cnst1.setGroup(group1);
    cnst1.setDecimal(decimal1);
    cnst1.setCurrency(currency);

    String addSeqPid1 = registry.getPluginId(StepPluginType.class, cnst1);
    StepMeta addSeqStep1 = new StepMeta(addSeqPid1, constStepname1, (StepMetaInterface) cnst1);
    transMeta.addStep(addSeqStep1);

    TransHopMeta hi1 = new TransHopMeta(rowGeneratorStep, addSeqStep1);
    transMeta.addTransHop(hi1);

    // Now execute the transformation...
    Trans trans = new Trans(transMeta);

    trans.prepareExecution(null);

    StepInterface si = trans.getStepInterface(constStepname1, 0);
    RowStepCollector endRc = new RowStepCollector();
    si.addRowListener(endRc);

    trans.startThreads();

    trans.waitUntilFinished();

    // Now check whether the output is still as we expect.
    List<RowMetaAndData> goldenImageRows = createResultData1();
    List<RowMetaAndData> resultRows1 = endRc.getRowsWritten();
    checkRows(resultRows1, goldenImageRows);
  }
Ejemplo n.º 15
0
  public void testCalculator1() throws Exception {
    KettleEnvironment.init();

    PluginRegistry registry = PluginRegistry.getInstance();
    //
    // Create a new transformation...
    //
    TransMeta transMeta = new TransMeta();
    transMeta.setName("calculatortest1");

    //
    // create a row generator step...
    //
    String rowGeneratorStepname = "row generator step";
    RowGeneratorMeta rm = new RowGeneratorMeta();

    // Set the information of the row generator.
    String rowGeneratorPid = registry.getPluginId(StepPluginType.class, rm);
    StepMeta rowGeneratorStep = new StepMeta(rowGeneratorPid, rowGeneratorStepname, rm);
    transMeta.addStep(rowGeneratorStep);

    //
    // Generate 1 empty row
    //
    String[] strDummies = {};
    int[] intDummies = {};

    rm.setDefault();
    rm.setFieldName(strDummies);
    rm.setFieldType(strDummies);
    rm.setValue(strDummies);
    rm.setFieldLength(intDummies);
    rm.setFieldPrecision(intDummies);
    rm.setRowLimit("1");
    rm.setFieldFormat(strDummies);
    rm.setGroup(strDummies);
    rm.setDecimal(strDummies);

    //
    // Add calculator step.
    //
    String calculatorStepname1 = "calculator 1";
    CalculatorMeta calc1 = new CalculatorMeta();

    CalculatorMetaFunction[] calculations =
        new CalculatorMetaFunction[] {
          new CalculatorMetaFunction(
              "timestamp1", // fieldName
              CalculatorMetaFunction.CALC_CONSTANT, // calctype
              "1970-01-01 00:00:00.100100", // fieldA
              "", // String fieldB
              "", // String fieldC
              ValueMetaInterface.TYPE_TIMESTAMP, // valueType,
              0, // int valueLength,
              0, // int valuePrecision,
              false, // boolean removedFromResult,
              "", // String conversionMask,
              "", // String decimalSymbol,
              "", // String groupingSymbol,
              "" // String currencySymbol
              ),
          new CalculatorMetaFunction(
              "int1", // fieldName
              CalculatorMetaFunction.CALC_CONSTANT, // calctype
              "1", // fieldA
              "", // String fieldB
              "", // String fieldC
              ValueMetaInterface.TYPE_INTEGER, // valueType,
              0, // int valueLength,
              0, // int valuePrecision,
              false, // boolean removedFromResult,
              "", // String conversionMask,
              "", // String decimalSymbol,
              "", // String groupingSymbol,
              "" // String currencySymbol
              ),
          new CalculatorMetaFunction(
              "timestamp plus 1 day", // fieldName
              CalculatorMetaFunction.CALC_ADD_DAYS, // calctype
              "timestamp1", // fieldA
              "int1", // String fieldB
              "", // String fieldC
              ValueMetaInterface.TYPE_DATE, // valueType,
              0, // int valueLength,
              0, // int valuePrecision,
              false, // boolean removedFromResult,
              "", // String conversionMask,
              "", // String decimalSymbol,
              "", // String groupingSymbol,
              "" // String currencySymbol
              )
        };
    calc1.setCalculation(calculations);
    //
    String calculatorPid1 = registry.getPluginId(StepPluginType.class, calc1);
    StepMeta calcualtorStep1 = new StepMeta(calculatorPid1, calculatorStepname1, calc1);
    transMeta.addStep(calcualtorStep1);

    //
    TransHopMeta hi1 = new TransHopMeta(rowGeneratorStep, calcualtorStep1);
    transMeta.addTransHop(hi1);

    // Now execute the transformation...
    Trans trans = new Trans(transMeta);

    trans.prepareExecution(null);

    StepInterface si = trans.getStepInterface(calculatorStepname1, 0);
    RowStepCollector endRc = new RowStepCollector();
    si.addRowListener(endRc);

    trans.startThreads();
    trans.waitUntilFinished();

    // Now check whether the output is still as we expect.
    List<RowMetaAndData> goldenImageRows = createResultData1();
    List<RowMetaAndData> resultRows1 = endRc.getRowsWritten();
    checkRows(resultRows1, goldenImageRows);
  }
 @BeforeClass
 public static void setupClass() throws KettleException {
   KettleEnvironment.init();
 }
  @Test
  public void testMondrianImportExport() throws Exception {
    final String domainName = "SalesData";
    List<MimeType> mimeTypeList = new ArrayList<MimeType>();
    mimeTypeList.add(new MimeType("Mondrian", "mondrian.xml"));
    System.setProperty(
        "org.osjava.sj.root", "test-res/solution1/system/simple-jndi"); // $NON-NLS-1$ //$NON-NLS-2$

    File mondrian = new File("test-res/dsw/testData/SalesData.mondrian.xml");
    RepositoryFile repoMondrianFile =
        new RepositoryFile.Builder(mondrian.getName()).folder(false).hidden(false).build();
    RepositoryFileImportBundle bundle1 =
        new RepositoryFileImportBundle.Builder()
            .file(repoMondrianFile)
            .charSet("UTF-8")
            .input(new FileInputStream(mondrian))
            .mime("mondrian.xml")
            .withParam("parameters", "Datasource=Pentaho;overwrite=true")
            .withParam("domain-id", "SalesData")
            .build();
    MondrianImportHandler mondrianImportHandler =
        new MondrianImportHandler(mimeTypeList, PentahoSystem.get(IMondrianCatalogService.class));
    mondrianImportHandler.importFile(bundle1);

    try {
      KettleEnvironment.init();
      Props.init(Props.TYPE_PROPERTIES_EMPTY);
    } catch (Exception e) {
      // may already be initialized by another test
    }

    Domain domain = generateModel();

    ModelerWorkspace model = new ModelerWorkspace(new GwtModelerWorkspaceHelper());
    model.setModelName("ORDERS");
    model.setDomain(domain);
    model.getWorkspaceHelper().populateDomain(model);

    new ModelerService().serializeModels(domain, domainName);

    final Response salesData =
        new DatasourceResource().doGetDSWFilesAsDownload(domainName + ".xmi");
    Assert.assertEquals(salesData.getStatus(), Response.Status.OK.getStatusCode());
    Assert.assertNotNull(salesData.getMetadata());
    Assert.assertNotNull(salesData.getMetadata().getFirst("Content-Disposition"));
    Assert.assertEquals(
        salesData.getMetadata().getFirst("Content-Disposition").getClass(), String.class);
    Assert.assertTrue(
        ((String) salesData.getMetadata().getFirst("Content-Disposition"))
            .endsWith(domainName + ".zip\""));

    File file = File.createTempFile(domainName, ".zip");
    final FileOutputStream fileOutputStream = new FileOutputStream(file);
    ((StreamingOutput) salesData.getEntity()).write(fileOutputStream);
    fileOutputStream.close();

    final ZipFile zipFile = new ZipFile(file);
    final Enumeration<? extends ZipEntry> entries = zipFile.entries();
    while (entries.hasMoreElements()) {
      final ZipEntry zipEntry = entries.nextElement();
      Assert.assertTrue(
          zipEntry.getName().equals(domainName + ".xmi")
              || zipEntry.getName().equals(domainName + ".mondrian.xml"));
    }
    zipFile.close();
    file.delete();
  }
Ejemplo n.º 18
0
  /** Test case for janino step. */
  public void testJaninoStep() throws Exception {
    KettleEnvironment.init();

    //
    // Create a new transformation...
    //
    TransMeta transMeta = new TransMeta();
    transMeta.setName("janino test");

    PluginRegistry registry = PluginRegistry.getInstance();

    // create an injector step...
    String injectorStepName = "injector step";
    InjectorMeta im = new InjectorMeta();

    // Set the information of the injector.
    String injectorPid = registry.getPluginId(StepPluginType.class, im);
    StepMeta injectorStep = new StepMeta(injectorPid, injectorStepName, im);
    transMeta.addStep(injectorStep);

    //
    // create a janino step...
    //
    String stepname = "janino";
    JaninoMeta jm = new JaninoMeta();

    // Set the information of the step
    String janinoPid = registry.getPluginId(StepPluginType.class, jm);
    StepMeta janinoStep = new StepMeta(janinoPid, stepname, jm);
    transMeta.addStep(janinoStep);

    jm.setDefault();

    JaninoMetaFunction[] formulas = {
      new JaninoMetaFunction(
          "string",
          "(string==null)?null:\"string-value\"",
          ValueMeta.TYPE_STRING,
          -1,
          -1,
          "string"),
      new JaninoMetaFunction(
          "integer",
          "(integer==null)?null:new Long(42L)",
          ValueMeta.TYPE_INTEGER,
          -1,
          -1,
          "integer"),
      new JaninoMetaFunction(
          "number",
          "(number==null)?null:new Double(23.0)",
          ValueMeta.TYPE_NUMBER,
          -1,
          -1,
          "number"),
      new JaninoMetaFunction(
          "bigdecimal",
          "(bigdecimal==null)?null:new java.math.BigDecimal(11.0)",
          ValueMeta.TYPE_BIGNUMBER,
          -1,
          -1,
          "bigdecimal"),
      new JaninoMetaFunction(
          "date",
          "(date==null)?null:new java.util.Date(10000000)",
          ValueMeta.TYPE_DATE,
          -1,
          -1,
          "date"),
      new JaninoMetaFunction(
          "binary",
          "(binary==null)?null:new byte[]{1,2,3,4,5}",
          ValueMeta.TYPE_BINARY,
          -1,
          -1,
          "binary"),
      new JaninoMetaFunction(
          "bool", "(bool==null)?null:Boolean.TRUE", ValueMeta.TYPE_BOOLEAN, -1, -1, "bool"),
    };

    jm.setFormula(formulas);

    transMeta.addTransHop(new TransHopMeta(injectorStep, janinoStep));

    //
    // Create a dummy step
    //
    String dummyStepname = "dummy step";
    DummyTransMeta dm = new DummyTransMeta();

    String dummyPid = registry.getPluginId(StepPluginType.class, dm);
    StepMeta dummyStep = new StepMeta(dummyPid, dummyStepname, dm);
    transMeta.addStep(dummyStep);

    TransHopMeta hi = new TransHopMeta(janinoStep, dummyStep);
    transMeta.addTransHop(hi);

    // Now execute the transformation...
    Trans trans = new Trans(transMeta);

    trans.prepareExecution(null);

    StepInterface si = trans.getStepInterface(dummyStepname, 0);
    RowStepCollector rc = new RowStepCollector();
    si.addRowListener(rc);
    RowProducer rp = trans.addRowProducer(injectorStepName, 0);

    trans.startThreads();

    for (RowMetaAndData rm : createInputList()) {
      rp.putRow(rm.getRowMeta(), rm.getData());
    }
    rp.finished();

    trans.waitUntilFinished();

    List<RowMetaAndData> checkList = createExpectedList();
    List<RowMetaAndData> resultRows = rc.getRowsWritten();
    checkRows(resultRows, checkList);
  }
 @Override
 protected void setUp() throws Exception {
   KettleEnvironment.init();
 }
  @Test
  public void testSyncWebService() throws Exception {

    // first init kettle

    KettleEnvironment.init(false);
    BasePropertyHandler.getInstance().notify(new TestPropertyHandler());
    File f = new File(Const.getKettleDirectory());
    f.mkdirs();

    // second init platform
    PentahoSystem.registerObjectFactory(new SimpleObjectFactory());
    PentahoSystem.init(new TestAppContext(), null);
    PentahoSystem.setSystemSettingsService(
        new ISystemSettings() {
          public String getSystemCfgSourceName() {
            return null;
          }

          public String getSystemSetting(String arg0, String arg1) {
            if ("singleDiServerInstance".equals(arg0)) {
              return "false";
            }
            return arg1;
          }

          public String getSystemSetting(String arg0, String arg1, String arg2) {
            return null;
          }

          public List getSystemSettings(String arg0) {
            return null;
          }

          public List getSystemSettings(String arg0, String arg1) {
            return null;
          }

          public Document getSystemSettingsDocument(String arg0) {
            return null;
          }

          public Properties getSystemSettingsProperties(String arg0) {
            return null;
          }

          public void resetSettingsCache() {}
        });

    // now test the webservice
    IRepositorySyncWebService webservice = getRepositorySyncWebService();

    // first without the plugin available
    try {
      webservice.sync("test id", "http://localhost:8080/pentaho-di");
      Assert.fail();
    } catch (RepositorySyncException e) {
      Assert.assertTrue(
          e.getMessage().indexOf("unable to load the PentahoEnterpriseRepository plugin") >= 0);
    }

    // second with plugin but not registered
    RepositoryPluginType.getInstance()
        .registerCustom(
            TestRepositoryMeta.class,
            "PentahoEnterpriseRepository",
            "PentahoEnterpriseRepository",
            "PentahoEnterpriseRepository",
            "PentahoEnterpriseRepository",
            "");
    PluginRegistry.getInstance()
        .getPlugin(RepositoryPluginType.class, "PentahoEnterpriseRepository")
        .getClassMap()
        .put(
            RepositoryMeta.class,
            "com.pentaho.pdi.ws.RepositorySyncWebServiceTest$TestRepositoryMeta");

    RepositorySyncStatus status = webservice.sync("test id", "http://localhost:8080/pentaho-di");

    Assert.assertEquals(RepositorySyncStatus.REGISTERED, status);

    // third after already registered
    status = webservice.sync("test id", "http://localhost:8080/pentaho-di");

    Assert.assertEquals(RepositorySyncStatus.ALREADY_REGISTERED, status);

    // forth test with different url
    try {
      webservice.sync("test id", "http://localhost:9090/pentaho-di");
      Assert.fail();
    } catch (RepositorySyncException e) {
      Assert.assertTrue(e.getMessage().indexOf("with the URL:") >= 0);
    }

    // fifth test different base-url
    fullyQualifiedServerUrl = "http://localhost:9090/pentaho-di";
    try {
      webservice.sync("test id", "http://localhost:8080/pentaho-di");
      Assert.fail();
    } catch (RepositorySyncException e) {
      Assert.assertTrue(e.getMessage().indexOf("fully qualified server url") >= 0);
    }
  }
 @BeforeClass
 public static void init() throws KettleException {
   KettleEnvironment.init(false);
 }
 public TransformationTestCase(String name) throws KettleException {
   super(name);
   KettleEnvironment.init();
 }