mil.dod.th.ose.core/test/mil/dod/th/ose/core/impl/persistence/TestObservationStoreImpl.java
@Test
    public final void testPersistValidatedObservation() throws IllegalArgumentException, PersistenceFailedException, 
        ValidationFailedException
    {
        m_Observation.setAssetUuid(UUID.randomUUID());
        
        Throwable e = null;
        try {m_SUT.persist(null); }
        catch (Throwable ex) { e = ex; }
        assertThat(e, instanceOf(IllegalArgumentException.class));
        
        m_SUT.persist(m_Observation);

        //verify
        verify(m_ObsValidator).validate(m_Observation);
        verify(m_PersistenceManager).makePersistent(m_Observation);
        ArgumentCaptor<Event> event = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, times(2)).postEvent(event.capture());
        verify(m_WakeLock, times(2)).activate();
        verify(m_WakeLock, times(2)).cancel();
 
        //check first event does not observation
        assertThat(event.getAllValues().get(0).getTopic(), is(ObservationStore.TOPIC_OBSERVATION_PERSISTED));
        assertThat((String)event.getAllValues().get(0).getProperty(FactoryDescriptor.EVENT_PROP_OBJ_UUID), 
                is(m_Observation.getAssetUuid().toString()));
        assertThat((UUID)event.getAllValues().get(0).getProperty(ObservationStore.EVENT_PROP_OBSERVATION_UUID), 
                is(m_Observation.getUuid()));
        assertThat(event.getAllValues().get(0).getProperty(ObservationStore.EVENT_PROP_OBSERVATION), is(nullValue()));

        //second event should have the observation
        assertThat(event.getAllValues().get(1).getTopic(), is(ObservationStore.TOPIC_OBSERVATION_PERSISTED_WITH_OBS));
        assertThat((String)event.getAllValues().get(0).getProperty(FactoryDescriptor.EVENT_PROP_OBJ_UUID), 
                is(m_Observation.getAssetUuid().toString()));
        assertThat((UUID)event.getAllValues().get(1).getProperty(ObservationStore.EVENT_PROP_OBSERVATION_UUID), 
                is(m_Observation.getUuid()));
        assertThat((Observation)event.getAllValues().get(1).getProperty(ObservationStore.EVENT_PROP_OBSERVATION), 
                is(m_Observation));
    }
/**
     * Test that observations can be persisted.
     * Verify events, one without an observation and the other with the actual observation as a property.
     */
Test that observations can be persisted.
Verify events, one without an observation and the other with the actual observation as a property.
Test that observations can be persisted . Verify events one without an observation and the other with the actual observation as a property .
@Test
    public final void testPersistValidatedObservation() throws IllegalArgumentException, PersistenceFailedException, 
        ValidationFailedException
    {
        m_Observation.setAssetUuid(UUID.randomUUID());
        Throwable e = null;
        try {m_SUT.persist(null); }
        catch (Throwable ex) { e = ex; }
        assertThat(e, instanceOf(IllegalArgumentException.class));
        m_SUT.persist(m_Observation);
        verify(m_ObsValidator).validate(m_Observation);
        verify(m_PersistenceManager).makePersistent(m_Observation);
        ArgumentCaptor<Event> event = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, times(2)).postEvent(event.capture());
        verify(m_WakeLock, times(2)).activate();
        verify(m_WakeLock, times(2)).cancel();
        assertThat(event.getAllValues().get(0).getTopic(), is(ObservationStore.TOPIC_OBSERVATION_PERSISTED));
        assertThat((String)event.getAllValues().get(0).getProperty(FactoryDescriptor.EVENT_PROP_OBJ_UUID), 
                is(m_Observation.getAssetUuid().toString()));
        assertThat((UUID)event.getAllValues().get(0).getProperty(ObservationStore.EVENT_PROP_OBSERVATION_UUID), 
                is(m_Observation.getUuid()));
        assertThat(event.getAllValues().get(0).getProperty(ObservationStore.EVENT_PROP_OBSERVATION), is(nullValue()));
        assertThat(event.getAllValues().get(1).getTopic(), is(ObservationStore.TOPIC_OBSERVATION_PERSISTED_WITH_OBS));
        assertThat((String)event.getAllValues().get(0).getProperty(FactoryDescriptor.EVENT_PROP_OBJ_UUID), 
                is(m_Observation.getAssetUuid().toString()));
        assertThat((UUID)event.getAllValues().get(1).getProperty(ObservationStore.EVENT_PROP_OBSERVATION_UUID), 
                is(m_Observation.getUuid()));
        assertThat((Observation)event.getAllValues().get(1).getProperty(ObservationStore.EVENT_PROP_OBSERVATION), 
                is(m_Observation));
    }
@ Test public final void testPersistValidatedObservation ( ) throws IllegalArgumentException , PersistenceFailedException , ValidationFailedException { m_Observation . setAssetUuid ( UUID . randomUUID ( ) ) ; Throwable e = null ; try { m_SUT . persist ( null ) ; } catch ( Throwable ex ) { e = ex ; } assertThat ( e , instanceOf ( IllegalArgumentException . class ) ) ; m_SUT . persist ( m_Observation ) ; verify ( m_ObsValidator ) . validate ( m_Observation ) ; verify ( m_PersistenceManager ) . makePersistent ( m_Observation ) ; ArgumentCaptor < Event > event = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin , times ( 2 ) ) . postEvent ( event . capture ( ) ) ; verify ( m_WakeLock , times ( 2 ) ) . activate ( ) ; verify ( m_WakeLock , times ( 2 ) ) . cancel ( ) ; assertThat ( event . getAllValues ( ) . get ( 0 ) . getTopic ( ) , is ( ObservationStore . TOPIC_OBSERVATION_PERSISTED ) ) ; assertThat ( ( String ) event . getAllValues ( ) . get ( 0 ) . getProperty ( FactoryDescriptor . EVENT_PROP_OBJ_UUID ) , is ( m_Observation . getAssetUuid ( ) . toString ( ) ) ) ; assertThat ( ( UUID ) event . getAllValues ( ) . get ( 0 ) . getProperty ( ObservationStore . EVENT_PROP_OBSERVATION_UUID ) , is ( m_Observation . getUuid ( ) ) ) ; assertThat ( event . getAllValues ( ) . get ( 0 ) . getProperty ( ObservationStore . EVENT_PROP_OBSERVATION ) , is ( nullValue ( ) ) ) ; assertThat ( event . getAllValues ( ) . get ( 1 ) . getTopic ( ) , is ( ObservationStore . TOPIC_OBSERVATION_PERSISTED_WITH_OBS ) ) ; assertThat ( ( String ) event . getAllValues ( ) . get ( 0 ) . getProperty ( FactoryDescriptor . EVENT_PROP_OBJ_UUID ) , is ( m_Observation . getAssetUuid ( ) . toString ( ) ) ) ; assertThat ( ( UUID ) event . getAllValues ( ) . get ( 1 ) . getProperty ( ObservationStore . EVENT_PROP_OBSERVATION_UUID ) , is ( m_Observation . getUuid ( ) ) ) ; assertThat ( ( Observation ) event . getAllValues ( ) . get ( 1 ) . getProperty ( ObservationStore . EVENT_PROP_OBSERVATION ) , is ( m_Observation ) ) ; }
Test that observations can be persisted.
Test that observations can be persisted .
//verify //check first event does not observation //second event should have the observation