How to deal with properties in Spring context tests?

@ComponentScan("my.company.example*")
@Configuration
@PropertySource("classpath:/my/company/props/from/file/test.properties")
public class MyTestConfig {

static {
System.setProperty("my.company.hard.coded.props.example", "true"); 
}

/** properties loading */
@Bean
public static PropertySourcesPlaceholderConfigurer properties() {
final PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer();
pspc.setProperties(System.getProperties());
return pspc;
}
}

Usage:

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = MyTestConfig.class)
public class MySpringTest {

Java SSH Client

http://www.yegor256.com/2014/09/02/java-ssh-client.html

String hello = new Shell.Plain(
  new SSH(
    "ssh.example.com", 22,
    "yegor", "-----BEGIN RSA PRIVATE KEY-----..."
  )
).exec("echo 'Hello, world!'");

Java console program + Maven

Use “Assembler Plugin”:

http://www.mojohaus.org/appassembler/appassembler-maven-plugin/usage-program.html

How it looks:

$ mvn package appassembler:assemble
...
$ sh target/appassembler/bin/app
Hello World!

Linux renaming many files

My task was to rename many i18n files, because of technology migration. I found following solution:

rename 's/app_/messages_/' app*properties

Example of result:

app_it.properties -> messages_it.properties

DynamicReports – tool for generating Java reports pdf/docx/xlsx

Undoubtedly the most popular library for Java reporting is Jasper Reports. However in case of new projects is also nice to look for better approaches.

If you look at alternatives to Jasper Reports, you will find tones of similar products -> http://alternativeto.net/software/jasperreports/.

I had a few picks, but decided to test only DynamicReports. Here is why:

After creating one pretty simple layout I find out some questions:

  • how to effectively test changes in layout design? I’ve used “JasperReportBuilder.show();”, but I’m not sure it’s the best option.
  • is any way to share “JasperReportBuilder” across many threads and pass only some parameters when compiling reports? So far in header and summary section I was creating components initialized with data, which I think is not good for performance.
  • what is the right design pattern for class implementing reports with “JasperReportBuilder”? Example of class creating invoice report, called “InvoiceDesign.java”, has one huge method “build()” packed with styles and setup of “JasperReportBuilder”. I know it’s only demo, but also I was expecting some production-ready examples.

Summary:

I like DynamicReports mainly because it’s pure Java. Support for JasperReports is also encouraging. If I develop answers for above questions, I’m sure I will use it in the future.