Saturday, 23 November 2013

Sample Spring TTD BDD :: Revisiting

Planning to revisit my old blog.

Going to explain Step by Step

> mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.geethsangam.music -DartifactId=Geethsangam


I am going to use eclipse

>  mvn eclipse:eclipse


You can change the pom.xml


<packaging>jar</packaging> to <packaging>pom</packaging>

This is going to be the parent pom for us

You can create the mvn module from the command prompt or from eclipse

From terminal


>cd Geethsangam

> mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.geethsangam.music -DartifactId=geethsangam-core


From Eclipse 


File > New > Maven > Maven module 

or

Right click on the project 

Maven > New Maven Module Project



Adding cucumber-jvm to projects

Add these 2 dependencies in the pom.xml

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.1.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.1.2</version>
        <scope>test</scope>

    </dependency>

Create Folders for cucumber BDD test


> cd Geethsangam

> mkdir cucumber

> cd cucumber

> mkdir features

 encies in the pom.xml

In the cucumber folder create test acceptance folder.

> mkdir test

Then Add the following class

import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@Cucumber.Options(format = {"pretty""html:target/cucumber-html-report""json-pretty:target/cucumber-json-report.json"}, tags = "~@wip")
public class RunCukesTest {
}

Wednesday, 18 September 2013

Adding cucumber-jvm to projects

Add these 2 dependencies in the pom.xml

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.1.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.1.2</version>
        <scope>test</scope>

    </dependency>


In the Test add a acceptance folder


Then Add the following class

import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@Cucumber.Options(format = {"pretty", "html:target/cucumber-html-report", "json-pretty:target/cucumber-json-report.json"}, tags = "~@wip")
public class RunCukesTest {
}


Now when you run 

>mvn test


It will complain that there are no feature file

Now in the resources folder based on your package structure create acceptance folder and then add a sample feature

Feature: Testing for sample core

Scenario Outline: Successful login

        Given I want to use the browser [browser]
        When I type testuser1 in the username input field
        When I type testuser1 in the password input field
        And I click the login button
        Then I am on the launcher page

        Examples:
                |     browser            |
                |     Firefox            |
                |     Chrome             |
                |     InternetExplorer   |

Now when you run >mvn test

it will ask us to implement the feature


You can implement missing steps with the snippets below:

@Given("^I want to use the browser \\[browser\\]$")
public void I_want_to_use_the_browser_browser() throws Throwable {
    // Express the Regexp above with the code you wish you had
    throw new PendingException();
}

@When("^I type testuser(\\d+) in the username input field$")
public void I_type_testuser_in_the_username_input_field(int arg1) throws Throwable {
    // Express the Regexp above with the code you wish you had
    throw new PendingException();
}

you have configured cucumber-jvm to your projects


Adding Apache log4j

in pom.xml add the log4j dependency

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>

    </dependency>

in resources add a new file log4j.properties

# Root logger option
log4j.rootLogger=debug, stdout

# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n


Now you should be able to log in messages


For mockito add this dependency

        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.9.5</version>
            <scope>test</scope>

        </dependency>


We can have exception rules as

    @Rule

    public ExpectedException expectedEx = ExpectedException.none();

    @Test
    public void shouldAcceptOnlyIncrementOf100Messages() {
        expectedEx.expect(IllegalArgumentException.class);
        expectedEx.expectMessage("The number of messages per seconds must be multiple of 100 )");
        new FixedRateMessageInjector(queueDriver, 108, 2);
    }


In case if you want to use AWS add

        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk</artifactId>
            <version>1.4.1</version>

        </dependency>

Tuesday, 11 June 2013

UK Oracle Developer Day


Oracle Developer Day 2013

http://www.oracle.com/us/dm/h2fy11/180676-emeafm13047156mpp001c003-oem-1940507.html

Friday, 7 June 2013

One question by a user on Java pass by reference

Hi

Was just going through one of the blogs where there was confusion on pass by value and pass by reference, i found a interesting problem posted by one of the user.

I guess he wanted to interchange values of 2 Objects using a temp Object.

This was his program

http://javapapers.com/core-java/java-pass-by-value-and-pass-by-reference/

hello guys, i am above Anonymous
i hope this will help more for your confusion.
just a simple example
public class point
{
int x,y;
public void tricky(Point arg1, Point arg2)
{
arg1.x = 100;
arg1.y = 100;
Point temp = arg1;
arg1 = arg2;
arg2 = temp;
}
public static void main(String [] args)
{
Point pnt1 = new Point(0,0);
Point pnt2 = new Point(0,0);
line 1:System.out.println(“X: ” + pnt1.x + ” Y: ” +pnt1.y);
line 2:System.out.println(“X: ” + pnt2.x + ” Y: ” +pnt2.y);
System.out.println(” “);
tricky(pnt1,pnt2);
line 3:System.out.println(“X: ” + pnt1.x + ” Y:” + pnt1.y);
line 4:System.out.println(“X: ” + pnt2.x + ” Y: ” +pnt2.y);
}
}
just think there is a pass by reference in java. the output at line 4 will be 100 and 100 but it gives 0 and 0. so there is no pass by reference in java.

X: 0 Y: 0
X: 0 Y: 0

X: 100 Y: 100
X: 0 Y: 0



import java.awt.Point;

public class point {

    int x;
    int y;

    public static void tricky(Point arg1, Point arg2) {
        arg1.x = 100;
        arg1.y = 100;
        Point temp = arg1;
        arg1 = arg2;
        arg2 = temp;
    }

    public static void tricky1(Point arg1, Point arg2) {
        arg1.x = 100;
        arg1.y = 100;
        Point temp = new Point(arg1.x, arg1.y);
        System.out.println("temp :: X: "+ temp.x + " Y: " +temp.y);
        arg1.x = arg2.x;
        arg1.y = arg2.y;
        arg2.x = temp.x;
        arg2.y = temp.y;
    }

    public static void main(String [] args) {
        Point pnt1 = new Point(0,0);
        Point pnt2 = new Point(0,0);
        System.out.println("X: "+ pnt1.x + " Y: " +pnt1.y);
        System.out.println("X: "+ pnt2.x + " Y: " +pnt2.y);
        System.out.println(" The users wrong way of pass by reference");
        tricky(pnt1,pnt2);
        System.out.println("X: "+ pnt1.x + " Y: " +pnt1.y);
        System.out.println("X: "+ pnt2.x + " Y: " +pnt2.y);
        System.out.println(" My solution to the problem pass by reference");
        tricky1(pnt1,pnt2);
        System.out.println("X: "+ pnt1.x + " Y: " +pnt1.y);
        System.out.println("X: "+ pnt2.x + " Y: " +pnt2.y);
    }
}

> java point

X: 0 Y: 0
X: 0 Y: 0
 The users wrong way of pass by reference
X: 100 Y: 100
X: 0 Y: 0
 My solution to the problem pass by reference
temp :: X: 100 Y: 100
X: 0 Y: 0
X: 100 Y: 100

Sunday, 2 June 2013

Virtual Developer Day: Java

Virtual Developer Day: Java

Click on the image or link to register for Java Virtual Developer Day 2013



Join this FREE virtual event where you will learn about:
•    Improved developer productivity and HTML5 applications
•    What's new in Java that helps you begin programming on a wide range of embedded devices
•    Language improvements in Java SE to accelerate application development
Watch informative tutorials that you can repeat at your own pace to improve your Java programming expertise, as well as engage in live chat sessions with technical experts.
Americas/Canada - Wednesday June 19, 2013 
9:00 a.m. - 1:00 p.m. PDT / 12:00 p.m. - 4:00 p.m. EDT / 1:00 p.m. - 5:00 p.m. BRT
EMEA/Africa/Middle East - Tuesday June 25th, 2013 
9:00:00 a.m.  - 1:00pm BST / 10:00:00 a.m. -  2:00 p.m.CEST /
1:30:00 p.m.  - 5:30:00 p.m. IST / 12:00:00 p.m. - 4:00 p.m. MSK /
08:00:00 a.m.  - 12:00 p.m. Corresponding UTC (GMT)



Tuesday, 21 May 2013

Introduction to JEE 7 (Live Webcast)


Register yourself for the Live Webcast JAVA EE 7

Click on the image to the registration page for this event.




Wednesday, June 12, 2013 / Thursday, June 13, 2013 
Two opportunities to come together with the Java community, chat with experts, and explore Java EE 7: 
9 a.m. PT / 12 p.m. ET / 5 p.m. London or 
9 p.m. PT / 12 a.m. ET (Thursday) / 2 p.m. Sydney (Thursday)