mil.dod.th.ose.remote.integration/src/mil/dod/th/ose/remote/integration/namespace/TestObservationStoreMessageService.java
@Test
    public void testGetObservationCountWithQueryParams() throws IOException, InterruptedException
    {
        //message listener that will wait for responses
        MessageListener listener = new MessageListener(socket);
        
        //create get observation request
        Query query = Query.newBuilder().
            addObservationSubType(ObservationSubTypeEnumConverter
                    .convertJavaEnumToProto(ObservationSubTypeEnum.DETECTION)).build();

        GetObservationRequestData obsResquest = GetObservationRequestData.newBuilder().
            setObsQuery(query).build();
        
        //send request
        TerraHarvestMessage message = createObservationStoreMessage(ObservationStoreMessageType.GetObservationRequest,
            obsResquest);

        //send request
        message.writeDelimitedTo(socket.getOutputStream());

        //wait for response
        Message response = listener.waitForMessage(Namespace.ObservationStore, 
            ObservationStoreMessageType.GetObservationResponse, WAIT_TIME_MS);

        //check observation is the observation expected
        ObservationStoreNamespace obsNamespaceResponse = (ObservationStoreNamespace) response;
        GetObservationResponseData getObsResponse = GetObservationResponseData.parseFrom(
            obsNamespaceResponse.getData());
        
        assertThat(getObsResponse.getObservationFormat(), is(RemoteTypesGen.LexiconFormat.Enum.NATIVE));
        int initialCount = getObsResponse.getObservationNativeCount();
        
        // capture 5 observations
        for (int i=0; i < 5; i++)
        {
            AssetNamespaceUtils.requestDataCapture(socket, assetUuid);
        }
        
        message.writeDelimitedTo(socket.getOutputStream());

        //wait for response
        response = listener.waitForMessage(Namespace.ObservationStore, 
            ObservationStoreMessageType.GetObservationResponse, WAIT_TIME_MS);

        obsNamespaceResponse = (ObservationStoreNamespace)response;
        getObsResponse = GetObservationResponseData.parseFrom(obsNamespaceResponse.getData());
        
        // count should be 5 more than before
        assertThat(getObsResponse.getObservationFormat(), is(RemoteTypesGen.LexiconFormat.Enum.NATIVE));
        assertThat(getObsResponse.getObservationNativeCount(), is(initialCount + 5));
        
        //create the message
        Query queryCount = Query.newBuilder().
                addObservationSubType(ObservationSubTypeEnumConverter
                        .convertJavaEnumToProto(ObservationSubTypeEnum.DETECTION)).build();
        
        GetObservationCountRequestData request = GetObservationCountRequestData
                .newBuilder().setObsQuery(queryCount).build();
        
        TerraHarvestMessage messageCount = createObservationStoreMessage(
                ObservationStoreMessageType.GetObservationCountRequest,
                request);
        
        //send request
        messageCount.writeDelimitedTo(socket.getOutputStream());
        
        Message responseCount = listener.waitForMessage(Namespace.ObservationStore, 
                ObservationStoreMessageType.GetObservationCountResponse, WAIT_TIME_MS);
        
        obsNamespaceResponse = (ObservationStoreNamespace)responseCount;
        GetObservationCountResponseData getObsCountResponse = 
                GetObservationCountResponseData.parseFrom(obsNamespaceResponse.getData());
        
        assertThat((int)getObsCountResponse.getCount(), is(getObsResponse.getObservationNativeCount()));
    }
/**
     * Verify that the correct observation count can be retrieved based on the given query.
     * Given query contains the asset sub type.
     */
Verify that the correct observation count can be retrieved based on the given query.
Given query contains the asset sub type.
Verify that the correct observation count can be retrieved based on the given query . Given query contains the asset sub type .
@Test
    public void testGetObservationCountWithQueryParams() throws IOException, InterruptedException
    {
        MessageListener listener = new MessageListener(socket);
        Query query = Query.newBuilder().
            addObservationSubType(ObservationSubTypeEnumConverter
                    .convertJavaEnumToProto(ObservationSubTypeEnum.DETECTION)).build();
        GetObservationRequestData obsResquest = GetObservationRequestData.newBuilder().
            setObsQuery(query).build();
        TerraHarvestMessage message = createObservationStoreMessage(ObservationStoreMessageType.GetObservationRequest,
            obsResquest);
        message.writeDelimitedTo(socket.getOutputStream());
        Message response = listener.waitForMessage(Namespace.ObservationStore, 
            ObservationStoreMessageType.GetObservationResponse, WAIT_TIME_MS);
        ObservationStoreNamespace obsNamespaceResponse = (ObservationStoreNamespace) response;
        GetObservationResponseData getObsResponse = GetObservationResponseData.parseFrom(
            obsNamespaceResponse.getData());
        assertThat(getObsResponse.getObservationFormat(), is(RemoteTypesGen.LexiconFormat.Enum.NATIVE));
        int initialCount = getObsResponse.getObservationNativeCount();
        for (int i=0; i < 5; i++)
        {
            AssetNamespaceUtils.requestDataCapture(socket, assetUuid);
        }
        message.writeDelimitedTo(socket.getOutputStream());
        response = listener.waitForMessage(Namespace.ObservationStore, 
            ObservationStoreMessageType.GetObservationResponse, WAIT_TIME_MS);
        obsNamespaceResponse = (ObservationStoreNamespace)response;
        getObsResponse = GetObservationResponseData.parseFrom(obsNamespaceResponse.getData());
        assertThat(getObsResponse.getObservationFormat(), is(RemoteTypesGen.LexiconFormat.Enum.NATIVE));
        assertThat(getObsResponse.getObservationNativeCount(), is(initialCount + 5));
        Query queryCount = Query.newBuilder().
                addObservationSubType(ObservationSubTypeEnumConverter
                        .convertJavaEnumToProto(ObservationSubTypeEnum.DETECTION)).build();
        GetObservationCountRequestData request = GetObservationCountRequestData
                .newBuilder().setObsQuery(queryCount).build();
        TerraHarvestMessage messageCount = createObservationStoreMessage(
                ObservationStoreMessageType.GetObservationCountRequest,
                request);
        messageCount.writeDelimitedTo(socket.getOutputStream());
        Message responseCount = listener.waitForMessage(Namespace.ObservationStore, 
                ObservationStoreMessageType.GetObservationCountResponse, WAIT_TIME_MS);
        obsNamespaceResponse = (ObservationStoreNamespace)responseCount;
        GetObservationCountResponseData getObsCountResponse = 
                GetObservationCountResponseData.parseFrom(obsNamespaceResponse.getData());
        assertThat((int)getObsCountResponse.getCount(), is(getObsResponse.getObservationNativeCount()));
    }
@ Test public void testGetObservationCountWithQueryParams ( ) throws IOException , InterruptedException { MessageListener listener = new MessageListener ( socket ) ; Query query = Query . newBuilder ( ) . addObservationSubType ( ObservationSubTypeEnumConverter . convertJavaEnumToProto ( ObservationSubTypeEnum . DETECTION ) ) . build ( ) ; GetObservationRequestData obsResquest = GetObservationRequestData . newBuilder ( ) . setObsQuery ( query ) . build ( ) ; TerraHarvestMessage message = createObservationStoreMessage ( ObservationStoreMessageType . GetObservationRequest , obsResquest ) ; message . writeDelimitedTo ( socket . getOutputStream ( ) ) ; Message response = listener . waitForMessage ( Namespace . ObservationStore , ObservationStoreMessageType . GetObservationResponse , WAIT_TIME_MS ) ; ObservationStoreNamespace obsNamespaceResponse = ( ObservationStoreNamespace ) response ; GetObservationResponseData getObsResponse = GetObservationResponseData . parseFrom ( obsNamespaceResponse . getData ( ) ) ; assertThat ( getObsResponse . getObservationFormat ( ) , is ( RemoteTypesGen . LexiconFormat . Enum . NATIVE ) ) ; int initialCount = getObsResponse . getObservationNativeCount ( ) ; for ( int i = 0 ; i < 5 ; i ++ ) { AssetNamespaceUtils . requestDataCapture ( socket , assetUuid ) ; } message . writeDelimitedTo ( socket . getOutputStream ( ) ) ; response = listener . waitForMessage ( Namespace . ObservationStore , ObservationStoreMessageType . GetObservationResponse , WAIT_TIME_MS ) ; obsNamespaceResponse = ( ObservationStoreNamespace ) response ; getObsResponse = GetObservationResponseData . parseFrom ( obsNamespaceResponse . getData ( ) ) ; assertThat ( getObsResponse . getObservationFormat ( ) , is ( RemoteTypesGen . LexiconFormat . Enum . NATIVE ) ) ; assertThat ( getObsResponse . getObservationNativeCount ( ) , is ( initialCount + 5 ) ) ; Query queryCount = Query . newBuilder ( ) . addObservationSubType ( ObservationSubTypeEnumConverter . convertJavaEnumToProto ( ObservationSubTypeEnum . DETECTION ) ) . build ( ) ; GetObservationCountRequestData request = GetObservationCountRequestData . newBuilder ( ) . setObsQuery ( queryCount ) . build ( ) ; TerraHarvestMessage messageCount = createObservationStoreMessage ( ObservationStoreMessageType . GetObservationCountRequest , request ) ; messageCount . writeDelimitedTo ( socket . getOutputStream ( ) ) ; Message responseCount = listener . waitForMessage ( Namespace . ObservationStore , ObservationStoreMessageType . GetObservationCountResponse , WAIT_TIME_MS ) ; obsNamespaceResponse = ( ObservationStoreNamespace ) responseCount ; GetObservationCountResponseData getObsCountResponse = GetObservationCountResponseData . parseFrom ( obsNamespaceResponse . getData ( ) ) ; assertThat ( ( int ) getObsCountResponse . getCount ( ) , is ( getObsResponse . getObservationNativeCount ( ) ) ) ; }
Verify that the correct observation count can be retrieved based on the given query.
Verify that the correct observation count can be retrieved based on the given query .
//message listener that will wait for responses //create get observation request //send request //send request //wait for response //check observation is the observation expected // capture 5 observations //wait for response // count should be 5 more than before //create the message //send request