Search in sources :

Example 1 with VariableResolver

use of org.apache.sling.provisioning.model.ModelUtility.VariableResolver in project sling by apache.

the class ModelResolveUtilityReplaceTest method testOneResolver.

@Test
public void testOneResolver() {
    VariableResolver resolver = new VariableResolver() {

        @Override
        public String resolve(Feature feature, String name) {
            return name.toUpperCase();
        }
    };
    assertEquals("one VAR1 variable", replace(TEST_FEATURE, "one ${var1} variable", resolver));
    assertEquals("VAR1 one variable", replace(TEST_FEATURE, "${var1} one variable", resolver));
    assertEquals("VAR1 one variable VAR2", replace(TEST_FEATURE, "${var1} one variable ${var2}", resolver));
}
Also used : VariableResolver(org.apache.sling.provisioning.model.ModelUtility.VariableResolver) Test(org.junit.Test)

Example 2 with VariableResolver

use of org.apache.sling.provisioning.model.ModelUtility.VariableResolver in project sling by apache.

the class ModelUtilityApplyVariablesTest method setUp.

@Before
public void setUp() {
    testModel = new Model();
    Feature feature = testModel.getOrCreateFeature("feature1");
    feature.getVariables().put("param1", "v1");
    feature.getVariables().put("extparam2", "v2");
    RunMode runMode = feature.getOrCreateRunMode(new String[] { "rm1" });
    ArtifactGroup group = runMode.getOrCreateArtifactGroup(10);
    group.add(new Artifact("g1", "a1", "${param1}", "c1", "t1"));
    group.add(new Artifact("g2", "a2", "${extparam2}", null, null));
    Configuration conf = runMode.getOrCreateConfiguration("pid1", null);
    conf.getProperties().put(ModelConstants.CFG_UNPROCESSED, "conf1=\"${extparam1}\"\n" + "conf2=\"${extparam2}\"");
    runMode.getSettings().put("set1", "${param1}");
    // dummy variable resolver that simulates external resolving of some variables
    testVariableResolver = new VariableResolver() {

        @Override
        public String resolve(Feature feature, String name) {
            if ("extparam1".equals(name)) {
                return "extvalue1";
            }
            if ("extparam2".equals(name)) {
                return "extvalue2";
            }
            return feature.getVariables().get(name);
        }
    };
}
Also used : VariableResolver(org.apache.sling.provisioning.model.ModelUtility.VariableResolver) Before(org.junit.Before)

Example 3 with VariableResolver

use of org.apache.sling.provisioning.model.ModelUtility.VariableResolver in project sling by apache.

the class CustomResolverTest method testCustomVariableResolverNoFilter.

@Test
public void testCustomVariableResolverNoFilter() throws Exception {
    final Model m = U.readCompleteTestModel();
    final VariableResolver r = new CustomVariableResolver();
    final Model effective = ModelUtility.getEffectiveModel(m, new ResolverOptions().variableResolver(r));
    final ArtifactGroup g = U.getGroup(effective, "example", "jackrabbit", 15);
    U.assertArtifact(g, "mvn:org.apache.sling/org.apache.sling.jcr.jackrabbit.server/#example#jackrabbit.version#/jar");
}
Also used : VariableResolver(org.apache.sling.provisioning.model.ModelUtility.VariableResolver) ResolverOptions(org.apache.sling.provisioning.model.ModelUtility.ResolverOptions) Test(org.junit.Test)

Aggregations

VariableResolver (org.apache.sling.provisioning.model.ModelUtility.VariableResolver)3 Test (org.junit.Test)2 ResolverOptions (org.apache.sling.provisioning.model.ModelUtility.ResolverOptions)1 Before (org.junit.Before)1