mil.dod.th.ose.gui.webapp/test/mil/dod/th/ose/gui/webapp/asset/TestAddAssetDialogHelperImpl.java
@Test
    public void testRequestCreateAssetWithProps()
    {
        
        //mock asset factory
        AssetFactoryModel factoryModel = mock(AssetFactoryModel.class);
        when(factoryModel.getFullyQualifiedAssetType()).thenReturn("com.example.Awesome");
        
        //mock configuration and meta data
        UnmodifiableConfigMetatypeModel configModel = mock(UnmodifiableConfigMetatypeModel.class);
        when(m_ConfigWrapper.getConfigurationDefaultsByFactoryPidAsync(125, "com.example.AwesomeConfig"))
            .thenReturn(configModel);
        
        AttributeModel attrib1 = mock(AttributeModel.class);
        AttributeModel attrib2 = mock(AttributeModel.class);
        when(attrib1.getId()).thenReturn("some.value1");
        when(attrib1.getType()).thenReturn(AttributeDefinition.INTEGER);
        when(attrib1.getDefaultValues()).thenReturn(new ArrayList<String>());
        when(attrib1.getOptionLabels()).thenReturn(new ArrayList<String>());
        when(attrib2.getId()).thenReturn("some.value2");
        when(attrib2.getType()).thenReturn(AttributeDefinition.BOOLEAN);
        when(attrib2.getDefaultValues()).thenReturn(new ArrayList<String>());
        when(attrib2.getOptionLabels()).thenReturn(new ArrayList<String>());
        
        ConfigPropModelImpl prop1 = new ConfigPropModelImpl(attrib1);
        prop1.setValue(1337);
        ConfigPropModelImpl prop2 = new ConfigPropModelImpl(attrib2);
        prop2.setValue(true);
        List<UnmodifiablePropertyModel> propList = new ArrayList<>();
        propList.add(prop1);
        propList.add(prop2);
        when(configModel.getProperties()).thenReturn(propList);
        
        //controller id to use
        int systemId = 321;

        //create variables
        String productType = "mil.dod.you.me.Everybody";
        String name = "EverybodyAsset";

        m_SUT.setAssetFactory(factoryModel);
        m_SUT.requestCreateAsset(productType, systemId, name);

        //verify message sent to remove the assetS
        ArgumentCaptor<CreateAssetRequestData> request = 
            ArgumentCaptor.forClass(CreateAssetRequestData.class);

        verify(m_MessageFactory).createAssetDirectoryServiceMessage(
            eq(AssetDirectoryServiceMessageType.CreateAssetRequest), 
                request.capture());
        verify(m_MessageWrapper).queue(eq(systemId), Mockito.any(RemoteCreateAssetHandler.class));
        verify(m_AssetMgr).createRemoteAssetHandler();

        //get message
        CreateAssetRequestData requestCapture = request.getValue();

        //verify
        assertThat(requestCapture.getProductType(), is(productType));
        Map<String, Object> requestProps = SharedMessageUtils.convertListSimpleTypesMapEntrytoMapStringObject(
                requestCapture.getPropertiesList());
        assertThat(requestProps, hasEntry("some.value1", (Object)1337));
        assertThat(requestProps, hasEntry("some.value2", (Object)true));
    }
/**
     * Test the request to create a new asset.
     * Verify message sent.
     * Verify response handler requested from asset manager.
     * Verify configuration properties are sent with message.
     */
Test the request to create a new asset.
Verify message sent.
Verify response handler requested from asset manager.
Verify configuration properties are sent with message.
Test the request to create a new asset . Verify message sent . Verify response handler requested from asset manager . Verify configuration properties are sent with message .
@Test
    public void testRequestCreateAssetWithProps()
    {
        AssetFactoryModel factoryModel = mock(AssetFactoryModel.class);
        when(factoryModel.getFullyQualifiedAssetType()).thenReturn("com.example.Awesome");
        UnmodifiableConfigMetatypeModel configModel = mock(UnmodifiableConfigMetatypeModel.class);
        when(m_ConfigWrapper.getConfigurationDefaultsByFactoryPidAsync(125, "com.example.AwesomeConfig"))
            .thenReturn(configModel);
        AttributeModel attrib1 = mock(AttributeModel.class);
        AttributeModel attrib2 = mock(AttributeModel.class);
        when(attrib1.getId()).thenReturn("some.value1");
        when(attrib1.getType()).thenReturn(AttributeDefinition.INTEGER);
        when(attrib1.getDefaultValues()).thenReturn(new ArrayList<String>());
        when(attrib1.getOptionLabels()).thenReturn(new ArrayList<String>());
        when(attrib2.getId()).thenReturn("some.value2");
        when(attrib2.getType()).thenReturn(AttributeDefinition.BOOLEAN);
        when(attrib2.getDefaultValues()).thenReturn(new ArrayList<String>());
        when(attrib2.getOptionLabels()).thenReturn(new ArrayList<String>());
        ConfigPropModelImpl prop1 = new ConfigPropModelImpl(attrib1);
        prop1.setValue(1337);
        ConfigPropModelImpl prop2 = new ConfigPropModelImpl(attrib2);
        prop2.setValue(true);
        List<UnmodifiablePropertyModel> propList = new ArrayList<>();
        propList.add(prop1);
        propList.add(prop2);
        when(configModel.getProperties()).thenReturn(propList);
        int systemId = 321;
        String productType = "mil.dod.you.me.Everybody";
        String name = "EverybodyAsset";
        m_SUT.setAssetFactory(factoryModel);
        m_SUT.requestCreateAsset(productType, systemId, name);
        ArgumentCaptor<CreateAssetRequestData> request = 
            ArgumentCaptor.forClass(CreateAssetRequestData.class);
        verify(m_MessageFactory).createAssetDirectoryServiceMessage(
            eq(AssetDirectoryServiceMessageType.CreateAssetRequest), 
                request.capture());
        verify(m_MessageWrapper).queue(eq(systemId), Mockito.any(RemoteCreateAssetHandler.class));
        verify(m_AssetMgr).createRemoteAssetHandler();
        CreateAssetRequestData requestCapture = request.getValue();
        assertThat(requestCapture.getProductType(), is(productType));
        Map<String, Object> requestProps = SharedMessageUtils.convertListSimpleTypesMapEntrytoMapStringObject(
                requestCapture.getPropertiesList());
        assertThat(requestProps, hasEntry("some.value1", (Object)1337));
        assertThat(requestProps, hasEntry("some.value2", (Object)true));
    }
@ Test public void testRequestCreateAssetWithProps ( ) { AssetFactoryModel factoryModel = mock ( AssetFactoryModel . class ) ; when ( factoryModel . getFullyQualifiedAssetType ( ) ) . thenReturn ( "com.example.Awesome" ) ; UnmodifiableConfigMetatypeModel configModel = mock ( UnmodifiableConfigMetatypeModel . class ) ; when ( m_ConfigWrapper . getConfigurationDefaultsByFactoryPidAsync ( 125 , "com.example.AwesomeConfig" ) ) . thenReturn ( configModel ) ; AttributeModel attrib1 = mock ( AttributeModel . class ) ; AttributeModel attrib2 = mock ( AttributeModel . class ) ; when ( attrib1 . getId ( ) ) . thenReturn ( "some.value1" ) ; when ( attrib1 . getType ( ) ) . thenReturn ( AttributeDefinition . INTEGER ) ; when ( attrib1 . getDefaultValues ( ) ) . thenReturn ( new ArrayList < String > ( ) ) ; when ( attrib1 . getOptionLabels ( ) ) . thenReturn ( new ArrayList < String > ( ) ) ; when ( attrib2 . getId ( ) ) . thenReturn ( "some.value2" ) ; when ( attrib2 . getType ( ) ) . thenReturn ( AttributeDefinition . BOOLEAN ) ; when ( attrib2 . getDefaultValues ( ) ) . thenReturn ( new ArrayList < String > ( ) ) ; when ( attrib2 . getOptionLabels ( ) ) . thenReturn ( new ArrayList < String > ( ) ) ; ConfigPropModelImpl prop1 = new ConfigPropModelImpl ( attrib1 ) ; prop1 . setValue ( 1337 ) ; ConfigPropModelImpl prop2 = new ConfigPropModelImpl ( attrib2 ) ; prop2 . setValue ( true ) ; List < UnmodifiablePropertyModel > propList = new ArrayList < > ( ) ; propList . add ( prop1 ) ; propList . add ( prop2 ) ; when ( configModel . getProperties ( ) ) . thenReturn ( propList ) ; int systemId = 321 ; String productType = "mil.dod.you.me.Everybody" ; String name = "EverybodyAsset" ; m_SUT . setAssetFactory ( factoryModel ) ; m_SUT . requestCreateAsset ( productType , systemId , name ) ; ArgumentCaptor < CreateAssetRequestData > request = ArgumentCaptor . forClass ( CreateAssetRequestData . class ) ; verify ( m_MessageFactory ) . createAssetDirectoryServiceMessage ( eq ( AssetDirectoryServiceMessageType . CreateAssetRequest ) , request . capture ( ) ) ; verify ( m_MessageWrapper ) . queue ( eq ( systemId ) , Mockito . any ( RemoteCreateAssetHandler . class ) ) ; verify ( m_AssetMgr ) . createRemoteAssetHandler ( ) ; CreateAssetRequestData requestCapture = request . getValue ( ) ; assertThat ( requestCapture . getProductType ( ) , is ( productType ) ) ; Map < String , Object > requestProps = SharedMessageUtils . convertListSimpleTypesMapEntrytoMapStringObject ( requestCapture . getPropertiesList ( ) ) ; assertThat ( requestProps , hasEntry ( "some.value1" , ( Object ) 1337 ) ) ; assertThat ( requestProps , hasEntry ( "some.value2" , ( Object ) true ) ) ; }
Test the request to create a new asset.
Test the request to create a new asset .
//mock asset factory //mock configuration and meta data //controller id to use //create variables //verify message sent to remove the assetS //get message //verify