- Add test cases to different modules of android-aitt.
- Improve the test coverage
if (protocol != Aitt.Protocol.WEBRTC)
throw new InvalidParameterException("Invalid protocol");
+ if (topic == null || topic.isEmpty())
+ throw new InvalidParameterException("Invalid topic");
+
if (role == AittStream.StreamRole.SUBSCRIBER) {
return createSubscriberStream(topic, role, context);
} else {
byte[] newPayload = aittMessage.getPayload();
assertEquals("Received payload and expected payload are equal", 0, newPayload.length);
}
+
+ @Test(expected = NullPointerException.class)
+ public void testGetInvalidPayload_N() {
+ AittMessage aittMessage = new AittMessage(null);
+ byte[] newPayload = aittMessage.getPayload();
+ }
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
}
@Test
+ public void testSubscribeIpcInvalidCallback_N() {
+ try {
+ shadowJniInterface.setInitReturn(true);
+ Aitt aitt = new Aitt(appContext, aittId);
+ aitt.connect(brokerIp, port);
+
+ assertThrows(IllegalArgumentException.class, () -> aitt.subscribe(topic, null, Aitt.Protocol.IPC, Aitt.QoS.AT_MOST_ONCE));
+
+ aitt.disconnect();
+ } catch (Exception e) {
+ fail("Failed testSubscribeIpcInvalidCallback " + e);
+ }
+ }
+
+ @Test
public void testSubscribeAnyProtocol_P() {
try {
shadowJniInterface.setInitReturn(true);
}
@Test
- public void testCreateRTSPStreamInvalidTopic_N() {
+ public void testCreateRTSPSubscriberStreamEmptyTopic_N() {
try {
shadowJniInterface.setInitReturn(true);
Aitt aitt = new Aitt(appContext, aittId);
aitt.disconnect();
} catch (Exception e) {
- fail("Failed testCreateRTSPStreamInvalidTopic " + e);
+ fail("Failed testCreateRTSPSubscriberStreamEmptyTopic " + e);
+ }
+ }
+
+ @Test
+ public void testCreateRTSPPublisherStreamEmptyTopic_N() {
+ try {
+ shadowJniInterface.setInitReturn(true);
+ Aitt aitt = new Aitt(appContext, aittId);
+ aitt.connect(brokerIp, port);
+
+ assertThrows(IllegalArgumentException.class, () -> aitt.createStream(Aitt.Protocol.RTSP, "", AittStream.StreamRole.PUBLISHER));
+
+ aitt.disconnect();
+ } catch (Exception e) {
+ fail("Failed testCreateRTSPPublisherStreamEmptyTopic " + e);
+ }
+ }
+
+ @Test
+ public void testCreateRTSPSubscriberStreamNullTopic_N() {
+ try {
+ shadowJniInterface.setInitReturn(true);
+ Aitt aitt = new Aitt(appContext, aittId);
+ aitt.connect(brokerIp, port);
+
+ assertThrows(IllegalArgumentException.class, () -> aitt.createStream(Aitt.Protocol.RTSP, null, AittStream.StreamRole.SUBSCRIBER));
+
+ aitt.disconnect();
+ } catch (Exception e) {
+ fail("Failed testCreateRTSPSubscriberStreamNullTopic " + e);
+ }
+ }
+
+ @Test
+ public void testCreateRTSPPublisherStreamNullTopic_N() {
+ try {
+ shadowJniInterface.setInitReturn(true);
+ Aitt aitt = new Aitt(appContext, aittId);
+ aitt.connect(brokerIp, port);
+
+ assertThrows(IllegalArgumentException.class, () -> aitt.createStream(Aitt.Protocol.RTSP, null, AittStream.StreamRole.PUBLISHER));
+
+ aitt.disconnect();
+ } catch (Exception e) {
+ fail("Failed testCreateRTSPPublisherStreamNullTopic " + e);
+ }
+ }
+
+ @Test
+ public void testCreateWebRTCSubscriberStreamEmptyTopic_N() {
+ try {
+ shadowJniInterface.setInitReturn(true);
+ Aitt aitt = new Aitt(appContext, aittId);
+ aitt.connect(brokerIp, port);
+
+ assertThrows(IllegalArgumentException.class, () -> aitt.createStream(Aitt.Protocol.WEBRTC, "", AittStream.StreamRole.SUBSCRIBER));
+
+ aitt.disconnect();
+ } catch (Exception e) {
+ fail("Failed testCreateWebRTCSubscriberStreamEmptyTopic " + e);
+ }
+ }
+
+ @Test
+ public void testCreateWebRTCPublisherStreamEmptyTopic_N() {
+ try {
+ shadowJniInterface.setInitReturn(true);
+ Aitt aitt = new Aitt(appContext, aittId);
+ aitt.connect(brokerIp, port);
+
+ assertThrows(IllegalArgumentException.class, () -> aitt.createStream(Aitt.Protocol.WEBRTC, "", AittStream.StreamRole.PUBLISHER));
+
+ aitt.disconnect();
+ } catch (Exception e) {
+ fail("Failed testCreateWebRTCPublisherStreamEmptyTopic " + e);
+ }
+ }
+
+ @Test
+ public void testCreateWebRTCSubscriberStreamNullTopic_N() {
+ try {
+ shadowJniInterface.setInitReturn(true);
+ Aitt aitt = new Aitt(appContext, aittId);
+ aitt.connect(brokerIp, port);
+
+ assertThrows(IllegalArgumentException.class, () -> aitt.createStream(Aitt.Protocol.WEBRTC, null, AittStream.StreamRole.SUBSCRIBER));
+
+ aitt.disconnect();
+ } catch (Exception e) {
+ fail("Failed testCreateWebRTCSubscriberStreamNullTopic " + e);
+ }
+ }
+
+ @Test
+ public void testCreateWebRTCPublisherStreamNullTopic_N() {
+ try {
+ shadowJniInterface.setInitReturn(true);
+ Aitt aitt = new Aitt(appContext, aittId);
+ aitt.connect(brokerIp, port);
+
+ assertThrows(IllegalArgumentException.class, () -> aitt.createStream(Aitt.Protocol.WEBRTC, null, AittStream.StreamRole.PUBLISHER));
+
+ aitt.disconnect();
+ } catch (Exception e) {
+ fail("Failed testCreateWebRTCPublisherStreamNullTopic " + e);
+ }
+ }
+
+ @Test
+ public void testCreateMqttStream_N() {
+ try {
+ shadowJniInterface.setInitReturn(true);
+ Aitt aitt = new Aitt(appContext, aittId);
+ aitt.connect(brokerIp, port);
+
+ AittStream aittStream = aitt.createStream(Aitt.Protocol.MQTT, topic, AittStream.StreamRole.PUBLISHER);
+ assertNull(aittStream);
+
+ aitt.disconnect();
+ } catch (Exception e) {
+ fail("Failed testCreateMqttStream " + e);
+ }
+ }
+
+ @Test
+ public void testCreateTcpStream_N() {
+ try {
+ shadowJniInterface.setInitReturn(true);
+ Aitt aitt = new Aitt(appContext, aittId);
+ aitt.connect(brokerIp, port);
+
+ AittStream aittStream = aitt.createStream(Aitt.Protocol.TCP, topic, AittStream.StreamRole.PUBLISHER);
+ assertNull(aittStream);
+
+ aitt.disconnect();
+ } catch (Exception e) {
+ fail("Failed testCreateTcpStream " + e);
}
}
}
}
@Test
+ public void testRTSPSetNullUri_N() {
+ try {
+ Aitt aitt = new Aitt(appContext, AITT_ID, wifiIP, true);
+ aitt.connect(brokerIp, PORT);
+
+ AittStream publisher = aitt.createStream(Aitt.Protocol.RTSP, TEST_TOPIC, PUBLISHER);
+
+ assertThrows(IllegalArgumentException.class, () -> publisher.setConfig("URI", null));
+
+ publisher.disconnect();
+ } catch (Exception e) {
+ fail("Failed testRTSPSetNullUri, (" + e + ")");
+ }
+ }
+
+ @Test
+ public void testRTSPSetInvalidUri_N() {
+ try {
+ Aitt aitt = new Aitt(appContext, AITT_ID, wifiIP, true);
+ aitt.connect(brokerIp, PORT);
+
+ AittStream publisher = aitt.createStream(Aitt.Protocol.RTSP, TEST_TOPIC, PUBLISHER);
+
+ assertThrows(IllegalArgumentException.class, () -> publisher.setConfig("URI", "tcp://someurl"));
+
+ publisher.disconnect();
+ } catch (Exception e) {
+ fail("Failed testRTSPSetInvalidUri, (" + e + ")");
+ }
+ }
+
+ @Test
public void testRTSPSetNullKey_N() {
try {
Aitt aitt = new Aitt(appContext, AITT_ID, wifiIP, true);
}
@Test
- public void testWebRTCStreamInvalidWidth_N() {
+ public void testWebRTCStreamNegativeWidth_N() {
try {
Aitt publisher = new Aitt(appContext, AITT_WEBRTC_CLIENT_ID + VIDEO_PREFIX, wifiIP, true);
publisher.connect(brokerIp, PORT);
publisherStream.disconnect();
} catch (Exception e) {
- fail("Failed testWebRTCStreamInvalidWidth, (" + e + ")");
+ fail("Failed testWebRTCStreamNegativeWidth, (" + e + ")");
}
}
@Test
- public void testWebRTCStreamInvalidHeight_N() {
+ public void testWebRTCStreamZeroWidth_N() {
+ try {
+ Aitt publisher = new Aitt(appContext, AITT_WEBRTC_CLIENT_ID + VIDEO_PREFIX, wifiIP, true);
+ publisher.connect(brokerIp, PORT);
+ AittStream publisherStream = publisher.createStream(Aitt.Protocol.WEBRTC, TEST_VIDEO_TOPIC, PUBLISHER);
+
+ assertThrows(IllegalArgumentException.class, () -> publisherStream.setConfig("WIDTH", "0")
+ .setConfig("HEIGHT", "240"));
+
+ publisherStream.disconnect();
+ } catch (Exception e) {
+ fail("Failed testWebRTCStreamZeroWidth, (" + e + ")");
+ }
+ }
+
+ @Test
+ public void testWebRTCStreamNegativeHeight_N() {
try {
Aitt publisher = new Aitt(appContext, AITT_WEBRTC_CLIENT_ID + VIDEO_PREFIX, wifiIP, true);
publisher.connect(brokerIp, PORT);
publisherStream.disconnect();
} catch (Exception e) {
- fail("Failed testWebRTCStreamInvalidHeight, (" + e + ")");
+ fail("Failed testWebRTCStreamNegativeHeight, (" + e + ")");
}
}
@Test
+ public void testWebRTCStreamZeroHeight_N() {
+ try {
+ Aitt publisher = new Aitt(appContext, AITT_WEBRTC_CLIENT_ID + VIDEO_PREFIX, wifiIP, true);
+ publisher.connect(brokerIp, PORT);
+ AittStream publisherStream = publisher.createStream(Aitt.Protocol.WEBRTC, TEST_VIDEO_TOPIC, PUBLISHER);
+
+ assertThrows(IllegalArgumentException.class, () -> publisherStream.setConfig("WIDTH", "320")
+ .setConfig("HEIGHT", "0"));
+
+ publisherStream.disconnect();
+ } catch (Exception e) {
+ fail("Failed testWebRTCStreamZeroHeight, (" + e + ")");
+ }
+ }
+ @Test
public void testWebRTCStreamInvalidSourceType_N() {
try {
Aitt publisher = new Aitt(appContext, AITT_WEBRTC_CLIENT_ID + VIDEO_PREFIX, wifiIP, true);
publisherStream.disconnect();
} catch (Exception e) {
- fail("Failed testWebRTCStreamInvalidHeight, (" + e + ")");
+ fail("Failed testWebRTCStreamInvalidSourceType, (" + e + ")");
+ }
+ }
+ @Test
+ public void testWebRTCStreamInvalidMediaFormat_N() {
+ try {
+ Aitt publisher = new Aitt(appContext, AITT_WEBRTC_CLIENT_ID + VIDEO_PREFIX, wifiIP, true);
+ publisher.connect(brokerIp, PORT);
+ AittStream publisherStream = publisher.createStream(Aitt.Protocol.WEBRTC, TEST_VIDEO_TOPIC, PUBLISHER);
+
+ assertThrows(IllegalArgumentException.class, () -> publisherStream.setConfig("MEDIA_FORMAT", "A"));
+
+ publisherStream.disconnect();
+ } catch (Exception e) {
+ fail("Failed testWebRTCStreamInvalidMediaFormat, (" + e + ")");
}
}
@Test
- public void testWebRTCStreamInvalidFrameRate_N() {
+ public void testWebRTCStreamNegativeFrameRate_N() {
try {
Aitt publisher = new Aitt(appContext, AITT_WEBRTC_CLIENT_ID + VIDEO_PREFIX, wifiIP, true);
publisher.connect(brokerIp, PORT);
publisherStream.disconnect();
} catch (Exception e) {
- fail("Failed testWebRTCStreamInvalidHeight, (" + e + ")");
+ fail("Failed testWebRTCStreamNegativeFrameRate, (" + e + ")");
+ }
+ }
+
+ @Test
+ public void testWebRTCStreamZeroFrameRate_N() {
+ try {
+ Aitt publisher = new Aitt(appContext, AITT_WEBRTC_CLIENT_ID + VIDEO_PREFIX, wifiIP, true);
+ publisher.connect(brokerIp, PORT);
+ AittStream publisherStream = publisher.createStream(Aitt.Protocol.WEBRTC, TEST_VIDEO_TOPIC, PUBLISHER);
+
+ assertThrows(IllegalArgumentException.class, () -> publisherStream.setConfig("FRAME_RATE", "0"));
+
+ publisherStream.disconnect();
+ } catch (Exception e) {
+ fail("Failed testWebRTCStreamZeroFrameRate, (" + e + ")");
}
}