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 0bab702  make logbook test install log from classpath to temp file
0bab702 is described below

commit 0bab702be46e8fae3617b97f3d61e825ee7a204e
Author: Alex Heneveld <[email protected]>
AuthorDate: Fri Jul 16 22:42:01 2021 +0100

    make logbook test install log from classpath to temp file
    
    otherwise tests will fail when run from a jar or with different CWD
    (test previously assumed file was on the filesystem and test is running in 
project root)
    
    also rename the sample log file so it doesn't get blown away by a `find . 
-name \*.log`
---
 .../rest/resources/LogbookResourceTest.java        | 35 ++++++++++++++++++++--
 .../{logbook.test.log => logbook.log.sample}       |  0
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git 
a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/LogbookResourceTest.java
 
b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/LogbookResourceTest.java
index 8a59e63..0261c29 100644
--- 
a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/LogbookResourceTest.java
+++ 
b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/LogbookResourceTest.java
@@ -20,10 +20,17 @@ package org.apache.brooklyn.rest.resources;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
+import java.io.File;
+import java.io.FileWriter;
+import java.nio.file.Files;
 import org.apache.brooklyn.core.internal.BrooklynProperties;
 import org.apache.brooklyn.rest.api.LogbookApi;
 import org.apache.brooklyn.rest.testing.BrooklynRestResourceTest;
+import org.apache.brooklyn.util.core.ResourceUtils;
 import org.apache.brooklyn.util.core.logbook.BrooklynLogEntry;
+import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.apache.brooklyn.util.os.Os;
+import org.apache.brooklyn.util.stream.Streams;
 import org.apache.http.HttpStatus;
 import org.testng.annotations.*;
 
@@ -42,10 +49,34 @@ import static org.testng.Assert.assertEquals;
 @Test(singleThreaded = true, suiteName = "LogbookResourceTest")
 public class LogbookResourceTest extends BrooklynRestResourceTest {
 
+    static class LogbookResourceTestHelper {
+        private static File LOG_TEMP_FILE;
+
+        public synchronized static File installSampleLog() {
+            if (LOG_TEMP_FILE == null) {
+                // copy from classpath so tests don't make assumptions about 
file system, e.g. if running from jar
+                LOG_TEMP_FILE = Os.newTempFile(LogbookResourceTest.class, 
"log");
+                try {
+                    FileWriter fw = new FileWriter(LOG_TEMP_FILE);
+                    
fw.write(ResourceUtils.create(LogbookResourceTest.class).getResourceAsString("classpath:/logbook.log.sample"));
+                    fw.close();
+                } catch (IOException e) {
+                    throw Exceptions.propagate(e);
+                }
+            }
+            return LOG_TEMP_FILE;
+        }
+
+        public static void installSampleLog(BrooklynProperties 
brooklynProperties) {
+            installSampleLog();
+            brooklynProperties.put("brooklyn.logbook.fileLogStore.path", 
LOG_TEMP_FILE.getAbsolutePath());
+        }
+    }
+
     @Override
     protected BrooklynProperties getBrooklynProperties() {
         BrooklynProperties brooklynProperties = 
BrooklynProperties.Factory.newEmpty();
-        brooklynProperties.put("brooklyn.logbook.fileLogStore.path", 
"src/test/resources/logbook.test.log");
+        LogbookResourceTestHelper.installSampleLog(brooklynProperties);
         return brooklynProperties;
     }
 
@@ -116,7 +147,7 @@ public class LogbookResourceTest extends 
BrooklynRestResourceTest {
         protected BrooklynProperties getBrooklynProperties() {
             BrooklynProperties brooklynProperties = 
BrooklynProperties.Factory.newEmpty();
             brooklynProperties.put("brooklyn.entitlements.global", 
this.getBrooklynEntitlementsGlobal());
-            brooklynProperties.put("brooklyn.logbook.fileLogStore.path", 
"src/test/resources/logbook.test.log");
+            LogbookResourceTestHelper.installSampleLog(brooklynProperties);
             return brooklynProperties;
         }
 
diff --git a/rest/rest-resources/src/test/resources/logbook.test.log 
b/rest/rest-resources/src/test/resources/logbook.log.sample
similarity index 100%
rename from rest/rest-resources/src/test/resources/logbook.test.log
rename to rest/rest-resources/src/test/resources/logbook.log.sample

Reply via email to