|
| 1 | +/* |
| 2 | + * Copyright (C) 2015 Red Hat, Inc. |
| 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.fabric8.crd.generator.types; |
| 17 | + |
| 18 | +import io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition; |
| 19 | +import io.fabric8.kubernetes.client.utils.Serialization; |
| 20 | +import org.junit.jupiter.api.BeforeEach; |
| 21 | +import org.junit.jupiter.params.ParameterizedTest; |
| 22 | +import org.junit.jupiter.params.provider.Arguments; |
| 23 | +import org.junit.jupiter.params.provider.MethodSource; |
| 24 | + |
| 25 | +import java.util.stream.Stream; |
| 26 | + |
| 27 | +import static org.assertj.core.api.Assertions.assertThat; |
| 28 | + |
| 29 | +class TypeMappingsTest { |
| 30 | + |
| 31 | + private CustomResourceDefinition crd; |
| 32 | + |
| 33 | + @BeforeEach |
| 34 | + void setUp() { |
| 35 | + crd = Serialization.unmarshal( |
| 36 | + TypeMappingsTest.class.getResourceAsStream("/META-INF/fabric8/typemappings.type-mappings.fabric8.io-v1.yml"), |
| 37 | + CustomResourceDefinition.class); |
| 38 | + } |
| 39 | + |
| 40 | + @ParameterizedTest(name = "{0} type maps to {1}") |
| 41 | + @MethodSource("targetTypeCases") |
| 42 | + void targetType(String propertyName, String expectedType) { |
| 43 | + assertThat(crd.getSpec().getVersions().iterator().next().getSchema().getOpenAPIV3Schema().getProperties()) |
| 44 | + .extracting(schema -> schema.get("spec").getProperties()) |
| 45 | + .returns(expectedType, specProps -> specProps.get(propertyName).getType()); |
| 46 | + } |
| 47 | + |
| 48 | + private static Stream<Arguments> targetTypeCases() { |
| 49 | + return Stream.of( |
| 50 | + Arguments.of("date", "string"), |
| 51 | + Arguments.of("localDate", "object"), // to review |
| 52 | + Arguments.of("localDateTime", "object"), // to review |
| 53 | + Arguments.of("zonedDateTime", "object"), // to review |
| 54 | + Arguments.of("offsetDateTime", "object"), // to review |
| 55 | + Arguments.of("offsetTime", "object"), // to review |
| 56 | + Arguments.of("yearMonth", "object"), // to review |
| 57 | + Arguments.of("monthDay", "object"), // to review |
| 58 | + Arguments.of("instant", "object"), // to review |
| 59 | + Arguments.of("duration", "object"), // to review |
| 60 | + Arguments.of("period", "object"), // to review |
| 61 | + Arguments.of("timestamp", "object"), // to review |
| 62 | + // Arguments.of("aShort", "integer"), // TODO: Not even present in the CRD |
| 63 | + Arguments.of("aShortObj", "object"), // to review |
| 64 | + Arguments.of("aInt", "integer"), |
| 65 | + Arguments.of("aIntegerObj", "integer"), |
| 66 | + Arguments.of("aLong", "integer"), |
| 67 | + Arguments.of("aLongObj", "integer"), |
| 68 | + Arguments.of("aDouble", "number"), |
| 69 | + Arguments.of("aDoubleObj", "number"), |
| 70 | + Arguments.of("aFloat", "number"), |
| 71 | + Arguments.of("aFloatObj", "number"), |
| 72 | + Arguments.of("aNumber", "object"), // to review |
| 73 | + Arguments.of("aBigInteger", "object"), // to review |
| 74 | + Arguments.of("aBigDecimal", "object"), // to review |
| 75 | + Arguments.of("aBoolean", "boolean"), |
| 76 | + Arguments.of("aBooleanObj", "boolean"), |
| 77 | + // Arguments.of("aChar", "string"), // TODO: Not even present in the CRD |
| 78 | + Arguments.of("aCharacterObj", "object"), // to review |
| 79 | + Arguments.of("aCharArray", "array"), |
| 80 | + Arguments.of("aCharSequence", "object"), // to review |
| 81 | + Arguments.of("aString", "string"), |
| 82 | + Arguments.of("aStringArray", "array"), |
| 83 | + // Arguments.of("aByte", "?"), // TODO: Not even present in the CRD |
| 84 | + Arguments.of("aByteObj", "object"), // to review |
| 85 | + Arguments.of("aByteArray", "array"), // to review, should be string (base64) |
| 86 | + Arguments.of("uuid", "object")); // to review, should be string |
| 87 | + } |
| 88 | + |
| 89 | +} |
0 commit comments