// Path: airomem-direct/src/main/java/pl/setblack/airomem/direct/impl/PrevaylerRegister.java
// public final class PrevaylerRegister {
// 
//     private static final PrevaylerRegister INSTANCE = new PrevaylerRegister();
// 
//     private final ConcurrentHashMap<String, SimpleController> prevaylers = new ConcurrentHashMap<>();
// 
//     public static final PrevaylerRegister getInstance() {
//         return PrevaylerRegister.INSTANCE;
//     }
// 
//     public void clear() {
//         for (final SimpleController ctrl : this.prevaylers.values()) {
//             ctrl.close();
//         }
//         this.prevaylers.clear();
//     }
// 
//     public <T extends Serializable> SimpleController<T> getController(final Class<T> type, final String name) {
//         final String fullName = calcName(type, name);
//         final SimpleController<T> existing = this.prevaylers.get(fullName);
//         if (existing != null) {
//             return existing;
//         } else {
//             final SimpleController<T> newPrevayler = createController(type, name);
//             this.prevaylers.putIfAbsent(fullName, newPrevayler);
//             return this.prevaylers.get(fullName);
//         }
// 
//     }
// 
//     private <T extends Serializable> SimpleController<T> createController(Class<T> type, String name) {
//         SimpleController<T> controller = SimpleController.loadOptional(name, () -> createInitialState(type));
//         return controller;
//     }
// 
//     private <T extends Serializable> T createInitialState(Class<T> type) {
//         return Politician.beatAroundTheBush(() -> {
//             final Constructor<T> constr = type.getDeclaredConstructor();
//             return constr.newInstance();
//         });
//     }
// 
//     private static <T> String calcName(final Class<T> clazz, final String name) {
//         return clazz.getCanonicalName() + name;
//     }
// 
//     public void shut() {
//         for (final SimpleController ctrl : this.prevaylers.values()) {
//             ctrl.shut();
//         }
//         this.prevaylers.clear();
//     }
// }


import java.io.File;
import java.lang.reflect.Method;
import javax.inject.Inject;
import org.apache.commons.io.FileUtils;
import org.jglue.cdiunit.AdditionalClasses;
import org.jglue.cdiunit.CdiRunner;
import org.junit.After;
import org.junit.Assert;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import pl.setblack.airomem.core.builders.PersistenceFactory;
import pl.setblack.airomem.direct.impl.PrevaylerRegister;
import pl.setblack.badass.Politician;
/*
 *  Copyright (c) Jarek Ratajski, Licensed under the Apache License, Version 2.0
 *  http://www.apache.org/licenses/LICENSE-2.0
 */
package pl.setblack.airomem.direct;



/**
 *
 */
@RunWith(CdiRunner.class)
@AdditionalClasses(PersistenceInterceptor.class)
public class ContainerTest {

    @Inject
    SampleController controller;

    @Inject
    SampleController controller2;

    @Before @After
    public void clean() {
        PrevaylerRegister.getInstance().clear();
        Politician.beatAroundTheBush(() -> {
            FileUtils.deleteDirectory(new File(PersistenceFactory.STORAGE_FOLDER));
        });
        controller.getObject();//prefetch
    }

    @Test
    public void shouldRunMethodWithoutErrors() {


        controller.writeMethod();
    }

    @Test
    public void shouldRunGetMethodWithParamsWithoutErrors() {
        //GIVEN
        //WHEN
        controller.writeMethod();
// Path: airomem-direct/src/main/java/pl/setblack/airomem/direct/impl/PrevaylerRegister.java
// public final class PrevaylerRegister {
// 
//     private static final PrevaylerRegister INSTANCE = new PrevaylerRegister();
// 
//     private final ConcurrentHashMap<String, SimpleController> prevaylers = new ConcurrentHashMap<>();
// 
//     public static final PrevaylerRegister getInstance() {
//         return PrevaylerRegister.INSTANCE;
//     }
// 
//     public void clear() {
//         for (final SimpleController ctrl : this.prevaylers.values()) {
//             ctrl.close();
//         }
//         this.prevaylers.clear();
//     }
// 
//     public <T extends Serializable> SimpleController<T> getController(final Class<T> type, final String name) {
//         final String fullName = calcName(type, name);
//         final SimpleController<T> existing = this.prevaylers.get(fullName);
//         if (existing != null) {
//             return existing;
//         } else {
//             final SimpleController<T> newPrevayler = createController(type, name);
//             this.prevaylers.putIfAbsent(fullName, newPrevayler);
//             return this.prevaylers.get(fullName);
//         }
// 
//     }
// 
//     private <T extends Serializable> SimpleController<T> createController(Class<T> type, String name) {
//         SimpleController<T> controller = SimpleController.loadOptional(name, () -> createInitialState(type));
//         return controller;
//     }
// 
//     private <T extends Serializable> T createInitialState(Class<T> type) {
//         return Politician.beatAroundTheBush(() -> {
//             final Constructor<T> constr = type.getDeclaredConstructor();
//             return constr.newInstance();
//         });
//     }
// 
//     private static <T> String calcName(final Class<T> clazz, final String name) {
//         return clazz.getCanonicalName() + name;
//     }
// 
//     public void shut() {
//         for (final SimpleController ctrl : this.prevaylers.values()) {
//             ctrl.shut();
//         }
//         this.prevaylers.clear();
//     }
// }


// Path: airomem-direct/src/test/java/pl/setblack/airomem/direct/ContainerTest.java
import java.io.File;
import java.lang.reflect.Method;
import javax.inject.Inject;
import org.apache.commons.io.FileUtils;
import org.jglue.cdiunit.AdditionalClasses;
import org.jglue.cdiunit.CdiRunner;
import org.junit.After;
import org.junit.Assert;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import pl.setblack.airomem.core.builders.PersistenceFactory;
import pl.setblack.airomem.direct.impl.PrevaylerRegister;
import pl.setblack.badass.Politician;

/*
 *  Copyright (c) Jarek Ratajski, Licensed under the Apache License, Version 2.0
 *  http://www.apache.org/licenses/LICENSE-2.0
 */
package pl.setblack.airomem.direct;



/**
 *
 */
@RunWith(CdiRunner.class)
@AdditionalClasses(PersistenceInterceptor.class)
public class ContainerTest {

    @Inject
    SampleController controller;

    @Inject
    SampleController controller2;

    @Before @After
    public void clean() {
        PrevaylerRegister.getInstance().clear();
        Politician.beatAroundTheBush(() -> {
            FileUtils.deleteDirectory(new File(PersistenceFactory.STORAGE_FOLDER));
        });
        controller.getObject();//prefetch
    }

    @Test
    public void shouldRunMethodWithoutErrors() {


        controller.writeMethod();
    }

    @Test
    public void shouldRunGetMethodWithParamsWithoutErrors() {
        //GIVEN
        //WHEN
        controller.writeMethod();
        final String val = controller.readMethod(".fix");