mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/observation/TestObservationMessageService.java
@Test
    public void testGetObservationRequestQueryObsTypeTimeMaxObs() throws IOException, ObjectConverterException
    {
        //necessary messages for request
        TimeConstraintData time = getCreatedTimeConstraint();
        Query query = Query.newBuilder().addObservationSubType(
                ObservationSubTypeEnumConverter.convertJavaEnumToProto(ObservationSubTypeEnum.AUDIO_METADATA))
                .setCreatedTimeRange(time)
                .setMaxNumberOfObs(1).build();
        
        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);
        List<Observation> observations = new ArrayList<Observation>();
        observations.add(obs1);
        
        Date timeStart = new Date(1L);
        Date timeEnd = new Date(3L);
        ObservationQuery oQuery = mockObservationQueryExecute(null, null, ObservationSubTypeEnum.AUDIO_METADATA, 
                timeStart, timeEnd, null, null, null, null, null, null, 1, observations);

        //proto observations to return
        ObservationGen.Observation obGen1 = TerraHarvestMessageHelper.getProtoObs();

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

        // 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(1));
        assertThat(responseData.getObservationNativeList(), hasItems(obGen1));
        
        verify(oQuery).withSubType(ObservationSubTypeEnum.AUDIO_METADATA);
        verify(oQuery).withTimeCreatedRange(timeStart, timeEnd);
        verify(oQuery).withMaxObservations(1);
        verify(oQuery).execute();
    }
/**
     * Test GetObservationRequest with query of observation type and time constraints and maximum observation type.
     * Verify response is sent.
     */
Test GetObservationRequest with query of observation type and time constraints and maximum observation type.
Verify response is sent.
Test GetObservationRequest with query of observation type and time constraints and maximum observation type . Verify response is sent .
@Test
    public void testGetObservationRequestQueryObsTypeTimeMaxObs() throws IOException, ObjectConverterException
    {
        TimeConstraintData time = getCreatedTimeConstraint();
        Query query = Query.newBuilder().addObservationSubType(
                ObservationSubTypeEnumConverter.convertJavaEnumToProto(ObservationSubTypeEnum.AUDIO_METADATA))
                .setCreatedTimeRange(time)
                .setMaxNumberOfObs(1).build();
        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);
        List<Observation> observations = new ArrayList<Observation>();
        observations.add(obs1);
        Date timeStart = new Date(1L);
        Date timeEnd = new Date(3L);
        ObservationQuery oQuery = mockObservationQueryExecute(null, null, ObservationSubTypeEnum.AUDIO_METADATA, 
                timeStart, timeEnd, null, null, null, null, null, null, 1, observations);
        ObservationGen.Observation obGen1 = TerraHarvestMessageHelper.getProtoObs();
        when(m_Converter.convertToProto(obs1)).thenReturn(obGen1);
        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(1));
        assertThat(responseData.getObservationNativeList(), hasItems(obGen1));
        verify(oQuery).withSubType(ObservationSubTypeEnum.AUDIO_METADATA);
        verify(oQuery).withTimeCreatedRange(timeStart, timeEnd);
        verify(oQuery).withMaxObservations(1);
        verify(oQuery).execute();
    }
@ Test public void testGetObservationRequestQueryObsTypeTimeMaxObs ( ) throws IOException , ObjectConverterException { TimeConstraintData time = getCreatedTimeConstraint ( ) ; Query query = Query . newBuilder ( ) . addObservationSubType ( ObservationSubTypeEnumConverter . convertJavaEnumToProto ( ObservationSubTypeEnum . AUDIO_METADATA ) ) . setCreatedTimeRange ( time ) . setMaxNumberOfObs ( 1 ) . build ( ) ; 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 ) ; List < Observation > observations = new ArrayList < Observation > ( ) ; observations . add ( obs1 ) ; Date timeStart = new Date ( 1L ) ; Date timeEnd = new Date ( 3L ) ; ObservationQuery oQuery = mockObservationQueryExecute ( null , null , ObservationSubTypeEnum . AUDIO_METADATA , timeStart , timeEnd , null , null , null , null , null , null , 1 , observations ) ; ObservationGen . Observation obGen1 = TerraHarvestMessageHelper . getProtoObs ( ) ; when ( m_Converter . convertToProto ( obs1 ) ) . thenReturn ( obGen1 ) ; 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 ( 1 ) ) ; assertThat ( responseData . getObservationNativeList ( ) , hasItems ( obGen1 ) ) ; verify ( oQuery ) . withSubType ( ObservationSubTypeEnum . AUDIO_METADATA ) ; verify ( oQuery ) . withTimeCreatedRange ( timeStart , timeEnd ) ; verify ( oQuery ) . withMaxObservations ( 1 ) ; verify ( oQuery ) . execute ( ) ; }
Test GetObservationRequest with query of observation type and time constraints and maximum observation type.
Test GetObservationRequest with query of observation type and time constraints and maximum observation type .
//necessary messages for request // 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