mil.dod.th.ose.gui.webapp/test/mil/dod/th/ose/gui/webapp/advanced/configuration/TestSystemMetatypeMgrImpl.java
@Test
    public void testMetaTypeEventHandlerNoAddPartial() throws SecurityException, IllegalArgumentException, 
        NoSuchFieldException, IllegalAccessException
    {
        setupMetaTypeInfo();
        
        String ocdName = "name";
        String ocdId = "ID";
        String description = ConfigurationConstants.PARTIAL_OBJECT_CLASS_DEFINITION;
        
        ObjectClassDefinitionType ocdMes1 = ObjectClassDefinitionType.newBuilder()
                .setName(ocdName)
                .setId(ocdId)
                .setDescription(description).build();
        ObjectClassDefinitionType ocdMes2 = ObjectClassDefinitionType.newBuilder()
                .setName(ocdName)
                .setId(ocdId).build();
        AttributeDefinitionType attrInt = AttributeDefinitionType.newBuilder().setAttributeType(
                AttributeDefinition.INTEGER).setCardinality(0).setDescription("some description int").setId("intField").
                setName("Int Field").build();
        AttributeDefinitionType attrString = AttributeDefinitionType.newBuilder().setAttributeType(
                AttributeDefinition.STRING).setCardinality(0).setDescription("some description string").
                setId("stringField").setName("String Field").build();
        AttributeDefinitionType attrBool = AttributeDefinitionType.newBuilder().setAttributeType(
                AttributeDefinition.BOOLEAN).setCardinality(0).setDescription("some description bool").
                setId("boolField").setName("Bool Field").build();
        List<AttributeDefinitionType> attributeList = new ArrayList<MetaTypeMessages.AttributeDefinitionType>();
        attributeList.add(attrInt);
        attributeList.add(attrString);
        attributeList.add(attrBool);
                
        MetaTypeInfoType meta1 = MetaTypeInfoType.newBuilder().setBundleId(BUNDLEID).setPid("some.factory").
                setIsFactory(true).addAllAttributes(attributeList).setOcd(ocdMes2).build();
        MetaTypeInfoType meta2 = MetaTypeInfoType.newBuilder().setBundleId(BUNDLEID2).setPid("some.service.bundle3").
                setIsFactory(false).addAllAttributes(attributeList).setOcd(ocdMes2).build();
        MetaTypeInfoType meta3 = MetaTypeInfoType.newBuilder().setBundleId(BUNDLEID2).
                setPid("something.different").setIsFactory(true).setOcd(ocdMes1)
                .addAllAttributes(attributeList).build();
        MetaTypeInfoType meta4 = MetaTypeInfoType.newBuilder().setBundleId(BUNDLEID).
                setPid("blah.blah").setIsFactory(false).setOcd(ocdMes1)
                .addAllAttributes(attributeList).build();
        List<MetaTypeInfoType> metaInfoList = new ArrayList<MetaTypeInfoType>();
        metaInfoList.add(meta1);
        metaInfoList.add(meta2);
        metaInfoList.add(meta3);
        metaInfoList.add(meta4);
        
        GetMetaTypeInfoResponseData responseMessage = 
                GetMetaTypeInfoResponseData.newBuilder().addAllMetaType(metaInfoList).build();
        MetaTypeNamespace namespace = MetaTypeNamespace.newBuilder().setType(
                MetaTypeMessageType.GetMetaTypeInfoResponse).setData(responseMessage.toByteString()).build();
        TerraHarvestMessage thMessage = TerraHarvestMessageHelper.createTerraHarvestMessage(CONTROLLERID, 0, 
                Namespace.MetaType, 5000, namespace);
        
        //Mock event
        Map<String, Object> props = new HashMap<>();
        props.put(RemoteConstants.EVENT_PROP_MESSAGE, thMessage);
        props.put(RemoteConstants.EVENT_PROP_DATA_MESSAGE, responseMessage);
        Event event = new Event(RemoteConstants.TOPIC_MESSAGE_RECEIVED, props);
        
        m_MetaTypeEventHandler.handleEvent(event);
        
        List<MetaTypeModel> modelList = m_SUT.getConfigurationsListAsync(CONTROLLERID);
        assertThat(modelList.size(), is(2));
        List<String> metaPidList = new ArrayList<String>();
        for (MetaTypeModel model: modelList)
        {
            metaPidList.add(model.getPid());
        }
        assertThat(metaPidList, hasItems("some.service.bundle3", "already.existent.service"));
        assertThat(metaPidList, not(hasItem("blah.blah")));
        
        List<MetaTypeModel> factoryModelList = m_SUT.getFactoriesListAsync(CONTROLLERID);
        assertThat(factoryModelList.size(), is(2));
        metaPidList = new ArrayList<String>();
        for (MetaTypeModel model: factoryModelList)
        {
            metaPidList.add(model.getPid());
        }
        assertThat(metaPidList, hasItems("some.factory", "already.existent.factory"));
        assertThat(metaPidList, not(hasItem("something.different")));
    }
/**
     * Test the metatype event handler.
     * Verify that the event handler handles all the get meta type information response correctly.
     * And will ignore the attributes if the OCD is a partial.
     */
Test the metatype event handler.
Verify that the event handler handles all the get meta type information response correctly.
And will ignore the attributes if the OCD is a partial.
Test the metatype event handler . Verify that the event handler handles all the get meta type information response correctly . And will ignore the attributes if the OCD is a partial .
@Test
    public void testMetaTypeEventHandlerNoAddPartial() throws SecurityException, IllegalArgumentException, 
        NoSuchFieldException, IllegalAccessException
    {
        setupMetaTypeInfo();
        String ocdName = "name";
        String ocdId = "ID";
        String description = ConfigurationConstants.PARTIAL_OBJECT_CLASS_DEFINITION;
        ObjectClassDefinitionType ocdMes1 = ObjectClassDefinitionType.newBuilder()
                .setName(ocdName)
                .setId(ocdId)
                .setDescription(description).build();
        ObjectClassDefinitionType ocdMes2 = ObjectClassDefinitionType.newBuilder()
                .setName(ocdName)
                .setId(ocdId).build();
        AttributeDefinitionType attrInt = AttributeDefinitionType.newBuilder().setAttributeType(
                AttributeDefinition.INTEGER).setCardinality(0).setDescription("some description int").setId("intField").
                setName("Int Field").build();
        AttributeDefinitionType attrString = AttributeDefinitionType.newBuilder().setAttributeType(
                AttributeDefinition.STRING).setCardinality(0).setDescription("some description string").
                setId("stringField").setName("String Field").build();
        AttributeDefinitionType attrBool = AttributeDefinitionType.newBuilder().setAttributeType(
                AttributeDefinition.BOOLEAN).setCardinality(0).setDescription("some description bool").
                setId("boolField").setName("Bool Field").build();
        List<AttributeDefinitionType> attributeList = new ArrayList<MetaTypeMessages.AttributeDefinitionType>();
        attributeList.add(attrInt);
        attributeList.add(attrString);
        attributeList.add(attrBool);
        MetaTypeInfoType meta1 = MetaTypeInfoType.newBuilder().setBundleId(BUNDLEID).setPid("some.factory").
                setIsFactory(true).addAllAttributes(attributeList).setOcd(ocdMes2).build();
        MetaTypeInfoType meta2 = MetaTypeInfoType.newBuilder().setBundleId(BUNDLEID2).setPid("some.service.bundle3").
                setIsFactory(false).addAllAttributes(attributeList).setOcd(ocdMes2).build();
        MetaTypeInfoType meta3 = MetaTypeInfoType.newBuilder().setBundleId(BUNDLEID2).
                setPid("something.different").setIsFactory(true).setOcd(ocdMes1)
                .addAllAttributes(attributeList).build();
        MetaTypeInfoType meta4 = MetaTypeInfoType.newBuilder().setBundleId(BUNDLEID).
                setPid("blah.blah").setIsFactory(false).setOcd(ocdMes1)
                .addAllAttributes(attributeList).build();
        List<MetaTypeInfoType> metaInfoList = new ArrayList<MetaTypeInfoType>();
        metaInfoList.add(meta1);
        metaInfoList.add(meta2);
        metaInfoList.add(meta3);
        metaInfoList.add(meta4);
        GetMetaTypeInfoResponseData responseMessage = 
                GetMetaTypeInfoResponseData.newBuilder().addAllMetaType(metaInfoList).build();
        MetaTypeNamespace namespace = MetaTypeNamespace.newBuilder().setType(
                MetaTypeMessageType.GetMetaTypeInfoResponse).setData(responseMessage.toByteString()).build();
        TerraHarvestMessage thMessage = TerraHarvestMessageHelper.createTerraHarvestMessage(CONTROLLERID, 0, 
                Namespace.MetaType, 5000, namespace);
        Map<String, Object> props = new HashMap<>();
        props.put(RemoteConstants.EVENT_PROP_MESSAGE, thMessage);
        props.put(RemoteConstants.EVENT_PROP_DATA_MESSAGE, responseMessage);
        Event event = new Event(RemoteConstants.TOPIC_MESSAGE_RECEIVED, props);
        m_MetaTypeEventHandler.handleEvent(event);
        List<MetaTypeModel> modelList = m_SUT.getConfigurationsListAsync(CONTROLLERID);
        assertThat(modelList.size(), is(2));
        List<String> metaPidList = new ArrayList<String>();
        for (MetaTypeModel model: modelList)
        {
            metaPidList.add(model.getPid());
        }
        assertThat(metaPidList, hasItems("some.service.bundle3", "already.existent.service"));
        assertThat(metaPidList, not(hasItem("blah.blah")));
        List<MetaTypeModel> factoryModelList = m_SUT.getFactoriesListAsync(CONTROLLERID);
        assertThat(factoryModelList.size(), is(2));
        metaPidList = new ArrayList<String>();
        for (MetaTypeModel model: factoryModelList)
        {
            metaPidList.add(model.getPid());
        }
        assertThat(metaPidList, hasItems("some.factory", "already.existent.factory"));
        assertThat(metaPidList, not(hasItem("something.different")));
    }
@ Test public void testMetaTypeEventHandlerNoAddPartial ( ) throws SecurityException , IllegalArgumentException , NoSuchFieldException , IllegalAccessException { setupMetaTypeInfo ( ) ; String ocdName = "name" ; String ocdId = "ID" ; String description = ConfigurationConstants . PARTIAL_OBJECT_CLASS_DEFINITION ; ObjectClassDefinitionType ocdMes1 = ObjectClassDefinitionType . newBuilder ( ) . setName ( ocdName ) . setId ( ocdId ) . setDescription ( description ) . build ( ) ; ObjectClassDefinitionType ocdMes2 = ObjectClassDefinitionType . newBuilder ( ) . setName ( ocdName ) . setId ( ocdId ) . build ( ) ; AttributeDefinitionType attrInt = AttributeDefinitionType . newBuilder ( ) . setAttributeType ( AttributeDefinition . INTEGER ) . setCardinality ( 0 ) . setDescription ( "some description int" ) . setId ( "intField" ) . setName ( "Int Field" ) . build ( ) ; AttributeDefinitionType attrString = AttributeDefinitionType . newBuilder ( ) . setAttributeType ( AttributeDefinition . STRING ) . setCardinality ( 0 ) . setDescription ( "some description string" ) . setId ( "stringField" ) . setName ( "String Field" ) . build ( ) ; AttributeDefinitionType attrBool = AttributeDefinitionType . newBuilder ( ) . setAttributeType ( AttributeDefinition . BOOLEAN ) . setCardinality ( 0 ) . setDescription ( "some description bool" ) . setId ( "boolField" ) . setName ( "Bool Field" ) . build ( ) ; List < AttributeDefinitionType > attributeList = new ArrayList < MetaTypeMessages . AttributeDefinitionType > ( ) ; attributeList . add ( attrInt ) ; attributeList . add ( attrString ) ; attributeList . add ( attrBool ) ; MetaTypeInfoType meta1 = MetaTypeInfoType . newBuilder ( ) . setBundleId ( BUNDLEID ) . setPid ( "some.factory" ) . setIsFactory ( true ) . addAllAttributes ( attributeList ) . setOcd ( ocdMes2 ) . build ( ) ; MetaTypeInfoType meta2 = MetaTypeInfoType . newBuilder ( ) . setBundleId ( BUNDLEID2 ) . setPid ( "some.service.bundle3" ) . setIsFactory ( false ) . addAllAttributes ( attributeList ) . setOcd ( ocdMes2 ) . build ( ) ; MetaTypeInfoType meta3 = MetaTypeInfoType . newBuilder ( ) . setBundleId ( BUNDLEID2 ) . setPid ( "something.different" ) . setIsFactory ( true ) . setOcd ( ocdMes1 ) . addAllAttributes ( attributeList ) . build ( ) ; MetaTypeInfoType meta4 = MetaTypeInfoType . newBuilder ( ) . setBundleId ( BUNDLEID ) . setPid ( "blah.blah" ) . setIsFactory ( false ) . setOcd ( ocdMes1 ) . addAllAttributes ( attributeList ) . build ( ) ; List < MetaTypeInfoType > metaInfoList = new ArrayList < MetaTypeInfoType > ( ) ; metaInfoList . add ( meta1 ) ; metaInfoList . add ( meta2 ) ; metaInfoList . add ( meta3 ) ; metaInfoList . add ( meta4 ) ; GetMetaTypeInfoResponseData responseMessage = GetMetaTypeInfoResponseData . newBuilder ( ) . addAllMetaType ( metaInfoList ) . build ( ) ; MetaTypeNamespace namespace = MetaTypeNamespace . newBuilder ( ) . setType ( MetaTypeMessageType . GetMetaTypeInfoResponse ) . setData ( responseMessage . toByteString ( ) ) . build ( ) ; TerraHarvestMessage thMessage = TerraHarvestMessageHelper . createTerraHarvestMessage ( CONTROLLERID , 0 , Namespace . MetaType , 5000 , namespace ) ; Map < String , Object > props = new HashMap < > ( ) ; props . put ( RemoteConstants . EVENT_PROP_MESSAGE , thMessage ) ; props . put ( RemoteConstants . EVENT_PROP_DATA_MESSAGE , responseMessage ) ; Event event = new Event ( RemoteConstants . TOPIC_MESSAGE_RECEIVED , props ) ; m_MetaTypeEventHandler . handleEvent ( event ) ; List < MetaTypeModel > modelList = m_SUT . getConfigurationsListAsync ( CONTROLLERID ) ; assertThat ( modelList . size ( ) , is ( 2 ) ) ; List < String > metaPidList = new ArrayList < String > ( ) ; for ( MetaTypeModel model : modelList ) { metaPidList . add ( model . getPid ( ) ) ; } assertThat ( metaPidList , hasItems ( "some.service.bundle3" , "already.existent.service" ) ) ; assertThat ( metaPidList , not ( hasItem ( "blah.blah" ) ) ) ; List < MetaTypeModel > factoryModelList = m_SUT . getFactoriesListAsync ( CONTROLLERID ) ; assertThat ( factoryModelList . size ( ) , is ( 2 ) ) ; metaPidList = new ArrayList < String > ( ) ; for ( MetaTypeModel model : factoryModelList ) { metaPidList . add ( model . getPid ( ) ) ; } assertThat ( metaPidList , hasItems ( "some.factory" , "already.existent.factory" ) ) ; assertThat ( metaPidList , not ( hasItem ( "something.different" ) ) ) ; }
Test the metatype event handler.
Test the metatype event handler .
//Mock event