IGNITE-2977: Unit tests.

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

Branch: refs/heads/ignite-2977
Commit: fcb23411eaab8e19fd197a41cddae6f830057ec2
Parents: 9fefde4
Author: vozerov-gridgain <[email protected]>
Authored: Wed Apr 13 11:50:14 2016 +0300
Committer: vozerov-gridgain <[email protected]>
Committed: Wed Apr 13 11:50:14 2016 +0300

----------------------------------------------------------------------
 .../PlatformDefaultJavaObjectFactory.java       |   6 +-
 .../PlatformJavaObjectFactoryProxy.java         |  35 ++-
 .../platform/utils/PlatformUtils.java           |   4 +-
 ...latformDefaultJavaObjectFactorySelfTest.java | 185 +++++++++++++
 .../PlatformJavaObjectFactoryProxySelfTest.java | 220 +++++++++++++++
 .../platform/javaobject/TestJavaObject.java     | 271 +++++++++++++++++++
 .../javaobject/TestJavaObjectNoDefaultCtor.java |  49 ++++
 .../TestJavaObjectNoDefaultCtorFactory.java     |  68 +++++
 .../ignite/testsuites/IgniteBasicTestSuite.java |   2 +
 .../testsuites/IgnitePlatformsTestSuite.java    |  41 +++
 10 files changed, 869 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/fcb23411/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformDefaultJavaObjectFactory.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformDefaultJavaObjectFactory.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformDefaultJavaObjectFactory.java
index c22cbd9..011088c 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformDefaultJavaObjectFactory.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformDefaultJavaObjectFactory.java
@@ -17,6 +17,7 @@
 
 package org.apache.ignite.internal.processors.platform;
 
+import org.apache.ignite.IgniteException;
 import org.apache.ignite.internal.processors.platform.utils.PlatformUtils;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.jetbrains.annotations.Nullable;
@@ -35,7 +36,10 @@ public class PlatformDefaultJavaObjectFactory<T> implements 
PlatformJavaObjectFa
 
     /** {@inheritDoc} */
     @Override public void initialize(@Nullable Object payload, @Nullable 
Map<String, Object> props) {
-        assert payload != null && payload instanceof String;
+        if (payload == null)
+            throw new IgniteException("Java object class name is not 
provided.");
+
+        assert payload instanceof String;
 
         clsName = (String)payload;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/fcb23411/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformJavaObjectFactoryProxy.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformJavaObjectFactoryProxy.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformJavaObjectFactoryProxy.java
index 6984328..ecce23d 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformJavaObjectFactoryProxy.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformJavaObjectFactoryProxy.java
@@ -30,6 +30,7 @@ import 
org.apache.ignite.internal.util.tostring.GridToStringExclude;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.platform.PlatformJavaObjectFactory;
+import org.jetbrains.annotations.Nullable;
 
 import java.io.Externalizable;
 import java.io.IOException;
@@ -43,13 +44,13 @@ import java.util.Map;
  */
 public class PlatformJavaObjectFactoryProxy implements Externalizable, 
Binarylizable {
     /** User-defined type. */
-    private static final int TYP_USER = 0;
+    public static final int TYP_USER = 0;
 
     /** Default factory. */
-    private static final int TYP_DEFAULT = 1;
+    public static final int TYP_DEFAULT = 1;
 
     /** Factory type. */
-    private int factoryType;
+    private int factoryTyp;
 
     /** Factory class name. */
     private String factoryClsName;
@@ -70,6 +71,22 @@ public class PlatformJavaObjectFactoryProxy implements 
Externalizable, Binaryliz
     }
 
     /**
+     * Constructor.
+     *
+     * @param factoryTyp Factory type.
+     * @param factoryClsName Factory class name.
+     * @param payload Payload.
+     * @param props Properties.
+     */
+    public PlatformJavaObjectFactoryProxy(int factoryTyp, @Nullable String 
factoryClsName, @Nullable Object payload,
+        @Nullable Map<String, Object> props) {
+        this.factoryTyp = factoryTyp;
+        this.factoryClsName = factoryClsName;
+        this.payload = payload;
+        this.props = props;
+    }
+
+    /**
      * Get factory instance.
      *
      * @param ctx Kernal context for injections.
@@ -79,7 +96,7 @@ public class PlatformJavaObjectFactoryProxy implements 
Externalizable, Binaryliz
         // Create factory.
         PlatformJavaObjectFactory res;
 
-        switch (factoryType) {
+        switch (factoryTyp) {
             case TYP_DEFAULT:
                 res = new PlatformDefaultJavaObjectFactory();
 
@@ -91,7 +108,7 @@ public class PlatformJavaObjectFactoryProxy implements 
Externalizable, Binaryliz
                 break;
 
             default:
-                throw new IgniteException("Unsupported Java object factory 
type: " + factoryType);
+                throw new IgniteException("Unsupported Java object factory 
type: " + factoryTyp);
         }
 
         // Initialize factory.
@@ -107,7 +124,7 @@ public class PlatformJavaObjectFactoryProxy implements 
Externalizable, Binaryliz
     @Override public void writeBinary(BinaryWriter writer) throws 
BinaryObjectException {
         BinaryRawWriterEx rawWriter = (BinaryRawWriterEx)writer.rawWriter();
 
-        rawWriter.writeInt(factoryType);
+        rawWriter.writeInt(factoryTyp);
         rawWriter.writeString(factoryClsName);
         rawWriter.writeObjectDetached(payload);
 
@@ -127,7 +144,7 @@ public class PlatformJavaObjectFactoryProxy implements 
Externalizable, Binaryliz
     @Override public void readBinary(BinaryReader reader) throws 
BinaryObjectException {
         BinaryRawReaderEx rawReader = (BinaryRawReaderEx)reader.rawReader();
 
-        factoryType = rawReader.readInt();
+        factoryTyp = rawReader.readInt();
         factoryClsName = rawReader.readString();
         payload = rawReader.readObjectDetached();
 
@@ -147,7 +164,7 @@ public class PlatformJavaObjectFactoryProxy implements 
Externalizable, Binaryliz
 
     /** {@inheritDoc} */
     @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeInt(factoryType);
+        out.writeInt(factoryTyp);
         U.writeString(out, factoryClsName);
         out.writeObject(payload);
         U.writeMap(out, props);
@@ -155,7 +172,7 @@ public class PlatformJavaObjectFactoryProxy implements 
Externalizable, Binaryliz
 
     /** {@inheritDoc} */
     @Override public void readExternal(ObjectInput in) throws IOException, 
ClassNotFoundException {
-        factoryType = in.readInt();
+        factoryTyp = in.readInt();
         factoryClsName = U.readString(in);
         payload = in.readObject();
         props = U.readMap(in);

http://git-wip-us.apache.org/repos/asf/ignite/blob/fcb23411/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java
index f1047be..97bf1d4 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java
@@ -974,9 +974,9 @@ public class PlatformUtils {
                 try {
                     field.set(obj, prop.getValue());
                 }
-                catch (ReflectiveOperationException e) {
+                catch (Exception e) {
                     throw new IgniteException("Failed to set Java 
object/factory field [className=" + clsName +
-                        ", fieldName=" + fieldName + ']', e);
+                        ", fieldName=" + fieldName + ", fieldValue=" + 
prop.getValue() + ']', e);
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/fcb23411/modules/core/src/test/java/org/apache/ignite/platform/PlatformDefaultJavaObjectFactorySelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/platform/PlatformDefaultJavaObjectFactorySelfTest.java
 
b/modules/core/src/test/java/org/apache/ignite/platform/PlatformDefaultJavaObjectFactorySelfTest.java
new file mode 100644
index 0000000..45fda4f
--- /dev/null
+++ 
b/modules/core/src/test/java/org/apache/ignite/platform/PlatformDefaultJavaObjectFactorySelfTest.java
@@ -0,0 +1,185 @@
+/*
+ * 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.platform;
+
+import org.apache.ignite.IgniteException;
+import 
org.apache.ignite.internal.processors.platform.PlatformDefaultJavaObjectFactory;
+import org.apache.ignite.platform.javaobject.TestJavaObject;
+import org.apache.ignite.platform.javaobject.TestJavaObjectNoDefaultCtor;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.Callable;
+
+/**
+ * Dedicated tests for {@link PlatformDefaultJavaObjectFactory}.
+ */
+@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
+public class PlatformDefaultJavaObjectFactorySelfTest extends 
GridCommonAbstractTest {
+    /** Name of the class. */
+    private static final String CLS_NAME = TestJavaObject.class.getName();
+
+    /** Name of the class without default constructor. */
+    private static final String NO_DFLT_CTOR_CLS_NAME = 
TestJavaObjectNoDefaultCtor.class.getName();
+
+    /**
+     * Test normal object creation.
+     */
+    public void testNormal() {
+        final PlatformDefaultJavaObjectFactory factory = new 
PlatformDefaultJavaObjectFactory();
+
+        Map<String, Object> props = new HashMap<>();
+
+        props.put("fBoolean", true);
+        props.put("fByte", (byte)1);
+        props.put("fShort", (short)2);
+        props.put("fChar", '3');
+        props.put("fInt", 4);
+        props.put("fLong", 5L);
+        props.put("fFloat", 6.6f);
+        props.put("fDouble", 7.7d);
+
+        UUID obj = UUID.randomUUID();
+
+        props.put("fObj", obj);
+
+        props.put("fIntBoxed", 10);
+
+        factory.initialize(CLS_NAME, props);
+
+        Object val = factory.create();
+
+        TestJavaObject expVal = new 
TestJavaObject().setBoolean(true).setByte((byte)1).setShort((short)2).setChar('3')
+            
.setInt(4).setLong(5L).setFloat(6.6f).setDouble(7.7d).setObject(obj).setIntBoxed(10);
+
+        assertEquals(expVal, val);
+    }
+
+    /**
+     * Test object creation with boxed property.
+     */
+    public void testBoxedProperty() {
+        final PlatformDefaultJavaObjectFactory factory = new 
PlatformDefaultJavaObjectFactory();
+
+        factory.initialize(CLS_NAME, Collections.singletonMap("fIntBoxed", 1));
+
+        Object val = factory.create();
+
+        assertEquals(val, new TestJavaObject().setIntBoxed(1));
+    }
+
+    /**
+     * Test object creation without properties.
+     */
+    public void testNoProperties() {
+        final PlatformDefaultJavaObjectFactory factory = new 
PlatformDefaultJavaObjectFactory();
+
+        factory.initialize(CLS_NAME, Collections.emptyMap());
+
+        Object val = factory.create();
+
+        assertEquals(val, new TestJavaObject());
+    }
+
+    /**
+     * Test object creation with invalid property name.
+     */
+    public void testInvalidPropertyName() {
+        final PlatformDefaultJavaObjectFactory factory = new 
PlatformDefaultJavaObjectFactory();
+
+        factory.initialize(CLS_NAME, Collections.singletonMap("invalid", 1));
+
+        GridTestUtils.assertThrows(null, new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                return factory.create();
+            }
+        }, IgniteException.class, null);
+    }
+
+    /**
+     * Test object creation with invalid property value.
+     */
+    public void testInvalidPropertyValue() {
+        final PlatformDefaultJavaObjectFactory factory = new 
PlatformDefaultJavaObjectFactory();
+
+        factory.initialize(CLS_NAME, Collections.singletonMap("fInt", 1L));
+
+        GridTestUtils.assertThrows(null, new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                return factory.create();
+            }
+        }, IgniteException.class, null);
+    }
+
+    /**
+     * Test object creation without default constructor.
+     */
+    public void testNoDefaultConstructor() {
+        final PlatformDefaultJavaObjectFactory factory = new 
PlatformDefaultJavaObjectFactory();
+
+        factory.initialize(NO_DFLT_CTOR_CLS_NAME, null);
+
+        GridTestUtils.assertThrows(null, new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                return factory.create();
+            }
+        }, IgniteException.class, null);
+    }
+
+    /**
+     * Test object creation with null class name.
+     */
+    public void testNullClassName() {
+        final PlatformDefaultJavaObjectFactory factory = new 
PlatformDefaultJavaObjectFactory();
+
+        GridTestUtils.assertThrows(null, new Callable<Void>() {
+            @Override public Void call() throws Exception {
+                factory.initialize(null, null);
+
+                return null;
+            }
+        }, IgniteException.class, null);
+
+        GridTestUtils.assertThrows(null, new Callable<Void>() {
+            @Override public Void call() throws Exception {
+                factory.initialize(null, new HashMap<String, Object>());
+
+                return null;
+            }
+        }, IgniteException.class, null);
+    }
+
+    /**
+     * Test object creation with invalid class name.
+     */
+    public void testInvalidClassName() {
+        final PlatformDefaultJavaObjectFactory factory = new 
PlatformDefaultJavaObjectFactory();
+
+        factory.initialize("invalid", null);
+
+        GridTestUtils.assertThrows(null, new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                return factory.create();
+            }
+        }, IgniteException.class, null);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/fcb23411/modules/core/src/test/java/org/apache/ignite/platform/PlatformJavaObjectFactoryProxySelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/platform/PlatformJavaObjectFactoryProxySelfTest.java
 
b/modules/core/src/test/java/org/apache/ignite/platform/PlatformJavaObjectFactoryProxySelfTest.java
new file mode 100644
index 0000000..18fb806
--- /dev/null
+++ 
b/modules/core/src/test/java/org/apache/ignite/platform/PlatformJavaObjectFactoryProxySelfTest.java
@@ -0,0 +1,220 @@
+/*
+ * 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.platform;
+
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.IgniteKernal;
+import 
org.apache.ignite.internal.processors.platform.PlatformJavaObjectFactoryProxy;
+import org.apache.ignite.platform.javaobject.TestJavaObject;
+import org.apache.ignite.platform.javaobject.TestJavaObjectNoDefaultCtor;
+import 
org.apache.ignite.platform.javaobject.TestJavaObjectNoDefaultCtorFactory;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.Callable;
+
+/**
+ * Dedicated tests for {@link PlatformJavaObjectFactoryProxy}.
+ */
+@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
+public class PlatformJavaObjectFactoryProxySelfTest extends 
GridCommonAbstractTest {
+    /** Name of the class. */
+    private static final String CLS_NAME = TestJavaObject.class.getName();
+
+    /** Name of the factory class to create object without default 
constructor. */
+    private static final String NO_DFLT_CTOR_FACTORY_CLS_NAME = 
TestJavaObjectNoDefaultCtorFactory.class.getName();
+
+    /** Kernal context. */
+    private GridKernalContext ctx;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        ctx = 
((IgniteKernal)Ignition.start(getConfiguration(PlatformJavaObjectFactoryProxySelfTest.class.getName())))
+            .context();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        ctx = null;
+
+        Ignition.stopAll(true);
+    }
+
+    /**
+     * Test normal object creation using default factory.
+     */
+    public void testDefaultFactoryNormal() {
+        Map<String, Object> props = new HashMap<>();
+
+        props.put("fBoolean", true);
+        props.put("fByte", (byte)1);
+        props.put("fShort", (short)2);
+        props.put("fChar", '3');
+        props.put("fInt", 4);
+        props.put("fLong", 5L);
+        props.put("fFloat", 6.6f);
+        props.put("fDouble", 7.7d);
+
+        UUID obj = UUID.randomUUID();
+
+        props.put("fObj", obj);
+
+        props.put("fIntBoxed", 10);
+
+        PlatformJavaObjectFactoryProxy proxy =
+            new 
PlatformJavaObjectFactoryProxy(PlatformJavaObjectFactoryProxy.TYP_DEFAULT, 
null, CLS_NAME, props);
+
+        TestJavaObject val = (TestJavaObject)proxy.factory(ctx).create();
+
+        TestJavaObject expVal = new 
TestJavaObject().setBoolean(true).setByte((byte)1).setShort((short)2).setChar('3')
+            
.setInt(4).setLong(5L).setFloat(6.6f).setDouble(7.7d).setObject(obj).setIntBoxed(10);
+
+        assertEquals(expVal, val);
+    }
+
+    /**
+     * Test normal object creation using custom factory.
+     */
+    public void testCustomFactoryNormal() {
+        Map<String, Object> props = new HashMap<>();
+
+        props.put("fBoolean", true);
+        props.put("fByte", (byte)1);
+        props.put("fShort", (short)2);
+        props.put("fChar", '3');
+        props.put("fInt", 4);
+        props.put("fLong", 5L);
+        props.put("fFloat", 6.6f);
+        props.put("fDouble", 7.7d);
+
+        UUID obj = UUID.randomUUID();
+
+        props.put("fObj", obj);
+
+        props.put("fIntBoxed", 10);
+
+        PlatformJavaObjectFactoryProxy proxy = 
proxyForCustom(NO_DFLT_CTOR_FACTORY_CLS_NAME, props);
+
+        TestJavaObjectNoDefaultCtor val = 
(TestJavaObjectNoDefaultCtor)proxy.factory(ctx).create();
+
+        TestJavaObject expVal = new 
TestJavaObject().setBoolean(true).setByte((byte)1).setShort((short)2).setChar('3')
+            
.setInt(4).setLong(5L).setFloat(6.6f).setDouble(7.7d).setObject(obj).setIntBoxed(10);
+
+        assertEquals(expVal, val);
+
+        assertNotNull(val.node);
+        assertEquals(val.node.name(), ctx.gridName());
+    }
+
+    /**
+     * Test object creation with boxed property.
+     */
+    public void testCustomFactoryBoxedProperty() {
+        PlatformJavaObjectFactoryProxy proxy = 
proxyForCustom(NO_DFLT_CTOR_FACTORY_CLS_NAME,
+            Collections.singletonMap("fIntBoxed", (Object)1));
+
+        Object val = proxy.factory(ctx).create();
+
+        assertEquals(val, new TestJavaObject().setIntBoxed(1));
+    }
+
+    /**
+     * Test object creation without properties.
+     */
+    public void testCustomFactoryNoProperties() {
+        PlatformJavaObjectFactoryProxy proxy = 
proxyForCustom(NO_DFLT_CTOR_FACTORY_CLS_NAME,
+            Collections.<String, Object>emptyMap());
+
+        Object val = proxy.factory(ctx).create();
+
+        assertEquals(val, new TestJavaObject());
+    }
+
+    /**
+     * Test object creation with invalid property name.
+     */
+    public void testCustomFactoryInvalidPropertyName() {
+        final PlatformJavaObjectFactoryProxy proxy = 
proxyForCustom(NO_DFLT_CTOR_FACTORY_CLS_NAME,
+            Collections.singletonMap("invalid", (Object)1));
+
+        GridTestUtils.assertThrows(null, new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                return proxy.factory(ctx).create();
+            }
+        }, IgniteException.class, null);
+    }
+
+    /**
+     * Test object creation with invalid property value.
+     */
+    public void testCustomFactoryInvalidPropertyValue() {
+        final PlatformJavaObjectFactoryProxy proxy = 
proxyForCustom(NO_DFLT_CTOR_FACTORY_CLS_NAME,
+            Collections.singletonMap("fInt", (Object)1L));
+
+        GridTestUtils.assertThrows(null, new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                return proxy.factory(ctx).create();
+            }
+        }, IgniteException.class, null);
+    }
+
+    /**
+     * Test object creation with null class name.
+     */
+    public void testCustomFactoryNullClassName() {
+        GridTestUtils.assertThrows(null, new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                return proxyForCustom(null, null).factory(ctx).create();
+            }
+        }, IgniteException.class, null);
+
+        GridTestUtils.assertThrows(null, new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                return proxyForCustom(null, new HashMap<String, 
Object>()).factory(ctx).create();
+            }
+        }, IgniteException.class, null);
+    }
+
+    /**
+     * Test object creation with invalid class name.
+     */
+    public void testCustomFactoryInvalidClassName() {
+        GridTestUtils.assertThrows(null, new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                return proxyForCustom("invalid", null).factory(ctx).create();
+            }
+        }, IgniteException.class, null);
+    }
+
+    /**
+     * Create proxy for user-defined factory.
+     *
+     * @param clsName Class name.
+     * @param props Properties.
+     * @return Proxy.
+     */
+    private static PlatformJavaObjectFactoryProxy proxyForCustom(String 
clsName, Map<String, Object> props) {
+        return new 
PlatformJavaObjectFactoryProxy(PlatformJavaObjectFactoryProxy.TYP_USER, 
clsName, null, props);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/fcb23411/modules/core/src/test/java/org/apache/ignite/platform/javaobject/TestJavaObject.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/platform/javaobject/TestJavaObject.java
 
b/modules/core/src/test/java/org/apache/ignite/platform/javaobject/TestJavaObject.java
new file mode 100644
index 0000000..3c76798
--- /dev/null
+++ 
b/modules/core/src/test/java/org/apache/ignite/platform/javaobject/TestJavaObject.java
@@ -0,0 +1,271 @@
+/*
+ * 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.platform.javaobject;
+
+/**
+ * Test object.
+ */
+public class TestJavaObject {
+    /** */
+    protected boolean fBoolean;
+
+    /** */
+    protected byte fByte;
+
+    /** */
+    protected short fShort;
+
+    /** */
+    protected char fChar;
+
+    /** */
+    protected int fInt;
+
+    /** */
+    protected long fLong;
+
+    /** */
+    protected float fFloat;
+
+    /** */
+    protected double fDouble;
+
+    /** */
+    protected Object fObj;
+
+    /** Integer field. */
+    protected Integer fIntBoxed;
+
+    /**
+     * Default constructor.
+     */
+    public TestJavaObject() {
+        // No-op.
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param fBoolean Boolean field.
+     * @param fByte Byte field.
+     * @param fShort Short field.
+     * @param fChar Char field.
+     * @param fInt Integer field.
+     * @param fLong Long field.
+     * @param fDouble Double field.
+     * @param fFloat Float field.
+     * @param fObj Object field.
+     * @param fIntBoxed Integer boxed field.
+     */
+    public TestJavaObject(boolean fBoolean, byte fByte, short fShort, char 
fChar, int fInt, long fLong, float fFloat,
+        double fDouble, Object fObj, Integer fIntBoxed) {
+        this.fBoolean = fBoolean;
+        this.fByte = fByte;
+        this.fShort = fShort;
+        this.fChar = fChar;
+        this.fInt = fInt;
+        this.fLong = fLong;
+        this.fDouble = fDouble;
+        this.fFloat = fFloat;
+        this.fObj = fObj;
+        this.fIntBoxed = fIntBoxed;
+    }
+
+    /**
+     * Set boolean field.
+     *
+     * @param fBoolean Value.
+     * @return This instance for chaining.
+     */
+    public TestJavaObject setBoolean(boolean fBoolean) {
+        this.fBoolean = fBoolean;
+
+        return this;
+    }
+
+    /**
+     * Set byte field.
+     *
+     * @param fByte Value.
+     * @return This instance for chaining.
+     */
+    public TestJavaObject setByte(byte fByte) {
+        this.fByte = fByte;
+
+        return this;
+    }
+
+    /**
+     * Set short field.
+     *
+     * @param fShort Value.
+     * @return This instance for chaining.
+     */
+    public TestJavaObject setShort(short fShort) {
+        this.fShort = fShort;
+
+        return this;
+    }
+
+    /**
+     * Set char field.
+     *
+     * @param fChar Value.
+     * @return This instance for chaining.
+     */
+    public TestJavaObject setChar(char fChar) {
+        this.fChar = fChar;
+
+        return this;
+    }
+
+    /**
+     * Set int field.
+     *
+     * @param fInt Value.
+     * @return This instance for chaining.
+     */
+    public TestJavaObject setInt(int fInt) {
+        this.fInt = fInt;
+
+        return this;
+    }
+
+    /**
+     * Set long field.
+     *
+     * @param fLong Value.
+     * @return This instance for chaining.
+     */
+    public TestJavaObject setLong(long fLong) {
+        this.fLong = fLong;
+
+        return this;
+    }
+
+    /**
+     * Set float field.
+     *
+     * @param fFloat Value.
+     * @return This instance for chaining.
+     */
+    public TestJavaObject setFloat(float fFloat) {
+        this.fFloat = fFloat;
+
+        return this;
+    }
+
+    /**
+     * Set double field.
+     *
+     * @param fDouble Value.
+     * @return This instance for chaining.
+     */
+    public TestJavaObject setDouble(double fDouble) {
+        this.fDouble = fDouble;
+
+        return this;
+    }
+
+    /**
+     * Set object field.
+     *
+     * @param fObj Value.
+     * @return This instance for chaining.
+     */
+    public TestJavaObject setObject(Object fObj) {
+        this.fObj = fObj;
+
+        return this;
+    }
+
+    /**
+     * Set wrapped integer field.
+     *
+     * @param fInteger Value.
+     * @return This instance for chaining.
+     */
+    public TestJavaObject setIntBoxed(Integer fInteger) {
+        this.fIntBoxed = fInteger;
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings({"EqualsWhichDoesntCheckParameterClass", 
"SimplifiableIfStatement"})
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null)
+            return false;
+
+        TestJavaObject that = (TestJavaObject) o;
+
+        if (fBoolean != that.fBoolean)
+            return false;
+
+        if (fByte != that.fByte)
+            return false;
+
+        if (fShort != that.fShort)
+            return false;
+
+        if (fChar != that.fChar)
+            return false;
+
+        if (fInt != that.fInt)
+            return false;
+
+        if (fLong != that.fLong)
+            return false;
+
+        if (Double.compare(that.fDouble, fDouble) != 0)
+            return false;
+
+        if (Float.compare(that.fFloat, fFloat) != 0)
+            return false;
+
+        if (fObj != null ? !fObj.equals(that.fObj) : that.fObj != null)
+            return false;
+
+        return fIntBoxed != null ? fIntBoxed.equals(that.fIntBoxed) : 
that.fIntBoxed == null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int res;
+        long tmp;
+
+        res = (fBoolean ? 1 : 0);
+        res = 31 * res + (int) fByte;
+        res = 31 * res + (int) fShort;
+        res = 31 * res + (int) fChar;
+        res = 31 * res + fInt;
+        res = 31 * res + (int) (fLong ^ (fLong >>> 32));
+
+        tmp = Double.doubleToLongBits(fDouble);
+
+        res = 31 * res + (int) (tmp ^ (tmp >>> 32));
+        res = 31 * res + (fFloat != +0.0f ? Float.floatToIntBits(fFloat) : 0);
+        res = 31 * res + (fObj != null ? fObj.hashCode() : 0);
+        res = 31 * res + (fIntBoxed != null ? fIntBoxed.hashCode() : 0);
+
+        return res;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/fcb23411/modules/core/src/test/java/org/apache/ignite/platform/javaobject/TestJavaObjectNoDefaultCtor.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/platform/javaobject/TestJavaObjectNoDefaultCtor.java
 
b/modules/core/src/test/java/org/apache/ignite/platform/javaobject/TestJavaObjectNoDefaultCtor.java
new file mode 100644
index 0000000..1d7ed07
--- /dev/null
+++ 
b/modules/core/src/test/java/org/apache/ignite/platform/javaobject/TestJavaObjectNoDefaultCtor.java
@@ -0,0 +1,49 @@
+/*
+ * 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.platform.javaobject;
+
+import org.apache.ignite.Ignite;
+
+/**
+ * Test Java object without default constructor.
+ */
+public class TestJavaObjectNoDefaultCtor extends TestJavaObject {
+    /** Node. */
+    public Ignite node;
+
+    /**
+     * Constructor.
+     *
+     * @param fBoolean Boolean field.
+     * @param fByte Byte field.
+     * @param fShort Short field.
+     * @param fChar Char field.
+     * @param fInt Integer field.
+     * @param fLong Long field.
+     * @param fDouble Double field.
+     * @param fFloat Float field.
+     * @param fObj Object field.
+     * @param fIntBoxed Integer boxed field.
+     */
+    public TestJavaObjectNoDefaultCtor(boolean fBoolean, byte fByte, short 
fShort, char fChar, int fInt, long fLong,
+        float fFloat, double fDouble, Object fObj, Integer fIntBoxed, Ignite 
node) {
+        super(fBoolean, fByte, fShort, fChar, fInt, fLong, fFloat, fDouble, 
fObj, fIntBoxed);
+
+        this.node = node;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/fcb23411/modules/core/src/test/java/org/apache/ignite/platform/javaobject/TestJavaObjectNoDefaultCtorFactory.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/platform/javaobject/TestJavaObjectNoDefaultCtorFactory.java
 
b/modules/core/src/test/java/org/apache/ignite/platform/javaobject/TestJavaObjectNoDefaultCtorFactory.java
new file mode 100644
index 0000000..0e6dd99
--- /dev/null
+++ 
b/modules/core/src/test/java/org/apache/ignite/platform/javaobject/TestJavaObjectNoDefaultCtorFactory.java
@@ -0,0 +1,68 @@
+/*
+ * 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.platform.javaobject;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.platform.PlatformJavaObjectFactory;
+import org.apache.ignite.resources.IgniteInstanceResource;
+
+/**
+ * Test factory.
+ */
+@SuppressWarnings("unused")
+public class TestJavaObjectNoDefaultCtorFactory implements 
PlatformJavaObjectFactory {
+    /** Injected node. */
+    @IgniteInstanceResource
+    public Ignite node;
+
+    /** */
+    private boolean fBoolean;
+
+    /** */
+    private byte fByte;
+
+    /** */
+    private short fShort;
+
+    /** */
+    private char fChar;
+
+    /** */
+    private int fInt;
+
+    /** */
+    private long fLong;
+
+    /** */
+    private float fFloat;
+
+    /** */
+    private double fDouble;
+
+    /** */
+    private Object fObj;
+
+    /** Integer field. */
+    private Integer fIntBoxed;
+
+    /** {@inheritDoc} */
+    @Override public Object create() {
+        return new TestJavaObjectNoDefaultCtor(fBoolean, fByte, fShort, fChar, 
fInt, fLong, fFloat, fDouble, fObj,
+            fIntBoxed, node);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/fcb23411/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
 
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
index 9e2324c..c67a07d 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
@@ -86,6 +86,8 @@ public class IgniteBasicTestSuite extends TestSuite {
         
suite.addTest(IgniteCacheP2pUnmarshallingErrorTestSuite.suite(ignoredTests));
         suite.addTest(IgniteStreamSelfTestSuite.suite());
 
+        suite.addTest(IgnitePlatformsTestSuite.suite());
+
         suite.addTest(new TestSuite(GridSelfTest.class));
         suite.addTest(new TestSuite(ClusterGroupHostsSelfTest.class));
         suite.addTest(new TestSuite(IgniteMessagingWithClientTest.class));

http://git-wip-us.apache.org/repos/asf/ignite/blob/fcb23411/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePlatformsTestSuite.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePlatformsTestSuite.java
 
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePlatformsTestSuite.java
new file mode 100644
index 0000000..f7021d8
--- /dev/null
+++ 
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePlatformsTestSuite.java
@@ -0,0 +1,41 @@
+/*
+ * 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.testsuites;
+
+import junit.framework.TestSuite;
+import org.apache.ignite.platform.PlatformDefaultJavaObjectFactorySelfTest;
+import org.apache.ignite.platform.PlatformJavaObjectFactoryProxySelfTest;
+
+/**
+ * Suite for platform tests.
+ */
+public class IgnitePlatformsTestSuite extends TestSuite {
+    /**
+     * @return Test suite.
+     * @throws Exception If failed.
+     */
+    public static TestSuite suite() throws Exception {
+        TestSuite suite = new TestSuite("Ignite Deployment SPI Test Suite");
+
+        // LocalDeploymentSpi tests
+        suite.addTest(new 
TestSuite(PlatformDefaultJavaObjectFactorySelfTest.class));
+        suite.addTest(new 
TestSuite(PlatformJavaObjectFactoryProxySelfTest.class));
+
+        return suite;
+    }
+}

Reply via email to