List of usage examples for java.util Collections EMPTY_MAP
Map EMPTY_MAP
To view the source code for java.util Collections EMPTY_MAP.
Click Source Link
From source file:org.apache.tiles.definition.TestUrlDefinitionsFactory.java
/** * Tests addSource with a bad source object type. * * @throws Exception If something goes wrong. *//*from w w w . j a v a 2 s .c om*/ @SuppressWarnings("unchecked") public void testBadSourceType() throws Exception { try { DefinitionsFactory factory = new UrlDefinitionsFactory(); factory.init(Collections.EMPTY_MAP); factory.addSource("Bad object."); fail("Should've thrown exception."); } catch (DefinitionsFactoryException e) { if (LOG.isDebugEnabled()) { LOG.debug("Bad class name intercepted, it is ok", e); } // success. } }
From source file:org.apereo.portal.utils.cache.CachingResourceLoaderImplTest.java
@Test public void testCachedNotModified() throws Exception { final Resource doc1Resouce = new FileSystemResource(doc1); final CachingResourceLoaderImpl loader = new CachingResourceLoaderImpl(); final Ehcache cache = createMock(Ehcache.class); final CachedResource<?> cachedResource = createMock(CachedResource.class); final ResourcesElementsProvider elementsProvider = createMock(ResourcesElementsProvider.class); expect(elementsProvider.getDefaultIncludedType()).andReturn(Included.AGGREGATED); expect(cache.getInternalContext()).andReturn(null).anyTimes(); expect(cache.getCacheConfiguration()).andReturn(new CacheConfiguration()); final Element element = new Element("class path resource [CachingResourceLoaderImplTest_doc1.txt]", cachedResource);/*w w w . j ava 2 s . c o m*/ expect(cache.get(doc1Resouce)).andReturn(element); final long lastModified = doc1.lastModified(); expect(cachedResource.getResource()).andReturn(doc1Resouce); expect(cachedResource.getLastCheckTime()).andReturn(0L); expect(cachedResource.getLastLoadTime()).andReturn(lastModified + TimeUnit.MINUTES.toMillis(5)); expect(cachedResource.getAdditionalResources()).andReturn(Collections.EMPTY_MAP); cachedResource.setLastCheckTime(anyLong()); cache.put(element); expectLastCall(); replay(cache, cachedResource, elementsProvider); loader.setResourceCache(cache); loader.setResourcesElementsProvider(elementsProvider); final CachedResource<String> cachedResource1 = loader.getResource(doc1Resouce, StringResourceBuilder.INSTANCE); verify(cache, cachedResource, elementsProvider); assertNotNull(cachedResource1); assertTrue(cachedResource1 == cachedResource); }
From source file:org.apache.atlas.web.integration.EntityJerseyResourceIT.java
@Test //API should accept single entity (or jsonarray of entities) public void testSubmitSingleEntity() throws Exception { Referenceable databaseInstance = new Referenceable(DATABASE_TYPE_BUILTIN); String dbName = randomString(); databaseInstance.set("name", dbName); databaseInstance.set(QUALIFIED_NAME, dbName); databaseInstance.set("clusterName", randomString()); databaseInstance.set("description", randomString()); databaseInstance.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName); databaseInstance.set("owner", "user1"); databaseInstance.set("clusterName", "cl1"); databaseInstance.set("parameters", Collections.EMPTY_MAP); databaseInstance.set("location", "/tmp"); JSONObject response = atlasClientV1.callAPIWithBody(AtlasClient.API.CREATE_ENTITY, InstanceSerialization.toJson(databaseInstance, true)); assertNotNull(response);//from w w w .j a v a 2s . c om Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); EntityResult entityResult = EntityResult.fromString(response.toString()); assertEquals(entityResult.getCreatedEntities().size(), 1); assertNotNull(entityResult.getCreatedEntities().get(0)); }
From source file:org.kbac.spring.scope.TransactionScope.java
/** * @param transactionId/*from w w w . j ava 2s.c om*/ * @return unmodifiable map of bean names to bean instances for given transactionId, empty map when none found */ public Map<String, Object> getTransactionBeans(String transactionId) { final Map<String, Object> namedBeans = this.transactionNamedBeans.get(transactionId); return Collections.unmodifiableMap(namedBeans == null ? Collections.EMPTY_MAP : namedBeans); }
From source file:org.zkoss.zk.grails.web.ZULUrlMappingsFilter.java
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override//from w w w . j av a2 s.c o m protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { UrlMappingsHolder holder = WebUtils.lookupUrlMappings(getServletContext()); String uri = urlHelper.getPathWithinApplication(request); if (uri.startsWith("/zkau") || uri.startsWith("/zkcomet") || uri.startsWith("/dbconsole") || uri.startsWith("/ext") || uri.startsWith("~.")) { LOG.debug("Excluding: " + uri); processFilterChain(request, response, filterChain); return; } if (!"/".equals(uri) && noControllers() && noComposers() && noRegexMappings(holder)) { // not index request, no controllers, and no URL mappings for views, so it's not a Grails request LOG.debug( "not index request, no controllers, and no URL mappings for views, so it's not a Grails request"); processFilterChain(request, response, filterChain); return; } if (isUriExcluded(holder, uri)) { LOG.debug("Excluded by pattern: " + uri); processFilterChain(request, response, filterChain); return; } if (LOG.isDebugEnabled()) { LOG.debug("Executing URL mapping filter..."); LOG.debug(holder); } if (areFileExtensionsEnabled()) { String format = WebUtils.getFormatFromURI(uri, mimeTypes); if (format != null) { MimeType[] configuredMimes = mimeTypes == null ? MimeType.getConfiguredMimeTypes() : mimeTypes; // only remove the file extension if it's one of the configured mimes in Config.groovy for (MimeType configuredMime : configuredMimes) { if (configuredMime.getExtension().equals(format)) { request.setAttribute(GrailsApplicationAttributes.RESPONSE_FORMAT, format); uri = uri.substring(0, (uri.length() - format.length() - 1)); break; } } } } GrailsWebRequest webRequest = (GrailsWebRequest) request .getAttribute(GrailsApplicationAttributes.WEB_REQUEST); UrlMappingInfo[] urlInfos = holder.matchAll(uri); WrappedResponseHolder.setWrappedResponse(response); boolean dispatched = false; try { // GRAILS-3369: Save the original request parameters. Map backupParameters; try { backupParameters = new HashMap(webRequest.getParams()); } catch (Exception e) { LOG.error("Error creating params object: " + e.getMessage(), e); backupParameters = Collections.EMPTY_MAP; } for (UrlMappingInfo info : urlInfos) { if (info != null) { // GRAILS-3369: The configure() will modify the // parameter map attached to the web request. So, // we need to clear it each time and restore the // original request parameters. webRequest.getParams().clear(); webRequest.getParams().putAll(backupParameters); final String viewName; try { info.configure(webRequest); String action = info.getActionName() == null ? "" : info.getActionName(); viewName = info.getViewName(); if (viewName == null && info.getURI() == null) { final String controllerName = info.getControllerName(); String pluginName = info.getPluginName(); String featureUri = WebUtils.SLASH + urlConverter.toUrlElement(controllerName) + WebUtils.SLASH + urlConverter.toUrlElement(action); Object featureId = null; if (pluginName != null) { Map featureIdMap = new HashMap(); featureIdMap.put("uri", featureUri); featureIdMap.put("pluginName", pluginName); featureId = featureIdMap; } else { featureId = featureUri; } GrailsClass controller = application .getArtefactForFeature(ControllerArtefactHandler.TYPE, featureId); if (controller == null) { if (uri.endsWith(".zul")) { RequestDispatcher dispatcher = request.getRequestDispatcher(uri); dispatcher.forward(request, response); dispatched = true; break; } String zul = composerMapping.resolveZul(controllerName); if (zul != null) { RequestDispatcher dispatcher = request.getRequestDispatcher(zul); dispatcher.forward(request, response); dispatched = true; break; } } else { webRequest.setAttribute(GrailsApplicationAttributes.CONTROLLER_NAME_ATTRIBUTE, controller.getLogicalPropertyName(), WebRequest.SCOPE_REQUEST); webRequest.setAttribute(GrailsApplicationAttributes.GRAILS_CONTROLLER_CLASS, controller, WebRequest.SCOPE_REQUEST); // webRequest.setAttribute(GrailsApplicationAttributes. GRAILS_CONTROLLER_CLASS_AVAILABLE, Boolean.TRUE, WebRequest.SCOPE_REQUEST); } } } catch (Exception e) { if (e instanceof MultipartException) { reapplySitemesh(request); throw ((MultipartException) e); } LOG.error("Error when matching URL mapping [" + info + "]:" + e.getMessage(), e); continue; } dispatched = true; if (!WAR_DEPLOYED) { checkDevelopmentReloadingState(request); } request = checkMultipart(request); if (viewName == null || (viewName.endsWith(GSP_SUFFIX) || viewName.endsWith(JSP_SUFFIX))) { if (info.isParsingRequest()) { webRequest.informParameterCreationListeners(); } String forwardUrl = WebUtils.forwardRequestForUrlMappingInfo(request, response, info); if (LOG.isDebugEnabled()) { LOG.debug("Matched URI [" + uri + "] to URL mapping [" + info + "], forwarding to [" + forwardUrl + "] with response [" + response.getClass() + "]"); } } else if (viewName != null && viewName.endsWith(ZUL_SUFFIX)) { RequestDispatcher dispatcher = request.getRequestDispatcher(viewName); dispatcher.forward(request, response); } else { if (viewName == null) { dispatched = false; } else if (!renderViewForUrlMappingInfo(request, response, info, viewName)) { dispatched = false; } } break; } } // for } finally { WrappedResponseHolder.setWrappedResponse(null); } if (!dispatched) { if (LOG.isDebugEnabled()) { LOG.debug("No match found, processing remaining filter chain."); } processFilterChain(request, response, filterChain); } }
From source file:fr.inria.atlanmod.neoemf.map.datastore.MapPersistenceBackendFactoryTest.java
@Test public void testCreatePersistentEStoreDirectWriteWithIndexesOption() throws InvalidDataStoreException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { storeOptions.add(MapResourceOptions.EStoreMapOption.DIRECT_WRITE_WITH_INDEXES); PersistenceBackend persistentBackend = persistenceBackendFactory.createPersistentBackend(testFile, Collections.EMPTY_MAP); SearcheableResourceEStore eStore = persistenceBackendFactory.createPersistentEStore(null, persistentBackend, options);//from w w w. ja v a2 s. com assert eStore instanceof DirectWriteMapWithIndexesResourceEStoreImpl : "Invalid EStore created"; PersistenceBackend innerBackend = getInnerBackend((DirectWriteMapWithIndexesResourceEStoreImpl) eStore); assert innerBackend == persistentBackend : "The backend in the EStore is not the created one"; }
From source file:de.hybris.platform.cronjob.jalo.CronJobTest.java
@Test public void testEmailNotification() throws Exception { // create essential data for doing an import new CoreBasicDataCreator().createSupportedEncodings(); getOrCreateLanguage("de"); getOrCreateLanguage("en"); // create essential data for cronjob to create default template CronJobManager.getInstance().createEssentialData(Collections.EMPTY_MAP, null); // create cronjob without setting a template final BatchJob job = manager.createBatchJob("testBatch"); final CronJob cronJob11 = createCronJob(job, CRONJOB_11, true, node1, running); // check if default template was set assertNotNull("No default notification template set at cronjob", cronJob11.getEmailNotificationTemplate()); assertEquals("Assigned notification template is not the default one", CronJobManager.getInstance().getDefaultCronJobFinishNotificationTemplate(), cronJob11.getEmailNotificationTemplate()); }
From source file:com.espertech.esper.epl.variable.VariableReadWritePackage.java
/** * Ctor.//from w w w .j av a2 s . c o m * @param assignments the list of variable assignments * @param variableService variable service * @param eventAdapterService event adapters * @throws ExprValidationException when variables cannot be found */ public VariableReadWritePackage(List<OnTriggerSetAssignment> assignments, VariableService variableService, EventAdapterService eventAdapterService) throws ExprValidationException { this.readers = new VariableReader[assignments.size()]; this.mustCoerce = new boolean[assignments.size()]; this.writers = new WriteDesc[assignments.size()]; this.variableTypes = new HashMap<String, Object>(); this.eventAdapterService = eventAdapterService; Map<EventTypeSPI, CopyMethodDesc> eventTypeWrittenProps = new HashMap<EventTypeSPI, CopyMethodDesc>(); int count = 0; List<VariableTriggerSetDesc> assignmentList = new ArrayList<VariableTriggerSetDesc>(); for (OnTriggerSetAssignment expressionWithAssignments : assignments) { Pair<String, ExprNode> possibleVariableAssignment = ExprNodeUtility .checkGetAssignmentToVariableOrProp(expressionWithAssignments.getExpression()); if (possibleVariableAssignment == null) { throw new ExprValidationException( "Missing variable assignment expression in assignment number " + count); } assignmentList.add(new VariableTriggerSetDesc(possibleVariableAssignment.getFirst(), possibleVariableAssignment.getSecond().getExprEvaluator())); String fullVariableName = possibleVariableAssignment.getFirst(); String variableName = fullVariableName; String subPropertyName = null; int indexOfDot = variableName.indexOf('.'); if (indexOfDot != -1) { subPropertyName = variableName.substring(indexOfDot + 1, variableName.length()); variableName = variableName.substring(0, indexOfDot); } VariableReader variableReader = variableService.getReader(variableName); readers[count] = variableReader; if (variableReader == null) { throw new ExprValidationException( "Variable by name '" + variableName + "' has not been created or configured"); } if (variableReader.isConstant()) { throw new ExprValidationException( "Variable by name '" + variableName + "' is declared constant and may not be set"); } if (subPropertyName != null) { if (variableReader.getEventType() == null) { throw new ExprValidationException("Variable by name '" + variableName + "' does not have a property named '" + subPropertyName + "'"); } EventType type = variableReader.getEventType(); if (!(type instanceof EventTypeSPI)) { throw new ExprValidationException("Variable by name '" + variableName + "' event type '" + type.getName() + "' not writable"); } EventTypeSPI spi = (EventTypeSPI) type; EventPropertyWriter writer = spi.getWriter(subPropertyName); EventPropertyGetter getter = spi.getGetter(subPropertyName); if (writer == null) { throw new ExprValidationException("Variable by name '" + variableName + "' the property '" + subPropertyName + "' is not writable"); } variableTypes.put(fullVariableName, spi.getPropertyType(subPropertyName)); CopyMethodDesc writtenProps = eventTypeWrittenProps.get(spi); if (writtenProps == null) { writtenProps = new CopyMethodDesc(variableName, new ArrayList<String>()); eventTypeWrittenProps.put(spi, writtenProps); } writtenProps.getPropertiesCopied().add(subPropertyName); writers[count] = new WriteDesc(spi, variableName, writer, getter); } else { // determine types Class expressionType = possibleVariableAssignment.getSecond().getExprEvaluator().getType(); if (variableReader.getEventType() != null) { if ((expressionType != null) && (!JavaClassHelper.isSubclassOrImplementsInterface(expressionType, variableReader.getEventType().getUnderlyingType()))) { throw new VariableValueException("Variable '" + variableName + "' of declared event type '" + variableReader.getEventType().getName() + "' underlying type '" + variableReader.getEventType().getUnderlyingType().getName() + "' cannot be assigned a value of type '" + expressionType.getName() + "'"); } variableTypes.put(variableName, variableReader.getEventType().getUnderlyingType()); } else { Class variableType = variableReader.getType(); variableTypes.put(variableName, variableType); // determine if the expression type can be assigned if (variableType != java.lang.Object.class) { if ((JavaClassHelper.getBoxedType(expressionType) != variableType) && (expressionType != null)) { if ((!JavaClassHelper.isNumeric(variableType)) || (!JavaClassHelper.isNumeric(expressionType))) { throw new ExprValidationException(VariableServiceImpl .getAssigmentExMessage(variableName, variableType, expressionType)); } if (!(JavaClassHelper.canCoerce(expressionType, variableType))) { throw new ExprValidationException(VariableServiceImpl .getAssigmentExMessage(variableName, variableType, expressionType)); } mustCoerce[count] = true; } } } } count++; } this.assignments = assignmentList.toArray(new VariableTriggerSetDesc[assignmentList.size()]); if (eventTypeWrittenProps.isEmpty()) { copyMethods = Collections.EMPTY_MAP; return; } copyMethods = new HashMap<EventTypeSPI, EventBeanCopyMethod>(); for (Map.Entry<EventTypeSPI, CopyMethodDesc> entry : eventTypeWrittenProps.entrySet()) { List<String> propsWritten = entry.getValue().getPropertiesCopied(); String[] props = propsWritten.toArray(new String[propsWritten.size()]); EventBeanCopyMethod copyMethod = entry.getKey().getCopyMethod(props); if (copyMethod == null) { throw new ExprValidationException( "Variable '" + entry.getValue().getVariableName() + "' of declared type " + JavaClassHelper.getClassNameFullyQualPretty(entry.getKey().getUnderlyingType()) + "' cannot be assigned to"); } copyMethods.put(entry.getKey(), copyMethod); } }
From source file:de.betterform.xml.config.DefaultConfig.java
private HashMap loadCustomElements(NodeInfo configContext, String sectionPath) throws XFormsException { HashMap map = new HashMap(); List nodeset = XPathCache.getInstance().evaluate(configContext, sectionPath, Collections.EMPTY_MAP, null); for (int i = 0; i < nodeset.size(); ++i) { Element element = (Element) XPathUtil.getAsNode(nodeset, i + 1); String namespace = element.getAttribute("namespace"); namespace = ("".equals(namespace)) ? null : namespace; String elementName = element.getAttribute("name"); elementName = ("".equals(elementName)) ? null : elementName; String elementClass = element.getAttribute("class"); elementClass = ("".equals(elementClass)) ? null : elementClass; String key = (namespace == null) ? elementName : namespace + ((elementName == null) ? "" : ":" + elementName); if ((elementName != null) && (elementClass != null)) { if (key != null) { map.put(key, elementClass); }//w ww.j av a2s . c o m } } return map; }
From source file:de.hybris.platform.catalog.jalo.synchronization.ItemCopyCreatorTest.java
@Test public void testUpdatingNullValues() throws JaloBusinessException { final UnitModel u = modelService.create(UnitModel.class); u.setCode("unit-" + System.nanoTime()); u.setUnitType("type"); u.setConversion(Double.valueOf(1.0)); modelService.save(u);//from w ww. j av a 2s.c o m final ProductModel p = modelService.create(ProductModel.class); p.setCatalogVersion((CatalogVersionModel) modelService.get(src)); p.setCode("foo-" + System.nanoTime()); p.setMinOrderQuantity(12); p.setUnit(u); p.setApprovalStatus(ArticleApprovalStatus.APPROVED); modelService.save(p); final Product pJalo = modelService.getSource(p); // 1. create copy -> values are non-null final Product pCopyJalo = (Product) new CatalogVersionSyncCopyContext(syncJob, syncCronJob, worker) { @Override protected Set<Language> getTargetLanguages() { return jaloSession.getC2LManager().getAllLanguages(); } @Override protected SyncSchedule getCurrentSchedule() { return new SyncSchedule(pJalo.getPK(), null, null, Collections.EMPTY_SET, Collections.EMPTY_MAP); } }.copy(pJalo); Assert.assertNotNull("Product not copied", pCopyJalo); final ProductModel pCopy = modelService.get(pCopyJalo); Assert.assertEquals(p.getCode(), pCopy.getCode()); Assert.assertEquals(p.getMinOrderQuantity(), pCopy.getMinOrderQuantity()); Assert.assertEquals(p.getApprovalStatus(), pCopy.getApprovalStatus()); Assert.assertEquals(p.getUnit(), pCopy.getUnit()); // 2. change original -> some values are null now p.setUnit(null); p.setMinOrderQuantity(null); modelService.save(p); Assert.assertNull(p.getMinOrderQuantity()); Assert.assertNull(p.getUnit()); // 3. copy again -> copy should have null values too final Product pCopyJalo2 = (Product) new CatalogVersionSyncCopyContext(syncJob, syncCronJob, worker) { @Override protected Set<Language> getTargetLanguages() { return jaloSession.getC2LManager().getAllLanguages(); } @Override protected SyncSchedule getCurrentSchedule() { return new SyncSchedule(pJalo.getPK(), pCopyJalo.getPK(), null, Collections.EMPTY_SET, Collections.EMPTY_MAP); } }.copy(pJalo); Assert.assertNotNull("Product not copied", pCopyJalo2); final ProductModel pCopy2 = modelService.get(pCopyJalo2); Assert.assertSame(pCopy, pCopy2); modelService.refresh(pCopy2); // unchanged ? Assert.assertEquals(p.getCode(), pCopy2.getCode()); Assert.assertEquals(p.getApprovalStatus(), pCopy2.getApprovalStatus()); // null'ed ? Assert.assertNull(pCopy2.getUnit()); Assert.assertNull(pCopy2.getMinOrderQuantity()); }