<commit_before>/*
 * jPOS Project [http://jpos.org]
 * Copyright (C) 2000-2019 jPOS Software SRL
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.jpos.q2;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;

import java.io.File;

import javax.management.MBeanServer;
import javax.management.ObjectInstance;
import javax.management.ObjectName;

import org.jdom2.Document;
import org.jdom2.Element;
import org.jpos.q2.qbean.SystemMonitor;
import org.jpos.util.Log;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;


public class Q2Test {
    String[] m_args = new String[0];
    Q2 m_q2;

    @BeforeEach
    public void setUp() {
        m_q2 = new Q2(m_args);
    }

    @Test
    public void testAccept() throws Throwable {
        String[] args = new String[2];
        args[0] = "";
        args[1] = "";
        boolean result = new Q2(args).accept(new File("testQ2Param1"));
        assertFalse(result, "result");
    }

    @Test
    public void testAcceptThrowsNullPointerException() throws Throwable {
        String[] args = new String[1];
        args[0] = "";
        try {
            new Q2(args).accept(null);
            fail("Expected NullPointerException to be thrown");
        } catch (NullPointerException ex) {
            assertNull(ex.getMessage(), "ex.getMessage()");
        }
    }

    @Test
    public void testConstructor() throws Throwable {
        assertEquals("deploy", m_q2.getDeployDir().getName(), "m_q2.getDeployDir().getName()");
        assertSame(m_args, m_q2.getCommandLineArgs(), "m_q2.getCommandLineArgs()");
    }

    @Test
    public void testDecrypt() throws Throwable {
        String[] args = new String[2];
        args[0] = "testString";
        args[1] = "testString";
        m_q2 = new Q2(args);
        Document doc = mock(Document.class);
        Element element = mock(Element.class);
        given(doc.getRootElement()).willReturn(element);
        given(element.getName()).willReturn("testString");
        Document result = m_q2.decrypt(doc);
        assertSame(doc, result, "result");
    }

    @Test
    public void testDecryptThrowsIllegalStateException() throws Throwable {
        try {
            m_q2.decrypt(new Document());
            fail("Expected IllegalStateException to be thrown");
        } catch (IllegalStateException ex) {
            assertEquals("Root element not set", ex.getMessage(), "ex.getMessage()");
        }
    }

    @Test
    public void testDecryptThrowsNullPointerException() throws Throwable {
        String[] args = new String[1];
        args[0] = "testString";
        Q2 q2 = new Q2(args);
        try {
            q2.decrypt(null);
            fail("Expected NullPointerException to be thrown");
        } catch (NullPointerException ex) {
            assertNull(ex.getMessage(), "ex.getMessage()");
        }
    }

    @Disabled
    @Test
    public void testEncryptThrowsIllegalStateException() throws Throwable {
        try {
            m_q2.encrypt(new Document());
            fail("Expected IllegalStateException to be thrown");
        } catch (IllegalStateException ex) {
            assertEquals("Root element not set", ex.getMessage(), "ex.getMessage()");
        }
    }

    @Test
    public void testGetCommandLineArgs() throws Throwable {
        String[] args = new String[1];
        args[0] = "testString";
        String[] result = new Q2(args).getCommandLineArgs();
        assertSame(args, result, "result");
        assertEquals("testString", args[0], "m_args[0]");
    }

    @Test
    public void testGetDeployDir() throws Throwable {
        String[] args = new String[0];
        File result = new Q2(args).getDeployDir();
        assertEquals("deploy", result.getName(), "result.getName()");
    }

    @Test
    public void testGetFactory() throws Throwable {
        String[] args = new String[2];
        args[0] = "testString";
        args[1] = "testString";
        QFactory result = new Q2(args).getFactory();
        assertNull(result, "result");
    }

    @Test
    public void testGetKey() throws Throwable {
        String[] args = new String[2];
        args[0] = "testString";
        args[1] = "testString";
        Q2 q2 = new Q2(args);
        byte[] result = q2.getKey();
        assertEquals(8, result.length, "result.length");
        assertEquals((byte) 67, result[0], "result[0]");
    }

    @Test
    public void testGetLoader() throws Throwable {
        QClassLoader result = m_q2.getLoader();
        assertNull(result, "result");
    }

    @Test
    public void testGetLog() throws Throwable {
        Log result = m_q2.getLog();
        assertEquals("Q2.system", result.getRealm(), "result.getRealm()");
    }

    @Test
    public void testGetLog2() throws Throwable {
        String[] args = new String[2];
        args[0] = "testString";
        args[1] = "testString";
        m_q2 = new Q2(args);
        Log log = m_q2.getLog();
        Log result = m_q2.getLog();
        assertSame(log, result, "result");
    }

    @Test
    public void testGetMBeanServer() throws Throwable {
        String[] args = new String[0];
        MBeanServer result = new Q2(args).getMBeanServer();
        assertNull(result, "result");
    }

    @Test
    public void testQEntryConstructor() throws Throwable {<commit_msg>use single Q2 instance for all tests<commit_after>/*
 * jPOS Project [http://jpos.org]
 * Copyright (C) 2000-2019 jPOS Software SRL
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.jpos.q2;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;

import java.io.File;

import javax.management.MBeanServer;
import javax.management.ObjectInstance;
import javax.management.ObjectName;

import org.jdom2.Document;
import org.jdom2.Element;
import org.jpos.q2.qbean.SystemMonitor;
import org.jpos.util.Log;
import org.junit.jupiter.api.*;


@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class Q2Test {
    String[] m_args = new String[0];
    Q2 m_q2;

    @BeforeAll
    public void setUp() {
        m_q2 = new Q2(m_args);
    }

    @AfterAll
    public void tearDown() throws Exception {
        m_q2.shutdown(true);
    }

    @Test
    public void testAccept() throws Throwable {
        String[] args = new String[2];
        args[0] = "";
        args[1] = "";
        boolean result = new Q2(args).accept(new File("testQ2Param1"));
        assertFalse(result, "result");
    }

    @Test
    public void testAcceptThrowsNullPointerException() throws Throwable {
        String[] args = new String[1];
        args[0] = "";
        try {
            new Q2(args).accept(null);
            fail("Expected NullPointerException to be thrown");
        } catch (NullPointerException ex) {
            assertNull(ex.getMessage(), "ex.getMessage()");
        }
    }

    @Test
    public void testConstructor() throws Throwable {
        assertEquals("deploy", m_q2.getDeployDir().getName(), "m_q2.getDeployDir().getName()");
        assertSame(m_args, m_q2.getCommandLineArgs(), "m_q2.getCommandLineArgs()");
    }

    @Test
    public void testDecrypt() throws Throwable {
        String[] args = new String[2];
        args[0] = "testString";
        args[1] = "testString";
        Q2 m_q2 = new Q2(args);
        Document doc = mock(Document.class);
        Element element = mock(Element.class);
        given(doc.getRootElement()).willReturn(element);
        given(element.getName()).willReturn("testString");
        Document result = m_q2.decrypt(doc);
        assertSame(doc, result, "result");
    }

    @Test
    public void testDecryptThrowsIllegalStateException() throws Throwable {
        try {
            m_q2.decrypt(new Document());
            fail("Expected IllegalStateException to be thrown");
        } catch (IllegalStateException ex) {
            assertEquals("Root element not set", ex.getMessage(), "ex.getMessage()");
        }
    }

    @Test
    public void testDecryptThrowsNullPointerException() throws Throwable {
        String[] args = new String[1];
        args[0] = "testString";
        Q2 q2 = new Q2(args);
        try {
            q2.decrypt(null);
            fail("Expected NullPointerException to be thrown");
        } catch (NullPointerException ex) {
            assertNull(ex.getMessage(), "ex.getMessage()");
        }
    }

    @Disabled
    @Test
    public void testEncryptThrowsIllegalStateException() throws Throwable {
        try {
            m_q2.encrypt(new Document());
            fail("Expected IllegalStateException to be thrown");
        } catch (IllegalStateException ex) {
            assertEquals("Root element not set", ex.getMessage(), "ex.getMessage()");
        }
    }

    @Test
    public void testGetCommandLineArgs() throws Throwable {
        String[] args = new String[1];
        args[0] = "testString";
        String[] result = new Q2(args).getCommandLineArgs();
        assertSame(args, result, "result");
        assertEquals("testString", args[0], "m_args[0]");
    }

    @Test
    public void testGetDeployDir() throws Throwable {
        String[] args = new String[0];
        File result = new Q2(args).getDeployDir();
        assertEquals("deploy", result.getName(), "result.getName()");
    }

    @Test
    public void testGetFactory() throws Throwable {
        String[] args = new String[2];
        args[0] = "testString";
        args[1] = "testString";
        QFactory result = new Q2(args).getFactory();
        assertNull(result, "result");
    }

    @Test
    public void testGetKey() throws Throwable {
        String[] args = new String[2];
        args[0] = "testString";
        args[1] = "testString";
        Q2 q2 = new Q2(args);
        byte[] result = q2.getKey();
        assertEquals(8, result.length, "result.length");
        assertEquals((byte) 67, result[0], "result[0]");
    }

    @Test
    public void testGetLoader() throws Throwable {
        QClassLoader result = m_q2.getLoader();
        assertNull(result, "result");
    }

    @Test
    public void testGetLog() throws Throwable {
        Log result = m_q2.getLog();
        assertEquals("Q2.system", result.getRealm(), "result.getRealm()");
    }

    @Test
    public void testGetLog2() throws Throwable {
        String[] args = new String[2];
        args[0] = "testString";
        args[1] = "testString";
        Q2 q2 = new Q2(args);
        Log log = q2.getLog();
        Log result = q2.getLog();
        assertSame(log, result, "result");
    }

    @Test
    public void testGetMBeanServer() throws Throwable {
        String[] args = new String[0];
        MBeanServer result = new Q2(args).getMBeanServer();
        assertNull(result, "result");
    }

    @Test
    public void testQEntryConstructor() throws Throwable {
{'fraction_non_alphanumeric': 0.11935055811412068, 'fraction_numerical': 0.013113730387947857, 'mean_word_length': 2.7693439246837306, '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': '6529128', 'n_tokens_mistral': 3771, 'n_tokens_neox': 3725, 'n_words': 1002}