diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/example/cyclic/CyclicList.java b/crd-generator/api/src/test/java/io/fabric8/crd/example/cyclic/CyclicList.java new file mode 100644 index 00000000000..fdc047935e4 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/example/cyclic/CyclicList.java @@ -0,0 +1,27 @@ +/** + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.example.cyclic; + +import io.fabric8.kubernetes.api.model.Namespaced; +import io.fabric8.kubernetes.client.CustomResource; +import io.fabric8.kubernetes.model.annotation.Group; +import io.fabric8.kubernetes.model.annotation.Version; + +@Group("sample.fabric8.io") +@Version("v1alpha1") +public class CyclicList extends CustomResource implements Namespaced { + +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/example/cyclic/CyclicListSpec.java b/crd-generator/api/src/test/java/io/fabric8/crd/example/cyclic/CyclicListSpec.java new file mode 100644 index 00000000000..a5f0798b2a0 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/example/cyclic/CyclicListSpec.java @@ -0,0 +1,22 @@ +/** + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.example.cyclic; + +import java.util.List; + +public class CyclicListSpec { + private List ref; +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/example/cyclic/RefList.java b/crd-generator/api/src/test/java/io/fabric8/crd/example/cyclic/RefList.java new file mode 100644 index 00000000000..f1bd5c9bc25 --- /dev/null +++ b/crd-generator/api/src/test/java/io/fabric8/crd/example/cyclic/RefList.java @@ -0,0 +1,24 @@ +/** + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fabric8.crd.example.cyclic; + +import java.util.List; + +public class RefList { + + private List ref; + +} diff --git a/crd-generator/api/src/test/java/io/fabric8/crd/generator/CRDGeneratorTest.java b/crd-generator/api/src/test/java/io/fabric8/crd/generator/CRDGeneratorTest.java index 2e8c98c9fa8..1565545b1a4 100644 --- a/crd-generator/api/src/test/java/io/fabric8/crd/generator/CRDGeneratorTest.java +++ b/crd-generator/api/src/test/java/io/fabric8/crd/generator/CRDGeneratorTest.java @@ -19,6 +19,7 @@ import io.fabric8.crd.example.basic.BasicSpec; import io.fabric8.crd.example.basic.BasicStatus; import io.fabric8.crd.example.cyclic.Cyclic; +import io.fabric8.crd.example.cyclic.CyclicList; import io.fabric8.crd.example.inherited.*; import io.fabric8.crd.example.joke.Joke; import io.fabric8.crd.example.joke.JokeRequest; @@ -210,6 +211,20 @@ void generatingACycleShouldFail() { .forCRDVersions("v1", "v1beta1") .withOutput(output); + assertThrows( + IllegalArgumentException.class, + () -> generator.detailedGenerate(), + "An IllegalArgument Exception hasn't been thrown when generating a CRD with cyclic references" + ); + } + + @Test + void generatingACycleInListShouldFail() { + final CRDGenerator generator = new CRDGenerator() + .customResourceClasses(CyclicList.class) + .forCRDVersions("v1", "v1beta1") + .withOutput(output); + assertThrows( IllegalArgumentException.class, () -> generator.detailedGenerate(),