From 0f8eb731dd0cc25deb405e99b57b40eedd247ed2 Mon Sep 17 00:00:00 2001 From: Maciej Lew Date: Tue, 4 Jun 2024 12:07:58 +0200 Subject: [PATCH 01/12] Moves VMS factory test to package --- .../VmsTest.java => api/action/vms/VmsFactoryTest.java} | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) rename src/test/java/pl/smsapi/{test/run/VmsTest.java => api/action/vms/VmsFactoryTest.java} (94%) diff --git a/src/test/java/pl/smsapi/test/run/VmsTest.java b/src/test/java/pl/smsapi/api/action/vms/VmsFactoryTest.java similarity index 94% rename from src/test/java/pl/smsapi/test/run/VmsTest.java rename to src/test/java/pl/smsapi/api/action/vms/VmsFactoryTest.java index e4c583d..a6fa362 100644 --- a/src/test/java/pl/smsapi/test/run/VmsTest.java +++ b/src/test/java/pl/smsapi/api/action/vms/VmsFactoryTest.java @@ -1,12 +1,9 @@ -package pl.smsapi.test.run; +package pl.smsapi.api.action.vms; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import pl.smsapi.api.VmsFactory; -import pl.smsapi.api.action.vms.VMSDelete; -import pl.smsapi.api.action.vms.VMSGet; -import pl.smsapi.api.action.vms.VMSSend; import pl.smsapi.api.response.CountableResponse; import pl.smsapi.api.response.MessageResponse; import pl.smsapi.api.response.StatusResponse; @@ -18,7 +15,7 @@ import java.util.Date; @Ignore -public class VmsTest extends TestSmsapi { +public class VmsFactoryTest extends TestSmsapi { private String numberTest = "694562829"; private String[] ids; From c83c2918e97fc52393909d6bd4d44fe4e2e99075 Mon Sep 17 00:00:00 2001 From: Maciej Lew Date: Tue, 4 Jun 2024 13:00:06 +0200 Subject: [PATCH 02/12] Refactors VMS e2e test --- .../smsapi/api/action/vms/VmsFactoryTest.java | 108 ++++++------------ 1 file changed, 38 insertions(+), 70 deletions(-) diff --git a/src/test/java/pl/smsapi/api/action/vms/VmsFactoryTest.java b/src/test/java/pl/smsapi/api/action/vms/VmsFactoryTest.java index a6fa362..5c452b1 100644 --- a/src/test/java/pl/smsapi/api/action/vms/VmsFactoryTest.java +++ b/src/test/java/pl/smsapi/api/action/vms/VmsFactoryTest.java @@ -13,11 +13,13 @@ import java.io.File; import java.io.FileNotFoundException; import java.util.Date; +import java.util.Optional; + +import static org.junit.Assert.*; @Ignore public class VmsFactoryTest extends TestSmsapi { - private String numberTest = "694562829"; - private String[] ids; + private String numberTest = "48694562829"; VmsFactory apiFactory; @@ -29,97 +31,63 @@ public void setUp() { @Test public void vmsSendTtsTest() throws SmsapiException { - final long time = (new Date().getTime() / 1000) + 86400; - - final String tts = "to jest test"; - VMSSend action = apiFactory.actionSend() - .setTts(tts) - .setTo(numberTest) - .setInterval(300) - .setDateSent(time); + .setTts("to jest test") + .setTo(numberTest); - StatusResponse result = action.execute(); + StatusResponse responseAdd = action.execute(); - System.out.println("VmsSend:"); - - ids = new String[result.getCount()]; - int i = 0; - - for (MessageResponse item : result.getList()) { - if (!item.isError()) { - renderMessageItem(item); - ids[i] = item.getId(); - i++; - } - } - - if (ids.length > 0) { - writeIds(ids); - } + assertNotNull(responseAdd); + assertEquals(1, responseAdd.count); + assertTrue(responseAdd.list.stream().anyMatch(messageResponse -> messageResponse.getNumber().equals(numberTest))); } @Test public void vmsSendFileTest() throws FileNotFoundException, SmsapiException { - final long time = (new Date().getTime() / 1000) + 86400; - - final File fileAudio = new File("src/test/java/pl/smsapi/test/voice_small.wav"); - VMSSend action = apiFactory.actionSend() - .setFile(fileAudio) - .setTo(numberTest) - .setDateSent(time); - - StatusResponse result = action.execute(); - - System.out.println("VmsSend:"); + .setFile(new File("src/test/java/pl/smsapi/test/voice_small.wav")) + .setTo(numberTest); - if (result.getCount() > 0) { - ids = new String[result.getCount()]; - } + StatusResponse responseAdd = action.execute(); - int i = 0; - - for (MessageResponse item : result.getList()) { - if (!item.isError()) { - renderMessageItem(item); - ids[i] = item.getId(); - i++; - } - } - - if (ids.length > 0) { - writeIds(ids); - } + assertNotNull(responseAdd); + assertEquals(1, responseAdd.count); + assertTrue(responseAdd.list.stream().anyMatch(messageResponse -> messageResponse.getNumber().equals(numberTest))); } @Test public void vmsGetTest() throws SmsapiException { - System.out.println("VmsGet:"); - ids = readIds(); + StatusResponse responseAdd = apiFactory.actionSend() + .setTts("to jest test") + .setTo(numberTest) + .execute(); - if (ids != null) { - VMSGet action = apiFactory.actionGet().ids(ids); + Optional addMessageResponse = responseAdd.list.stream().findFirst(); + assertTrue(addMessageResponse.isPresent()); - StatusResponse result = action.execute(); + VMSGet actionGet = apiFactory.actionGet().id(addMessageResponse.get().getId()); + StatusResponse responseGet = actionGet.execute(); - for (MessageResponse item : result.getList()) { - renderMessageItem(item); - } - } + assertNotNull(responseGet); + assertEquals(1, responseGet.count); + assertTrue(responseGet.list.stream().anyMatch(getMessageResponse -> getMessageResponse.getNumber().equals(numberTest))); } @Test public void vmsDeleteTest() throws SmsapiException { - System.out.println("VmsDelete:"); - ids = readIds(); + StatusResponse responseAdd = apiFactory.actionSend() + .setTts("to jest test") + .setTo(numberTest) + .setDateSent((new Date().getTime() / 1000) + 120) + .execute(); - if (ids != null) { - VMSDelete action = apiFactory.actionDelete().ids(ids); + Optional addMessageResponse = responseAdd.list.stream().findFirst(); + assertTrue(addMessageResponse.isPresent()); - CountableResponse item = action.execute(); + VMSDelete actionDelete = apiFactory.actionDelete(addMessageResponse.get().getId()); + CountableResponse responseDelete = actionDelete.execute(); - System.out.println("Delete: " + item.getCount()); - } + assertNotNull(responseDelete); + assertEquals(1, responseDelete.count); } } \ No newline at end of file From 1706be0ff691ad00e3d237e9474ec02e8d688aac Mon Sep 17 00:00:00 2001 From: Maciej Lew Date: Tue, 4 Jun 2024 13:00:19 +0200 Subject: [PATCH 03/12] Refactors VMS e2e test --- src/test/java/pl/smsapi/api/action/vms/VmsFactoryTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/pl/smsapi/api/action/vms/VmsFactoryTest.java b/src/test/java/pl/smsapi/api/action/vms/VmsFactoryTest.java index 5c452b1..b6714cb 100644 --- a/src/test/java/pl/smsapi/api/action/vms/VmsFactoryTest.java +++ b/src/test/java/pl/smsapi/api/action/vms/VmsFactoryTest.java @@ -19,7 +19,7 @@ @Ignore public class VmsFactoryTest extends TestSmsapi { - private String numberTest = "48694562829"; + private final String numberTest = "48694562829"; VmsFactory apiFactory; From 8329023fe3c3f924e8e707152a347d6e14da1263 Mon Sep 17 00:00:00 2001 From: Maciej Lew Date: Tue, 4 Jun 2024 13:03:46 +0200 Subject: [PATCH 04/12] Refactors VMS e2e test --- .../java/pl/smsapi/api/action/vms/VmsFactoryTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/pl/smsapi/api/action/vms/VmsFactoryTest.java b/src/test/java/pl/smsapi/api/action/vms/VmsFactoryTest.java index b6714cb..2bcb018 100644 --- a/src/test/java/pl/smsapi/api/action/vms/VmsFactoryTest.java +++ b/src/test/java/pl/smsapi/api/action/vms/VmsFactoryTest.java @@ -30,7 +30,7 @@ public void setUp() { } @Test - public void vmsSendTtsTest() throws SmsapiException { + public void vmsSendTts() throws SmsapiException { VMSSend action = apiFactory.actionSend() .setTts("to jest test") .setTo(numberTest); @@ -43,7 +43,7 @@ public void vmsSendTtsTest() throws SmsapiException { } @Test - public void vmsSendFileTest() throws FileNotFoundException, SmsapiException { + public void vmsSendFile() throws FileNotFoundException, SmsapiException { VMSSend action = apiFactory.actionSend() .setFile(new File("src/test/java/pl/smsapi/test/voice_small.wav")) .setTo(numberTest); @@ -56,7 +56,7 @@ public void vmsSendFileTest() throws FileNotFoundException, SmsapiException { } @Test - public void vmsGetTest() throws SmsapiException { + public void vmsGet() throws SmsapiException { StatusResponse responseAdd = apiFactory.actionSend() .setTts("to jest test") .setTo(numberTest) @@ -74,7 +74,7 @@ public void vmsGetTest() throws SmsapiException { } @Test - public void vmsDeleteTest() throws SmsapiException { + public void vmsDelete() throws SmsapiException { StatusResponse responseAdd = apiFactory.actionSend() .setTts("to jest test") .setTo(numberTest) From be520a9ae842e9ae6ca103fc6a8b15d2bd49bb65 Mon Sep 17 00:00:00 2001 From: Maciej Lew Date: Tue, 4 Jun 2024 13:05:11 +0200 Subject: [PATCH 05/12] Refactors VMS e2e test --- .../java/pl/smsapi/api/action/vms/VmsFactoryTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/pl/smsapi/api/action/vms/VmsFactoryTest.java b/src/test/java/pl/smsapi/api/action/vms/VmsFactoryTest.java index 2bcb018..b24d0ab 100644 --- a/src/test/java/pl/smsapi/api/action/vms/VmsFactoryTest.java +++ b/src/test/java/pl/smsapi/api/action/vms/VmsFactoryTest.java @@ -30,7 +30,7 @@ public void setUp() { } @Test - public void vmsSendTts() throws SmsapiException { + public void sendVmsWithTts() throws SmsapiException { VMSSend action = apiFactory.actionSend() .setTts("to jest test") .setTo(numberTest); @@ -43,7 +43,7 @@ public void vmsSendTts() throws SmsapiException { } @Test - public void vmsSendFile() throws FileNotFoundException, SmsapiException { + public void sendVmsWithFile() throws FileNotFoundException, SmsapiException { VMSSend action = apiFactory.actionSend() .setFile(new File("src/test/java/pl/smsapi/test/voice_small.wav")) .setTo(numberTest); @@ -56,7 +56,7 @@ public void vmsSendFile() throws FileNotFoundException, SmsapiException { } @Test - public void vmsGet() throws SmsapiException { + public void getVms() throws SmsapiException { StatusResponse responseAdd = apiFactory.actionSend() .setTts("to jest test") .setTo(numberTest) @@ -74,7 +74,7 @@ public void vmsGet() throws SmsapiException { } @Test - public void vmsDelete() throws SmsapiException { + public void deleteVms() throws SmsapiException { StatusResponse responseAdd = apiFactory.actionSend() .setTts("to jest test") .setTo(numberTest) From dd327d7a8832040e0efcadb3505830cae1ccdd42 Mon Sep 17 00:00:00 2001 From: Maciej Lew Date: Tue, 4 Jun 2024 13:37:43 +0200 Subject: [PATCH 06/12] Deprecates some VMS action factories --- CHANGELOG.md | 3 + src/main/java/pl/smsapi/api/VmsFactory.java | 36 ++++++- .../smsapi/api/action/vms/VmsFactoryTest.java | 94 +++++++++++++++---- 3 files changed, 115 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f7f8db..82663f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a - `pl.smsapi.exception.ClientException` marked as deprecated, use `pl.smsapi.exception.SmsapiLegacyErrorException` instead - `pl.smsapi.exception.HostException` marked as deprecated, use `pl.smsapi.exception.SmsapiLegacyErrorException` instead - all client and server side errors are now being translated to `pl.smsapi.exception.SmsapiErrorException` or `pl.smsapi.exception.SmsapiLegacyErrorException` +- `pl.smsapi.api.VmsFactory.actionSend` without parameters marked as deprecated +- `pl.smsapi.api.VmsFactory.actionGet` without parameters marked as deprecated +- `pl.smsapi.api.VmsFactory.actionDelete` without parameters marked as deprecated ### Removed - legacy `phonebook.do` contacts API support diff --git a/src/main/java/pl/smsapi/api/VmsFactory.java b/src/main/java/pl/smsapi/api/VmsFactory.java index 565a530..9ae378f 100644 --- a/src/main/java/pl/smsapi/api/VmsFactory.java +++ b/src/main/java/pl/smsapi/api/VmsFactory.java @@ -6,6 +6,9 @@ import pl.smsapi.api.action.vms.VMSSend; import pl.smsapi.proxy.Proxy; +import java.io.File; +import java.io.FileNotFoundException; + public class VmsFactory extends ActionFactory { /** @@ -20,6 +23,10 @@ public VmsFactory(Client client, Proxy proxy) { super(client, proxy); } + /** + * @deprecated use {@link #actionSend(String, String)} or {@link #actionSend(String[], String)} + * or {@link #actionSend(String, File)} or {@link #actionSend(String[], File)} instead + */ public VMSSend actionSend() { VMSSend action = new VMSSend(); action.client(client); @@ -28,8 +35,11 @@ public VMSSend actionSend() { } public VMSSend actionSend(String to, String tts) { - String[] tos = new String[]{to}; - return actionSend(tos, tts); + VMSSend action = actionSend(); + action.setTo(to); + action.setTts(tts); + + return action; } public VMSSend actionSend(String[] to, String tts) { @@ -40,6 +50,25 @@ public VMSSend actionSend(String[] to, String tts) { return action; } + public VMSSend actionSend(String to, File file) throws FileNotFoundException { + VMSSend action = actionSend(); + action.setTo(to); + action.setFile(file); + + return action; + } + + public VMSSend actionSend(String[] to, File file) throws FileNotFoundException { + VMSSend action = actionSend(); + action.setTo(to); + action.setFile(file); + + return action; + } + + /** + * @deprecated use {@link #actionGet(String)} instead + */ public VMSGet actionGet() { VMSGet action = new VMSGet(); action.client(client); @@ -53,6 +82,9 @@ public VMSGet actionGet(String id) { return action; } + /** + * @deprecated use {@link #actionDelete(String)} instead + */ public VMSDelete actionDelete() { VMSDelete action = new VMSDelete(); action.client(client); diff --git a/src/test/java/pl/smsapi/api/action/vms/VmsFactoryTest.java b/src/test/java/pl/smsapi/api/action/vms/VmsFactoryTest.java index b24d0ab..5fb9885 100644 --- a/src/test/java/pl/smsapi/api/action/vms/VmsFactoryTest.java +++ b/src/test/java/pl/smsapi/api/action/vms/VmsFactoryTest.java @@ -7,6 +7,7 @@ import pl.smsapi.api.response.CountableResponse; import pl.smsapi.api.response.MessageResponse; import pl.smsapi.api.response.StatusResponse; +import pl.smsapi.exception.ActionException; import pl.smsapi.exception.SmsapiException; import pl.smsapi.test.TestSmsapi; @@ -31,9 +32,7 @@ public void setUp() { @Test public void sendVmsWithTts() throws SmsapiException { - VMSSend action = apiFactory.actionSend() - .setTts("to jest test") - .setTo(numberTest); + VMSSend action = apiFactory.actionSend(numberTest, "to jest test"); StatusResponse responseAdd = action.execute(); @@ -44,9 +43,7 @@ public void sendVmsWithTts() throws SmsapiException { @Test public void sendVmsWithFile() throws FileNotFoundException, SmsapiException { - VMSSend action = apiFactory.actionSend() - .setFile(new File("src/test/java/pl/smsapi/test/voice_small.wav")) - .setTo(numberTest); + VMSSend action = apiFactory.actionSend(numberTest, new File("src/test/java/pl/smsapi/test/voice_small.wav")); StatusResponse responseAdd = action.execute(); @@ -57,15 +54,13 @@ public void sendVmsWithFile() throws FileNotFoundException, SmsapiException { @Test public void getVms() throws SmsapiException { - StatusResponse responseAdd = apiFactory.actionSend() - .setTts("to jest test") - .setTo(numberTest) - .execute(); + StatusResponse responseAdd = apiFactory.actionSend(numberTest, "to jest test") + .execute(); Optional addMessageResponse = responseAdd.list.stream().findFirst(); assertTrue(addMessageResponse.isPresent()); - VMSGet actionGet = apiFactory.actionGet().id(addMessageResponse.get().getId()); + VMSGet actionGet = apiFactory.actionGet(addMessageResponse.get().getId()); StatusResponse responseGet = actionGet.execute(); assertNotNull(responseGet); @@ -75,11 +70,9 @@ public void getVms() throws SmsapiException { @Test public void deleteVms() throws SmsapiException { - StatusResponse responseAdd = apiFactory.actionSend() - .setTts("to jest test") - .setTo(numberTest) - .setDateSent((new Date().getTime() / 1000) + 120) - .execute(); + StatusResponse responseAdd = apiFactory.actionSend(numberTest, "to jest test") + .setDateSent((new Date().getTime() / 1000) + 120) + .execute(); Optional addMessageResponse = responseAdd.list.stream().findFirst(); assertTrue(addMessageResponse.isPresent()); @@ -90,4 +83,73 @@ public void deleteVms() throws SmsapiException { assertNotNull(responseDelete); assertEquals(1, responseDelete.count); } + + @Test + public void sendVmsWithError() throws SmsapiException { + boolean errorCatch = false; + VMSSend actionSend = apiFactory.actionSend(); + + try { + actionSend.execute(); + } catch (ActionException badRequest) { + assertEquals("Recipients list cannot be empty", badRequest.getMessage()); + assertEquals(13, badRequest.getCode()); + } + + try { + actionSend.setTo(numberTest).execute(); + } catch (ActionException badRequest) { + assertEquals("Set Content requires one of parameters (tts, file)! None of them given!", badRequest.getMessage()); + assertEquals(11, badRequest.getCode()); + errorCatch = true; + } + + assertTrue(errorCatch); + } + + @Test + public void getVmsWithError() throws SmsapiException { + boolean errorCatch = false; + VMSGet actionGet = apiFactory.actionGet(); + + try { + actionGet.execute(); + } catch (ActionException badRequest) { + assertEquals("Recipients list cannot be empty", badRequest.getMessage()); + assertEquals(13, badRequest.getCode()); + } + + try { + actionGet.id("not existing").execute(); + } catch (ActionException badRequest) { + assertEquals("Not exists ID message", badRequest.getMessage()); + assertEquals(301, badRequest.getCode()); + errorCatch = true; + } + + assertTrue(errorCatch); + } + + @Test + public void deleteVmsWithError() throws SmsapiException { + boolean errorCatch = false; + VMSDelete actionDelete = apiFactory.actionDelete(); + + try { + actionDelete.execute(); + } catch (ActionException badRequest) { + assertEquals("Recipients list cannot be empty", badRequest.getMessage()); + assertEquals(13, badRequest.getCode()); + } + + try { + actionDelete.id("not existing").execute(); + } catch (ActionException badRequest) { + assertEquals("Not exists ID message", badRequest.getMessage()); + assertEquals(301, badRequest.getCode()); + errorCatch = true; + } + + assertTrue(errorCatch); + } } \ No newline at end of file From 71bbf187beeaf9188a85479e9e204b98ea402817 Mon Sep 17 00:00:00 2001 From: Maciej Lew Date: Tue, 4 Jun 2024 14:49:34 +0200 Subject: [PATCH 07/12] Deprecates VMS delete without parameters action --- CHANGELOG.md | 1 + src/main/java/pl/smsapi/api/VmsFactory.java | 5 +- .../pl/smsapi/api/action/vms/VMSDelete.java | 17 +++++ .../smsapi/api/action/vms/VMSDeleteTest.java | 65 +++++++++++++++++++ 4 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 src/test/java/pl/smsapi/api/action/vms/VMSDeleteTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 82663f0..be28b68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a - `pl.smsapi.api.VmsFactory.actionSend` without parameters marked as deprecated - `pl.smsapi.api.VmsFactory.actionGet` without parameters marked as deprecated - `pl.smsapi.api.VmsFactory.actionDelete` without parameters marked as deprecated +- `pl.smsapi.api.action.vms.VMSDelete` without parameters marked as deprecated ### Removed - legacy `phonebook.do` contacts API support diff --git a/src/main/java/pl/smsapi/api/VmsFactory.java b/src/main/java/pl/smsapi/api/VmsFactory.java index 9ae378f..1368fc2 100644 --- a/src/main/java/pl/smsapi/api/VmsFactory.java +++ b/src/main/java/pl/smsapi/api/VmsFactory.java @@ -93,8 +93,9 @@ public VMSDelete actionDelete() { } public VMSDelete actionDelete(String id) { - VMSDelete action = actionDelete(); - action.id(id); + VMSDelete action = new VMSDelete(id); + action.client(client); + action.proxy(proxy); return action; } } diff --git a/src/main/java/pl/smsapi/api/action/vms/VMSDelete.java b/src/main/java/pl/smsapi/api/action/vms/VMSDelete.java index 62bbab9..6f41588 100644 --- a/src/main/java/pl/smsapi/api/action/vms/VMSDelete.java +++ b/src/main/java/pl/smsapi/api/action/vms/VMSDelete.java @@ -7,15 +7,30 @@ public class VMSDelete extends AbstractAction { + /** + * @deprecated use {@link VMSDelete(String)} or {@link VMSDelete(String[])} instead + */ public VMSDelete() { setJson(true); id(""); } + public VMSDelete(String id) { + setJson(true); + params.put("sch_del", id); + } + + public VMSDelete(String[] ids) { + setJson(true); + params.put("sch_del", StringUtils.join(ids, '|')); + } + /** * Set ID of message to delete. *

* This id was returned after sending message. + * + * @deprecated set id while constructing action, {@link VMSDelete(String)} */ public VMSDelete id(String id) { params.put("sch_del", id); @@ -26,6 +41,8 @@ public VMSDelete id(String id) { * Set ID of message to delete. *

* This id was returned after sending message. + * + * @deprecated set ids while constructing action, {@link VMSDelete(String[])} */ public VMSDelete ids(String[] ids) { params.put("sch_del", StringUtils.join(ids, '|')); diff --git a/src/test/java/pl/smsapi/api/action/vms/VMSDeleteTest.java b/src/test/java/pl/smsapi/api/action/vms/VMSDeleteTest.java new file mode 100644 index 0000000..8bff77f --- /dev/null +++ b/src/test/java/pl/smsapi/api/action/vms/VMSDeleteTest.java @@ -0,0 +1,65 @@ +package pl.smsapi.api.action.vms; + +import org.junit.Test; +import pl.smsapi.exception.SmsapiException; +import pl.smsapi.test.doubles.ClientStub; +import pl.smsapi.test.doubles.ProxyRequestSpy; + +import java.util.HashMap; + +import static org.junit.Assert.assertEquals; + +public class VMSDeleteTest { + + @Test + public void executeDeleteVmsRequest() throws SmsapiException { + ProxyRequestSpy requestStub = new ProxyRequestSpy( + "{" + + "\"count\":1," + + "\"list\":[" + + "{" + + " \"id\":\"0f0f0f0f0f0f0f0f0f0f0f0f\"" + + "}" + + "]" + + "}" + ); + VMSDelete action = new VMSDelete("0f0f0f0f0f0f0f0f0f0f0f0f"); + action.client(new ClientStub()); + action.proxy(requestStub); + + action.execute(); + + assertEquals("POST", requestStub.requestMethod); + assertEquals("vms.do", requestStub.requestEndpoint); + HashMap expectedRequestPayload = new HashMap<>(); + expectedRequestPayload.put("sch_del", "0f0f0f0f0f0f0f0f0f0f0f0f"); + expectedRequestPayload.put("format", "json"); + assertEquals(expectedRequestPayload, requestStub.requestPayload); + } + + @Test + public void executeDeleteMultipleVmsRequest() throws SmsapiException { + ProxyRequestSpy requestStub = new ProxyRequestSpy( + "{" + + "\"count\":1," + + "\"list\":[" + + "{" + + " \"id\":\"0f0f0f0f0f0f0f0f0f0f0f0f\"" + + "}" + + "]" + + "}" + ); + VMSDelete action = new VMSDelete(new String[]{"0f0f0f0f0f0f0f0f0f0f0f0f", "0f0f0f0f0f0f0f0f0f0f0f01"}); + action.client(new ClientStub()); + action.proxy(requestStub); + + action.execute(); + + assertEquals("POST", requestStub.requestMethod); + assertEquals("vms.do", requestStub.requestEndpoint); + HashMap expectedRequestPayload = new HashMap<>(); + expectedRequestPayload.put("sch_del", "0f0f0f0f0f0f0f0f0f0f0f0f|0f0f0f0f0f0f0f0f0f0f0f01"); + expectedRequestPayload.put("format", "json"); + assertEquals(expectedRequestPayload, requestStub.requestPayload); + } +} From edce302623d095ee31441b832a785488c78275ae Mon Sep 17 00:00:00 2001 From: Maciej Lew Date: Tue, 4 Jun 2024 15:10:43 +0200 Subject: [PATCH 08/12] Deprecates VMS get without parameters action --- src/main/java/pl/smsapi/api/VmsFactory.java | 5 +- .../java/pl/smsapi/api/action/vms/VMSGet.java | 17 ++++ .../pl/smsapi/api/action/vms/VMSGetTest.java | 81 +++++++++++++++++++ 3 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 src/test/java/pl/smsapi/api/action/vms/VMSGetTest.java diff --git a/src/main/java/pl/smsapi/api/VmsFactory.java b/src/main/java/pl/smsapi/api/VmsFactory.java index 1368fc2..505ddfc 100644 --- a/src/main/java/pl/smsapi/api/VmsFactory.java +++ b/src/main/java/pl/smsapi/api/VmsFactory.java @@ -77,8 +77,9 @@ public VMSGet actionGet() { } public VMSGet actionGet(String id) { - VMSGet action = actionGet(); - action.id(id); + VMSGet action = new VMSGet(id); + action.client(client); + action.proxy(proxy); return action; } diff --git a/src/main/java/pl/smsapi/api/action/vms/VMSGet.java b/src/main/java/pl/smsapi/api/action/vms/VMSGet.java index 8fde659..dbae902 100644 --- a/src/main/java/pl/smsapi/api/action/vms/VMSGet.java +++ b/src/main/java/pl/smsapi/api/action/vms/VMSGet.java @@ -7,15 +7,30 @@ public class VMSGet extends AbstractAction { + /** + * @deprecated use {@link VMSGet(String)} or {@link VMSGet(String[])} instead + */ public VMSGet() { setJson(true); id(""); } + public VMSGet(String id) { + setJson(true); + params.put("status", id); + } + + public VMSGet(String[] ids) { + setJson(true); + params.put("status", StringUtils.join(ids, '|')); + } + /** * Set ID of message to check. *

* This id was returned after sending message. + * + * @deprecated set id while constructing action, {@link VMSGet(String)} */ public VMSGet id(String id) { params.put("status", id); @@ -26,6 +41,8 @@ public VMSGet id(String id) { * Set IDs of messages to check. *

* This id was returned after sending message. + * + * @deprecated set id while constructing action, {@link VMSGet(String[])} */ public VMSGet ids(String[] ids) { params.put("status", StringUtils.join(ids, '|')); diff --git a/src/test/java/pl/smsapi/api/action/vms/VMSGetTest.java b/src/test/java/pl/smsapi/api/action/vms/VMSGetTest.java new file mode 100644 index 0000000..127f2f8 --- /dev/null +++ b/src/test/java/pl/smsapi/api/action/vms/VMSGetTest.java @@ -0,0 +1,81 @@ +package pl.smsapi.api.action.vms; + +import org.junit.Test; +import pl.smsapi.exception.SmsapiException; +import pl.smsapi.test.doubles.ClientStub; +import pl.smsapi.test.doubles.ProxyRequestSpy; + +import java.util.HashMap; + +import static org.junit.Assert.assertEquals; + +public class VMSGetTest { + + @Test + public void executeGetVmsRequest() throws SmsapiException { + ProxyRequestSpy requestStub = new ProxyRequestSpy( + "{" + + "\"count\":1," + + "\"list\":[" + + "{" + + " \"id\":\"0f0f0f0f0f0f0f0f0f0f0f0f\"," + + " \"points\":0.21," + + " \"number\":\"00000000000\"," + + " \"date_sent\":1717500698," + + " \"submitted_number\":\"000000\"," + + " \"status\":\"QUEUE\"," + + " \"error\":null," + + " \"idx\":null," + + " \"parts\":1" + + "}" + + "]" + + "}" + ); + VMSGet action = new VMSGet("0f0f0f0f0f0f0f0f0f0f0f0f"); + action.client(new ClientStub()); + action.proxy(requestStub); + + action.execute(); + + assertEquals("POST", requestStub.requestMethod); + assertEquals("vms.do", requestStub.requestEndpoint); + HashMap expectedRequestPayload = new HashMap<>(); + expectedRequestPayload.put("status", "0f0f0f0f0f0f0f0f0f0f0f0f"); + expectedRequestPayload.put("format", "json"); + assertEquals(expectedRequestPayload, requestStub.requestPayload); + } + + @Test + public void executeGetMultipleVmsRequest() throws SmsapiException { + ProxyRequestSpy requestStub = new ProxyRequestSpy( + "{" + + "\"count\":1," + + "\"list\":[" + + "{" + + " \"id\":\"0f0f0f0f0f0f0f0f0f0f0f0f\"," + + " \"points\":0.21," + + " \"number\":\"00000000000\"," + + " \"date_sent\":1717500698," + + " \"submitted_number\":\"000000\"," + + " \"status\":\"QUEUE\"," + + " \"error\":null," + + " \"idx\":null," + + " \"parts\":1" + + "}" + + "]" + + "}" + ); + VMSGet action = new VMSGet(new String[]{"0f0f0f0f0f0f0f0f0f0f0f0f", "0f0f0f0f0f0f0f0f0f0f0f01"}); + action.client(new ClientStub()); + action.proxy(requestStub); + + action.execute(); + + assertEquals("POST", requestStub.requestMethod); + assertEquals("vms.do", requestStub.requestEndpoint); + HashMap expectedRequestPayload = new HashMap<>(); + expectedRequestPayload.put("status", "0f0f0f0f0f0f0f0f0f0f0f0f|0f0f0f0f0f0f0f0f0f0f0f01"); + expectedRequestPayload.put("format", "json"); + assertEquals(expectedRequestPayload, requestStub.requestPayload); + } +} From cb5c79b652cfb31279edcb108030221bbb0de974 Mon Sep 17 00:00:00 2001 From: Maciej Lew Date: Tue, 4 Jun 2024 15:11:14 +0200 Subject: [PATCH 09/12] Deprecates VMS get without parameters action --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index be28b68..8ef2014 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a - `pl.smsapi.api.VmsFactory.actionGet` without parameters marked as deprecated - `pl.smsapi.api.VmsFactory.actionDelete` without parameters marked as deprecated - `pl.smsapi.api.action.vms.VMSDelete` without parameters marked as deprecated +- `pl.smsapi.api.action.vms.VMSGet` without parameters marked as deprecated ### Removed - legacy `phonebook.do` contacts API support From 0a2f918ab95be7e4edbe24312c67e6daa66065f1 Mon Sep 17 00:00:00 2001 From: Maciej Lew Date: Tue, 4 Jun 2024 16:10:39 +0200 Subject: [PATCH 10/12] Deprecates VMS send without parameters action --- CHANGELOG.md | 1 + src/main/java/pl/smsapi/api/VmsFactory.java | 30 ++++++------ .../pl/smsapi/api/action/vms/VMSSend.java | 49 +++++++++++++++++-- .../api/action/vms/StatusJsonMother.java | 24 +++++++++ .../pl/smsapi/api/action/vms/VMSGetTest.java | 38 +------------- .../pl/smsapi/api/action/vms/VMSSendTest.java | 49 +++++++++++++++++++ .../smsapi/api/action/vms/VmsFactoryTest.java | 4 +- 7 files changed, 138 insertions(+), 57 deletions(-) create mode 100644 src/test/java/pl/smsapi/api/action/vms/StatusJsonMother.java create mode 100644 src/test/java/pl/smsapi/api/action/vms/VMSSendTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ef2014..0fcad17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a - `pl.smsapi.api.VmsFactory.actionDelete` without parameters marked as deprecated - `pl.smsapi.api.action.vms.VMSDelete` without parameters marked as deprecated - `pl.smsapi.api.action.vms.VMSGet` without parameters marked as deprecated +- `pl.smsapi.api.action.vms.VMSSend` without parameters marked as deprecated ### Removed - legacy `phonebook.do` contacts API support diff --git a/src/main/java/pl/smsapi/api/VmsFactory.java b/src/main/java/pl/smsapi/api/VmsFactory.java index 505ddfc..4d0cf19 100644 --- a/src/main/java/pl/smsapi/api/VmsFactory.java +++ b/src/main/java/pl/smsapi/api/VmsFactory.java @@ -7,7 +7,7 @@ import pl.smsapi.proxy.Proxy; import java.io.File; -import java.io.FileNotFoundException; +import java.io.IOException; public class VmsFactory extends ActionFactory { @@ -35,33 +35,33 @@ public VMSSend actionSend() { } public VMSSend actionSend(String to, String tts) { - VMSSend action = actionSend(); - action.setTo(to); - action.setTts(tts); + VMSSend action = new VMSSend(to, tts); + action.client(client); + action.proxy(proxy); return action; } public VMSSend actionSend(String[] to, String tts) { - VMSSend action = actionSend(); - action.setTo(to); - action.setTts(tts); + VMSSend action = new VMSSend(to, tts); + action.client(client); + action.proxy(proxy); return action; } - public VMSSend actionSend(String to, File file) throws FileNotFoundException { - VMSSend action = actionSend(); - action.setTo(to); - action.setFile(file); + public VMSSend actionSend(String to, File file) throws IOException { + VMSSend action = new VMSSend(to, file); + action.client(client); + action.proxy(proxy); return action; } - public VMSSend actionSend(String[] to, File file) throws FileNotFoundException { - VMSSend action = actionSend(); - action.setTo(to); - action.setFile(file); + public VMSSend actionSend(String[] to, File file) throws IOException { + VMSSend action = new VMSSend(to, file); + action.client(client); + action.proxy(proxy); return action; } diff --git a/src/main/java/pl/smsapi/api/action/vms/VMSSend.java b/src/main/java/pl/smsapi/api/action/vms/VMSSend.java index c7a15bc..27853c2 100644 --- a/src/main/java/pl/smsapi/api/action/vms/VMSSend.java +++ b/src/main/java/pl/smsapi/api/action/vms/VMSSend.java @@ -4,10 +4,8 @@ import pl.smsapi.api.action.AbstractSendAction; import pl.smsapi.api.response.StatusResponse; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.InputStream; +import java.io.*; +import java.nio.file.Files; public class VMSSend extends AbstractSendAction { @@ -24,12 +22,49 @@ public String toString() { } } + /** + * @deprecated use {@link VMSSend(String, String)} or {@link VMSSend(String[], String)} or {@link VMSSend(String, File)} + * or {@link VMSSend(String[], File)} instead + */ public VMSSend() { setJson(true); } + public VMSSend(String to, String tts) { + setJson(true); + setTo(to); + params.put("tts", tts); + } + + public VMSSend(String[] to, String tts) { + setJson(true); + setTo(to); + params.put("tts", tts); + } + + public VMSSend(String to, File file) throws IOException { + setJson(true); + setTo(to); + files.put("file", Files.newInputStream(file.toPath())); + } + + public VMSSend(String[] to, File file) throws IOException { + setJson(true); + setTo(to); + files.put("file", Files.newInputStream(file.toPath())); + } + + public VMSSend(String[] to, InputStream file) { + setJson(true); + setTo(to); + files.put("file", file); + } + /** * Set local audio file. + * + * @deprecated use {@link VMSSend(String, File)} or {@link VMSSend(String[], File)} instead + * */ public VMSSend setFile(File file) throws FileNotFoundException { files.put("file", new FileInputStream(file)); @@ -38,6 +73,8 @@ public VMSSend setFile(File file) throws FileNotFoundException { /** * Set local audio filename. + * + * @deprecated use {@link VMSSend(String, File)} or {@link VMSSend(String[], File)} instead */ public VMSSend setFile(String pathFile) throws FileNotFoundException { files.put("file", new FileInputStream(pathFile)); @@ -46,6 +83,8 @@ public VMSSend setFile(String pathFile) throws FileNotFoundException { /** * Set local audio stream. + * + * @deprecated use {@link VMSSend(String[], InputStream)} instead */ public VMSSend setFile(InputStream inputStream) { files.put("file", inputStream); @@ -54,6 +93,8 @@ public VMSSend setFile(InputStream inputStream) { /** * Set text to voice synthesizer. + * + * @deprecated use {@link VMSSend(String, String)} or {@link VMSSend(String[], String)} instead */ public VMSSend setTts(String tts) { params.put("tts", tts); diff --git a/src/test/java/pl/smsapi/api/action/vms/StatusJsonMother.java b/src/test/java/pl/smsapi/api/action/vms/StatusJsonMother.java new file mode 100644 index 0000000..13e2fa8 --- /dev/null +++ b/src/test/java/pl/smsapi/api/action/vms/StatusJsonMother.java @@ -0,0 +1,24 @@ +package pl.smsapi.api.action.vms; + +public class StatusJsonMother { + + public static String create() { + return + "{" + + " \"count\":1," + + " \"list\":[" + + " {" + + " \"id\":\"0f0f0f0f0f0f0f0f0f0f0f0f\"," + + " \"points\":0.21," + + " \"number\":\"48123123123\"," + + " \"date_sent\":1717500698," + + " \"submitted_number\":\"123123123\"," + + " \"status\":\"QUEUE\"," + + " \"error\":null," + + " \"idx\":null," + + " \"parts\":1" + + " }" + + " ]" + + "}"; + } +} diff --git a/src/test/java/pl/smsapi/api/action/vms/VMSGetTest.java b/src/test/java/pl/smsapi/api/action/vms/VMSGetTest.java index 127f2f8..f55d30e 100644 --- a/src/test/java/pl/smsapi/api/action/vms/VMSGetTest.java +++ b/src/test/java/pl/smsapi/api/action/vms/VMSGetTest.java @@ -13,24 +13,7 @@ public class VMSGetTest { @Test public void executeGetVmsRequest() throws SmsapiException { - ProxyRequestSpy requestStub = new ProxyRequestSpy( - "{" + - "\"count\":1," + - "\"list\":[" + - "{" + - " \"id\":\"0f0f0f0f0f0f0f0f0f0f0f0f\"," + - " \"points\":0.21," + - " \"number\":\"00000000000\"," + - " \"date_sent\":1717500698," + - " \"submitted_number\":\"000000\"," + - " \"status\":\"QUEUE\"," + - " \"error\":null," + - " \"idx\":null," + - " \"parts\":1" + - "}" + - "]" + - "}" - ); + ProxyRequestSpy requestStub = new ProxyRequestSpy(StatusJsonMother.create()); VMSGet action = new VMSGet("0f0f0f0f0f0f0f0f0f0f0f0f"); action.client(new ClientStub()); action.proxy(requestStub); @@ -47,24 +30,7 @@ public void executeGetVmsRequest() throws SmsapiException { @Test public void executeGetMultipleVmsRequest() throws SmsapiException { - ProxyRequestSpy requestStub = new ProxyRequestSpy( - "{" + - "\"count\":1," + - "\"list\":[" + - "{" + - " \"id\":\"0f0f0f0f0f0f0f0f0f0f0f0f\"," + - " \"points\":0.21," + - " \"number\":\"00000000000\"," + - " \"date_sent\":1717500698," + - " \"submitted_number\":\"000000\"," + - " \"status\":\"QUEUE\"," + - " \"error\":null," + - " \"idx\":null," + - " \"parts\":1" + - "}" + - "]" + - "}" - ); + ProxyRequestSpy requestStub = new ProxyRequestSpy(StatusJsonMother.create()); VMSGet action = new VMSGet(new String[]{"0f0f0f0f0f0f0f0f0f0f0f0f", "0f0f0f0f0f0f0f0f0f0f0f01"}); action.client(new ClientStub()); action.proxy(requestStub); diff --git a/src/test/java/pl/smsapi/api/action/vms/VMSSendTest.java b/src/test/java/pl/smsapi/api/action/vms/VMSSendTest.java new file mode 100644 index 0000000..8ffd8b7 --- /dev/null +++ b/src/test/java/pl/smsapi/api/action/vms/VMSSendTest.java @@ -0,0 +1,49 @@ +package pl.smsapi.api.action.vms; + +import org.junit.Test; +import pl.smsapi.exception.SmsapiException; +import pl.smsapi.test.doubles.ClientStub; +import pl.smsapi.test.doubles.ProxyRequestSpy; + +import java.util.HashMap; + +import static org.junit.Assert.assertEquals; + +public class VMSSendTest { + + @Test + public void executeSendVmsFromTTSRequest() throws SmsapiException { + ProxyRequestSpy requestStub = new ProxyRequestSpy(StatusJsonMother.create()); + VMSSend action = new VMSSend("48123123123", "text to speech"); + action.client(new ClientStub()); + action.proxy(requestStub); + + action.execute(); + + assertEquals("POST", requestStub.requestMethod); + assertEquals("vms.do", requestStub.requestEndpoint); + HashMap expectedRequestPayload = new HashMap<>(); + expectedRequestPayload.put("tts", "text to speech"); + expectedRequestPayload.put("to", "48123123123"); + expectedRequestPayload.put("format", "json"); + assertEquals(expectedRequestPayload, requestStub.requestPayload); + } + + @Test + public void executeSendMultipleVmsFromTTSRequest() throws SmsapiException { + ProxyRequestSpy requestStub = new ProxyRequestSpy(StatusJsonMother.create()); + VMSSend action = new VMSSend(new String[]{"48123123123", "48123123124"}, "text to speech"); + action.client(new ClientStub()); + action.proxy(requestStub); + + action.execute(); + + assertEquals("POST", requestStub.requestMethod); + assertEquals("vms.do", requestStub.requestEndpoint); + HashMap expectedRequestPayload = new HashMap<>(); + expectedRequestPayload.put("tts", "text to speech"); + expectedRequestPayload.put("to", "48123123123,48123123124"); + expectedRequestPayload.put("format", "json"); + assertEquals(expectedRequestPayload, requestStub.requestPayload); + } +} diff --git a/src/test/java/pl/smsapi/api/action/vms/VmsFactoryTest.java b/src/test/java/pl/smsapi/api/action/vms/VmsFactoryTest.java index 5fb9885..114e75f 100644 --- a/src/test/java/pl/smsapi/api/action/vms/VmsFactoryTest.java +++ b/src/test/java/pl/smsapi/api/action/vms/VmsFactoryTest.java @@ -12,7 +12,7 @@ import pl.smsapi.test.TestSmsapi; import java.io.File; -import java.io.FileNotFoundException; +import java.io.IOException; import java.util.Date; import java.util.Optional; @@ -42,7 +42,7 @@ public void sendVmsWithTts() throws SmsapiException { } @Test - public void sendVmsWithFile() throws FileNotFoundException, SmsapiException { + public void sendVmsWithFile() throws IOException, SmsapiException { VMSSend action = apiFactory.actionSend(numberTest, new File("src/test/java/pl/smsapi/test/voice_small.wav")); StatusResponse responseAdd = action.execute(); From f86d08ae16e04a4b43380678ceb7513324d0a15a Mon Sep 17 00:00:00 2001 From: Maciej Lew Date: Tue, 4 Jun 2024 16:38:36 +0200 Subject: [PATCH 11/12] Adds VMS send with optional parameters action test --- .../pl/smsapi/api/action/vms/VMSSendTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/test/java/pl/smsapi/api/action/vms/VMSSendTest.java b/src/test/java/pl/smsapi/api/action/vms/VMSSendTest.java index 8ffd8b7..edb1e0d 100644 --- a/src/test/java/pl/smsapi/api/action/vms/VMSSendTest.java +++ b/src/test/java/pl/smsapi/api/action/vms/VMSSendTest.java @@ -46,4 +46,32 @@ public void executeSendMultipleVmsFromTTSRequest() throws SmsapiException { expectedRequestPayload.put("format", "json"); assertEquals(expectedRequestPayload, requestStub.requestPayload); } + + @Test + public void executeSendVmsWithOptionalFieldsRequest() throws SmsapiException { + ProxyRequestSpy requestStub = new ProxyRequestSpy(StatusJsonMother.create()); + VMSSend action = new VMSSend("48123123123", "text to speech") + .setSkipGsm(true) + .setTtsLector(VMSSend.Lector.EWA) + .setInterval(1000) + .setFrom("test"); + + action.client(new ClientStub()); + action.proxy(requestStub); + + action.execute(); + + assertEquals("POST", requestStub.requestMethod); + assertEquals("vms.do", requestStub.requestEndpoint); + HashMap expectedRequestPayload = new HashMap<>(); + expectedRequestPayload.put("tts", "text to speech"); + expectedRequestPayload.put("to", "48123123123"); + expectedRequestPayload.put("format", "json"); + expectedRequestPayload.put("skip_gsm", "1"); + expectedRequestPayload.put("tts_lector", "ewa"); + expectedRequestPayload.put("interval", "1000"); + expectedRequestPayload.put("from", "test"); + + assertEquals(expectedRequestPayload, requestStub.requestPayload); + } } From dcac3a1e5c5e29f1ef867984fd0e9705c430d0ef Mon Sep 17 00:00:00 2001 From: Maciej Lew Date: Tue, 4 Jun 2024 16:40:54 +0200 Subject: [PATCH 12/12] Removes AGNIESZKA TTS VMS action lector --- src/main/java/pl/smsapi/api/action/vms/VMSSend.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/pl/smsapi/api/action/vms/VMSSend.java b/src/main/java/pl/smsapi/api/action/vms/VMSSend.java index 27853c2..7c6b8f7 100644 --- a/src/main/java/pl/smsapi/api/action/vms/VMSSend.java +++ b/src/main/java/pl/smsapi/api/action/vms/VMSSend.java @@ -9,8 +9,7 @@ public class VMSSend extends AbstractSendAction { - public static enum Lector { - AGNIESZKA, + public enum Lector { EWA, JACEK, JAN,