mil.dod.th.ose.gui.webapp/test/mil/dod/th/ose/gui/webapp/observation/TestObservationMgrImpl.java
@Test
    public void testObservationWithSelectedObject()
    {
        AssetModel model1 = mock(AssetModel.class);
        UUID uuid = UUID.randomUUID();
        when(model1.getUuid()).thenReturn(uuid);
        when(m_AssetDisplayHelper.getSelectedFactoryObject()).thenReturn(model1);
        
        //Returns list of uuids corresponding to the four observations
        //made. Therefore, position 0 in the list corresponds to o1 in
        //that method.
        List<Observation> expectedObs = new ArrayList<Observation>();
        
        UUID uuid1 = UUID.randomUUID();
        UUID uuid2 = UUID.randomUUID();
        UUID uuid3 = UUID.randomUUID();
        UUID uuid4 = UUID.randomUUID();

        expectedObs.add(createMockedObservation(uuid1, 4000L, true, ObservationSubTypeEnum.DETECTION));
        expectedObs.add(createMockedObservation(uuid2, 3000L, true, ObservationSubTypeEnum.WEATHER));
        expectedObs.add(createMockedObservation(uuid3, 2000L, true, ObservationSubTypeEnum.STATUS));
        expectedObs.add(createMockedObservation(uuid4, 2000L, true, ObservationSubTypeEnum.BIOLOGICAL));
        
        when(m_ObsQuery.execute()).thenReturn(expectedObs);
        
        when(m_AssetDisplayHelper.getSelectedFactoryObject()).thenReturn(model1);
        List<GuiObservation> listObs = m_SUT.getObservations().load(0, 10, null, null, null);
        
        //Since 2 has a newer timestamp than 0, it should be listed first
        assertThat(listObs.size(), is(4));
        assertThat(listObs.get(0).getObservation().getUuid(), is(uuid1));
        assertThat(listObs.get(0).getRelatedObservationModels().size(), is(1));

        assertThat(listObs.get(0).getRelatedObservationModels().get(0).getObservationSubType(), 
                is(ObservationSubTypeEnum.DETECTION));
        assertThat(listObs.get(1).getObservation().getUuid(), is(uuid2));
        assertThat(listObs.get(1).getRelatedObservationModels().size(), is(1));
        assertThat(listObs.get(1).getRelatedObservationModels().get(0).getObservationSubType(), 
                is(ObservationSubTypeEnum.WEATHER));
        assertThat(listObs.get(2).getObservation().getUuid(), is(uuid3));
        assertThat(listObs.get(2).getRelatedObservationModels().size(), is(1));
        assertThat(listObs.get(2).getRelatedObservationModels().get(0).getObservationSubType(), 
                is(ObservationSubTypeEnum.STATUS));
        assertThat(listObs.get(3).getObservation().getUuid(), is(uuid4));
        assertThat(listObs.get(3).getRelatedObservationModels().size(), is(1));
        assertThat(listObs.get(3).getRelatedObservationModels().get(0).getObservationSubType(), 
                is(ObservationSubTypeEnum.BIOLOGICAL));
        
        verify(m_ObsQuery).withAssetUuid(uuid);
        verify(m_ObsQuery).withRange(0, 10);
        verify(m_ObsQuery).execute();
        verify(m_ObsCount).getCount();
    }
/**
     * Verify that getting observations with specific model returns the correct observations.
     */
Verify that getting observations with specific model returns the correct observations.
Verify that getting observations with specific model returns the correct observations .
@Test
    public void testObservationWithSelectedObject()
    {
        AssetModel model1 = mock(AssetModel.class);
        UUID uuid = UUID.randomUUID();
        when(model1.getUuid()).thenReturn(uuid);
        when(m_AssetDisplayHelper.getSelectedFactoryObject()).thenReturn(model1);
        List<Observation> expectedObs = new ArrayList<Observation>();
        UUID uuid1 = UUID.randomUUID();
        UUID uuid2 = UUID.randomUUID();
        UUID uuid3 = UUID.randomUUID();
        UUID uuid4 = UUID.randomUUID();
        expectedObs.add(createMockedObservation(uuid1, 4000L, true, ObservationSubTypeEnum.DETECTION));
        expectedObs.add(createMockedObservation(uuid2, 3000L, true, ObservationSubTypeEnum.WEATHER));
        expectedObs.add(createMockedObservation(uuid3, 2000L, true, ObservationSubTypeEnum.STATUS));
        expectedObs.add(createMockedObservation(uuid4, 2000L, true, ObservationSubTypeEnum.BIOLOGICAL));
        when(m_ObsQuery.execute()).thenReturn(expectedObs);
        when(m_AssetDisplayHelper.getSelectedFactoryObject()).thenReturn(model1);
        List<GuiObservation> listObs = m_SUT.getObservations().load(0, 10, null, null, null);
        assertThat(listObs.size(), is(4));
        assertThat(listObs.get(0).getObservation().getUuid(), is(uuid1));
        assertThat(listObs.get(0).getRelatedObservationModels().size(), is(1));
        assertThat(listObs.get(0).getRelatedObservationModels().get(0).getObservationSubType(), 
                is(ObservationSubTypeEnum.DETECTION));
        assertThat(listObs.get(1).getObservation().getUuid(), is(uuid2));
        assertThat(listObs.get(1).getRelatedObservationModels().size(), is(1));
        assertThat(listObs.get(1).getRelatedObservationModels().get(0).getObservationSubType(), 
                is(ObservationSubTypeEnum.WEATHER));
        assertThat(listObs.get(2).getObservation().getUuid(), is(uuid3));
        assertThat(listObs.get(2).getRelatedObservationModels().size(), is(1));
        assertThat(listObs.get(2).getRelatedObservationModels().get(0).getObservationSubType(), 
                is(ObservationSubTypeEnum.STATUS));
        assertThat(listObs.get(3).getObservation().getUuid(), is(uuid4));
        assertThat(listObs.get(3).getRelatedObservationModels().size(), is(1));
        assertThat(listObs.get(3).getRelatedObservationModels().get(0).getObservationSubType(), 
                is(ObservationSubTypeEnum.BIOLOGICAL));
        verify(m_ObsQuery).withAssetUuid(uuid);
        verify(m_ObsQuery).withRange(0, 10);
        verify(m_ObsQuery).execute();
        verify(m_ObsCount).getCount();
    }
@ Test public void testObservationWithSelectedObject ( ) { AssetModel model1 = mock ( AssetModel . class ) ; UUID uuid = UUID . randomUUID ( ) ; when ( model1 . getUuid ( ) ) . thenReturn ( uuid ) ; when ( m_AssetDisplayHelper . getSelectedFactoryObject ( ) ) . thenReturn ( model1 ) ; List < Observation > expectedObs = new ArrayList < Observation > ( ) ; UUID uuid1 = UUID . randomUUID ( ) ; UUID uuid2 = UUID . randomUUID ( ) ; UUID uuid3 = UUID . randomUUID ( ) ; UUID uuid4 = UUID . randomUUID ( ) ; expectedObs . add ( createMockedObservation ( uuid1 , 4000L , true , ObservationSubTypeEnum . DETECTION ) ) ; expectedObs . add ( createMockedObservation ( uuid2 , 3000L , true , ObservationSubTypeEnum . WEATHER ) ) ; expectedObs . add ( createMockedObservation ( uuid3 , 2000L , true , ObservationSubTypeEnum . STATUS ) ) ; expectedObs . add ( createMockedObservation ( uuid4 , 2000L , true , ObservationSubTypeEnum . BIOLOGICAL ) ) ; when ( m_ObsQuery . execute ( ) ) . thenReturn ( expectedObs ) ; when ( m_AssetDisplayHelper . getSelectedFactoryObject ( ) ) . thenReturn ( model1 ) ; List < GuiObservation > listObs = m_SUT . getObservations ( ) . load ( 0 , 10 , null , null , null ) ; assertThat ( listObs . size ( ) , is ( 4 ) ) ; assertThat ( listObs . get ( 0 ) . getObservation ( ) . getUuid ( ) , is ( uuid1 ) ) ; assertThat ( listObs . get ( 0 ) . getRelatedObservationModels ( ) . size ( ) , is ( 1 ) ) ; assertThat ( listObs . get ( 0 ) . getRelatedObservationModels ( ) . get ( 0 ) . getObservationSubType ( ) , is ( ObservationSubTypeEnum . DETECTION ) ) ; assertThat ( listObs . get ( 1 ) . getObservation ( ) . getUuid ( ) , is ( uuid2 ) ) ; assertThat ( listObs . get ( 1 ) . getRelatedObservationModels ( ) . size ( ) , is ( 1 ) ) ; assertThat ( listObs . get ( 1 ) . getRelatedObservationModels ( ) . get ( 0 ) . getObservationSubType ( ) , is ( ObservationSubTypeEnum . WEATHER ) ) ; assertThat ( listObs . get ( 2 ) . getObservation ( ) . getUuid ( ) , is ( uuid3 ) ) ; assertThat ( listObs . get ( 2 ) . getRelatedObservationModels ( ) . size ( ) , is ( 1 ) ) ; assertThat ( listObs . get ( 2 ) . getRelatedObservationModels ( ) . get ( 0 ) . getObservationSubType ( ) , is ( ObservationSubTypeEnum . STATUS ) ) ; assertThat ( listObs . get ( 3 ) . getObservation ( ) . getUuid ( ) , is ( uuid4 ) ) ; assertThat ( listObs . get ( 3 ) . getRelatedObservationModels ( ) . size ( ) , is ( 1 ) ) ; assertThat ( listObs . get ( 3 ) . getRelatedObservationModels ( ) . get ( 0 ) . getObservationSubType ( ) , is ( ObservationSubTypeEnum . BIOLOGICAL ) ) ; verify ( m_ObsQuery ) . withAssetUuid ( uuid ) ; verify ( m_ObsQuery ) . withRange ( 0 , 10 ) ; verify ( m_ObsQuery ) . execute ( ) ; verify ( m_ObsCount ) . getCount ( ) ; }
Verify that getting observations with specific model returns the correct observations.
Verify that getting observations with specific model returns the correct observations .
//Returns list of uuids corresponding to the four observations //made. Therefore, position 0 in the list corresponds to o1 in //that method. //Since 2 has a newer timestamp than 0, it should be listed first