mil.dod.th.ose.gui.webapp/test/mil/dod/th/ose/gui/webapp/observation/TestGuiObservation.java
@Test
    public void testFindRelatedObservationOfRelation()
    {
        Observation obs = mock(Observation.class);
        
        ObservationRef obsRefChild = mock(ObservationRef.class);
        Relationship childRel = new Relationship();
        childRel.setRelationshipType(RelationshipTypeEnum.CHILD);
        when(obsRefChild.getRelationship()).thenReturn(childRel);
        
        ObservationRef obsRefPeer = mock(ObservationRef.class);
        Relationship peerRel = new Relationship();
        peerRel.setRelationshipType(RelationshipTypeEnum.PEER);
        when(obsRefPeer.getRelationship()).thenReturn(peerRel);
        
        ObservationRef obsRefParent = mock(ObservationRef.class);
        Relationship parentRel = new Relationship();
        parentRel.setRelationshipType(RelationshipTypeEnum.PARENT);
        when(obsRefParent.getRelationship()).thenReturn(parentRel);
        
        List<ObservationRef> ref = new ArrayList<>();
        ref.add(obsRefChild);
        when(obs.getRelatedObservations()).thenReturn(ref);
        
        List<Boolean> foundList = new ArrayList<>();
        foundList.add(true);
        foundList.add(true);

        List<ObservationSubTypeEnum> typeList = new ArrayList<>();
        typeList.add(ObservationSubTypeEnum.DIGITAL_MEDIA);
        typeList.add(ObservationSubTypeEnum.DETECTION);
        
        List<RelatedObservationIdentity> obsReferences = makeListOfRelatedObservation(foundList, typeList);
        
        m_SUT = new GuiObservation(obs, obsReferences);
        
        List<Integer> indexes = m_SUT.findRelatedObservationOfRelation(RelationshipTypeEnum.CHILD);
        assertThat(indexes.size(), is(1));
        assertThat(indexes.get(0), is(0));
        assertThat(m_SUT.findRelatedObservationOfRelation(RelationshipTypeEnum.PEER).size(), is(0));
        assertThat(m_SUT.findRelatedObservationOfRelation(RelationshipTypeEnum.PARENT).size(), is(0));
        
        ref.clear();
        ref.add(obsRefPeer);
        
        when(obs.getRelatedObservations()).thenReturn(ref);
        m_SUT = new GuiObservation(obs, obsReferences);
        
        indexes = m_SUT.findRelatedObservationOfRelation(RelationshipTypeEnum.PEER);
        assertThat(indexes.size(), is(1));
        assertThat(indexes.get(0), is(0));
        assertThat(m_SUT.findRelatedObservationOfRelation(RelationshipTypeEnum.CHILD).size(), is(0));
        assertThat(m_SUT.findRelatedObservationOfRelation(RelationshipTypeEnum.PARENT).size(), is(0));
        
        ref.clear();
        ref.add(obsRefParent);
        
        when(obs.getRelatedObservations()).thenReturn(ref);
        m_SUT = new GuiObservation(obs, obsReferences);
        
        indexes = m_SUT.findRelatedObservationOfRelation(RelationshipTypeEnum.PARENT);
        assertThat(indexes.size(), is(1));
        assertThat(indexes.get(0), is(0));
        assertThat(m_SUT.findRelatedObservationOfRelation(RelationshipTypeEnum.CHILD).size(), is(0));
        assertThat(m_SUT.findRelatedObservationOfRelation(RelationshipTypeEnum.PEER).size(), is(0));
        
        ref.clear();
        ref.add(obsRefPeer);
        ref.add(obsRefChild);
        ref.add(obsRefParent);
        
        when(obs.getRelatedObservations()).thenReturn(ref);
        m_SUT = new GuiObservation(obs, obsReferences);
        
        indexes = m_SUT.findRelatedObservationOfRelation(RelationshipTypeEnum.PARENT);
        assertThat(indexes.size(), is(1));
        assertThat(indexes.get(0), is(2));
        indexes = m_SUT.findRelatedObservationOfRelation(RelationshipTypeEnum.CHILD);
        assertThat(indexes.size(), is(1));
        assertThat(indexes.get(0), is(1));
        indexes = m_SUT.findRelatedObservationOfRelation(RelationshipTypeEnum.PEER);
        assertThat(indexes.size(), is(1));
        assertThat(indexes.get(0), is(0));
    }
/**
     * Verify that observation references can be retrieved by type.
     */
Verify that observation references can be retrieved by type.
Verify that observation references can be retrieved by type .
@Test
    public void testFindRelatedObservationOfRelation()
    {
        Observation obs = mock(Observation.class);
        ObservationRef obsRefChild = mock(ObservationRef.class);
        Relationship childRel = new Relationship();
        childRel.setRelationshipType(RelationshipTypeEnum.CHILD);
        when(obsRefChild.getRelationship()).thenReturn(childRel);
        ObservationRef obsRefPeer = mock(ObservationRef.class);
        Relationship peerRel = new Relationship();
        peerRel.setRelationshipType(RelationshipTypeEnum.PEER);
        when(obsRefPeer.getRelationship()).thenReturn(peerRel);
        ObservationRef obsRefParent = mock(ObservationRef.class);
        Relationship parentRel = new Relationship();
        parentRel.setRelationshipType(RelationshipTypeEnum.PARENT);
        when(obsRefParent.getRelationship()).thenReturn(parentRel);
        List<ObservationRef> ref = new ArrayList<>();
        ref.add(obsRefChild);
        when(obs.getRelatedObservations()).thenReturn(ref);
        List<Boolean> foundList = new ArrayList<>();
        foundList.add(true);
        foundList.add(true);
        List<ObservationSubTypeEnum> typeList = new ArrayList<>();
        typeList.add(ObservationSubTypeEnum.DIGITAL_MEDIA);
        typeList.add(ObservationSubTypeEnum.DETECTION);
        List<RelatedObservationIdentity> obsReferences = makeListOfRelatedObservation(foundList, typeList);
        m_SUT = new GuiObservation(obs, obsReferences);
        List<Integer> indexes = m_SUT.findRelatedObservationOfRelation(RelationshipTypeEnum.CHILD);
        assertThat(indexes.size(), is(1));
        assertThat(indexes.get(0), is(0));
        assertThat(m_SUT.findRelatedObservationOfRelation(RelationshipTypeEnum.PEER).size(), is(0));
        assertThat(m_SUT.findRelatedObservationOfRelation(RelationshipTypeEnum.PARENT).size(), is(0));
        ref.clear();
        ref.add(obsRefPeer);
        when(obs.getRelatedObservations()).thenReturn(ref);
        m_SUT = new GuiObservation(obs, obsReferences);
        indexes = m_SUT.findRelatedObservationOfRelation(RelationshipTypeEnum.PEER);
        assertThat(indexes.size(), is(1));
        assertThat(indexes.get(0), is(0));
        assertThat(m_SUT.findRelatedObservationOfRelation(RelationshipTypeEnum.CHILD).size(), is(0));
        assertThat(m_SUT.findRelatedObservationOfRelation(RelationshipTypeEnum.PARENT).size(), is(0));
        ref.clear();
        ref.add(obsRefParent);
        when(obs.getRelatedObservations()).thenReturn(ref);
        m_SUT = new GuiObservation(obs, obsReferences);
        indexes = m_SUT.findRelatedObservationOfRelation(RelationshipTypeEnum.PARENT);
        assertThat(indexes.size(), is(1));
        assertThat(indexes.get(0), is(0));
        assertThat(m_SUT.findRelatedObservationOfRelation(RelationshipTypeEnum.CHILD).size(), is(0));
        assertThat(m_SUT.findRelatedObservationOfRelation(RelationshipTypeEnum.PEER).size(), is(0));
        ref.clear();
        ref.add(obsRefPeer);
        ref.add(obsRefChild);
        ref.add(obsRefParent);
        when(obs.getRelatedObservations()).thenReturn(ref);
        m_SUT = new GuiObservation(obs, obsReferences);
        indexes = m_SUT.findRelatedObservationOfRelation(RelationshipTypeEnum.PARENT);
        assertThat(indexes.size(), is(1));
        assertThat(indexes.get(0), is(2));
        indexes = m_SUT.findRelatedObservationOfRelation(RelationshipTypeEnum.CHILD);
        assertThat(indexes.size(), is(1));
        assertThat(indexes.get(0), is(1));
        indexes = m_SUT.findRelatedObservationOfRelation(RelationshipTypeEnum.PEER);
        assertThat(indexes.size(), is(1));
        assertThat(indexes.get(0), is(0));
    }
@ Test public void testFindRelatedObservationOfRelation ( ) { Observation obs = mock ( Observation . class ) ; ObservationRef obsRefChild = mock ( ObservationRef . class ) ; Relationship childRel = new Relationship ( ) ; childRel . setRelationshipType ( RelationshipTypeEnum . CHILD ) ; when ( obsRefChild . getRelationship ( ) ) . thenReturn ( childRel ) ; ObservationRef obsRefPeer = mock ( ObservationRef . class ) ; Relationship peerRel = new Relationship ( ) ; peerRel . setRelationshipType ( RelationshipTypeEnum . PEER ) ; when ( obsRefPeer . getRelationship ( ) ) . thenReturn ( peerRel ) ; ObservationRef obsRefParent = mock ( ObservationRef . class ) ; Relationship parentRel = new Relationship ( ) ; parentRel . setRelationshipType ( RelationshipTypeEnum . PARENT ) ; when ( obsRefParent . getRelationship ( ) ) . thenReturn ( parentRel ) ; List < ObservationRef > ref = new ArrayList < > ( ) ; ref . add ( obsRefChild ) ; when ( obs . getRelatedObservations ( ) ) . thenReturn ( ref ) ; List < Boolean > foundList = new ArrayList < > ( ) ; foundList . add ( true ) ; foundList . add ( true ) ; List < ObservationSubTypeEnum > typeList = new ArrayList < > ( ) ; typeList . add ( ObservationSubTypeEnum . DIGITAL_MEDIA ) ; typeList . add ( ObservationSubTypeEnum . DETECTION ) ; List < RelatedObservationIdentity > obsReferences = makeListOfRelatedObservation ( foundList , typeList ) ; m_SUT = new GuiObservation ( obs , obsReferences ) ; List < Integer > indexes = m_SUT . findRelatedObservationOfRelation ( RelationshipTypeEnum . CHILD ) ; assertThat ( indexes . size ( ) , is ( 1 ) ) ; assertThat ( indexes . get ( 0 ) , is ( 0 ) ) ; assertThat ( m_SUT . findRelatedObservationOfRelation ( RelationshipTypeEnum . PEER ) . size ( ) , is ( 0 ) ) ; assertThat ( m_SUT . findRelatedObservationOfRelation ( RelationshipTypeEnum . PARENT ) . size ( ) , is ( 0 ) ) ; ref . clear ( ) ; ref . add ( obsRefPeer ) ; when ( obs . getRelatedObservations ( ) ) . thenReturn ( ref ) ; m_SUT = new GuiObservation ( obs , obsReferences ) ; indexes = m_SUT . findRelatedObservationOfRelation ( RelationshipTypeEnum . PEER ) ; assertThat ( indexes . size ( ) , is ( 1 ) ) ; assertThat ( indexes . get ( 0 ) , is ( 0 ) ) ; assertThat ( m_SUT . findRelatedObservationOfRelation ( RelationshipTypeEnum . CHILD ) . size ( ) , is ( 0 ) ) ; assertThat ( m_SUT . findRelatedObservationOfRelation ( RelationshipTypeEnum . PARENT ) . size ( ) , is ( 0 ) ) ; ref . clear ( ) ; ref . add ( obsRefParent ) ; when ( obs . getRelatedObservations ( ) ) . thenReturn ( ref ) ; m_SUT = new GuiObservation ( obs , obsReferences ) ; indexes = m_SUT . findRelatedObservationOfRelation ( RelationshipTypeEnum . PARENT ) ; assertThat ( indexes . size ( ) , is ( 1 ) ) ; assertThat ( indexes . get ( 0 ) , is ( 0 ) ) ; assertThat ( m_SUT . findRelatedObservationOfRelation ( RelationshipTypeEnum . CHILD ) . size ( ) , is ( 0 ) ) ; assertThat ( m_SUT . findRelatedObservationOfRelation ( RelationshipTypeEnum . PEER ) . size ( ) , is ( 0 ) ) ; ref . clear ( ) ; ref . add ( obsRefPeer ) ; ref . add ( obsRefChild ) ; ref . add ( obsRefParent ) ; when ( obs . getRelatedObservations ( ) ) . thenReturn ( ref ) ; m_SUT = new GuiObservation ( obs , obsReferences ) ; indexes = m_SUT . findRelatedObservationOfRelation ( RelationshipTypeEnum . PARENT ) ; assertThat ( indexes . size ( ) , is ( 1 ) ) ; assertThat ( indexes . get ( 0 ) , is ( 2 ) ) ; indexes = m_SUT . findRelatedObservationOfRelation ( RelationshipTypeEnum . CHILD ) ; assertThat ( indexes . size ( ) , is ( 1 ) ) ; assertThat ( indexes . get ( 0 ) , is ( 1 ) ) ; indexes = m_SUT . findRelatedObservationOfRelation ( RelationshipTypeEnum . PEER ) ; assertThat ( indexes . size ( ) , is ( 1 ) ) ; assertThat ( indexes . get ( 0 ) , is ( 0 ) ) ; }
Verify that observation references can be retrieved by type.
Verify that observation references can be retrieved by type .