@Test public void testNoParentForApplicationContext() { JpaMedia mockJdkMedia = mock(JpaMedia.class); when(mockJdkMedia.getType()).thenReturn(MediaType.JDK); List<JpaMedia> mediaList = Collections.singletonList(mockJdkMedia); when(Config.mediaServiceMock.findAll()).thenReturn(mediaList); ContextRefreshedEvent mockStartupEvent = mock(ContextRefreshedEvent.class); ApplicationContext mockApplicationContext = mock(ApplicationContext.class); when(mockStartupEvent.getApplicationContext()).thenReturn(mockApplicationContext); applicationContextListener.handleEvent(mockStartupEvent); verify(Config.jvmServiceMock, never()).updateJvm(any(UpdateJvmRequest.class), eq(true)); verify(Config.mediaServiceMock, never()).create(anyMap(), anyMap()); }
@EventListener public void handleEvent(ApplicationEvent event) { if (!(event instanceof ContextRefreshedEvent)) { LOGGER.debug("Expecting ContextRefreshedEvent. Skipping."); return; } LOGGER.info("Received ContextRefreshedEvent {}", event); ContextRefreshedEvent crEvent = (ContextRefreshedEvent) event; final ApplicationContext applicationContext = crEvent.getApplicationContext(); if (null == applicationContext) { LOGGER.debug("Expecting non-null ApplicationContext. Skipping."); return; } if (null == applicationContext.getParent()) { LOGGER.debug("Expecting non-null ApplicationContext parent. Skipping."); return; } processBootstrapConfiguration(); }
ApplicationContextListener { @EventListener public void handleEvent(ApplicationEvent event) { if (!(event instanceof ContextRefreshedEvent)) { LOGGER.debug("Expecting ContextRefreshedEvent. Skipping."); return; } LOGGER.info("Received ContextRefreshedEvent {}", event); ContextRefreshedEvent crEvent = (ContextRefreshedEvent) event; final ApplicationContext applicationContext = crEvent.getApplicationContext(); if (null == applicationContext) { LOGGER.debug("Expecting non-null ApplicationContext. Skipping."); return; } if (null == applicationContext.getParent()) { LOGGER.debug("Expecting non-null ApplicationContext parent. Skipping."); return; } processBootstrapConfiguration(); } }
ApplicationContextListener { @EventListener public void handleEvent(ApplicationEvent event) { if (!(event instanceof ContextRefreshedEvent)) { LOGGER.debug("Expecting ContextRefreshedEvent. Skipping."); return; } LOGGER.info("Received ContextRefreshedEvent {}", event); ContextRefreshedEvent crEvent = (ContextRefreshedEvent) event; final ApplicationContext applicationContext = crEvent.getApplicationContext(); if (null == applicationContext) { LOGGER.debug("Expecting non-null ApplicationContext. Skipping."); return; } if (null == applicationContext.getParent()) { LOGGER.debug("Expecting non-null ApplicationContext parent. Skipping."); return; } processBootstrapConfiguration(); }  }
ApplicationContextListener { @EventListener public void handleEvent(ApplicationEvent event) { if (!(event instanceof ContextRefreshedEvent)) { LOGGER.debug("Expecting ContextRefreshedEvent. Skipping."); return; } LOGGER.info("Received ContextRefreshedEvent {}", event); ContextRefreshedEvent crEvent = (ContextRefreshedEvent) event; final ApplicationContext applicationContext = crEvent.getApplicationContext(); if (null == applicationContext) { LOGGER.debug("Expecting non-null ApplicationContext. Skipping."); return; } if (null == applicationContext.getParent()) { LOGGER.debug("Expecting non-null ApplicationContext parent. Skipping."); return; } processBootstrapConfiguration(); }  @EventListener void handleEvent(ApplicationEvent event); }
ApplicationContextListener { @EventListener public void handleEvent(ApplicationEvent event) { if (!(event instanceof ContextRefreshedEvent)) { LOGGER.debug("Expecting ContextRefreshedEvent. Skipping."); return; } LOGGER.info("Received ContextRefreshedEvent {}", event); ContextRefreshedEvent crEvent = (ContextRefreshedEvent) event; final ApplicationContext applicationContext = crEvent.getApplicationContext(); if (null == applicationContext) { LOGGER.debug("Expecting non-null ApplicationContext. Skipping."); return; } if (null == applicationContext.getParent()) { LOGGER.debug("Expecting non-null ApplicationContext parent. Skipping."); return; } processBootstrapConfiguration(); }  @EventListener void handleEvent(ApplicationEvent event);  }