sergehuber commented on a change in pull request #337:
URL: https://github.com/apache/unomi/pull/337#discussion_r708152040



##########
File path: 
itests/src/test/java/org/apache/unomi/itests/GroovyActionsServiceIT.java
##########
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.unomi.itests;
+
+import org.apache.unomi.api.actions.ActionType;
+import org.apache.unomi.api.services.DefinitionsService;
+import org.apache.unomi.groovy.actions.GroovyAction;
+import org.apache.unomi.groovy.actions.services.GroovyActionsService;
+import org.apache.unomi.groovy.actions.utils.Utils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerSuite;
+import org.ops4j.pax.exam.util.Filter;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerSuite.class)
+public class GroovyActionsServiceIT extends BaseIT {
+
+    @Inject
+    @Filter(timeout = 600000)
+    protected GroovyActionsService groovyActionsService;
+
+    @Inject
+    @Filter(timeout = 600000)
+    protected DefinitionsService definitionsService;
+
+    @Before
+    public void setUp() throws InterruptedException {
+        refreshPersistence();
+    }
+
+    @After
+    public void cleanUp() throws InterruptedException {
+        refreshPersistence();
+    }
+
+    private String loadGroovyAction(String pathname) throws IOException {
+        return Utils.convertInputStreamToString(new FileInputStream(new 
File(pathname)));

Review comment:
       Please replace with IOUtils.toString(InputStream)

##########
File path: 
extensions/groovy-actions/services/src/main/java/org/apache/unomi/groovy/actions/GroovyAction.java
##########
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.unomi.groovy.actions;
+
+import org.apache.unomi.api.Metadata;
+import org.apache.unomi.api.MetadataItem;
+
+/**
+ * Object which represents a Groovy action

Review comment:
       ```suggestion
    * Object which represents a Groovy action (including its script)
   ```
   ```suggestion
    * Object which represents a Groovy action
   ```

##########
File path: 
extensions/groovy-actions/services/src/main/java/org/apache/unomi/groovy/actions/utils/Utils.java
##########
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.unomi.groovy.actions.utils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.nio.charset.StandardCharsets;
+
+/**
+ * Utility class
+ */
+public class Utils {
+
+    public static String convertInputStreamToString(InputStream inputStream) 
throws IOException {

Review comment:
       Please do not use your own implementation, there are a LOT of available 
ones, especially in the Commons IO library.

##########
File path: extensions/groovy-actions/karaf-kar/pom.xml
##########
@@ -61,7 +69,11 @@
             <artifactId>jsoup</artifactId>
             <version>1.13.1</version>
         </dependency>
-
+        <dependency>
+            <groupId>com.sun.activation</groupId>

Review comment:
       Ok thank you I wonder what pull that dependency.

##########
File path: 
itests/src/test/java/org/apache/unomi/itests/GroovyActionsServiceIT.java
##########
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.unomi.itests;
+
+import org.apache.unomi.api.actions.ActionType;
+import org.apache.unomi.api.services.DefinitionsService;
+import org.apache.unomi.groovy.actions.GroovyAction;
+import org.apache.unomi.groovy.actions.services.GroovyActionsService;
+import org.apache.unomi.groovy.actions.utils.Utils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerSuite;
+import org.ops4j.pax.exam.util.Filter;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerSuite.class)
+public class GroovyActionsServiceIT extends BaseIT {
+
+    @Inject
+    @Filter(timeout = 600000)
+    protected GroovyActionsService groovyActionsService;
+
+    @Inject
+    @Filter(timeout = 600000)
+    protected DefinitionsService definitionsService;
+
+    @Before
+    public void setUp() throws InterruptedException {
+        refreshPersistence();
+    }
+
+    @After
+    public void cleanUp() throws InterruptedException {
+        refreshPersistence();
+    }
+
+    private String loadGroovyAction(String pathname) throws IOException {
+        return Utils.convertInputStreamToString(new FileInputStream(new 
File(pathname)));
+    }
+
+    @Test
+    public void testGroovyActionsService_saveActionAndTestSavedValues() throws 
IOException, InterruptedException {
+        
groovyActionsService.save(loadGroovyAction("data/tmp/groovy/script.groovy"));
+
+        Thread.sleep(2000);
+
+        GroovyAction groovyAction = 
groovyActionsService.getGroovyAction("MyAction");
+
+        ActionType actionType = 
definitionsService.getActionType("scriptGroovyAction");
+
+        Assert.assertEquals("MyAction", groovyAction.getItemId());
+        Assert.assertEquals("MyAction", groovyAction.getName());
+        Assert.assertTrue(groovyAction.getScript().contains("A test Groovy"));
+
+        
Assert.assertTrue(actionType.getMetadata().getId().contains("scriptGroovyAction"));
+        Assert.assertEquals(2, 
actionType.getMetadata().getSystemTags().size());
+        
Assert.assertTrue(actionType.getMetadata().getSystemTags().contains("tag1"));
+        Assert.assertEquals(2, actionType.getParameters().size());
+        Assert.assertEquals("param1", 
actionType.getParameters().get(0).getId());
+
+        Assert.assertEquals("groovy:MyAction", actionType.getActionExecutor());
+        Assert.assertFalse(actionType.getMetadata().isHidden());
+    }
+
+    @Test
+    public void testGroovyActionsService_removeGroovyAction() throws 
IOException, InterruptedException {
+        
groovyActionsService.save(loadGroovyAction("data/tmp/groovy/script.groovy"));
+
+        Thread.sleep(2000);
+
+        GroovyAction groovyAction = 
groovyActionsService.getGroovyAction("MyAction");
+
+        Assert.assertNotNull(groovyAction);
+
+        groovyActionsService.remove("MyAction");
+
+        Thread.sleep(2000);
+
+        groovyAction = 
groovyActionsService.getGroovyAction("scriptGroovyAction");
+
+        Assert.assertNull(groovyAction);

Review comment:
       Shouldn't we also remove the action from the definition service ? 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to