http://git-wip-us.apache.org/repos/asf/james-project/blob/a37176fb/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/ServiceMockProvider.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/ServiceMockProvider.java b/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/ServiceMockProvider.java new file mode 100644 index 0000000..669b92c --- /dev/null +++ b/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/ServiceMockProvider.java @@ -0,0 +1,33 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.mpt.onami.test.data; + +import org.easymock.EasyMock; + +public class ServiceMockProvider +{ + + public static Service providerMethod() + { + Service mockedService = EasyMock.createNiceMock( Service.class ); + return mockedService; + } + +}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a37176fb/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/ServiceModule.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/ServiceModule.java b/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/ServiceModule.java new file mode 100644 index 0000000..14400d5 --- /dev/null +++ b/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/ServiceModule.java @@ -0,0 +1,35 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.mpt.onami.test.data; + +import com.google.inject.AbstractModule; + +public class ServiceModule + extends AbstractModule +{ + + @Override + protected void configure() + { + bind( Service.class ).to( ServiceImpl.class ).asEagerSingleton(); + bind( TelephonService.class ).to( TelephonServiceImpl.class ).asEagerSingleton(); + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/a37176fb/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/SimpleModule.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/SimpleModule.java b/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/SimpleModule.java new file mode 100644 index 0000000..6694dd6 --- /dev/null +++ b/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/SimpleModule.java @@ -0,0 +1,34 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.mpt.onami.test.data; + +import com.google.inject.AbstractModule; + +public class SimpleModule + extends AbstractModule +{ + + @Override + protected void configure() + { + bind( HelloWorld.class ); + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/a37176fb/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/TelephonService.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/TelephonService.java b/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/TelephonService.java new file mode 100644 index 0000000..906ddad --- /dev/null +++ b/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/TelephonService.java @@ -0,0 +1,27 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.mpt.onami.test.data; + +public interface TelephonService +{ + + String getTelephonNumber(); + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/a37176fb/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/TelephonServiceImpl.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/TelephonServiceImpl.java b/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/TelephonServiceImpl.java new file mode 100644 index 0000000..b61384e --- /dev/null +++ b/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/TelephonServiceImpl.java @@ -0,0 +1,31 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.mpt.onami.test.data; + +public class TelephonServiceImpl + implements TelephonService +{ + + public String getTelephonNumber() + { + return "It's real class"; + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/a37176fb/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/TestAnnotation.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/TestAnnotation.java b/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/TestAnnotation.java new file mode 100644 index 0000000..04a3b42 --- /dev/null +++ b/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/TestAnnotation.java @@ -0,0 +1,32 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.mpt.onami.test.data; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.inject.Qualifier; + +@Qualifier +@Retention( RetentionPolicy.RUNTIME ) +public @interface TestAnnotation +{ + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/a37176fb/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/TestAnnotation2.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/TestAnnotation2.java b/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/TestAnnotation2.java new file mode 100644 index 0000000..48e1440 --- /dev/null +++ b/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/TestAnnotation2.java @@ -0,0 +1,32 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.mpt.onami.test.data; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.inject.Qualifier; + +@Qualifier +@Retention( RetentionPolicy.RUNTIME ) +public @interface TestAnnotation2 +{ + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/a37176fb/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/WhoIm.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/WhoIm.java b/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/WhoIm.java new file mode 100644 index 0000000..b18bb2b --- /dev/null +++ b/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/data/WhoIm.java @@ -0,0 +1,37 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.mpt.onami.test.data; + +public class WhoIm +{ + + private final String name; + + public WhoIm( String name ) + { + this.name = name; + } + + public String sayWhoIm() + { + return name; + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/a37176fb/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/guice/MockAnnotatedWithTestCase.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/guice/MockAnnotatedWithTestCase.java b/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/guice/MockAnnotatedWithTestCase.java new file mode 100644 index 0000000..94cd32c --- /dev/null +++ b/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/guice/MockAnnotatedWithTestCase.java @@ -0,0 +1,76 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.mpt.onami.test.guice; + +import org.apache.james.mpt.onami.test.OnamiRunner; +import org.apache.james.mpt.onami.test.annotation.Mock; +import org.apache.james.mpt.onami.test.data.HelloWordAnnotated; +import org.apache.james.mpt.onami.test.data.Service; +import org.apache.james.mpt.onami.test.data.TestAnnotation; +import org.easymock.EasyMock; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.inject.Inject; + +@RunWith( OnamiRunner.class ) +public class MockAnnotatedWithTestCase +{ + + @Mock( annotatedWith = TestAnnotation.class ) + private Service service2; + + @Mock + private Service service; + + @Mock( namedWith = "test.named" ) + private Service serviceNamed; + + @Inject + private HelloWordAnnotated seviceImplAnnotated; + + @Test + public void test() + throws Exception + { + Assert.assertNotNull( service2 ); + Assert.assertNotNull( service ); + Assert.assertNotNull( serviceNamed ); + } + + @Test + public void test3() + throws Exception + { + Assert.assertNotNull( service2 ); + Assert.assertNotNull( serviceNamed ); + + EasyMock.expect( service2.go() ).andReturn( "Mocked injected class annotated" ).anyTimes(); + EasyMock.expect( serviceNamed.go() ).andReturn( "Mocked injected class named" ).anyTimes(); + EasyMock.replay( service2, serviceNamed ); + + Assert.assertEquals( "Mocked injected class annotated", service2.go() ); + Assert.assertEquals( "Mocked injected class annotated", seviceImplAnnotated.go() ); + Assert.assertEquals( "Mocked injected class named", seviceImplAnnotated.getNamed() ); + EasyMock.verify( service2 ); + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/a37176fb/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/guice/TestCustomInjectionTest.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/guice/TestCustomInjectionTest.java b/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/guice/TestCustomInjectionTest.java new file mode 100644 index 0000000..1fde58d --- /dev/null +++ b/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/guice/TestCustomInjectionTest.java @@ -0,0 +1,82 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.mpt.onami.test.guice; + +import org.apache.james.mpt.onami.test.OnamiRunner; +import org.apache.james.mpt.onami.test.annotation.GuiceModules; +import org.apache.james.mpt.onami.test.annotation.Mock; +import org.apache.james.mpt.onami.test.data.HelloWorld; +import org.apache.james.mpt.onami.test.data.Service; +import org.apache.james.mpt.onami.test.data.ServiceModule; +import org.apache.james.mpt.onami.test.data.TelephonService; +import org.easymock.EasyMock; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.inject.Inject; + +@RunWith( OnamiRunner.class ) +@GuiceModules( ServiceModule.class ) +public class TestCustomInjectionTest +{ + + @Mock + private static Service service; + + @Inject + private TelephonService telephonService; + + @Inject + private HelloWorld helloWorld; + + @BeforeClass + public static void setUp() + { + Assert.assertNotNull( service ); + // service.go(); + } + + @Test + public void test() + throws Exception + { + Assert.assertNotNull( service ); + Assert.assertNotNull( telephonService ); + Assert.assertNotNull( helloWorld ); + } + + @Test + public void testOverideModule() + throws Exception + { + Assert.assertNotNull( service ); + Assert.assertNotNull( telephonService ); + Assert.assertEquals( "It's real class", telephonService.getTelephonNumber() ); + + EasyMock.expect( service.go() ).andReturn( "Mocked injected class" ); + EasyMock.replay( service ); + + Assert.assertEquals( "Mocked injected class", helloWorld.sayHalloByService() ); + EasyMock.verify( service ); + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/a37176fb/mpt/onami-test/src/test/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/test/resources/log4j.properties b/mpt/onami-test/src/test/resources/log4j.properties new file mode 100644 index 0000000..3836f2c --- /dev/null +++ b/mpt/onami-test/src/test/resources/log4j.properties @@ -0,0 +1,46 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +# Set root category priority to INFO and its only appender to CONSOLE. +#log4j.rootCategory=DEBUG, CONSOLE + +# Set the enterprise logger category to FATAL and its only appender to CONSOLE. +#log4j.logger.org.apache.onami=CONSOLE + +# CONSOLE is set to be a ConsoleAppender using a PatternLayout. +#log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender +#log4j.appender.CONSOLE.Threshold=DEBUG +#log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout +#log4j.appender.CONSOLE.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n + + + +# Specify the handlers to create in the root logger +# (all loggers are children of the root logger) +# The following creates two handlers +handlers = java.util.logging.ConsoleHandler + +# Set the default logging level for the root logger +.level = ALL + +# Set the default logging level for new ConsoleHandler instances +java.util.logging.ConsoleHandler.level = ALL + +# Set the default formatter for new ConsoleHandler instances +java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter http://git-wip-us.apache.org/repos/asf/james-project/blob/a37176fb/mpt/pom.xml ---------------------------------------------------------------------- diff --git a/mpt/pom.xml b/mpt/pom.xml index 3b06028..bbe1466 100644 --- a/mpt/pom.xml +++ b/mpt/pom.xml @@ -47,6 +47,7 @@ <module>impl/managesieve</module> <module>impl/smtp</module> <module>mavenplugin</module> + <module>onami-test</module> </modules> <issueManagement> --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
