Example usage for java.util Collections EMPTY_MAP

List of usage examples for java.util Collections EMPTY_MAP

Introduction

In this page you can find the example usage for java.util Collections EMPTY_MAP.

Prototype

Map EMPTY_MAP

To view the source code for java.util Collections EMPTY_MAP.

Click Source Link

Document

The empty map (immutable).

Usage

From source file:org.hawkular.alerts.actions.elasticsearch.ElasticsearchPlugin.java

protected void writeAlert(Action a) throws Exception {
    String url = a.getProperties().get(PROP_URL);
    String index = a.getProperties().get(PROP_INDEX);
    String type = a.getProperties().get(PROP_TYPE);
    String[] urls = url.split(",");
    HttpHost[] hosts = new HttpHost[urls.length];
    for (int i = 0; i < urls.length; i++) {
        hosts[i] = HttpHost.create(urls[0]);
    }//from w  w w.j a v  a 2 s  . co  m
    RestClient client = RestClient.builder(hosts).setHttpClientConfigCallback(httpClientBuilder -> {
        httpClientBuilder.useSystemProperties();
        CredentialsProvider credentialsProvider = checkBasicCredentials(a);
        if (credentialsProvider != null) {
            httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
        }
        return httpClientBuilder;
    }).build();

    HttpEntity document = new NStringEntity(transform(a), ContentType.APPLICATION_JSON);
    String endpoint = "/" + index + "/" + type;
    Header[] headers = checkHeaders(a);
    Response response = headers == null
            ? client.performRequest("POST", endpoint, Collections.EMPTY_MAP, document)
            : client.performRequest("POST", endpoint, Collections.EMPTY_MAP, document, headers);
    log.debugf(response.toString());
    client.close();
}

From source file:com.redhat.rhn.manager.channel.ChannelManager.java

/**
 * Returns a list channel entitlements for all orgs.
 * @return channel entitlements for multiorgs
 *//*from  w ww  . j a v a  2 s . c o m*/
public static DataList<MultiOrgEntitlementsDto> entitlementsForAllMOrgs() {
    SelectMode m = ModeFactory.getMode("Channel_queries", "channel_entitlements_for_all_m_orgs");
    return DataList.getDataList(m, Collections.EMPTY_MAP, Collections.EMPTY_MAP);
}

From source file:org.artificer.repository.jcr.JCRRelationshipQueryTest.java

@Test
public void testGenericTargetAttributeQueries() throws Exception {
    XsdDocument xsdDoc = addXsdDoc();//from   w  w  w.  j  ava  2 s  .c om
    WsdlDocument wsdlDoc1 = addWsdlDoc();
    WsdlDocument wsdlDoc2 = addWsdlDoc();
    WsdlDocument wsdlDoc3 = addWsdlDoc();

    Map<QName, String> otherAttributes = new HashMap<QName, String>();
    otherAttributes.put(QName.valueOf("FooKey"), "FooValue");
    ArtificerModelUtils.addGenericRelationship(xsdDoc, "relWithAttr", wsdlDoc1.getUuid(), Collections.EMPTY_MAP,
            otherAttributes);
    ArtificerModelUtils.addGenericRelationship(xsdDoc, "relWithAttr", wsdlDoc2.getUuid(), Collections.EMPTY_MAP,
            otherAttributes);
    Map<QName, String> otherAttributes2 = new HashMap<QName, String>();
    otherAttributes2.put(QName.valueOf("FooKey2"), "FooValue2");
    ArtificerModelUtils.addGenericRelationship(xsdDoc, "relWithAttr2", wsdlDoc3.getUuid(),
            Collections.EMPTY_MAP, otherAttributes2);

    xsdDoc = (XsdDocument) persistenceManager.updateArtifact(xsdDoc, ArtifactType.XsdDocument());

    // add custom properties only to one of the wsdls
    Property prop = new Property();
    prop.setPropertyName("FooProperty");
    prop.setPropertyValue("FooValue");
    wsdlDoc1.getProperty().add(prop);

    wsdlDoc1 = (WsdlDocument) persistenceManager.updateArtifact(wsdlDoc1, ArtifactType.WsdlDocument());

    ArtificerQuery query = queryManager
            .createQuery("/s-ramp/xsd/XsdDocument[relWithAttr[s-ramp:getTargetAttribute(., 'FooKey')]]");
    ArtifactSet artifactSet = query.executeQuery();
    Assert.assertNotNull(artifactSet);
    Assert.assertEquals(1, artifactSet.size());

    query = queryManager.createQuery(
            "/s-ramp/xsd/XsdDocument[relWithAttr[s-ramp:getTargetAttribute(., 'FooKey') = 'FooValue']]");
    artifactSet = query.executeQuery();
    Assert.assertNotNull(artifactSet);
    Assert.assertEquals(1, artifactSet.size());

    query = queryManager
            .createQuery("/s-ramp/xsd/XsdDocument[relWithAttr[s-ramp:getTargetAttribute(., 'InvalidKey')]]");
    artifactSet = query.executeQuery();
    Assert.assertNotNull(artifactSet);
    Assert.assertEquals(0, artifactSet.size());

    query = queryManager.createQuery(
            "/s-ramp/xsd/XsdDocument[relWithAttr[s-ramp:getTargetAttribute(., 'FooKey') = 'FooValue' and @FooProperty = 'FooValue']]");
    artifactSet = query.executeQuery();
    Assert.assertNotNull(artifactSet);
    Assert.assertEquals(1, artifactSet.size());

    query = queryManager.createQuery(
            "/s-ramp/xsd/XsdDocument[relWithAttr[s-ramp:getTargetAttribute(., 'FooKey') = 'FooValue' and @InvalidProperty]]");
    artifactSet = query.executeQuery();
    Assert.assertNotNull(artifactSet);
    Assert.assertEquals(0, artifactSet.size());

    query = queryManager.createQuery(
            "/s-ramp/xsd/XsdDocument[relWithAttr[s-ramp:getTargetAttribute(., 'FooKey') = 'FooValue' or @FooProperty = 'FooValue']]");
    artifactSet = query.executeQuery();
    Assert.assertNotNull(artifactSet);
    Assert.assertEquals(1, artifactSet.size());

    query = queryManager.createQuery(
            "/s-ramp/xsd/XsdDocument[relWithAttr[s-ramp:getTargetAttribute(., 'FooKey') = 'InvalidValue' or @FooProperty = 'FooValue']]");
    artifactSet = query.executeQuery();
    Assert.assertNotNull(artifactSet);
    Assert.assertEquals(1, artifactSet.size());

    query = queryManager.createQuery(
            "/s-ramp/xsd/XsdDocument[relWithAttr[s-ramp:getTargetAttribute(., 'FooKey') = 'InvalidValue' or @FooProperty = 'FooValue']]");
    artifactSet = query.executeQuery();
    Assert.assertNotNull(artifactSet);
    Assert.assertEquals(1, artifactSet.size());

    query = queryManager.createQuery("/s-ramp/xsd/XsdDocument[@uuid = ?]/relWithAttr2");
    query.setString(xsdDoc.getUuid());
    artifactSet = query.executeQuery();
    Assert.assertNotNull(artifactSet);
    Assert.assertEquals(1, artifactSet.size());

    query = queryManager.createQuery(
            "/s-ramp/xsd/XsdDocument[@uuid = ?]/relWithAttr2[s-ramp:getTargetAttribute(., 'FooKey2')]");
    query.setString(xsdDoc.getUuid());
    artifactSet = query.executeQuery();
    Assert.assertNotNull(artifactSet);
    Assert.assertEquals(1, artifactSet.size());
    Assert.assertEquals(wsdlDoc3.getUuid(), artifactSet.iterator().next().getUuid());

    query = queryManager.createQuery(
            "/s-ramp/xsd/XsdDocument[@uuid = ?]/relWithAttr2[s-ramp:getTargetAttribute(., 'FooKey2') = 'FooValue2']");
    query.setString(xsdDoc.getUuid());
    artifactSet = query.executeQuery();
    Assert.assertNotNull(artifactSet);
    Assert.assertEquals(1, artifactSet.size());
    Assert.assertEquals(wsdlDoc3.getUuid(), artifactSet.iterator().next().getUuid());

    query = queryManager.createQuery(
            "/s-ramp/xsd/XsdDocument[@uuid = ?]/relWithAttr2[s-ramp:getTargetAttribute(., 'InvalidKey')]");
    query.setString(xsdDoc.getUuid());
    artifactSet = query.executeQuery();
    Assert.assertNotNull(artifactSet);
    Assert.assertEquals(0, artifactSet.size());
}

From source file:net.sf.json.JSONObject.java

/**
 * Creates a bean from a JSONObject, with the specific configuration.
 *//*from  ww  w  . ja  va2 s .  c o m*/
public static Object toBean(JSONObject jsonObject, JsonConfig jsonConfig) {
    if (jsonObject == null || jsonObject.isNullObject()) {
        return null;
    }

    Class beanClass = jsonConfig.getRootClass();
    Map classMap = jsonConfig.getClassMap();

    if (beanClass == null) {
        return toBean(jsonObject);
    }
    if (classMap == null) {
        classMap = Collections.EMPTY_MAP;
    }

    Object bean = null;
    try {
        if (beanClass.isInterface()) {
            if (!Map.class.isAssignableFrom(beanClass)) {
                throw new JSONException("beanClass is an interface. " + beanClass);
            } else {
                bean = new HashMap();
            }
        } else {
            bean = jsonConfig.getNewBeanInstanceStrategy().newInstance(beanClass, jsonObject);
        }
    } catch (JSONException jsone) {
        throw jsone;
    } catch (Exception e) {
        throw new JSONException(e);
    }

    Map props = JSONUtils.getProperties(jsonObject);
    PropertyFilter javaPropertyFilter = jsonConfig.getJavaPropertyFilter();
    for (Iterator entries = jsonObject.names(jsonConfig).iterator(); entries.hasNext();) {
        String name = (String) entries.next();
        Class type = (Class) props.get(name);
        Object value = jsonObject.get(name);
        if (javaPropertyFilter != null && javaPropertyFilter.apply(bean, name, value)) {
            continue;
        }
        String key = Map.class.isAssignableFrom(beanClass)
                && jsonConfig.isSkipJavaIdentifierTransformationInMapKeys() ? name
                        : JSONUtils.convertToJavaIdentifier(name, jsonConfig);
        PropertyNameProcessor propertyNameProcessor = jsonConfig.findJavaPropertyNameProcessor(beanClass);
        if (propertyNameProcessor != null) {
            key = propertyNameProcessor.processPropertyName(beanClass, key);
        }
        try {
            if (Map.class.isAssignableFrom(beanClass)) {
                // no type info available for conversion
                if (JSONUtils.isNull(value)) {
                    setProperty(bean, key, value, jsonConfig);
                } else if (value instanceof JSONArray) {
                    setProperty(bean, key, convertPropertyValueToCollection(key, value, jsonConfig, name,
                            classMap, List.class), jsonConfig);
                } else if (String.class.isAssignableFrom(type) || JSONUtils.isBoolean(type)
                        || JSONUtils.isNumber(type) || JSONUtils.isString(type)
                        || JSONFunction.class.isAssignableFrom(type)) {
                    if (jsonConfig.isHandleJettisonEmptyElement() && "".equals(value)) {
                        setProperty(bean, key, null, jsonConfig);
                    } else {
                        setProperty(bean, key, value, jsonConfig);
                    }
                } else {
                    Class targetClass = resolveClass(classMap, key, name, type);
                    JsonConfig jsc = jsonConfig.copy();
                    jsc.setRootClass(targetClass);
                    jsc.setClassMap(classMap);
                    if (targetClass != null) {
                        setProperty(bean, key, toBean((JSONObject) value, jsc), jsonConfig);
                    } else {
                        setProperty(bean, key, toBean((JSONObject) value), jsonConfig);
                    }
                }
            } else {
                PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(bean, key);
                if (pd != null && pd.getWriteMethod() == null) {
                    log.info("Property '" + key + "' of " + bean.getClass() + " has no write method. SKIPPED.");
                    continue;
                }

                if (pd != null) {
                    Class targetType = pd.getPropertyType();
                    if (!JSONUtils.isNull(value)) {
                        if (value instanceof JSONArray) {
                            if (List.class.isAssignableFrom(pd.getPropertyType())) {
                                setProperty(bean, key, convertPropertyValueToCollection(key, value, jsonConfig,
                                        name, classMap, pd.getPropertyType()), jsonConfig);
                            } else if (Set.class.isAssignableFrom(pd.getPropertyType())) {
                                setProperty(bean, key, convertPropertyValueToCollection(key, value, jsonConfig,
                                        name, classMap, pd.getPropertyType()), jsonConfig);
                            } else {
                                setProperty(bean, key, convertPropertyValueToArray(key, value, targetType,
                                        jsonConfig, classMap), jsonConfig);
                            }
                        } else if (String.class.isAssignableFrom(type) || JSONUtils.isBoolean(type)
                                || JSONUtils.isNumber(type) || JSONUtils.isString(type)
                                || JSONFunction.class.isAssignableFrom(type)) {
                            if (pd != null) {
                                if (jsonConfig.isHandleJettisonEmptyElement() && "".equals(value)) {
                                    setProperty(bean, key, null, jsonConfig);
                                } else if (!targetType.isInstance(value)) {
                                    setProperty(bean, key, morphPropertyValue(key, value, type, targetType),
                                            jsonConfig);
                                } else {
                                    setProperty(bean, key, value, jsonConfig);
                                }
                            } else if (beanClass == null || bean instanceof Map) {
                                setProperty(bean, key, value, jsonConfig);
                            } else {
                                log.warn("Tried to assign property " + key + ":" + type.getName()
                                        + " to bean of class " + bean.getClass().getName());
                            }
                        } else {
                            if (jsonConfig.isHandleJettisonSingleElementArray()) {
                                JSONArray array = new JSONArray().element(value, jsonConfig);
                                Class newTargetClass = resolveClass(classMap, key, name, type);
                                JsonConfig jsc = jsonConfig.copy();
                                jsc.setRootClass(newTargetClass);
                                jsc.setClassMap(classMap);
                                if (targetType.isArray()) {
                                    setProperty(bean, key, JSONArray.toArray(array, jsc), jsonConfig);
                                } else if (JSONArray.class.isAssignableFrom(targetType)) {
                                    setProperty(bean, key, array, jsonConfig);
                                } else if (List.class.isAssignableFrom(targetType)
                                        || Set.class.isAssignableFrom(targetType)) {
                                    jsc.setCollectionType(targetType);
                                    setProperty(bean, key, JSONArray.toCollection(array, jsc), jsonConfig);
                                } else {
                                    setProperty(bean, key, toBean((JSONObject) value, jsc), jsonConfig);
                                }
                            } else {
                                if (targetType == Object.class || targetType.isInterface()) {
                                    Class targetTypeCopy = targetType;
                                    targetType = findTargetClass(key, classMap);
                                    targetType = targetType == null ? findTargetClass(name, classMap)
                                            : targetType;
                                    targetType = targetType == null && targetTypeCopy.isInterface()
                                            ? targetTypeCopy
                                            : targetType;
                                }
                                JsonConfig jsc = jsonConfig.copy();
                                jsc.setRootClass(targetType);
                                jsc.setClassMap(classMap);
                                setProperty(bean, key, toBean((JSONObject) value, jsc), jsonConfig);
                            }
                        }
                    } else {
                        if (type.isPrimitive()) {
                            // assume assigned default value
                            log.warn("Tried to assign null value to " + key + ":" + type.getName());
                            setProperty(bean, key, JSONUtils.getMorpherRegistry().morph(type, null),
                                    jsonConfig);
                        } else {
                            setProperty(bean, key, null, jsonConfig);
                        }
                    }
                } else {
                    if (!JSONUtils.isNull(value)) {
                        if (value instanceof JSONArray) {
                            setProperty(bean, key, convertPropertyValueToCollection(key, value, jsonConfig,
                                    name, classMap, List.class), jsonConfig);
                        } else if (String.class.isAssignableFrom(type) || JSONUtils.isBoolean(type)
                                || JSONUtils.isNumber(type) || JSONUtils.isString(type)
                                || JSONFunction.class.isAssignableFrom(type)) {
                            if (beanClass == null || bean instanceof Map
                                    || jsonConfig.getPropertySetStrategy() != null
                                    || !jsonConfig.isIgnorePublicFields()) {
                                setProperty(bean, key, value, jsonConfig);
                            } else {
                                log.warn("Tried to assign property " + key + ":" + type.getName()
                                        + " to bean of class " + bean.getClass().getName());
                            }
                        } else {
                            if (jsonConfig.isHandleJettisonSingleElementArray()) {
                                Class newTargetClass = resolveClass(classMap, key, name, type);
                                JsonConfig jsc = jsonConfig.copy();
                                jsc.setRootClass(newTargetClass);
                                jsc.setClassMap(classMap);
                                setProperty(bean, key, toBean((JSONObject) value, jsc), jsonConfig);
                            } else {
                                setProperty(bean, key, value, jsonConfig);
                            }
                        }
                    } else {
                        if (type.isPrimitive()) {
                            // assume assigned default value
                            log.warn("Tried to assign null value to " + key + ":" + type.getName());
                            setProperty(bean, key, JSONUtils.getMorpherRegistry().morph(type, null),
                                    jsonConfig);
                        } else {
                            setProperty(bean, key, null, jsonConfig);
                        }
                    }
                }
            }
        } catch (JSONException jsone) {
            throw jsone;
        } catch (Exception e) {
            throw new JSONException("Error while setting property=" + name + " type " + type, e);
        }
    }

    return bean;
}

From source file:it.units.malelab.ege.util.DUMapper.java

private static double[][][] buildGEData(String mapperName, int generations, int genotypeSize, Problem problem,
        long seed, int tournamentSize) throws InterruptedException, ExecutionException {
    Mapper<BitsGenotype, String> mapper;
    if (mapperName.equals("whge")) {
        mapper = new WeightedHierarchicalMapper<>(2, problem.getGrammar());
    } else if (mapperName.equals("hge")) {
        mapper = new HierarchicalMapper<>(problem.getGrammar());
    } else {/* w w w.j  a  v  a  2s . c o  m*/
        mapper = new StandardGEMapper<>(8, 10, problem.getGrammar());
    }
    StandardConfiguration<BitsGenotype, String, NumericFitness> configuration = new StandardConfiguration<>(500,
            generations, new RandomInitializer<>(new BitsGenotypeFactory(genotypeSize)),
            new Any<BitsGenotype>(), mapper,
            new Utils.MapBuilder<GeneticOperator<BitsGenotype>, Double>()
                    .put(new LengthPreservingTwoPointsCrossover(), 0.8d)
                    .put(new ProbabilisticMutation(0.01), 0.2d).build(),
            new ComparableRanker<>(new IndividualComparator<BitsGenotype, String, NumericFitness>(
                    IndividualComparator.Attribute.FITNESS)),
            new Tournament<Individual<BitsGenotype, String, NumericFitness>>(tournamentSize),
            new LastWorst<Individual<BitsGenotype, String, NumericFitness>>(), 500, true, problem, false, -1,
            -1);
    StandardEvolver evolver = new StandardEvolver(configuration, false);
    List<EvolverListener> listeners = new ArrayList<>();
    final EvolutionImageSaverListener evolutionImageSaverListener = new EvolutionImageSaverListener(
            Collections.EMPTY_MAP, null, EvolutionImageSaverListener.ImageType.DU);
    listeners.add(evolutionImageSaverListener);
    listeners.add(new CollectorGenerationLogger<>(Collections.EMPTY_MAP, System.out, true, 10, " ", " | ",
            new Population(), new NumericFirstBest(false, problem.getTestingFitnessComputer(), "%6.2f"),
            new Diversity(), new BestPrinter(problem.getPhenotypePrinter(), "%30.30s")));
    ExecutorService executorService = Executors.newCachedThreadPool();
    evolver.solve(executorService, new Random(seed), listeners);
    return evolutionImageSaverListener.getLastEvolutionData();
}

From source file:org.codehaus.groovy.grails.web.mapping.RegexUrlMapping.java

@SuppressWarnings({ "unchecked" })
private String createURLInternal(Map paramValues, String encoding, boolean includeContextPath) {

    if (encoding == null)
        encoding = "utf-8";

    String contextPath = "";
    if (includeContextPath) {
        GrailsWebRequest webRequest = (GrailsWebRequest) RequestContextHolder.getRequestAttributes();
        if (webRequest != null) {
            contextPath = webRequest.getAttributes().getApplicationUri(webRequest.getCurrentRequest());
        }/*w  w w.  ja  v  a2s.c  om*/
    }
    if (paramValues == null)
        paramValues = Collections.EMPTY_MAP;
    StringBuilder uri = new StringBuilder(contextPath);
    Set usedParams = new HashSet();

    String[] tokens = urlData.getTokens();
    int paramIndex = 0;
    for (int i = 0; i < tokens.length; i++) {
        String token = tokens[i];
        if (i == tokens.length - 1 && urlData.hasOptionalExtension()) {
            token += UrlMapping.OPTIONAL_EXTENSION_WILDCARD;
        }
        Matcher m = OPTIONAL_EXTENSION_WILDCARD_PATTERN.matcher(token);
        if (m.find()) {

            if (token.startsWith(CAPTURED_WILDCARD)) {
                ConstrainedProperty prop = constraints[paramIndex++];
                String propName = prop.getPropertyName();

                Object value = paramValues.get(propName);
                usedParams.add(propName);

                if (value != null) {
                    token = token.replaceFirst(DOUBLE_WILDCARD_PATTERN.pattern(), value.toString());
                } else if (prop.isNullable()) {
                    break;
                }
            }
            uri.append(SLASH);
            ConstrainedProperty prop = constraints[paramIndex++];
            String propName = prop.getPropertyName();
            Object value = paramValues.get(propName);
            usedParams.add(propName);
            if (value != null) {
                String ext = "." + value;
                uri.append(token.replace(OPTIONAL_EXTENSION_WILDCARD + '?', ext)
                        .replace(OPTIONAL_EXTENSION_WILDCARD, ext));
            } else {
                uri.append(token.replace(OPTIONAL_EXTENSION_WILDCARD + '?', "")
                        .replace(OPTIONAL_EXTENSION_WILDCARD, ""));
            }

            continue;
        }
        if (token.endsWith("?")) {
            token = token.substring(0, token.length() - 1);
        }
        m = DOUBLE_WILDCARD_PATTERN.matcher(token);
        if (m.find()) {
            StringBuffer buf = new StringBuffer();
            do {
                ConstrainedProperty prop = constraints[paramIndex++];
                String propName = prop.getPropertyName();
                Object value = paramValues.get(propName);
                usedParams.add(propName);
                if (value == null && !prop.isNullable()) {
                    throw new UrlMappingException("Unable to create URL for mapping [" + this
                            + "] and parameters [" + paramValues + "]. Parameter [" + prop.getPropertyName()
                            + "] is required, but was not specified!");
                } else if (value == null) {
                    m.appendReplacement(buf, "");
                } else {
                    m.appendReplacement(buf, Matcher.quoteReplacement(value.toString()));
                }
            } while (m.find());

            m.appendTail(buf);

            try {
                String v = buf.toString();
                if (v.indexOf(SLASH) > -1 && CAPTURED_DOUBLE_WILDCARD.equals(token)) {
                    // individually URL encode path segments
                    if (v.startsWith(SLASH)) {
                        // get rid of leading slash
                        v = v.substring(SLASH.length());
                    }
                    String[] segs = v.split(SLASH);
                    for (String segment : segs) {
                        uri.append(SLASH).append(encode(segment, encoding));
                    }
                } else if (v.length() > 0) {
                    // original behavior
                    uri.append(SLASH).append(encode(v, encoding));
                } else {
                    // Stop processing tokens once we hit an empty one.
                    break;
                }
            } catch (UnsupportedEncodingException e) {
                throw new ControllerExecutionException("Error creating URL for parameters [" + paramValues
                        + "], problem encoding URL part [" + buf + "]: " + e.getMessage(), e);
            }
        } else {
            uri.append(SLASH).append(token);
        }
    }
    populateParameterList(paramValues, encoding, uri, usedParams);

    if (LOG.isDebugEnabled()) {
        LOG.debug("Created reverse URL mapping [" + uri.toString() + "] for parameters [" + paramValues + "]");
    }
    return uri.toString();
}

From source file:org.atomserver.utils.test.TestingAtomServer.java

private Server createServer(int port, String atomserverServletContext) {
    // set up the server and the atomserver web application context
    Server server = new Server(port);
    Context context = new Context(server, "/" + atomserverServletContext, true /*sessions*/,
            false /*no security*/);

    // we need to hard-code certain system properties to get the behavior we want here - we
    // will re-set them when we're done
    Properties properties = (Properties) System.getProperties().clone();
    System.setProperty("atomserver.env", "asdev-hsql-mem");
    System.setProperty("atomserver.servlet.context", atomserverServletContext);

    // TODO: this should be removed
    System.setProperty("atomserver.servlet.mapping", "v1");

    // our Spring application context will start off by loading the basic built-in bean
    // definitions
    appContext = new GenericWebApplicationContext();

    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(appContext);
    xmlReader.loadBeanDefinitions(new ClassPathResource("org/atomserver/spring/propertyConfigurerBeans.xml"));
    xmlReader.loadBeanDefinitions(new ClassPathResource("org/atomserver/spring/databaseBeans.xml"));
    xmlReader.loadBeanDefinitions(new ClassPathResource("org/atomserver/spring/logBeans.xml"));
    xmlReader.loadBeanDefinitions(new ClassPathResource("org/atomserver/spring/storageBeans.xml"));
    xmlReader.loadBeanDefinitions(new ClassPathResource("org/atomserver/spring/abderaBeans.xml"));

    // if we were given a Spring config location, we use that -- otherwise we configure the
    // workspaces that were set up through the API
    if (springBeansLocation != null) {
        xmlReader.loadBeanDefinitions(new ClassPathResource(springBeansLocation));
    } else {/*www  .j  av a 2s .  co  m*/
        RootBeanDefinition workspaces = new RootBeanDefinition(HashSet.class);
        ConstructorArgumentValues constructorArgumentValues = new ConstructorArgumentValues();
        constructorArgumentValues.addGenericArgumentValue(workspaceSet);
        workspaces.setConstructorArgumentValues(constructorArgumentValues);

        appContext.registerBeanDefinition("org.atomserver-workspaces", workspaces);
    }

    // override the base content storage to use DB-based storage
    RootBeanDefinition storage = new RootBeanDefinition(DBBasedContentStorage.class);
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.addPropertyValue("contentDAO", new RuntimeBeanReference("org.atomserver-contentDAO"));
    propertyValues.addPropertyValue("entriesDAO", new RuntimeBeanReference("org.atomserver-entriesDAO"));
    storage.setPropertyValues(propertyValues);
    appContext.registerBeanDefinition("org.atomserver-contentStorage", storage);

    // clear the existing ENV
    ConfigurationAwareClassLoader.invalidateENV();

    // refresh the context to actually instantiate everything.
    appContext.refresh();

    // re-set the system properties
    System.setProperties(properties);

    // clear the update ENV
    ConfigurationAwareClassLoader.invalidateENV();

    // put our app context into the servlet context
    context.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appContext);

    // load and init the service context for v1
    final ServiceContext serviceContext = (ServiceContext) appContext.getBean(ServiceContext.class.getName());
    serviceContext.init(new Abdera(), Collections.EMPTY_MAP);

    // create a new AtomServerServlet - but override the createServiceContext method
    AtomServerServlet servlet = new AtomServerServlet() {
        protected ServiceContext createServiceContext() {
            return serviceContext;
        }
    };

    // load and init the service context for v2
    final ServiceContext serviceContextV2 = (ServiceContext) appContext
            .getBean("org.atomserver-serviceContext.v2");
    serviceContextV2.init(new Abdera(), Collections.EMPTY_MAP);

    // create a new AtomServerServlet - but override the createServiceContext method
    AtomServerServlet servletV2 = new AtomServerServlet() {
        protected ServiceContext createServiceContext() {
            return serviceContextV2;
        }
    };

    // register the servlets
    context.addServlet(new ServletHolder(servlet), "/v1/*");
    context.addServlet(new ServletHolder(servletV2), "/v2/*");

    EntriesDAOiBatisImpl entriesDAO = (EntriesDAOiBatisImpl) appContext.getBean("org.atomserver-entriesDAO");
    entriesDAO.setUseWorkspaceCollectionCache(false);

    // ready to be started
    return server;
}

From source file:com.gemstone.gemfire.management.internal.cli.commands.ConfigCommandsDUnitTest.java

public void testAlterRuntimeConfig() throws ClassNotFoundException, IOException {
    final String controller = "controller";
    createDefaultSetup(null);//from www  . j  a  va2s .  c  om
    Properties localProps = new Properties();
    localProps.setProperty(DistributionConfig.NAME_NAME, controller);
    localProps.setProperty(DistributionConfig.LOG_LEVEL_NAME, "error");
    getSystem(localProps);
    final GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
    final DistributionConfig config = cache.getSystem().getConfig();
    CommandStringBuilder csb = new CommandStringBuilder(CliStrings.ALTER_RUNTIME_CONFIG);
    csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__MEMBER, controller);
    csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__LEVEL, "info");
    csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__FILE__SIZE__LIMIT, "50");
    csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__DISK__SPACE__LIMIT, "32");
    csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__FILE__SIZE__LIMIT, "49");
    csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLE__RATE, "2000");
    csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__ARCHIVE__FILE, "stat.gfs");
    csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLING__ENABLED, "true");
    csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__DISK__SPACE__LIMIT, "10");
    CommandResult cmdResult = executeCommand(csb.getCommandString());
    String resultString = commandResultToString(cmdResult);
    getLogWriter().info("Result\n");
    getLogWriter().info(resultString);
    assertEquals(true, cmdResult.getStatus().equals(Status.OK));
    assertEquals(LogWriterImpl.INFO_LEVEL, config.getLogLevel());
    assertEquals(50, config.getLogFileSizeLimit());
    assertEquals(32, config.getArchiveDiskSpaceLimit());
    assertEquals(2000, config.getStatisticSampleRate());
    assertEquals("stat.gfs", config.getStatisticArchiveFile().getName());
    assertEquals(true, config.getStatisticSamplingEnabled());
    assertEquals(10, config.getLogDiskSpaceLimit());

    CommandProcessor commandProcessor = new CommandProcessor();
    Result result = commandProcessor.createCommandStatement("alter runtime", Collections.EMPTY_MAP).process();
}

From source file:eu.openanalytics.rsb.RestJobsITCase.java

@Test
public void submitValidJobRequiringMetaWithoutMeta() throws Exception {
    final String applicationName = newTestApplicationName();
    @SuppressWarnings("unchecked")
    final Document resultDoc = doTestSubmitZipJob(applicationName, getTestData("r-job-meta-required.zip"),
            Collections.EMPTY_MAP);
    final String resultUri = getResultUri(resultDoc);
    ponderUntilOneResultAvailable(resultUri);
    retrieveAndValidateZipError(resultUri);
}