ignite-1865: Need to add tests on SpringResource annotation

Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/db221f52
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/db221f52
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/db221f52

Branch: refs/heads/ignite-1282
Commit: db221f52ef895d475e399f8cec49b75aeba4817d
Parents: dc32789
Author: Roman Shtykh <app...@gmail.com>
Authored: Mon Nov 16 14:34:24 2015 +0300
Committer: dmagda <magda7...@gmail.com>
Committed: Mon Nov 16 14:34:24 2015 +0300

----------------------------------------------------------------------
 .../GridSpringResourceInjectionSelfTest.java    | 143 +++++++++++++++++++
 .../processors/resource/spring-resource.xml     |  27 ++++
 .../testsuites/IgniteResourceSelfTestSuite.java |   2 +
 3 files changed, 172 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/db221f52/modules/spring/src/test/java/org/apache/ignite/internal/processors/resource/GridSpringResourceInjectionSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/spring/src/test/java/org/apache/ignite/internal/processors/resource/GridSpringResourceInjectionSelfTest.java
 
b/modules/spring/src/test/java/org/apache/ignite/internal/processors/resource/GridSpringResourceInjectionSelfTest.java
new file mode 100644
index 0000000..968c8c4
--- /dev/null
+++ 
b/modules/spring/src/test/java/org/apache/ignite/internal/processors/resource/GridSpringResourceInjectionSelfTest.java
@@ -0,0 +1,143 @@
+/*
+ * 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.ignite.internal.processors.resource;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteSpring;
+import org.apache.ignite.lang.IgniteCallable;
+import org.apache.ignite.resources.SpringResource;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * Tests for injected resource.
+ */
+public class GridSpringResourceInjectionSelfTest extends 
GridCommonAbstractTest {
+    /** Bean name. */
+    private static final String DUMMY_BEAN = "dummyResourceBean";
+
+    /** Test grid with Spring context. */
+    private static Ignite grid;
+
+    /** {@inheritDoc} */
+    @Override public void beforeTestsStarted() throws Exception {
+        grid = IgniteSpring.start(new ClassPathXmlApplicationContext(
+            
"/org/apache/ignite/internal/processors/resource/spring-resource.xml"));
+    }
+
+    /** {@inheritDoc} */
+    @Override public void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testClosureField() throws Exception {
+        grid.compute().call(new IgniteCallable<Object>() {
+            @SpringResource(resourceName = DUMMY_BEAN)
+            private transient DummyResourceBean dummyResourceBean;
+
+            @Override public Object call() throws Exception {
+                assertNotNull(dummyResourceBean);
+
+                return null;
+            }
+        });
+    }
+
+    /**
+     * Resource injection with non-existing resource name.
+     */
+    public void testClosureFieldWithWrongResourceName() throws Exception {
+        try {
+            grid.compute().call(new IgniteCallable<Object>() {
+                @SpringResource(resourceName = "")
+                private transient DummyResourceBean dummyResourceBean;
+
+                @Override public Object call() throws Exception {
+                    assertNull(dummyResourceBean);
+
+                    return null;
+                }
+            });
+        }
+        catch (IgniteException e) {
+            if (e.getMessage().contains("No bean named '' is defined"))
+                return;
+        }
+
+        fail();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testClosureMethod() throws Exception {
+        grid.compute().call(new IgniteCallable<Object>() {
+            private DummyResourceBean dummyResourceBean;
+
+            @SpringResource(resourceName = DUMMY_BEAN)
+            private void setDummyResourceBean(DummyResourceBean 
dummyResourceBean) {
+                assertNotNull(dummyResourceBean);
+
+                this.dummyResourceBean = dummyResourceBean;
+            }
+
+            @Override public Object call() throws Exception {
+                return null;
+            }
+        });
+    }
+
+    /**
+     * Resource injection with non-existing resource name.
+     */
+    public void testClosureMethodWithWrongResourceName() throws Exception {
+        try {
+            grid.compute().call(new IgniteCallable<Object>() {
+                private DummyResourceBean dummyResourceBean;
+
+                @SpringResource(resourceName = "")
+                private void setDummyResourceBean(DummyResourceBean 
dummyResourceBean) {
+                }
+
+                @Override public Object call() throws Exception {
+                    assertNull(dummyResourceBean);
+
+                    return null;
+                }
+            });
+        }
+        catch (IgniteException e) {
+            if (e.getMessage().contains("No bean named '' is defined"))
+                return;
+        }
+
+        fail();
+    }
+
+    /**
+     * Dummy resource bean.
+     */
+    public static class DummyResourceBean {
+        public DummyResourceBean() {
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/db221f52/modules/spring/src/test/java/org/apache/ignite/internal/processors/resource/spring-resource.xml
----------------------------------------------------------------------
diff --git 
a/modules/spring/src/test/java/org/apache/ignite/internal/processors/resource/spring-resource.xml
 
b/modules/spring/src/test/java/org/apache/ignite/internal/processors/resource/spring-resource.xml
new file mode 100644
index 0000000..3abb521
--- /dev/null
+++ 
b/modules/spring/src/test/java/org/apache/ignite/internal/processors/resource/spring-resource.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+
+<beans xmlns="http://www.springframework.org/schema/beans";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="http://www.springframework.org/schema/beans
+       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd";>
+
+    <bean id="dummyResourceBean"
+          
class="org.apache.ignite.internal.processors.resource.GridSpringResourceInjectionSelfTest$DummyResourceBean">
+    </bean>
+</beans>

http://git-wip-us.apache.org/repos/asf/ignite/blob/db221f52/modules/spring/src/test/java/org/apache/ignite/testsuites/IgniteResourceSelfTestSuite.java
----------------------------------------------------------------------
diff --git 
a/modules/spring/src/test/java/org/apache/ignite/testsuites/IgniteResourceSelfTestSuite.java
 
b/modules/spring/src/test/java/org/apache/ignite/testsuites/IgniteResourceSelfTestSuite.java
index 5ad93e8..742190b 100644
--- 
a/modules/spring/src/test/java/org/apache/ignite/testsuites/IgniteResourceSelfTestSuite.java
+++ 
b/modules/spring/src/test/java/org/apache/ignite/testsuites/IgniteResourceSelfTestSuite.java
@@ -21,6 +21,7 @@ import junit.framework.TestSuite;
 import 
org.apache.ignite.internal.processors.resource.GridLoggerInjectionSelfTest;
 import 
org.apache.ignite.internal.processors.resource.GridResourceProcessorSelfTest;
 import 
org.apache.ignite.internal.processors.resource.GridServiceInjectionSelfTest;
+import 
org.apache.ignite.internal.processors.resource.GridSpringResourceInjectionSelfTest;
 
 /**
  * Ignite resource injection test Suite.
@@ -37,6 +38,7 @@ public class IgniteResourceSelfTestSuite extends TestSuite {
         suite.addTest(new TestSuite(GridResourceProcessorSelfTest.class));
         suite.addTest(new TestSuite(GridLoggerInjectionSelfTest.class));
         suite.addTest(new TestSuite(GridServiceInjectionSelfTest.class));
+        suite.addTest(new 
TestSuite(GridSpringResourceInjectionSelfTest.class));
 
         return suite;
     }

Reply via email to