Beispiel #1
0
 public function testGetDocument()
 {
     $type = self::$index->getType('message');
     $document = $type->getDocument(1);
     $message = $this->marshaler->unmarshal($document);
     $this->assertTrue($this->message->equals($message));
 }
Beispiel #2
0
 public function testAddToMessage()
 {
     $message = EmailMessage::create();
     $field = DynamicField::createFloatVal('float_val', 3.14);
     $message->addToList('dynamic_fields', [$field]);
     $this->assertTrue($message->getFromListAt('dynamic_fields', 0)->equals($field));
 }
Beispiel #3
0
 public function testGetItem()
 {
     try {
         $result = self::$client->getItem(['TableName' => self::$tableName, 'ConsistentRead' => true, 'Key' => ['id' => ['S' => $this->message->get('id')->toString()]]]);
     } catch (\Exception $e) {
         $this->fail($e->getMessage());
         return;
     }
     $this->assertSame($result['Item']['id']['S'], $this->message->get('id')->toString());
     $message = $this->marshaler->unmarshal($result['Item']);
     foreach ($this->message->schema()->getFields() as $field) {
         $expected = $this->message->get($field->getName());
         $actual = $message->get($field->getName());
         if ($field->isASet()) {
             sort($expected);
             sort($actual);
         }
         $this->assertSame(json_encode($expected), json_encode($actual));
     }
     //echo json_encode($message, JSON_PRETTY_PRINT);
 }
Beispiel #4
0
<?php

error_reporting(-1);
date_default_timezone_set('UTC');
// Ensure that composer has installed all dependencies
if (!file_exists(dirname(__DIR__) . '/composer.lock')) {
    die("Dependencies must be installed using composer:\n\nphp composer.phar install\n\n" . "See http://getcomposer.org for help with installing composer\n");
}
// Include the composer autoloader
$loader = (require dirname(__DIR__) . '/vendor/autoload.php');
// auto registers the schema with the MessageResolver
// only done for tests or dynamic messages.
\Gdbots\Tests\Pbj\Fixtures\EmailMessage::schema();
\Gdbots\Tests\Pbj\Fixtures\NestedMessage::schema();
\Gdbots\Tests\Pbj\Fixtures\MapsMessage::schema();
Beispiel #5
0
 public function testAnyOfMessageInList()
 {
     $message = EmailMessage::create()->addToList('any_of_message', [MapsMessage::create()->addToMap('String', 'test:field:name', 'value1'), NestedMessage::create()->set('test1', 'value1')]);
     $this->assertCount(2, $message->get('any_of_message'));
 }
Beispiel #6
0
    public function testCreate()
    {
        $type = new Type(new Index(new Client(), $this->indexName), 'pbj_test_type');
        $schema = EmailMessage::schema();
        $mapping = $this->factory->create($schema, 'english');
        $mapping->setType($type);
        $expected = <<<JSON
{
    "pbj_test_type": {
        "properties": {
            "_schema": {
                "type": "string",
                "index": "not_analyzed",
                "include_in_all": false
            },
            "id": {
                "type": "string",
                "index": "not_analyzed",
                "include_in_all": false
            },
            "from_name": {
                "type": "string",
                "analyzer": "english"
            },
            "from_email": {
                "type": "string",
                "analyzer": "pbj_keyword_analyzer",
                "include_in_all": false
            },
            "subject": {
                "type": "string",
                "analyzer": "english"
            },
            "body": {
                "type": "string",
                "analyzer": "english"
            },
            "priority": {
                "type": "integer",
                "include_in_all": false
            },
            "sent": {
                "type": "boolean",
                "include_in_all": false
            },
            "date_sent": {
                "type": "date",
                "include_in_all": false
            },
            "microtime_sent": {
                "type": "long",
                "include_in_all": false
            },
            "provider": {
                "type": "string",
                "index": "not_analyzed",
                "include_in_all": false
            },
            "labels": {
                "type": "string",
                "analyzer": "pbj_keyword_analyzer",
                "include_in_all": false
            },
            "nested": {
                "type": "object",
                "properties": {
                    "_schema": {
                        "type": "string",
                        "index": "not_analyzed",
                        "include_in_all": false
                    },
                    "test1": {
                        "type": "string",
                        "analyzer": "english"
                    },
                    "test2": {
                        "type": "long",
                        "include_in_all": false
                    },
                    "location": {
                        "type": "geo_point",
                        "include_in_all": false
                    },
                    "refs": {
                        "type": "object",
                        "properties": {
                            "curie": {
                                "type": "string",
                                "index": "not_analyzed",
                                "include_in_all": false
                            },
                            "id": {
                                "type": "string",
                                "index": "not_analyzed",
                                "include_in_all": false
                            },
                            "tag": {
                                "type": "string",
                                "index": "not_analyzed",
                                "include_in_all": false
                            }
                        }
                    }
                }
            },
            "enum_in_set": {
                "type": "string",
                "index": "not_analyzed",
                "include_in_all": false
            },
            "enum_in_list": {
                "type": "string",
                "index": "not_analyzed",
                "include_in_all": false
            },
            "any_of_message": {
                "type": "nested",
                "properties": {
                    "_schema": {
                        "type": "string",
                        "index": "not_analyzed",
                        "include_in_all": false
                    }
                }
            },
            "dynamic_fields": {
                "type": "nested",
                "properties": {
                    "name": {
                        "type": "string",
                        "index": "not_analyzed",
                        "include_in_all": false
                    },
                    "bool_val": {
                        "type": "boolean",
                        "include_in_all": false
                    },
                    "date_val": {
                        "type": "date",
                        "include_in_all": false
                    },
                    "float_val": {
                        "type": "float",
                        "include_in_all": false
                    },
                    "int_val": {
                        "type": "long",
                        "include_in_all": false
                    },
                    "string_val": {
                        "type": "string",
                        "analyzer": "english"
                    },
                    "text_val": {
                        "type": "string",
                        "analyzer": "english"
                    }
                }
            }
        }
    }
}
JSON;
        $this->assertSame($expected, json_encode($mapping->toArray(), JSON_PRETTY_PRINT));
        $schema = MapsMessage::schema();
        $mapping = $this->factory->create($schema, 'english');
        $mapping->setType($type);
        $expected = <<<JSON
{
    "pbj_test_type": {
        "properties": {
            "_schema": {
                "type": "string",
                "index": "not_analyzed",
                "include_in_all": false
            }
        },
        "dynamic_templates": [
            {
                "bigint_template": {
                    "path_match": "BigInt.*",
                    "mapping": {
                        "type": "long",
                        "include_in_all": false
                    }
                }
            },
            {
                "binary_template": {
                    "path_match": "Binary.*",
                    "mapping": {
                        "type": "binary"
                    }
                }
            },
            {
                "blob_template": {
                    "path_match": "Blob.*",
                    "mapping": {
                        "type": "binary"
                    }
                }
            },
            {
                "boolean_template": {
                    "path_match": "Boolean.*",
                    "mapping": {
                        "type": "boolean",
                        "include_in_all": false
                    }
                }
            },
            {
                "datetime_template": {
                    "path_match": "DateTime.*",
                    "mapping": {
                        "type": "date",
                        "include_in_all": false
                    }
                }
            },
            {
                "date_template": {
                    "path_match": "Date.*",
                    "mapping": {
                        "type": "date",
                        "include_in_all": false
                    }
                }
            },
            {
                "decimal_template": {
                    "path_match": "Decimal.*",
                    "mapping": {
                        "type": "double",
                        "include_in_all": false
                    }
                }
            },
            {
                "dynamicfield_template": {
                    "path_match": "DynamicField.*",
                    "mapping": {
                        "type": "object",
                        "properties": {
                            "name": {
                                "type": "string",
                                "index": "not_analyzed",
                                "include_in_all": false
                            },
                            "bool_val": {
                                "type": "boolean",
                                "include_in_all": false
                            },
                            "date_val": {
                                "type": "date",
                                "include_in_all": false
                            },
                            "float_val": {
                                "type": "float",
                                "include_in_all": false
                            },
                            "int_val": {
                                "type": "long",
                                "include_in_all": false
                            },
                            "string_val": {
                                "type": "string",
                                "analyzer": "english"
                            },
                            "text_val": {
                                "type": "string",
                                "analyzer": "english"
                            }
                        }
                    }
                }
            },
            {
                "float_template": {
                    "path_match": "Float.*",
                    "mapping": {
                        "type": "float",
                        "include_in_all": false
                    }
                }
            },
            {
                "geopoint_template": {
                    "path_match": "GeoPoint.*",
                    "mapping": {
                        "type": "geo_point",
                        "include_in_all": false
                    }
                }
            },
            {
                "identifier_template": {
                    "path_match": "Identifier.*",
                    "mapping": {
                        "type": "string",
                        "index": "not_analyzed",
                        "include_in_all": false
                    }
                }
            },
            {
                "intenum_template": {
                    "path_match": "IntEnum.*",
                    "mapping": {
                        "type": "integer",
                        "include_in_all": false
                    }
                }
            },
            {
                "int_template": {
                    "path_match": "Int.*",
                    "mapping": {
                        "type": "long",
                        "include_in_all": false
                    }
                }
            },
            {
                "mediumblob_template": {
                    "path_match": "MediumBlob.*",
                    "mapping": {
                        "type": "binary"
                    }
                }
            },
            {
                "mediumint_template": {
                    "path_match": "MediumInt.*",
                    "mapping": {
                        "type": "integer",
                        "include_in_all": false
                    }
                }
            },
            {
                "mediumtext_template": {
                    "path_match": "MediumText.*",
                    "mapping": {
                        "type": "string",
                        "analyzer": "english"
                    }
                }
            },
            {
                "messageref_template": {
                    "path_match": "MessageRef.*",
                    "mapping": {
                        "type": "object",
                        "properties": {
                            "curie": {
                                "type": "string",
                                "index": "not_analyzed",
                                "include_in_all": false
                            },
                            "id": {
                                "type": "string",
                                "index": "not_analyzed",
                                "include_in_all": false
                            },
                            "tag": {
                                "type": "string",
                                "index": "not_analyzed",
                                "include_in_all": false
                            }
                        }
                    }
                }
            },
            {
                "message_template": {
                    "path_match": "Message.*",
                    "mapping": {
                        "type": "object",
                        "properties": {
                            "_schema": {
                                "type": "string",
                                "index": "not_analyzed",
                                "include_in_all": false
                            },
                            "test1": {
                                "type": "string",
                                "analyzer": "english"
                            },
                            "test2": {
                                "type": "long",
                                "include_in_all": false
                            },
                            "location": {
                                "type": "geo_point",
                                "include_in_all": false
                            },
                            "refs": {
                                "type": "object",
                                "properties": {
                                    "curie": {
                                        "type": "string",
                                        "index": "not_analyzed",
                                        "include_in_all": false
                                    },
                                    "id": {
                                        "type": "string",
                                        "index": "not_analyzed",
                                        "include_in_all": false
                                    },
                                    "tag": {
                                        "type": "string",
                                        "index": "not_analyzed",
                                        "include_in_all": false
                                    }
                                }
                            }
                        }
                    }
                }
            },
            {
                "microtime_template": {
                    "path_match": "Microtime.*",
                    "mapping": {
                        "type": "long",
                        "include_in_all": false
                    }
                }
            },
            {
                "signedbigint_template": {
                    "path_match": "SignedBigInt.*",
                    "mapping": {
                        "type": "long",
                        "include_in_all": false
                    }
                }
            },
            {
                "signedint_template": {
                    "path_match": "SignedInt.*",
                    "mapping": {
                        "type": "integer",
                        "include_in_all": false
                    }
                }
            },
            {
                "signedmediumint_template": {
                    "path_match": "SignedMediumInt.*",
                    "mapping": {
                        "type": "long",
                        "include_in_all": false
                    }
                }
            },
            {
                "signedsmallint_template": {
                    "path_match": "SignedSmallInt.*",
                    "mapping": {
                        "type": "short",
                        "include_in_all": false
                    }
                }
            },
            {
                "signedtinyint_template": {
                    "path_match": "SignedTinyInt.*",
                    "mapping": {
                        "type": "byte",
                        "include_in_all": false
                    }
                }
            },
            {
                "smallint_template": {
                    "path_match": "SmallInt.*",
                    "mapping": {
                        "type": "integer",
                        "include_in_all": false
                    }
                }
            },
            {
                "stringenum_template": {
                    "path_match": "StringEnum.*",
                    "mapping": {
                        "type": "string",
                        "index": "not_analyzed",
                        "include_in_all": false
                    }
                }
            },
            {
                "string_template": {
                    "path_match": "String.*",
                    "mapping": {
                        "type": "string",
                        "analyzer": "english"
                    }
                }
            },
            {
                "text_template": {
                    "path_match": "Text.*",
                    "mapping": {
                        "type": "string",
                        "analyzer": "english"
                    }
                }
            },
            {
                "timestamp_template": {
                    "path_match": "Timestamp.*",
                    "mapping": {
                        "type": "date",
                        "include_in_all": false
                    }
                }
            },
            {
                "timeuuid_template": {
                    "path_match": "TimeUuid.*",
                    "mapping": {
                        "type": "string",
                        "index": "not_analyzed",
                        "include_in_all": false
                    }
                }
            },
            {
                "tinyint_template": {
                    "path_match": "TinyInt.*",
                    "mapping": {
                        "type": "short",
                        "include_in_all": false
                    }
                }
            },
            {
                "trinary_template": {
                    "path_match": "Trinary.*",
                    "mapping": {
                        "type": "short",
                        "include_in_all": false
                    }
                }
            },
            {
                "uuid_template": {
                    "path_match": "Uuid.*",
                    "mapping": {
                        "type": "string",
                        "index": "not_analyzed",
                        "include_in_all": false
                    }
                }
            }
        ]
    }
}
JSON;
        $expected = json_decode($expected, true);
        $actual = $mapping->toArray();
        $expected['pbj_test_type']['dynamic_templates'] = $this->sortDynamicTemplates($expected['pbj_test_type']['dynamic_templates']);
        $actual['pbj_test_type']['dynamic_templates'] = $this->sortDynamicTemplates($actual['pbj_test_type']['dynamic_templates']);
        $this->assertSame(json_encode($expected['pbj_test_type']['properties']), json_encode($actual['pbj_test_type']['properties']));
        $this->assertSame(json_encode($expected['pbj_test_type']['dynamic_templates']), json_encode($actual['pbj_test_type']['dynamic_templates']));
        //echo json_encode($mapping->toArray(), JSON_PRETTY_PRINT);
    }
Beispiel #7
0
 protected function getInvalidTypeValues()
 {
     return ['BigInt' => [new BigNumber(-1), new BigNumber('18446744073709551616')], 'Binary' => false, 'Blob' => false, 'Boolean' => 'not_a_bool', 'Date' => 'not_a_date', 'DateTime' => 'not_a_date', 'Decimal' => 1, 'DynamicField' => 'not_a_dynamic_field', 'Float' => 1, 'GeoPoint' => 'not_a_geo_point', 'IntEnum' => Priority::NORMAL(), 'Int' => [-1, 4294967296], 'MediumInt' => [-1, 16777216], 'MediumBlob' => false, 'MediumText' => false, 'Message' => EmailMessage::create(), 'MessageRef' => 'not_a_message_ref', 'Microtime' => microtime(), 'SignedBigInt' => [new BigNumber('-9223372036854775809'), new BigNumber('9223372036854775808')], 'SignedMediumInt' => [-8388609, 8388608], 'SignedSmallInt' => [-32769, 32768], 'SignedTinyInt' => [-129, 128], 'SmallInt' => [-1, 65536], 'StringEnum' => Provider::AOL(), 'String' => false, 'Text' => false, 'TimeUuid' => 'not_a_time_uuid', 'Timestamp' => 'not_a_timestamp', 'TinyInt' => [-1, 256], 'Uuid' => 'not_a_uuid'];
 }