atlas-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shweth...@apache.org
Subject [1/2] incubator-atlas git commit: ATLAS-631 Introduce Versioning to Atlas Notification Payload (tbeerbower via shwethags)
Date Wed, 04 May 2016 06:08:17 GMT
Repository: incubator-atlas
Updated Branches:
  refs/heads/master 73640cc68 -> b2ae1371b


http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/b2ae1371/notification/src/test/java/org/apache/atlas/notification/entity/EntityMessageDeserializerTest.java
----------------------------------------------------------------------
diff --git a/notification/src/test/java/org/apache/atlas/notification/entity/EntityMessageDeserializerTest.java
b/notification/src/test/java/org/apache/atlas/notification/entity/EntityMessageDeserializerTest.java
new file mode 100644
index 0000000..be32427
--- /dev/null
+++ b/notification/src/test/java/org/apache/atlas/notification/entity/EntityMessageDeserializerTest.java
@@ -0,0 +1,61 @@
+/**
+ * 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.atlas.notification.entity;
+
+import org.apache.atlas.notification.AbstractNotification;
+import org.apache.atlas.typesystem.IStruct;
+import org.apache.atlas.typesystem.Referenceable;
+import org.apache.atlas.typesystem.Struct;
+import org.testng.annotations.Test;
+
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.testng.Assert.assertEquals;
+
+/**
+ * EntityMessageDeserializer tests.
+ */
+public class EntityMessageDeserializerTest {
+
+    @Test
+    public void testDeserialize() throws Exception {
+        EntityMessageDeserializer deserializer = new EntityMessageDeserializer();
+
+        Referenceable entity = EntityNotificationImplTest.getEntity("id");
+        String traitName = "MyTrait";
+        List<IStruct> traitInfo = new LinkedList<>();
+        IStruct trait = new Struct(traitName, Collections.<String, Object>emptyMap());
+        traitInfo.add(trait);
+
+        EntityNotificationImpl notification =
+            new EntityNotificationImpl(entity, EntityNotification.OperationType.TRAIT_ADD,
traitInfo);
+
+        String json = AbstractNotification.getMessageJson(notification);
+
+        EntityNotification deserializedNotification = deserializer.deserialize(json);
+        assertEquals(deserializedNotification.getOperationType(), notification.getOperationType());
+        assertEquals(deserializedNotification.getEntity().getId(), notification.getEntity().getId());
+        assertEquals(deserializedNotification.getEntity().getTypeName(), notification.getEntity().getTypeName());
+        assertEquals(deserializedNotification.getEntity().getTraits(), notification.getEntity().getTraits());
+        assertEquals(deserializedNotification.getEntity().getTrait(traitName),
+            notification.getEntity().getTrait(traitName));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/b2ae1371/notification/src/test/java/org/apache/atlas/notification/entity/EntityNotificationImplTest.java
----------------------------------------------------------------------
diff --git a/notification/src/test/java/org/apache/atlas/notification/entity/EntityNotificationImplTest.java
b/notification/src/test/java/org/apache/atlas/notification/entity/EntityNotificationImplTest.java
index 385c41f..c3a2db8 100644
--- a/notification/src/test/java/org/apache/atlas/notification/entity/EntityNotificationImplTest.java
+++ b/notification/src/test/java/org/apache/atlas/notification/entity/EntityNotificationImplTest.java
@@ -131,7 +131,7 @@ public class EntityNotificationImplTest {
         assertTrue(entityNotification2.equals(entityNotification));
     }
 
-    private Referenceable getEntity(String id, IStruct... traits) {
+    public static Referenceable getEntity(String id, IStruct... traits) {
         String typeName = "typeName";
         Map<String, Object> values = new HashMap<>();
 

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/b2ae1371/notification/src/test/java/org/apache/atlas/notification/hook/HookMessageDeserializerTest.java
----------------------------------------------------------------------
diff --git a/notification/src/test/java/org/apache/atlas/notification/hook/HookMessageDeserializerTest.java
b/notification/src/test/java/org/apache/atlas/notification/hook/HookMessageDeserializerTest.java
new file mode 100644
index 0000000..3724fd5
--- /dev/null
+++ b/notification/src/test/java/org/apache/atlas/notification/hook/HookMessageDeserializerTest.java
@@ -0,0 +1,70 @@
+/**
+ * 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.atlas.notification.hook;
+
+import org.apache.atlas.notification.AbstractNotification;
+import org.apache.atlas.notification.entity.EntityNotificationImplTest;
+import org.apache.atlas.typesystem.IStruct;
+import org.apache.atlas.typesystem.Referenceable;
+import org.apache.atlas.typesystem.Struct;
+import org.testng.annotations.Test;
+
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
+/**
+ * HookMessageDeserializer tests.
+ */
+public class HookMessageDeserializerTest {
+    @Test
+    public void testDeserialize() throws Exception {
+        HookMessageDeserializer deserializer = new HookMessageDeserializer();
+
+        Referenceable entity = EntityNotificationImplTest.getEntity("id");
+        String traitName = "MyTrait";
+        List<IStruct> traitInfo = new LinkedList<>();
+        IStruct trait = new Struct(traitName, Collections.<String, Object>emptyMap());
+        traitInfo.add(trait);
+
+        HookNotification.EntityUpdateRequest message =
+            new HookNotification.EntityUpdateRequest("user1", entity);
+
+        String json = AbstractNotification.getMessageJson(message);
+
+        HookNotification.HookNotificationMessage deserializedMessage = deserializer.deserialize(json);
+
+        assertEquals(deserializedMessage.getType(), message.getType());
+        assertEquals(deserializedMessage.getUser(), message.getUser());
+
+        assertTrue(deserializedMessage instanceof HookNotification.EntityUpdateRequest);
+
+        HookNotification.EntityUpdateRequest deserializedEntityUpdateRequest =
+            (HookNotification.EntityUpdateRequest) deserializedMessage;
+
+        Referenceable deserializedEntity = deserializedEntityUpdateRequest.getEntities().get(0);
+        assertEquals(deserializedEntity.getId(), entity.getId());
+        assertEquals(deserializedEntity.getTypeName(), entity.getTypeName());
+        assertEquals(deserializedEntity.getTraits(), entity.getTraits());
+        assertEquals(deserializedEntity.getTrait(traitName), entity.getTrait(traitName));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/b2ae1371/notification/src/test/java/org/apache/atlas/notification/hook/HookNotificationTest.java
----------------------------------------------------------------------
diff --git a/notification/src/test/java/org/apache/atlas/notification/hook/HookNotificationTest.java
b/notification/src/test/java/org/apache/atlas/notification/hook/HookNotificationTest.java
index 57b0eea..dd3257e 100644
--- a/notification/src/test/java/org/apache/atlas/notification/hook/HookNotificationTest.java
+++ b/notification/src/test/java/org/apache/atlas/notification/hook/HookNotificationTest.java
@@ -17,7 +17,7 @@
  */
 package org.apache.atlas.notification.hook;
 
-import org.apache.atlas.notification.AbstractNotificationConsumer;
+import org.apache.atlas.notification.AbstractNotification;
 import org.apache.atlas.typesystem.Referenceable;
 import org.testng.annotations.Test;
 
@@ -25,6 +25,9 @@ import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNull;
 
 public class HookNotificationTest {
+
+    public static final HookMessageDeserializer HOOK_MESSAGE_DESERIALIZER = new HookMessageDeserializer();
+
     @Test
     public void testNewMessageSerDe() throws Exception {
         Referenceable entity1 = new Referenceable("sometype");
@@ -34,9 +37,10 @@ public class HookNotificationTest {
         String user = "user";
         HookNotification.EntityCreateRequest request = new HookNotification.EntityCreateRequest(user,
entity1, entity2);
 
-        String notificationJson = AbstractNotificationConsumer.GSON.toJson(request);
-        HookNotification.HookNotificationMessage actualNotification = AbstractNotificationConsumer.GSON.fromJson(
-                notificationJson, HookNotification.HookNotificationMessage.class);
+        String notificationJson = AbstractNotification.GSON.toJson(request);
+        HookNotification.HookNotificationMessage actualNotification =
+            HOOK_MESSAGE_DESERIALIZER.deserialize(notificationJson);
+
         assertEquals(actualNotification.getType(), HookNotification.HookNotificationType.ENTITY_CREATE);
         assertEquals(actualNotification.getUser(), user);
 
@@ -56,7 +60,7 @@ public class HookNotificationTest {
         entity.set("attr", "value");
         HookNotification.EntityCreateRequest request = new HookNotification.EntityCreateRequest(null,
entity);
 
-        String notificationJsonFromCode = AbstractNotificationConsumer.GSON.toJson(request);
+        String notificationJsonFromCode = AbstractNotification.GSON.toJson(request);
         System.out.println(notificationJsonFromCode);
 
         //Json without user and assert that the string can be deserialised
@@ -82,8 +86,10 @@ public class HookNotificationTest {
                 + "  \"type\": \"ENTITY_CREATE\"\n"
                 + "}";
 
-        HookNotification.HookNotificationMessage actualNotification = AbstractNotificationConsumer.GSON.fromJson(
-                notificationJson, HookNotification.HookNotificationMessage.class);
+
+        HookNotification.HookNotificationMessage actualNotification =
+            HOOK_MESSAGE_DESERIALIZER.deserialize(notificationJson);
+
         assertEquals(actualNotification.getType(), HookNotification.HookNotificationType.ENTITY_CREATE);
         assertNull(actualNotification.user);
         assertEquals(actualNotification.getUser(), HookNotification.HookNotificationMessage.UNKNOW_USER);

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/b2ae1371/release-log.txt
----------------------------------------------------------------------
diff --git a/release-log.txt b/release-log.txt
index de16600..da3e6d2 100644
--- a/release-log.txt
+++ b/release-log.txt
@@ -18,6 +18,7 @@ ATLAS-409 Atlas will not import avro tables with schema read from a file
(dosset
 ATLAS-379 Create sqoop and falcon metadata addons (venkatnrangan,bvellanki,sowmyaramesh via
shwethags)
 
 ALL CHANGES:
+ATLAS-631 Introduce Versioning to Atlas Notification Payload (tbeerbower via shwethags)
 ATLAS-723 JSON deserialization regression (guptaneeru via shwethags)
 ATLAS-728 Fix few typos in committer email IDs (yhemanth)
 ATLAS-435 Add ORDER BY and Limit to search DSL (neerugupta via sumasai)


Mime
View raw message