Showing posts with label Software Development. Show all posts
Showing posts with label Software Development. Show all posts
Monday, April 2, 2012
restorecon command: fixes the corrupted files in linux
SOme times some files may get corrupted and may shows errors as shown below:
Cannot load /etc/httpd/modules/mod_jk.so into server: /etc/httpd/modules/mod_jk.so: failed to map segment from shared object: Permission denied
The only and easiest way to solve this problem is to use the restorecon command
Ex: [root@mulmu01-VM6783 httpd]# apachectl start
Syntax error on line 4 of /etc/httpd/conf.d/tomcat.conf:
Cannot load /etc/httpd/modules/mod_jk.so into server: /etc/httpd/modules/mod_jk.so: failed to map segment from shared object: Permission denied
[root@mulmu01-VM6783 httpd]# restorecon -v /etc/httpd/modules/mod_jk.so
restorecon reset context /usr/lib/httpd/modules/mod_jk.so:root:object_r:usr_t->system_u:object_r:httpd_modules_t
[root@mulmu01-VM6783 httpd]# apachectl start
[root@mulmu01-VM6783 httpd]#
Saturday, March 31, 2012
How to automate Email testing
If you are looking for a solution to automate the email testing i.e.. sending an email and verifying the reception, I prefer using WISER a dummy email server:
Wiser is a simple SMTP server that you can use for unit testing applications that send mail. It accepts all messages and stores them in an internal ArrayList. Your unit test code can then examine the messages (or lack thereof) and verify their validity.
WISER IS NOT A MAIL SERVER. If you want to receive email and then "do something" with the mail, simply implement the MessageHandler or MessageListener interfaces. Look at the (very short) Wiser code as an example.
if (wiser.getMessages().size() > 0) {
WiserMessage wMsg = wiser.getMessages().get(0);
MimeMessage msg = wMsg.getMimeMessage();
System.out.println( msg.getSubject() );
}
Good Luck!!!
Wiser:
Wiser is a simple SMTP server that you can use for unit testing applications that send mail. It accepts all messages and stores them in an internal ArrayList. Your unit test code can then examine the messages (or lack thereof) and verify their validity.
WISER IS NOT A MAIL SERVER. If you want to receive email and then "do something" with the mail, simply implement the MessageHandler or MessageListener interfaces. Look at the (very short) Wiser code as an example.
How To Use It
Include the following jars on your classpath:- subethasmtp.jar
- slf4j-api-X.X.X.jar
- One of the slf4j connectors such as slf4j-simple-X.X.X.jar
- JavaMail (mail.jar and activation.jar)
Sample code:
package com.ca.example;
import org.junit.*;
import org.subethamail.wiser.Wiser;
import org.subethamail.wiser.WiserMessage;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import org.junit.*;
import org.subethamail.wiser.Wiser;
import org.subethamail.wiser.WiserMessage;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class WiserJUnitTest {
private Wiser wiser;
@Before
public void setup() {
wiser = new Wiser(2500);
wiser.setHostname("localhost");
wiser.setPort(2500);
wiser.start();
System.out.println("Wiser SMTP server started.");
}
@Test
public void sendTest() throws Exception {
/**
* Creating and sending an email using Java Mail API
*/
Properties props = new Properties();
props.put("mail.smtp.host", "localhost");
props.put("mail.smtp.port", "2500");
props.put("mail.smtp.user", "username");
props.put("mail.smtp.password", "password");
Session session = Session.getInstance(props);
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("from@company.com"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("to@company.com"));
message.setSubject("Testing Subject");
message.setText("This is just a test e-mail! ");
message.setHeader("Organization", "company.com");
// Transport.send(message);
System.out.println("Done sending this email :" + message);
System.out.println("Wiser messages count:"+wiser.getMessages().size());
Assert.assertEquals("No mail messages found", 1, wiser.getMessages().size());
private Wiser wiser;
@Before
public void setup() {
wiser = new Wiser(2500);
wiser.setHostname("localhost");
wiser.setPort(2500);
wiser.start();
System.out.println("Wiser SMTP server started.");
}
@Test
public void sendTest() throws Exception {
/**
* Creating and sending an email using Java Mail API
*/
Properties props = new Properties();
props.put("mail.smtp.host", "localhost");
props.put("mail.smtp.port", "2500");
props.put("mail.smtp.user", "username");
props.put("mail.smtp.password", "password");
Session session = Session.getInstance(props);
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("from@company.com"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("to@company.com"));
message.setSubject("Testing Subject");
message.setText("This is just a test e-mail! ");
message.setHeader("Organization", "company.com");
// Transport.send(message);
System.out.println("Done sending this email :" + message);
System.out.println("Wiser messages count:"+wiser.getMessages().size());
Assert.assertEquals("No mail messages found", 1, wiser.getMessages().size());
WiserMessage wMsg = wiser.getMessages().get(0);
MimeMessage msg = wMsg.getMimeMessage();
System.out.println( msg.getSubject() );
}
Good Luck!!!
Subscribe to:
Posts (Atom)