Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TEST] Added unit tests for MetadataServiceUtil and MetadataService … #800

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public MetadataServiceUtil() {
* @return
*/
protected String getLocale() {
String locale = LocaleHelper.getClosestLocale( LocaleHelper.getLocale().toString(), domain.getLocaleCodes() );
String locale = LocaleHelper.getClosestLocale( LocaleHelper.getLocale().toString(), getDomain().getLocaleCodes() );
return locale;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public void initialize() {

metadataServiceUtil = mock( MetadataServiceUtil.class );
when( metadataServiceUtil.getMetadataRepository() ).thenReturn( iMetadataDomainRepository );
when( metadataServiceUtil.getCategory( anyString(), any( LogicalModel.class ) ) ).thenCallRealMethod();
when( metadataServiceUtil.createThinModel( any( LogicalModel.class ), anyString() ) ).thenCallRealMethod();
when( metadataService.getMetadataServiceUtil() ).thenReturn( metadataServiceUtil );
}
Expand Down Expand Up @@ -232,7 +233,6 @@ public void testDoQuery() {
when( metadataService.doQuery( any( Query.class ), anyInt() ) ).thenCallRealMethod();
when( metadataService.doXmlQuery( anyString(), any( Integer.class ) ) ).thenCallRealMethod();
when( metadataServiceUtil.convertQuery( any( Query.class ) ) ).thenCallRealMethod();
when( metadataServiceUtil.getCategory( anyString(), any( LogicalModel.class ) ) ).thenCallRealMethod();

MarshallableResultSet marshallableResultSet = getMarshallableResultSet();
when( metadataService.getMarshallableResultSet() ).thenReturn( marshallableResultSet );
Expand Down Expand Up @@ -323,6 +323,37 @@ public void testDoXmlQueryToCdaJson() {

}

@Test
public void testGetQueryXmlFromJson() {

final String jsonQuery = "{\"columns\": [ {\"id\":\"" + COLUMN_NAME + "\", \"name\":\"" + COLUMN_ID
+ "\", \"selectedAggType\":\"" + AggregationType.NONE.toString() + "\", \"category\":\"" + CATEGORY_ID + "\", \"class\":\"org.pentaho.platform.dataaccess.metadata.model.impl.Column\"}],"
+ "\"conditions\":[],"
+ "\"orders\":[ {\"column\":\"" + COLUMN_ID + "\", \"orderType\":\"" + org.pentaho.metadata.query.model.Order.Type.ASC.toString() + "\","
+ "\"class\":\"org.pentaho.platform.dataaccess.metadata.model.impl.Order\"}],"
+ "\"parameters\":[ {\"column\":\"" + COLUMN_NAME + "\", \"value\":[\"" + VALUE + "\"],"
+ "\"class\":\"org.pentaho.platform.dataaccess.metadata.model.impl.Parameter\"}],"
+ "\"class\":\"org.pentaho.platform.dataaccess.metadata.model.impl.Query\",\"domainName\":\"" + DOMAIN_ID + "\","
+ "\"modelId\":\"" + LOGICAL_MODEL_ID + "\",\"disableDistinct\":null,\"defaultParameterMap\":null}";

final String expectedXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><mql><domain_id>DOMAIN_ID</domain_id"
+ "><model_id>MODEL_ID</model_id><options><disable_distinct>false</disable_distinct><limit>-1</limit></options"
+ "><parameters><parameter defaultValue=\"VALUE1\" name=\"COLUMN_NAME\" "
+ "type=\"STRING\"/></parameters><selections><selection><view>CATEGORY_ID</view><column>COLUMN_ID</column"
+ "><aggregation>NONE</aggregation></selection></selections><constraints/><orders><order><direction>ASC"
+ "</direction><view_id>CATEGORY_ID</view_id><column_id>COLUMN_ID</column_id><aggregation>NONE</aggregation"
+ "></order></orders></mql>";

when( metadataServiceUtil.deserializeJsonQuery( anyString() ) ).thenCallRealMethod();
when( metadataServiceUtil.convertQuery( any( Query.class ) ) ).thenCallRealMethod();
when( metadataService.getQueryXmlFromJson( anyString() ) ).thenCallRealMethod();

String xmlFromJson = metadataService.getQueryXmlFromJson( jsonQuery );

Assert.assertTrue( expectedXml.equals( xmlFromJson ) );

}

private MarshallableResultSet getMarshallableResultSet() {

//Build the IPentahoResultSet
Expand Down
Loading