mil.dod.th.ose.remote.integration/src/mil/dod/th/ose/remote/integration/base/TestMessageRouter.java
@Test
    public void testMessageRouterInvalidData() throws UnknownHostException, IOException
    {
        // verify can make connection
        try (Socket socket = SocketHostHelper.connectToController())
        {
            // set invalid data for the custom comms namespace builder and verify that
            // a message is still sent back after an exception is thrown
            CustomCommsNamespace.Builder customCommsMessage = CustomCommsNamespace.newBuilder().
                    setType(CustomCommsMessageType.CreatePhysicalLinkRequest).
                    setData(ByteString.copyFromUtf8("ImInvalidddd"));
                
            //send an invalid namespace
            TerraHarvestMessage message = TerraHarvestMessageHelper.
                    createTerraHarvestMsg(Namespace.CustomComms, customCommsMessage);
            
            message.writeDelimitedTo(socket.getOutputStream());
            
            // read in response
            TerraHarvestMessage response = TerraHarvestMessage.parseDelimitedFrom(socket.getInputStream());
            TerraHarvestPayload payLoadTest = TerraHarvestPayload.parseFrom(response.getTerraHarvestPayload());
            
            BaseNamespace baseTest = BaseNamespace.parseFrom(payLoadTest.getNamespaceMessage()); 
            GenericErrorResponseData genericErrorResponseTest = GenericErrorResponseData.parseFrom(baseTest.getData());
           
            assertThat(response.getVersion(), is(RemoteConstants.SPEC_VERSION));
            assertThat(genericErrorResponseTest.getError(), is(ErrorCode.INVALID_REQUEST));
            assertThat(genericErrorResponseTest.getErrorDescription(), 
                is("Failed IO operation when handling [CustomComms] namespace message: " 
                        + "Protocol message end-group tag did not match expected tag."));
    
            assertThat(payLoadTest.getNamespace(), is(Namespace.Base));
            assertThat(baseTest.getType(), is(BaseMessageType.GenericErrorResponse));
        }
    }
/**
     * Verify invalid data returns a response after an exception is thrown when attempting to handle a message.
     */
Verify invalid data returns a response after an exception is thrown when attempting to handle a message.
Verify invalid data returns a response after an exception is thrown when attempting to handle a message .
@Test
    public void testMessageRouterInvalidData() throws UnknownHostException, IOException
    {
        try (Socket socket = SocketHostHelper.connectToController())
        {
            CustomCommsNamespace.Builder customCommsMessage = CustomCommsNamespace.newBuilder().
                    setType(CustomCommsMessageType.CreatePhysicalLinkRequest).
                    setData(ByteString.copyFromUtf8("ImInvalidddd"));
            TerraHarvestMessage message = TerraHarvestMessageHelper.
                    createTerraHarvestMsg(Namespace.CustomComms, customCommsMessage);
            message.writeDelimitedTo(socket.getOutputStream());
            TerraHarvestMessage response = TerraHarvestMessage.parseDelimitedFrom(socket.getInputStream());
            TerraHarvestPayload payLoadTest = TerraHarvestPayload.parseFrom(response.getTerraHarvestPayload());
            BaseNamespace baseTest = BaseNamespace.parseFrom(payLoadTest.getNamespaceMessage()); 
            GenericErrorResponseData genericErrorResponseTest = GenericErrorResponseData.parseFrom(baseTest.getData());
            assertThat(response.getVersion(), is(RemoteConstants.SPEC_VERSION));
            assertThat(genericErrorResponseTest.getError(), is(ErrorCode.INVALID_REQUEST));
            assertThat(genericErrorResponseTest.getErrorDescription(), 
                is("Failed IO operation when handling [CustomComms] namespace message: " 
                        + "Protocol message end-group tag did not match expected tag."));
            assertThat(payLoadTest.getNamespace(), is(Namespace.Base));
            assertThat(baseTest.getType(), is(BaseMessageType.GenericErrorResponse));
        }
    }
@ Test public void testMessageRouterInvalidData ( ) throws UnknownHostException , IOException { try ( Socket socket = SocketHostHelper . connectToController ( ) ) { CustomCommsNamespace . Builder customCommsMessage = CustomCommsNamespace . newBuilder ( ) . setType ( CustomCommsMessageType . CreatePhysicalLinkRequest ) . setData ( ByteString . copyFromUtf8 ( "ImInvalidddd" ) ) ; TerraHarvestMessage message = TerraHarvestMessageHelper . createTerraHarvestMsg ( Namespace . CustomComms , customCommsMessage ) ; message . writeDelimitedTo ( socket . getOutputStream ( ) ) ; TerraHarvestMessage response = TerraHarvestMessage . parseDelimitedFrom ( socket . getInputStream ( ) ) ; TerraHarvestPayload payLoadTest = TerraHarvestPayload . parseFrom ( response . getTerraHarvestPayload ( ) ) ; BaseNamespace baseTest = BaseNamespace . parseFrom ( payLoadTest . getNamespaceMessage ( ) ) ; GenericErrorResponseData genericErrorResponseTest = GenericErrorResponseData . parseFrom ( baseTest . getData ( ) ) ; assertThat ( response . getVersion ( ) , is ( RemoteConstants . SPEC_VERSION ) ) ; assertThat ( genericErrorResponseTest . getError ( ) , is ( ErrorCode . INVALID_REQUEST ) ) ; assertThat ( genericErrorResponseTest . getErrorDescription ( ) , is ( "Failed IO operation when handling [CustomComms] namespace message: " + "Protocol message end-group tag did not match expected tag." ) ) ; assertThat ( payLoadTest . getNamespace ( ) , is ( Namespace . Base ) ) ; assertThat ( baseTest . getType ( ) , is ( BaseMessageType . GenericErrorResponse ) ) ; } }
Verify invalid data returns a response after an exception is thrown when attempting to handle a message.
Verify invalid data returns a response after an exception is thrown when attempting to handle a message .
// verify can make connection // set invalid data for the custom comms namespace builder and verify that // a message is still sent back after an exception is thrown //send an invalid namespace // read in response