mil.dod.th.ose.core/test/mil/dod/th/ose/core/factory/api/TestFactoryRegistry.java
@Test
    public void testPersistObjectData() throws IllegalArgumentException, FactoryException,
        FactoryObjectInformationException
    {
        // mock an object
        UUID testUuid = UUID.randomUUID();
        ComponentInstance instance = mockComponentInstance(testUuid, "DefaultName", null);
        FactoryObjectProxy testObjProxy = mock(FactoryObjectProxy.class);

        // mock another object
        UUID testUuid2 = UUID.randomUUID();
        ComponentInstance instance2 = mockComponentInstance(testUuid2, "DuplicateName", null);
        FactoryObjectProxy testObjProxy2 = mock(FactoryObjectProxy.class);

        // mock factory return (supports getting the PID)
        when(m_FactoryDescriptor.create()).thenReturn(testObjProxy, testObjProxy2);
        when(m_ServiceProxy.createFactoryObjectInternal(m_FactoryDescriptor)).thenReturn(instance, instance2);

        // replay
        m_SUT.createOrRestoreObject(m_FactoryDescriptor, testUuid);
        m_SUT.createOrRestoreObject(m_FactoryDescriptor, testUuid2);

        try
        {
            m_SUT.setName((FactoryObjectInternal)instance.getInstance(), null);
            fail("Expecting IllegalArgumentException, name should not be set to null.");
        }
        catch (final IllegalArgumentException e)
        {
            // name cannot be null
        }

        try
        {
            m_SUT.setName((FactoryObjectInternal)instance.getInstance(), "   ");
            fail("Expecting IllegalArgumentException, name cannot be blank.");
        }
        catch (final IllegalArgumentException e)
        {
            // name cannot be blank
        }

        //factory object manager behavior
        when(m_FactoryObjectDataManager.getPersistentUuid("DuplicateName")).thenReturn(testUuid2);

        try
        {
            m_SUT.setName((FactoryObjectInternal)instance.getInstance(), "DuplicateName");
            fail("Expecting IllegalArgumentException, duplicate name found.");
        }
        catch (final IllegalArgumentException e)
        {
            // name cannot be duplicate
        }

        // test that an IllegalArgumentException is not thrown if the name already exists but
        // but uniquely belongs to the object being named.
        m_SUT.setName((FactoryObjectInternal)instance.getInstance(), "DefaultName");
        verify((FactoryObjectInternal)instance.getInstance()).internalSetName("DefaultName");
        // name will not be persisted because it is already associated with that uuid in the data store

        // test that a valid, non-duplicate name is set and persisted.
        // this updates a pre-existing entry in the data store
        m_SUT.setName((FactoryObjectInternal)instance.getInstance(), "NewName");
    }
/**
     *  Tests that the name of an object is set and persisted if it is a valid name.
     *  A name that is blank, null, or a duplicate is considered invalid.
     */
Tests that the name of an object is set and persisted if it is a valid name.
A name that is blank, null, or a duplicate is considered invalid.
Tests that the name of an object is set and persisted if it is a valid name . A name that is blank null or a duplicate is considered invalid .
@Test
    public void testPersistObjectData() throws IllegalArgumentException, FactoryException,
        FactoryObjectInformationException
    {
        UUID testUuid = UUID.randomUUID();
        ComponentInstance instance = mockComponentInstance(testUuid, "DefaultName", null);
        FactoryObjectProxy testObjProxy = mock(FactoryObjectProxy.class);
        UUID testUuid2 = UUID.randomUUID();
        ComponentInstance instance2 = mockComponentInstance(testUuid2, "DuplicateName", null);
        FactoryObjectProxy testObjProxy2 = mock(FactoryObjectProxy.class);
        when(m_FactoryDescriptor.create()).thenReturn(testObjProxy, testObjProxy2);
        when(m_ServiceProxy.createFactoryObjectInternal(m_FactoryDescriptor)).thenReturn(instance, instance2);
        m_SUT.createOrRestoreObject(m_FactoryDescriptor, testUuid);
        m_SUT.createOrRestoreObject(m_FactoryDescriptor, testUuid2);
        try
        {
            m_SUT.setName((FactoryObjectInternal)instance.getInstance(), null);
            fail("Expecting IllegalArgumentException, name should not be set to null.");
        }
        catch (final IllegalArgumentException e)
        {
        }
        try
        {
            m_SUT.setName((FactoryObjectInternal)instance.getInstance(), "   ");
            fail("Expecting IllegalArgumentException, name cannot be blank.");
        }
        catch (final IllegalArgumentException e)
        {
        }
        when(m_FactoryObjectDataManager.getPersistentUuid("DuplicateName")).thenReturn(testUuid2);
        try
        {
            m_SUT.setName((FactoryObjectInternal)instance.getInstance(), "DuplicateName");
            fail("Expecting IllegalArgumentException, duplicate name found.");
        }
        catch (final IllegalArgumentException e)
        {
        }
        m_SUT.setName((FactoryObjectInternal)instance.getInstance(), "DefaultName");
        verify((FactoryObjectInternal)instance.getInstance()).internalSetName("DefaultName");
        m_SUT.setName((FactoryObjectInternal)instance.getInstance(), "NewName");
    }
@ Test public void testPersistObjectData ( ) throws IllegalArgumentException , FactoryException , FactoryObjectInformationException { UUID testUuid = UUID . randomUUID ( ) ; ComponentInstance instance = mockComponentInstance ( testUuid , "DefaultName" , null ) ; FactoryObjectProxy testObjProxy = mock ( FactoryObjectProxy . class ) ; UUID testUuid2 = UUID . randomUUID ( ) ; ComponentInstance instance2 = mockComponentInstance ( testUuid2 , "DuplicateName" , null ) ; FactoryObjectProxy testObjProxy2 = mock ( FactoryObjectProxy . class ) ; when ( m_FactoryDescriptor . create ( ) ) . thenReturn ( testObjProxy , testObjProxy2 ) ; when ( m_ServiceProxy . createFactoryObjectInternal ( m_FactoryDescriptor ) ) . thenReturn ( instance , instance2 ) ; m_SUT . createOrRestoreObject ( m_FactoryDescriptor , testUuid ) ; m_SUT . createOrRestoreObject ( m_FactoryDescriptor , testUuid2 ) ; try { m_SUT . setName ( ( FactoryObjectInternal ) instance . getInstance ( ) , null ) ; fail ( "Expecting IllegalArgumentException, name should not be set to null." ) ; } catch ( final IllegalArgumentException e ) { } try { m_SUT . setName ( ( FactoryObjectInternal ) instance . getInstance ( ) , "   " ) ; fail ( "Expecting IllegalArgumentException, name cannot be blank." ) ; } catch ( final IllegalArgumentException e ) { } when ( m_FactoryObjectDataManager . getPersistentUuid ( "DuplicateName" ) ) . thenReturn ( testUuid2 ) ; try { m_SUT . setName ( ( FactoryObjectInternal ) instance . getInstance ( ) , "DuplicateName" ) ; fail ( "Expecting IllegalArgumentException, duplicate name found." ) ; } catch ( final IllegalArgumentException e ) { } m_SUT . setName ( ( FactoryObjectInternal ) instance . getInstance ( ) , "DefaultName" ) ; verify ( ( FactoryObjectInternal ) instance . getInstance ( ) ) . internalSetName ( "DefaultName" ) ; m_SUT . setName ( ( FactoryObjectInternal ) instance . getInstance ( ) , "NewName" ) ; }
Tests that the name of an object is set and persisted if it is a valid name.
Tests that the name of an object is set and persisted if it is a valid name .
// mock an object // mock another object // mock factory return (supports getting the PID) // replay // name cannot be null // name cannot be blank //factory object manager behavior // name cannot be duplicate // test that an IllegalArgumentException is not thrown if the name already exists but // but uniquely belongs to the object being named. // name will not be persisted because it is already associated with that uuid in the data store // test that a valid, non-duplicate name is set and persisted. // this updates a pre-existing entry in the data store