Labels

Saturday, 30 January 2016

Generate SSH Public Key

SSH Connection to Github account

1. checking existing SSH keys

$ ls -al ~/.ssh
# Lists the files in your .ssh directory, if they exist

2. Add existing SSH Key to Github account

$ pbcopy < ~/.ssh/id_rsa.pub
Then add this copied key to Github account SSH Key 

3. Test SSH connection

$ ssh -T git@github.com
after a few steps and add passphrase, it will successfully with below msg - 
"Hi wzunix! You've successfully authenticated, but GitHub does not provide shell access."
If get error git@github.com: Permission denied (publickey).
Solution: Generate a new SSH Key

4. Generate a new SSH Key and add to ssh-agent

$

5. Changing passphrase for SSH Key

sudo ssh-keygen -p -f ~/.ssh/id_rsa
Note: Need to use 'sudo', otherwise will get 'Saving key "/Users/wzunix/.ssh/id_rsa" failed: Permission denied'



Step 2: Add new SSH key to Github account:













Step 2.1 on Github page, Add SSH Key



Step 1: To generate a new SSH key, copy and paste the text below, making sure to substitute in your email address. The default settings are preferred, so when you're prompted to "Enter a file in which to save the key", just press Enter to continue.
ssh-keygen -t rsa -C "your_email@example.com"
# Creates a new ssh key, using the provided email as a label
# Generating public/private rsa key pair.
# Enter file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]
Next, you'll be asked to enter a passphrase.
Strongly recommend a very good, secure passphrase. For more information, see Working with SSH key passphrases.
# Enter passphrase (empty for no passphrase): [Type a passphrase]
# Enter same passphrase again: [Type passphrase again]
Which should give you something like this:
# Your identification has been saved in /Users/you/.ssh/id_rsa.
# Your public key has been saved in /Users/you/.ssh/id_rsa.pub.
# The key fingerprint is:
# 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com
Then add your new key to the ssh-agent:
# start the ssh-agent in the background
eval "$(ssh-agent -s)"
# Agent pid 59566
ssh-add ~/.ssh/id_rsa

Sunday, 19 January 2014

JUnit

1. Declare this is a Test method:
@Test 
public void method()

2. This method is executed before each Test:
Note: used to prepare the test environment (i.e. Read input files..)
@Before
public void method()

3. This method is executed after each Test:
Note: To cleanup environment (i.e. Delete temporary file, data..)
@After
public void method()

4.This method is executed ONLY once before start of All tests.
Note: To perform time intensive activities (i.e. DB connections..) 
@BeforeClass
public static void method()

5. This method is executed ONLY once after all tests.
Note: i.e. To disconnect DB
@AfterClass
public static void method()

6. To ignore one test method:
Note: Do not execute this method
@Ignore
some_method()

7, Fail the test if the method takes longer than n milliseconds:
Note: Fails the test if it takes > 100 milliseconds
@Test(timeout=100)
some_method()

8. Fail the test if method NOT throwing the named exception;
Note; Test has to throw out the specified exception.
@Test(expected=Some_Exception.class)
some_method()

9. Hamcrest
assertThat( actual, is(expected value));
































Hamcrest comes with a library of useful matchers. Here are some of the most important ones.
  • Core
    • anything - always matches, useful if you don't care what the object under test is
    • describedAs - decorator to adding custom failure description
    • is - decorator to improve readability - see "Sugar", below
  • Logical
    • allOf - matches if all matchers match, short circuits (like Java &&)
    • anyOf - matches if any matchers match, short circuits (like Java ||)
    • not - matches if the wrapped matcher doesn't match and vice versa
  • Object
    • equalTo - test object equality using Object.equals
    • hasToString - test Object.toString
    • instanceOfisCompatibleType - test type
    • notNullValuenullValue - test for null
    • sameInstance - test object identity
  • Beans
    • hasProperty - test JavaBeans properties
  • Collections
    • array - test an array's elements against an array of matchers
    • hasEntryhasKeyhasValue - test a map contains an entry, key or value
    • hasItemhasItems - test a collection contains elements
    • hasItemInArray - test an array contains an element
  • Number
    • closeTo - test floating point values are close to a given value
    • greaterThangreaterThanOrEqualTolessThanlessThanOrEqualTo - test ordering
  • Text
    • equalToIgnoringCase - test string equality ignoring case
    • equalToIgnoringWhiteSpace - test string equality ignoring differences in runs of whitespace
    • containsStringendsWithstartsWith - test string matching

Maven - Troubleshooting

1. Re-download MAVEN repository: 
Only download repository dependency, not test the code.
  • mvn clean compile -DskipTests=true
2. Proxy - (In case proxy used in Workplace): 
   Note: Set Proxy first; then download repository
    2.1 Locate "Auto Proxy Script"
  • Control Panel/ Internet Options/ Connections Tab/ LAN Settings 
    2.2 Download "Proxy Data File"
    2.3 Select a proxy setting as below:
  • var some_id = "PROXY some_host.com:some_port";
    2.4 Now set proxy in settings.xml config file:
         Note: some one save it under .../.m2/ folder 
  • Open settings.xml from %M2_HOME%\conf directory
  • Edit settings.xml as below:
      <proxy>
              <id> some_id </id>
              <active> true </active>
              <protocol> http </protocol>
              <host> some_host </host>
              <port> some_port </port>
      </proxy>

3. Force Maven to Re-download A particular Repository
    When Maven encounters a problem and unable to download A repository --> We need to use this command to re-download that Repo after problem has been solved.

  • mvn dependency:purge-local-repository
4. Force Maven to Update dependencies
    Note: Used for update the jar files
  • mvn clean compile -U -DskipTests=true