mil.dod.th.ose.remote.integration/src/mil/dod/th/ose/remote/integration/namespace/TestEventAdminNamespace.java
@Test
    public void testSendEvent_ObservationXml() throws Exception
    {
        // 1. register for remote event
        int regId = RemoteEventRegistration.regRemoteEventMessages(m_Socket, 
                ObservationStore.TOPIC_OBSERVATION_PERSISTED_WITH_OBS + RemoteConstants.REMOTE_TOPIC_SUFFIX, 
                RemoteTypesGen.LexiconFormat.Enum.XML);

        //create a basic observation
        UUID assetUuid = UUID.randomUUID();
        UUID obsUuid = UUID.randomUUID();
        long createTime = System.currentTimeMillis();

        ObservationGen.Observation observation = ObservationGen.Observation.newBuilder().
            setSystemInTestMode(true).
            setAssetUuid(SharedMessageUtils.convertUUIDToProtoUUID(assetUuid)).
            setAssetName("NAME").
            setAssetType(ExampleAsset.class.getName()).
            setCreatedTimestamp(createTime).
            setSystemId(321).
            setVersion(SharedTypesGen.Version.newBuilder().setMajorNumber(1).setMinorNumber(2).build()).
            setUuid(SharedMessageUtils.convertUUIDToProtoUUID(obsUuid)).build();
        
        Observation jaxbObservation = new Observation()
            .withSystemInTestMode(true)
            .withAssetUuid(assetUuid)
            .withAssetName("NAME")
            .withAssetType(ExampleAsset.class.getName())
            .withCreatedTimestamp(createTime)
            .withSystemId(321)
            .withVersion(new Version(1, 2))
            .withUuid(obsUuid);

        // property map of the event
        ComplexTypesMapEntry props = ComplexTypesMapEntry.newBuilder().
            setKey(ObservationStore.EVENT_PROP_OBSERVATION).setObservationNative(observation).build();

        // send event message
        SendEventData sendEvent = SendEventData.newBuilder()
            .setTopic(ObservationStore.TOPIC_OBSERVATION_PERSISTED_WITH_OBS)
            .addProperty(props).build();

        TerraHarvestMessage message = createEventAdminMessage(EventAdminMessageType.SendEvent, sendEvent);

        // 2. send message
        message.writeDelimitedTo(m_Socket.getOutputStream());
        
        // 3 and 4 happen on the controller

        // 5. listener
        MessageListener listener = new MessageListener(m_Socket);
        EventAdminNamespace namespace = (EventAdminNamespace)listener.waitForRemoteEvent(
                ObservationStore.TOPIC_OBSERVATION_PERSISTED_WITH_OBS + RemoteConstants.REMOTE_TOPIC_SUFFIX, 1500);

        MessageListener.unregisterEvent(regId, m_Socket);

        SendEventData response = SendEventData.parseFrom(namespace.getData());

        //verify property for the observation
        ImmutableMap<String, ComplexTypesMapEntry> responseProps = 
                Maps.uniqueIndex(response.getPropertyList(), new Function<ComplexTypesMapEntry, String>()
                {
                    @Override
                    public String apply(ComplexTypesMapEntry entry)
                    {
                        return entry.getKey();
                    }
                });
        
        JAXBContext jc = JAXBContext.newInstance(Observation.class);
        Marshaller m = jc.createMarshaller();
        final ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);
        m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
        m.marshal(jaxbObservation, byteStream);
        
        assertThat(responseProps.get(ObservationStore.EVENT_PROP_OBSERVATION).getObservationXml(), 
                is(ByteString.copyFrom(byteStream.toByteArray())));
    }
/**
     * Verify observation event data can be sent back as XML.
     * 
     * This test will:
     *  1. register for an observation persisted event with the controller
     *  2. send a SendEvent message (with observation) to the controller
     *  3. the controller will receive the SendEvent message, convert the observation to a JAXB object and post a remote
     *     observation persisted event locally
     *  4. the controller will convert the JAXB observation object back to XML format and send a SendEvent message when 
     *     a remote observation persisted event is posted locally
     *  5. the test will receive the SendEvent back
     */
Verify observation event data can be sent back as XML.

This test will:
1. register for an observation persisted event with the controller
2. send a SendEvent message (with observation) to the controller
3. the controller will receive the SendEvent message, convert the observation to a JAXB object and post a remote
observation persisted event locally
4. the controller will convert the JAXB observation object back to XML format and send a SendEvent message when
a remote observation persisted event is posted locally
5. the test will receive the SendEvent back
Verify observation event data can be sent back as XML . This test will : 1 . register for an observation persisted event with the controller 2 . send a SendEvent message ( with observation ) to the controller 3 . the controller will receive the SendEvent message convert the observation to a JAXB object and post a remote observation persisted event locally 4 . the controller will convert the JAXB observation object back to XML format and send a SendEvent message when a remote observation persisted event is posted locally 5 . the test will receive the SendEvent back
@Test
    public void testSendEvent_ObservationXml() throws Exception
    {
        int regId = RemoteEventRegistration.regRemoteEventMessages(m_Socket, 
                ObservationStore.TOPIC_OBSERVATION_PERSISTED_WITH_OBS + RemoteConstants.REMOTE_TOPIC_SUFFIX, 
                RemoteTypesGen.LexiconFormat.Enum.XML);
        UUID assetUuid = UUID.randomUUID();
        UUID obsUuid = UUID.randomUUID();
        long createTime = System.currentTimeMillis();
        ObservationGen.Observation observation = ObservationGen.Observation.newBuilder().
            setSystemInTestMode(true).
            setAssetUuid(SharedMessageUtils.convertUUIDToProtoUUID(assetUuid)).
            setAssetName("NAME").
            setAssetType(ExampleAsset.class.getName()).
            setCreatedTimestamp(createTime).
            setSystemId(321).
            setVersion(SharedTypesGen.Version.newBuilder().setMajorNumber(1).setMinorNumber(2).build()).
            setUuid(SharedMessageUtils.convertUUIDToProtoUUID(obsUuid)).build();
        Observation jaxbObservation = new Observation()
            .withSystemInTestMode(true)
            .withAssetUuid(assetUuid)
            .withAssetName("NAME")
            .withAssetType(ExampleAsset.class.getName())
            .withCreatedTimestamp(createTime)
            .withSystemId(321)
            .withVersion(new Version(1, 2))
            .withUuid(obsUuid);
        ComplexTypesMapEntry props = ComplexTypesMapEntry.newBuilder().
            setKey(ObservationStore.EVENT_PROP_OBSERVATION).setObservationNative(observation).build();
        SendEventData sendEvent = SendEventData.newBuilder()
            .setTopic(ObservationStore.TOPIC_OBSERVATION_PERSISTED_WITH_OBS)
            .addProperty(props).build();
        TerraHarvestMessage message = createEventAdminMessage(EventAdminMessageType.SendEvent, sendEvent);
        message.writeDelimitedTo(m_Socket.getOutputStream());
        MessageListener listener = new MessageListener(m_Socket);
        EventAdminNamespace namespace = (EventAdminNamespace)listener.waitForRemoteEvent(
                ObservationStore.TOPIC_OBSERVATION_PERSISTED_WITH_OBS + RemoteConstants.REMOTE_TOPIC_SUFFIX, 1500);
        MessageListener.unregisterEvent(regId, m_Socket);
        SendEventData response = SendEventData.parseFrom(namespace.getData());
        ImmutableMap<String, ComplexTypesMapEntry> responseProps = 
                Maps.uniqueIndex(response.getPropertyList(), new Function<ComplexTypesMapEntry, String>()
                {
                    @Override
                    public String apply(ComplexTypesMapEntry entry)
                    {
                        return entry.getKey();
                    }
                });
        JAXBContext jc = JAXBContext.newInstance(Observation.class);
        Marshaller m = jc.createMarshaller();
        final ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);
        m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
        m.marshal(jaxbObservation, byteStream);
        assertThat(responseProps.get(ObservationStore.EVENT_PROP_OBSERVATION).getObservationXml(), 
                is(ByteString.copyFrom(byteStream.toByteArray())));
    }
@ Test public void testSendEvent_ObservationXml ( ) throws Exception { int regId = RemoteEventRegistration . regRemoteEventMessages ( m_Socket , ObservationStore . TOPIC_OBSERVATION_PERSISTED_WITH_OBS + RemoteConstants . REMOTE_TOPIC_SUFFIX , RemoteTypesGen . LexiconFormat . Enum . XML ) ; UUID assetUuid = UUID . randomUUID ( ) ; UUID obsUuid = UUID . randomUUID ( ) ; long createTime = System . currentTimeMillis ( ) ; ObservationGen . Observation observation = ObservationGen . Observation . newBuilder ( ) . setSystemInTestMode ( true ) . setAssetUuid ( SharedMessageUtils . convertUUIDToProtoUUID ( assetUuid ) ) . setAssetName ( "NAME" ) . setAssetType ( ExampleAsset . class . getName ( ) ) . setCreatedTimestamp ( createTime ) . setSystemId ( 321 ) . setVersion ( SharedTypesGen . Version . newBuilder ( ) . setMajorNumber ( 1 ) . setMinorNumber ( 2 ) . build ( ) ) . setUuid ( SharedMessageUtils . convertUUIDToProtoUUID ( obsUuid ) ) . build ( ) ; Observation jaxbObservation = new Observation ( ) . withSystemInTestMode ( true ) . withAssetUuid ( assetUuid ) . withAssetName ( "NAME" ) . withAssetType ( ExampleAsset . class . getName ( ) ) . withCreatedTimestamp ( createTime ) . withSystemId ( 321 ) . withVersion ( new Version ( 1 , 2 ) ) . withUuid ( obsUuid ) ; ComplexTypesMapEntry props = ComplexTypesMapEntry . newBuilder ( ) . setKey ( ObservationStore . EVENT_PROP_OBSERVATION ) . setObservationNative ( observation ) . build ( ) ; SendEventData sendEvent = SendEventData . newBuilder ( ) . setTopic ( ObservationStore . TOPIC_OBSERVATION_PERSISTED_WITH_OBS ) . addProperty ( props ) . build ( ) ; TerraHarvestMessage message = createEventAdminMessage ( EventAdminMessageType . SendEvent , sendEvent ) ; message . writeDelimitedTo ( m_Socket . getOutputStream ( ) ) ; MessageListener listener = new MessageListener ( m_Socket ) ; EventAdminNamespace namespace = ( EventAdminNamespace ) listener . waitForRemoteEvent ( ObservationStore . TOPIC_OBSERVATION_PERSISTED_WITH_OBS + RemoteConstants . REMOTE_TOPIC_SUFFIX , 1500 ) ; MessageListener . unregisterEvent ( regId , m_Socket ) ; SendEventData response = SendEventData . parseFrom ( namespace . getData ( ) ) ; ImmutableMap < String , ComplexTypesMapEntry > responseProps = Maps . uniqueIndex ( response . getPropertyList ( ) , new Function < ComplexTypesMapEntry , String > ( ) { @ Override public String apply ( ComplexTypesMapEntry entry ) { return entry . getKey ( ) ; } } ) ; JAXBContext jc = JAXBContext . newInstance ( Observation . class ) ; Marshaller m = jc . createMarshaller ( ) ; final ByteArrayOutputStream byteStream = new ByteArrayOutputStream ( ) ; m . setProperty ( Marshaller . JAXB_FORMATTED_OUTPUT , false ) ; m . setProperty ( Marshaller . JAXB_ENCODING , "UTF-8" ) ; m . marshal ( jaxbObservation , byteStream ) ; assertThat ( responseProps . get ( ObservationStore . EVENT_PROP_OBSERVATION ) . getObservationXml ( ) , is ( ByteString . copyFrom ( byteStream . toByteArray ( ) ) ) ) ; }
Verify observation event data can be sent back as XML.
Verify observation event data can be sent back as XML .
// 1. register for remote event //create a basic observation // property map of the event // send event message // 2. send message // 3 and 4 happen on the controller // 5. listener //verify property for the observation