mil.dod.th.ose.core.integration/src/mil/dod/th/ose/core/integration/TestPersistence.java
public void testObservationQuerySortField()
        throws ValidationFailedException, IllegalArgumentException, PersistenceFailedException
    {
        List<Observation> expectedObs = new ArrayList<>();
        for (int i = 1; i < 4; i++)
        {
            Observation obs = createObservation();
            obs.setCreatedTimestamp((long)i);
            obs.setObservedTimestamp((long)(4-i));
            expectedObs.add(obs);
            m_ObservationStore.persist(expectedObs.get(i-1));
        }
        
        List<Observation> actualObs = new ArrayList<>(m_ObservationStore.newQuery().withAssetType(ASSETTYPE).execute());
        
        // verify default is descending (first is newest, last created)
        assertThat(actualObs.size(), is(expectedObs.size()));
        JaxbUtil.assertEqualContent(actualObs.get(0), expectedObs.get(2));
        JaxbUtil.assertEqualContent(actualObs.get(1), expectedObs.get(1));
        JaxbUtil.assertEqualContent(actualObs.get(2), expectedObs.get(0));
        
        // try again with ascending order
        actualObs = new ArrayList<>(m_ObservationStore.newQuery()
                .withAssetType(ASSETTYPE).withOrder(SortField.ObservedTimestamp, SortOrder.Descending).execute());
        
        // verify now ascending (first is oldest, first created)
        assertThat(actualObs.size(), is(expectedObs.size()));
        JaxbUtil.assertEqualContent(actualObs.get(0), expectedObs.get(0));
        JaxbUtil.assertEqualContent(actualObs.get(1), expectedObs.get(1));
        JaxbUtil.assertEqualContent(actualObs.get(2), expectedObs.get(2));
    }
/**
     * Verify can change sorting field in query to get collection back.
     */
Verify can change sorting field in query to get collection back.
Verify can change sorting field in query to get collection back .
public void testObservationQuerySortField()
        throws ValidationFailedException, IllegalArgumentException, PersistenceFailedException
    {
        List<Observation> expectedObs = new ArrayList<>();
        for (int i = 1; i < 4; i++)
        {
            Observation obs = createObservation();
            obs.setCreatedTimestamp((long)i);
            obs.setObservedTimestamp((long)(4-i));
            expectedObs.add(obs);
            m_ObservationStore.persist(expectedObs.get(i-1));
        }
        List<Observation> actualObs = new ArrayList<>(m_ObservationStore.newQuery().withAssetType(ASSETTYPE).execute());
        assertThat(actualObs.size(), is(expectedObs.size()));
        JaxbUtil.assertEqualContent(actualObs.get(0), expectedObs.get(2));
        JaxbUtil.assertEqualContent(actualObs.get(1), expectedObs.get(1));
        JaxbUtil.assertEqualContent(actualObs.get(2), expectedObs.get(0));
        actualObs = new ArrayList<>(m_ObservationStore.newQuery()
                .withAssetType(ASSETTYPE).withOrder(SortField.ObservedTimestamp, SortOrder.Descending).execute());
        assertThat(actualObs.size(), is(expectedObs.size()));
        JaxbUtil.assertEqualContent(actualObs.get(0), expectedObs.get(0));
        JaxbUtil.assertEqualContent(actualObs.get(1), expectedObs.get(1));
        JaxbUtil.assertEqualContent(actualObs.get(2), expectedObs.get(2));
    }
public void testObservationQuerySortField ( ) throws ValidationFailedException , IllegalArgumentException , PersistenceFailedException { List < Observation > expectedObs = new ArrayList < > ( ) ; for ( int i = 1 ; i < 4 ; i ++ ) { Observation obs = createObservation ( ) ; obs . setCreatedTimestamp ( ( long ) i ) ; obs . setObservedTimestamp ( ( long ) ( 4 - i ) ) ; expectedObs . add ( obs ) ; m_ObservationStore . persist ( expectedObs . get ( i - 1 ) ) ; } List < Observation > actualObs = new ArrayList < > ( m_ObservationStore . newQuery ( ) . withAssetType ( ASSETTYPE ) . execute ( ) ) ; assertThat ( actualObs . size ( ) , is ( expectedObs . size ( ) ) ) ; JaxbUtil . assertEqualContent ( actualObs . get ( 0 ) , expectedObs . get ( 2 ) ) ; JaxbUtil . assertEqualContent ( actualObs . get ( 1 ) , expectedObs . get ( 1 ) ) ; JaxbUtil . assertEqualContent ( actualObs . get ( 2 ) , expectedObs . get ( 0 ) ) ; actualObs = new ArrayList < > ( m_ObservationStore . newQuery ( ) . withAssetType ( ASSETTYPE ) . withOrder ( SortField . ObservedTimestamp , SortOrder . Descending ) . execute ( ) ) ; assertThat ( actualObs . size ( ) , is ( expectedObs . size ( ) ) ) ; JaxbUtil . assertEqualContent ( actualObs . get ( 0 ) , expectedObs . get ( 0 ) ) ; JaxbUtil . assertEqualContent ( actualObs . get ( 1 ) , expectedObs . get ( 1 ) ) ; JaxbUtil . assertEqualContent ( actualObs . get ( 2 ) , expectedObs . get ( 2 ) ) ; }
Verify can change sorting field in query to get collection back.
Verify can change sorting field in query to get collection back .
// verify default is descending (first is newest, last created) // try again with ascending order // verify now ascending (first is oldest, first created)