### Question:
WeatherMessageFactory extends AbstractMessageFactory { @Override protected Message.SOURCE getSource() { return Message.SOURCE.WEATHER; }  @Override List<Message2Send> getMessage(final MessageProcessUnit inUnit);  }### Answer:
@Test public void getSourceMessageNoLastTimeTest() { final Source source = new SourceMock(8205, "Nmeteo.FRANCE.Orléans.weather", 3, System.currentTimeMillis()); final Subscription theSubscription = new SubscriptionMock(1, Factories.APPLICATION.findByName("net.violet.weather"), getKowalskyObject()); final Map<String, Object> settings = new HashMap<String, Object>(); settings.put(WeatherHandler.LANGUAGE, "fr-FR"); settings.put(WeatherHandler.SOURCE, source.getSource_path()); theSubscription.setSettings(settings); final SubscriptionData theSubscriptionData = SubscriptionData.getData(theSubscription); final SubscriptionSchedulingData theScheduling = SubscriptionSchedulingData.create(theSubscriptionData, SchedulingType.SCHEDULING_TYPE.Ambiant); final WeatherMessageFactory factory = (WeatherMessageFactory) AbstractMessageFactory.getFactoryByApplication(theSubscription.getApplication()); final long theLastTime = System.currentTimeMillis(); final MessageDraft theMessage = factory.getSourceMessage(theScheduling, theLastTime); Assert.assertNotNull(theMessage); Assert.assertTrue(theMessage.isSourceModeUpdate()); Assert.assertEquals(new Integer((int) source.getSource_val()), theMessage.getSources().get(Integer.toString(factory.getSource().getId()))); Assert.assertEquals(Constantes.QUEUE_TTL_SOURCES, theMessage.getTTLInSecond()); final SubscriptionSchedulingSettingsData theLastTimeSetting = SubscriptionSchedulingSettingsData.findBySubscriptionSchedulingAndKey(theScheduling, AmbiantHandler.LAST_TIME); Assert.assertNotNull(theLastTimeSetting); Assert.assertEquals(theLastTime, Long.parseLong(theLastTimeSetting.getValue())); source.delete(); }
@Test public void getSourceMessageWithLastTimeUTest() { final long sourceUpdateTime = System.currentTimeMillis() / 1000; final Source source = new SourceMock(8205, "Nmeteo.FRANCE.Orléans.weather", 3, sourceUpdateTime + 60); final long theLastTime = sourceUpdateTime * 1000; final Subscription theSubscription = new SubscriptionMock(1, Factories.APPLICATION.findByName("net.violet.weather"), getKowalskyObject()); final Map<String, Object> settings = new HashMap<String, Object>(); settings.put(WeatherHandler.LANGUAGE, "fr-FR"); settings.put(WeatherHandler.SOURCE, source.getSource_path()); theSubscription.setSettings(settings); final SubscriptionData theSubscriptionData = SubscriptionData.getData(theSubscription); final SubscriptionSchedulingData theScheduling = SubscriptionSchedulingData.create(theSubscriptionData, SchedulingType.SCHEDULING_TYPE.Ambiant); theScheduling.createSetting(AmbiantHandler.LAST_TIME, Long.toString(theLastTime)); final WeatherMessageFactory factory = (WeatherMessageFactory) AbstractMessageFactory.getFactoryByApplication(theSubscription.getApplication()); final MessageDraft theMessage = factory.getSourceMessage(theScheduling, theLastTime); Assert.assertNotNull(theMessage); Assert.assertTrue(theMessage.isSourceModeUpdate()); Assert.assertEquals(new Integer((int) source.getSource_val()), theMessage.getSources().get(Integer.toString(factory.getSource().getId()))); Assert.assertEquals(Constantes.QUEUE_TTL_SOURCES, theMessage.getTTLInSecond()); final SubscriptionSchedulingSettingsData theLastTimeSetting = SubscriptionSchedulingSettingsData.findBySubscriptionSchedulingAndKey(theScheduling, AmbiantHandler.LAST_TIME); Assert.assertNotNull(theLastTimeSetting); Assert.assertEquals(theLastTime, Long.parseLong(theLastTimeSetting.getValue())); source.delete(); }