mil.dod.th.ose.gui.webapp/test/mil/dod/th/ose/gui/webapp/observation/TestObservationMgrImpl.java
@Test
    public void testObservationLazyLoading()
    {
        List<Observation> obs = new ArrayList<>();
        for (int i = 0; i < 20; i++)
        {
            obs.add(createMockedObservation(UUID.randomUUID(), (long)i, true, ObservationSubTypeEnum.DETECTION));
        }
        
        ObservationQuery query = mock(ObservationQuery.class);
        when(m_ObservationStore.newQuery()).thenReturn(query);
        
        when(query.withRange(Mockito.anyInt(), Mockito.anyInt())).thenReturn(query);
        when(query.execute()).thenReturn(obs.subList(16, 20));

        // simple, start at 0
        List<GuiObservation> listObs = m_SUT.getObservations().load(0, 4, null, null, null);
        assertThat(listObs.size(), is(4));
        assertThat(listObs.get(3).getObservation().getUuid(), is(obs.get(19).getUuid()));
        assertThat(listObs.get(2).getObservation().getUuid(), is(obs.get(18).getUuid()));
        assertThat(listObs.get(1).getObservation().getUuid(), is(obs.get(17).getUuid()));
        assertThat(listObs.get(0).getObservation().getUuid(), is(obs.get(16).getUuid()));
        
        // start at the 3rd newest (0 based)
        when(query.execute()).thenReturn(obs.subList(14, 17));
        listObs = m_SUT.getObservations().load(3, 3, null, null, null);
        assertThat(listObs.size(), is(3));
        assertThat(listObs.get(2).getObservation().getUuid(), is(obs.get(16).getUuid()));
        assertThat(listObs.get(1).getObservation().getUuid(), is(obs.get(15).getUuid()));
        assertThat(listObs.get(0).getObservation().getUuid(), is(obs.get(14).getUuid()));
        
        // start at the 15th newest with 10 per page, but there is only 20 total
        when(query.execute()).thenReturn(obs.subList(0, 5));
        listObs = m_SUT.getObservations().load(15, 10, null, null, null);
        assertThat(listObs.size(), is(5));
        assertThat(listObs.get(4).getObservation().getUuid(), is(obs.get(4).getUuid()));
        assertThat(listObs.get(3).getObservation().getUuid(), is(obs.get(3).getUuid()));
        assertThat(listObs.get(2).getObservation().getUuid(), is(obs.get(2).getUuid()));
        assertThat(listObs.get(1).getObservation().getUuid(), is(obs.get(1).getUuid()));
        assertThat(listObs.get(0).getObservation().getUuid(), is(obs.get(0).getUuid()));
    }
/**
     * Verify that only the appropriate observations are loaded based on the page settings
     */
Verify that only the appropriate observations are loaded based on the page settings
Verify that only the appropriate observations are loaded based on the page settings
@Test
    public void testObservationLazyLoading()
    {
        List<Observation> obs = new ArrayList<>();
        for (int i = 0; i < 20; i++)
        {
            obs.add(createMockedObservation(UUID.randomUUID(), (long)i, true, ObservationSubTypeEnum.DETECTION));
        }
        ObservationQuery query = mock(ObservationQuery.class);
        when(m_ObservationStore.newQuery()).thenReturn(query);
        when(query.withRange(Mockito.anyInt(), Mockito.anyInt())).thenReturn(query);
        when(query.execute()).thenReturn(obs.subList(16, 20));
        List<GuiObservation> listObs = m_SUT.getObservations().load(0, 4, null, null, null);
        assertThat(listObs.size(), is(4));
        assertThat(listObs.get(3).getObservation().getUuid(), is(obs.get(19).getUuid()));
        assertThat(listObs.get(2).getObservation().getUuid(), is(obs.get(18).getUuid()));
        assertThat(listObs.get(1).getObservation().getUuid(), is(obs.get(17).getUuid()));
        assertThat(listObs.get(0).getObservation().getUuid(), is(obs.get(16).getUuid()));
        when(query.execute()).thenReturn(obs.subList(14, 17));
        listObs = m_SUT.getObservations().load(3, 3, null, null, null);
        assertThat(listObs.size(), is(3));
        assertThat(listObs.get(2).getObservation().getUuid(), is(obs.get(16).getUuid()));
        assertThat(listObs.get(1).getObservation().getUuid(), is(obs.get(15).getUuid()));
        assertThat(listObs.get(0).getObservation().getUuid(), is(obs.get(14).getUuid()));
        when(query.execute()).thenReturn(obs.subList(0, 5));
        listObs = m_SUT.getObservations().load(15, 10, null, null, null);
        assertThat(listObs.size(), is(5));
        assertThat(listObs.get(4).getObservation().getUuid(), is(obs.get(4).getUuid()));
        assertThat(listObs.get(3).getObservation().getUuid(), is(obs.get(3).getUuid()));
        assertThat(listObs.get(2).getObservation().getUuid(), is(obs.get(2).getUuid()));
        assertThat(listObs.get(1).getObservation().getUuid(), is(obs.get(1).getUuid()));
        assertThat(listObs.get(0).getObservation().getUuid(), is(obs.get(0).getUuid()));
    }
@ Test public void testObservationLazyLoading ( ) { List < Observation > obs = new ArrayList < > ( ) ; for ( int i = 0 ; i < 20 ; i ++ ) { obs . add ( createMockedObservation ( UUID . randomUUID ( ) , ( long ) i , true , ObservationSubTypeEnum . DETECTION ) ) ; } ObservationQuery query = mock ( ObservationQuery . class ) ; when ( m_ObservationStore . newQuery ( ) ) . thenReturn ( query ) ; when ( query . withRange ( Mockito . anyInt ( ) , Mockito . anyInt ( ) ) ) . thenReturn ( query ) ; when ( query . execute ( ) ) . thenReturn ( obs . subList ( 16 , 20 ) ) ; List < GuiObservation > listObs = m_SUT . getObservations ( ) . load ( 0 , 4 , null , null , null ) ; assertThat ( listObs . size ( ) , is ( 4 ) ) ; assertThat ( listObs . get ( 3 ) . getObservation ( ) . getUuid ( ) , is ( obs . get ( 19 ) . getUuid ( ) ) ) ; assertThat ( listObs . get ( 2 ) . getObservation ( ) . getUuid ( ) , is ( obs . get ( 18 ) . getUuid ( ) ) ) ; assertThat ( listObs . get ( 1 ) . getObservation ( ) . getUuid ( ) , is ( obs . get ( 17 ) . getUuid ( ) ) ) ; assertThat ( listObs . get ( 0 ) . getObservation ( ) . getUuid ( ) , is ( obs . get ( 16 ) . getUuid ( ) ) ) ; when ( query . execute ( ) ) . thenReturn ( obs . subList ( 14 , 17 ) ) ; listObs = m_SUT . getObservations ( ) . load ( 3 , 3 , null , null , null ) ; assertThat ( listObs . size ( ) , is ( 3 ) ) ; assertThat ( listObs . get ( 2 ) . getObservation ( ) . getUuid ( ) , is ( obs . get ( 16 ) . getUuid ( ) ) ) ; assertThat ( listObs . get ( 1 ) . getObservation ( ) . getUuid ( ) , is ( obs . get ( 15 ) . getUuid ( ) ) ) ; assertThat ( listObs . get ( 0 ) . getObservation ( ) . getUuid ( ) , is ( obs . get ( 14 ) . getUuid ( ) ) ) ; when ( query . execute ( ) ) . thenReturn ( obs . subList ( 0 , 5 ) ) ; listObs = m_SUT . getObservations ( ) . load ( 15 , 10 , null , null , null ) ; assertThat ( listObs . size ( ) , is ( 5 ) ) ; assertThat ( listObs . get ( 4 ) . getObservation ( ) . getUuid ( ) , is ( obs . get ( 4 ) . getUuid ( ) ) ) ; assertThat ( listObs . get ( 3 ) . getObservation ( ) . getUuid ( ) , is ( obs . get ( 3 ) . getUuid ( ) ) ) ; assertThat ( listObs . get ( 2 ) . getObservation ( ) . getUuid ( ) , is ( obs . get ( 2 ) . getUuid ( ) ) ) ; assertThat ( listObs . get ( 1 ) . getObservation ( ) . getUuid ( ) , is ( obs . get ( 1 ) . getUuid ( ) ) ) ; assertThat ( listObs . get ( 0 ) . getObservation ( ) . getUuid ( ) , is ( obs . get ( 0 ) . getUuid ( ) ) ) ; }
Verify that only the appropriate observations are loaded based on the page settings
Verify that only the appropriate observations are loaded based on the page settings
// simple, start at 0 // start at the 3rd newest (0 based) // start at the 15th newest with 10 per page, but there is only 20 total