gt:     ModelerWorkspace model = prepareOrderModel();
context: /*!
   * PENTAHO CORPORATION PROPRIETARY AND CONFIDENTIAL
   *
   * Copyright 2002 - 2015 Pentaho Corporation (Pentaho). All rights reserved.
   *
   * NOTICE: All information including source code contained herein is, and
   * remains the sole property of Pentaho and its licensors. The intellectual
   * and technical concepts contained herein are proprietary and confidential
   * to, and are trade secrets of Pentaho and may be covered by U.S. and foreign
   * patents, or patents in process, and are protected by trade secret and
   * copyright laws. The receipt or possession of this source code and/or related
   * information does not convey or imply any rights to reproduce, disclose or
   * distribute its contents, or to manufacture, use, or sell anything that it
   * may describe, in whole or in part. Any reproduction, modification, distribution,
   * or public display of this information without the express written authorization
   * from Pentaho is strictly prohibited and in violation of applicable laws and
   * international treaties. Access to the source code contained herein is strictly
   * prohibited to anyone except those individuals and entities who have executed
   * confidentiality and non-disclosure agreements or other agreements with Pentaho,
   * explicitly covering such access.
   */
  
  package org.pentaho.agilebi.modeler.models.annotations;
  
  import org.junit.Assert;
  import static org.junit.Assert.assertEquals;
  import static org.junit.Assert.assertFalse;
  import static org.junit.Assert.assertTrue;
  import org.junit.Before;
  import org.junit.BeforeClass;
  import org.junit.Test;
  import org.pentaho.agilebi.modeler.ModelerException;
  import org.pentaho.agilebi.modeler.ModelerPerspective;
  import org.pentaho.agilebi.modeler.ModelerWorkspace;
  import org.pentaho.agilebi.modeler.geo.GeoContext;
  import org.pentaho.agilebi.modeler.geo.GeoContextConfigProvider;
  import org.pentaho.agilebi.modeler.geo.GeoContextFactory;
  import org.pentaho.agilebi.modeler.geo.GeoContextPropertiesProvider;
  import org.pentaho.agilebi.modeler.util.ModelerWorkspaceHelper;
  import org.pentaho.agilebi.modeler.util.TableModelerSource;
  import org.pentaho.di.core.KettleClientEnvironment;
  import org.pentaho.di.core.Props;
  import org.pentaho.di.core.database.Database;
  import org.pentaho.di.core.database.DatabaseMeta;
  import org.pentaho.di.core.plugins.PluginRegistry;
  import org.pentaho.di.core.plugins.StepPluginType;
  import org.pentaho.metadata.model.Domain;
  import org.pentaho.metadata.model.olap.OlapCalculatedMember;
  import org.pentaho.metadata.model.olap.OlapCube;
  import org.pentaho.metastore.stores.memory.MemoryMetaStore;
  import org.w3c.dom.Document;
  
  import javax.xml.parsers.DocumentBuilderFactory;
  import java.io.File;
  import java.io.FileReader;
  import java.io.Reader;
  import java.util.List;
  import java.util.Properties;
  
  public class CreateCalculatedMemberIT {
    private static final String TEST_CALCULATED_MEMBER_NAME = "TestCalculatedMember";
    private static final String TEST_CALCULCATED_MEMBER_CAPTION = "Test Caption";
    private static final String TEST_CALCULATED_MEMBER_DESC = "Test Description";
    private static final String TEST_CALCULATED_MEMBER_FORMULA = "Test Formula";
    private static final String TEST_CALCULATED_MEMBER_DIMENSION = "Test Dimension";
    private static final String TEST_CALCULATED_MEMBER_FORMAT_STRING = "$#,##0.00";
    private static final String TEST_CALCULATED_MEMBER_FORMAT_CATEGORY = "Default";
    private static final String MONDRIAN_TEST_FILE_PATH = "test-res/products.mondrian.xml";
    private static final String CAPTION_ATTRIB = "caption";
    private static final String DESCRIPTION_ATTRIB = "description";
    private static final String DIMENSION_ATTRIB = "dimension";
    private static final String FORMULA_ATTRIB = "formula";
    private static final String FORMAT_STRING_ATTRIB = "formatString";
    private static final String FORMAT_CATEGORY_ATTRIB = "formatCategory";
    private static final String GEO_ROLE_PROPERTIES = "test-res/geoRoles.properties";
  
  
    CreateCalculatedMember createCalculatedMember = new CreateCalculatedMember();
    Document mockDocument;
  
    private DatabaseMeta dbMeta;
  
    @Before
    public void setUp() throws Exception {
      createCalculatedMember.setName( TEST_CALCULATED_MEMBER_NAME );
      createCalculatedMember.setCaption( TEST_CALCULCATED_MEMBER_CAPTION );
      createCalculatedMember.setDescription( TEST_CALCULATED_MEMBER_DESC );
      createCalculatedMember.setFormula( TEST_CALCULATED_MEMBER_FORMULA );
      createCalculatedMember.setDimension( TEST_CALCULATED_MEMBER_DIMENSION );
      createCalculatedMember.setFormatString( TEST_CALCULATED_MEMBER_FORMAT_STRING );
      createCalculatedMember.setFormatCategory( TEST_CALCULATED_MEMBER_FORMAT_CATEGORY );
      createCalculatedMember.setHidden( Boolean.FALSE );
    }
  
    @Test
    public void testApplyMondrian() throws Exception {
      File mondrianSchemaXmlFile = new File( MONDRIAN_TEST_FILE_PATH );
  
      Document mondrianSchemaXmlDoc =
          DocumentBuilderFactory
          .newInstance()
          .newDocumentBuilder()
          .parse( mondrianSchemaXmlFile );
  
      createCalculatedMember.apply( mondrianSchemaXmlDoc );
  
      assertTrue( mondrianSchemaXmlDoc != null );
      assertTrue(
          mondrianSchemaXmlDoc.getElementsByTagName( AnnotationUtil.CALCULATED_MEMBER_ELEMENT_NAME ).getLength() > 0 );
      assertTrue( AnnotationUtil.validateNodeAttribute( mondrianSchemaXmlDoc,
          AnnotationUtil.CALCULATED_MEMBER_ELEMENT_NAME,
          TEST_CALCULATED_MEMBER_NAME,
          CAPTION_ATTRIB,
          TEST_CALCULCATED_MEMBER_CAPTION ) );
      assertTrue( AnnotationUtil.validateNodeAttribute( mondrianSchemaXmlDoc,
          AnnotationUtil.CALCULATED_MEMBER_ELEMENT_NAME,
          TEST_CALCULATED_MEMBER_NAME,
          DESCRIPTION_ATTRIB,
          TEST_CALCULATED_MEMBER_DESC ) );
      assertTrue( AnnotationUtil.validateNodeAttribute( mondrianSchemaXmlDoc,
          AnnotationUtil.CALCULATED_MEMBER_ELEMENT_NAME,
          TEST_CALCULATED_MEMBER_NAME,
          DIMENSION_ATTRIB,
          TEST_CALCULATED_MEMBER_DIMENSION ) );
      assertTrue( AnnotationUtil.validateNodeAttribute( mondrianSchemaXmlDoc,
          AnnotationUtil.CALCULATED_MEMBER_ELEMENT_NAME,
          TEST_CALCULATED_MEMBER_NAME,
          FORMULA_ATTRIB,
          TEST_CALCULATED_MEMBER_FORMULA ) );
      assertTrue( AnnotationUtil.validateNodeAttribute( mondrianSchemaXmlDoc,
          AnnotationUtil.CALCULATED_MEMBER_ELEMENT_NAME,
          TEST_CALCULATED_MEMBER_NAME,
          AnnotationUtil.NAME_ATTRIB,
          TEST_CALCULATED_MEMBER_NAME ) );
      assertTrue( AnnotationUtil.validateNodeAttribute( mondrianSchemaXmlDoc,
          AnnotationUtil.CALCULATED_MEMBER_ELEMENT_NAME,
          TEST_CALCULATED_MEMBER_NAME,
          FORMAT_STRING_ATTRIB,
          TEST_CALCULATED_MEMBER_FORMAT_STRING ) );
      assertTrue( AnnotationUtil.validateNodeAttribute( mondrianSchemaXmlDoc,
          AnnotationUtil.CALCULATED_MEMBER_ELEMENT_NAME,
          TEST_CALCULATED_MEMBER_NAME,
          AnnotationUtil.VISIBLE_ATTRIB,
          Boolean.TRUE.toString() ) );
      assertTrue( AnnotationUtil.validateNodeAttribute( mondrianSchemaXmlDoc,
          AnnotationUtil.CALCULATED_MEMBER_PROPERTY_ELEMENT_NAME, "SOLVE_ORDER", "value", "0" ) );
  
      // validate mondrian annotations
      assertTrue( AnnotationUtil.validateMondrianAnnotationValue( mondrianSchemaXmlDoc,
          AnnotationUtil.CALCULATED_MEMBER_ELEMENT_NAME,
          TEST_CALCULATED_MEMBER_NAME,
          FORMAT_CATEGORY_ATTRIB,
          TEST_CALCULATED_MEMBER_FORMAT_CATEGORY ) );
    }
  
    @Test
    public void testApplyMondrianCalculateSubTotalsHasSolvedOrder200() throws Exception {
      File mondrianSchemaXmlFile = new File( MONDRIAN_TEST_FILE_PATH );
  
      Document mondrianSchemaXmlDoc =
          DocumentBuilderFactory
              .newInstance()
              .newDocumentBuilder()
              .parse( mondrianSchemaXmlFile );
  
      createCalculatedMember.setCalculateSubtotals( true );
      createCalculatedMember.apply( mondrianSchemaXmlDoc );
  
      assertTrue( mondrianSchemaXmlDoc != null );
      assertTrue( AnnotationUtil.validateNodeAttribute( mondrianSchemaXmlDoc,
          AnnotationUtil.CALCULATED_MEMBER_PROPERTY_ELEMENT_NAME, "SOLVE_ORDER", "value", "200" ) );
    }
  
    @Test
    public void testGetSummary() throws Exception {
      CreateCalculatedMember cm = new CreateCalculatedMember();
      cm.setName( "Some Name" );
      cm.setFormula( "[A]+[B]" );
  
      assertEquals( "Some Name, calculated from [A]+[B]", cm.getSummary() );
    }
  
    @Test
    public void testValidate() throws Exception {
      createCalculatedMember.validate();
    }
  
    @Test
    public void testValidateException() throws Exception {
      CreateCalculatedMember cm = new CreateCalculatedMember();
  
      try {
        cm.validate();
      } catch ( ModelerException me ) {
        Assert.assertEquals( me.getMessage(), "Catalog name is required." );
      }
  
      try {
        cm.setPdiContext( true );
        cm.validate();
      } catch ( ModelerException me ) {
        Assert.assertEquals( me.getMessage(), "Measure name is required." );
      }
    }
  
    @BeforeClass
    public static void setUpBeforeClass() throws Exception {
      KettleClientEnvironment.init();
      PluginRegistry.addPluginType( StepPluginType.getInstance() );
      PluginRegistry.init();
      Props.init( 0 );
    }
  
    @Test
    public void testCreatesCalculatedMembersInAnalysisModel() throws Exception {
  