mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/observation/TestObservationMessageService.java
@Test
    public void testGetObservationRequestQueryAssetTimeMaxObs() throws IOException, ObjectConverterException
    {
        //necessary messages for request
        TimeConstraintData time = getCreatedTimeConstraint();
        
        Query query = Query.newBuilder().setAssetUuid(SharedMessageUtils.convertUUIDToProtoUUID(uuid))
                .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(uuid, null, null, 
                timeStart, timeEnd, null, null, null, null, null, null, null, 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(), hasItem(obGen1));
        
        verify(oQuery).withAssetUuid(uuid);
        verify(oQuery).withTimeCreatedRange(timeStart, timeEnd);
        verify(oQuery).withMaxObservations(1);
        verify(oQuery).execute();
    }
/**
     * Test GetObservationRequest with query of assetUuid with time constraints and maximum observations.
     * Verify response is sent.
     */
Test GetObservationRequest with query of assetUuid with time constraints and maximum observations.
Verify response is sent.
Test GetObservationRequest with query of assetUuid with time constraints and maximum observations . Verify response is sent .
@Test
    public void testGetObservationRequestQueryAssetTimeMaxObs() throws IOException, ObjectConverterException
    {
        TimeConstraintData time = getCreatedTimeConstraint();
        Query query = Query.newBuilder().setAssetUuid(SharedMessageUtils.convertUUIDToProtoUUID(uuid))
                .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(uuid, null, null, 
                timeStart, timeEnd, null, null, null, null, null, null, null, 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(), hasItem(obGen1));
        verify(oQuery).withAssetUuid(uuid);
        verify(oQuery).withTimeCreatedRange(timeStart, timeEnd);
        verify(oQuery).withMaxObservations(1);
        verify(oQuery).execute();
    }
@ Test public void testGetObservationRequestQueryAssetTimeMaxObs ( ) throws IOException , ObjectConverterException { TimeConstraintData time = getCreatedTimeConstraint ( ) ; Query query = Query . newBuilder ( ) . setAssetUuid ( SharedMessageUtils . convertUUIDToProtoUUID ( uuid ) ) . 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 ( uuid , null , null , timeStart , timeEnd , null , null , null , null , null , null , null , 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 ( ) , hasItem ( obGen1 ) ) ; verify ( oQuery ) . withAssetUuid ( uuid ) ; verify ( oQuery ) . withTimeCreatedRange ( timeStart , timeEnd ) ; verify ( oQuery ) . withMaxObservations ( 1 ) ; verify ( oQuery ) . execute ( ) ; }
Test GetObservationRequest with query of assetUuid with time constraints and maximum observations.
Test GetObservationRequest with query of assetUuid with time constraints and maximum observations .
//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