Search in sources :

Example 1 with SessionImpl

use of com.haulmont.chile.core.model.impl.SessionImpl in project cuba by cuba-platform.

the class BaseGenericIdEntityTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    dynamicAttributes = new DynamicAttributes() {

        @Override
        public Collection<Category> getCategoriesForMetaClass(MetaClass metaClass) {
            return null;
        }

        @Override
        public Collection<CategoryAttribute> getAttributesForMetaClass(MetaClass metaClass) {
            return null;
        }

        @Nullable
        @Override
        public CategoryAttribute getAttributeForMetaClass(MetaClass metaClass, String code) {
            CategoryAttribute categoryAttribute = new CategoryAttribute();
            categoryAttribute.setCode(code);
            return categoryAttribute;
        }
    };
    metadata = new Metadata() {

        @Override
        public Session getSession() {
            return new SessionImpl() {

                @Override
                public MetaClass getClassNN(String name) {
                    return new MetaClassImpl(new MetaModelImpl(this, name), name);
                }

                @Override
                public MetaClass getClassNN(Class clazz) {
                    return new MetaClassImpl(new MetaModelImpl(this, clazz.getName()), clazz.getName());
                }
            };
        }

        @Override
        public ViewRepository getViewRepository() {
            return null;
        }

        @Override
        public ExtendedEntities getExtendedEntities() {
            return null;
        }

        @Override
        public MetadataTools getTools() {
            return null;
        }

        @Override
        public DatatypeRegistry getDatatypes() {
            return null;
        }

        @Override
        public <T extends Entity> T create(Class<T> entityClass) {
            if (User.class.equals(entityClass)) {
                return (T) new User();
            }
            if (CategoryAttributeValue.class.equals(entityClass)) {
                CategoryAttributeValue attributeValue = new CategoryAttributeValue();
                attributeValue.setEntity(new ReferenceToEntity());
                return (T) attributeValue;
            }
            throw new IllegalArgumentException("Add support for " + entityClass.getSimpleName() + " to Mock");
        }

        @Override
        public Entity create(MetaClass metaClass) {
            return null;
        }

        @Override
        public Entity create(String entityName) {
            return null;
        }

        @Override
        public List<String> getRootPackages() {
            return null;
        }

        @Override
        public MetaModel getModel(String name) {
            return null;
        }

        @Override
        public Collection<MetaModel> getModels() {
            return null;
        }

        @Nullable
        @Override
        public MetaClass getClass(String name) {
            return null;
        }

        @Override
        public MetaClass getClassNN(String name) {
            return null;
        }

        @Nullable
        @Override
        public MetaClass getClass(Class<?> clazz) {
            return null;
        }

        @Override
        public MetaClass getClassNN(Class<?> clazz) {
            return null;
        }

        @Override
        public Collection<MetaClass> getClasses() {
            return null;
        }
    };
    new Expectations() {

        {
            AppBeans.get(DynamicAttributes.NAME);
            result = dynamicAttributes;
            minTimes = 0;
            AppBeans.get(Metadata.NAME);
            result = metadata;
            minTimes = 0;
            AppBeans.get(ReferenceToEntitySupport.class);
            result = referenceToEntitySupport;
            minTimes = 0;
        }
    };
}
Also used : User(com.haulmont.cuba.security.entity.User) MetaModelImpl(com.haulmont.chile.core.model.impl.MetaModelImpl) DatatypeRegistry(com.haulmont.chile.core.datatypes.DatatypeRegistry) List(java.util.List) MetaClassImpl(com.haulmont.chile.core.model.impl.MetaClassImpl) Expectations(mockit.Expectations) DynamicAttributes(com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributes) MetaModel(com.haulmont.chile.core.model.MetaModel) MetaClass(com.haulmont.chile.core.model.MetaClass) Collection(java.util.Collection) MetaClass(com.haulmont.chile.core.model.MetaClass) SessionImpl(com.haulmont.chile.core.model.impl.SessionImpl) Nullable(javax.annotation.Nullable) Session(com.haulmont.chile.core.model.Session) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

DatatypeRegistry (com.haulmont.chile.core.datatypes.DatatypeRegistry)1 MetaClass (com.haulmont.chile.core.model.MetaClass)1 MetaModel (com.haulmont.chile.core.model.MetaModel)1 Session (com.haulmont.chile.core.model.Session)1 MetaClassImpl (com.haulmont.chile.core.model.impl.MetaClassImpl)1 MetaModelImpl (com.haulmont.chile.core.model.impl.MetaModelImpl)1 SessionImpl (com.haulmont.chile.core.model.impl.SessionImpl)1 DynamicAttributes (com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributes)1 User (com.haulmont.cuba.security.entity.User)1 Collection (java.util.Collection)1 List (java.util.List)1 Nullable (javax.annotation.Nullable)1 Expectations (mockit.Expectations)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1