Skip to content

Commit 0a2f918

Browse files
committed
Deprecates VMS send without parameters action
1 parent cb5c79b commit 0a2f918

7 files changed

Lines changed: 138 additions & 57 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
2929
- `pl.smsapi.api.VmsFactory.actionDelete` without parameters marked as deprecated
3030
- `pl.smsapi.api.action.vms.VMSDelete` without parameters marked as deprecated
3131
- `pl.smsapi.api.action.vms.VMSGet` without parameters marked as deprecated
32+
- `pl.smsapi.api.action.vms.VMSSend` without parameters marked as deprecated
3233

3334
### Removed
3435
- legacy `phonebook.do` contacts API support

src/main/java/pl/smsapi/api/VmsFactory.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pl.smsapi.proxy.Proxy;
88

99
import java.io.File;
10-
import java.io.FileNotFoundException;
10+
import java.io.IOException;
1111

1212
public class VmsFactory extends ActionFactory {
1313

@@ -35,33 +35,33 @@ public VMSSend actionSend() {
3535
}
3636

3737
public VMSSend actionSend(String to, String tts) {
38-
VMSSend action = actionSend();
39-
action.setTo(to);
40-
action.setTts(tts);
38+
VMSSend action = new VMSSend(to, tts);
39+
action.client(client);
40+
action.proxy(proxy);
4141

4242
return action;
4343
}
4444

4545
public VMSSend actionSend(String[] to, String tts) {
46-
VMSSend action = actionSend();
47-
action.setTo(to);
48-
action.setTts(tts);
46+
VMSSend action = new VMSSend(to, tts);
47+
action.client(client);
48+
action.proxy(proxy);
4949

5050
return action;
5151
}
5252

53-
public VMSSend actionSend(String to, File file) throws FileNotFoundException {
54-
VMSSend action = actionSend();
55-
action.setTo(to);
56-
action.setFile(file);
53+
public VMSSend actionSend(String to, File file) throws IOException {
54+
VMSSend action = new VMSSend(to, file);
55+
action.client(client);
56+
action.proxy(proxy);
5757

5858
return action;
5959
}
6060

61-
public VMSSend actionSend(String[] to, File file) throws FileNotFoundException {
62-
VMSSend action = actionSend();
63-
action.setTo(to);
64-
action.setFile(file);
61+
public VMSSend actionSend(String[] to, File file) throws IOException {
62+
VMSSend action = new VMSSend(to, file);
63+
action.client(client);
64+
action.proxy(proxy);
6565

6666
return action;
6767
}

src/main/java/pl/smsapi/api/action/vms/VMSSend.java

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
import pl.smsapi.api.action.AbstractSendAction;
55
import pl.smsapi.api.response.StatusResponse;
66

7-
import java.io.File;
8-
import java.io.FileInputStream;
9-
import java.io.FileNotFoundException;
10-
import java.io.InputStream;
7+
import java.io.*;
8+
import java.nio.file.Files;
119

1210
public class VMSSend extends AbstractSendAction<VMSSend, StatusResponse> {
1311

@@ -24,12 +22,49 @@ public String toString() {
2422
}
2523
}
2624

25+
/**
26+
* @deprecated use {@link VMSSend(String, String)} or {@link VMSSend(String[], String)} or {@link VMSSend(String, File)}
27+
* or {@link VMSSend(String[], File)} instead
28+
*/
2729
public VMSSend() {
2830
setJson(true);
2931
}
3032

33+
public VMSSend(String to, String tts) {
34+
setJson(true);
35+
setTo(to);
36+
params.put("tts", tts);
37+
}
38+
39+
public VMSSend(String[] to, String tts) {
40+
setJson(true);
41+
setTo(to);
42+
params.put("tts", tts);
43+
}
44+
45+
public VMSSend(String to, File file) throws IOException {
46+
setJson(true);
47+
setTo(to);
48+
files.put("file", Files.newInputStream(file.toPath()));
49+
}
50+
51+
public VMSSend(String[] to, File file) throws IOException {
52+
setJson(true);
53+
setTo(to);
54+
files.put("file", Files.newInputStream(file.toPath()));
55+
}
56+
57+
public VMSSend(String[] to, InputStream file) {
58+
setJson(true);
59+
setTo(to);
60+
files.put("file", file);
61+
}
62+
3163
/**
3264
* Set local audio file.
65+
*
66+
* @deprecated use {@link VMSSend(String, File)} or {@link VMSSend(String[], File)} instead
67+
*
3368
*/
3469
public VMSSend setFile(File file) throws FileNotFoundException {
3570
files.put("file", new FileInputStream(file));
@@ -38,6 +73,8 @@ public VMSSend setFile(File file) throws FileNotFoundException {
3873

3974
/**
4075
* Set local audio filename.
76+
*
77+
* @deprecated use {@link VMSSend(String, File)} or {@link VMSSend(String[], File)} instead
4178
*/
4279
public VMSSend setFile(String pathFile) throws FileNotFoundException {
4380
files.put("file", new FileInputStream(pathFile));
@@ -46,6 +83,8 @@ public VMSSend setFile(String pathFile) throws FileNotFoundException {
4683

4784
/**
4885
* Set local audio stream.
86+
*
87+
* @deprecated use {@link VMSSend(String[], InputStream)} instead
4988
*/
5089
public VMSSend setFile(InputStream inputStream) {
5190
files.put("file", inputStream);
@@ -54,6 +93,8 @@ public VMSSend setFile(InputStream inputStream) {
5493

5594
/**
5695
* Set text to voice synthesizer.
96+
*
97+
* @deprecated use {@link VMSSend(String, String)} or {@link VMSSend(String[], String)} instead
5798
*/
5899
public VMSSend setTts(String tts) {
59100
params.put("tts", tts);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package pl.smsapi.api.action.vms;
2+
3+
public class StatusJsonMother {
4+
5+
public static String create() {
6+
return
7+
"{" +
8+
" \"count\":1," +
9+
" \"list\":[" +
10+
" {" +
11+
" \"id\":\"0f0f0f0f0f0f0f0f0f0f0f0f\"," +
12+
" \"points\":0.21," +
13+
" \"number\":\"48123123123\"," +
14+
" \"date_sent\":1717500698," +
15+
" \"submitted_number\":\"123123123\"," +
16+
" \"status\":\"QUEUE\"," +
17+
" \"error\":null," +
18+
" \"idx\":null," +
19+
" \"parts\":1" +
20+
" }" +
21+
" ]" +
22+
"}";
23+
}
24+
}

src/test/java/pl/smsapi/api/action/vms/VMSGetTest.java

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,7 @@ public class VMSGetTest {
1313

1414
@Test
1515
public void executeGetVmsRequest() throws SmsapiException {
16-
ProxyRequestSpy requestStub = new ProxyRequestSpy(
17-
"{" +
18-
"\"count\":1," +
19-
"\"list\":[" +
20-
"{" +
21-
" \"id\":\"0f0f0f0f0f0f0f0f0f0f0f0f\"," +
22-
" \"points\":0.21," +
23-
" \"number\":\"00000000000\"," +
24-
" \"date_sent\":1717500698," +
25-
" \"submitted_number\":\"000000\"," +
26-
" \"status\":\"QUEUE\"," +
27-
" \"error\":null," +
28-
" \"idx\":null," +
29-
" \"parts\":1" +
30-
"}" +
31-
"]" +
32-
"}"
33-
);
16+
ProxyRequestSpy requestStub = new ProxyRequestSpy(StatusJsonMother.create());
3417
VMSGet action = new VMSGet("0f0f0f0f0f0f0f0f0f0f0f0f");
3518
action.client(new ClientStub());
3619
action.proxy(requestStub);
@@ -47,24 +30,7 @@ public void executeGetVmsRequest() throws SmsapiException {
4730

4831
@Test
4932
public void executeGetMultipleVmsRequest() throws SmsapiException {
50-
ProxyRequestSpy requestStub = new ProxyRequestSpy(
51-
"{" +
52-
"\"count\":1," +
53-
"\"list\":[" +
54-
"{" +
55-
" \"id\":\"0f0f0f0f0f0f0f0f0f0f0f0f\"," +
56-
" \"points\":0.21," +
57-
" \"number\":\"00000000000\"," +
58-
" \"date_sent\":1717500698," +
59-
" \"submitted_number\":\"000000\"," +
60-
" \"status\":\"QUEUE\"," +
61-
" \"error\":null," +
62-
" \"idx\":null," +
63-
" \"parts\":1" +
64-
"}" +
65-
"]" +
66-
"}"
67-
);
33+
ProxyRequestSpy requestStub = new ProxyRequestSpy(StatusJsonMother.create());
6834
VMSGet action = new VMSGet(new String[]{"0f0f0f0f0f0f0f0f0f0f0f0f", "0f0f0f0f0f0f0f0f0f0f0f01"});
6935
action.client(new ClientStub());
7036
action.proxy(requestStub);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package pl.smsapi.api.action.vms;
2+
3+
import org.junit.Test;
4+
import pl.smsapi.exception.SmsapiException;
5+
import pl.smsapi.test.doubles.ClientStub;
6+
import pl.smsapi.test.doubles.ProxyRequestSpy;
7+
8+
import java.util.HashMap;
9+
10+
import static org.junit.Assert.assertEquals;
11+
12+
public class VMSSendTest {
13+
14+
@Test
15+
public void executeSendVmsFromTTSRequest() throws SmsapiException {
16+
ProxyRequestSpy requestStub = new ProxyRequestSpy(StatusJsonMother.create());
17+
VMSSend action = new VMSSend("48123123123", "text to speech");
18+
action.client(new ClientStub());
19+
action.proxy(requestStub);
20+
21+
action.execute();
22+
23+
assertEquals("POST", requestStub.requestMethod);
24+
assertEquals("vms.do", requestStub.requestEndpoint);
25+
HashMap<String, String> expectedRequestPayload = new HashMap<>();
26+
expectedRequestPayload.put("tts", "text to speech");
27+
expectedRequestPayload.put("to", "48123123123");
28+
expectedRequestPayload.put("format", "json");
29+
assertEquals(expectedRequestPayload, requestStub.requestPayload);
30+
}
31+
32+
@Test
33+
public void executeSendMultipleVmsFromTTSRequest() throws SmsapiException {
34+
ProxyRequestSpy requestStub = new ProxyRequestSpy(StatusJsonMother.create());
35+
VMSSend action = new VMSSend(new String[]{"48123123123", "48123123124"}, "text to speech");
36+
action.client(new ClientStub());
37+
action.proxy(requestStub);
38+
39+
action.execute();
40+
41+
assertEquals("POST", requestStub.requestMethod);
42+
assertEquals("vms.do", requestStub.requestEndpoint);
43+
HashMap<String, String> expectedRequestPayload = new HashMap<>();
44+
expectedRequestPayload.put("tts", "text to speech");
45+
expectedRequestPayload.put("to", "48123123123,48123123124");
46+
expectedRequestPayload.put("format", "json");
47+
assertEquals(expectedRequestPayload, requestStub.requestPayload);
48+
}
49+
}

src/test/java/pl/smsapi/api/action/vms/VmsFactoryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import pl.smsapi.test.TestSmsapi;
1313

1414
import java.io.File;
15-
import java.io.FileNotFoundException;
15+
import java.io.IOException;
1616
import java.util.Date;
1717
import java.util.Optional;
1818

@@ -42,7 +42,7 @@ public void sendVmsWithTts() throws SmsapiException {
4242
}
4343

4444
@Test
45-
public void sendVmsWithFile() throws FileNotFoundException, SmsapiException {
45+
public void sendVmsWithFile() throws IOException, SmsapiException {
4646
VMSSend action = apiFactory.actionSend(numberTest, new File("src/test/java/pl/smsapi/test/voice_small.wav"));
4747

4848
StatusResponse responseAdd = action.execute();

0 commit comments

Comments
 (0)