Monday, January 23, 2017

Ubuntu Terminal Is Not Working Properly in Vi Editor

Ubuntu terminal is not working properly in vi Editor

As we all know vi editor is one of the major editing tool for developers. Sometimes its obvious to handle the issue if its not response properly. There are few scenario where this kind of behavior occurs. 

If you have newly installed the Ubuntu , or you have not updated the terminal with latest update. 

Just try to update the terminal by using below command.

sudo apt-get update

Now check your vi editor behavior , if not yet resolved then try the below command to install the vi (vim) editor.

Install Vim Editor using below command :-

sudo apt-get install vim

Now check your vi editor, I hope its fixed. It worked for me and its working awesome :)

Friday, November 11, 2016

How to Convert a String Date to Java Calendar

How to convert String date to Java Calendar.


This can be done by some other way also, but  I have done in the below format. Hope this is will help you.

 

Example :- 
Input String Date - "20160829T23:59:59Z"

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class StringDateToCalendar {

    /**
     * @param args
     */
    public static void main(String[] args) throws Exception {
            String string = "20160829T23:59:59Z";
            String pattern = "yyyyMMdd'T'HH:mm:ss'Z'";
            Date date = new SimpleDateFormat(pattern).parse(string);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            System.out.println("Calendar is :: "+ calendar.getTime());
    }

}
Output :-
Calendar is :: Mon Aug 29 23:59:59 AEST 2016

How to Convert a String Date to Java Date

This can be done by some other way also, but  I have done in the below format. Hope this is will help you.

Example :- 

Input String Date - "20160829T23:59:59Z"


import java.text.SimpleDateFormat;
import java.util.Date;

public class StringDateToCalender {
    public static void main(String[] args) throws Exception {
        String string = "20160829T23:59:59Z";
        String pattern = "yyyyMMdd'T'HH:mm:ss'Z'";
        Date date = new SimpleDateFormat(pattern).parse(string);
        System.out.println(date);
    }
}

Output :-
Converted Date is :: Mon Aug 29 23:59:59 AEST 2016

Monday, October 10, 2016

JUnit Error: Unresolved Compilation Problems Due to Missing WebLogic JAR

java.lang.Error: Unresolved compilation problems:

Facing issue is often hurdle for developer :) :) As you all know, Java Developers Guide always posted the real time issues. This issue I have faced while writing Junit test cases, but its not so easy to fix your development desktop. The below issue normally happens when the class path is missed the related weblogic jar.

I am using weblogic for jaxrpc client calls, and its failing to find the weblogic jar. Below error logs :
  

java.lang.Error: Unresolved compilation problems:
    The type weblogic.wsee.jaxrpc.ServiceImpl cannot be resolved. It is indirectly referenced from required .class files
    The type weblogic.wsee.jaxrpc.StubImpl cannot be resolved. It is indirectly referenced from required .class files
    The import weblogic.wsee.security cannot be resolved
    The import weblogic.xml cannot be resolved
    The import weblogic.xml cannot be resolved
    The method addCredentialsToSecurityHeader(Stub, HandlerInfo) in the type JdcNotificationHandler is not applicable for the arguments (JdcEnablerService_PortType_Stub, HandlerInfo)
    The method addCredentialsToSecurityHeader(Stub, HandlerInfo) in the type JdcNotificationHandler is not applicable for the arguments (JdcEnablerService_PortType_Stub, HandlerInfo)
    The method addCredentialsToSecurityHeader(Stub, HandlerInfo) in the type JdcNotificationHandler is not applicable for the arguments (JdcEnablerService_PortType_Stub, HandlerInfo)
    CredentialProvider cannot be resolved to a type
    CredentialProvider cannot be resolved to a type
    CredentialProvider cannot be resolved to a type
    ClientUNTCredentialProvider cannot be resolved to a type
    WSSecurityContext cannot be resolved to a variable

    at au.com.mycompany.mcas.sdp.bizservice.user.domain.util.notification.JdcNotificationHandler.<init>(JdcNotificationHandler.java:1)
    at au.com.mycompany.mcas.sdp.bizservice.user.application.facade.spring.handler.JdcNotificationHandlerTest.<init>(JdcNotificationHandlerTest.java:31)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.junit.internal.runners.JUnit4ClassRunner.createTest(JUnit4ClassRunner.java:72)
    at org.mockito.internal.runners.JUnit44RunnerImpl$1.createTest(JUnit44RunnerImpl.java:26)
    at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:79)
    at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
    at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
    at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
    at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
    at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
    at org.mockito.internal.runners.JUnit44RunnerImpl.run(JUnit44RunnerImpl.java:37)
    at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)



How to fix  :- This is very simple, just add the weblogic.jar library jar into your class path. Steps as below,


Right Click on Project => Build Path => Libraries and then add the required jar (In my case I have added weblogic.jar).

The screenshot attached for reference. 


java.lang.Error




Tuesday, September 13, 2016

How to configure the username on git

How to configure the user name on git.

 

This is simple solution but BIG question .....???

To change/configure the user name at your local machine is very easy, but the user name issue is often trouble to developer.

Usually you will get the below error :-

remote: refs/heads/bugfix/testtagging: bd04a65ec413cecbd11cadc336cb4dd25fa3d935: expected committer name 'Manoj Kumar Bardhan' but found 'manojkumar.bardhan'

To fix this , you need to configure the user name as expected. First check what is the existing user name before set to new.

dev@jdg-developer-desktop ~/testtagging/test $ git config --global user.name
manojkumar.bardhan


Change/Configure the user name by using below command, you can provide your expected user name.


dev@jdg-developer-desktop ~/testtagging/test $ git config --global user.name "Manoj Kumar Bardhan"

Now, you can check again the user name after change/configure.

dev@jdg-developer-desktop ~/testtagging/test $ git config --global user.name
Manoj Kumar Bardhan


Now you can see the old user name was "manojkumar.bardhan" and new user name is "Manoj Kumar Bardhan".


It worked for me, hope it will help you.




Follow for more details on Google+ and @Facebook!!!

Find More :-

How to Create a Git Tag

How to create tagging on git.



Really creating tag is  one of the best practice for development and maintain version. 


As per my understanding production release for your code is a nightmare , we don't know what will happen ???????

Also to maintain the code base stable and safety we need this tagging. This is quite often developers do google for tagging the their code (branch / master) for safety and reference future use.

This is quite simple , and below example will help you to understand the commands on command line.

Clone your code branch (use clone command to clone the code)

git clone https://your.user.name@stash.jdgnet.com.au/scm/enabler/testcode.git

Switch your expected branch (i.e.  bugfix/jdctagging) , which you want to create tagging and make sure you are inside the expected branch.

dev@jdg-developer-desktop ~/jdgtaggingdemo/test $ git checkout bugfix/jdctagging
Branch bugfix/testing set up to track remote branch bugfix/jdctagging from origin.
Switched to a new branch 'bugfix/jdctagging'
dev@jdg-developer-desktop ~/jdgtaggingdemo/test $ git branch
* bugfix/jdctagging
  master


Create the tag with below command, you can specify the tag version name.

dev@jdg-developer-desktop ~/jdgtaggingdemo/test $ git tag -a "v1.taging.version1" -m "commiting with for test tagging for my branch code"

Check the tag got created on above command.

dev@jdg-developer-desktop ~/jdgtaggingdemo/test $ git tag
v1.taging.version1

Push the newly created tag into remote server (stash)

dev@jdg-developer-desktop ~/jdgtaggingdemo/test $ git push origin v1.taging.version1
Password for 'https://your.user.name@stash.jdgnet.com.au':
To https://your.user.name@stash.jdgnet.com.au/scm/enabler/test.git
 * [new tag]         v1.taging.version1 -> v1.taging.version1

If you don't want to push the tag by name and you want to push all tags then use below command. In my example I have only created one tag and I didn't use the below command.


git push origin --tags


Now you can see the [new tag] got created on remote server. See the snapshot below , showing the tag on stash.







Tuesday, August 16, 2016

How to Mock Private Fields of a Class for JUnit Testing

This is really very tricky and major concern for developers. Specially who are not following TDD(Test Driven Development ) process.


Of course it not the challenge for java developer to get this done, but when there is a time period to deliver your project. ohh god !!! you only can save me.

By the way , I also faced same issue with my recent project. After some kind of investigation .. and its weird. 


Actully I was using Junit with Mockito. I tried with mockito , but no luck. Hence mockito will not allow you to set the private fields . 

Finally I tried with Reflection to enforce the private variable to set the data using ReflectionTestUtils.
import org.springframework.test.util.ReflectionTestUtils;
 

Sample code fix using Junit Test (Reflection API) :-

/**
 * This class contains your private variables those you want to mock.
 */

public class MyObjectImplImpl {
    private String fieldName1;
    private String fieldName2;

}

Test Class (MyObjectImplTest.java):-

public class MyObjectImplTest {

    @InjectMocks
    MyObjectImplImpl myObjectImplImpl;

    @Before
    public void before() {
        myObjectImplImpl = mock(MyObjectImplImpl.class);
        myObjectImplImpl = new MyObjectImplImpl();

        //Set the private variable values here by reflection.
        ReflectionTestUtils.setField(myObjectImplImpl, "fieldName1", "setnew-field-value-1");
        ReflectionTestUtils.setField(myObjectImplImpl, "fieldName2", "setnew-field-value-2");
    }

    

    /**
     * Your Test Method.
     */
    @Test
    public void testJavaDeveloperGuide() {
       //do your test case here.
    }

}


This is working fine for me.


Either the alternative is you can try power-mock , instead of mockito. Powermock is working for this issue. This will fix this private field access issue. Also its more powerful than mockito.



Happy coding.........!!!