[GitHub] [openmeetings] sebawagner commented on a change in pull request #68: OPENMEETINGS-2299 Add unit test for recording when sharing wasn't ena…

2020-04-25 Thread GitBox


sebawagner commented on a change in pull request #68:
URL: https://github.com/apache/openmeetings/pull/68#discussion_r415220521



##
File path: 
openmeetings-core/src/test/java/org/apache/openmeetings/core/remote/TestRecordingFlowMocked.java
##
@@ -0,0 +1,222 @@
+/*
+
+ * 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.openmeetings.core.remote;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.Locale;
+import java.util.logging.StreamHandler;
+
+import org.apache.openmeetings.db.dao.label.LabelDao;
+import org.apache.openmeetings.db.dao.record.RecordingDao;
+import org.apache.openmeetings.db.dao.room.RoomDao;
+import org.apache.openmeetings.db.dao.user.UserDao;
+import org.apache.openmeetings.db.entity.basic.Client;
+import org.apache.openmeetings.db.entity.basic.Client.Activity;
+import org.apache.openmeetings.db.entity.basic.Client.StreamDesc;
+import org.apache.openmeetings.db.entity.label.OmLanguage;
+import org.apache.openmeetings.db.entity.record.Recording;
+import org.apache.openmeetings.db.entity.room.Room;
+import org.apache.openmeetings.db.entity.user.User;
+import org.apache.openmeetings.db.manager.IClientManager;
+import org.junit.Test;
+import org.kurento.client.MediaPipeline;
+import org.kurento.client.Transaction;
+import org.mockito.BDDMockito;
+import org.mockito.Mock;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+
+import com.github.openjson.JSONObject;
+
+@PrepareForTest(LabelDao.class)
+public class TestRecordingFlowMocked extends BaseMockedTest {
+   private static final Long USER_ID = 1L;
+   private static final Long ROOM_ID = 5L;
+   @Mock
+   private UserDao userDao;
+   @Mock
+   private RoomDao roomDao;
+   @Mock
+   private RecordingDao recDao;
+   @Mock
+   private IClientManager cm;
+   
+   //This variable holds a reference to the current client in the room
+   private Client c;
+   
+   //This variable hold a reference to the UID of the StreamDesc that will 
be created 
+   private String streamDescUID;
+
+   @Override
+   public void setup() {
+   super.setup();
+   
when(client.createMediaPipeline(any(Transaction.class))).thenReturn(mock(MediaPipeline.class));
+   User u = new User();
+   u.setId(USER_ID);
+   u.setFirstname("firstname");
+   u.setLastname("lastname");
+   when(userDao.get(USER_ID)).thenReturn(u);
+   doReturn(true).when(handler).isConnected();
+   when(recDao.update(any(Recording.class))).thenAnswer(new 
Answer() {

Review comment:
   nice





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [openmeetings] sebawagner commented on a change in pull request #68: OPENMEETINGS-2299 Add unit test for recording when sharing wasn't ena…

2020-04-25 Thread GitBox


sebawagner commented on a change in pull request #68:
URL: https://github.com/apache/openmeetings/pull/68#discussion_r415211032



##
File path: 
openmeetings-core/src/test/java/org/apache/openmeetings/core/remote/TestRecordingFlowMocked.java
##
@@ -0,0 +1,222 @@
+/*
+
+ * 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.openmeetings.core.remote;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.Locale;
+import java.util.logging.StreamHandler;
+
+import org.apache.openmeetings.db.dao.label.LabelDao;
+import org.apache.openmeetings.db.dao.record.RecordingDao;
+import org.apache.openmeetings.db.dao.room.RoomDao;
+import org.apache.openmeetings.db.dao.user.UserDao;
+import org.apache.openmeetings.db.entity.basic.Client;
+import org.apache.openmeetings.db.entity.basic.Client.Activity;
+import org.apache.openmeetings.db.entity.basic.Client.StreamDesc;
+import org.apache.openmeetings.db.entity.label.OmLanguage;
+import org.apache.openmeetings.db.entity.record.Recording;
+import org.apache.openmeetings.db.entity.room.Room;
+import org.apache.openmeetings.db.entity.user.User;
+import org.apache.openmeetings.db.manager.IClientManager;
+import org.junit.Test;
+import org.kurento.client.MediaPipeline;
+import org.kurento.client.Transaction;
+import org.mockito.BDDMockito;
+import org.mockito.Mock;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+
+import com.github.openjson.JSONObject;
+
+@PrepareForTest(LabelDao.class)
+public class TestRecordingFlowMocked extends BaseMockedTest {
+   private static final Long USER_ID = 1L;
+   private static final Long ROOM_ID = 5L;
+   @Mock
+   private UserDao userDao;
+   @Mock
+   private RoomDao roomDao;
+   @Mock
+   private RecordingDao recDao;
+   @Mock
+   private IClientManager cm;
+   
+   //This variable holds a reference to the current client in the room
+   private Client c;
+   
+   //This variable hold a reference to the UID of the StreamDesc that will 
be created 
+   private String streamDescUID;
+
+   @Override
+   public void setup() {
+   super.setup();
+   
when(client.createMediaPipeline(any(Transaction.class))).thenReturn(mock(MediaPipeline.class));
+   User u = new User();
+   u.setId(USER_ID);
+   u.setFirstname("firstname");
+   u.setLastname("lastname");
+   when(userDao.get(USER_ID)).thenReturn(u);
+   doReturn(true).when(handler).isConnected();
+   when(recDao.update(any(Recording.class))).thenAnswer(new 
Answer() {
+   @Override
+   public Recording answer(InvocationOnMock invocation) 
throws Throwable {
+   Object[] args = invocation.getArguments();
+   Recording r = (Recording) args[0];
+   r.setId(1L);
+   return r;
+   }
+   });
+   
+   PowerMockito.mockStatic(LabelDao.class);

Review comment:
   I think I did that in my last commit. Let me check





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [openmeetings] sebawagner commented on a change in pull request #68: OPENMEETINGS-2299 Add unit test for recording when sharing wasn't ena…

2020-04-25 Thread GitBox


sebawagner commented on a change in pull request #68:
URL: https://github.com/apache/openmeetings/pull/68#discussion_r415210442



##
File path: 
openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/StreamProcessor.java
##
@@ -442,9 +446,10 @@ public void stopRecording(Client c) {
});
}
 
-   void startConvertion(Recording rec) {
+   public boolean startConvertion(Recording rec) {
IRecordingConverter conv = rec.isInterview() ? 
interviewConverter : recordingConverter;
taskExecutor.execute(() -> conv.startConversion(rec));
+   return true;

Review comment:
   You can't mock it otherwise. Mockito won't let you mock the method if 
its returning void. But we need to mock this method, the problem is the method 
is in a @InjectedMock class. So you need to use the alternative syntax for Spy. 
but can only do that if method returns a value.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [openmeetings] sebawagner commented on a change in pull request #68: OPENMEETINGS-2299 Add unit test for recording when sharing wasn't ena…

2020-04-25 Thread GitBox


sebawagner commented on a change in pull request #68:
URL: https://github.com/apache/openmeetings/pull/68#discussion_r415210242



##
File path: 
openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/StreamProcessor.java
##
@@ -442,9 +446,10 @@ public void stopRecording(Client c) {
});
}
 
-   void startConvertion(Recording rec) {
+   public boolean startConvertion(Recording rec) {

Review comment:
   Right, I think package private should also work. Let me check





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [openmeetings] sebawagner commented on a change in pull request #68: OPENMEETINGS-2299 Add unit test for recording when sharing wasn't ena…

2020-04-25 Thread GitBox


sebawagner commented on a change in pull request #68:
URL: https://github.com/apache/openmeetings/pull/68#discussion_r415204548



##
File path: 
openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/StreamProcessor.java
##
@@ -345,7 +349,7 @@ private void startSharing(Client c, Optional 
osd, JSONObject msg, Ac
}
}
 
-   private void pauseSharing(Client c, String uid) {
+   void pauseSharing(Client c, String uid) {

Review comment:
   Needed package private access for verify via Mockito if the method has 
been called.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [openmeetings] sebawagner commented on a change in pull request #68: OPENMEETINGS-2299 Add unit test for recording when sharing wasn't ena…

2020-04-25 Thread GitBox


sebawagner commented on a change in pull request #68:
URL: https://github.com/apache/openmeetings/pull/68#discussion_r415204479



##
File path: 
openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/StreamProcessor.java
##
@@ -442,9 +446,10 @@ public void stopRecording(Client c) {
});
}
 
-   void startConvertion(Recording rec) {
+   public boolean startConvertion(Recording rec) {

Review comment:
   Needs a return value in order to have a Mockity.Spy annotation mock + 
verify the mock has been called.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [openmeetings] sebawagner commented on a change in pull request #68: OPENMEETINGS-2299 Add unit test for recording when sharing wasn't ena…

2020-04-25 Thread GitBox


sebawagner commented on a change in pull request #68:
URL: https://github.com/apache/openmeetings/pull/68#discussion_r415160620



##
File path: 
openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/StreamProcessor.java
##
@@ -188,6 +188,10 @@ private void handleBroadcastStarted(Client c, final String 
uid, JSONObject msg)
log.error("Failed to start broadcast", e);
}
}
+   
+   public KStream startBroadcast(KStream stream, StreamDesc sd, String 
sdpOffer) {

Review comment:
   Unfortunate I had to modify the main code to write a unit test. But that 
seemed the only way how I can prevent calling the webRTC methods in KStream. 
Cause otherwise mocking those is almost impossible.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [openmeetings] sebawagner commented on a change in pull request #68: OPENMEETINGS-2299 Add unit test for recording when sharing wasn't ena…

2020-04-25 Thread GitBox


sebawagner commented on a change in pull request #68:
URL: https://github.com/apache/openmeetings/pull/68#discussion_r415160556



##
File path: 
openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/StreamProcessor.java
##
@@ -188,6 +188,10 @@ private void handleBroadcastStarted(Client c, final String 
uid, JSONObject msg)
log.error("Failed to start broadcast", e);
}
}
+   

Review comment:
   Unfortunate I had to modify the main code to write a unit test. But that 
seemed the only way how I can prevent calling the webRTC methods in KStream. 
Cause otherwise mocking those is almost impossible.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [openmeetings] sebawagner commented on a change in pull request #68: OPENMEETINGS-2299 Add unit test for recording when sharing wasn't ena…

2020-04-25 Thread GitBox


sebawagner commented on a change in pull request #68:
URL: https://github.com/apache/openmeetings/pull/68#discussion_r415160556



##
File path: 
openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/StreamProcessor.java
##
@@ -188,6 +188,10 @@ private void handleBroadcastStarted(Client c, final String 
uid, JSONObject msg)
log.error("Failed to start broadcast", e);
}
}
+   

Review comment:
   Unfortunate I had to modify the main code to write a unit test. But that 
seemed the only way how I can prevent calling the webRTC methods in KStream. 
Cause otherwise mocking those is almost impossible.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org