mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/asset/TestAssetDirectoryMessageService.java
@Test
    public void testCreateAssetWithName() throws IllegalArgumentException, AssetException, IOException
    {
        CreateAssetRequestData request = CreateAssetRequestData.newBuilder().
                setProductType("my.FQ.className").setName("TheBestName").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(this.m_AssetDirectoryService.createAsset(Mockito.anyString(), Mockito.anyString())).thenReturn(asset);
        
        // mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);

        // replay
        m_SUT.handleMessage(message, payload, channel);

        //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 name is set and 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 name is set and 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 name is set and passed to the core service correctly when provided in the message .
@Test
    public void testCreateAssetWithName() throws IllegalArgumentException, AssetException, IOException
    {
        CreateAssetRequestData request = CreateAssetRequestData.newBuilder().
                setProductType("my.FQ.className").setName("TheBestName").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(this.m_AssetDirectoryService.createAsset(Mockito.anyString(), Mockito.anyString())).thenReturn(asset);
        RemoteChannel channel = mock(RemoteChannel.class);
        m_SUT.handleMessage(message, payload, channel);
        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 public void testCreateAssetWithName ( ) throws IllegalArgumentException , AssetException , IOException { CreateAssetRequestData request = CreateAssetRequestData . newBuilder ( ) . setProductType ( "my.FQ.className" ) . setName ( "TheBestName" ) . 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 ( this . m_AssetDirectoryService . createAsset ( Mockito . anyString ( ) , Mockito . anyString ( ) ) ) . thenReturn ( asset ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; m_SUT . handleMessage ( message , payload , channel ) ; 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 event has been posted locally //capture and verify response //assert that uuid in response matches expected uuid