Exemplo n.º 1
0
  @Test
  public void testGuiceInterceptionModule() {
    Injector injector = Guice.createInjector(new InterceptionModule());
    assertThat(injector.getInstance(LogPerformancesInterceptor.class))
        .isNotNull()
        .isInstanceOf(LogPerformancesInterceptor.class);

    assertThat(injector.getProvider(LogPerformancesInterceptor.class)).isNotNull();
  }
 @Override
 public Object createServiceInstance(Class<? extends RequestContext> requestContext) {
   Class<? extends ServiceLocator> serviceLocatorClass;
   if ((serviceLocatorClass = getTop().resolveServiceLocator(requestContext)) != null) {
     return injector
         .getProvider(serviceLocatorClass)
         .get()
         .getInstance(requestContext.getAnnotation(Service.class).value());
   } else {
     return null;
   }
 }
 /**
  * Constructor de la clase que genera la instancia del Scheduler de Quartz.
  *
  * @param injector
  */
 @Inject
 public SchedulerService(Injector injector) {
   LOG.info("Iniciando servicio de tareas programadas");
   try {
     Properties properties = new Properties();
     properties.load(getClass().getResourceAsStream("/org/quartz/quartz.properties"));
     scheduler = new StdSchedulerFactory(properties).getScheduler();
     scheduler.getContext().put(Injector.class.getName(), injector);
     entityManagerProvider = injector.getProvider(EntityManager.class);
     classLoader = Thread.currentThread().getContextClassLoader();
   } catch (Exception ex) {
     throw new RuntimeException("Error al arrancar el servicio de tareas programadas", ex);
   }
 }
Exemplo n.º 4
0
  @Before
  public void setUp() throws Exception {
    // Injector injector = Guice.createInjector(##new PastryTestModule(), new
    // DatamodelImplModule());
    Injector injector = Guice.createInjector(new PastryTestModule());
    datamodelFactory = injector.getInstance(DatamodelFactory.class);

    Provider<PastryResolutionService> provider =
        injector.getProvider(PastryResolutionService.class);
    resolutionServices = new ArrayList<PastryResolutionService>();
    for (int i = 0; i < NODE_NUMBER; i++) {
      resolutionServices.add(provider.get());
    }
    getterCommands = new ArrayList<NodeGetCommand>();
  }
Exemplo n.º 5
0
 public void run() {
   if (isDatabaseInitialized()) {
     LOG.warn("Database already initialized. Aborting");
   }
   ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
   EntityManager entityManager = injector.getProvider(EntityManager.class).get();
   entityManager.getTransaction().begin();
   try {
     injector
         .getInstance(PredefinedPortfolioFeeder.class)
         .feed(classLoader.getResourceAsStream("csv/predefined-portfolio.csv"));
     entityManager.getTransaction().commit();
   } catch (Exception ex) {
     LOG.error("Bootstrap error", ex);
     entityManager.getTransaction().rollback();
   }
   injector.getInstance(DemoUserCreator.class).run();
   LOG.debug("Bootstrap completed");
 }
Exemplo n.º 6
0
  public void testScopedProviderMethodThrowsException() {
    Injector injector =
        Guice.createInjector(
            new AbstractModule() {
              @Override
              protected void configure() {}

              @Provides
              @Singleton
              int provideInt() {
                throw new RuntimeException("boom");
              }
            });
    Provider<Integer> intProvider = injector.getProvider(Integer.class);
    try {
      intProvider.get();
      fail();
    } catch (ProvisionException pe) {
      // by default assertContains asserts that the last item doesn't repeat... which is the main
      // thing we are testing for
      assertContains(pe.getMessage(), "java.lang.RuntimeException: boom", "provideInt");
    }
  }
 /**
  * Uses Guice to create the instance of the target locator, so the locator implementation could be
  * injected.
  */
 @Override
 public <T extends Locator<?, ?>> T createLocator(Class<T> clazz) {
   return injector.getProvider(clazz).get();
 }
Exemplo n.º 8
0
  @Override
  public boolean initialize(Properties properties) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("==> AtlasTagSource.initialize()");
    }

    Properties atlasProperties = new Properties();

    boolean ret = AtlasResourceMapperUtil.initializeAtlasResourceMappers(properties);

    if (ret) {

      InputStream inputStream =
          getClass().getClassLoader().getResourceAsStream(TAGSYNC_ATLAS_PROPERTIES_FILE_NAME);

      if (inputStream != null) {
        try {
          atlasProperties.load(inputStream);
        } catch (Exception exception) {
          ret = false;
          LOG.error(
              "Cannot load Atlas application properties file, file-name:"
                  + TAGSYNC_ATLAS_PROPERTIES_FILE_NAME,
              exception);
        } finally {
          try {
            inputStream.close();
          } catch (IOException ioException) {
            LOG.error(
                "Cannot close Atlas application properties file, file-name:\" + TAGSYNC_ATLAS_PROPERTIES_FILE_NAME",
                ioException);
          }
        }
      } else {
        ret = false;
        LOG.error("Cannot find Atlas application properties file");
      }
    }

    if (ret) {
      if (StringUtils.isBlank(atlasProperties.getProperty(TAGSYNC_ATLAS_KAFKA_ENDPOINTS))) {
        ret = false;
        LOG.error("Value of property '" + TAGSYNC_ATLAS_KAFKA_ENDPOINTS + "' is not specified!");
      }
      if (StringUtils.isBlank(atlasProperties.getProperty(TAGSYNC_ATLAS_ZOOKEEPER_ENDPOINT))) {
        ret = false;
        LOG.error("Value of property '" + TAGSYNC_ATLAS_ZOOKEEPER_ENDPOINT + "' is not specified!");
      }
      if (StringUtils.isBlank(atlasProperties.getProperty(TAGSYNC_ATLAS_CONSUMER_GROUP))) {
        ret = false;
        LOG.error("Value of property '" + TAGSYNC_ATLAS_CONSUMER_GROUP + "' is not specified!");
      }
    }

    if (ret) {
      NotificationModule notificationModule = new NotificationModule();

      Injector injector = Guice.createInjector(notificationModule);

      Provider<NotificationInterface> consumerProvider =
          injector.getProvider(NotificationInterface.class);
      NotificationInterface notification = consumerProvider.get();
      List<NotificationConsumer<EntityNotification>> iterators =
          notification.createConsumers(NotificationInterface.NotificationType.ENTITIES, 1);

      consumerTask = new ConsumerRunnable(iterators.get(0));
    }

    if (LOG.isDebugEnabled()) {
      LOG.debug("<== AtlasTagSource.initialize(), result=" + ret);
    }
    return ret;
  }