ASTERIXDB-1587 Test upsert when using foreign datatype

Change-Id: I4c374a44389af5916c8398afb3be8628b7872389
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1091
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <tillw@apache.org>
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/cross-dataverse/drop-dataverse/drop-dataverse.1.ddl.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/cross-dataverse/drop-dataverse/drop-dataverse.1.ddl.aql
index b9b280c..c71bc9b 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/cross-dataverse/drop-dataverse/drop-dataverse.1.ddl.aql
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/cross-dataverse/drop-dataverse/drop-dataverse.1.ddl.aql
@@ -25,8 +25,8 @@
  */
 
 
-drop dataverse a if exists;
 drop dataverse b if exists;
+drop dataverse a if exists;
 create dataverse a;
 create dataverse b;
 
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/upsert/issue1587-foreignDataType/issue1587-foreignDataType.1.ddl.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/upsert/issue1587-foreignDataType/issue1587-foreignDataType.1.ddl.aql
new file mode 100644
index 0000000..e64f67c
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/upsert/issue1587-foreignDataType/issue1587-foreignDataType.1.ddl.aql
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : Upsert into a dataset which has a foreign datatype
+ * Expected Res : Success
+ * Date         : Aug 18th 2016
+ */
+
+drop dataverse b if exists;
+drop dataverse a if exists;
+create dataverse a;
+create dataverse b;
+use dataverse a;
+
+create type TypeA as closed{
+id:int32,
+age:int32
+};
+
+use dataverse b;
+
+create dataset UpsertTo(a.TypeA) primary key id;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/upsert/issue1587-foreignDataType/issue1587-foreignDataType.2.update.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/upsert/issue1587-foreignDataType/issue1587-foreignDataType.2.update.aql
new file mode 100644
index 0000000..6c3f6b4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/upsert/issue1587-foreignDataType/issue1587-foreignDataType.2.update.aql
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : Upsert into a dataset which has a foreign datatype
+ * Expected Res : Success
+ * Date         : Aug 18th 2016
+ */
+
+// upsert UpsertFrom into UpsertTo
+use dataverse b;
+
+upsert into dataset UpsertTo(
+{"id":1,"age":7}
+);
+
+upsert into dataset UpsertTo(
+{"id":2,"age":8}
+);
+
+upsert into dataset UpsertTo(
+{"id":1,"age":9}
+);
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/upsert/issue1587-foreignDataType/issue1587-foreignDataType.3.query.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/upsert/issue1587-foreignDataType/issue1587-foreignDataType.3.query.aql
new file mode 100644
index 0000000..1f85348
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/upsert/issue1587-foreignDataType/issue1587-foreignDataType.3.query.aql
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ */
+/*
+ * Description  : Upsert into a dataset which has a foreign datatype
+ * Expected Res : Success
+ * Date         : Aug 18th 2016
+ */
+
+use dataverse b;
+
+for $x in dataset UpsertTo
+order by $x.id
+return $x;
+
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/upsert/issue1587-foreignDataType/issue1587-foreignDataType.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/upsert/issue1587-foreignDataType/issue1587-foreignDataType.1.adm
new file mode 100644
index 0000000..ab1f6f2
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/upsert/issue1587-foreignDataType/issue1587-foreignDataType.1.adm
@@ -0,0 +1,2 @@
+{ "id": 1, "age": 9 }
+{ "id": 2, "age": 8 }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
index 749965e..6b63ff0 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
@@ -257,6 +257,11 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="upsert">
+      <compilation-unit name="issue1587-foreignDataType">
+        <output-dir compare="Text">issue1587-foreignDataType</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="upsert">
       <compilation-unit name="nested-index">
         <output-dir compare="Text">nested-index</output-dir>
       </compilation-unit>