List of usage examples for java.util Collections emptyMap
@SuppressWarnings("unchecked") public static final <K, V> Map<K, V> emptyMap()
From source file:org.mayocat.configuration.internal.DefaultConfigurationService.java
public Map<String, Serializable> getSettingsAsJson(final Tenant tenant) { if (tenant == null) { return Collections.emptyMap(); }/*from w w w .j a v a 2 s . c om*/ try { return configurations.get(tenant.getId(), new Callable<Map<String, Serializable>>() { @Override public Map<String, Serializable> call() { synchronized (lock) { logger.debug("loading cache configuration value for tenant {}", tenant.getSlug()); Map<String, Serializable> tenantConfiguration = tenant.getConfiguration(); Map<String, Serializable> platformConfiguration = getExposedPlatformSettingsAsJson(); ConfigurationJsonMerger merger = new ConfigurationJsonMerger(platformConfiguration, tenantConfiguration); return merger.merge(); } } }); } catch (ExecutionException e) { throw new RuntimeException(e); } }
From source file:com.ikanow.aleph2.analytics.storm.assets.TestPassthroughTopology_Transient.java
@Test public void test_passthroughTopology() throws InterruptedException, ExecutionException { ////////////////////////////////////////////////////// // PHASE 1: GET AN IN-TECHNOLOGY CONTEXT // Bucket//from w ww. j av a2 s. c o m final AnalyticThreadJobBean.AnalyticThreadJobInputBean analytic_input = BeanTemplateUtils .build(AnalyticThreadJobBean.AnalyticThreadJobInputBean.class) .with(AnalyticThreadJobBean.AnalyticThreadJobInputBean::data_service, "stream") .with(AnalyticThreadJobBean.AnalyticThreadJobInputBean::resource_name_or_id, "").done().get(); final AnalyticThreadJobBean.AnalyticThreadJobOutputBean analytic_output = BeanTemplateUtils .build(AnalyticThreadJobBean.AnalyticThreadJobOutputBean.class) .with(AnalyticThreadJobBean.AnalyticThreadJobOutputBean::is_transient, true) .with(AnalyticThreadJobBean.AnalyticThreadJobOutputBean::transient_type, DataBucketBean.MasterEnrichmentType.streaming) .done().get(); final AnalyticThreadJobBean analytic_job1 = BeanTemplateUtils.build(AnalyticThreadJobBean.class) .with(AnalyticThreadJobBean::name, "analytic_job1") .with(AnalyticThreadJobBean::inputs, Arrays.asList(analytic_input)) .with(AnalyticThreadJobBean::output, analytic_output).done().get(); final AnalyticThreadBean analytic_thread = BeanTemplateUtils.build(AnalyticThreadBean.class) .with(AnalyticThreadBean::jobs, Arrays.asList(analytic_job1)).done().get(); final DataBucketBean test_bucket = BeanTemplateUtils.build(DataBucketBean.class) .with(DataBucketBean::_id, "test_passthroughtopology_transient") .with(DataBucketBean::modified, new Date()) .with(DataBucketBean::full_name, "/test/passthrough/transient") .with(DataBucketBean::analytic_thread, analytic_thread) .with("data_schema", BeanTemplateUtils.build(DataSchemaBean.class) .with("search_index_schema", BeanTemplateUtils.build(DataSchemaBean.SearchIndexSchemaBean.class).done().get()) .done().get()) .done().get(); // // ////////////////////////////////////////////////////// // // PHASE 2: SPECIFICALLY FOR THIS TEST // //(Also: register a listener on the output to generate a secondary queue) final ICoreDistributedServices cds = _service_context .getService(ICoreDistributedServices.class, Optional.empty()).get(); final String inter_queue_topic = cds.generateTopicName(test_bucket.full_name(), Optional.of("analytic_job1")); cds.createTopic(inter_queue_topic, Optional.of(Collections.emptyMap())); ////////////////////////////////////////////////////// // PHASE 3: SUBMIT TO TESTING SERVICE final BasicMessageBean res = new MockStormTestingService(_service_context).testAnalyticModule(test_bucket) .get(); assertTrue("Storm starts", res.success()); _logger.info("******** Submitted storm cluster: " + res.message()); Thread.sleep(5000L); ////////////////////////////////////////////////////// //PHASE 4: PREPARE INPUT DATA // 4a: cleanse final ISearchIndexService index_service = _service_context .getService(ISearchIndexService.class, Optional.empty()).get(); final ICrudService<JsonNode> crud_service = index_service.getDataService().flatMap( s -> s.getWritableDataService(JsonNode.class, test_bucket, Optional.empty(), Optional.empty())) .flatMap(IDataWriteService::getCrudService).get(); crud_service.deleteDatastore().get(); _logger.info("******** Cleansed existing datastore"); Thread.sleep(2000L); assertEquals(0L, crud_service.countObjects().get().intValue()); // 4b: write to kafka final String topic_name = cds.generateTopicName(test_bucket.full_name(), Optional.empty()); Iterator<String> consumer = cds.consumeAs(inter_queue_topic, Optional.of(BucketUtils.getUniqueSignature(test_bucket.full_name(), Optional.empty())), Optional.empty()); cds.produce(topic_name, "{\"test\":\"test1\"}"); Thread.sleep(5000); //wait for producers to dump batch _logger.info("******** Written to CDS: " + topic_name); ////////////////////////////////////////////////////// //PHASE 5: CHECK OUTPUT DATA // 5a: check ES index Thread.sleep(5000); //wait for producers to dump batch for (int i = 0; i < 60; ++i) { Thread.sleep(1000L); if (consumer.hasNext()) { _logger.info("******** Waited for queue to populate: " + i); break; } } assertEquals("Should be 0 objects in the repo", 0L, crud_service.countObjects().get().intValue()); // 5b: check kafka queue int message_count = 0; //read the item off the queue while (consumer.hasNext()) { consumer.next(); message_count++; } assertEquals(1, message_count); }
From source file:ai.grakn.test.engine.controller.TasksControllerTest.java
@Test @Ignore("Fails randomly when running on travis") public void afterSendingTaskWithRunAt_ItIsDelayedInStorage() { Instant runAt = now();/*ww w . j a v a2 s . c o m*/ send(Collections.emptyMap(), defaultParams()); verify(manager).addTask(argThat(argument -> argument.schedule().runAt().equals(runAt)), any()); }
From source file:com.haulmont.cuba.gui.data.impl.AbstractCollectionDatasource.java
@Override public Map<String, Object> getLastRefreshParameters() { return savedParameters == null ? Collections.emptyMap() : Collections.unmodifiableMap(savedParameters); }
From source file:com.erudika.para.utils.ValidationUtils.java
/** * Validates objects./*from ww w .ja v a 2 s. com*/ * @param content an object to be validated * @param app the current app * @return a list of error messages or empty if object is valid */ public static String[] validateObject(App app, ParaObject content) { if (content == null || app == null) { return new String[] { "Object cannot be null." }; } try { String type = content.getType(); boolean isCustomType = (content instanceof Sysprop) && !type.equals(Utils.type(Sysprop.class)); // Validate custom types and user-defined properties if (!app.getValidationConstraints().isEmpty() && isCustomType) { Map<String, Map<String, Map<String, Object>>> fieldsMap = app.getValidationConstraints().get(type); if (fieldsMap != null && !fieldsMap.isEmpty()) { ArrayList<String> errors = new ArrayList<String>(); for (Map.Entry<String, Map<String, Map<String, Object>>> e : fieldsMap.entrySet()) { String field = e.getKey(); Object actualValue = ((Sysprop) content).getProperty(field); // overriding core property validation rules is allowed if (actualValue == null && PropertyUtils.isReadable(content, field)) { actualValue = PropertyUtils.getProperty(content, field); } Map<String, Map<String, Object>> consMap = e.getValue(); for (Map.Entry<String, Map<String, Object>> constraint : consMap.entrySet()) { String consName = constraint.getKey(); Map<String, Object> vals = constraint.getValue(); if (vals == null) { vals = Collections.emptyMap(); } Object val = vals.get("value"); Object min = vals.get("min"); Object max = vals.get("max"); Object in = vals.get("integer"); Object fr = vals.get("fraction"); if ("required".equals(consName) && !required().isValid(actualValue)) { errors.add(Utils.formatMessage("{0} is required.", field)); } else if (matches(Min.class, consName) && !min(val).isValid(actualValue)) { errors.add( Utils.formatMessage("{0} must be a number larger than {1}.", field, val)); } else if (matches(Max.class, consName) && !max(val).isValid(actualValue)) { errors.add( Utils.formatMessage("{0} must be a number smaller than {1}.", field, val)); } else if (matches(Size.class, consName) && !size(min, max).isValid(actualValue)) { errors.add( Utils.formatMessage("{0} must be between {1} and {2}.", field, min, max)); } else if (matches(Email.class, consName) && !email().isValid(actualValue)) { errors.add(Utils.formatMessage("{0} is not a valid email.", field)); } else if (matches(Digits.class, consName) && !digits(in, fr).isValid(actualValue)) { errors.add( Utils.formatMessage("{0} is not a valid number or within range.", field)); } else if (matches(Pattern.class, consName) && !pattern(val).isValid(actualValue)) { errors.add(Utils.formatMessage("{0} doesn't match the pattern {1}.", field, val)); } else if (matches(AssertFalse.class, consName) && !falsy().isValid(actualValue)) { errors.add(Utils.formatMessage("{0} must be false.", field)); } else if (matches(AssertTrue.class, consName) && !truthy().isValid(actualValue)) { errors.add(Utils.formatMessage("{0} must be true.", field)); } else if (matches(Future.class, consName) && !future().isValid(actualValue)) { errors.add(Utils.formatMessage("{0} must be in the future.", field)); } else if (matches(Past.class, consName) && !past().isValid(actualValue)) { errors.add(Utils.formatMessage("{0} must be in the past.", field)); } else if (matches(URL.class, consName) && !url().isValid(actualValue)) { errors.add(Utils.formatMessage("{0} is not a valid URL.", field)); } } } if (!errors.isEmpty()) { return errors.toArray(new String[0]); } } } } catch (Exception ex) { logger.error(null, ex); } return validateObject(content); }
From source file:grails.plugin.springsecurity.web.access.GrailsWebInvocationPrivilegeEvaluator.java
static HttpServletRequest createInstance(final String contextPath, final String httpMethod, final String requestURI) { final Map<String, Object> attributes = new HashMap<String, Object>(); return (HttpServletRequest) Proxy.newProxyInstance(HttpServletRequest.class.getClassLoader(), new Class[] { HttpServletRequest.class }, new InvocationHandler() { public Object invoke(Object proxy, Method method, Object[] args) { String methodName = method.getName(); if ("getContextPath".equals(methodName)) return contextPath; if ("getMethod".equals(methodName)) return httpMethod; if ("getRequestURI".equals(methodName)) return requestURI; if ("setAttribute".equals(methodName)) { attributes.put((String) args[0], args[1]); return null; }// w w w.j av a 2 s . c o m if ("getAttribute".equals(methodName)) { return attributes.get(args[0]); } if ("getProtocol".equals(methodName) || "getScheme".equals(methodName)) return "http"; if ("getServerName".equals(methodName)) return "localhost"; if ("getServerPort".equals(methodName)) return 8080; if (methodName.startsWith("is")) return false; if ("getParameterMap".equals(methodName)) return Collections.emptyMap(); if ("getAttributeNames".equals(methodName) || "getHeaderNames".equals(methodName) || "getHeaders".equals(methodName) || "getLocales".equals(methodName) || "getParameterNames".equals(methodName)) { return Collections.enumeration(Collections.emptySet()); } return null; } }); }
From source file:com.github.nmorel.gwtjackson.client.deser.bean.AbstractBeanJsonDeserializer.java
/** * Initialize the {@link Map} containing the {@link SubtypeDeserializer}. Returns an empty map if the bean has no subtypes. *//*from w w w . j a v a2 s. c o m*/ protected Map<Class, SubtypeDeserializer> initMapSubtypeClassToDeserializer() { return Collections.emptyMap(); }
From source file:tech.sirwellington.alchemy.http.AlchemyHttpBuilderTest.java
@Repeat(100) @Test/*from w ww . j a va 2s . c o m*/ public void testUsingDefaultHeaders() { Map<String, String> headers = mapOf(alphabeticString(), asString(smallPositiveIntegers()), 100); AlchemyHttpBuilder result = instance.usingDefaultHeaders(headers); assertThat(result, notNullValue()); AlchemyHttp http = result.build(); assertThat(http, notNullValue()); assertThat(http.getDefaultHeaders(), is(headers)); //Edge cases assertThrows(() -> instance.usingDefaultHeaders(null)).isInstanceOf(IllegalArgumentException.class); //Empty headers is ok instance.usingDefaultHeaders(Collections.emptyMap()); }
From source file:io.coala.json.DynaBean.java
/** * @return the map of property values/*from w w w . j av a 2s . co m*/ */ @JsonAnyGetter protected Map<String, Object> any() { return this.dynamicProperties == null ? Collections.emptyMap() : this.dynamicProperties; }