OptionsLoader { public static MeshOptions createOrloadOptions(String... args) { return createOrloadOptions(null, args); } private  OptionsLoader(); static MeshOptions createOrloadOptions(String... args); static MeshOptions createOrloadOptions(MeshOptions defaultOption, String... args); static MeshOptions generateDefaultConfig(MeshOptions defaultOption); static ObjectMapper getYAMLMapper();  }
@Test public void testApplyEnvs() throws Exception { environmentVariables.set(MeshOptions.MESH_DEFAULT_LANG_ENV, "ru"); environmentVariables.set(MeshOptions.MESH_UPDATECHECK_ENV, "false"); environmentVariables.set(HttpServerConfig.MESH_HTTP_PORT_ENV, "8100"); environmentVariables.set(ElasticSearchOptions.MESH_ELASTICSEARCH_URL_ENV, "https: environmentVariables.set(MeshOptions.MESH_CLUSTER_INIT_ENV, "true"); environmentVariables.set(HttpServerConfig.MESH_HTTP_CORS_ORIGIN_PATTERN_ENV, "*"); environmentVariables.set(HttpServerConfig.MESH_HTTP_CORS_ENABLE_ENV, "true"); environmentVariables.set(VertxOptions.MESH_VERTX_EVENT_POOL_SIZE_ENV, "41"); environmentVariables.set(VertxOptions.MESH_VERTX_WORKER_POOL_SIZE_ENV, "42"); environmentVariables.set(MeshOptions.MESH_LOCK_PATH_ENV, "dummy/1234"); environmentVariables.set(MeshUploadOptions.MESH_BINARY_DIR_ENV, "/uploads"); environmentVariables.set(MonitoringConfig.MESH_MONITORING_HTTP_HOST_ENV, "0.0.0.0"); environmentVariables.set(ContentConfig.MESH_CONTENT_AUTO_PURGE_ENV, "true"); environmentVariables.set(ElasticSearchOptions.MESH_ELASTICSEARCH_MAPPING_MODE_ENV, "STRICT"); environmentVariables.set(ImageManipulatorOptions.MESH_IMAGE_CACHE_DIRECTORY_ENV, "data" + File.separator +"binaryImageCache"); MeshOptions options = OptionsLoader.createOrloadOptions(); assertEquals(8100, options.getHttpServerOptions().getPort()); assertEquals("ru", options.getDefaultLanguage()); assertFalse(options.isUpdateCheckEnabled()); assertEquals("https: assertTrue(options.isInitClusterMode()); assertTrue(options.getHttpServerOptions().getEnableCors()); assertEquals(41, options.getVertxOptions().getEventPoolSize()); assertEquals(42, options.getVertxOptions().getWorkerPoolSize()); assertEquals("*", options.getHttpServerOptions().getCorsAllowedOriginPattern()); assertEquals("dummy/1234", options.getLockPath()); assertEquals("/uploads", options.getUploadOptions().getDirectory()); assertEquals("0.0.0.0", options.getMonitoringOptions().getHost()); assertTrue(options.getContentOptions().isAutoPurge()); assertEquals(MappingMode.STRICT, options.getSearchOptions().getMappingMode()); assertEquals("data" + File.separator + "binaryImageCache", options.getImageOptions().getImageCacheDirectory()); }
@Test public void testApplyEnvsNull() throws Exception { environmentVariables.set(ElasticSearchOptions.MESH_ELASTICSEARCH_URL_ENV, "null"); MeshOptions options = OptionsLoader.createOrloadOptions(); assertNull(options.getSearchOptions().getUrl()); }
@Test public void testTrustedCertListOneItemEnv() { environmentVariables.set(HttpServerConfig.MESH_HTTP_SSL_TRUSTED_CERTS_ENV, "abc"); MeshOptions options = OptionsLoader.createOrloadOptions(); List<String> list = options.getHttpServerOptions().getTrustedCertPaths(); assertEquals("The path list should contain oneentries", 1, list.size()); assertEquals("abc", list.get(0)); }
@Test public void testTrustedCertListEnv() { environmentVariables.set(HttpServerConfig.MESH_HTTP_SSL_TRUSTED_CERTS_ENV, "abc,efg"); MeshOptions options = OptionsLoader.createOrloadOptions(); List<String> list = options.getHttpServerOptions().getTrustedCertPaths(); assertEquals("The path list should contain two entries", 2, list.size()); assertEquals("abc", list.get(0)); assertEquals("efg", list.get(1)); }
@Test public void testEmptyTrustedCertListEnv() { environmentVariables.set(HttpServerConfig.MESH_HTTP_SSL_TRUSTED_CERTS_ENV, ""); MeshOptions options = OptionsLoader.createOrloadOptions(); List<String> list = options.getHttpServerOptions().getTrustedCertPaths(); assertEquals("The path list should contain two entries", 0, list.size()); }
@Test public void testApplyArgs() { MeshOptions options = OptionsLoader.createOrloadOptions("-nodeName", "theNodeName", "-clusterName", "theClusterName"); assertEquals("The node name should have been specified.", "theNodeName", options.getNodeName()); assertEquals("The cluster name should have been specified.", "theClusterName", options.getClusterOptions().getClusterName()); assertTrue("We specified the clusterName thus clustering should automatically be enabled.", options.getClusterOptions().isEnabled()); }