Skip to content

Commit

Permalink
Merge pull request #167 from Nexmo/feature/update-conversation-musico…
Browse files Browse the repository at this point in the history
…nholdurl-to-array

Update conversation musicOnHoldUrl to Array
  • Loading branch information
cr0wst authored May 29, 2018
2 parents d97fac9 + 4345131 commit 990e3fc
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [Development]

### Fixed
- Updated `ConversationNcco`'s `musicOnHoldUrl` to serialize into an array for use in the Voice API.

### Added
- Add `split` attribute to the `RecordNcco` object.

Expand Down
18 changes: 11 additions & 7 deletions src/main/java/com/nexmo/client/voice/ncco/ConversationNcco.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,16 @@ public String getMusicOnHoldUrl() {
return musicOnHoldUrl;
}

public void setMusicOnHoldUrl(String musicOnHoldUrl) {
this.musicOnHoldUrl = musicOnHoldUrl;
@JsonProperty("musicOnHoldUrl")
public String[] getMusicOnHoldUrlAsArray() {
// TODO: Rework in 4.0.
// This property is expected to be serialized as an array, however we want to also insure it remains null
// if null.
return this.musicOnHoldUrl != null ? new String[]{this.musicOnHoldUrl} : null;
}

public void setMusicOnHoldUrl(String... musicOnHoldUrl) {
this.musicOnHoldUrl = musicOnHoldUrl[0];
}

public Boolean getStartOnEnter() {
Expand Down Expand Up @@ -87,12 +95,8 @@ public String[] getEventUrl() {
return eventUrl;
}

public void setEventUrl(String eventUrl) {
setEventUrl(new String[]{eventUrl});
}

@JsonProperty("eventUrl")
public void setEventUrl(String[] eventUrl) {
public void setEventUrl(String... eventUrl) {
this.eventUrl = eventUrl;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ public class ConversationNccoTest {
@Test
public void testJson() throws Exception {
ConversationNcco ncco = new ConversationNcco("conversation-name");
assertEquals(
"{\"name\":\"conversation-name\",\"action\":\"conversation\"}",
ncco.toJson());
assertEquals("{\"name\":\"conversation-name\",\"action\":\"conversation\"}", ncco.toJson());
}

@Test
Expand All @@ -56,4 +54,67 @@ public void testToJson() throws Exception {
assertEquals(false, ncco2.getStartOnEnter());
}

@Test
public void testWithOnlyNameParameter() throws Exception {
ConversationNcco ncco = new ConversationNcco("Test");

String expectedJson = "{\"name\":\"Test\",\"action\":\"conversation\"}";
assertEquals(expectedJson, ncco.toJson());
}

@Test
public void testMusicOnHoldUrl() throws Exception {
ConversationNcco ncco = new ConversationNcco("Test");
ncco.setMusicOnHoldUrl("https://example.org");

String expectedJson = "{\"name\":\"Test\",\"musicOnHoldUrl\":[\"https://example.org\"],\"action\":\"conversation\"}";
assertEquals(expectedJson, ncco.toJson());

ncco = new ConversationNcco("Test");
}

@Test
public void testStartOnEnter() throws Exception {
ConversationNcco ncco = new ConversationNcco("Test");
ncco.setStartOnEnter(true);

String expectedJson = "{\"name\":\"Test\",\"startOnEnter\":true,\"action\":\"conversation\"}";
assertEquals(expectedJson, ncco.toJson());
}

@Test
public void testEndOnExit() throws Exception {
ConversationNcco ncco = new ConversationNcco("Test");
ncco.setEndOnExit(true);

String expectedJson = "{\"name\":\"Test\",\"endOnExit\":true,\"action\":\"conversation\"}";
assertEquals(expectedJson, ncco.toJson());
}

@Test
public void testRecord() throws Exception {
ConversationNcco ncco = new ConversationNcco("Test");
ncco.setRecord(true);

String expectedJson = "{\"name\":\"Test\",\"record\":true,\"action\":\"conversation\"}";
assertEquals(expectedJson, ncco.toJson());
}

@Test
public void testEventUrl() throws Exception {
ConversationNcco ncco = new ConversationNcco("Test");
ncco.setEventUrl("https://exmaple.org");

String expectedJson = "{\"name\":\"Test\",\"action\":\"conversation\",\"eventUrl\":[\"https://exmaple.org\"]}";
assertEquals(expectedJson, ncco.toJson());
}

@Test
public void testEventMethod() throws Exception {
ConversationNcco ncco = new ConversationNcco("Test");
ncco.setEventMethod("Test");

String expectedJson = "{\"name\":\"Test\",\"eventMethod\":\"Test\",\"action\":\"conversation\"}";
assertEquals(expectedJson, ncco.toJson());
}
}

0 comments on commit 990e3fc

Please sign in to comment.