Example usage for java.util Date setMonth

List of usage examples for java.util Date setMonth

Introduction

In this page you can find the example usage for java.util Date setMonth.

Prototype

@Deprecated
public void setMonth(int month) 

Source Link

Document

Sets the month of this date to the specified value.

Usage

From source file:org.apache.lens.cube.metadata.UpdatePeriod.java

public Date truncate(Date date) {
    switch (this) {
    case WEEKLY:// w w w.j  av a 2s.  c  o  m
        Date truncDate = DateUtils.truncate(date, Calendar.DAY_OF_MONTH);
        Calendar cal = Calendar.getInstance();
        cal.setTime(truncDate);
        cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
        return cal.getTime();
    case QUARTERLY:
        Date dt = DateUtils.truncate(date, this.calendarField());
        dt.setMonth(dt.getMonth() - (dt.getMonth() % 3));
        return dt;
    default:
        return DateUtils.truncate(date, this.calendarField());
    }
}

From source file:com.eastcom.hrmis.modules.emp.dao.impl.EmployeeDaoImpl.java

@SuppressWarnings("deprecation")
@Override//ww w.j  av a  2  s.c o  m
public Map<String, Object> getEmployeeStatByDeptIdAndDate(String deptId, Date date) {
    Map<String, Object> map = Maps.newHashMap();
    map.put("statDate", DateUtils.formatDate(date, "yyyy-MM"));

    date.setDate(1);
    String startDate = DateUtils.formatDate(date);
    date.setMonth(date.getMonth() + 1);
    String endDate = DateUtils.formatDate(date);
    Object[] params = new Object[] { startDate, endDate };

    String deptSql = "";
    if (StringUtils.isNotBlank(deptId)) {
        deptSql = " and EMPLOYEE_DEPT_ID = ? ";
        params = new Object[] { deptId, startDate, endDate };
    }

    //?
    String enrtyCountSql = "select count(*) from ( select * from t_employee where RECORD_STATUS = 1 AND AUDIT_STATUS = 2 and HAS_QUIT_COMPANY = 0 "
            + deptSql + " ) t where t.enrty_date >= ? and t.enrty_date < ? ";
    //
    String regularCountSql = "select count(*) from ( select * from t_employee where RECORD_STATUS = 1 AND AUDIT_STATUS = 2 and HAS_QUIT_COMPANY = 0 and IS_REGULAR = 1"
            + deptSql + " ) t where t.regular_date >= ? and t.regular_date < ? ";
    //?
    String quitCompanyCountSql = "select count(*) from ( select * from t_employee where RECORD_STATUS = 1 AND AUDIT_STATUS = 2 and HAS_QUIT_COMPANY = 1"
            + deptSql + " ) t where t.quit_company_date >= ? and t.quit_company_date < ? ";
    //??
    String contractEndCountSql = "select count(*) from ( select * from t_employee where RECORD_STATUS = 1 AND AUDIT_STATUS = 2 and HAS_QUIT_COMPANY = 0"
            + deptSql + " ) t where t.contract_end_date >= ? and t.contract_end_date < ? ";
    //??
    String insureCountSql = "select count(*) from ( select * from t_employee where RECORD_STATUS = 1 AND AUDIT_STATUS = 2 and HAS_QUIT_COMPANY = 0"
            + deptSql + " ) t where t.enrty_date >= ? and t.enrty_date < ? and HAS_PERSION_INSURE = 1 ";
    //??
    String noInsureCountSql = "select count(*) from ( select * from t_employee where RECORD_STATUS = 1 AND AUDIT_STATUS = 2 and HAS_QUIT_COMPANY = 0"
            + deptSql + " ) t where t.enrty_date >= ? and t.enrty_date < ? and HAS_PERSION_INSURE = 0 ";
    //
    String retireCountSql = "select count(*) from ( select * from t_employee where RECORD_STATUS = 1 AND AUDIT_STATUS = 2 and HAS_QUIT_COMPANY = 0"
            + deptSql + " ) t where t.retire_date >= ? and t.retire_date < ? ";

    map.put("enrtyCount", ((BigInteger) createSqlQuery(enrtyCountSql, params).uniqueResult()).intValue());
    map.put("regularCount", ((BigInteger) createSqlQuery(regularCountSql, params).uniqueResult()).intValue());
    map.put("quitCompanyCount",
            ((BigInteger) createSqlQuery(quitCompanyCountSql, params).uniqueResult()).intValue());
    map.put("contractEndCount",
            ((BigInteger) createSqlQuery(contractEndCountSql, params).uniqueResult()).intValue());
    map.put("insureCount", ((BigInteger) createSqlQuery(insureCountSql, params).uniqueResult()).intValue());
    map.put("noInsureCount", ((BigInteger) createSqlQuery(noInsureCountSql, params).uniqueResult()).intValue());
    map.put("retireCount", ((BigInteger) createSqlQuery(retireCountSql, params).uniqueResult()).intValue());
    return map;
}

From source file:oscar.oscarEncounter.oscarMeasurements.pageUtil.FormUpdateAction.java

public boolean doInput(FlowSheetItem item, EctMeasurementTypesBean mtypeBean, MeasurementFlowSheet mFlowsheet,
        String inputType, String mInstructions, String value, String comment, String date, String apptNo,
        HttpServletRequest request) {//from w  w w  .  j  av  a 2s . c o m
    EctValidation ectValidation = new EctValidation();
    ActionMessages errors = new ActionMessages();

    String temp = request.getParameter("template");
    String demographicNo = request.getParameter("demographic_no");
    HttpSession session = request.getSession();
    String providerNo = (String) session.getAttribute("user");

    ResultSet rs;
    String regCharExp;

    String regExp = null;
    double dMax = 0;
    double dMin = 0;
    int iMax = 0;
    int iMin = 0;

    rs = ectValidation.getValidationType(inputType, mInstructions);
    regCharExp = ectValidation.getRegCharacterExp();

    boolean valid = true;

    try {

        if (rs.next()) {
            dMax = rs.getDouble("maxValue");
            dMin = rs.getDouble("minValue");
            iMax = rs.getInt("maxLength");
            iMin = rs.getInt("minLength");
            regExp = oscar.Misc.getString(rs, "regularExp");
        }
        rs.close();

        String inputTypeDisplay = mtypeBean.getTypeDisplayName();
        String inputValueName = item.getDisplayName();
        String inputValue = value;
        String comments = comment;
        String dateObserved = date;

        java.util.Calendar calender = java.util.Calendar.getInstance();
        String hour = Integer.toString(calender.get(java.util.Calendar.HOUR_OF_DAY));
        String min = Integer.toString(calender.get(java.util.Calendar.MINUTE));
        String second = Integer.toString(calender.get(java.util.Calendar.SECOND));
        String dateEntered = dateObserved + " " + hour + ":" + min + ":" + second;

        if (!ectValidation.isInRange(dMax, dMin, inputValue)) {
            errors.add(inputValueName, new ActionMessage("errors.range", inputTypeDisplay,
                    Double.toString(dMin), Double.toString(dMax)));
            saveErrors(request, errors);
            valid = false;
        }
        if (!ectValidation.maxLength(iMax, inputValue)) {
            errors.add(inputValueName,
                    new ActionMessage("errors.maxlength", inputTypeDisplay, Integer.toString(iMax)));
            saveErrors(request, errors);
            valid = false;
        }
        if (!ectValidation.minLength(iMin, inputValue)) {
            errors.add(inputValueName,
                    new ActionMessage("errors.minlength", inputTypeDisplay, Integer.toString(iMin)));
            saveErrors(request, errors);
            valid = false;
        }

        if (!ectValidation.matchRegExp(regExp, inputValue)) {
            errors.add(inputValueName, new ActionMessage("errors.invalid", inputTypeDisplay));
            saveErrors(request, errors);
            valid = false;
        }
        if (!ectValidation.isValidBloodPressure(regExp, inputValue)) {
            errors.add(inputValueName, new ActionMessage("error.bloodPressure"));
            saveErrors(request, errors);
            valid = false;
        }
        if (!ectValidation.isDate(dateObserved) && inputValue.compareTo("") != 0) {
            errors.add("Date", new ActionMessage("errors.invalidDate", inputTypeDisplay));
            saveErrors(request, errors);
            valid = false;
        }

        if (valid) {
            comments = org.apache.commons.lang.StringEscapeUtils.escapeSql(comments);
            MsgStringQuote str = new MsgStringQuote();

            Properties p = (Properties) session.getAttribute("providerBean");
            String by = "";
            if (p != null) {
                by = p.getProperty(providerNo, "");
            }

            org.apache.commons.validator.GenericValidator gValidator = new org.apache.commons.validator.GenericValidator();
            if (!GenericValidator.isBlankOrNull(inputValue)) {

                String[] dateComp = date.split("-");
                Date dateObs = new Date();
                dateObs.setYear(Integer.parseInt(dateComp[0]) - 1900);
                dateObs.setMonth(Integer.parseInt(dateComp[1]) - 1);
                dateObs.setDate(Integer.parseInt(dateComp[2]));

                Measurement measurement = new Measurement();
                measurement.setDemographicId(Integer.parseInt(demographicNo));
                measurement.setDataField(inputValue);
                measurement.setMeasuringInstruction(mInstructions);
                if (comments.equals("")) {
                    comments = " ";
                }
                measurement.setComments(comments);
                measurement.setDateObserved(dateObs);
                measurement.setType(inputType);
                if (apptNo != null) {
                    measurement.setAppointmentNo(Integer.parseInt(apptNo));
                } else {
                    measurement.setAppointmentNo(0);
                }
                measurement.setProviderNo(providerNo);

                //Find if the same data has already been entered into the system
                MeasurementDao measurementDao = (MeasurementDao) SpringUtils.getBean("measurementDao");
                List<Measurement> measurements = measurementDao.findMatching(measurement);

                if (measurements.size() == 0) {
                    //Write to the Dababase if all input values are valid
                    measurementDao.persist(measurement);
                }
                rs.close();
            }

        }

    } catch (SQLException e) {

    }

    return valid;
}

From source file:com.andco.salasucc.bean.nuevaBean.java

public String siguiente() {
    FacesContext context = FacesContext.getCurrentInstance();

    horaInicio.setYear(fecha.getYear());
    horaInicio.setMonth(fecha.getMonth());
    horaInicio.setDate(fecha.getDate());
    horaFin.setYear(fecha.getYear());//  w  ww  .j  ava  2 s. co m
    horaFin.setMonth(fecha.getMonth());
    horaFin.setDate(fecha.getDate());
    if ((horaFin.getTime() - horaInicio.getTime()) < 3600000) {
        FacesMessage errorMessage = new FacesMessage("Fecha Invalida");
        errorMessage.setSeverity(FacesMessage.SEVERITY_ERROR);
        context.addMessage(null, errorMessage);
        horaFin = null;
        return null;
    } else {
        SalasJpaController salasCont = new SalasJpaController();
        listaSalasDisponibles = new ArrayList<>();
        if (!recurrente) {
            listaSalasDisponibles = salasCont.buscarSalasDisponibles(Integer.parseInt(numEstudiantes),
                    Integer.parseInt(software), horaInicio, horaFin);
        } else {
            Date fechaFinSemestre = new Date();
            fechaFinSemestre.setHours(23);
            fechaFinSemestre.setMinutes(59);

            if (fecha.getMonth() >= 1 && fecha.getMonth() <= 4) {
                fechaFinSemestre.setMonth(4);
                fechaFinSemestre.setDate(31);
            } else {
                fechaFinSemestre.setMonth(10);
                fechaFinSemestre.setDate(30);
            }
            listaFechasInicio = generaFechasRecurrentes(horaInicio, fechaFinSemestre);
            listaFechasFin = generaFechasRecurrentes(horaFin, fechaFinSemestre);
            HashMap<Salas, Integer> map = new HashMap<>();

            int tam = listaFechasInicio.size();
            for (int i = 0; i < tam; i++) {
                List<Salas> lSalas = salasCont.buscarSalasDisponibles(Integer.parseInt(numEstudiantes),
                        Integer.parseInt(software), listaFechasInicio.get(i), listaFechasFin.get(i));
                for (int j = 0; j < lSalas.size(); j++) {
                    Salas salaActual = lSalas.get(j);
                    Integer previousValue = map.get(salaActual);
                    map.put(salaActual, previousValue == null ? 1 : previousValue + 1);
                }
            }

            for (Salas key : map.keySet()) {
                if (map.get(key) == tam) {
                    listaSalasDisponibles.add(key);
                }
            }

        }

        if (listaSalasDisponibles.isEmpty()) {
            FacesMessage warnMessage = new FacesMessage("No hay salas disponibles");
            warnMessage.setSeverity(FacesMessage.SEVERITY_WARN);
            context.addMessage(null, warnMessage);
            return null;
        } else {
            return "disponibles";
        }

    }
}

From source file:ca.ualberta.cs.cmput301w15t04team04project.EditClaimActivity.java

/**
 * This function controls the MenuItem and shown as a  on the scream.<br>
 * <ol>The MenuItem has the following functions:
 * <ul>/*from w  w w.  ja  v  a 2  s.com*/
 * <li>The function will find all needed views by their id.
 * <li>The function will test the user chooses either adding or editing.
 * <li>If user chooses to add a claim, the class "AddThread" will be called
 * <li>Else if user chooses to edit a claim, the class "updateThread will be called 
 * </ul>
 * </ol>
 * 
 * @author Chenrui Lei
 * @author Ji Yang
 * @author Yufei Zhang
 * @version 1.1
 * @since 2015-03-12
 * @version 1.2
 * @since 2015-03-20
 */

@SuppressWarnings("deprecation")
public void confirmClaim(MenuItem item) {
    EditText claimName = (EditText) findViewById(R.id.claimNameEditText);
    EditText description = (EditText) findViewById(R.id.descriptionEditText);
    EditText tag = (EditText) findViewById(R.id.tagEditText);
    DatePicker fromDatePicker = (DatePicker) findViewById(R.id.fromDatePicker);
    DatePicker toDatePicker = (DatePicker) findViewById(R.id.toDatePicker);
    Date sDate = new Date();
    Date eDate = new Date();
    String cName = claimName.getText().toString();
    String cDescription = description.getText().toString();
    String cTag = tag.getText().toString();
    sDate.setDate(fromDatePicker.getDayOfMonth());
    sDate.setMonth(fromDatePicker.getMonth());
    sDate.setYear(fromDatePicker.getYear() - 1900);
    eDate.setDate(toDatePicker.getDayOfMonth());
    eDate.setMonth(toDatePicker.getMonth());
    eDate.setYear(toDatePicker.getYear() - 1900);
    if (addEditStatus == 0) {
        ArrayList<Item> cItem = new ArrayList<Item>();
        ArrayList<String> cComments = new ArrayList<String>();
        Claim claim = controller.setClaim(cName, cDescription, cTag, sDate, eDate, destinationList,
                user.getName(), cItem, cComments, claimLocation);
        Thread add = new AddThread(claim);
        add.start();
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    else {

        Claim claim = controller.setClaim(cName, cDescription, cTag, sDate, eDate, destinationList,
                user.getName(), items, comments, claimLocation);
        Thread update = new UpdateThread(claim);
        update.start();

        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}

From source file:accountgen.controller.Controller.java

private void setBday(Document doc, Person p) {
    Element bday = doc.select(".bday").first();
    Date bd = new Date();

    Date date = null;/*from   w w  w.ja  v  a 2  s . com*/
    try {
        date = new SimpleDateFormat("MMM", Locale.ENGLISH).parse(bday.text().split(" ")[0]);
    } catch (ParseException ex) {
        Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, null, ex);
    }
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    int month = cal.get(Calendar.MONTH);
    bd.setMonth(month);
    bd.setDate(Integer.parseInt(bday.text().split(" ")[1].replace(",", "")));
    bd.setYear(Integer.parseInt(bday.text().split(",")[1].substring(1, 5)) - 1900);
    p.setBirthday(bd);
}

From source file:com.progym.custom.fragments.FoodCalloriesProgressYearlyLineFragment.java

public void setYearProgressData(Date date) {
    int yMaxAxisValue = 0;
    try {//from  ww  w  .j av a  2s  .  c  o m
        rlRootGraphLayout.removeView(viewChart);
    } catch (Exception edsx) {
        edsx.printStackTrace();
    }
    DATE = date;
    // Get amount of days in a month to find out average
    int daysInMonth = Utils.getDaysInMonth(date.getMonth(),
            Integer.valueOf(Utils.formatDate(date, DataBaseUtils.DATE_PATTERN_YYYY)));
    // set January as first month
    date.setMonth(0);
    date.setDate(1);

    int[] x = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };

    XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
    CategorySeries seriesCallories = new CategorySeries("Callories");

    List<Ingridient> list;
    for (int i = 0; i < x.length; i++) {
        list = DataBaseUtils
                .getAllFoodConsumedInMonth(Utils.formatDate(date, DataBaseUtils.DATE_PATTERN_YYYY_MM));

        // init "average" data
        int totalCallories = 0;
        for (Ingridient ingridient : list) {
            totalCallories += ingridient.kkal;
        }
        // add value to series
        seriesCallories.add(totalCallories / daysInMonth);
        // calculate maximum Y axis values
        yMaxAxisValue = Math.max(yMaxAxisValue, totalCallories / daysInMonth);
        // increment month
        date = DateUtils.addMonths(date, 1);
    }

    int[] colors = new int[] { getActivity().getResources().getColor(R.color.purple) };
    XYMultipleSeriesRenderer renderer = buildBarRenderer(colors);
    setChartSettings(renderer,
            String.format("Callories statistic for %s year", Utils.getSpecificDateValue(DATE, "yyyy")),
            "Months", "Amount (g)", 0.7, 12.3, 0, yMaxAxisValue + 30, Color.GRAY, Color.LTGRAY);

    renderer.getSeriesRendererAt(0).setDisplayChartValues(true);
    renderer.getSeriesRendererAt(0).setChartValuesTextSize(15f);
    renderer.setXLabels(0);
    renderer.setClickEnabled(false);
    renderer.setZoomEnabled(false);
    renderer.setPanEnabled(false, false);
    renderer.setZoomButtonsVisible(false);
    renderer.setPanLimits(new double[] { 1, 11 });
    renderer.setShowGrid(true);
    renderer.setShowLegend(true);
    renderer.setFitLegend(true);

    for (int i = 0; i < ActivityWaterProgress.months_short.length; i++) {
        renderer.addXTextLabel(i + 1, ActivityWaterProgress.months_short[i]);

    }
    dataset.addSeries(seriesCallories.toXYSeries());

    viewChart = ChartFactory.getBarChartView(getActivity(), dataset, renderer, Type.DEFAULT);
    rlRootGraphLayout.addView(viewChart, 0);
}

From source file:org.pentaho.platform.dataaccess.datasource.wizard.service.agile.CsvTransformGeneratorTest.java

public void testGoodTransform() throws Exception {
    IPentahoSession session = new StandaloneSession("test");
    KettleSystemListener.environmentInit(session);
    ModelInfo info = createModel();//from   ww  w  .  j ava 2s. co  m
    CsvTransformGenerator gen = new CsvTransformGenerator(info, getDatabaseMeta());

    gen.preview(session);

    DataRow rows[] = info.getData();
    assertNotNull(rows);
    assertEquals(235, rows.length);

    Date testDate = new Date();
    testDate.setDate(1);
    testDate.setHours(0);
    testDate.setMinutes(0);
    testDate.setMonth(0);
    testDate.setSeconds(0);
    testDate.setYear(110);

    // test the first row
    // test the data types
    DataRow row = rows[0];
    assertNotNull(row);
    Object cells[] = row.getCells();
    assertNotNull(cells);
    //    assertEquals( 8, cells.length );
    assertTrue(cells[0] instanceof Long);
    assertTrue(cells[1] instanceof Double);
    assertTrue(cells[2] instanceof Long);
    assertTrue(cells[3] instanceof Date);
    assertTrue(cells[4] instanceof String);
    assertTrue(cells[5] instanceof Long);
    assertTrue(cells[6] instanceof Double);
    assertTrue(cells[7] instanceof Boolean);
    // test the values
    assertEquals((long) 3, cells[0]);
    assertEquals(25677.96525, cells[1]);
    assertEquals((long) 1231, cells[2]);
    assertEquals(testDate.getYear(), ((Date) cells[3]).getYear());
    assertEquals(testDate.getMonth(), ((Date) cells[3]).getMonth());
    assertEquals(testDate.getDate(), ((Date) cells[3]).getDate());
    assertEquals(testDate.getHours(), ((Date) cells[3]).getHours());
    //    assertEquals( testDate.getMinutes(), ((Date)cells[3]).getMinutes() ); this fails, a bug in the PDI date parsing?
    assertEquals(testDate.getSeconds(), ((Date) cells[3]).getSeconds());

    //    assertEquals( testDate, cells[3] );
    assertEquals("Afghanistan", cells[4]);
    assertEquals((long) 11, cells[5]);
    assertEquals(111.9090909, cells[6]);
    assertEquals(false, cells[7]);

    // test the second row
    testDate.setDate(2);
    // test the data types
    row = rows[1];
    assertNotNull(row);
    cells = row.getCells();
    assertNotNull(cells);
    assertTrue(cells[0] instanceof Long);
    assertTrue(cells[1] instanceof Double);
    assertTrue(cells[2] instanceof Long);
    assertTrue(cells[3] instanceof Date);
    assertTrue(cells[4] == null);
    assertTrue(cells[5] instanceof Long);
    assertTrue(cells[6] instanceof Double);
    assertTrue(cells[7] instanceof Boolean);
    // test the values
    assertEquals((long) 4, cells[0]);
    assertEquals(24261.81026, cells[1]);
    assertEquals((long) 1663, cells[2]);
    assertEquals(testDate.getYear(), ((Date) cells[3]).getYear());
    assertEquals(testDate.getMonth(), ((Date) cells[3]).getMonth());
    assertEquals(testDate.getDate(), ((Date) cells[3]).getDate());
    assertEquals(testDate.getHours(), ((Date) cells[3]).getHours());
    //    assertEquals( testDate.getMinutes(), ((Date)cells[3]).getMinutes() ); this fails, a bug in the PDI date parsing?
    assertEquals(testDate.getSeconds(), ((Date) cells[3]).getSeconds());

    //    assertEquals( testDate, cells[3] );
    assertEquals(null, cells[4]); // IfNull value does not seem to work
    assertEquals((long) 7, cells[5]);
    assertEquals(237.5714286, cells[6]);
    assertEquals(true, cells[7]);

}

From source file:org.pentaho.platform.dataaccess.datasource.wizard.service.agile.CsvTransformGeneratorIT.java

public void testLoadTable1() throws Exception {
    IPentahoSession session = new StandaloneSession("test");
    KettleSystemListener.environmentInit(session);
    ModelInfo info = createModel();//from   ww  w  . ja  va 2 s .c  o  m
    CsvTransformGenerator gen = new CsvTransformGenerator(info, getDatabaseMeta());

    // create the model
    String tableName = info.getStageTableName();
    try {
        gen.execSqlStatement(getDropTableStatement(tableName), getDatabaseMeta(), null);
    } catch (CsvTransformGeneratorException e) {
        // table might not be there yet, it is OK
    }

    // generate the database table
    gen.createOrModifyTable(session);

    // load the table
    loadTable(gen, info, true, session);

    // check the results
    long rowCount = this.getRowCount(tableName);
    assertEquals((long) 235, rowCount);
    DatabaseMeta databaseMeta = getDatabaseMeta();
    assertNotNull(databaseMeta);
    Database database = new Database(databaseMeta);
    assertNotNull(database);
    database.connect();

    Connection connection = null;
    Statement stmt = null;
    ResultSet sqlResult = null;

    try {
        connection = database.getConnection();
        assertNotNull(connection);
        stmt = database.getConnection().createStatement();

        // check the first row
        Date testDate = new Date();
        testDate.setDate(1);
        testDate.setHours(0);
        testDate.setMinutes(0);
        testDate.setMonth(0);
        testDate.setSeconds(0);
        testDate.setYear(110);
        boolean ok = stmt.execute("select * from " + tableName);
        assertTrue(ok);
        sqlResult = stmt.getResultSet();
        assertNotNull(sqlResult);
        ok = sqlResult.next();
        assertTrue(ok);

        // test the values
        assertEquals((long) 3, sqlResult.getLong(1));
        assertEquals(25677.96525, sqlResult.getDouble(2));
        assertEquals((long) 1231, sqlResult.getLong(3));
        assertEquals(testDate.getYear(), sqlResult.getDate(4).getYear());
        assertEquals(testDate.getMonth(), sqlResult.getDate(4).getMonth());
        assertEquals(testDate.getDate(), sqlResult.getDate(4).getDate());
        assertEquals(testDate.getHours(), sqlResult.getTime(4).getHours());
        //    assertEquals( testDate.getMinutes(), ((Date)cells[3]).getMinutes() ); this fails, a bug in the PDI date parsing?
        assertEquals(testDate.getSeconds(), sqlResult.getTime(4).getSeconds());

        //    assertEquals( testDate, cells[3] );
        assertEquals("Afghanistan", sqlResult.getString(5));
        assertEquals((long) 11, sqlResult.getLong(6));
        assertEquals(111.9090909, sqlResult.getDouble(7));
        assertEquals(false, sqlResult.getBoolean(8));
    } finally {
        sqlResult.close();
        stmt.close();
        connection.close();
    }

}

From source file:org.pentaho.platform.dataaccess.datasource.wizard.service.agile.CsvTransformGeneratorIT.java

public void testGoodTransform() throws Exception {
    IPentahoSession session = new StandaloneSession("test");
    KettleSystemListener.environmentInit(session);
    String KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL = System.getProperty("KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL",
            "N");
    ModelInfo info = createModel();/*w  ww .  j  a va2 s  .  c  om*/
    CsvTransformGenerator gen = new CsvTransformGenerator(info, getDatabaseMeta());

    gen.preview(session);

    DataRow rows[] = info.getData();
    assertNotNull(rows);
    assertEquals(235, rows.length);

    Date testDate = new Date();
    testDate.setDate(1);
    testDate.setHours(0);
    testDate.setMinutes(0);
    testDate.setMonth(0);
    testDate.setSeconds(0);
    testDate.setYear(110);

    // test the first row
    // test the data types
    DataRow row = rows[0];
    assertNotNull(row);
    Object cells[] = row.getCells();
    assertNotNull(cells);
    //    assertEquals( 8, cells.length );
    assertTrue(cells[0] instanceof Long);
    assertTrue(cells[1] instanceof Double);
    assertTrue(cells[2] instanceof Long);
    assertTrue(cells[3] instanceof Date);
    assertTrue(cells[4] instanceof String);
    assertTrue(cells[5] instanceof Long);
    assertTrue(cells[6] instanceof Double);
    assertTrue(cells[7] instanceof Boolean);
    // test the values
    assertEquals((long) 3, cells[0]);
    assertEquals(25677.96525, cells[1]);
    assertEquals((long) 1231, cells[2]);
    assertEquals(testDate.getYear(), ((Date) cells[3]).getYear());
    assertEquals(testDate.getMonth(), ((Date) cells[3]).getMonth());
    assertEquals(testDate.getDate(), ((Date) cells[3]).getDate());
    assertEquals(testDate.getHours(), ((Date) cells[3]).getHours());
    //    assertEquals( testDate.getMinutes(), ((Date)cells[3]).getMinutes() ); this fails, a bug in the PDI date parsing?
    assertEquals(testDate.getSeconds(), ((Date) cells[3]).getSeconds());

    //    assertEquals( testDate, cells[3] );
    assertEquals("Afghanistan", cells[4]);
    assertEquals((long) 11, cells[5]);
    assertEquals(111.9090909, cells[6]);
    assertEquals(false, cells[7]);

    // test the second row
    testDate.setDate(2);
    // test the data types
    row = rows[1];
    assertNotNull(row);
    cells = row.getCells();
    assertNotNull(cells);
    assertTrue(cells[0] instanceof Long);
    assertTrue(cells[1] instanceof Double);
    assertTrue(cells[2] instanceof Long);
    assertTrue(cells[3] instanceof Date);
    if ("Y".equals(KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL)) {
        assertTrue("".equals(cells[4]));
    } else {
        assertTrue(cells[4] == null);
    }
    assertTrue(cells[5] instanceof Long);
    assertTrue(cells[6] instanceof Double);
    assertTrue(cells[7] instanceof Boolean);
    // test the values
    assertEquals((long) 4, cells[0]);
    assertEquals(24261.81026, cells[1]);
    assertEquals((long) 1663, cells[2]);
    assertEquals(testDate.getYear(), ((Date) cells[3]).getYear());
    assertEquals(testDate.getMonth(), ((Date) cells[3]).getMonth());
    assertEquals(testDate.getDate(), ((Date) cells[3]).getDate());
    assertEquals(testDate.getHours(), ((Date) cells[3]).getHours());
    //    assertEquals( testDate.getMinutes(), ((Date)cells[3]).getMinutes() ); this fails, a bug in the PDI date parsing?
    assertEquals(testDate.getSeconds(), ((Date) cells[3]).getSeconds());

    //    assertEquals( testDate, cells[3] );
    if ("Y".equals(KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL)) {
        assertEquals("", cells[4]);
        assertEquals(cells[4], "");
    } else {
        assertEquals(null, cells[4]); // IfNull value does not seem to work
    }

    assertEquals((long) 7, cells[5]);
    assertEquals(237.5714286, cells[6]);
    assertEquals(true, cells[7]);

}