You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openmeetings.apache.org by so...@apache.org on 2019/02/02 14:45:58 UTC
[openmeetings] branch master updated: [OPENMEETINGS-1856] more
tests are added
This is an automated email from the ASF dual-hosted git repository.
solomax pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openmeetings.git
The following commit(s) were added to refs/heads/master by this push:
new 73ca751 [OPENMEETINGS-1856] more tests are added
73ca751 is described below
commit 73ca75123b54656f70732a65e724ff26588c3f1e
Author: Maxim Solodovnik <so...@gmail.com>
AuthorDate: Sat Feb 2 21:45:43 2019 +0700
[OPENMEETINGS-1856] more tests are added
---
.../openmeetings/core/remote/KurentoHandler.java | 4 +-
.../openmeetings/core/remote/BaseMockedTest.java | 66 ++++++++++
.../core/remote/TestNotConnectedMocked.java | 59 +++++++++
.../core/remote/TestRoomFlowMocked.java | 145 +++++++++++++++++++++
...HandlerMocked.java => TestSetupFlowMocked.java} | 54 ++------
5 files changed, 284 insertions(+), 44 deletions(-)
diff --git a/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/KurentoHandler.java b/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/KurentoHandler.java
index c376ee5..c0d751a 100644
--- a/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/KurentoHandler.java
+++ b/openmeetings-core/src/main/java/org/apache/openmeetings/core/remote/KurentoHandler.java
@@ -120,7 +120,7 @@ public class KurentoHandler {
@Autowired
private InterviewConverter interviewConverter;
- private boolean isConnected() {
+ boolean isConnected() {
boolean connctd = client != null && !client.isClosed() && connected;
if (!connctd) {
log.warn(WARN_NO_KURENTO);
@@ -129,9 +129,7 @@ public class KurentoHandler {
}
public void init() {
- log.warn("!!!!!!!!!!!!!!!! Init");
check = () -> {
- log.warn("!!!!!!!!!!!!!!!! CHECK !!!!!!!!!!!!!!!!!!!!");
try {
kuid = randomUUID().toString();
client = KurentoClient.create(kurentoWsUrl, new KConnectionListener(kuid));
diff --git a/openmeetings-core/src/test/java/org/apache/openmeetings/core/remote/BaseMockedTest.java b/openmeetings-core/src/test/java/org/apache/openmeetings/core/remote/BaseMockedTest.java
new file mode 100644
index 0000000..bde9fa7
--- /dev/null
+++ b/openmeetings-core/src/test/java/org/apache/openmeetings/core/remote/BaseMockedTest.java
@@ -0,0 +1,66 @@
+/*
+
+ * 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.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Mockito.when;
+import static org.powermock.api.mockito.PowerMockito.mockStatic;
+
+import org.apache.openmeetings.core.util.WebSocketHelper;
+import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.kurento.client.KurentoClient;
+import org.kurento.client.KurentoConnectionListener;
+import org.kurento.client.ServerManager;
+import org.kurento.client.internal.TransactionImpl;
+import org.kurento.client.internal.client.RomManager;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Spy;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import com.github.openjson.JSONObject;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({KurentoClient.class, WebSocketHelper.class, IKStream.class})
+public class BaseMockedTest {
+ @Mock
+ protected RomManager romManager;
+ @Mock
+ protected ServerManager kServerManager;
+ @Mock
+ protected KurentoClient client;
+ @Spy
+ @InjectMocks
+ protected KurentoHandler handler;
+ protected final static JSONObject MSG_BASE = new JSONObject();
+
+ @Before
+ public void setup() {
+ mockStatic(KurentoClient.class);
+ mockStatic(WebSocketHelper.class);
+ when(client.getServerManager()).thenReturn(kServerManager);
+ when(KurentoClient.create(nullable(String.class), any(KurentoConnectionListener.class))).thenReturn(client);
+ when(client.beginTransaction()).thenReturn(new TransactionImpl(romManager));
+ handler.init();
+ }
+}
diff --git a/openmeetings-core/src/test/java/org/apache/openmeetings/core/remote/TestNotConnectedMocked.java b/openmeetings-core/src/test/java/org/apache/openmeetings/core/remote/TestNotConnectedMocked.java
new file mode 100644
index 0000000..1877518
--- /dev/null
+++ b/openmeetings-core/src/test/java/org/apache/openmeetings/core/remote/TestNotConnectedMocked.java
@@ -0,0 +1,59 @@
+/*
+
+ * 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.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import org.junit.Test;
+
+import com.github.openjson.JSONObject;
+
+public class TestNotConnectedMocked extends BaseMockedTest {
+ @Test
+ public void testNotConnected() {
+ handler.onMessage(null, MSG_BASE);
+ }
+
+ @Test
+ public void testRecordingAllowed() {
+ assertFalse(handler.recordingAllowed(null));
+ }
+
+ @Test
+ public void testStartRecording() {
+ handler.startRecording(null);
+ }
+
+ @Test
+ public void testStopRecording() {
+ handler.stopRecording(null);
+ }
+
+ @Test
+ public void testIsRecording() {
+ assertFalse(handler.isRecording(null));
+ }
+
+ @Test
+ public void testGetRecordingUser() {
+ assertEquals(new JSONObject().toString(), handler.getRecordingUser(null).toString());
+ }
+}
diff --git a/openmeetings-core/src/test/java/org/apache/openmeetings/core/remote/TestRoomFlowMocked.java b/openmeetings-core/src/test/java/org/apache/openmeetings/core/remote/TestRoomFlowMocked.java
new file mode 100644
index 0000000..a95994e
--- /dev/null
+++ b/openmeetings-core/src/test/java/org/apache/openmeetings/core/remote/TestRoomFlowMocked.java
@@ -0,0 +1,145 @@
+/*
+
+ * 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.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.openmeetings.db.dao.record.RecordingDao;
+import org.apache.openmeetings.db.dao.user.UserDao;
+import org.apache.openmeetings.db.entity.basic.Client;
+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.Mock;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+import com.github.openjson.JSONObject;
+
+public class TestRoomFlowMocked extends BaseMockedTest {
+ private static final Long USER_ID = 1L;
+ private static final Long ROOM_ID = 5L;
+ @Mock
+ private UserDao userDao;
+ @Mock
+ private RecordingDao recDao;
+ @Mock
+ private IClientManager cm;
+
+ @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<Recording>() {
+ @Override
+ public Recording answer(InvocationOnMock invocation) throws Throwable {
+ Object[] args = invocation.getArguments();
+ Recording r = (Recording) args[0];
+ r.setId(1L);
+ return r;
+ }
+ });
+ }
+
+ @Test
+ public void testNoClient() {
+ handler.onMessage(null, MSG_BASE.put("id", "aa"));
+ }
+
+ private Client getClient() {
+ return new Client("sessionId", 0, USER_ID, userDao);
+ }
+
+ @Test
+ public void testNoRoom() {
+ handler.onMessage(getClient(), MSG_BASE.put("id", "aa"));
+ }
+
+ @Test
+ public void testRecordingAllowed() {
+ Client c = getClient();
+ assertFalse(handler.recordingAllowed(c));
+ c.setRoom(new Room());
+ assertFalse(handler.recordingAllowed(c));
+ c.getRoom().setId(ROOM_ID);
+ c.getRoom().setAllowRecording(true);
+ assertFalse(handler.recordingAllowed(c));
+ c.allow(Room.Right.moderator);
+ assertTrue(handler.recordingAllowed(c));
+ }
+
+ private Client getClientWithRoom() {
+ Client c = getClient();
+ c.setRoom(new Room());
+ c.getRoom().setId(ROOM_ID);
+ return c;
+ }
+
+ @Test
+ public void testWannaRecord1() throws Exception {
+ JSONObject msg = new JSONObject(MSG_BASE.toString()).put("id", "wannaRecord");
+ handler.onMessage(getClientWithRoom(), msg);
+ }
+
+ private Client getClientFull() {
+ Client c = getClientWithRoom();
+ c.getRoom().setAllowRecording(true);
+ c.allow(Room.Right.moderator);
+ return c;
+ }
+
+ @Test
+ public void testWannaRecord2() throws Exception {
+ JSONObject msg = new JSONObject(MSG_BASE.toString()).put("id", "wannaRecord");
+ Client c = getClientFull();
+ c.getRoom().setType(Room.Type.interview);
+ handler.onMessage(c, msg);
+ }
+
+ @Test
+ public void testRecordRecord() throws Exception {
+ JSONObject msg = new JSONObject(MSG_BASE.toString())
+ .put("id", "wannaRecord")
+ .put("width", 640)
+ .put("height", 480)
+ .put("shareType", "shareType")
+ .put("fps", "fps")
+ ;
+ Client c = getClientFull();
+ handler.onMessage(c, msg);
+ assertTrue(handler.isSharing(ROOM_ID));
+ handler.onMessage(c, msg);
+ }
+}
diff --git a/openmeetings-core/src/test/java/org/apache/openmeetings/core/remote/TestKurentoHandlerMocked.java b/openmeetings-core/src/test/java/org/apache/openmeetings/core/remote/TestSetupFlowMocked.java
similarity index 68%
rename from openmeetings-core/src/test/java/org/apache/openmeetings/core/remote/TestKurentoHandlerMocked.java
rename to openmeetings-core/src/test/java/org/apache/openmeetings/core/remote/TestSetupFlowMocked.java
index e77afe7..303a759 100644
--- a/openmeetings-core/src/test/java/org/apache/openmeetings/core/remote/TestKurentoHandlerMocked.java
+++ b/openmeetings-core/src/test/java/org/apache/openmeetings/core/remote/TestSetupFlowMocked.java
@@ -24,61 +24,33 @@ import static org.apache.openmeetings.core.remote.KurentoHandler.PARAM_CANDIDATE
import static org.apache.openmeetings.core.remote.KurentoHandler.TAG_MODE;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.powermock.api.mockito.PowerMockito.mockStatic;
import static org.powermock.api.mockito.PowerMockito.whenNew;
-import org.apache.openmeetings.core.util.WebSocketHelper;
import org.apache.openmeetings.db.entity.basic.WsClient;
-import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.kurento.client.KurentoClient;
-import org.kurento.client.KurentoConnectionListener;
import org.kurento.client.MediaPipeline;
import org.kurento.client.MediaProfileSpecType;
import org.kurento.client.PlayerEndpoint;
import org.kurento.client.RecorderEndpoint;
-import org.kurento.client.ServerManager;
import org.kurento.client.Transaction;
import org.kurento.client.WebRtcEndpoint;
-import org.kurento.client.internal.TransactionImpl;
-import org.kurento.client.internal.client.RomManager;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
import com.github.openjson.JSONObject;
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({KurentoClient.class, WebSocketHelper.class, IKStream.class})
-public class TestKurentoHandlerMocked {
- @Mock
- private RomManager romManager;
- @Mock
- private ServerManager kServerManager;
- @Mock
- private KurentoClient client;
- @InjectMocks
- private KurentoHandler handler;
- private final static JSONObject TEST_BASE = new JSONObject().put(TAG_MODE, MODE_TEST);
-
- @Before
+public class TestSetupFlowMocked extends BaseMockedTest {
+ @Override
public void setup() {
- mockStatic(KurentoClient.class);
- mockStatic(WebSocketHelper.class);
- when(client.getServerManager()).thenReturn(kServerManager);
- when(KurentoClient.create(nullable(String.class), any(KurentoConnectionListener.class))).thenReturn(client);
- when(client.beginTransaction()).thenReturn(new TransactionImpl(romManager));
- handler.init();
+ super.setup();
+ doReturn(true).when(handler).isConnected();
+ MSG_BASE.put(TAG_MODE, MODE_TEST);
}
@Test
public void testMsgTestWannaRecord() throws Exception {
- JSONObject msg = new JSONObject(TEST_BASE.toString()).put("id", "wannaRecord");
+ JSONObject msg = new JSONObject(MSG_BASE.toString()).put("id", "wannaRecord");
WsClient c = new WsClient("sessionId", 0);
handler.onMessage(c, msg);
}
@@ -99,7 +71,7 @@ public class TestKurentoHandlerMocked {
WsClient c = new WsClient("sessionId", 0);
for (boolean audio : new boolean[] {true, false}) {
for (boolean video : new boolean[] {true, false}) {
- JSONObject msg = new JSONObject(TEST_BASE.toString())
+ JSONObject msg = new JSONObject(MSG_BASE.toString())
.put("id", "record")
.put("sdpOffer", "")
.put("audio", audio)
@@ -107,7 +79,7 @@ public class TestKurentoHandlerMocked {
handler.onMessage(c, msg);
}
}
- JSONObject iceMsg = new JSONObject(TEST_BASE.toString())
+ JSONObject iceMsg = new JSONObject(MSG_BASE.toString())
.put("id", "iceCandidate")
.put(PARAM_CANDIDATE, new JSONObject()
.put(PARAM_CANDIDATE, "candidate")
@@ -117,14 +89,14 @@ public class TestKurentoHandlerMocked {
PlayerEndpoint.Builder playBuilder = mock(PlayerEndpoint.Builder.class);
whenNew(PlayerEndpoint.Builder.class).withArguments(any(MediaPipeline.class), anyString()).thenReturn(playBuilder);
when(playBuilder.build()).thenReturn(mock(PlayerEndpoint.class));
- handler.onMessage(c, new JSONObject(TEST_BASE.toString())
+ handler.onMessage(c, new JSONObject(MSG_BASE.toString())
.put("id", "play")
.put("sdpOffer", "sdpOffer"));
}
@Test
public void testMsgTestIceCandidate() throws Exception {
- JSONObject msg = new JSONObject(TEST_BASE.toString())
+ JSONObject msg = new JSONObject(MSG_BASE.toString())
.put("id", "iceCandidate")
.put(KurentoHandler.PARAM_CANDIDATE, new JSONObject());
WsClient c = new WsClient("sessionId", 0);
@@ -133,14 +105,14 @@ public class TestKurentoHandlerMocked {
@Test
public void testMsgTestWannaPlay() throws Exception {
- JSONObject msg = new JSONObject(TEST_BASE.toString()).put("id", "wannaPlay");
+ JSONObject msg = new JSONObject(MSG_BASE.toString()).put("id", "wannaPlay");
WsClient c = new WsClient("sessionId", 0);
handler.onMessage(c, msg);
}
@Test
public void testMsgTestPlay() throws Exception {
- JSONObject msg = new JSONObject(TEST_BASE.toString()).put("id", "play");
+ JSONObject msg = new JSONObject(MSG_BASE.toString()).put("id", "play");
WsClient c = new WsClient("sessionId", 0);
handler.onMessage(c, msg);
}