mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/observation/TestObservationMessageService.java
@Test
    public void testGetObservationRequestAll() throws ObjectConverterException, IOException
    {
        Query query = Query.getDefaultInstance();
        
        GetObservationRequestData message = GetObservationRequestData.newBuilder().setObsQuery(query).build();
        
        ObservationStoreNamespace namespace = ObservationStoreNamespace.newBuilder().
            setData(message.toByteString()).
            setType(ObservationStoreMessageType.GetObservationRequest).build();
        TerraHarvestPayload payload = createPayload(namespace);
        TerraHarvestMessage thMessage = createMessageObservationStore(namespace);

        // mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);

        //mock observation that will be returned from obs store
        Observation obs1 = mock(Observation.class);
        Observation obs2 = mock(Observation.class);
        List<Observation> observations = new ArrayList<Observation>();
        observations.add(obs1);
        observations.add(obs2);
        
        ObservationQuery oQuery = mockObservationQueryExecute(null, null, null, null, 
                null, null, null, null, null, null, null, null, observations);
        
        //proto observations to return
        ObservationGen.Observation obGen1 = TerraHarvestMessageHelper.getProtoObs();
        ObservationGen.Observation obGen2 = TerraHarvestMessageHelper.getProtoObs();

        //mock converter behavior
        when(m_Converter.convertToProto(obs1)).thenReturn(obGen1);
        when(m_Converter.convertToProto(obs2)).thenReturn(obGen2);

        // replay
        m_SUT.handleMessage(thMessage, payload, channel);

        //capture response
        ArgumentCaptor<GetObservationResponseData> response = ArgumentCaptor.forClass(GetObservationResponseData.class);
        verify(m_MessageFactory).createObservationStoreResponseMessage(eq(thMessage), 
            eq(ObservationStoreMessageType.GetObservationResponse), response.capture());
        verify(m_ResponseWrapper).queue(channel);

        //check response message for proto observations
        GetObservationResponseData responseData = response.getValue();
        assertThat(responseData.getObservationFormat(), is(RemoteTypesGen.LexiconFormat.Enum.NATIVE));
        assertThat(responseData.getObservationNativeCount(), is(2));
        assertThat(responseData.getObservationNativeList(), hasItems(obGen1, obGen2));
        
        verify(oQuery, never()).withAssetUuid(Mockito.any(UUID.class));
        verify(oQuery, never()).withAssetType(Mockito.anyString());
        verify(oQuery, never()).withMaxObservations(Mockito.anyInt());
        verify(oQuery, never()).withOrder(Mockito.any(ObservationQuery.SortField.class),
                                          Mockito.any(ObservationQuery.SortOrder.class));
        verify(oQuery, never()).withRange(Mockito.anyInt(), Mockito.anyInt());
        verify(oQuery, never()).withTimeCreatedRange(Mockito.any(Date.class), Mockito.any(Date.class));
        verify(oQuery, never()).withSubType(Mockito.any(ObservationSubTypeEnum.class));
        
        verify(oQuery).execute();
    }
/**
     * Verify a query with no parameters set still calls execute and returns all observations.
     * Verify response is sent.
     */
Verify a query with no parameters set still calls execute and returns all observations.
Verify response is sent.
Verify a query with no parameters set still calls execute and returns all observations . Verify response is sent .
@Test
    public void testGetObservationRequestAll() throws ObjectConverterException, IOException
    {
        Query query = Query.getDefaultInstance();
        GetObservationRequestData message = GetObservationRequestData.newBuilder().setObsQuery(query).build();
        ObservationStoreNamespace namespace = ObservationStoreNamespace.newBuilder().
            setData(message.toByteString()).
            setType(ObservationStoreMessageType.GetObservationRequest).build();
        TerraHarvestPayload payload = createPayload(namespace);
        TerraHarvestMessage thMessage = createMessageObservationStore(namespace);
        RemoteChannel channel = mock(RemoteChannel.class);
        Observation obs1 = mock(Observation.class);
        Observation obs2 = mock(Observation.class);
        List<Observation> observations = new ArrayList<Observation>();
        observations.add(obs1);
        observations.add(obs2);
        ObservationQuery oQuery = mockObservationQueryExecute(null, null, null, null, 
                null, null, null, null, null, null, null, null, observations);
        ObservationGen.Observation obGen1 = TerraHarvestMessageHelper.getProtoObs();
        ObservationGen.Observation obGen2 = TerraHarvestMessageHelper.getProtoObs();
        when(m_Converter.convertToProto(obs1)).thenReturn(obGen1);
        when(m_Converter.convertToProto(obs2)).thenReturn(obGen2);
        m_SUT.handleMessage(thMessage, payload, channel);
        ArgumentCaptor<GetObservationResponseData> response = ArgumentCaptor.forClass(GetObservationResponseData.class);
        verify(m_MessageFactory).createObservationStoreResponseMessage(eq(thMessage), 
            eq(ObservationStoreMessageType.GetObservationResponse), response.capture());
        verify(m_ResponseWrapper).queue(channel);
        GetObservationResponseData responseData = response.getValue();
        assertThat(responseData.getObservationFormat(), is(RemoteTypesGen.LexiconFormat.Enum.NATIVE));
        assertThat(responseData.getObservationNativeCount(), is(2));
        assertThat(responseData.getObservationNativeList(), hasItems(obGen1, obGen2));
        verify(oQuery, never()).withAssetUuid(Mockito.any(UUID.class));
        verify(oQuery, never()).withAssetType(Mockito.anyString());
        verify(oQuery, never()).withMaxObservations(Mockito.anyInt());
        verify(oQuery, never()).withOrder(Mockito.any(ObservationQuery.SortField.class),
                                          Mockito.any(ObservationQuery.SortOrder.class));
        verify(oQuery, never()).withRange(Mockito.anyInt(), Mockito.anyInt());
        verify(oQuery, never()).withTimeCreatedRange(Mockito.any(Date.class), Mockito.any(Date.class));
        verify(oQuery, never()).withSubType(Mockito.any(ObservationSubTypeEnum.class));
        verify(oQuery).execute();
    }
@ Test public void testGetObservationRequestAll ( ) throws ObjectConverterException , IOException { Query query = Query . getDefaultInstance ( ) ; GetObservationRequestData message = GetObservationRequestData . newBuilder ( ) . setObsQuery ( query ) . build ( ) ; ObservationStoreNamespace namespace = ObservationStoreNamespace . newBuilder ( ) . setData ( message . toByteString ( ) ) . setType ( ObservationStoreMessageType . GetObservationRequest ) . build ( ) ; TerraHarvestPayload payload = createPayload ( namespace ) ; TerraHarvestMessage thMessage = createMessageObservationStore ( namespace ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; Observation obs1 = mock ( Observation . class ) ; Observation obs2 = mock ( Observation . class ) ; List < Observation > observations = new ArrayList < Observation > ( ) ; observations . add ( obs1 ) ; observations . add ( obs2 ) ; ObservationQuery oQuery = mockObservationQueryExecute ( null , null , null , null , null , null , null , null , null , null , null , null , observations ) ; ObservationGen . Observation obGen1 = TerraHarvestMessageHelper . getProtoObs ( ) ; ObservationGen . Observation obGen2 = TerraHarvestMessageHelper . getProtoObs ( ) ; when ( m_Converter . convertToProto ( obs1 ) ) . thenReturn ( obGen1 ) ; when ( m_Converter . convertToProto ( obs2 ) ) . thenReturn ( obGen2 ) ; m_SUT . handleMessage ( thMessage , payload , channel ) ; ArgumentCaptor < GetObservationResponseData > response = ArgumentCaptor . forClass ( GetObservationResponseData . class ) ; verify ( m_MessageFactory ) . createObservationStoreResponseMessage ( eq ( thMessage ) , eq ( ObservationStoreMessageType . GetObservationResponse ) , response . capture ( ) ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; GetObservationResponseData responseData = response . getValue ( ) ; assertThat ( responseData . getObservationFormat ( ) , is ( RemoteTypesGen . LexiconFormat . Enum . NATIVE ) ) ; assertThat ( responseData . getObservationNativeCount ( ) , is ( 2 ) ) ; assertThat ( responseData . getObservationNativeList ( ) , hasItems ( obGen1 , obGen2 ) ) ; verify ( oQuery , never ( ) ) . withAssetUuid ( Mockito . any ( UUID . class ) ) ; verify ( oQuery , never ( ) ) . withAssetType ( Mockito . anyString ( ) ) ; verify ( oQuery , never ( ) ) . withMaxObservations ( Mockito . anyInt ( ) ) ; verify ( oQuery , never ( ) ) . withOrder ( Mockito . any ( ObservationQuery . SortField . class ) , Mockito . any ( ObservationQuery . SortOrder . class ) ) ; verify ( oQuery , never ( ) ) . withRange ( Mockito . anyInt ( ) , Mockito . anyInt ( ) ) ; verify ( oQuery , never ( ) ) . withTimeCreatedRange ( Mockito . any ( Date . class ) , Mockito . any ( Date . class ) ) ; verify ( oQuery , never ( ) ) . withSubType ( Mockito . any ( ObservationSubTypeEnum . class ) ) ; verify ( oQuery ) . execute ( ) ; }
Verify a query with no parameters set still calls execute and returns all observations.
Verify a query with no parameters set still calls execute and returns all observations .
// mock the channel the message came from //mock observation that will be returned from obs store //proto observations to return //mock converter behavior // replay //capture response //check response message for proto observations