Github user bostko commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/558#discussion_r100781917
--- Diff:
camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java
---
@@ -750,6 +754,175 @@ public void testPortSetAsAttributeOnSoftwareProcess()
throws Exception {
assertEquals(entity.sensors().get(Sensors.newSensor(Object.class,
"my.param.key")), 1234);
}
+ @Test
+ public void testConfigParameterConstraintRequired() throws Exception {
+ addCatalogItems(
+ "brooklyn.catalog:",
+ " itemType: entity",
+ " items:",
+ " - id: entity-with-keys",
+ " item:",
+ " type: "+TestEntity.class.getName(),
+ " brooklyn.parameters:",
+ " - name: testRequired",
+ " type: String",
+ " constraints:",
+ " - required");
+
+ String yamlNoVal = Joiner.on("\n").join(
+ "services:",
+ "- type: entity-with-keys");
+
+ String yamlWithVal = Joiner.on("\n").join(
+ "services:",
+ "- type: entity-with-keys",
+ " brooklyn.config:",
+ " testRequired: myval");
+
+ try {
+ createStartWaitAndLogApplication(yamlNoVal);
+ Asserts.shouldHaveFailedPreviously();
+ } catch (ConstraintViolationException e) {
+ // success
+ }
+
+ Entity app = createStartWaitAndLogApplication(yamlWithVal);
+ TestEntity entity = (TestEntity)
Iterables.getOnlyElement(app.getChildren());
+ assertKeyEquals(entity, "testRequired", null, String.class, null,
"myval");
+
+ // Rebind, and then check again that the config key is listed
+ Entity newApp = rebind();
+ TestEntity newEntity = (TestEntity)
Iterables.getOnlyElement(newApp.getChildren());
+ assertKeyEquals(newEntity, "testRequired", null, String.class,
null, "myval");
+ }
+
+ @Test
+ public void testConfigParameterConstraintRegex() throws Exception {
+ addCatalogItems(
+ "brooklyn.catalog:",
+ " itemType: entity",
+ " items:",
+ " - id: entity-with-keys",
+ " item:",
+ " type: "+TestEntity.class.getName(),
+ " brooklyn.parameters:",
+ " - name: testRequired",
+ " type: String",
+ " constraints:",
+ " - regex: myprefix.*");
+
+ String yamlNoVal = Joiner.on("\n").join(
+ "services:",
+ "- type: entity-with-keys");
+
+ String yamlWrongVal = Joiner.on("\n").join(
+ "services:",
+ "- type: entity-with-keys",
+ " brooklyn.config:",
+ " testRequired: wrongval");
+
+ String yamlWithVal = Joiner.on("\n").join(
+ "services:",
+ "- type: entity-with-keys",
+ " brooklyn.config:",
+ " testRequired: myprefix-myVal");
+
+ try {
+ createStartWaitAndLogApplication(yamlNoVal);
+ Asserts.shouldHaveFailedPreviously();
+ } catch (ConstraintViolationException e) {
+ // success
+ }
+
+ try {
+ createStartWaitAndLogApplication(yamlWrongVal);
+ Asserts.shouldHaveFailedPreviously();
+ } catch (ConstraintViolationException e) {
+ // success
+ }
+
+ Entity app = createStartWaitAndLogApplication(yamlWithVal);
+ TestEntity entity = (TestEntity)
Iterables.getOnlyElement(app.getChildren());
+ assertKeyEquals(entity, "testRequired", null, String.class, null,
"myprefix-myVal");
+
+ // Rebind, and then check again that the config key is listed
+ Entity newApp = rebind();
+ TestEntity newEntity = (TestEntity)
Iterables.getOnlyElement(newApp.getChildren());
+ assertKeyEquals(newEntity, "testRequired", null, String.class,
null, "myprefix-myVal");
+ }
+
+ @Test
+ public void testConfigParameterConstraintObject() throws Exception {
+ addCatalogItems(
+ "brooklyn.catalog:",
+ " itemType: entity",
+ " items:",
+ " - id: entity-with-keys",
+ " item:",
+ " type: "+TestEntity.class.getName(),
+ " brooklyn.parameters:",
+ " - name: testRequired",
+ " type: String",
+ " constraints:",
+ " - $brooklyn:object:",
+ " type: " + PredicateRegexPojo.class.getName(),
+ " object.fields:",
+ " regex: myprefix.*");
+
+
+ String yamlNoVal = Joiner.on("\n").join(
+ "services:",
+ "- type: entity-with-keys");
+
+ String yamlWrongVal = Joiner.on("\n").join(
+ "services:",
+ "- type: entity-with-keys",
+ " brooklyn.config:",
+ " testRequired: wrongval");
+
+ String yamlWithVal = Joiner.on("\n").join(
+ "services:",
+ "- type: entity-with-keys",
+ " brooklyn.config:",
+ " testRequired: myprefix-myVal");
+
+ try {
+ createStartWaitAndLogApplication(yamlNoVal);
+ Asserts.shouldHaveFailedPreviously();
+ } catch (ConstraintViolationException e) {
+ // success
--- End diff --
What about putting a message assertion?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---