Sunday, July 15, 2018

How can I listen for keypress event on the whole page in AngularJS 2 – 6

Add following line on @component decorator class
host: {‘(document:keypress)’: ‘handleKeyboardEvent($event)’}
and implement handleKeyboardEvent(event:KeyboardEvent)
i.e.
@Component({
selector:’app-add-component’,
templateUrl:’./add-component.component.html’,
styleUrls: [‘./add-component.component.css’],
// tslint:disable-next-line:use-host-property-decorator
host: {‘(document:keypress)’:’handleKeyboardEvent($event)’}
})
handleKeyboardEvent(event: KeyboardEvent) {
console.log(event);
if (event.keyCode===13)
{
console.log(“Enter key pressed 13”);
} else if (event.keyCode === 40)
{
} else if (event.keyCode === 38)
{
}
}

How to disable browser back button in AngularJS 2 to 6

Use location.onPopState to the same in AppComponent
import { PlatformLocation } from ‘@angular/common’;
constructor(location: PlatformLocation, private router: Router) {
location.onPopState(() => {
console.log(‘pressed back in add!!!!!’);
//this.router.navigateByUrl(‘/multicomponent’);
//history.forward();
});

Tuesday, June 05, 2018

How to do JUnit for Servlet class

Mockito class can be used to do JUnit for your servlet
Lets say we have following below given servlet in our code
package com.siddhu;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class HelloWorldServlet extends HttpServlet {
private static final long serialVersionUID = 1031422249396784970L;
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
out.print("Hello World from Servlet");
out.flush();
out.close();
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
doGet(request, response);
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// TODO Auto-generated method stub
}
}
And we want to do Junit for this servlet follow below given steps
1- If you project is MAVEN add follwing line in your POM.xml
org.mockito
mockito-all
1.9.5
test
junit
junit
4.12
test
2- If your project is normale dynamic project please add above jar to your project build path
3- Create a new class in the same package for doing JUnit
package com.siddhu;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;
import java.io.PrintWriter;
import java.io.StringWriter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.junit.Test;
import org.mockito.Mockito;
public class TestHelloWorldServlet extends Mockito{
@Test
public void testServlet() throws Exception {
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
//Way to set parameter in servlet
/*when(request.getParameter("username")).thenReturn("me");
when(request.getParameter("password")).thenReturn("secret");*/
StringWriter stringWriter = new StringWriter();
PrintWriter writer = new PrintWriter(stringWriter);
when(response.getWriter()).thenReturn(writer);
new HelloWorldServlet().doPost(request, response);
//verify(request, atLeast(1)).getParameter("username"); // Checking the value if username as same from calling servlets
writer.flush(); // it may not have been flushed yet...
assertTrue(stringWriter.toString().contains("Hello World from Servlet"));
}
}
3- If you are using Eclipse run the above class as right click --> run as --> Junit Test and you will find below screen
Image1

Wednesday, May 16, 2018

Creating new Project in AngularJS6

1- Create new angularJS2 project using Eclipse Plugin i.e. AddSubDivMultiProjectAngularJS6
2- Use Terminal Prospective and run following command inside it ng serve
i.e. cd c:\ng serve\AddSubDivMultiProjectAngularJS6
3- Refresh the project in Eclipse
4- Run following command on terminal
/c/eclipse_workspace_angularjs2/AddSubDivMultiProjectAngularJS6 (master)
$ ng serve
** Angular Live Development Server is listening on localhost: 4200, open your browser on http://localhost:4200/ **
Date: 2018-05-16T10:07:23.618Z
Hash: 7aa519b4302c2dcafe34
Time: 16419ms
chunk {main} main.js, main.js.map (main) 446 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 415 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 5.4 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 149 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 5.14 MB [initial] [rendered]
i ?wdm?: Compiled successfully.
i ?wdm?: Compiling...
Date: 2018-05-16T10:09:11.742Z - Hash: a4781c06eea8b6e93b0c - Time: 1178ms
4 unchanged chunks
chunk {main} main.js, main.js.map (main) 446 kB [initial] [rendered]
i ?wdm?: Compiled successfully.
Note:
- If during execution if you are gettin errors like TS2307: Cannot find module 'rxjs-compat/Observable'.
Make sure to run
/c/eclipse_workspace_angularjs2/AddSubDivMultiProjectAngularJS6 (master)
$ npm install rxjs-compat --save
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
+ rxjs-compat@6.1.0
added 1 package in 30.978s

- If getting below error
ERROR in src/app/app.module.ts(13,31): error TS2307: Cannot find module 'primeng/primeng'.
src/app/app.module.ts(14,28): error TS2307: Cannot find module 'primeng/primeng'.
Execute :-
/c/eclipse_workspace_angularjs2/AddSubDivMultiProjectAngularJS6 (master)
$ npm install primeng --save
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
+ primeng@5.2.6
added 1 package in 50.168s

Eclipse

Thursday, March 22, 2018

How to configure Local Email server hMailServer and Thunderbird

1- First installed the hMailServer from the follwing url.
https://www.hmailserver.com/download
2- Installed ThunderBird from below given location
https://www.mozilla.org/en-US/thunderbird/
3- Configure hMailserver and Thunderbird Email agent as given below

Image1Image2Image3Image4Image5Image6Image7






Image9Image10Image11Image12Image13Image14

Saturday, March 17, 2018

Deploying the war file in tomcat using Bamboo

Please refer to this link before moving



http://siddharathadhumale.blogspot.in/2018/03/bamboo-with-bitbucket-maven-project.html

http://siddharathadhumale.blogspot.in/2018/03/check-out-code-from-bitbucket-build.html

Image1Image2Image3

Check out code from Bitbucket-Build Maven, Stop Tomcat, Re-Deploy new war files Using Bamboo


Please refer to the above the link to first configure project, plan and creating task to create deployable war file using Bombat for Bitbucket repository.

http://siddharathadhumale.blogspot.in/2018/03/bamboo-with-bitbucket-maven-project.html


Image1Image2Image3Image4Image5Image6Image7Image8

Bamboo with BitBucket Maven Project

Step 1:- Create Bamboo project

Image1Image2

Step 2:- Create Plan

Image3Image4Image5

Step3:- Configure Task in the above created Plan.

Image6

If you see in above image it shown one task already created and that is checking out of the code in repository
Lets create a new Task that will execute the Maven Build i.e. build.xml from our Maven project kept at BitBucket using bamboo tool.
Click on "Add task" button and as we are using Maven 3 we will configure the same in the Bamboo.
Image7Image8Image9
cick on save and create button.
Step4:- Execute the task and see the build is prepared.

Image10Image11Image12

Step 5:- Check if our war is created properly at given locations.

Please note while using Bamboo version of 6.4.0 we were facing issue with Test Connection button and it was throwing error "git credentials storage exception". So we had taken lower version 6.3.2 and it work like charm.