Tuesday

Critical error during deployment: : com.sun.faces.config.ConfigurationException: Factory 'javax.faces.render.RenderKitFactory' was not configured properly

BUG:
I was trying to deploy a JSF (RichFaces) application in JBOSS 7.1.0 and I got following error:

Critical error during deployment: : com.sun.faces.config.ConfigurationException: Factory 'javax.faces.render.RenderKitFactory' was not configured properly


FIX:
Add following parameters to the web.xml:

<listener>
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>

Sunday

Quartz 2 Scheduler example

Quartz helps to schedule a job to run at a specific time.
  • Download quartz-2.1.5.jar from this location and add to buildpath of your project.
  • For maven Project:

<dependencies>
 <dependency>
  <groupId>org.quartz-scheduler</groupId>
  <artifactId>quartz</artifactId>
  <version>2.1.5</version>
 </dependency>
</dependencies>

  • File > New > Other > Dynamic Web Project







  • Copy quartz.2.1.5.jar under WEB-INF/lib


  • File > New > Class










package code.more.talk.less;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class QuartzJOB implements Job{
     
   public void execute(JobExecutionContext context)throws JobExecutionException 
{
          System.out.println("Hello Quartz!");     
 }
}


File > New > Folder >> resources

  • Right click > properties > Java Build Path > Source


  • Right click on resources folder > New > Other > Properties File
  • Content of quartz.properties file:

org.quartz.scheduler.instanceName = QuartzJOB
org.quartz.threadPool.threadCount = 3

org.quartz.plugin.jobInitializer.class =org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
org.quartz.plugin.jobInitializer.fileNames = quartz.xml
org.quartz.plugin.jobInitializer.failOnFileNotFound = true
  • Right click on resources folder > New > Other > Xml file


Content of quartz.xml file:

    <?xml version="1.0" encoding="UTF-8"?>
<job-scheduling-data
      xmlns="http://www.quartz-scheduler.org/xml/JobSchedulingData"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.quartz-scheduler.org/xml/JobSchedulingData
        http://www.quartz-scheduler.org/xml/job_scheduling_data_1_8.xsd"
      version="1.8">

      <schedule>
            <job>
                  <name>QuartzJOB</name>
                  <job-class>code.more.talk.less.QuartzJOB</job-class>
            </job>

            <trigger>
                  <cron>
                        <name>QuartzTrigger</name>
                        <job-name>QuartzJOB</job-name>
                        <!-- It will run every 5 seconds -->
                        <cron-expression>0/5 * * * * ?</cron-expression>
                  </cron>
            </trigger>
      </schedule>
     
</job-scheduling-data>


Add below code to the web.xml:


    <context-param>
         <param-name>quartz:config-file</param-name>
         <param-value>quartz.properties</param-value>
         <!-- <param-value>/some/path/my_quartz.properties</param-value> -->
     </context-param>
     <context-param>
         <param-name>quartz:shutdown-on-unload</param-name>
         <param-value>true</param-value>
     </context-param>
     <context-param>
         <param-name>quartz:wait-on-shutdown</param-name>
         <param-value>true</param-value>
     </context-param>
     <context-param>
         <param-name>quartz:start-on-load</param-name>
         <param-value>true</param-value>
     </context-param>
    
     <listener>
          <listener-class>
              org.quartz.ee.servlet.QuartzInitializerListener
         </listener-class>
     </listener>
Start application server and see the result:


Wednesday

Writing and running JUnit tests in Eclipse

1. File > New > Project > Java Project





2. File > New > Class


package code.more.talk.less;
public class Calculation {
       public int sum (int a, int b) {
              return a + b;
       }

}


File > New > Other > JUnit Test Case





CalculationTest class:

package code.more.talk.less;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class CalculationTest {

       @Before
       public void setUp() throws Exception {
              System.out.println("Calling Calculation Test");
       }

       @After
       public void tearDown() throws Exception {
              System.out.println("Finished Calculation Test");
       }

       @Test
       public void test() {
              int result = new Calculation().sum(1, 2);
              Assert.assertEquals(3, result);
       }


}





Change test method expected value and run test again. See the testFailure.
       @Test
       public void test() {
              int result = new Calculation().sum(1, 2);
              Assert.assertEquals(4, result);

       }





File > New > Other > JUnit Test Suite


Add a new method in CalculationTest class:
    @Test
       public void test2() {
              int result = new Calculation().sum(1, 2);
              Assert.assertEquals(3, result);

       }


> Run AllTests class. You'll see two reults for test(failure) and test2(successful ) methods.




  •  To ignore a test just add an @Ignore:  You can add it before or after @Test. 
  • In test suite you can run more then one class. @SuiteClasses({ class1.class , Class2.class })
  • You can add timeout for the test method. Example:
       @Test(timeout=1)
       public void test2() {
              int result = new Calculation().sum(1, 2);
              try {
                     Thread.sleep(1000);
              } catch (InterruptedException e) {
                     e.printStackTrace();
              }
              Assert.assertEquals(3, result);
       }




Sunday

Install JBoss Application Server 7.1 in Eclipse Kepler

  1. Download Eclipse Kepler from this location. http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/keplerr
  2. Open Eclipse. Help > Install New Software > Write the following  urls according to eclipse version to the “Work With” area.


Click to Add buton.


Choose only “Jboss Web and Java EE Development” and click Next.

Click Next.








Servers > New Server > JBoss AS 7.1 > Next










Unzip ‘ jboss-as-7.1.0.Final.zip’ in downloaded folder.





Then click “Finish”.