EasyMock

Posted by Olga on May 23, 2010 in Development
No Comments

Mock Objects

A unit test should verify just the behaviour of the tested object. But you’ll often find yourself  writing unit tests for classes that relay on other classes or methods’ results. That’s why you need a way of simulate these classes behaviour, that’s called mocking objects. This way you can assure you are testing an specific functionality avoiding dependencies with other classes.
Mock object is an object that mimic the behavior of real objects in controlled ways.

EasyMock

EasyMock is a library that provides an easy way to use Mock Objects for given interfaces or classes.

EasyMock 3.0

Allows you not only to mock interfaces but also classes. Also, you can capture mocked method’s parameters, to be able to check later the values, this way you can check just some of the attributes of the objects, instead of building the whole object to compare.

Sample Code:

Create mock object, you have to pass the class of the object mocked. You can also use an interface.
MyClass mockObj = EasyMock.createStrictMock(MyClass.class);
Set up expectations for the mocked object.
Without parameters or return
mockObj.myMethod1();
EasyMock.expectLastCall();
Without parameters
mockObj.myMethod2();
EasyMock.expectLastCall().andReturn(true);
EasyMock.expect(mockObj.myMethod3()).andReturn(true);
With parameters and return
EasyMock.expect(mockObj.myMethod4(1)).andReturn(2);
If you don’t know the parameters and you don’t care, you can user EasyMock comparison, but you have to use it for every parameter.
EasyMock.expect(mockObj.myMethod5(EasyMock.isA(MyParameter.class), EasyMock.eq(1))).andReturn(2);
Finally, if you don’t know the parameters but you want to check it later. You need a capture object
Define the capture object
Capture<MyParameter> captureObj = new Capture<MyParameter>();
Set up expectations
mockObj.myMethod5(EasyMock.capture(captureObj), EasyMock.eq(1));
EasyMock.expectLastCall();
After setting the expectations replay the mock objects.
EasyMock.replay(mockObj);
Execute Test calls that will make these expectations to carry out.
Verify the expectations
EasyMock.verify(MockObj);
Check captured parameters
assertTrue("MyParameter captured", captureObj.hasCaptured());
MyParameter param = (MyParameter) captureObj.getValue()
Check param.

References

Wikipedia.

EasyMock Documentation.

Tags: , , ,

DBUnit

Posted by Olga on May 13, 2010 in Development
No Comments

When testing code that access and modify the database, you’ll need to insert the initial data into the database, execute your code, and check if the data in the database is exactly what you expected after executing your code. To automate this kind of testing you’ll need any kind of tool that can do all that without trusting in visual inspection.

DbUnit is a JUnit extension targeted for database-driven projects. It allows you to put your database into a known state before testing, import and export data to or from xml datasets.

The initial data and expected data can be expresed in a simple xml way, that you can easily read, and modify without changing your testing code.

Installing DBUnit

Dependencies:

- Java SE SDK 1.4+
- Maven 2
- Oracle JDBC

Installing Oracle JDBC

Download it from Oracle JDBC Download page.

Install it into your Maven repository using te next command:

mvn install:install-file -Dfile=ojdbc14.jar -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.4.0 -Dpackaging=jar -DgeneratePom=true

Generating the JAR

  1. Install Java SE SDK 1.4+, Maven 2 and the Oracle JDBC Driver.
  2. Download DbUnit code, from sourceforge.
  3. On the root directory, use the command:
mvn

Writing testing code:

Create the data xml:

initialDataset.xml

<?xml version='1.0' encoding='UTF-8'?>
<dataset>
	<table_name id="1" field1="initial_field1_data1" field2="initial_field2_data1"/>
        <table_name id="2" field1="initial_field1_data2" field2="initial_field2_data2"/>
        <table_name2 id="2" other="other_data"/>
</dataset>

expectedDataset.xml

<?xml version='1.0' encoding='UTF-8'?>
<dataset>
	<table_name id="1" field1="expected_field1_data1" field2="expected_field2_data1"/>
        <table_name id="2" field1="expected_field1_data2" field2="expected_field2_data2"/>
        <table_name2 id="2" other="other_data"/>
</dataset>

Create your testing class

public class SampleTest extends TestCase
{
    private IDatabaseTester databaseTester;

Set up your connection

    protected void setUp() throws Exception
    {
        databaseTester = new JdbcDatabaseTester("org.hsqldb.jdbcDriver",
            "jdbc:hsqldb:sample", "sa", "");

Initialize your dataset here

        IDataSet dataSet = new FlatXmlDataSetBuilder().build(new File("initialDataSet.xml"));
        ITable expectedTable = expectedDataSet.getTable("TABLE_NAME");
        IDatabaseConnection connection = databaseTester.getConnection();
        databaseTester.setDataSet( dataSet );
        DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet);

       }

Testing your code

       public void testMyCode(){

Obtain your expected data

           IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(new File("expectedDataSet.xml"));
           ITable expectedTable = expectedDataSet.getTable("TABLE_NAME");

Execute your code

           //modifying database

Fetch database data after executing your code

           IDataSet databaseDataSet = databaseTester.getConnection().createDataSet();
           ITable actualTable = databaseDataSet.getTable("TABLE_NAME");

Compare your data with your expecting data

           assertEquals(expectedTable, actualTable);
        }
      }

Best practices:

Use a testing database:

You’ll need your own testing database,one you can modify trusting nobody else is accessing or modifying it.

Write independent tests:

Make a clean insert of the testing data and clean all the data when your are finished.

Use multiple small data set:

Initialize your database with the data you’ll need for that specific test.

References:

DBUnit.org.
DBUnit wiki.
Dallaway: DB Testing.

Tags: , , , , , ,

Maven

Posted by Olga on May 7, 2010 in Uncategorized
No Comments

Apache Maven is a software project management tool that  provides a standard way to build the project. It bases on project object model (POM) to describe how the project is build, order and dependencies with other modules. It also specify some development guidelines as keeping your testing and source code in a separate structure.

Maven dynamically downloads Java libraries and Maven plug-ins from one or more repositories and allows you to uploas arrtifcats to a specific repository.

Installing

  1. Download last version of maven from the maven repository.
  2. Extract the distribution archive, <maven> folder
  3. Add the M2_HOME environment variable pointing to <maven> folder, and the M2 variable pointing to %M2_HOME%\bin.
  4. Add M2 to the PATH variable
  5. Run mvn –version to verify that it is correctly installed.

Eclipse Plugin

To install m2eclipse in the Eclipse IDE:

  1. Select Help > Install New Software. This should display the “Install” dialog.
  2. Search the site http://m2eclipse.sonatype.org/sites/m2e.
  3. Choose the component listed under m2eclipse: “Maven Integration for Eclipse (Required)”.

Netbeans plugin

Maven is integrated with Netbeans 6.7+.

References

Apache Maven Project Site.

Wikipedia: Apache Maven.

m2eclipse.

Tags: , , , , ,

JUnit

Posted by Olga on April 29, 2010 in Development
No Comments

JUnit is a simple, open source framework to write and run repeatable tests.

Installing JUnit

1. Download the latest version of JUnit, from junit.org.

2. Then install JUnit on your platform:

Windows

1.Unzip the junit.zip distribution file to a directory referred to as %JUNIT_HOME%.
2. Add JUnit to the classpath:

set CLASSPATH=%CLASSPATH%;%JUNIT_HOME%\junit.jar

Unix (bash)

1.Unzip the junit.zip distribution file to a directory referred to as $JUNIT_HOME.

2.Add JUnit to the classpath:

export CLASSPATH=$CLASSPATH:$JUNIT_HOME/junit.jar

Writing Test:

1. Create a class:

        import org.junit.*;
        import static org.junit.Assert.*;
        import java.util.*;
        public class SimpleTest {

2. Write a test method (annotated with @Test):

          @Test
          public void testMethod() {

3. That asserts expected results on the object under test

              assertTrue(...);

4. Use fail for unexpected behavior.

              try {
                   ...
              } catch (Exception e) {
                   fail (...);
              }
            }
          }

Best practices:

1. Start method name with the word ‘test’.

2. Use a describing method name.

3. Test each method in an independent testing method.

4. Test can’t be dependent on each other.

5. Keep the testing classes in the same package than the tested class.

References

JUnit FAQ

Java Unit Testing: Best Practices

JUnit Best Practices

Tags: , , , ,

Unit testing

Posted by Olga on April 28, 2010 in Development
No Comments

Real stupidity beats artificial intelligence every time.

Terry Pratchett.

Testing your application cannot be reduced to test that your application normal use would work, you have to test that every piece of code works at it should.

Unit testing consist on identifying and consistently verifying each software unit, checking  inputs, state and outputs of an specific function.

To write proper unit testing, you should follow a guideline.

Identify units:

In object oriented programming, a unit might be a function or method. The scope is the determinant issue, if the scope is too narrow, the test could be too obvious, if the scope is too broad you could miss testing parts of the code.

Identify requirements:

The purpose of the unit, had to be crystal clear, no input,  output, state or functionallity can be missed.

Write the test according to the requirements:

Ideally, Test Driven Development determine writing the tests before the code. But even if you don’t do that, you should write your tests watching the requirements, not looking through the code, this way you won’t be tempted to write the tests that will work with your code, instead of writing right code that will pass the tests.

Test everything.

Not just the output, test every possible output, input and the state of the object after the execution.

References:

IEEE Standard for Software Unit Testing.

Effective unit testing.

Writing Great Unit Tests: Best and Worst Practices.

Wikipedia:Test-driven development.

Tags: , , , ,

Oracle Identity Manager: Provisioning to a Database Table

Posted by Olga on February 16, 2010 in Identity Management
No Comments

Provisioning a User to a Database Table

More information in the Provisioning a User to a Database Table tutorial.

Create or configure the database table

1.Creating the table

You can work with a already configured table or you can create your table of user data as follows:

CREATE TABLE "XLADM"."USER_DATA"
(	"USER_ID" VARCHAR2(20 BYTE) NOT NULL ENABLE,
	"FIRSTNAME" VARCHAR2(20 BYTE),
	"LASTNAME" VARCHAR2(20 BYTE),
	"ORGANIZATION" VARCHAR2(20 BYTE),
	"PASSWORD" VARCHAR2(20 BYTE),
	"EMAIL" VARCHAR2(20 BYTE),
	"COMPANY" VARCHAR2(20 BYTE),
	 CONSTRAINT "USER_DATA_PK" PRIMARY KEY ("USER_ID")
	) ;

Install the Connector

1. Download the Database Application Table Connector 9.1.0.3

from Oracle Identity Manager Connectors or download the Database Application Table Connector 9.1.0.0 from the tutorial zip.

2. Copy the unzipped folder DBAT_9103 to \ConnectorDefaultDirectory

D:\Oracle\xellerate\ConnectorDefaultDirectory\DBAT_9103

3. Installing the Connector

Deployment Management > Install Connector
Select DatabaseApplicationTables 9.1.0.3.0
Load
Continue

Create the GTC Connector

1. Generic Technology connector > Create.

2. Provide basic information:

Name: A name for the connector
Provisioning: Provision information into the resource.
Transport Provider: The method used to transfer the record contained in the flat file into Oracle identity Manager.
Format Provider: The method used to parse the record fetched by the transport provider and convert this data into a structure to be stored in Oracle Identity Manager.

Ex:

Name: DB App Users
Provisioning: yes
Transport Provider: Database Application Tables Provisioning
Format Provider: Database Application Tables Provisioning

3. Specify Parameter values for the connector

Runtime Parameters: These parameters are input variables of the selected transport and format providers. A runtime parameter represents a value not constrained by the design of the providers.

Database Driver: JDBC driver class
Database URL: JDBC URL for the target database. Value: jdbc:oracle:thin:@host_IP:1521:Database_Name
Database User ID: Database user ID (as sysdba) on the target database.
Database Password: Password of the DBA login that is used to create users.
Connection Properties

Ex (Oracle Database)

Database Drive: oracle.jdbc.driver.OracleDriver
Database URL: jdbc:oracle:thin:@localhost:1521:XELL
Database User: xladm
Database Password: Password1
Connection Properties:

Design Parameters. These parameters are either design parameters of the providers or reconciliation-specific parameters common to all GTCs.
Parent Table/View Name: Table where the user data is located.
Ex
Parent Table/View Name: USER_DATA

4. For this connector, all data fields and mappings are correct

5. Verify Connector Form Names

DBAPPS

Assign the Resource to the user

1. Select the user

Users > Manage > Search

2. Select the Resource Profile and click Provision New Resource

3. Select the Resource

DB APPS USERS_GTC


						

Tags: , , ,

Oracle Identity Manager – Flat File Reconciliation

Posted by Olga on February 11, 2010 in Identity Management
No Comments

Performing Flat-File Reconciliation.

This guide uses the following tutorial.

Create the flat file.

1. Shut down

Oracle Identity Manager Server
Administrative and User Console
Design Console.

2. Create the flat file.

Within the stage dir /GTC/External Files directory, create the flat file and call it
.
Example: D:\Oracle\xellerate\GTC\External Files\users 20100101.txt

#GTC Trusted Source
login,firstName,lastName,eMail,organization
USERTEST,usu_name,usu_lastname,usutest@example.com,Xellerate Users

3. Save the file and restart:

Oracle Identity Manager Server.
Administrative and User Console.

Creating a Generic Technology Connector (GTC)

1. Create the Connector

Generic Technology connector > Create.

2. Provide basic information:

Name: A name for the connector
Reconciling: Retrieve information from the resource.
Transport Provider: The method used to transfer the record contained in the flat file into Oracle identity Manager.
Format Provider: The method used to parse the record fetched by the transport provider and convert this data into a structure to be stored in Oracle Identity Manager.
Trusted Source.
Ex:

Name: Flatfile Users
Reconciling: yes
Transport Provider: Shared Drive
Format Provider: CSV
Trusted Source: yes

3. Specify Parameter values for the connector

Runtime Parameters. These parameters are input variables of the selected transport and format providers. A runtime parameter represents a value not constrained by the design of the providers.

Staging Directory (Parent identity data): The staging directory where the flat file is found. This file have one entry for each identity.
Staging Directory (Multivalued identity data): The staging directory where “child” files are found. These files have one entry for each value of the multivalued fields.
Archiving Directory: Processed files wil be moved to this directory. If it doesn’t exist it won’t be moved.
File Prefix: Part of the name of the file preceding the date.
Specified Delimiter: Field delimiter.
Tab Delimiter: For tabbed delimited files.
Fixed Column width: For fixed width files, not having delimiter.
Unique Attribute (Parent Data): Used for multivalued identity files, to get linked with the parent data, and identify each identity.

Ex

Staging Directory (Parent identity data): D:\Oracle\xellerate\GTC\External Files\
Staging Directory (Multivalued identity data):
Archiving Directory: D:\Oracle\xellerate\GTC\External Files\Archive
File Prefix: users
Specified Delimiter: ,
Tab Delimiter: No
Fixed Column width:
Unique Attribute (Parent Data):

Design Parameters. These parameters are either design parameters of the providers or reconciliation-specific parameters common to all GTCs.

File Encoding: Character set encoding used in the parent and data files.
Follow the encoding guide to select your encoding.
Batch Size
Stop Reconciliation Threshold
Stop Threshold Minimun Records
Source Date Format
Reconcile Deletion of Multivalued Attribute Data: To delete in the reconciliation.
Reconciliation Type: To make full reconciliation, or make incremental reconciliation.

Ex

File Encoding: UTF8
Batch Size: All
Stop Reconciliation Threshold: None
Stop Threshold Minimun Records
Source Date Format: yyyy/MM/dd hh:mm:ss z
Reconcile Deletion of Multivalued Attribute Data: No
Reconciliation Type: Full

4. Modify Connector Configuration.

Defining data fields and specifying data mappings for the connector.

The following OIM fields must be mapped to correct values.

User ID: A valid user ID as specified in the policies.
First Name
Last Name
Email
Password
Organization: An existing organization within OIM.
Employee Type: One of the available employee types. By default: Full-Time, Part-Time, Temp, Intern, Consultant
As seen in Lookup.User.Role
User Type: One of the available user types. By default: End-User, End-User Administrator

Ex

login: login: User ID
firstName: firstName: First Name
lastName: lastName: Last Name
eMail: eMail: Email
login: password: Password
(literal) Xellerate User: organization: Organization
(literal) Full-Time: employeeType: Employee Type
(literal) End-User: userType: UserType

5. Verify Connector Information.

Verify and save the GTC Connector.

6. Correct the password field.

Due to known product limitation, the variable associated with the password field is incorrect. You have to modify it from the Oracle Identity Manager Client.
Start Oracle Identity Manager Design Console
Oracle Identity Manager 9.1 > Oracle Identity Manager Client
Open your connector’s Process Definition
Process Management > Process Definition
Name: FLATFILE USERS_GTC
Search
Modify the mapping for password
Reconciliation Field Mappings > Password
User Attribute: Identity.

Launch Scheduled Task

1. Resource Management > Manage Scheduled Task

Flatfile Users_GTC

2. Click enable.

3. Launch with the Run Now button.

Tags: , ,

Oracle Identity Manager: Installation

Posted by admin on February 9, 2010 in Identity Management
No Comments

This is just a resume of I what did following the Oracle Identity Manager Installation Guide.

Installing Oracle Identity Manager on Windows.

1 – Installing WebLogic

wls1032_win32.exe

2 – Creating a WebLogic Domain, User, and Group for Oracle Identity Manager
Launch the WebLogic Configuration Wizard
Oracle WebLogic > WebLogic Server 11gR1 > Tools > Configuration Wizard
Select the Create a new WebLogic domain
Generate a domain configured automatically to support the following products:
Basic WebLogic Server Domain
Enter a domain name and location
Enter a user name, password, and confirm the password for the domain.
Select either Development Mode
Select the Sun SDK 1.6.0_14
Exit the Configuration Wizard after the domain is created

3 – Start the WebLogic application server
Oracle WebLogic > User Projects > <domain_name> > Start Admin Server

4 – Create user and Group
Log in to the WebLogic Admin Console using your new account by pointing a web browser to the following url:
http://<hostname>:7001/console
User: weblogic
Select Security Realms, then myrealm, and then User and Groups
Create a Group:
Name: User
Description <optional>
Create a User
Name: Internal
Group: User

5 – Installing Oracle 10g Release 2
10201_database_win32.zip
10201_database_win32/database/setup.exe

Basic installation

6 – Create the database
Use the Database Configuration Assistant (DBCA) tool to create the database
Oracle – OraDB110g_home1 > Configuration and Migration Tools > Database Configuration Assistant
Set the database character to AL32UTF8

7 – Prepare the database
prepare_xl_db.bat
oracle_identity_manager_9101\OIM9101\installServer\Xellerate\db\oracle\prepare_xl_db.bat
prepare_xl_db.bat <ORACLE_SID> <ORACLE_HOME> <XELL_USER> <XELL_USER_PWD> <TABLESPACE_NAME> <DATAFILE_DIRECTORY> <DATAFILE_NAME> <XELL_USER_TEMP_TABLESPACE> <SYS_USER_PASSWORD>
XELL                 Name of the database
C:\oracle\ora92     Directory where the Oracle database is installed
xladm                 Name of the Oracle Identity Manager user to be created
xladm                 Password for the Oracle Identity Manager user
xeltbs                 Name of the tablespace to be created
C:\oracle\oradata     Directory where the datafiles will be placed
xeltbs_01             Name of the datafile (you do not need to give .dbf extension)
TEMP                 Name of the temporary tablespace that already exists in your database
manager             Password for the SYS user

prepare_xl_db.bat XELL D:\ORACLE\PRODUCT\10.2.0\ORADATA\ xladm <password_xladm> xeltbs C:\oracle\oradata xeltbs_01 TEMP <password_SYSMAN>

8 – Installing Oracle Identity Manager
oracle_identity_manager_9101.zip
oracle_identity_manager_9101\OIM9101\installServer\setup_server.exe

Enter the new xelsysadm password.
Select Oracle Identity Manager
Select <xeldirectory>
Select Oracle Database
Enter your Oracle connection data
localhost
1521
XELL
xladm
<password_xladm>
Enter your weblogic configuration

9 – Run the Server
<xeldirectory>\xellerate\bin\xlStartServer.bat

Tags: , ,

HTC Tattoo: Other Applications

Posted by Olga on February 6, 2010 in Devices
No Comments

TasKiller

The HTC Tattoo has a problem, open applications never close or have an option to get close. That’s no so bad because it makes the applications to show the last state you left, this way, the browser will be open in the last page you visited.

But you’ll eventually want to close applications, to make your battery to last more. You have to go to settings, manage applications, the filter by running and select each application and force stop, at one’s own risk. That’s where TasKiller enter, it’s a free downloadable application that enable you to close applications whenever you want, without risks.

You just have to remember few things, you can’t close mail application or you won’t receive notifications when you got a new mail, and don’t close the Clock application, at least if you use mobile alarm to wake in the mornings.

More information: TasKiller page.

NewsRob

This is a Google Reader application, I wonder why there is no application for that by default, by anyway, this is a good one. It download your feeds, you can configure it to download up to 1000 articles, select if you want just the feed or the whole page, when or how you want to synchronize – interval and wifi…

The best thing is it works perfectly offline, so, after download everything to your local, you will be reading everything at the subway in your way to work.

More information: NewsRob blog.

wpToGo

This is the WordPress application for Android. It allows you to configure different WordPress blogs to be able to post from your HTC. It stores the drafts in local and you can upload as draft or published whenever you want.

The worse part is that it is a little slow to write long articles from the HTC, but as you can review it from your computer after upload it, that is not a big problem.

More Information: WordPress Android Section.

Tags: , , , ,

HTC Tattoo

Posted by Olga on January 19, 2010 in Devices
No Comments

Due to the recent lost of my mobile, I decided to have a new one, a better one.
The HTC Tattoo is an Android based smartphone, smaller than the other HTC in the market, with a resistive touchscreen.
The first thing you have to do is link your google account, it will be used for gmail, calendar, synchronizing contacts.
Then I started playing with the HTC Sense interface, quite customizable. You can add widgets and shortcuts through the seven homepages. To move or delete them you just have to long touch the widgets and rearrange to the new position or move it to the bin.
HTC Widgets:

  • Bookmarks: There are two kind of views, a four screenshots view, and a bookmarks’ list view.
  • Calendar: It’s google calendar widget, you can have a fill monthly view, or a next task view.
  • Clock: There are twelve different clock views, including a digital one situación weather information, or a two cities’ time view.
  • Footprints: You can trace where have you been using GPS and camera. You can have it in big or small view.
  • Mail: Shows the last mails you have had of your other email account you configured.
  • Messages: It shows a list of the last SMS text messages received.
  • Music: You can play the music you have on your SD card, there is a big and small view.
  • People: It’s a 9 or 3 favorite people shortcut. Each favorite person with the selected preferred action (phone call, email, sms, …)
  • Photo album/frame: Big or small slideshow of your photos.
  • Search: A google search toolbar.
  • Settings: You can add a setting shortcut as Airplane Mode, Bluetooth, GPS, Mobile connection or Wifi, where you can enable or disable them.
  • Twitter: Can be a list of the last twitts you have, or a quick update input text.
  • Weather: Shows the weather of the chosen city.

It also give access to the standar Android Widgets:

  • Analog clock.
  • Calendar.
  • Music.
  • Picture frame.
  • Power control.
  • Search.

I missed some applications in the default list, even though it was very complete:

  • Albums: Photos and default images.
  • Browser
  • Calculator: Must be mobile application.
  • Calendar: Google calendar, you can add events to your calendar and see every calendar. You can use it offline.
  • Camcorder
  • Camera
  • Clock
  • FM Radio
  • Footprints: You can trace where have you been using GPS and camera.
  • Gmail: It manages labels and download lasts email so you can use it offline.
  • Google talk
  • Mail
  • Maps
  • Market: Where you buy or download new applications
  • Messages: Text messages.
  • Music
  • Peep: Twitter application.
  • People: Agenda.
  • Phone
  • Settings
  • SIM Toolkit
  • USB to PC
  • Voice Recorder
  • Weather
  • YouTube

Tags: ,

Copyright © 2006-2012 Too weak to give in All rights reserved.
Shades v1.5.1 theme from BuyNowShop.com.