-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[java-generator] Fix additionalProperties ser/deser
- Loading branch information
Showing
6 changed files
with
300 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
java-generator/it/src/it/preserve-unknown-serdeser/invoker.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
invoker.goals=test |
88 changes: 88 additions & 0 deletions
88
java-generator/it/src/it/preserve-unknown-serdeser/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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. | ||
--> | ||
<project> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>preserve-unknown-serdeser</artifactId> | ||
<groupId>io.fabric8.it</groupId> | ||
<version>0.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<maven.compiler.source>@maven.compiler.source@</maven.compiler.source> | ||
<maven.compiler.target>@maven.compiler.target@</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.fabric8</groupId> | ||
<artifactId>java-generator-integration-tests</artifactId> | ||
<version>@project.version@</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.fabric8</groupId> | ||
<artifactId>generator-annotations</artifactId> | ||
<version>@project.version@</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<version>@junit.version@</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<version>@junit.version@</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.fabric8</groupId> | ||
<artifactId>java-generator-maven-plugin</artifactId> | ||
<version>@project.version@</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>generate</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<source>src/test/resources/dapr-components-crd.yaml</source> | ||
<generatedAnnotations>false</generatedAnnotations> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>3.0.0-M7</version> | ||
<configuration> | ||
<useFile>false</useFile> | ||
<trimStackTrace>false</trimStackTrace> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
90 changes: 90 additions & 0 deletions
90
...unknown-serdeser/src/test/java/io/fabric8/it/certmanager/TestPreserveUnkonwnSerDeser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/** | ||
* 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.it.certmanager; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import io.dapr.v1alpha1.Component; | ||
import io.dapr.v1alpha1.ComponentSpec; | ||
import io.fabric8.kubernetes.api.model.AnyType; | ||
import io.fabric8.kubernetes.api.model.ObjectMeta; | ||
import io.fabric8.kubernetes.client.utils.Serialization; | ||
import org.junit.jupiter.api.Test; | ||
import io.fabric8.java.generator.testing.KubernetesResourceDiff; | ||
|
||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.nio.file.Files; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class TestPreserveUnknownSerDeser { | ||
|
||
@Test | ||
void testDeserialization() { | ||
// Arrange | ||
Component sample = | ||
Serialization.unmarshal(getClass().getResourceAsStream("/sample.yaml"), Component.class); | ||
|
||
// Act | ||
Map<String, Object> testObj = sample.getSpec().getTest().getAdditionalProperties(); | ||
|
||
// Assert | ||
assertEquals(2, testObj.size()); | ||
// TODO check content | ||
} | ||
|
||
private Component createSampleComponent() throws Exception { | ||
Component component = new Component(); | ||
ComponentSpec spec = new ComponentSpec(); | ||
|
||
io.dapr.v1alpha1.componentspec.Test t = new io.dapr.v1alpha1.componentspec.Test(); | ||
|
||
t.setAdditionalProperties("one", "ONE"); | ||
|
||
HashMap<String, Object> twoContent = new HashMap(); | ||
twoContent.put("more", 1); | ||
twoContent.put("complex", true); | ||
t.setAdditionalProperties("two", twoContent); | ||
|
||
spec.setTest(t); | ||
|
||
component.setSpec(spec); | ||
ObjectMeta om = new ObjectMeta(); | ||
om.setName("messagebus"); | ||
component.setMetadata(om); | ||
|
||
return component; | ||
} | ||
|
||
@Test | ||
void testAgainstSample() throws Exception { | ||
// Arrange | ||
Path resPath = Paths.get(getClass().getResource("/sample.yaml").toURI()); | ||
String yamlContent = new String(Files.readAllBytes(resPath), "UTF8"); | ||
Component sample = createSampleComponent(); | ||
KubernetesResourceDiff diff = new KubernetesResourceDiff(yamlContent, Serialization.asYaml(sample)); | ||
|
||
// Act | ||
List<JsonNode> aggregatedDiffs = diff.getListOfDiffs(); | ||
|
||
// Assert | ||
assertEquals(0, aggregatedDiffs.size()); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...generator/it/src/it/preserve-unknown-serdeser/src/test/resources/dapr-components-crd.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
apiVersion: apiextensions.k8s.io/v1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
name: components.dapr.io | ||
spec: | ||
group: dapr.io | ||
versions: | ||
- name: v1alpha1 | ||
schema: | ||
openAPIV3Schema: | ||
description: Component describes an Dapr component type | ||
properties: | ||
apiVersion: | ||
description: 'APIVersion defines the versioned schema of this representation | ||
of an object. Servers should convert recognized schemas to the latest | ||
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' | ||
type: string | ||
auth: | ||
description: Auth represents authentication details for the component | ||
properties: | ||
secretStore: | ||
type: string | ||
required: | ||
- secretStore | ||
type: object | ||
kind: | ||
description: 'Kind is a string value representing the REST resource this | ||
object represents. Servers may infer this from the endpoint the client | ||
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' | ||
type: string | ||
metadata: | ||
type: object | ||
scopes: | ||
items: | ||
type: string | ||
type: array | ||
spec: | ||
description: ComponentSpec is the spec for a component | ||
type: object | ||
properties: | ||
test: | ||
type: object | ||
x-kubernetes-preserve-unknown-fields: true | ||
type: object | ||
served: true | ||
storage: true | ||
names: | ||
kind: Component | ||
plural: components | ||
singular: component | ||
categories: | ||
- all | ||
- dapr | ||
scope: Namespaced |
26 changes: 26 additions & 0 deletions
26
java-generator/it/src/it/preserve-unknown-serdeser/src/test/resources/sample.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
apiVersion: dapr.io/v1alpha1 | ||
kind: Component | ||
metadata: | ||
name: messagebus | ||
spec: | ||
test: | ||
one: "ONE" | ||
two: | ||
more: 1 | ||
complex: true |