Irmina

Spring testing support

License

License

Categories

Categories

Geo Business Logic Libraries Geospatial MINA Net Networking
GroupId

GroupId

com.geodevv.testing
ArtifactId

ArtifactId

irmina
Last Version

Last Version

1.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

Irmina
Spring testing support
Project URL

Project URL

http://irmina.geodevv.com
Project Organization

Project Organization

Geodevv
Source Code Management

Source Code Management

https://github.com/przemekgalazka/irmina

Download irmina

How to add to project

<!-- https://jarcasting.com/artifacts/com.geodevv.testing/irmina/ -->
<dependency>
    <groupId>com.geodevv.testing</groupId>
    <artifactId>irmina</artifactId>
    <version>1.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.geodevv.testing/irmina/
implementation 'com.geodevv.testing:irmina:1.0.2'
// https://jarcasting.com/artifacts/com.geodevv.testing/irmina/
implementation ("com.geodevv.testing:irmina:1.0.2")
'com.geodevv.testing:irmina:jar:1.0.2'
<dependency org="com.geodevv.testing" name="irmina" rev="1.0.2">
  <artifact name="irmina" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.geodevv.testing', module='irmina', version='1.0.2')
)
libraryDependencies += "com.geodevv.testing" % "irmina" % "1.0.2"
[com.geodevv.testing/irmina "1.0.2"]

Dependencies

compile (9)

Group / Artifact Type Version
javax.inject : javax.inject jar 1
org.slf4j : slf4j-api jar 1.7.7
junit : junit jar 4.11
org.mockito : mockito-all jar 1.9.5
com.google.guava : guava jar 17.0
org.springframework : spring-test jar 3.2.12.RELEASE
org.springframework : spring-beans jar 3.2.12.RELEASE
org.springframework : spring-tx jar 3.2.12.RELEASE
org.springframework : spring-context jar 3.2.12.RELEASE

test (3)

Group / Artifact Type Version
ch.qos.logback : logback-classic jar 1.1.2
org.assertj : assertj-core jar 1.6.0
com.googlecode.catch-exception : catch-exception jar 1.2.0

Project Modules

There are no modules declared in this project.

What is it?

Irmina is Spring integration tests runner

@RunWith(IrminaRunner.class)

Irmina mocks all your new, not provided dependencies. Also adds extra behavior to your mocks when needed while spring context bootstraps

define(SuspensionDesign.class).named("AudiA4")
                    .asMockWithBehavior(new Behavior<SuspensionDesign>() {
                        @Override
                        public void teach(SuspensionDesign bean) throws Exception {
                            given(bean.getVersion()).willReturn("v2");
                        }
                    });

Irmina lets you decide if you need mock, spy or implementation at certain injection point

define(Engine.class).named("AudiA4-engine").asMock();

Irmina will mock out all dependencies you did not included in configuration but are needed (like DAO layer or DataSource)

Examples

Irmina mocks out not provieded injection points definitons

@ContextConfiguration(classes = SampleConfiguration.class)
@TestExecutionListeners(IrminaTestContextListener.class)
@RunWith(IrminaRunner.class)
public class MockInjectionTest {

    @Inject
    @Bmw
    Vehicle bmw;

    @Inject
    @Named("Mustang")
    Vehicle mustang;

    // this is not defined in configuration - mock will be injected
    @Inject
    @Named("V6")
    Engine mustangEngine;  

    @Test
    public void shouldInjectBmwX5() {
        //expect
        assertThat(bmw).isInstanceOf(BmwX5.class);
    }

    @Test
    public void shouldInjectMockEngineForFordMustang() {
        // when
        mustang.start();
        //expect
        verify(mustangEngine).turnOn();
    }
}

Irmina will mock or spy what you want - any injection point

@ContextConfiguration(classes = SampleConfiguration.class,
        loader = MockingOutStandardInjectionPointsTest.ContextLoader.class)
@TestExecutionListeners(IrminaTestContextListener.class)
@RunWith(SpringJUnit4ClassRunner.class)
public class MockingOutStandardInjectionPointsTest {

    @Inject
    @Bmw
    Vehicle bmw;
     
    // this is defined in configuration but mock will be injected 
    @Inject
    @Bmw
    Engine bwmEngine;

    @Test
    public void shouldInjectMockEngineForFordBmw() {
        // when
        bmw.start();
        //expect
        verify(bwmEngine).turnOn();
    }

    static class ContextLoader extends IrminaContextLoader {
        @Override
        public void defineMocksAndSpies() {
            // this will be injected as mock even though its implementation is available in configuration
            define(Engine.class).annotated(Bmw.class).asMock();  
        }
    }
}

Use mockito annotations on fields if you want

@ContextConfiguration(classes = SampleConfiguration.class,
        loader = MockingOutNamedBeansButWithScanningForMockTest.ContextLoader.class)
@TestExecutionListeners(IrminaTestContextListener.class)
@RunWith(IrminaRunner.class)
public class MockingOutNamedBeansButWithScanningForMockTest {

    @Inject
    @Named("AudiA4") Vehicle audi;

    @Inject @Mock
    @Named("AudiA4-engine") Engine audiEngine;

    @Test
    public void shouldInjectMockEngineForAudi() {
        // when
        audi.start();
        //expect
        verify(audiEngine).turnOn();
    }

    static class ContextLoader extends IrminaContextLoader {
        @Override
        public void defineMocksAndSpies() {
            registerSpiesAndMockByScanningTestClass(MockingOutNamedBeansButWithScanningForMockTest.class);
        }
    }

}

Maven dependency

        <dependency>
            <groupId>com.geodevv.testing</groupId>
            <artifactId>irmina</artifactId>
            <version>1.0.2</version>
            <scope>test</scope>
        </dependency>

Usage

Add configuration to your test

@ContextConfiguration(classes = {your spring configuration}.class,
        loader = {your test class name}.ContextLoader.class)
@TestExecutionListeners(IrminaTestContextListener.class)
@RunWith(IrminaRunner.class)

Setup mock if needed

   static class ContextLoader extends IrminaContextLoader {

        @Override
        public void defineMocksAndSpies() {
            // this will be injected as mock even though its implementation is available in configuration
            define(Engine.class).annotated(Bmw.class).asMock(); 
        }
    }

or with using @Mock

...
@Inject @Mock
@Named("AudiA4-engine") Engine audiEngine;
...
static class ContextLoader extends IrminaContextLoader {
        @Override
        public void defineMocksAndSpies() {
            registerSpiesAndMockByScanningTestClass(MockingOutNamedBeansButWithScanningForMockTest.class);
        }
}
...

##Dependencies

  • Spring 3.2.12.RELEASE
  • Mockito mockito-all 1.9.5

##Latest Release

  • 1.0.2

Versions

Version
1.0.2
1.0.1
1.0.0