This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git


The following commit(s) were added to refs/heads/master by this push:
     new f4f37fb  fix for logic error in skipping config resolution via rest 
api, and more tests
     new caa78c9  This closes #1207
f4f37fb is described below

commit f4f37fbebd28bf8e007cb443c5a23fd587f2a991
Author: Alex Heneveld <[email protected]>
AuthorDate: Mon Jul 19 09:57:02 2021 +0100

    fix for logic error in skipping config resolution via rest api, and more 
tests
---
 .../resources/AbstractBrooklynRestResource.java    |  2 +-
 .../rest/resources/EntityConfigResourceTest.java   | 76 ++++++++++++++++------
 .../rest/testing/BrooklynRestResourceTest.java     | 14 +++-
 .../rest/testing/mocks/RestMockSimpleEntity.java   |  3 +
 4 files changed, 72 insertions(+), 23 deletions(-)

diff --git 
a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/AbstractBrooklynRestResource.java
 
b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/AbstractBrooklynRestResource.java
index c9e4172..31846d5 100644
--- 
a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/AbstractBrooklynRestResource.java
+++ 
b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/AbstractBrooklynRestResource.java
@@ -183,7 +183,7 @@ public abstract class AbstractBrooklynRestResource {
 
         public Object resolve() {
             Object valueResult =
-                    Boolean.FALSE.equals(skipResolution)
+                    Boolean.TRUE.equals(skipResolution)
                             ? valueToResolve
                             : getImmediateValue(valueToResolve, entity, 
immediately, timeout);
             if (valueResult==UNRESOLVED) valueResult = valueToResolve;
diff --git 
a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/EntityConfigResourceTest.java
 
b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/EntityConfigResourceTest.java
index 49b3651..16dc385 100644
--- 
a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/EntityConfigResourceTest.java
+++ 
b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/EntityConfigResourceTest.java
@@ -18,23 +18,22 @@
  */
 package org.apache.brooklyn.rest.resources;
 
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertNull;
-import static org.testng.Assert.assertTrue;
-
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
 import java.net.URI;
 import java.util.List;
 import java.util.Map;
-
+import java.util.function.Function;
 import javax.annotation.Nullable;
+import javax.ws.rs.core.GenericType;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
+import org.apache.brooklyn.api.entity.Application;
+import 
org.apache.brooklyn.camp.brooklyn.spi.dsl.methods.BrooklynDslCommon.DslFormatString;
+import org.apache.brooklyn.config.ConfigKey;
 import org.apache.brooklyn.core.entity.EntityInternal;
 import org.apache.brooklyn.core.entity.EntityPredicates;
 import org.apache.brooklyn.rest.domain.ApplicationSpec;
@@ -43,13 +42,16 @@ import org.apache.brooklyn.rest.domain.EntitySpec;
 import org.apache.brooklyn.rest.testing.BrooklynRestResourceTest;
 import org.apache.brooklyn.rest.testing.mocks.RestMockSimpleEntity;
 import org.apache.brooklyn.util.collections.MutableMap;
-
-import com.google.common.base.Optional;
-import com.google.common.base.Predicate;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
-import javax.ws.rs.core.GenericType;
+import org.apache.brooklyn.util.text.StringEscapes.JavaStringEscapes;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.Assert;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
 
 @Test(singleThreaded = true,
         // by using a different suite name we disallow interleaving other 
tests between the methods of this test class, which wrecks the test fixtures
@@ -57,6 +59,9 @@ import javax.ws.rs.core.GenericType;
 public class EntityConfigResourceTest extends BrooklynRestResourceTest {
     
     private final static Logger log = 
LoggerFactory.getLogger(EntityConfigResourceTest.class);
+
+    final static String HELLO_WORLD_DSL = "$brooklyn:formatString(\"%s-%s\", 
\"hello\", \"world\")";
+
     private URI applicationUri;
     private EntityInternal entity;
 
@@ -74,9 +79,12 @@ public class EntityConfigResourceTest extends 
BrooklynRestResourceTest {
         assertTrue(status >= 200 && status <= 299, "expected HTTP Response of 
2xx but got " + status);
         applicationUri = response.getLocation();
         log.debug("Built app: application");
-        waitForApplicationToBeRunning(applicationUri);
+        Application app = waitForApplicationToBeRunning(applicationUri);
         
         entity = (EntityInternal) 
Iterables.find(getManagementContext().getEntityManager().getEntities(), 
EntityPredicates.displayNameEqualTo("simple-ent"));
+        Assert.assertEquals( Iterables.getOnlyElement(app.getChildren()), 
entity );
+
+        entity.config().set( (ConfigKey) RestMockSimpleEntity.SECRET_CONFIG, 
new DslFormatString("%s-%s", "hello", "world") );
     }
 
     @Test
@@ -133,6 +141,36 @@ public class EntityConfigResourceTest extends 
BrooklynRestResourceTest {
     }
 
     @Test
+    public void testGetJsonWithParameters() throws Exception {
+        Function<String,String> getSecretWithQueryParams = qp ->
+                client().path(
+                        
URI.create("/applications/simple-app/entities/simple-ent/config/"+RestMockSimpleEntity.SECRET_CONFIG.getName()))
+                        .replaceQuery(qp)
+                        .accept(MediaType.APPLICATION_JSON_TYPE)
+                        .get(String.class);
+
+        assertEquals(getSecretWithQueryParams.apply(""), 
JavaStringEscapes.wrapJavaString("hello-world"));
+        assertEquals(getSecretWithQueryParams.apply("suppressSecrets=true"), 
JavaStringEscapes.wrapJavaString("<suppressed> (MD5 hash: 
2095312189753DE6AD47DFE20CBE97EC)"));
+        assertEquals(getSecretWithQueryParams.apply("skipResolution=true"), 
JavaStringEscapes.wrapJavaString(HELLO_WORLD_DSL));
+        
assertEquals(getSecretWithQueryParams.apply("suppressSecrets=true&skipResolution=true"),
 JavaStringEscapes.wrapJavaString(HELLO_WORLD_DSL));
+    }
+
+    @Test
+    public void testGetPlainWithParameters() throws Exception {
+        Function<String,String> getSecretWithQueryParams = qp ->
+                client().path(
+                    
URI.create("/applications/simple-app/entities/simple-ent/config/"+RestMockSimpleEntity.SECRET_CONFIG.getName()))
+                    .replaceQuery(qp)
+                    .accept(MediaType.TEXT_PLAIN_TYPE)
+                    .get(String.class);
+
+        assertEquals(getSecretWithQueryParams.apply(""), "hello-world");
+        assertEquals(getSecretWithQueryParams.apply("suppressSecrets=true"), 
"<suppressed> (MD5 hash: 2095312189753DE6AD47DFE20CBE97EC)");
+        assertEquals(getSecretWithQueryParams.apply("skipResolution=true"), 
HELLO_WORLD_DSL);
+        
assertEquals(getSecretWithQueryParams.apply("suppressSecrets=true&skipResolution=true"),
 HELLO_WORLD_DSL);
+    }
+
+    @Test
     public void testSet() throws Exception {
         try {
             String uri = 
"/applications/simple-app/entities/simple-ent/config/"+
diff --git 
a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/testing/BrooklynRestResourceTest.java
 
b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/testing/BrooklynRestResourceTest.java
index 576a535..b27debb 100644
--- 
a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/testing/BrooklynRestResourceTest.java
+++ 
b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/testing/BrooklynRestResourceTest.java
@@ -18,6 +18,10 @@
  */
 package org.apache.brooklyn.rest.testing;
 
+import com.google.common.collect.Iterables;
+import java.util.stream.Collectors;
+import org.apache.brooklyn.core.entity.Attributes;
+import org.apache.brooklyn.core.entity.EntityAsserts;
 import static org.testng.Assert.assertTrue;
 
 import java.io.IOException;
@@ -143,10 +147,10 @@ public abstract class BrooklynRestResourceTest extends 
BrooklynRestApiTest {
         }
     }
     
-    protected void waitForApplicationToBeRunning(final URI applicationRef) {
-        waitForApplicationToBeRunning(applicationRef, Duration.minutes(3));
+    protected Application waitForApplicationToBeRunning(final URI 
applicationRef) {
+        return waitForApplicationToBeRunning(applicationRef, 
Duration.minutes(3));
     }
-    protected void waitForApplicationToBeRunning(final URI applicationRef, 
Duration timeout) {
+    protected Application waitForApplicationToBeRunning(final URI 
applicationRef, Duration timeout) {
         if (applicationRef==null)
             throw new NullPointerException("No application URI available 
(consider using BrooklynRestResourceTest.clientDeploy)");
         
@@ -172,6 +176,10 @@ public abstract class BrooklynRestResourceTest extends 
BrooklynRestApiTest {
                 Entities.dumpInfo(app);
         }
         assertTrue(started);
+
+        Application app = 
Iterables.getOnlyElement(getManagementContext().getApplications().stream().filter(appI
 -> 
applicationRef.toString().contains(appI.getId())).collect(Collectors.toList()));
+        EntityAsserts.assertAttributeEquals(app, Attributes.SERVICE_UP, true);
+        return app;
     }
 
     protected Status getApplicationStatus(URI uri) {
diff --git 
a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/testing/mocks/RestMockSimpleEntity.java
 
b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/testing/mocks/RestMockSimpleEntity.java
index f1977a9..130dcd4 100644
--- 
a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/testing/mocks/RestMockSimpleEntity.java
+++ 
b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/testing/mocks/RestMockSimpleEntity.java
@@ -46,6 +46,9 @@ public class RestMockSimpleEntity extends SoftwareProcessImpl 
{
     public static final ConfigKey<String> SAMPLE_CONFIG = new 
BasicConfigKey<String>(
             String.class, "brooklyn.rest.mock.sample.config", "Mock sample 
config", "DEFAULT_VALUE");
 
+    public static final ConfigKey<String> SECRET_CONFIG = new 
BasicConfigKey<String>(
+            String.class, "brooklyn.rest.mock.secret.config");
+
     public static final AttributeSensor<String> SAMPLE_SENSOR = new 
BasicAttributeSensor<String>(
             String.class, "brooklyn.rest.mock.sample.sensor", "Mock sample 
sensor");
 

Reply via email to