Monday, 7 November 2011

Android : Your First Dream Application Hello World

Initial Requirement:

     1. The "Eclipse Classic" version is recommended. Otherwise, a Java or RCP version of Eclipse is  recommended.
     2. Install the SDK starter package from the table above.  
             Windows android-sdk_r15-windows.zip 
            installer_r15-windows.exe (Recommended)

      3. Install the ADT Plugin for Eclipse (if you'll be developing in Eclipse).
      4. Add Android platforms and other components to your SDK.

After installing ADT and SDK.We can launch the Android SDK and AVD Manager in one of the following ways:
  • From within Eclipse, select Window > Android SDK and AVD Manager.
  • On Windows, double-click the SDK Manager.exe file at the root of the Android SDK directory.
  • On Mac or Linux, open a terminal and navigate to the tools/ directory in the Android SDK, then execute: android
  • In the right panel, expand the Android Repository list to display the components available for installation.
  • Select at least one platform to install, and click Install Selected. If you aren't sure which platform to install, use the latest version.


To download components, use the graphical UI of the Android SDK and AVD Manager to browse the SDK repository and select new or updated components. The Android SDK and AVD Manager installs the selected components in your SDK environment. 

Create an AVD

Here you will run your application in the Android Emulator. Before you  launch the emulator, you must create an Android Virtual Device (AVD). An AVD defines the system image and device settings used by the emulator.
To create an AVD:
  1. In Eclipse, select Window > Android SDK and AVD Manager.
  2. Select Virtual Devices in the left panel.
  3. Click New.... The Create New AVD dialog appears.
  4. Type the name of the AVD, such as "my_avd".
  5. Choose a target. The target is the platform (that is, the version of the Android SDK, such as 2.3.3) you want to run on the emulator. Choose the latest platform that you have installed and ignore the rest of the fields.
  6. Click Create AVD.

Create a New Android Project

Next  step start the eclipse 
In Eclipse, select File > New > Project....
  1. If the ADT Plugin for Eclipse has been successfully installed, the resulting dialog should have a folder labeled "Android" which should contain "Android Project".
  2. Select "Android Project" and click Next.
  3. Fill in the project details with the following values:
    • Project name: HelloAndroid
    • Build Target: Select a platform version that is equal to or lower than the target you chose for your AVD.
    • Application name: Hello, Android
    • Package name: com.example.helloandroid (or your own private namespace)
    • Create Activity: HelloAndroid
    Click Finish.




    Your Android project is now ready. It should be visible in the Package Explorer on the left. Open the HelloAndroid.java file, located inside HelloAndroid > src > com.example.helloandroid). It should look like this:


    package com.example.helloandroid;
    import android.app.Activity;
    import android.os.Bundle;
    public class HelloAndroid extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
        }
    }

Ready for  UI?

Modify the above code

                 package com.example.helloandroid;
        import android.app.Activity;
        import android.os.Bundle;
        import android.widget.TextView;
       public class HelloAndroid extends Activity {
           /** Called when the activity is first created. */
           @Override
          public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            TextView tv = new TextView(this);
            tv.setText("Hello, Android");
            setContentView(tv);
          }
       }

Run the Application


The Eclipse plugin makes it easy to run your applications:
  1. Select Run > Run.
  2. Select "Android Application".
The Eclipse plugin automatically creates a new run configuration for your project and then launches the Android Emulator. Depending on your environment, the Android emulator might take several minutes to boot fully, so please be patient. When the emulator is booted, the Eclipse plugin installs your application and launches the default Activity. You should now see something like this: 

That concludes the basic "Hello World" tutorial.



Friday, 4 November 2011

Flex 4 & Spring 3 Integration

Integrating Flex And Spring

Adobe Flex has strong ties to Java, which include an Eclipse-based
IDE and BlazeDS, its open source server-based Java remoting and
web messaging technology. 

By default BlazeDS creates instances of server-side Java objects and
uses them to fulfill remote object requests. This approach doesn’t work
with Spring, as the framework is built around injecting the service beans
through the Spring container. The Spring integration with BlazeDS
allows you to configure Spring beans as BlazeDS destinations for use as
remote objects in Flex.

You will initially need:
1) An Eclipse 3.5 Distribution. Either You may choose either the standard Eclipse 3.5 (Galileo) for Java EE Developers (On Mac use the Eclipse Carbon version): http://www.eclipse.org/downloads/
For enhanced Spring support you can use the SpringSource Tool Suite:
    http://www.springsource.com/products/springsource-tool-suite-download/ 
2) Flash Builder 4 (60 day T rial) installed as a plug-in for the Java EE Eclipse
    http://www.adobe.com/go/try_flashbuilder
3) Tomcat 6: http://tomcat.apache.org/
4) BlazeDS 4 (Binary Distribution):
     http://opensource.adobe.com/wiki/display/blazeds/BlazeDS/
5) Spring Framework 3.0.2 (vanilla r elease):
     http://www.springsource.org/download
6)  Spring BlazeDS Integration 1.0.3 (vanilla r elease):
     http://www.springsource.org/spring-flex
7)  AOP Alliance 1.0:
     http://sourceforge.net/projects/aopalliance/files/
8) backport-util-concurrent 3.1 for the Java version you’r e using:
http://sourceforge.net/projects/backport-jsr166/files/backport-jsr166/
9) cglib 2.2 http://sourceforge.net/projects/cglib/files/
10) asm 3.2 http://forge.ow2.org/projects/asm/

I think now we are ready with initial elements lets start with server setup

First install your chosen Eclipse  and then install Flash Builder 4 as a plug-in to the Eclipse distribution you just installed. Also extract the ZIP files for the other dependencies specified above. When you’ve completed these steps, run Eclipse. In Eclipse create a server that will run the application:
1. Choose File > New > Other
2. Select Server > Server
3. Click Next
4. Select Apache > Tomcat v6.0 Server
5. Click Next
6. Specify the location where Tomcat is installed and select the JRE(version 5 or higher) to use
7. Click Finish


Set up the server-side Java web project in Eclipse by creating a web application from the blazeds.war file
(found inside the BlazeDS zip file).
In Eclipse, import the blazeds.war file to create the project:
1. Choose File > Import
2. Select the WAR file option. Specify the location of the blazeds.war file.
For the name of the web project, type samplepring
3. Click Finish
First remove the xalan.jar file from the WebContent/WEB-INF/lib folder. Next, go into the project properties. One way to get there is by right-clicking on the project and selecting Properties. In the project properties, select Java Build Path and then click the Source tab. Set the Default Output Folder samplepring/WebContent/WEB-INF/classes
This causes all Java classes that are created in the project to be deployed in the web application.
In the WebContent/WEB-INF/flex folder update the services-config.xml file with the following contents:

<?xml version=”1.0” encoding=”UTF-8”?>
<services-config>
<channels>
<channel-definition id=”my-amf” class=”mx.messaging.channels.AMFChannel”>
<endpoint url=”http://{server.name}:{server.port}/{context.root}/messagebroker/amf” class=”flex.messaging.endpoints.AMFEndpoint”/>
</channel-definition>
<channel-definition id=”my-streaming-amf” class=”mx.messaging.channels.StreamingAMFChannel”>
<endpoint url=”http://{server.name}:{server.port}/{context.root}/messagebroker/streamingamf” class=”flex.messaging.endpoints.StreamingAMFEndpoint”/>
</channel-definition>
<channel-definition id=”my-polling-amf” class=”mx.messaging.channels.AMFChannel”>
<endpoint url=”http://{server.name}:{server.port}/{context.root}/messagebroker/amfpolling” class=”flex.messaging.endpoints.AMFEndpoint”/>
</channel-definition>
</channels>
</services-config>


Now select the Servers tab in Eclipse. If the tab is not visible you can make it visible by choosing Windows > Show View > Servers. Right-click the Tomcat Server and select Add and Remove. To add the samplepring web application to the server, select it in the Available list and then click Add. Finally, click Finish.
Next, you need to add the required dependencies to the samplepring web application. Copy all of the Spring Framework libraries / JAR files (located in the dist folder) to the WebContent/WEB-INF/lib folder. Also copy the Spring BlazeDS Integration library (located in the dist folder) to the lib folder. Do the same for aopalliance.jar, backport-util-concurrent.jar, cglib-2.2.jar, asm-3.2.jar.


Simple Flex Remoting
To configure the server for simple Flex Remoting first edit the web.xml file in the WebContent/WEB-INF folder. Replace its contents with:

<?xml version=”1.0” encoding=”UTF-8”?>
<web-app xmlns=”http://java.sun.com/xml/ns/javaee” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xmlns:web=”http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd”
xsi:schemaLocation=”
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd”
version=”2.5”>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>flex.messaging.HttpFlexSession</listener-class>
</listener>
<servlet>
<servlet-name>samplespring</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>samplespring</servlet-name>
<url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>
</web-app>

Eclipse may try to change the web-app version to 2.4 instead of 2.5. If this happens just manually change it back to 2.5.Spring will now handle requests to the /messagebroker/url.
Now configure Spring by creating an applicationContext.xml file in the WebContent/WEB-INF folder with the following contents:

<?xml version=”1.0” encoding=”UTF-8”?>
<beans xmlns=”http://www.springframework.org/schema/beans”
xmlns:flex=”http://www.springframework.org/schema/flex”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”

xmlns:context=”http://www.springframework.org/schema/context”
xsi:schemaLocation=”http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/flex
http://www.springframework.org/schema/flex/spring-flex-1.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd”>
<flex:message-broker>
<flex:remoting-service default-channels=”my-amf”/>
</flex:message-broker>
<context:component-scan base-package=”flex” />
</beans>
 

Now create a simple Java class that will be exposed through the AMF channel to a Flex application. In the src folder create a new Java Class in the flex package with the name “HelloWorldService”. Set the contents of the HelloWorldService.java file to:

package flex;
import org.springframework.flex.remoting.RemotingDestination;
import org.springframework.flex.remoting.RemotingInclude;
import org.springframework.stereotype.Service;
@Service
@RemotingDestination
public class HelloWorldService {
@RemotingInclude
public String sayHello(String name) {
return “howdy, “ + name;
}
}


The @Service annotation tells Spring that the class is a Service and the @RemotingDestination annotation exposes the class as a remoting endpoint for Flex. This class also contains a single method named sayHello, which simply takes a string and returns a slightly modified version of the string. By default all public methods on a class are available for remoting. You can keep a public method from being exposed as a remoting endpoint by using the @RemotingExclude annotation.

Create the Flex Application
Now you can create a Flex application that will call the sayHello method on HelloWorldService. To begin building the Flex application, simply create a new Flex Project in Eclipse. In the New Flex Project wizard, type sayHello as the name, select Web as the Application type, and set the Flex SDK Version to Flex 4.0 (usually the default). Also select J2EE as the Application Server Type, enable Use Remote Object Access Service, and select BlazeDS. Ensure that the Create Combined Java/Flex Project Using WTP option is not checked and then click Next. Now enter the information for your samplespring project. The Root folder is the WebContent folder in your samplespring project. The Root URL should be http://localhost:8080/samplespring/. The Context root should be /samplespring.
Click Finish to create the project. You should now see the template code for the application. Replace the code with the following:

<?xml version=”1.0” encoding=”utf-8”?>
<s:Application xmlns:fx=”http://ns.adobe.com/mxml/2009”
xmlns:s=”library://ns.adobe.com/flex/spark”
xmlns:mx=”library://ns.adobe.com/flex/mx”>
<fx:Declarations>

<s:RemoteObject id=”ro” destination=”helloWorldService”
endpoint=”http://localhost:8080/samplespring/messagebroker/amf”/>
</fx:Declarations>
<s:layout><s:VerticalLayout/></s:layout>
<s:TextInput id=”t”/>
<s:Button label=”sayHello” click=”ro.sayHello(t.text)”/>
<s:Label text=”{ro.sayHello.lastResult}”/>
</s:Application>



When you save the file it should automatically compile. When it is compiled it should automatically be deployed in your web application.You are now ready to start the server and test the application. Go to
the Servers View in Eclipse and start the Tomcat server. Watch the console and make sure that there are no startup errors.Now run the sayHello application (one way is to right-click the sayHello.mxml file, select Run As, and then select Web Application). Your browser should open the sayHello.html file that then downloads and runs the Flex application. Type your name in the TextInput box and click the sayHello button. This will initiate a Flex Remoting request to the Tomcat server calling the Spring DispatcherServlet, which then will
look up the service based on the destination helloWorldService. This destination is automatically mapped to the HelloWorldService Spring Bean. Then the sayHello method will be invoked on the bean, passing
in the String that was specified in the RemoteObject call on the client. The method returns a new String, which is then serialized into AMF, inserted into the HTTP Response body, and sent back to the client. On
the client side the Flex application will parse the AMF and then set the ro.sayHello.lastResult property to what was returned from the server.Data binding in the Label will note the property change and refresh its
view of the data.

Create Selenium Java test case using Eclipse

Requirement:

1. Eclipse 3.4+
2. FireFox Browser
3. Java 1.5 or 1.6
4. Selenium Jars
      selenium-server-standalone-2.3.0.jar
      selenium-java-2.3.0.jar


Steps to create selenium project:
 1. Open Eclipse
2. Create new project
3. import selenium-server-standalone-2.3.0.jar and
    selenium-java-2.3.0.jar
4. Create new java file with name TestSample
5. Refer the below code 


 import java.util.Properties;
 import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.WebDriverBackedSelenium;
 import org.openqa.selenium.firefox.FirefoxDriver;
 import com.thoughtworks.selenium.Selenium;

 public class TestSample {
  public static void main(String[] args) throws Exception {
     String url = "http://www.google.co.in";
     Properties properties = LoadProperties.loadPropertiesFile();
     WebDriver driver = new FirefoxDriver();
     Selenium selenium = new WebDriverBackedSelenium(driver, url);
     driver.get(url);
    selenium.waitForPageToLoad("900000");
    String a = selenium.captureScreenshotToString();
    driver.close();
    selenium = null;
    driver = new FirefoxDriver();
    selenium = new WebDriverBackedSelenium(driver, url);
    driver.get(url);
    selenium.waitForPageToLoad("400000");
    selenium.waitForPageToLoad("400000");
    String b = selenium.captureScreenshotToString();
    System.out.println("clicked" + a);
    System.out.println("clicked" + b);
    if(a.equalsIgnoreCase(b)){
        System.out.println("true");
    }  else {
        System.out.println("false");
    }
 }
}
6. Save file
7. Run TestSample : java file as a Run Test.

Wednesday, 2 November 2011

Hello World: Package and Brand Your App

In this blog you'll package the created Hello world App so you can distribute it on the AppExchange. A package is simply a container for components,in this case it's your app, tab, and page. 

1. In the sidebar menu, click Create > Packages, and then click New.
2. In the Package Name field enter Hello World and then click Save.
3. On the Package Detail page click Add Components.
4. Select your Hello World app and then click Add to Package.
5. Click Branding.
6. On the Package Branding detail page, click Edit.
7. Select Enable to use your own branding.
8. Enter information about your company in the fields provided.
9. Click Save to preview the branded emails.

Assign a Namespace

1. In the sidebar menu, click Create > Packages.
2. In the Developer Settings list, click Edit and on the following page click Continue.
3. In the Namespace Prefix field, enter a 1-15 character alphanumeric ID and then click Check Availability. Repeat this step until you have a unique namespace.
4. In the Package to be managed field choose your Hello World package and then click Review Your Selections.
5. Review the information on the page and then click Save.

Upload a Beta
Before you upload a production version of your app, it's a common practice to upload a beta version for testing.
1. In the sidebar menu, click Create > Packages.
2. On the Packages page, click your Hello World package and then click Upload.
3. On the Upload Package page, enter a version name and number.
4. For the Release Type, make sure to choose Managed — Beta.
5. Scroll to the bottom and click Upload. It may take a moment for the upload to complete.

Wowww. Congratulations, you've uploaded an app to the AppExchange!
Your app isn't available to the public, but you can access it
through an install link.

Hello World: Build a saleforce app in five minutes

Salesforce.com is all about CRM. It's a site that's built for Customer Relationship Management, this basically means they give you a resource to keep a firm base of communication and knowledge with your customers that will help you succeed as well as gain new customers. It is a program and part of a business plan to help you gain knowledge about your customers and their behaviors and needs that you can help provide to get a stronger base for your company. It gives you a great advantage over those companies and businesses that choose not to focus on CRM and do not keep a tab on customers and what it will take to draw in new ones. Salesforce is a technology that is basically a cloud computing platform that will help you with your CRM and budget everything to make your business as successful as it can possibly be! 



Create an App in Salesforce

In this step you're going to create an app that contains a page, and a tab to display the page.
1. In your browser, log into salesforce developer edition
2. Click Your Name > Setup in the upper right corner, and then click Develop > Pages in the sidebar menu.
3. In the Visualforce list, click New.
4. In the Label field enter Greeting.
5. In the Visualforce Markup area, replace the contents of the <h1> tag with Hello World.
6. Click Save.
7. In the sidebar menu, click Create > Tabs.
8. In the Visualforce Tabs list, click New.
9. In the New Visualforce Tab wizard, click the drop-down box and select the Hello World page you just created.
10. For the Tab Label, enter Hello.
11. Click the Tab Style field and choose any icon to represent your tab.
12. Click Next, then Next again, and Save on the final page.
 

Now you'll create a new app that contains your tab and page.
1. In the sidebar menu, click Create > Apps.
2. Click New.
3. In the App Label field enter Hello World and then click Next and Next again on the following page.
4. On the Choose the Tabs page, scroll to the bottom of the Available Tabs list, find your Hello tab, and add it to the Selected
Tabs list. Click Next.
5. Select the Visible checkbox to make this app visible to all profiles and then click Save.

Tuesday, 1 November 2011

Write selenium test case in C# using Nunit

1) Download selenium jar files and run these files using Java command.
2) Download Nunit.
3) Download selenium core dll files for .Net and add it into References.
4) Create new test case in C#
5) Run below code into Nunit


using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using Selenium;

namespace Phoenix.Web.Tests.Controller
{
    [TestFixture]
    public class SeleniumTest
    {
        private ISelenium selenium;
        private StringBuilder verificationErrors;

        [SetUp]
        public void SetupTest()
        {
            selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://localhost:4848/");
            selenium.Start();
           verificationErrors = new StringBuilder();
        }

        [TearDown]
        public void TeardownTest()
        {
            try
            {
                selenium.Stop();
            }
            catch (Exception)
            {
            }
            Assert.AreEqual("", verificationErrors.ToString());
        }

        [Test]
        public void FirstSeleniumTest()
        {
            # region Previous Smoke Test Code
            selenium.Open("/SignIn");
            selenium.SetSpeed("9000");
            selenium.Type("id=UserName", "ac10");
            selenium.Type("id=Password", "password1");
            selenium.Click("name=btnSubmitSignIn");
            selenium.WaitForPageToLoad("30000");
            selenium.Click("link=Create");
            selenium.WaitForPageToLoad("30000");
            selenium.Type("id=Name", "GREEN VALLEY SCHOOL");
            selenium.Type("id=PostCode_1", "KT198DL");
            selenium.Click("id=btnFindAddress_1");
        }    }

Calling WSDL in Salesforce using HttpRequest and HttpResponce

         String url = 'http://soap.amazon.com/schemas2/AmazonWebServices.wsdl';
         HttpRequest req = new HttpRequest();
         req.setEndpoint(url);
         String sbody = 'username=uname&password=passwd';
         System.debug('Body-'+sbody);
         req.setBody(sbody);
         req.setMethod('POST');
         req.setHeader('content-type', 'application/x-www-form-urlencoded');
         req.setTimeout(120000);
         req.setHeader('Content-Length','1024');
         req.setHeader('Connection','keep-alive');
    
         Http http = new Http();
         HTTPResponse res = http.send(req);
    
        //either use getBody and parse xml manually
         System.debug('Output>>>>'+res.getBody());
         //Using parser we can manually traverse the xml