/*
// $Id$
// This software is subject to the terms of the Eclipse Public License v1.0
// Agreement, available at the following URL:
// http://www.eclipse.org/legal/epl-v10.html.
// Copyright (C) 2007-2010 Julian Hyde and others
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
package mondrian.rolap;

import mondrian.test.FoodMartTestCase;
import mondrian.olap.*;

/**
 * Test case for '&amp;[..]' capability in MDX identifiers.
 *
 * @author pierluiggi@users.sourceforge.net
 * @version $Id$
 */
public class IndexedValuesTest extends FoodMartTestCase {
    public IndexedValuesTest(final String name) {
        super(name);
    }

    public IndexedValuesTest() {
        super();
    }

    public void testQueryWithIndex() {
        final Connection conn = getConnection();

        // Query using name
        final String queryStr1 =
            "SELECT {[Measures].[Org Salary], [Measures].[Count]} "
            + "ON COLUMNS, "
            + "{[Employees].[Sheri Nowmer]} "
            + "ON ROWS FROM [HR]";
        final Query query1 = conn.parseQuery(queryStr1);
        final Result result1 = conn.execute(query1);

        // Query using key
        final String queryStr2 =
            "SELECT {[Measures].[Org Salary], [Measures].[Count]} "
            + "ON COLUMNS, "
            + "{[Employees].&[1]} "
            + "ON ROWS FROM [HR]";
        final Query query2 = conn.parseQuery(queryStr2);
        final Result result2 = conn.execute(query2);

        // Results of two previous queries must be the same
        assertEquals(
            result2.getCell(new int[] {0, 0}).getValue(),
            result1.getCell(new int[] {0, 0}).getValue());
        assertEquals(
            result2.getCell(new int[] {1, 0}).getValue(),
            result1.getCell(new int[] {1, 0}).getValue());
    }

}

// End IndexedValuesTest.java

@@ -385,32 +385,8 @@
 ase;
-%0Aimport mondrian.olap.*;
 %0A%0A/*
@@ -765,41 +765,329 @@
 nal 
-Connection conn = getConnection()
+String desiredResult =%0A            %22Axis #0:%5Cn%22%0A            + %22%7B%7D%5Cn%22%0A            + %22Axis #1:%5Cn%22%0A            + %22%7B%5BMeasures%5D.%5BOrg Salary%5D%7D%5Cn%22%0A            + %22%7B%5BMeasures%5D.%5BCount%5D%7D%5Cn%22%0A            + %22Axis #2:%5Cn%22%0A            + %22%7B%5BEmployees%5D.%5BSheri Nowmer%5D%7D%5Cn%22%0A            + %22Row #0: $39,431.67%5Cn%22%0A            + %22Row #0: 7,392%5Cn%22
 ;%0A%0A 
@@ -1125,32 +1125,27 @@
     
-final String queryStr1 =
+assertQueryReturns(
 %0A   
@@ -1309,33 +1309,33 @@
  ROWS FROM %5BHR%5D%22
-;
+,
 %0A        final Q
@@ -1331,170 +1331,104 @@
     
-final Query query1 = conn.parseQuery(queryStr1);%0A        final Result result1 = conn.execute(query1);%0A%0A        // Query using key%0A        final String queryStr2 =
+    desiredResult);%0A%0A        // Query using key; expect same result.%0A        assertQueryReturns(
 %0A   
@@ -1590,17 +1590,17 @@
 OM %5BHR%5D%22
-;
+,
 %0A       
@@ -1604,65 +1604,37 @@
     
-final Query query2 = conn.parseQuery(queryStr2
+    desiredResult
 );%0A
+%0A
         
 fina
@@ -1633,113 +1633,98 @@
     
-final Resul
+// Cannot find members tha
 t 
+a
 re
-sult2 = conn.execute(query2);%0A%0A        // Results of two previous queries must be the same
+ not at root of hierarchy.%0A        // (We should fix this.)
 %0A   
@@ -1726,37 +1726,42 @@
 )%0A        assert
-Equal
+QueryThrow
 s(%0A            r
@@ -1763,112 +1763,311 @@
     
-result2.getCell(new int%5B%5D %7B0, 0%7D).getValue(),%0A            result1.getCell(new int%5B%5D %7B0, 0%7D).getValue());
+%22SELECT %7B%5BMeasures%5D.%5BOrg Salary%5D, %5BMeasures%5D.%5BCount%5D%7D %22%0A            + %22ON COLUMNS, %22%0A            + %22%7B%5BEmployees%5D.&%5B4%5D%7D %22%0A            + %22ON ROWS FROM %5BHR%5D%22,%0A            %22MDX object '%5BEmployees%5D.&%5B4%5D' not found in cube 'HR'%22);%0A%0A        // %22level.&key%22 syntax not supported%0A        // (We should fix this.)
 %0A   
@@ -2081,13 +2081,18 @@
 sert
-Equal
+QueryThrow
 s(%0A 
@@ -2106,110 +2106,194 @@
     
-result2.getCell(new int%5B%5D %7B1, 0%7D).getValue(),%0A            result1.getCell(new int%5B%5D %7B1, 0%7D).getValue()
+%22SELECT %5BMeasures%5D ON COLUMNS, %22%0A            + %22%7B%5BProduct%5D.%5BProduct Name%5D.&%5B9%5D%7D %22%0A            + %22ON ROWS FROM %5BSales%5D%22,%0A            %22MDX object '%5BEmployees%5D.&%5B4%5D' not found in cube 'HR'%22
 );%0A 
@@ -2297,17 +2297,16 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A%0A// En

Rework test case to illustrate how limited the current implementation of '&' key segments is.