All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.deephacks.tools4j.config.test.ConfigDefaultSetup Maven / Gradle / Ivy

There is a newer version: 0.15.0
Show newest version
/**
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.deephacks.tools4j.config.test;

import com.google.common.collect.ImmutableList;
import org.deephacks.tools4j.config.RuntimeContext;
import org.deephacks.tools4j.config.admin.AdminContext;
import org.deephacks.tools4j.config.model.Bean;
import org.deephacks.tools4j.config.model.Lookup;
import org.deephacks.tools4j.config.test.ConfigTestData.*;

import java.util.Collection;

import static org.deephacks.tools4j.config.test.ConfigTestData.*;
import static org.deephacks.tools4j.config.test.ConversionUtils.toBeans;

public abstract class ConfigDefaultSetup {
    protected RuntimeContext runtime;
    protected AdminContext admin;
    protected Child c1;
    protected Child c2;
    protected Parent p1;
    protected Parent p2;
    protected Grandfather g1;
    protected Grandfather g2;
    protected SingletonParent sp1;
    protected Singleton s1;
    protected JSR303Validation jsr303;
    protected static Collection defaultBeans;

    protected void setupDefaultConfigData() {

        if (runtime == null) {
            runtime = Lookup.get().lookup(RuntimeContext.class);
        }

        if (admin == null) {
            admin = Lookup.get().lookup(AdminContext.class);
        }
        sp1 = getSingletonParent("sp1");
        s1 = getSingleton();

        c1 = getChild("c1");
        c2 = getChild("c2");

        p1 = getParent("p1");
        p1.add(c2, c1);
        p1.set(c1);
        p1.put(c1);
        p1.put(c2);

        p2 = getParent("p2");
        p2.add(c1, c2);
        p2.set(c2);
        p2.put(c1);
        p2.put(c2);

        g1 = getGrandfather("g1");
        g1.add(p1, p2);

        g2 = getGrandfather("g2");
        g2.add(p1, p2);
        g2.put(p1);

        jsr303 = getJSR303Validation("jsr303");

        runtime.register(Grandfather.class, Parent.class, Child.class, Singleton.class,
                SingletonParent.class, JSR303Validation.class);
        if (defaultBeans == null) {
            // toBeans steals quite a bit of performance when having larger hierarchies.
            defaultBeans = ImmutableList.copyOf(toBeans(c1, c2, p1, p2, g1, g2));
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy