|
| 1 | +/* |
| 2 | + * Copyright 2023 the original author or authors. |
| 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 | + * https://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 org.springframework.data.relational.schemasqlgeneration; |
| 17 | + |
| 18 | +import org.junit.jupiter.api.Test; |
| 19 | +import org.springframework.data.relational.core.mapping.Column; |
| 20 | +import org.springframework.data.relational.core.mapping.RelationalMappingContext; |
| 21 | +import org.springframework.data.relational.core.mapping.Table; |
| 22 | +import org.springframework.data.relational.core.mapping.schemasqlgeneration.SchemaSQLGenerationDataModel; |
| 23 | +import org.springframework.data.relational.core.mapping.schemasqlgeneration.TableModel; |
| 24 | + |
| 25 | +import static org.assertj.core.api.Assertions.assertThat; |
| 26 | + |
| 27 | +/** |
| 28 | + * Unit tests for the {@link SchemaSQLGenerationDataModel}. |
| 29 | + * |
| 30 | + * @author Kurt Niemi |
| 31 | + */ |
| 32 | +public class SchemaSQLGenerationDataModelTests { |
| 33 | + |
| 34 | + @Test |
| 35 | + void testBasicModelGeneration() { |
| 36 | + RelationalMappingContext context = new RelationalMappingContext(); |
| 37 | + context.getRequiredPersistentEntity(SchemaSQLGenerationDataModelTests.Luke.class); |
| 38 | + context.getRequiredPersistentEntity(SchemaSQLGenerationDataModelTests.Vader.class); |
| 39 | + |
| 40 | + SchemaSQLGenerationDataModel model = context.generateSchemaSQL(); |
| 41 | + |
| 42 | + assertThat(model.getTableData().size()).isEqualTo(2); |
| 43 | + |
| 44 | + TableModel t1 = model.getTableData().get(0); |
| 45 | + assertThat(t1.getName()).isEqualTo("luke"); |
| 46 | + assertThat(t1.getColumns().get(0).getName()).isEqualTo("force"); |
| 47 | + assertThat(t1.getColumns().get(1).getName()).isEqualTo("be"); |
| 48 | + assertThat(t1.getColumns().get(2).getName()).isEqualTo("with"); |
| 49 | + assertThat(t1.getColumns().get(3).getName()).isEqualTo("you"); |
| 50 | + |
| 51 | + TableModel t2 = model.getTableData().get(1); |
| 52 | + assertThat(t2.getName()).isEqualTo("vader"); |
| 53 | + assertThat(t2.getColumns().get(0).getName()).isEqualTo("luke_i_am_your_father"); |
| 54 | + assertThat(t2.getColumns().get(1).getName()).isEqualTo("dark_side"); |
| 55 | + } |
| 56 | + |
| 57 | + @Table |
| 58 | + static class Luke { |
| 59 | + @Column |
| 60 | + public String force; |
| 61 | + @Column |
| 62 | + public String be; |
| 63 | + @Column |
| 64 | + public String with; |
| 65 | + @Column |
| 66 | + public String you; |
| 67 | + } |
| 68 | + |
| 69 | + @Table |
| 70 | + static class Vader { |
| 71 | + @Column |
| 72 | + public String lukeIAmYourFather; |
| 73 | + @Column |
| 74 | + public Boolean darkSide; |
| 75 | + } |
| 76 | + |
| 77 | + |
| 78 | +} |
0 commit comments