|
| 1 | +/* |
| 2 | + * DISCLAIMER |
| 3 | + * |
| 4 | + * Copyright 2016 ArangoDB GmbH, Cologne, Germany |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + * |
| 18 | + * Copyright holder is ArangoDB GmbH, Cologne, Germany |
| 19 | + */ |
| 20 | + |
| 21 | +package com.arangodb.internal.velocypack; |
| 22 | + |
| 23 | +import com.arangodb.entity.ViewType; |
| 24 | +import com.arangodb.entity.arangosearch.ArangoSearchCompression; |
| 25 | +import com.arangodb.entity.arangosearch.ArangoSearchProperties; |
| 26 | +import com.arangodb.entity.arangosearch.StoredValue; |
| 27 | +import com.arangodb.model.arangosearch.ArangoSearchCreateOptions; |
| 28 | +import com.arangodb.velocypack.VPack; |
| 29 | +import com.arangodb.velocypack.VPackSlice; |
| 30 | +import org.junit.Before; |
| 31 | +import org.junit.Test; |
| 32 | + |
| 33 | +import java.util.Collections; |
| 34 | + |
| 35 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 36 | +import static org.hamcrest.Matchers.is; |
| 37 | +import static org.hamcrest.Matchers.notNullValue; |
| 38 | + |
| 39 | +public class VPackSerializersTest { |
| 40 | + |
| 41 | + private VPack vpack; |
| 42 | + |
| 43 | + @Before |
| 44 | + public void init() { |
| 45 | + vpack = new VPack.Builder() |
| 46 | + .registerSerializer(ArangoSearchProperties.class, VPackSerializers.ARANGO_SEARCH_PROPERTIES) |
| 47 | + .build(); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + public void serializeArangoSearchProperties() { |
| 52 | + final ArangoSearchCreateOptions opts = new ArangoSearchCreateOptions() |
| 53 | + .storedValues(new StoredValue(Collections.singletonList("dummy"), ArangoSearchCompression.lz4)); |
| 54 | + |
| 55 | + final VPackSlice slice = vpack.serialize(opts); |
| 56 | + |
| 57 | + assertThat(slice.isObject(), is(true)); |
| 58 | + assertThat(slice.get("type").isString(), is(true)); |
| 59 | + assertThat(slice.get("type").getAsString(), is(ViewType.ARANGO_SEARCH.name())); |
| 60 | + assertThat(slice.get("storedValues"), notNullValue()); |
| 61 | + assertThat(slice.get("storedValues").isArray(), is(true)); |
| 62 | + assertThat(slice.get("storedValues").size(), is(1)); |
| 63 | + assertThat(slice.get("storedValues").get(0).isObject(), is(true)); |
| 64 | + assertThat(slice.get("storedValues").get(0).get("fields").isArray(), is(true)); |
| 65 | + assertThat(slice.get("storedValues").get(0).get("fields").size(), is(1)); |
| 66 | + assertThat(slice.get("storedValues").get(0).get("fields").get(0).isString(), is(true)); |
| 67 | + assertThat(slice.get("storedValues").get(0).get("fields").get(0).getAsString(), is("dummy")); |
| 68 | + assertThat(slice.get("storedValues").get(0).get("compression").isString(), is(true)); |
| 69 | + assertThat(slice.get("storedValues").get(0).get("compression").getAsString(), is(ArangoSearchCompression.lz4.name())); |
| 70 | + } |
| 71 | + |
| 72 | + @Test |
| 73 | + public void serializeArangoSearchPropertiesWithDefaultCompression() { |
| 74 | + final ArangoSearchCreateOptions opts = new ArangoSearchCreateOptions() |
| 75 | + .storedValues(new StoredValue(Collections.singletonList("dummy"))); |
| 76 | + |
| 77 | + final VPackSlice slice = vpack.serialize(opts); |
| 78 | + |
| 79 | + assertThat(slice.get("storedValues").get(0).get("compression").isNone(), is(true)); |
| 80 | + } |
| 81 | +} |
0 commit comments