|
| 1 | +/* |
| 2 | + * Copyright (c) 2023 Oracle and/or its affiliates. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package io.helidon.dbclient.jsonp; |
| 17 | + |
| 18 | +import io.helidon.common.mapper.MapperManager; |
| 19 | +import io.helidon.dbclient.DbColumn; |
| 20 | +import io.helidon.dbclient.DbColumnBase; |
| 21 | +import io.helidon.dbclient.DbMapperManager; |
| 22 | +import io.helidon.dbclient.DbRow; |
| 23 | +import io.helidon.dbclient.DbRowBase; |
| 24 | + |
| 25 | +import jakarta.json.JsonObject; |
| 26 | +import org.junit.jupiter.api.Test; |
| 27 | + |
| 28 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 29 | +import static org.hamcrest.Matchers.is; |
| 30 | + |
| 31 | +/** |
| 32 | + * Tests {@link io.helidon.dbclient.jsonp.JsonProcessingMapper}. |
| 33 | + */ |
| 34 | +class JsonProcessingMapperTest { |
| 35 | + |
| 36 | + private static final DbMapperManager DB_MAPPER_MANAGER = DbMapperManager.builder() |
| 37 | + .addMapperProvider(new JsonProcessingMapperProvider()) |
| 38 | + .build(); |
| 39 | + |
| 40 | + @Test |
| 41 | + void testRowAsJsonObject() { |
| 42 | + DbRow row = row(column("foo", "bar"), column("bob", "alice")); |
| 43 | + JsonObject jsonObject = row.as(JsonObject.class); |
| 44 | + assertThat(jsonObject.getString("foo"), is("bar")); |
| 45 | + } |
| 46 | + |
| 47 | + private static DbRow row(DbColumnBase... columns) { |
| 48 | + return new DbRowBase(columns, DB_MAPPER_MANAGER) { |
| 49 | + @Override |
| 50 | + public DbColumn column(String name) { |
| 51 | + return super.column(name); |
| 52 | + } |
| 53 | + }; |
| 54 | + } |
| 55 | + |
| 56 | + private static DbColumnBase column(String name, Object value) { |
| 57 | + return new DbColumnBase(value, MapperManager.create()) { |
| 58 | + |
| 59 | + @Override |
| 60 | + public Class<?> javaType() { |
| 61 | + return value.getClass(); |
| 62 | + } |
| 63 | + |
| 64 | + @Override |
| 65 | + public String dbType() { |
| 66 | + return "test"; |
| 67 | + } |
| 68 | + |
| 69 | + @Override |
| 70 | + public String name() { |
| 71 | + return name; |
| 72 | + } |
| 73 | + }; |
| 74 | + } |
| 75 | +} |
0 commit comments