GrapesServer extends Service<GrapesServerConfig> { @Override public void run(final GrapesServerConfig config, final Environment env) throws DBException, UnknownHostException { PromoConfigValidator v = new PromoConfigValidator(); v.testValidity(config.getPromoValidationCfg()); PromoConfigPrinter.display(config.getPromoValidationCfg(), str -> { if (LOG.isInfoEnabled()) { LOG.info(str); } }); final RepositoryHandler repoHandler = getRepositoryHandler(config); Messages.init(config.getMsgBundle()); env.scanPackagesForResourcesAndProviders(CsvReportWriter.class); final GrapesAuthenticator grapesAuthenticator = new GrapesAuthenticator(repoHandler); final BasicAuthProvider authProvider = new BasicAuthProvider<>(grapesAuthenticator, "Grapes Authenticator Provider"); env.addProvider(authProvider); env.addTask(new AddUserTask(repoHandler)); env.addTask(new AddRoleTask(repoHandler)); env.addTask(new RemoveRoleTask(repoHandler)); env.addTask(new MaintenanceModeTask(config)); env.addTask(new KillTask()); env.addTask(new MigrationTask(config.getDataBaseConfig())); env.addTask(new RefreshCommercialDeliveriesTask(repoHandler)); env.addTask(new SendEmailTestTask(config.getGrapesEmailConfig())); env.addTask(new ShowValidationsTask()); env.addTask(new ChangeValidationsTask()); env.addHealthCheck(new DataBaseCheck(config.getDataBaseConfig())); env.addHealthCheck(new DataModelVersionCheck(config.getDataBaseConfig())); env.addResource(new OrganizationResource(repoHandler, config)); env.addResource(new ProductResource(repoHandler, config)); env.addResource(new ModuleResource(repoHandler, config)); env.addResource(new ArtifactResource(repoHandler, config)); env.addResource(new LicenseResource(repoHandler, config)); env.addResource(new Sequoia(repoHandler, config)); env.addResource(new WebAppResource(repoHandler, config)); env.addResource(new RootResource(repoHandler, config)); env.addResource(new ReportResource(repoHandler, config)); env.addResource(new SearchResource(repoHandler, config)); env.addResource(new WebSearchResource(repoHandler, config)); } protected  GrapesServer(); static void main(final String[] args); @Override void initialize(final Bootstrap<GrapesServerConfig> bootstrap); @Override void run(final GrapesServerConfig config, final Environment env); RepositoryHandler getRepositoryHandler(final GrapesServerConfig config);  }
@Test public void checkInitialization() throws UnknownHostException { String portProperty = System.getProperty(PROPERTY_PORT, null); if(portProperty == null || !isInteger(portProperty)){ Logger.getLogger(GrapesServerTest.class.getSimpleName()).info("No variable HTTP_PORT define, server mock will be run on the default port value: " + DEFAULT_PORT); portProperty = DEFAULT_PORT; } else{ Logger.getLogger(GrapesServerTest.class.getSimpleName()).info("Uses port " + portProperty + " as grapes http port for tests."); } String adminPortProperty = System.getProperty(PROPERTY_ADMIN_PORT, null); if(adminPortProperty == null || !isInteger(adminPortProperty)){ Logger.getLogger(GrapesServerTest.class.getSimpleName()).info("No variable HTTP_ADMIN_PORT define, server mock will be run on the default port value: " + DEFAULT_ADMIN_PORT); adminPortProperty = DEFAULT_ADMIN_PORT; } else{ Logger.getLogger(GrapesServerTest.class.getSimpleName()).info("Uses port " + adminPortProperty + " as admin port for grapes tests."); } final String templatePath = getClass().getResource("server-conf-template.yml").getPath(); final String confPath = overrideConfiguration(templatePath, portProperty, adminPortProperty); try { File templates = new File(templatePath).getParentFile(); FileUtils.copyFileToDirectory(new File(templates, "all-messages.txt"), new File("target")); } catch(IOException e) { e.printStackTrace(); } final GrapesServerTest grapesServer = new GrapesServerTest(); final String[] args = {"server",confPath}; Throwable exception = null; try { grapesServer.run(args); } catch (Exception e) { exception = e; } assertNull(exception); }