### Question:
MetadataService extends PentahoBase { public String doXmlQueryToCdaJson( String xml, int rowLimit ) { IPentahoResultSet resultSet = executeQuery( xml, rowLimit ); if ( resultSet == null ) { return null; } String json = null; try { MetadataServiceUtil util = getMetadataServiceUtil(); Domain domain = util.getDomainObject( xml ); util.setDomain( domain ); String locale = LocaleHelper.getClosestLocale( LocaleHelper.getLocale().toString(), domain.getLocaleCodes() ); json = util.createCdaJson( resultSet, locale ); } catch ( JSONException e ) { error( Messages.getErrorString( "MetadataService.ERROR_0007_JSON_ERROR" ), e ); } catch ( PentahoMetadataException e ) { error( Messages.getErrorString( "MetadataService.ERROR_0007_BAD_QUERY_DOMAIN" ), e ); } return json; } MetadataService(); @GET @Path( "/getDatasourcePermissions" ) @Produces( { APPLICATION_JSON } ) String getDatasourcePermissions(); ModelInfo[] listBusinessModels( String domainName ); String listBusinessModelsJson( String domainName ); Model loadModel( String domainId, String modelId ); String loadModelJson( String domainId, String modelId ); MarshallableResultSet doQuery( Query query, Integer rowLimit ); MarshallableResultSet doXmlQuery( String xml, Integer rowLimit ); String doXmlQueryToJson( String xml, int rowLimit ); String doXmlQueryToCdaJson( String xml, int rowLimit ); MarshallableResultSet doJsonQuery( String json, Integer rowLimit ); String doJsonQueryToJson( String json, int rowLimit ); String doJsonQueryToCdaJson( String json, int rowLimit ); @Override Log getLogger();  }### Answer:
@Test public void testDoXmlQueryToCdaJson() { String expectedQueryJson = "{\"metadata\":[{\"colName\":\"" + COLUMN_NAME + "\",\"colType\":\"" + DataType.STRING + "\",\"colIndex\":0," + "\"colLabel\":\"" + COLUMN_NAME + "\"}],\"resultset\":[[null],[null],[null],[null],[null],[null],[null],[null]," + "[null],[null]]}"; String xmlQuery = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><mql><domain_id>" + DOMAIN_ID + "</domain_id><model_id" + ">" + LOGICAL_MODEL_ID + "</model_id><options><disable_distinct>false</disable_distinct><limit>-1</limit></options" + "><parameters><parameter defaultValue=\"" + VALUE + "\" name=\"" + COLUMN_NAME + "\" " + "type=\"STRING\"/></parameters><selections><selection><view>" + CATEGORY_ID + "</view><column>" + COLUMN_ID + "</column" + "><aggregation>NONE</aggregation></selection></selections><constraints><constraint><operator>AND</operator" + "><condition>[" + CATEGORY_NAME + "." + COLUMN_NAME + "] = " + VALUE + "</condition></constraint></constraints><orders/></mql>"; try { when( metadataService.doXmlQuery( anyString(), any( Integer.class ) ) ).thenCallRealMethod(); when( metadataService.doXmlQueryToCdaJson( anyString(), anyInt() ) ).thenCallRealMethod(); when( metadataServiceUtil.createCdaJson( any( IPentahoResultSet.class ), anyString() ) ).thenCallRealMethod(); when( metadataServiceUtil.getDomainObject( anyString() ) ).thenCallRealMethod(); MarshallableResultSet marshallableResultSet = getMarshallableResultSet(); when( metadataService.getMarshallableResultSet() ).thenReturn( marshallableResultSet ); String queryJson = metadataService.doXmlQueryToCdaJson( xmlQuery, ROWS ); Assert.assertEquals( expectedQueryJson, queryJson ); } catch ( Exception ex ) { fail(); } }