mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/asset/TestAssetDirectoryMessageService.java
@SuppressWarnings({"unchecked", "rawtypes"})
    @Test
    public void testCreateAssetWithProperties() throws IllegalArgumentException, AssetException, IOException
    {
        SimpleTypesMapEntry property = SimpleTypesMapEntry.newBuilder().setKey("propA").setValue(
                Multitype.newBuilder().setType(Type.BOOL).setBoolValue(true).build()).build();
        CreateAssetRequestData request = CreateAssetRequestData.newBuilder().
                setProductType("my.FQ.className").setName("test").addProperties(property).build();
        AssetDirectoryServiceNamespace assetDirMessage = AssetDirectoryServiceNamespace.newBuilder().
                setType(AssetDirectoryServiceMessageType.CreateAssetRequest).
                setData(request.toByteString()).build();
        TerraHarvestPayload payload = createPayload(assetDirMessage);
        TerraHarvestMessage message = createMessage(assetDirMessage);
        
        Asset asset = FactoryObjectMocker.mockFactoryObject(Asset.class, "PID");
        when(m_AssetDirectoryService.createAsset(Mockito.anyString(), Mockito.anyString(), 
                Mockito.anyMap())).thenReturn(asset);
        
        // mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);

        // replay
        m_SUT.handleMessage(message, payload, channel);
        
        //capture and verify correct create asset method was called with appropriate properties
        ArgumentCaptor<Map> mapCaptor = ArgumentCaptor.forClass(Map.class);
        verify(m_AssetDirectoryService).createAsset(eq("my.FQ.className"), eq("test"), mapCaptor.capture());
        Map<String, Object> properties = mapCaptor.getValue();
        assertThat(properties.containsKey("propA"), is(true));
        assertThat((boolean)properties.get("propA"), is(true));

        //capture and verify event has been posted locally
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event event = eventCaptor.getValue();
        assertThat((CreateAssetRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(request));

        //capture and verify response
        ArgumentCaptor<CreateAssetResponseData> messageCaptor = ArgumentCaptor.forClass(CreateAssetResponseData.class); 
        verify(m_MessageFactory).createAssetDirectoryServiceResponseMessage(eq(message), 
                eq(AssetDirectoryServiceMessageType.CreateAssetResponse), messageCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);

        CreateAssetResponseData response = messageCaptor.getValue();
        
        //assert that uuid in response matches expected uuid
        assertThat(response.getInfo().getUuid().getLeastSignificantBits(), 
                is(asset.getUuid().getLeastSignificantBits()));
        assertThat(response.getInfo().getUuid().getMostSignificantBits(), 
                is(asset.getUuid().getMostSignificantBits()));
        assertThat(response.getInfo().getPid(), is("PID"));  
    }
/**
     * Test the create asset request/response remote message system for the asset directory service.
     * Specifically, this test verifies that the asset properties specified are passed to the core service correctly
     * when provided in the message.
     */
Test the create asset request/response remote message system for the asset directory service.
Specifically, this test verifies that the asset properties specified are passed to the core service correctly
when provided in the message.
Test the create asset request / response remote message system for the asset directory service . Specifically this test verifies that the asset properties specified are passed to the core service correctly when provided in the message .
@SuppressWarnings({"unchecked", "rawtypes"})
    @Test
    public void testCreateAssetWithProperties() throws IllegalArgumentException, AssetException, IOException
    {
        SimpleTypesMapEntry property = SimpleTypesMapEntry.newBuilder().setKey("propA").setValue(
                Multitype.newBuilder().setType(Type.BOOL).setBoolValue(true).build()).build();
        CreateAssetRequestData request = CreateAssetRequestData.newBuilder().
                setProductType("my.FQ.className").setName("test").addProperties(property).build();
        AssetDirectoryServiceNamespace assetDirMessage = AssetDirectoryServiceNamespace.newBuilder().
                setType(AssetDirectoryServiceMessageType.CreateAssetRequest).
                setData(request.toByteString()).build();
        TerraHarvestPayload payload = createPayload(assetDirMessage);
        TerraHarvestMessage message = createMessage(assetDirMessage);
        Asset asset = FactoryObjectMocker.mockFactoryObject(Asset.class, "PID");
        when(m_AssetDirectoryService.createAsset(Mockito.anyString(), Mockito.anyString(), 
                Mockito.anyMap())).thenReturn(asset);
        RemoteChannel channel = mock(RemoteChannel.class);
        m_SUT.handleMessage(message, payload, channel);
        ArgumentCaptor<Map> mapCaptor = ArgumentCaptor.forClass(Map.class);
        verify(m_AssetDirectoryService).createAsset(eq("my.FQ.className"), eq("test"), mapCaptor.capture());
        Map<String, Object> properties = mapCaptor.getValue();
        assertThat(properties.containsKey("propA"), is(true));
        assertThat((boolean)properties.get("propA"), is(true));
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event event = eventCaptor.getValue();
        assertThat((CreateAssetRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(request));
        ArgumentCaptor<CreateAssetResponseData> messageCaptor = ArgumentCaptor.forClass(CreateAssetResponseData.class); 
        verify(m_MessageFactory).createAssetDirectoryServiceResponseMessage(eq(message), 
                eq(AssetDirectoryServiceMessageType.CreateAssetResponse), messageCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        CreateAssetResponseData response = messageCaptor.getValue();
        assertThat(response.getInfo().getUuid().getLeastSignificantBits(), 
                is(asset.getUuid().getLeastSignificantBits()));
        assertThat(response.getInfo().getUuid().getMostSignificantBits(), 
                is(asset.getUuid().getMostSignificantBits()));
        assertThat(response.getInfo().getPid(), is("PID"));  
    }
@ SuppressWarnings ( { "unchecked" , "rawtypes" } ) @ Test public void testCreateAssetWithProperties ( ) throws IllegalArgumentException , AssetException , IOException { SimpleTypesMapEntry property = SimpleTypesMapEntry . newBuilder ( ) . setKey ( "propA" ) . setValue ( Multitype . newBuilder ( ) . setType ( Type . BOOL ) . setBoolValue ( true ) . build ( ) ) . build ( ) ; CreateAssetRequestData request = CreateAssetRequestData . newBuilder ( ) . setProductType ( "my.FQ.className" ) . setName ( "test" ) . addProperties ( property ) . build ( ) ; AssetDirectoryServiceNamespace assetDirMessage = AssetDirectoryServiceNamespace . newBuilder ( ) . setType ( AssetDirectoryServiceMessageType . CreateAssetRequest ) . setData ( request . toByteString ( ) ) . build ( ) ; TerraHarvestPayload payload = createPayload ( assetDirMessage ) ; TerraHarvestMessage message = createMessage ( assetDirMessage ) ; Asset asset = FactoryObjectMocker . mockFactoryObject ( Asset . class , "PID" ) ; when ( m_AssetDirectoryService . createAsset ( Mockito . anyString ( ) , Mockito . anyString ( ) , Mockito . anyMap ( ) ) ) . thenReturn ( asset ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; m_SUT . handleMessage ( message , payload , channel ) ; ArgumentCaptor < Map > mapCaptor = ArgumentCaptor . forClass ( Map . class ) ; verify ( m_AssetDirectoryService ) . createAsset ( eq ( "my.FQ.className" ) , eq ( "test" ) , mapCaptor . capture ( ) ) ; Map < String , Object > properties = mapCaptor . getValue ( ) ; assertThat ( properties . containsKey ( "propA" ) , is ( true ) ) ; assertThat ( ( boolean ) properties . get ( "propA" ) , is ( true ) ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin ) . postEvent ( eventCaptor . capture ( ) ) ; Event event = eventCaptor . getValue ( ) ; assertThat ( ( CreateAssetRequestData ) event . getProperty ( RemoteConstants . EVENT_PROP_DATA_MESSAGE ) , is ( request ) ) ; ArgumentCaptor < CreateAssetResponseData > messageCaptor = ArgumentCaptor . forClass ( CreateAssetResponseData . class ) ; verify ( m_MessageFactory ) . createAssetDirectoryServiceResponseMessage ( eq ( message ) , eq ( AssetDirectoryServiceMessageType . CreateAssetResponse ) , messageCaptor . capture ( ) ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; CreateAssetResponseData response = messageCaptor . getValue ( ) ; assertThat ( response . getInfo ( ) . getUuid ( ) . getLeastSignificantBits ( ) , is ( asset . getUuid ( ) . getLeastSignificantBits ( ) ) ) ; assertThat ( response . getInfo ( ) . getUuid ( ) . getMostSignificantBits ( ) , is ( asset . getUuid ( ) . getMostSignificantBits ( ) ) ) ; assertThat ( response . getInfo ( ) . getPid ( ) , is ( "PID" ) ) ; }
Test the create asset request/response remote message system for the asset directory service.
Test the create asset request / response remote message system for the asset directory service .
// mock the channel the message came from // replay //capture and verify correct create asset method was called with appropriate properties //capture and verify event has been posted locally //capture and verify response //assert that uuid in response matches expected uuid