Skip to content

Commit

Permalink
Fix Voice UUID & remove spring-test (#473)
Browse files Browse the repository at this point in the history
* More permissive UUID for Voice

* Removed spring-web test dependency
  • Loading branch information
SMadani authored Aug 10, 2023
1 parent d9d801c commit 5ee1f52
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Added missing fields to Application, capabilities and webhooks
- Removed `PageList` (replaced by `HalPageResponse`)
- Improved documentation for Application API implementation
- Relaxed UUID validation in `VoiceClient`

# [7.6.0] - 2023-06-30
- Added Proactive Connect API implementation
Expand Down
2 changes: 0 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ dependencies {

testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-inline:4.11.0'
testImplementation 'org.springframework:spring-test:5.3.29'
testImplementation 'org.springframework:spring-web:5.3.29'
testImplementation 'jakarta.servlet:jakarta.servlet-api:4.0.4'
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/vonage/client/voice/VoiceClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Objects;
import java.util.UUID;

/**
* A client for talking to the Vonage Voice API. The standard way to obtain an instance of this class is to use {@link
Expand Down Expand Up @@ -60,7 +59,7 @@ public VoiceClient(HttpWrapper httpWrapper) {
}

private String validateUuid(String uuid) {
return UUID.fromString(Objects.requireNonNull(uuid, "UUID is required.")).toString();
return Objects.requireNonNull(uuid, "UUID is required.");
}

private String validateUrl(String url) {
Expand Down
42 changes: 37 additions & 5 deletions src/test/java/com/vonage/client/auth/RequestSigningTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
import org.apache.http.message.BasicNameValuePair;
import static org.junit.Assert.*;
import org.junit.Test;
import org.mockito.Mockito;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.springframework.mock.web.MockHttpServletRequest;
import javax.servlet.ReadListener;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -231,11 +234,40 @@ private HttpServletRequest constructDummyRequest() {
}


private HttpServletRequest constructDummyRequestJson() {
MockHttpServletRequest request = new MockHttpServletRequest();
private HttpServletRequest constructDummyRequestJson() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
String dummyJson = "{\"a\":\"alphabet\",\"b\":\"bananas\",\"timestamp\":\"2100\",\"sig\":\"b7f749de27b4adcf736cc95c9a7e059a16c85127\"}";
request.setContent(dummyJson.getBytes());
request.setContentType("application/json");
Mockito.when(request.getContentType()).thenReturn("application/json");
final byte[] contentBytes = dummyJson.getBytes(StandardCharsets.UTF_8);
ServletInputStream servletInputStream = new ServletInputStream() {
private int index = 0;

@Override
public int read() {
if (index < contentBytes.length) {
return contentBytes[index++] & 0xFF;
}
return -1;
}

@Override
public boolean isFinished() {
return index >= contentBytes.length;
}

@Override
public boolean isReady() {
return true;
}

@Override
public void setReadListener(ReadListener readListener) {
// No need to implement for this example
}
};

when(request.getInputStream()).thenReturn(servletInputStream);

return request;
}

Expand Down
8 changes: 3 additions & 5 deletions src/test/java/com/vonage/client/voice/VoiceClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,15 @@ public void testSendDtmf() throws Exception {
assertThrows(IllegalArgumentException.class, () ->
client.sendDtmf("944dd293-ca13-4a58-bc37-6252e11474be", null)
);
assertThrows(IllegalArgumentException.class, () ->
client.sendDtmf("invalid", "1234")
);
assertThrows(NullPointerException.class, () -> client.sendDtmf(null, "1234"));
}

@Test
public void testModifyCall() throws Exception {
VoiceClient client = new VoiceClient(stubHttpWrapper(200, "{\"message\":\"Received\"}"));
ModifyCallResponse call = client.modifyCall("93137ee3-580e-45f7-a61a-e0b5716000ef", ModifyCallAction.HANGUP);
assertEquals("Received", call.getMessage());
assertThrows(IllegalArgumentException.class, () -> client.modifyCall("invalid", ModifyCallAction.HANGUP));
assertThrows(NullPointerException.class, () -> client.modifyCall(null, ModifyCallAction.HANGUP));
assertThrows(NullPointerException.class, () ->
client.modifyCall("93137ee3-580e-45f7-a61a-e0b5716000ef", null)
);
Expand Down Expand Up @@ -352,7 +350,7 @@ public void testStopTalk() throws Exception {
TalkResponse response = client.stopTalk("944dd293-ca13-4a58-bc37-6252e11474be");
assertEquals("Talk stopped", response.getMessage());
assertEquals("944dd293-ca13-4a58-bc37-6252e11474be", response.getUuid());
assertThrows(IllegalArgumentException.class, () -> client.stopTalk("Blah"));
assertThrows(NullPointerException.class, () -> client.stopTalk(null));
}

@Test
Expand Down

0 comments on commit 5ee1f52

Please sign in to comment.