class TestGraphsonWriter(unittest.TestCase): def setUp(self): self.writerClass = JanusGraphSONWriter() self.writer = None pass def test_mock_serializer(self): # Create Mock Object mockObj = X # Create Mock object's serializer serializer = MockSerializer # Register the serializer and object. and build it. self.writerClass.register_serializer(mockObj, serializer) self.writer = self.writerClass.build() # Test the updated writer build. mockObj = X() # Serialize mock object into GSON mockGSON = self.writer.writeObject(mockObj) # Retrive actual serialization from MockSerializer mockSer = MockSerializer().serialize(mockObj) expectedJSON = json.loads(mockGSON) actualJSON = mockSer.get_serialized_json() self.assertEqual(expectedJSON, actualJSON)
def test_point_serialization(self): latitude = 80 longitude = 100 point = Point(latitude, longitude) writer = JanusGraphSONWriter().build() graphSON = writer.writeObject(point) expectedJSON = dict() expectedJSON["@type"] = "janusgraph:Geoshape" expectedJSON["@value"] = dict() expectedJSON["@value"]["type"] = "Point" expectedJSON["@value"]["coordinates"] = list() expectedJSON["@value"]["coordinates"].append({ "@type": "g:Double", "@value": float(longitude) }) expectedJSON["@value"]["coordinates"].append({ "@type": "g:Double", "@value": float(latitude) }) actualGson = json.loads(graphSON) self.assertEqual(actualGson, expectedJSON)
def setUp(self): self.latitude = 80 self.longitude = 100 self.point = Point(self.longitude, self.latitude) self.writer = JanusGraphSONWriter().build() pass
def setUp(self): self.latitude = 80 self.longitude = 100 self.radius = 5 self.circle = Circle(self.longitude, self.latitude, self.radius) self.writer = JanusGraphSONWriter().build() pass
def test_relationID_serialization(self): relationID = "74q-9n4-b2t-cr4" edge = RelationIdentifier(relationID) writer = JanusGraphSONWriter().build() graphSON = writer.writeObject(edge) expectedJSON = dict() expectedJSON["@type"] = "janusgraph:RelationIdentifier" expectedJSON["@value"] = {"relationId": relationID} actualJSON = json.loads(graphSON) self.assertEqual(expectedJSON, actualJSON)
class TestCircleSerialization(unittest.TestCase): def setUp(self): self.latitude = 80 self.longitude = 100 self.radius = 5 self.circle = Circle(self.longitude, self.latitude, self.radius) self.writer = JanusGraphSONWriter().build() pass def test_circle_serialization(self): graphSON = self.writer.writeObject(self.circle) expectedJSONStr = "{\"@type\":\"janusgraph:Geoshape\",\"@value\":{\"geometry\":{\"type\":\"Circle\", \ \"coordinates\":[{\"@type\":\"g:Double\",\"@value\":" + str( self.latitude) + "},\ {\"@type\":\"g:Double\",\"@value\":" + str( self.longitude) + "}], \"radius\":{\"@type\":\"g:Double\",\ \"@value\":" + str( self.radius ) + "},\"properties\":{\"radius_units\":\"km\"}}}}" actualGson = json.loads(graphSON) expectedGson = json.loads(expectedJSONStr) self.assertEqual(actualGson, expectedGson) pass
class TestCircleSerialization(unittest.TestCase): def setUp(self): self.latitude = 80 self.longitude = 100 self.point = Point(self.longitude, self.latitude) self.writer = JanusGraphSONWriter().build() pass def test_point_serialization(self): graphSON = self.writer.writeObject(self.point) expectedJSONStr = "{\"@type\":\"janusgraph:Geoshape\",\"@value\":{\"type\":\"Point\", \ \"coordinates\":[{\"@type\":\"g:Double\",\"@value\":" + str( self.latitude) + "},\ {\"@type\":\"g:Double\",\"@value\":" + str( self.longitude) + "}]}}" actualGson = json.loads(graphSON) expectedGson = json.loads(expectedJSONStr) self.assertEqual(actualGson, expectedGson) pass
def test_circle_serialization(self): latitude = 80 longitude = 100 radius = 5 circle = Circle(latitude, longitude, radius) writer = JanusGraphSONWriter().build() graphSON = writer.writeObject(circle) expectedJSON = dict() expectedJSON["@type"] = "janusgraph:Geoshape" expectedJSON["@value"] = dict() expectedJSON["@value"]["geometry"] = dict() expectedJSON["@value"]["geometry"]["type"] = "Circle" expectedJSON["@value"]["geometry"]["coordinates"] = list() expectedJSON["@value"]["geometry"]["coordinates"].append({ "@type": "g:Double", "@value": float(longitude) }) expectedJSON["@value"]["geometry"]["coordinates"].append({ "@type": "g:Double", "@value": float(latitude) }) expectedJSON["@value"]["geometry"]["radius"] = dict() expectedJSON["@value"]["geometry"]["radius"]["@type"] = "g:Double" expectedJSON["@value"]["geometry"]["radius"]["@value"] = radius expectedJSON["@value"]["geometry"]["properties"] = { "radius_units": "km" } actualGson = json.loads(graphSON) self.assertEqual(actualGson, expectedJSON)
class TestRelationIdentifierSerializer(unittest.TestCase): def setUp(self): self.relationID = "74q-9n4-b2t-cr4" self.edge = RelationIdentifier(self.relationID) self.writer = JanusGraphSONWriter().build() pass def test_relationID_serialization(self): graphSON = self.writer.writeObject(self.edge) expectedJSONStr = "{\"@type\":\"janusgraph:RelationIdentifier\",\"@value\": {\"relationId\": \"" + self.relationID + "\"}}" expectedJSON = json.loads(expectedJSONStr) actualJSON = json.loads(graphSON) self.assertEqual(expectedJSON, actualJSON) pass
def setUp(self): self.writerClass = JanusGraphSONWriter() self.writer = None pass
def setUp(self): self.relationID = "74q-9n4-b2t-cr4" self.edge = RelationIdentifier(self.relationID) self.writer = JanusGraphSONWriter().build() pass