//	Paging
  @Test
  public void testPageListOfAssets() throws Exception {

    // add 3 stories
    Asset storyAsset = createDisposableStory();
    storyAsset.setAttributeValue(nameDef, "Paging Test - Story1");
    storyAsset.setAttributeValue(scopeDef, APIClientLegacyIntegrationTestSuiteIT.get_projectId());
    services.save(storyAsset);
    storyAsset = createDisposableStory();
    storyAsset.setAttributeValue(nameDef, "Paging Test - Story2");
    storyAsset.setAttributeValue(scopeDef, APIClientLegacyIntegrationTestSuiteIT.get_projectId());
    services.save(storyAsset);
    storyAsset = createDisposableStory();
    storyAsset.setAttributeValue(nameDef, "Paging Test - Story3");
    storyAsset.setAttributeValue(scopeDef, APIClientLegacyIntegrationTestSuiteIT.get_projectId());
    services.save(storyAsset);

    Query query = new Query(storyType);
    IAttributeDefinition nameAttribute = storyType.getAttributeDefinition("Name");
    IAttributeDefinition estimateAttribute = storyType.getAttributeDefinition("Estimate");
    query.getSelection().add(nameAttribute);
    query.getSelection().add(estimateAttribute);
    QueryResult result = services.retrieve(query);

    Assert.assertTrue(result.getAssets().length > 2);

    query.getPaging().setPageSize(2);
    query.getPaging().setStart(0);
    result = services.retrieve(query);

    Assert.assertTrue(result.getAssets().length == 2);
  }
  // asof
  @Test
  @Ignore
  public void testAsof() throws Exception {
    Asset storyAsset = createDisposableStory();
    storyAsset.setAttributeValue(nameDef, "Test Asof");
    storyAsset.setAttributeValue(scopeDef, APIClientLegacyIntegrationTestSuiteIT.get_projectId());
    services.save(storyAsset);

    IAssetType storyType = metaModel.getAssetType("Story");
    Query query = new Query(storyType, true);
    IAttributeDefinition nameAttribute = storyType.getAttributeDefinition("Name");
    IAttributeDefinition createDateAttribute = storyType.getAttributeDefinition("CreateDate");

    query.getSelection().add(nameAttribute);
    query.getSelection().add(createDateAttribute);
    AttributeSelection selection = new AttributeSelection();
    selection.add(nameAttribute);
    query.setFind(new QueryFind("Test Asof", selection));
    Date date = (Date) Calendar.getInstance().getTime();
    query.setAsOf(date);
    QueryResult result = services.retrieve(query);

    //	Assert.assertNotNull(result);

    Assert.assertEquals(
        "Test Asof", result.getAssets()[0].getAttribute(nameAttribute).getValue().toString());
  }
  // Sort query
  @Test
  public void testSortStories() throws Exception {

    // add 3 stories
    Asset storyAsset = createDisposableStory();
    storyAsset.setAttributeValue(nameDef, "MM-Story");
    storyAsset.setAttributeValue(scopeDef, APIClientLegacyIntegrationTestSuiteIT.get_projectId());
    services.save(storyAsset);
    storyAsset = createDisposableStory();
    storyAsset.setAttributeValue(nameDef, "AA-Story");
    storyAsset.setAttributeValue(scopeDef, APIClientLegacyIntegrationTestSuiteIT.get_projectId());
    services.save(storyAsset);
    storyAsset = createDisposableStory();
    storyAsset.setAttributeValue(nameDef, "HH-Story");
    storyAsset.setAttributeValue(scopeDef, APIClientLegacyIntegrationTestSuiteIT.get_projectId());
    services.save(storyAsset);

    IAssetType storyType = metaModel.getAssetType("Story");
    Query query = new Query(storyType);
    IAttributeDefinition nameAttribute = storyType.getAttributeDefinition("Name");
    query.getSelection().add(nameAttribute);
    query.getOrderBy().minorSort(nameAttribute, Order.Ascending);

    QueryResult result = services.retrieve(query);

    Asset first_story = result.getAssets()[0];

    Assert.assertEquals("AA-Story", first_story.getAttribute(nameAttribute).getValue().toString());
  }
  // Query for multiple assets
  @Test
  public void testQueryMultipleAsset() throws Exception {

    Query query = new Query(storyType);
    IAttributeDefinition nameAttribute = storyType.getAttributeDefinition("Name");
    IAttributeDefinition estimateAttribute = storyType.getAttributeDefinition("Estimate");
    query.getSelection().add(nameAttribute);
    query.getSelection().add(estimateAttribute);
    QueryResult result = services.retrieve(query);

    Assert.assertNotNull(result.getAssets());

    Assert.assertTrue(result.getAssets().length > 1);
  }
  @BeforeClass
  public static void beforeClass() {

    metaModel = APIClientLegacyIntegrationTestSuiteIT.get_metaModel();
    services = APIClientLegacyIntegrationTestSuiteIT.get_services();
    storyType = metaModel.getAssetType("Story");

    nameDef = storyType.getAttributeDefinition("Name");
    scopeDef = storyType.getAttributeDefinition("Scope");
    momentDef = storyType.getAttributeDefinition("Moment");
    attributesToQuery = new LinkedList<IAttributeDefinition>();
    attributesToQuery.add(nameDef);
    attributesToQuery.add(scopeDef);
    attributesToQuery.add(momentDef);
  }
  // Filter query // Find query
  @Test
  @Ignore
  public void testFindInAQuery() throws Exception {

    Asset newStoryUrgent =
        createDisposableStory(); // services.createNew(storyType,
                                 // APIClientIntegrationTestSuiteIT.get_projectId());
    IAttributeDefinition nameAttribute = storyType.getAttributeDefinition("Name");
    newStoryUrgent.setAttributeValue(
        nameAttribute, "FindAndQueryTest: Find in a Query - Urgent story");
    services.save(newStoryUrgent);

    Asset newStory =
        createDisposableStory(); // services.createNew(storyType,
                                 // APIClientIntegrationTestSuiteIT.get_projectId());
    nameAttribute = storyType.getAttributeDefinition("Name");
    newStory.setAttributeValue(nameAttribute, "FindAndQueryTest: Find in a Query - Common story");
    services.save(newStory);
    //		query
    IAssetType requestType = metaModel.getAssetType("Story");
    Query query = new Query(requestType);
    IAttributeDefinition nameAttributeToQuery = requestType.getAttributeDefinition("Name");
    query.getSelection().add(nameAttributeToQuery);

    //		find
    IAttributeDefinition nameAttributeToFindQuery = requestType.getAttributeDefinition("Name");
    AttributeSelection selection = new AttributeSelection();
    selection.add(nameAttributeToFindQuery);
    query.setFind(new QueryFind("Urgent", selection));
    QueryResult result = services.retrieve(query);
    Asset urgentStory = result.getAssets()[0];

    Assert.assertEquals(
        "FindAndQueryTest: Find in a Query - Urgent story",
        urgentStory.getAttribute(nameAttribute).getValue().toString());
  }