Exemplo n.º 1
0
  @Test
  public void testMondrianUpdateFormat() throws Exception {
    File mondrianSchemaXmlFile = new File(MONDRIAN_TEST_FILE_PATH);

    Document mondrianSchemaXmlDoc =
        DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(mondrianSchemaXmlFile);
    assertTrue(mondrianSchemaXmlDoc != null);
    // Check existing state
    assertTrue(
        AnnotationUtil.validateNodeAttribute(
            mondrianSchemaXmlDoc,
            AnnotationUtil.MEASURE_ELEMENT_NAME,
            INIT_BUYPRICE_COLUMN,
            AnnotationUtil.NAME_ATTRIB,
            INIT_BUYPRICE_COLUMN));
    assertTrue(
        AnnotationUtil.validateNodeAttribute(
            mondrianSchemaXmlDoc,
            AnnotationUtil.MEASURE_ELEMENT_NAME,
            INIT_BUYPRICE_COLUMN,
            AnnotationUtil.FORMATSTRING_ATTRIB,
            INIT_FORMAT));

    // Changing the aggregation type
    UpdateMeasure updateMeasure = new UpdateMeasure();
    updateMeasure.setMeasure(INIT_MEASURE_MONDRIAN_FORMULA);
    updateMeasure.setName(INIT_BUYPRICE_COLUMN);
    updateMeasure.setFormat(NEW_FORMAT);
    boolean isApplied = updateMeasure.apply(mondrianSchemaXmlDoc);
    assertTrue(isApplied);

    // Check change
    assertTrue(
        mondrianSchemaXmlDoc.getElementsByTagName(AnnotationUtil.MEASURE_ELEMENT_NAME).getLength()
            > 0);
    assertTrue(
        AnnotationUtil.validateNodeAttribute(
            mondrianSchemaXmlDoc,
            AnnotationUtil.MEASURE_ELEMENT_NAME,
            INIT_BUYPRICE_COLUMN,
            AnnotationUtil.NAME_ATTRIB,
            INIT_BUYPRICE_COLUMN));
    assertTrue(
        AnnotationUtil.validateNodeAttribute(
            mondrianSchemaXmlDoc,
            AnnotationUtil.MEASURE_ELEMENT_NAME,
            INIT_BUYPRICE_COLUMN,
            AnnotationUtil.FORMATSTRING_ATTRIB,
            NEW_FORMAT));
  }
Exemplo n.º 2
0
  @Test
  public void testUpdatesCaptionNameUnchanged() throws Exception {
    File mondrianSchemaXmlFile = new File(MONDRIAN_TEST_FILE_PATH);

    Document mondrianSchemaXmlDoc =
        DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(mondrianSchemaXmlFile);

    // Renaming the measure
    UpdateMeasure updateMeasure = new UpdateMeasure();
    updateMeasure.setMeasure(INIT_MEASURE_MONDRIAN_FORMULA);
    updateMeasure.setCaption(NEW_BUYPRICE_NAME);
    boolean isApplied = updateMeasure.apply(mondrianSchemaXmlDoc);
    assertTrue(isApplied);

    assertTrue(mondrianSchemaXmlDoc != null);
    assertTrue(
        mondrianSchemaXmlDoc.getElementsByTagName(AnnotationUtil.MEASURE_ELEMENT_NAME).getLength()
            > 0);
    assertTrue(
        AnnotationUtil.validateNodeAttribute(
            mondrianSchemaXmlDoc,
            AnnotationUtil.MEASURE_ELEMENT_NAME,
            INIT_BUYPRICE_COLUMN,
            AnnotationUtil.CAPTION_ATTRIB,
            NEW_BUYPRICE_NAME));
  }
Exemplo n.º 3
0
  @Test
  public void testMondrianNoDuplicateNames() throws Exception {
    File mondrianSchemaXmlFile = new File(MONDRIAN_TEST_FILE_PATH);

    Document mondrianSchemaXmlDoc =
        DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(mondrianSchemaXmlFile);

    // Renaming the measure
    UpdateMeasure updateMeasure = new UpdateMeasure();
    updateMeasure.setMeasure(INIT_MEASURE_MONDRIAN_FORMULA);
    updateMeasure.setName(EXISTING_COLUMN);
    assertFalse(updateMeasure.apply(mondrianSchemaXmlDoc));

    // Ensure nothing has changed
    assertTrue(mondrianSchemaXmlDoc != null);
    assertTrue(
        mondrianSchemaXmlDoc.getElementsByTagName(AnnotationUtil.MEASURE_ELEMENT_NAME).getLength()
            > 0);

    // Ensure new Element was not created
    assertFalse(
        AnnotationUtil.validateNodeAttribute(
            mondrianSchemaXmlDoc,
            AnnotationUtil.MEASURE_ELEMENT_NAME,
            NEW_BUYPRICE_NAME,
            AnnotationUtil.NAME_ATTRIB,
            ""));

    // Ensure original element still exists
    assertTrue(
        AnnotationUtil.validateNodeAttribute(
            mondrianSchemaXmlDoc,
            AnnotationUtil.MEASURE_ELEMENT_NAME,
            EXISTING_COLUMN,
            AnnotationUtil.NAME_ATTRIB,
            EXISTING_COLUMN));
  }