Repository: EnMasseProject/enmasse
Pull request #2440 (2019-03-12 17:38:00)

Unit tests for plan builders

lulf: @enmasse-ci run tests testcase="plans.PlansTest"
lulf: @enmasse-ci run tests

Patch:
diff --git a/api-model/src/main/java/io/enmasse/admin/model/v1/AddressPlan.java b/api-model/src/main/java/io/enmasse/admin/model/v1/AddressPlan.java
index 1bfc1dc79..59f0aeaa3 100644
--- a/api-model/src/main/java/io/enmasse/admin/model/v1/AddressPlan.java
+++ b/api-model/src/main/java/io/enmasse/admin/model/v1/AddressPlan.java
@@ -5,9 +5,8 @@
 
 package io.enmasse.admin.model.v1;
 
-import com.fasterxml.jackson.annotation.JsonAnyGetter;
-import com.fasterxml.jackson.annotation.JsonAnySetter;
-import io.enmasse.common.model.AbstractHasMetadata;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
 import io.enmasse.common.model.DefaultCustomResource;
 import io.fabric8.kubernetes.api.model.Doneable;
 import io.sundr.builder.annotations.Buildable;
@@ -74,6 +73,7 @@ public class AddressPlan extends AbstractHasMetadataWithAdditionalProperties<Add
     }
 
     @Override
+    @JsonIgnore
     public String getShortDescription() {
         if (spec != null) {
             return spec.getShortDescription();
@@ -83,6 +83,7 @@ public class AddressPlan extends AbstractHasMetadataWithAdditionalProperties<Add
     }
 
     @Override
+    @JsonIgnore
     public String getAddressType() {
         if (spec != null) {
             return spec.getAddressType();
@@ -92,30 +93,35 @@ public class AddressPlan extends AbstractHasMetadataWithAdditionalProperties<Add
     }
 
     @Override
+    @JsonIgnore
     public Map<String, Double> getResources() {
         if (spec != null) {
             return spec.getResources();
         } else {
             Map<String, Double> returnedResources = new HashMap<>();
-            for (ResourceRequest resourceRequest : getRequiredResources()) {
+            for (ResourceRequest resourceRequest : requiredResources) {
                 returnedResources.put(resourceRequest.getName(), resourceRequest.getCredit());
             }
             return returnedResources;
         }
     }
 
+    @JsonIgnore
+    public List<ResourceRequest> getRequiredResources() {
+        return requiredResources;
+    }
+
+    @JsonProperty("shortDescription")
     public void setShortDescription(String shortDescription) {
         this.shortDescription = shortDescription;
     }
 
+    @JsonProperty("addressType")
     public void setAddressType(String addressType) {
         this.addressType = addressType;
     }
 
-    List<ResourceRequest> getRequiredResources() {
-        return requiredResources;
-    }
-
+    @JsonProperty("requiredResources")
     public void setRequiredResources(List<ResourceRequest> requiredResources) {
         this.requiredResources = requiredResources;
     }
diff --git a/api-model/src/main/java/io/enmasse/admin/model/v1/AddressSpacePlan.java b/api-model/src/main/java/io/enmasse/admin/model/v1/AddressSpacePlan.java
index 023ff3e24..7359ccdf1 100644
--- a/api-model/src/main/java/io/enmasse/admin/model/v1/AddressSpacePlan.java
+++ b/api-model/src/main/java/io/enmasse/admin/model/v1/AddressSpacePlan.java
@@ -13,6 +13,8 @@ import java.util.Objects;
 import com.fasterxml.jackson.annotation.JsonAnyGetter;
 import com.fasterxml.jackson.annotation.JsonAnySetter;
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
 import io.enmasse.common.model.AbstractHasMetadata;
 import io.enmasse.common.model.DefaultCustomResource;
 import io.fabric8.kubernetes.api.model.Doneable;
@@ -41,21 +43,40 @@ public class AddressSpacePlan extends AbstractHasMetadataWithAdditionalPropertie
     private List<String> addressPlans = new LinkedList<>();
 
     public AddressSpacePlan() {
-        super(KIND, AdminCrd.API_VERSION_V1BETA1);
+        super(KIND, AdminCrd.API_VERSION_V1BETA2);
     }
 
-    public void setResources(List<ResourceAllowance> resources) {
-        this.resources = resources;
+    public void setSpec(AddressSpacePlanSpec spec) {
+        this.spec = spec;
     }
-    
-    public List<ResourceAllowance> getResources() {
-        return resources;
+
+    public AddressSpacePlanSpec getSpec() {
+        return spec;
     }
 
-    public void setAddressPlans(List<String> addressPlans) {
-        this.addressPlans = addressPlans;
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+        AddressSpacePlan that = (AddressSpacePlan) o;
+        return Objects.equals(getMetadata(), that.getMetadata()) &&
+                Objects.equals(spec, that.getSpec());
     }
 
+    @Override
+    public int hashCode() {
+        return Objects.hash(getMetadata(), spec);
+    }
+
+    @Override
+    public String toString() {
+        return "AddressSpacePlan{" +
+                "metadata='" + getMetadata()+ '\'' +
+                ", spec='" + spec + '\'' +
+                '}';
+    }
+
+    @JsonIgnore
     @Override
     public Map<String, Double> getResourceLimits() {
         if (spec != null) {
@@ -69,6 +90,8 @@ public class AddressSpacePlan extends AbstractHasMetadataWithAdditionalPropertie
         }
     }
 
+    @JsonIgnore
+    @Override
     public List<String> getAddressPlans() {
         if (spec != null) {
             return spec.getAddressPlans();
@@ -77,10 +100,8 @@ public class AddressSpacePlan extends AbstractHasMetadataWithAdditionalPropertie
         }
     }
 
-    public void setShortDescription(String shortDescription) {
-        this.shortDescription = shortDescription;
-    }
-    
+    @JsonIgnore
+    @Override
     public String getShortDescription() {
         if (spec != null) {
             return spec.getShortDescription();
@@ -89,10 +110,8 @@ public class AddressSpacePlan extends AbstractHasMetadataWithAdditionalPropertie
         }
     }
 
-    public void setAddressSpaceType(String addressSpaceType) {
-        this.addressSpaceType = addressSpaceType;
-    }
-    
+    @JsonIgnore
+    @Override
     public String getAddressSpaceType() {
         if (spec != null) {
             return spec.getAddressSpaceType();
@@ -101,33 +120,29 @@ public class AddressSpacePlan extends AbstractHasMetadataWithAdditionalPropertie
         }
     }
 
-    @Override
-    public boolean equals(Object o) {
-        if (this == o) return true;
-        if (o == null || getClass() != o.getClass()) return false;
-        AddressSpacePlan that = (AddressSpacePlan) o;
-        return Objects.equals(getMetadata(), that.getMetadata()) &&
-                Objects.equals(spec, that.getSpec());
+    @JsonIgnore
+    public List<ResourceAllowance> getResources() {
+        return resources;
     }
 
-    @Override
-    public int hashCode() {
-        return Objects.hash(getMetadata(), spec);
+    @JsonProperty("resources")
+    public void setResources(List<ResourceAllowance> resources) {
+        this.resources = resources;
     }
 
-    @Override
-    public String toString() {
-        return "AddressSpacePlan{" +
-                "metadata='" + getMetadata()+ '\'' +
-                ", spec='" + spec + '\'' +
-                '}';
+    @JsonProperty("addressPlans")
+    public void setAddressPlans(List<String> addressPlans) {
+        this.addressPlans = addressPlans;
     }
 
-    public void setSpec(AddressSpacePlanSpec spec) {
-        this.spec = spec;
+    @JsonProperty("shortDescription")
+    public void setShortDescription(String shortDescription) {
+        this.shortDescription = shortDescription;
     }
 
-    public AddressSpacePlanSpec getSpec() {
-        return spec;
+    @JsonProperty("addressSpaceType")
+    public void setAddressSpaceType(String addressSpaceType) {
+        this.addressSpaceType = addressSpaceType;
     }
+
 }
diff --git a/api-model/src/main/java/io/enmasse/admin/model/v1/AddressSpacePlanSpec.java b/api-model/src/main/java/io/enmasse/admin/model/v1/AddressSpacePlanSpec.java
index 4efce16d8..ec7fa5073 100644
--- a/api-model/src/main/java/io/enmasse/admin/model/v1/AddressSpacePlanSpec.java
+++ b/api-model/src/main/java/io/enmasse/admin/model/v1/AddressSpacePlanSpec.java
@@ -24,7 +24,7 @@ public class AddressSpacePlanSpec extends AbstractWithAdditionalProperties {
     private String shortDescription;
     private String addressSpaceType;
     private Map<String, Double> resourceLimits = new HashMap<>();
-    private List<String> addressPlans;
+    private List<String> addressPlans = new ArrayList<>();
 
     public String getShortDescription() {
         return shortDescription;
diff --git a/pkg/apis/admin/v1beta1/types.go b/pkg/apis/admin/v1beta1/types.go
index e98ca5173..933fba7e2 100644
--- a/pkg/apis/admin/v1beta1/types.go
+++ b/pkg/apis/admin/v1beta1/types.go
@@ -54,6 +54,7 @@ type AuthenticationServiceSpecStandard struct {
 	RouteName          *string                                      `json:"routeName,omitempty"`
 	Image              *enmassev1beta1.ImageOverride                `json:"image,omitempty"`
 	InitImage          *enmassev1beta1.ImageOverride                `json:"initImage,omitempty"`
+	JvmOptions         *string                                      `json:"jvmOptions,omitempty"`
 	Resources          *corev1.ResourceRequirements                 `json:"resources,omitempty"`
 	Storage            *AuthenticationServiceSpecStandardStorage    `json:"storage,omitempty"`
 	Datasource         *AuthenticationServiceSpecStandardDatasource `json:"datasource,omitempty"`
diff --git a/pkg/apis/admin/v1beta1/zz_generated.deepcopy.go b/pkg/apis/admin/v1beta1/zz_generated.deepcopy.go
index ccfbfb423..8e62adc2f 100644
--- a/pkg/apis/admin/v1beta1/zz_generated.deepcopy.go
+++ b/pkg/apis/admin/v1beta1/zz_generated.deepcopy.go
@@ -213,6 +213,11 @@ func (in *AuthenticationServiceSpecStandard) DeepCopyInto(out *AuthenticationSer
 		*out = new(enmassev1beta1.ImageOverride)
 		**out = **in
 	}
+	if in.JvmOptions != nil {
+		in, out := &in.JvmOptions, &out.JvmOptions
+		*out = new(string)
+		**out = **in
+	}
 	if in.Resources != nil {
 		in, out := &in.Resources, &out.Resources
 		*out = new(v1.ResourceRequirements)
diff --git a/pkg/apis/iot/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/iot/v1alpha1/zz_generated.deepcopy.go
index e7c97276c..8064eef4c 100644
--- a/pkg/apis/iot/v1alpha1/zz_generated.deepcopy.go
+++ b/pkg/apis/iot/v1alpha1/zz_generated.deepcopy.go
@@ -10,6 +10,8 @@
 package v1alpha1
 
 import (
+	json "encoding/json"
+
 	v1beta1 "github.com/enmasseproject/enmasse/pkg/apis/enmasse/v1beta1"
 	runtime "k8s.io/apimachinery/pkg/runtime"
 )
@@ -305,6 +307,11 @@ func (in *IoTProjectList) DeepCopyObject() runtime.Object {
 func (in *IoTProjectSpec) DeepCopyInto(out *IoTProjectSpec) {
 	*out = *in
 	in.DownstreamStrategy.DeepCopyInto(&out.DownstreamStrategy)
+	if in.Configuration != nil {
+		in, out := &in.Configuration, &out.Configuration
+		*out = make(json.RawMessage, len(*in))
+		copy(*out, *in)
+	}
 	return
 }
 
diff --git a/pkg/controller/authenticationservice/standard.go b/pkg/controller/authenticationservice/standard.go
index 37ac1c538..998cdd99f 100644
--- a/pkg/controller/authenticationservice/standard.go
+++ b/pkg/controller/authenticationservice/standard.go
@@ -108,7 +108,11 @@ func applyStandardAuthServiceDeployment(authservice *adminv1beta1.Authentication
 	install.ApplyContainer(deployment, "keycloak", func(container *corev1.Container) {
 		install.ApplyContainerImage(container, "keycloak", authservice.Spec.Standard.Image)
 		install.ApplyEnvSimple(container, "KEYCLOAK_SASL_XOAUTH_BASE_URI", authservice.Annotations["enmasse.io/oauth-url"])
-		install.ApplyEnvSimple(container, "JAVA_OPTS", "-Dvertx.cacheDirBase=/tmp -Djboss.bind.address=0.0.0.0 -Djava.net.preferIPv4Stack=true -Duser.timezone=UTC -Xms512m -Xmx1024m")
+		jvmOptions := "-Dvertx.cacheDirBase=/tmp -Djboss.bind.address=0.0.0.0 -Djava.net.preferIPv4Stack=true -Duser.timezone=UTC"
+		if authservice.Spec.Standard.JvmOptions != nil {
+			jvmOptions += " " + *authservice.Spec.Standard.JvmOptions
+		}
+		install.ApplyEnvSimple(container, "JAVA_OPTS", jvmOptions)
 		install.ApplyEnvSecret(container, "KEYCLOAK_USER", "admin.username", authservice.Spec.Standard.CredentialsSecret.Name)
 		install.ApplyEnvSecret(container, "KEYCLOAK_PASSWORD", "admin.password", authservice.Spec.Standard.CredentialsSecret.Name)
 
diff --git a/templates/crds/authenticationservices.crd.yaml b/templates/crds/authenticationservices.crd.yaml
index b1ee1650d..08809f169 100644
--- a/templates/crds/authenticationservices.crd.yaml
+++ b/templates/crds/authenticationservices.crd.yaml
@@ -85,6 +85,8 @@ spec:
                       type: string
                     pullPolicy:
                       type: string
+                jvmOptions:
+                  type: string
                 image:
                   type: object
                   properties:


Test patch:
diff --git a/api-model/src/test/java/io/enmasse/address/model/v1/address/SerializationTest.java b/api-model/src/test/java/io/enmasse/address/model/v1/address/SerializationTest.java
index 0906ffd5f..5ba7cfaa9 100644
--- a/api-model/src/test/java/io/enmasse/address/model/v1/address/SerializationTest.java
+++ b/api-model/src/test/java/io/enmasse/address/model/v1/address/SerializationTest.java
@@ -17,14 +17,13 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.io.IOException;
 import java.net.URL;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.UUID;
+import java.util.*;
 
 import javax.validation.ConstraintViolationException;
 import javax.validation.ValidationException;
 
+import com.fasterxml.jackson.core.JsonProcessingException;
+import io.enmasse.admin.model.v1.*;
 import org.junit.jupiter.api.Test;
 import org.mockito.internal.util.collections.Sets;
 
@@ -39,13 +38,6 @@ import io.enmasse.address.model.AddressSpaceList;
 import io.enmasse.address.model.AddressSpaceSchema;
 import io.enmasse.address.model.AuthenticationServiceType;
 import io.enmasse.address.model.Phase;
-import io.enmasse.admin.model.v1.AddressPlan;
-import io.enmasse.admin.model.v1.AddressSpacePlan;
-import io.enmasse.admin.model.v1.AddressSpacePlanBuilder;
-import io.enmasse.admin.model.v1.BrokeredInfraConfig;
-import io.enmasse.admin.model.v1.BrokeredInfraConfigBuilder;
-import io.enmasse.admin.model.v1.StandardInfraConfig;
-import io.enmasse.admin.model.v1.StandardInfraConfigBuilder;
 import io.fabric8.kubernetes.api.model.networking.NetworkPolicyIngressRuleBuilder;
 
 // TODO: Add more tests of invalid input to deserialization
@@ -330,9 +322,9 @@ public class SerializationTest {
         assertThat(addressSpacePlan.getAdditionalProperties().get("displayName"), is("MySpace"));
         assertThat(addressSpacePlan.getAddressPlans().size(), is(1));
         assertThat(addressSpacePlan.getAddressPlans().get(0), is("plan1"));
-        assertThat(addressSpacePlan.getResources().size(), is(2));
-        assertThat(addressSpacePlan.getResources().get(0).getName(), is("router"));
-        assertThat(addressSpacePlan.getResources().get(1).getName(), is("broker"));
+        assertThat(addressSpacePlan.getResourceLimits().size(), is(2));
+        assertThat(addressSpacePlan.getResourceLimits().get("router"), is(1.0));
+        assertThat(addressSpacePlan.getResourceLimits().get("broker"), is(0.5));
         assertThat(addressSpacePlan.getMetadata().getAnnotations().size(), is(1));
         assertThat(addressSpacePlan.getAnnotation("mykey"), is("myvalue"));
     }
@@ -394,9 +386,9 @@ public class SerializationTest {
         assertThat(addressSpacePlan.getMetadata().getName(), is("myspace"));
         assertThat(addressSpacePlan.getAddressPlans().size(), is(1));
         assertThat(addressSpacePlan.getAddressPlans().get(0), is("plan1"));
-        assertThat(addressSpacePlan.getResources().size(), is(2));
-        assertThat(addressSpacePlan.getResources().get(0).getName(), is("router"));
-        assertThat(addressSpacePlan.getResources().get(1).getName(), is("broker"));
+        assertThat(addressSpacePlan.getResourceLimits().size(), is(2));
+        assertThat(addressSpacePlan.getResourceLimits().get("router"), is(1.0));
+        assertThat(addressSpacePlan.getResourceLimits().get("broker"), is(0.5));
     }
 
     @Test
@@ -442,6 +434,59 @@ public class SerializationTest {
         assertEquals("desc", plan.getShortDescription());
     }
 
+    @Test
+    void testAddressSpacePlanBuilder() throws IOException {
+        AddressSpacePlan plan = new AddressSpacePlanBuilder()
+                .withNewMetadata()
+                .withName("test-plan")
+                .withAnnotations(Collections.singletonMap("test-key", "test-value"))
+                .endMetadata()
+                .withNewSpec()
+                .withAddressSpaceType("standard")
+                .withAddressPlans("a", "b", "c")
+                .withResourceLimits(Map.of("router", 1.0))
+                .withShortDescription("myplan")
+                .endSpec()
+                .build();
+        assertEquals(3, plan.getAddressPlans().size());
+        assertEquals("test-plan", plan.getMetadata().getName());
+        ObjectMapper mapper = new ObjectMapper();
+        String serialized = mapper.writeValueAsString(plan);
+        String expected = "{\"apiVersion\":\"admin.enmasse.io/v1beta2\",\"kind\":\"AddressSpacePlan\",\"metadata\":{\"annotations\":{\"test-key\":\"test-value\"},\"labels\":{},\"name\":\"test-plan\"},\"spec\":{\"shortDescription\":\"myplan\",\"addressSpaceType\":\"standard\",\"addressPlans\":[\"a\",\"b\",\"c\"],\"resourceLimits\":{\"router\":1.0}}}";
+        assertEquals(expected, serialized);
+        System.out.println(serialized);
+        AddressSpacePlan deserialized = mapper.readValue(serialized, AddressSpacePlan.class);
+        assertEquals(plan, deserialized);
+    }
+
+    @Test
+    void testAddressPlanBuilder() throws IOException {
+        LinkedHashMap<String, Double> res = new LinkedHashMap<>();
+        res.put("router", 2.0);
+        res.put("broker", 14.0);
+        AddressPlan plan = new AddressPlanBuilder()
+                .withNewMetadata()
+                .withName("test-plan")
+                .withAnnotations(Collections.singletonMap("test-key", "test-value"))
+                .endMetadata()
+                .withNewSpec()
+                .withShortDescription("kornys")
+                .withAddressType("topic")
+                .withResources(res)
+                .endSpec()
+                .build();
+        assertEquals("test-plan", plan.getMetadata().getName());
+        assertEquals(14, plan.getSpec().getResources().get("broker"));
+
+        ObjectMapper mapper = new ObjectMapper();
+        String serialized = mapper.writeValueAsString(plan);
+        System.out.println(serialized);
+        String expected = "{\"apiVersion\":\"admin.enmasse.io/v1beta2\",\"kind\":\"AddressPlan\",\"metadata\":{\"annotations\":{\"test-key\":\"test-value\"},\"labels\":{},\"name\":\"test-plan\"},\"spec\":{\"shortDescription\":\"kornys\",\"addressType\":\"topic\",\"resources\":{\"broker\":14.0,\"router\":2.0}}}";
+        assertEquals(expected, serialized);
+        AddressPlan deserialized = mapper.readValue(serialized, AddressPlan.class);
+        assertEquals(plan, deserialized);
+    }
+
     /*
     @Test
     public void testDeserializeResourceDefinitionWithTemplate() throws IOException {