Sunday, May 31, 2020

Installation of Docker in Fedora

Hi,

In this post I am going to talk about how to install docker in fedora.

the least software/tool required is the terminal.

Let us now install docker in fedora....

Installing docker
Open a terminal and provide the command given below at the prompt...

> sudo dnf install docker
the package installer tool would display the packages to be installed and would wait for your confirmation as given in the picture given below...


press Y/y to proceed....

The package installer would now install the packages, if the installation is successful the package installer would show you the result as the one given below.



Now is the time to check the status of the docker installed...

Checking the status of the docker process
provide the command below to know the status of the docker process...

> sudo systemctl status docker
we have just installed the docker and would have the status as given in the picture below....


Enabling the docker process
In order to enable the docker, fire the below command at the prompt

> sudo systemctl enable docker
the above command would make the docker up and running at the start of the system every time...

Starting the docker process
In order to start the docker, provide the command mentioned below...

> sudo systemctl start docker
the above command would have the docker process up and running...

To view the details of the running docker process, proivde the command given below at the prompt...

> sudo systemctl status docker
and the result would be...



Well that is it, this concludes this post....

Hope you had great time reading...

Thanks/

Saturday, May 16, 2020

Liferay Aquillian Extension : Jacoco Report - Code Coverage Report

Hi,

In this post I am going to discuss about taking code coverage report for the integration and functional test the we have seen in the posts mentioned below...

1. Liferay Arquillian Extension : Integration Testing 
2. Liferay Arquillian Extension : Functional Testing 

Prerequisites
Name Version Download Page Direct Link
Java 1.8 Java Download Page N/A
Mysql 8.0.20 N/A N/A
Liferay Portal 7.3.0 - CE Lifeay Portal Download Page Click to Download Directly
IntelliJ IDE 2019.3.5 N/A N/A

My request to you is to go through the posts which talk about Integration and Functional test prior to this.

Those two posts mentioned above talks the configuration details or the fundamentals for having Code Coverage Report using Jacoco (Java Code Coverage)

Lets talk business...

To incorporate the code coverage report for the liferay plugins that we develop.... we must update the build.gradle file associated with the plugin...

Updating build.gradle of the plugin/bundle
Open the build.gradle file associated with the plugin hello-world and modify the file accordingly, the different sections involved would be given below for you to refer...

1. Java Imports
import javax.management.remote.JMXConnectorFactory
import javax.management.remote.JMXServiceURL

2. Adding Jacoco Plugin
apply plugin: 'jacoco'

jacoco {
toolVersion = '0.7.9'
}

3. Creating copyJacocoAgent task
task copyJacocoAgent(type: Copy) {
println configurations.jacocoAgent

configurations.jacocoAgent.asFileTree.each {
from(zipTree(it))
}

into "${rootDir}/build/jacoco"
}

4. Creating dumpJacoco task
task dumpJacoco {
doLast {
def serverUrl = 'service:jmx:rmi:///jndi/rmi://localhost:8099/jmxrmi'
String beanName = "org.jacoco:type=Runtime"
        def jmxServiceUrl = new JMXServiceURL(serverUrl)
def server = JMXConnectorFactory.connect(new JMXConnectorFactory(jmxServiceUrl)).MBeanServerConnection
def gmxb = new GroovyMBean(server, beanName)

println "Connected to:\n$gmxb\n"
println "Executing dump()"
gmxb.dump(true)
}
}

5. Creating jacocoTestReport closure
jacocoTestReport {
dependsOn dumpJacoco
group = "Reporting"
reports {
xml.enabled true
csv.enabled false
//html.destination "${buildDir}/reports/coverage"
}
executionData = files("${rootDir}/build/jacoco/testIntegration.exec")
}

Updating setenv.sh of Tomcat Container
Open up setenv.sh file of the tomcat which you can find under bundles/tomcat-9.0.17/bin and modify the file with the following conent...

JACOCO_OPTS="-javaagent:/home/ravaneswaran/projects/liferay-arquillian-example/bundles/tomcat-9.0.17/bin/jacocoagent.jar"
CATALINA_OPTS="${CATALINA_OPTS} ${JACOCO_OPTS}"

the path of the jacocoagent.jar is very important which will be referred by the testIntegration task of the gradle to prepare the code coverage report...

After the update the setenv.sh file should appear something like the one given in the image below...



Copying the jacocoagent.jar file to tomcat bin directory
You can download the jar online or else you can perform a search in IntelliJ installed directory to get the jar file...

A sample search is given below for your reference...



Now copy and paste the file in tomcat's bin directory...

It is not mandatory to have the file in tomcat's bin directory but the path where you have the jacocoagent.jar should be mentioned in setenv.sh

With this we have completed the configuration to have jacoco code coverage report...

Running testIntegration command
Now run the testIntegration command to have the tests executed...

The result of the execution would be like the one shown below...



You can find the generated report under the folder build/reports/test/testIntegration of the plugin.

Refer the image below for details....



Open index.html file in your favourite browser to see the test summary...


Well this concludes the post and hope you had great time learning.

Would like to hear from you about this post, please do comment.

Thanks.

Friday, May 15, 2020

Liferay Arquillian Extension : Functional Testing

Hi,

In this post I am going to discuss about how to use arquillian extension to perform functional testing on liferay plugins...

The following sections details the softwares used...

Prerequisites
Name Version Download Page Direct Link
Java 1.8 Java Download Page N/A
Mysql 8.0.20 N/A N/A
Liferay Portal 7.3.0 - CE Lifeay Portal Download Page Click to Download Directly
IntelliJ IDE 2019.3.5 N/A N/A

Before you proceed incorporating the functional testing for your plugins, I would recommend and it is must to go through an other post of mine for the configurations. The link to the post is given below....

Liferay Arquillian Extension : Integration Testing

Updating build.gradle of the plugin
Open up the build.gradle of the plugin and append the following in dependency closure...

testIntegrationCompile group: 'org.jboss.arquillian.graphene', name: 'graphene-webdriver', version: '2.3.2'

once done the complete build.gradle of the plugin should look something like the one given below..


Updating view.jsp...
Open view.jsp,  which you can find under the folder src/main/resources/META_INF/resources and paste the following contents in it...

<%@ include file="/init.jsp" %>

<div id="01">
    <liferay-ui:message key="helloworld.caption"/>
</div>

Creating Functional Test Class...
Create a test class called HelloWorldFunctionalTest.java under src/testIntegration/java folder and update the file with the following content...

import com.helloworld.test.HelloWorldTestHelper;
import com.liferay.arquillian.portal.annotation.PortalURL;
import com.liferay.portal.kernel.exception.PortalException;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.drone.api.annotation.Drone;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

@RunAsClient
@RunWith(Arquillian.class)
public class HelloWorldFunctionalTest{

    @Deployment
    public static JavaArchive create() throws Exception {
        final File tempDir = HelloWorldTestHelper.createTempDir();

        String gradlew = "../../gradlew";

        String osName = System.getProperty("os.name", "");
        if (osName.toLowerCase().contains("windows")) {
            gradlew = "../../gradlew.bat";
        }

        final ProcessBuilder processBuilder = new ProcessBuilder(
                gradlew, "jar", "-Pdir=" + tempDir.getAbsolutePath());
        final Process process = processBuilder.start();
        process.waitFor();

        Path jarFilePath = Paths.get("build/libs/com.helloworld-1.0.0.jar");
        Files.copy(jarFilePath, new FileOutputStream(
                tempDir.getAbsolutePath() +
                        "/com.helloworld-1.0.0.jar"));

        final File jarFile = new File(
                tempDir.getAbsolutePath() +
                        "/com.helloworld-1.0.0.jar");

        return ShrinkWrap.createFromZipFile(JavaArchive.class, jarFile);
    }

    @Test
    public void testGreetTheWorld() throws IOException, PortalException {
        _browser.get(_portalURL.toExternalForm());
        Assert.assertEquals("Hello from HelloWorld!", _result.getText());
    }

    @FindBy(id = "01")
    private WebElement _result;

    @PortalURL("com_helloworld_HelloWorldPortlet")
    private URL _portalURL;

    @Drone
    private WebDriver _browser;

}

Let us discuss some of the key points from the code given above....
1. _browser: Arquillian annotation @Drone sets this field as a Selenium WebDriver (browser)
2. _portalURL: Liferay Arquillian annotation @PortalURL assigns the portlet’s URL to this field.
the string parameter that the annotation @PortalURL takes is the id of the portlet HelloWorldPortlet
3. _result : JavaScript selectors and Selenium annotation @FindBy to map the field.

With that the configuration and the code part of the functional testing is completed....

Now run the gradle command testIntegration to have the results....

Once the command execution is completed, you would the test results something like the one in the image given below...



This concludes the functional testing of liferay plugins...

Hope you enjoyed it.

Thanks.

Wednesday, May 13, 2020

Liferay Arquillian Extension : Integration Testing

Hi,

In this post I am going to discuss about how to use arquillian extension to perform integration testing on liferay plugins...

The following sections details the softwares used...

Prerequisites
Name Version Download Page Direct Link
Java 1.8 Java Download Page N/A
Mysql 8.0.20 N/A N/A
Liferay Portal 7.3.0 - CE Lifeay Portal Download Page Click to Download Directly
IntelliJ IDE 2019.3.5 N/A N/A

The environment where the above mentioned softwares were installed had fedora as operating system but the procedure that I am going to detail here is not restricted to any particular operating system and also I am not going to discuss the installation of above mentioned softwares here in this post.

Ok now let me detail the procedure...

Creating a Liferay Project using Intellij IDE
Open up your IntelliJ IDE and create a project as given in the image below...




Once the project is created, you would have the layout of the project as given in the image below...


Creating a mvc portlet
Create a simple mvc portlet as directed by the images below...





Once the portlet is created the project layout should look something like the image given below...



Creating testIntegration folder
Expand the portlet we have just created and create a folder called testIntegration under src folder, to have a reference use the image below...



Please make a note of creating the resources folder under src/testIntegration/

Updating build.gradle of the plugin
Open up the build.gradle of the plugin and append the following in dependency closure...

testIntegrationCompile group: "com.liferay.arquillian", name: "com.liferay.arquillian.arquillian-container-liferay", version: "1.0.6"
testIntegrationCompile group: "junit", name: "junit", version: "4.12"
testIntegrationCompile group: "org.jboss.arquillian.junit", name: "arquillian-junit-container", version: "1.1.11.Final"

once done the complete build.gradle of the plugin should look something like the one given below..


Creating service classes
for our discussion, I have created two class files under src/main/java/

1. HelloWorldService.java an interface
2. HelloWorldServiceImpl.java an implementation of HelloWorldService.java

public interface HelloWorldService {

    public String greetTheWorld();

}

import org.osgi.service.component.annotations.Component;

@Component(immediate = true, service = HelloWorldService.class)
public class HelloWorldServiceImpl implements HelloWorldService {

    @Override
    public String greetTheWorld() {
        return "Hello World";
    }

}

Creating arquillian.xml file
Under the testIntegration/resources folder create a xml file called arquillian.xml and paste the contents given below...

<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://jboss.org/schema/arquillian"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">

    <engine>
        <property name="deploymentExportPath">build/deployments</property>
    </engine>

</arquillian>

Creating Integration Test classes
Under testIntegration/java create a Integration test class to the service the service we have implemented...

import com.helloworld.service.HelloWorldService;
import com.helloworld.test.HelloWorldTestHelper;
import com.liferay.arquillian.containter.remote.enricher.Inject;
import com.liferay.portal.kernel.exception.PortalException;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(Arquillian.class)
public class HelloWorldIntegrationTest {

    @Deployment
    public static JavaArchive create() throws Exception {
        final File tempDir = HelloWorldTestHelper.createTempDir();

        String gradlew = "../../gradlew";

        String osName = System.getProperty("os.name", "");
        if (osName.toLowerCase().contains("windows")) {
            gradlew = "../../gradlew.bat";
        }

        final ProcessBuilder processBuilder = new ProcessBuilder(
                gradlew, "jar", "-Pdir=" + tempDir.getAbsolutePath());
        final Process process = processBuilder.start();
        process.waitFor();

        Path jarFilePath = Paths.get("build/libs/com.helloworld-1.0.0.jar");
        Files.copy(jarFilePath, new FileOutputStream(
                tempDir.getAbsolutePath() +
                        "/com.helloworld-1.0.0.jar"));

        final File jarFile = new File(
                tempDir.getAbsolutePath() +
                        "/com.helloworld-1.0.0.jar");

        return ShrinkWrap.createFromZipFile(JavaArchive.class, jarFile);
    }

    @Test
    public void testGreetTheWorld() throws IOException, PortalException {
        final String result = _helloWorldService.greetTheWorld();

        Assert.assertEquals("Hello World", result);
    }

    @Inject
    private HelloWorldService _helloWorldService;

}

import java.io.File;

public class HelloWorldTestHelper {

    private static final int TEMP_DIR_ATTEMPTS = 10000;

    public  static File createTempDir() {
        File baseDir = new File(System.getProperty("java.io.tmpdir"));
        String baseName = System.currentTimeMillis() + "-";

        for (int counter = 0; counter < TEMP_DIR_ATTEMPTS; counter++) {
            File tempDir = new File(baseDir, baseName + counter);
            if (tempDir.mkdir()) {
                return tempDir;
            }
        }
        throw new IllegalStateException("Failed to create directory within "
                + TEMP_DIR_ATTEMPTS + " attempts (tried "
                + baseName + "0 to " + baseName + (TEMP_DIR_ATTEMPTS - 1) + ')');
    }
}

We all set now to execute the testIntegration command....

Executing testIntegration command
From you IDE, select the Gradle tab and fire the command testIntegration  as given in the image below...



the above command execution would automatically pull the liferay portal and dump it under the folder bundles folder of the project, the bundles folder would be created by the testIntegraton command, the folder can be viewed as given in the image below...



the result of the testIntegration command would appear something like the one given in the image below...



Do not be panic this is the result of missing JMX configuration that we have to set in the tomcat container....

Setting JMX Configuration in Tomcat Conatiner
Open the file setevn.sh under bundles/tomcat-9.0.17/bin and append the file with the following content

JMX_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=8099 -Dcom.sun.management.jmxremote.ssl=false"

CATALINA_OPTS="${CATALINA_OPTS} ${JMX_OPTS}"

soon after you update the setenv.sh file the entire file should appear something like the one mentioned in the image given below...


Updating portal-ext.properties
Open up portal-ext.properties file under bundles/portal-ext.properties and modify the properties as given...

include-and-override=portal-developer.properties

#
# MySQL
#
jdbc.default.driverClassName=com.mysql.cj.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=root
jdbc.default.password=admin

Run the testIntegration command again, if everything goes well fine else you would end in an error as said in the image below...



The above error is due to the installation of the plugin by the previous testIntegration command run...

Just delete the plugin which you find under the folder bundles/osgi/modules



rerun the testIntegration command again...

Now you should have your test executed and results success....



Hurray, we have successfully configured and executed the integration test.... well this concludes the post

Hope you had great learning....

Let me have your comments in the comments section about your try....

Thanks.



Tuesday, May 5, 2020

Changing the password of the root user of mysql in FEDORA

Hi all, In this post we are going to see how to reset the password of root user in mysql

As we all know the root user of mysql is something like the root user of linux with full power to access anything in MySql database server.

Normally during the install, the installation would ask for password to set for the root user but there are occasions where as administrator or developer would pushed to reset the password.

This post talks about resetting the password in a precise manner.

This post assumes that you already have a valid MySql Server instance up and running and I am going to use the command line tool i.e the Terminal for connecting to the server and resetting the password.

Let's start it...

Open a terminal and check whether the MySql server is up and running....
> sudo systemctl status mysql
In my case I had the following response on the terminal



If the server is up and running, then you would have something like given below...



Stop the Server(MySql Server) using the command given below
> sudo systemctl stop mysql
Now we have the server stopped.

We have to start the MySql Server differently to have the passord reset for the user root, to do that you must edit my.cnf file located in /etc folder...

Now open my.cnf file in your favourite editor and try to locate the group [mysqld], you can use the picture below to locate...



At the top of the group or just below the line which contains the content [mysqld]
add the line as said below
skip-grant-tables
Now the configuration file should appear something like the one shown below...



Save the file and exit from the text editor

Now try to start the server using the terminal as given below...
> sudo systemctl start mysql
Check the status of the mysql process
> sudo systemctl status mysql
you should have something like given below...



Connect to mysql server from the command using the command "mysql"
> mysql --user=root
Now you should be connected to the server and what you see on the server is the response connected to the server without the password for the user "root"



Change the password of the user "root" using the statements given below...

mysql> flush privileges;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';

Now stop the server and revert back the changes that we made in my.cnf file and start the server...

Connect to the server now using the password switch..
> mysql --user=root --password
Which would ask you to provide the password, provide the one you updated the user with, now you have successfully changed the password of the user "root"



Hope you enjoyed the post, feel free to post your comments...

Thanks.

MySQL - ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

Hi all,

In this post we are going to discuss the error mentioned in the post heading line....

I was trying to alter the password of an user in mysql server and the password was something like "testing", the mysql server was not allowing me to change the password as metioned rather throwing an error mentioned in the post headline.

this post will help you to overcome this situation if you follow the steps detailed below...

Keep in mind. this should not be performed where you should not be compromising security but for your local database server and other environments where security is not a high priority, then go ahead and try it out.
The environment where I have tried this has fedora as operating system and mysql 8.0.x as the database server. The procedure is more or less similar for other environments as well...

Lets talk business now...

The default password policy in mysql server is defined as given in the image below


the above details can be retrieved using the mysql command given below....

mysql> SHOW VARIABLES LIKE 'validate_password%';

In order to have a simple and plain password for any user, we should execute set of mysql commands as given below...

mysql> SET GLOBAL validate_password.policy=LOW;
mysql> SET GLOBAL validate_password.length=5;
mysql> SET GLOBAL validate_password.mixed_case_count=0;
mysql> SET GLOBAL validate_password.number_count=0;
mysql> SET GLOBAL validate_password.special_char_count=0;

the above commands are self explanatory and the execution of the above commands would change password policy settings for the current session.

After having the settings changed you can confirm the same by firing the command below...

mysql> SHOW VARIABLES LIKE 'validate_password%';

 
Now you can try the following command on the user to whom you want to change the password as something like given below...

mysql > ALTER USER 'testuser'@'localhost' IDENTIFIED BY 'testing';

this would change the password of the user.

The settings that we changed is for the current session only meaning once you have logged out or exited from the mysql server the new settings would be lost and the default settings would be retained

Well this concludes the post and hope you enjoyed it...

thanks and have a great time ahead.



How to change the root password in linux when it is forgotten/to change

This blog is all about changing the root password of the Linux system when it is forgotten or to reset the password...   Let's get it ...