mil.dod.th.ose.remote.integration/src/mil/dod/th/ose/remote/integration/base/TestMetatypeInformationListener.java
@SuppressWarnings({"unchecked"})//class casting to string array
    @Test
    public void testMetatypeInformationInstalledBundleXML() throws IOException, InterruptedException
    {
        MessageListener listener = new MessageListener(socket);

        //find the test bundle
        long testBundleId = BundleNamespaceUtils.getBundleBySymbolicName("mil.dod.th.ose.integration.example.metatype", 
                socket);

        //verify that the test bundle was found
        assertThat(testBundleId, greaterThan(0L));

        int regId = RemoteEventRegistration.regRemoteEventMessages(socket, 
                RemoteMetatypeConstants.TOPIC_METATYPE_INFORMATION_AVAILABLE);

        //jar to update
        File jarFile = new File(ResourceUtils.getBaseIntegrationPath(), 
                "generated/mil.dod.th.ose.integration.example.metatype.jar");
        byte[] buf = FileUtils.readFileToByteArray(jarFile);
        //construct request to start bundle
        UpdateRequestData requestStart = UpdateRequestData.newBuilder().setBundleFile(ByteString.copyFrom(buf)).
                setBundleId(testBundleId).build();
        TerraHarvestMessage message = 
                BundleNamespaceUtils.createBundleMessage(requestStart, BundleMessageType.UpdateRequest);

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

        //listen for response from the configuration listener, extraneous wait
        //because the bundle needs time to start, framework needs to post bundle event and then
        //then the metatype listener will post its event.
        List<MessageDetails> responses = listener.waitForRemoteEvents(
                RemoteMetatypeConstants.TOPIC_METATYPE_INFORMATION_AVAILABLE, TIME_OUT, MatchCount.atLeast(2));

        //unreg listener
        MessageListener.unregisterEvent(regId, socket);

        //parse Response
        EventAdminNamespace namespace = (EventAdminNamespace)responses.get(0).getNamespaceMessage();
        SendEventData event = SendEventData.parseFrom(namespace.getData());

        Map<String, Object> propertyMap = 
             SharedRemoteInterfaceUtils.getSimpleMapFromComplexTypesMap(event.getPropertyList());

        //check other response
        namespace = (EventAdminNamespace)responses.get(1).getNamespaceMessage();
        event = SendEventData.parseFrom(namespace.getData());

        Map<String, Object> propertyMap2 = 
             SharedRemoteInterfaceUtils.getSimpleMapFromComplexTypesMap(event.getPropertyList());
        //verify events
        if (((List<String>)propertyMap.get(RemoteMetatypeConstants.EVENT_PROP_PIDS)).
                contains("example.metatype.XML.ExampleClass"))
        {
            assertThat((Long)propertyMap.get(RemoteMetatypeConstants.EVENT_PROP_BUNDLE_ID), is(testBundleId));
        }
        else
        {
            //verify
            assertThat((Long)propertyMap.get(RemoteMetatypeConstants.EVENT_PROP_BUNDLE_ID), is(testBundleId));
            assertThat((List<String>)propertyMap.get(RemoteMetatypeConstants.EVENT_PROP_PIDS), 
                hasItem("example.metatype.configadmin.ExampleInMemConfigClass"));
        }
        //verify events
        if (((List<String>)propertyMap2.get(RemoteMetatypeConstants.EVENT_PROP_PIDS)).
                contains("example.metatype.XML.ExampleClass"))
        {
            assertThat((Long)propertyMap2.get(RemoteMetatypeConstants.EVENT_PROP_BUNDLE_ID), is(testBundleId));
        }
        else
        {
            //verify
            assertThat((Long)propertyMap2.get(RemoteMetatypeConstants.EVENT_PROP_BUNDLE_ID), is(testBundleId));
            assertThat((List<String>)propertyMap2.get(RemoteMetatypeConstants.EVENT_PROP_PIDS), 
                hasItem("example.metatype.configadmin.ExampleInMemConfigClass"));
        }
    }
/**
     * Test stopping and starting the example metatype bundle. This bundle contains both a managed service and 
     * XML based metatype information. 
     * Verify Meta type information available events are received with expected information.
     */
Test stopping and starting the example metatype bundle. This bundle contains both a managed service and
XML based metatype information.
Verify Meta type information available events are received with expected information.
Test stopping and starting the example metatype bundle . This bundle contains both a managed service and XML based metatype information . Verify Meta type information available events are received with expected information .
@SuppressWarnings({"unchecked"})
    @Test
    public void testMetatypeInformationInstalledBundleXML() throws IOException, InterruptedException
    {
        MessageListener listener = new MessageListener(socket);
        long testBundleId = BundleNamespaceUtils.getBundleBySymbolicName("mil.dod.th.ose.integration.example.metatype", 
                socket);
        assertThat(testBundleId, greaterThan(0L));
        int regId = RemoteEventRegistration.regRemoteEventMessages(socket, 
                RemoteMetatypeConstants.TOPIC_METATYPE_INFORMATION_AVAILABLE);
        File jarFile = new File(ResourceUtils.getBaseIntegrationPath(), 
                "generated/mil.dod.th.ose.integration.example.metatype.jar");
        byte[] buf = FileUtils.readFileToByteArray(jarFile);
        UpdateRequestData requestStart = UpdateRequestData.newBuilder().setBundleFile(ByteString.copyFrom(buf)).
                setBundleId(testBundleId).build();
        TerraHarvestMessage message = 
                BundleNamespaceUtils.createBundleMessage(requestStart, BundleMessageType.UpdateRequest);
        message.writeDelimitedTo(socket.getOutputStream());
        List<MessageDetails> responses = listener.waitForRemoteEvents(
                RemoteMetatypeConstants.TOPIC_METATYPE_INFORMATION_AVAILABLE, TIME_OUT, MatchCount.atLeast(2));
        MessageListener.unregisterEvent(regId, socket);
        EventAdminNamespace namespace = (EventAdminNamespace)responses.get(0).getNamespaceMessage();
        SendEventData event = SendEventData.parseFrom(namespace.getData());
        Map<String, Object> propertyMap = 
             SharedRemoteInterfaceUtils.getSimpleMapFromComplexTypesMap(event.getPropertyList());
        namespace = (EventAdminNamespace)responses.get(1).getNamespaceMessage();
        event = SendEventData.parseFrom(namespace.getData());
        Map<String, Object> propertyMap2 = 
             SharedRemoteInterfaceUtils.getSimpleMapFromComplexTypesMap(event.getPropertyList());
        if (((List<String>)propertyMap.get(RemoteMetatypeConstants.EVENT_PROP_PIDS)).
                contains("example.metatype.XML.ExampleClass"))
        {
            assertThat((Long)propertyMap.get(RemoteMetatypeConstants.EVENT_PROP_BUNDLE_ID), is(testBundleId));
        }
        else
        {
            assertThat((Long)propertyMap.get(RemoteMetatypeConstants.EVENT_PROP_BUNDLE_ID), is(testBundleId));
            assertThat((List<String>)propertyMap.get(RemoteMetatypeConstants.EVENT_PROP_PIDS), 
                hasItem("example.metatype.configadmin.ExampleInMemConfigClass"));
        }
        if (((List<String>)propertyMap2.get(RemoteMetatypeConstants.EVENT_PROP_PIDS)).
                contains("example.metatype.XML.ExampleClass"))
        {
            assertThat((Long)propertyMap2.get(RemoteMetatypeConstants.EVENT_PROP_BUNDLE_ID), is(testBundleId));
        }
        else
        {
            assertThat((Long)propertyMap2.get(RemoteMetatypeConstants.EVENT_PROP_BUNDLE_ID), is(testBundleId));
            assertThat((List<String>)propertyMap2.get(RemoteMetatypeConstants.EVENT_PROP_PIDS), 
                hasItem("example.metatype.configadmin.ExampleInMemConfigClass"));
        }
    }
@ SuppressWarnings ( { "unchecked" } ) @ Test public void testMetatypeInformationInstalledBundleXML ( ) throws IOException , InterruptedException { MessageListener listener = new MessageListener ( socket ) ; long testBundleId = BundleNamespaceUtils . getBundleBySymbolicName ( "mil.dod.th.ose.integration.example.metatype" , socket ) ; assertThat ( testBundleId , greaterThan ( 0L ) ) ; int regId = RemoteEventRegistration . regRemoteEventMessages ( socket , RemoteMetatypeConstants . TOPIC_METATYPE_INFORMATION_AVAILABLE ) ; File jarFile = new File ( ResourceUtils . getBaseIntegrationPath ( ) , "generated/mil.dod.th.ose.integration.example.metatype.jar" ) ; byte [ ] buf = FileUtils . readFileToByteArray ( jarFile ) ; UpdateRequestData requestStart = UpdateRequestData . newBuilder ( ) . setBundleFile ( ByteString . copyFrom ( buf ) ) . setBundleId ( testBundleId ) . build ( ) ; TerraHarvestMessage message = BundleNamespaceUtils . createBundleMessage ( requestStart , BundleMessageType . UpdateRequest ) ; message . writeDelimitedTo ( socket . getOutputStream ( ) ) ; List < MessageDetails > responses = listener . waitForRemoteEvents ( RemoteMetatypeConstants . TOPIC_METATYPE_INFORMATION_AVAILABLE , TIME_OUT , MatchCount . atLeast ( 2 ) ) ; MessageListener . unregisterEvent ( regId , socket ) ; EventAdminNamespace namespace = ( EventAdminNamespace ) responses . get ( 0 ) . getNamespaceMessage ( ) ; SendEventData event = SendEventData . parseFrom ( namespace . getData ( ) ) ; Map < String , Object > propertyMap = SharedRemoteInterfaceUtils . getSimpleMapFromComplexTypesMap ( event . getPropertyList ( ) ) ; namespace = ( EventAdminNamespace ) responses . get ( 1 ) . getNamespaceMessage ( ) ; event = SendEventData . parseFrom ( namespace . getData ( ) ) ; Map < String , Object > propertyMap2 = SharedRemoteInterfaceUtils . getSimpleMapFromComplexTypesMap ( event . getPropertyList ( ) ) ; if ( ( ( List < String > ) propertyMap . get ( RemoteMetatypeConstants . EVENT_PROP_PIDS ) ) . contains ( "example.metatype.XML.ExampleClass" ) ) { assertThat ( ( Long ) propertyMap . get ( RemoteMetatypeConstants . EVENT_PROP_BUNDLE_ID ) , is ( testBundleId ) ) ; } else { assertThat ( ( Long ) propertyMap . get ( RemoteMetatypeConstants . EVENT_PROP_BUNDLE_ID ) , is ( testBundleId ) ) ; assertThat ( ( List < String > ) propertyMap . get ( RemoteMetatypeConstants . EVENT_PROP_PIDS ) , hasItem ( "example.metatype.configadmin.ExampleInMemConfigClass" ) ) ; } if ( ( ( List < String > ) propertyMap2 . get ( RemoteMetatypeConstants . EVENT_PROP_PIDS ) ) . contains ( "example.metatype.XML.ExampleClass" ) ) { assertThat ( ( Long ) propertyMap2 . get ( RemoteMetatypeConstants . EVENT_PROP_BUNDLE_ID ) , is ( testBundleId ) ) ; } else { assertThat ( ( Long ) propertyMap2 . get ( RemoteMetatypeConstants . EVENT_PROP_BUNDLE_ID ) , is ( testBundleId ) ) ; assertThat ( ( List < String > ) propertyMap2 . get ( RemoteMetatypeConstants . EVENT_PROP_PIDS ) , hasItem ( "example.metatype.configadmin.ExampleInMemConfigClass" ) ) ; } }
Test stopping and starting the example metatype bundle.
Test stopping and starting the example metatype bundle .
//class casting to string array //find the test bundle //verify that the test bundle was found //jar to update //construct request to start bundle //send message //listen for response from the configuration listener, extraneous wait //because the bundle needs time to start, framework needs to post bundle event and then //then the metatype listener will post its event. //unreg listener //parse Response //check other response //verify events //verify //verify events //verify