<commit_before>/*
 * Copyright (c) 2008-2016 Haulmont.
 *
 * 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 com.haulmont.cuba.core;

import com.haulmont.cuba.core.app.ConfigStorageService;
import com.haulmont.cuba.core.entity.EntitySnapshot;
import com.haulmont.cuba.core.entity.KeyValueEntity;
import com.haulmont.cuba.core.entity.Server;
import com.haulmont.cuba.core.global.*;
import com.haulmont.cuba.security.app.LoginWorker;
import com.haulmont.cuba.security.entity.*;
import com.haulmont.cuba.security.global.UserSession;
import com.haulmont.cuba.testsupport.TestContainer;
import com.haulmont.cuba.testsupport.TestSupport;
import com.haulmont.cuba.testsupport.TestUserSessionSource;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;

import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.UUID;

import static org.junit.Assert.*;

public class NonEntityQueryTest {

    @ClassRule
    public static TestContainer cont = TestContainer.Common.INSTANCE;

    private static final String USER_NAME_1 = "queryTestUser1";
    private static final String USER_NAME_2 = "queryTestUser2";
    private static final String USER_PASSWORD = "<PASSWORD>";

    private DataManager dataManager;
    private PasswordEncryption passwordEncryption;

    private UUID serverId, role1Id,
            permission1Id, permission2Id,
            user1Id, user2Id,
            group1Id, group2Id,
            constraint1Id, constraint2Id,
            userRole1Id,
            entitySnapshotId;

    @Before
    public void setUp() throws Exception {
        dataManager = AppBeans.get(DataManager.class);
        passwordEncryption = AppBeans.get(PasswordEncryption.class);

        Transaction tx = cont.persistence().createTransaction();
        try {
            EntityManager em = cont.persistence().getEntityManager();
            UserSessionSource uss = AppBeans.get(UserSessionSource.class);
            UserSession userSession = uss.getUserSession();

            Server server = new Server();
            server.setName("someServer");
            server.setRunning(false);
            serverId = server.getId();
            em.persist(server);

            EntitySnapshot entitySnapshot = new EntitySnapshot();
            entitySnapshot.setSnapshotDate(new Date());
            entitySnapshot.setAuthor(userSession.getCurrentOrSubstitutedUser());
            entitySnapshotId = entitySnapshot.getId();
            em.persist(entitySnapshot);<commit_msg>PL-8127 Queries with scalars and aggregates from the client side(fix tests)<commit_after>/*
 * Copyright (c) 2008-2016 Haulmont.
 *
 * 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 com.haulmont.cuba.core;

import com.haulmont.bali.db.QueryRunner;
import com.haulmont.cuba.core.app.ConfigStorageService;
import com.haulmont.cuba.core.entity.EntitySnapshot;
import com.haulmont.cuba.core.entity.KeyValueEntity;
import com.haulmont.cuba.core.entity.Server;
import com.haulmont.cuba.core.global.*;
import com.haulmont.cuba.security.app.LoginWorker;
import com.haulmont.cuba.security.entity.*;
import com.haulmont.cuba.security.global.UserSession;
import com.haulmont.cuba.testsupport.TestContainer;
import com.haulmont.cuba.testsupport.TestSupport;
import com.haulmont.cuba.testsupport.TestUserSessionSource;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;

import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.UUID;

import static org.junit.Assert.*;

public class NonEntityQueryTest {

    @ClassRule
    public static TestContainer cont = TestContainer.Common.INSTANCE;

    private static final String USER_NAME_1 = "queryTestUser1";
    private static final String USER_NAME_2 = "queryTestUser2";
    private static final String USER_PASSWORD = "<PASSWORD>";

    private DataManager dataManager;
    private PasswordEncryption passwordEncryption;

    private UUID serverId, role1Id,
            permission1Id, permission2Id,
            user1Id, user2Id,
            group1Id, group2Id,
            constraint1Id, constraint2Id,
            userRole1Id,
            entitySnapshotId;

    @Before
    public void setUp() throws Exception {
        dataManager = AppBeans.get(DataManager.class);
        passwordEncryption = AppBeans.get(PasswordEncryption.class);

        QueryRunner runner = new QueryRunner(cont.persistence().getDataSource());
        runner.update("delete from SYS_SERVER");

        Transaction tx = cont.persistence().createTransaction();
        try {
            EntityManager em = cont.persistence().getEntityManager();
            UserSessionSource uss = AppBeans.get(UserSessionSource.class);
            UserSession userSession = uss.getUserSession();

            Server server = new Server();
            server.setName("someServer");
            server.setRunning(false);
            serverId = server.getId();
            em.persist(server);

            EntitySnapshot entitySnapshot = new EntitySnapshot();
            entitySnapshot.setSnapshotDate(new Date());
            entitySnapshot.setAuthor(userSession.getCurrentOrSubstitutedUser());
            entitySnapshotId = entitySnapshot.getId();
            em.persist(entitySnapshot);
{'fraction_non_alphanumeric': 0.09006162110917997, 'fraction_numerical': 0.008848159266866804, 'mean_word_length': 3.451476793248945, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4554886', 'n_tokens_mistral': 1749, 'n_tokens_neox': 1697, 'n_words': 448}