Search in sources :

Example 36 with SMSCommand

use of org.hisp.dhis.sms.command.SMSCommand in project dhis2-core by dhis2.

the class SMSCommandServiceTest method createEventRegistrationParserCommand.

private void createEventRegistrationParserCommand() {
    dataElementD = createDataElement('D');
    dataElementService.addDataElement(dataElementD);
    programD = createProgram('D');
    programService.addProgram(programD);
    programStageD = createProgramStage('S', programD);
    programStageService.saveProgramStage(programStageD);
    eventRegistrationCommand = new SMSCommand();
    eventRegistrationCommand.setName(eventRegistrationCommandName);
    eventRegistrationCommand.setProgram(programD);
    eventRegistrationCommand.setProgramStage(programStageD);
    smsCodeEvent = new SMSCode();
    smsCodeEvent.setCode("E");
    smsCodeEvent.setDataElement(dataElementD);
    eventRegistrationCommand.setCodes(Sets.newHashSet(smsCodeEvent));
}
Also used : SMSCommand(org.hisp.dhis.sms.command.SMSCommand) SMSCode(org.hisp.dhis.sms.command.code.SMSCode)

Example 37 with SMSCommand

use of org.hisp.dhis.sms.command.SMSCommand in project dhis2-core by dhis2.

the class SMSCommandServiceTest method createAlertParserCommand.

private void createAlertParserCommand() {
    alertParserCommand = new SMSCommand();
    alertParserCommand.setName(alertMessageCommandName);
    alertParserCommand.setParserType(ParserType.ALERT_PARSER);
    alertParserCommand.setSuccessMessage(success);
    alertParserCommand.setWrongFormatMessage(wrongFormat);
    defaultMessagesB.put(SUCCESS_MESSAGE, success);
    defaultMessagesB.put(WRONG_FORMAT_MESSAGE, wrongFormat);
}
Also used : SMSCommand(org.hisp.dhis.sms.command.SMSCommand)

Example 38 with SMSCommand

use of org.hisp.dhis.sms.command.SMSCommand in project dhis2-core by dhis2.

the class SMSCommandServiceTest method createKeyValueCommands.

// -------------------------------------------------------------------------
// Supportive Methods
// -------------------------------------------------------------------------
private void createKeyValueCommands() {
    dataElementA = createDataElement('A');
    dataElementB = createDataElement('B');
    dataElementC = createDataElement('C');
    dataElementService.addDataElement(dataElementA);
    dataElementService.addDataElement(dataElementB);
    dataElementService.addDataElement(dataElementC);
    dataSetA = createDataSet('A');
    dataSetA.addDataSetElement(dataElementA);
    dataSetA.addDataSetElement(dataElementB);
    dataSetService.addDataSet(dataSetA);
    smsCodeA1 = new SMSCode();
    smsCodeA1.setCode("a1");
    smsCodeA1.setDataElement(dataElementA);
    smsCodeA2 = new SMSCode();
    smsCodeA2.setCode("a2");
    smsCodeA2.setDataElement(dataElementB);
    smsCodeB1 = new SMSCode();
    smsCodeB1.setCode("b1");
    smsCodeB1.setDataElement(dataElementA);
    smsCodeB2 = new SMSCode();
    smsCodeB2.setCode("b2");
    smsCodeB2.setDataElement(dataElementB);
    smsCodeC = new SMSCode();
    smsCodeC.setCode("c");
    smsCodeC.setDataElement(dataElementC);
    characterA = new SMSSpecialCharacter();
    characterA.setName("charA");
    characterA.setValue("vCharA");
    characterB = new SMSSpecialCharacter();
    characterB.setName("charB");
    characterB.setValue("vCharB");
    keyValueCommandA = new SMSCommand();
    keyValueCommandA.setName(keyValueCommandName);
    keyValueCommandA.setParserType(ParserType.KEY_VALUE_PARSER);
    keyValueCommandA.setDataset(dataSetA);
    keyValueCommandA.setCodes(Sets.newHashSet(smsCodeA1, smsCodeA2));
    keyValueCommandA.setSpecialCharacters(Sets.newHashSet(characterA));
    keyValueCommandA.setSuccessMessage(success);
    defaultMessagesA.put(SUCCESS_MESSAGE, success);
    keyValueCommandB = new SMSCommand();
    keyValueCommandB.setName(keyValueCommandNameB);
    keyValueCommandB.setParserType(ParserType.KEY_VALUE_PARSER);
    keyValueCommandB.setDataset(dataSetA);
    keyValueCommandB.setCodes(Sets.newHashSet(smsCodeB1, smsCodeB2));
}
Also used : SMSCommand(org.hisp.dhis.sms.command.SMSCommand) SMSCode(org.hisp.dhis.sms.command.code.SMSCode) SMSSpecialCharacter(org.hisp.dhis.sms.command.SMSSpecialCharacter)

Example 39 with SMSCommand

use of org.hisp.dhis.sms.command.SMSCommand in project dhis2-core by dhis2.

the class SmsUtilsTest method testSelectOrganisationUnit.

@Test
void testSelectOrganisationUnit() {
    OrganisationUnit expected = organisationUnitA;
    Map<String, String> parsedMessage = Maps.newHashMap(ImmutableMap.of("ORG", "TESTORGA"));
    SMSCommand smsCommand = new SMSCommand();
    assertEquals(expected, SmsUtils.selectOrganisationUnit(Lists.newArrayList(organisationUnitA), parsedMessage, smsCommand));
    assertThrows(SMSParserException.class, () -> SmsUtils.selectOrganisationUnit(Lists.newArrayList(organisationUnitB, organisationUnitC), parsedMessage, smsCommand));
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) SMSCommand(org.hisp.dhis.sms.command.SMSCommand) Test(org.junit.jupiter.api.Test)

Example 40 with SMSCommand

use of org.hisp.dhis.sms.command.SMSCommand in project dhis2-core by dhis2.

the class SmsUtilsTest method testGetUser.

@Test
void testGetUser() {
    User returnedUser = SmsUtils.getUser("", new SMSCommand(), Lists.newArrayList(userA));
    assertEquals(userA, returnedUser);
    assertThrows(SMSParserException.class, () -> SmsUtils.getUser("", new SMSCommand(), Lists.newArrayList(userA, userB)));
}
Also used : User(org.hisp.dhis.user.User) SMSCommand(org.hisp.dhis.sms.command.SMSCommand) Test(org.junit.jupiter.api.Test)

Aggregations

SMSCommand (org.hisp.dhis.sms.command.SMSCommand)41 Test (org.junit.jupiter.api.Test)17 DhisSpringTest (org.hisp.dhis.DhisSpringTest)14 SMSCode (org.hisp.dhis.sms.command.code.SMSCode)14 User (org.hisp.dhis.user.User)9 Transactional (org.springframework.transaction.annotation.Transactional)8 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)7 SMSParserException (org.hisp.dhis.sms.parse.SMSParserException)7 SMSSpecialCharacter (org.hisp.dhis.sms.command.SMSSpecialCharacter)6 UserGroup (org.hisp.dhis.user.UserGroup)6 List (java.util.List)5 Set (java.util.Set)5 DataSet (org.hisp.dhis.dataset.DataSet)5 Program (org.hisp.dhis.program.Program)5 ParserType (org.hisp.dhis.sms.parse.ParserType)5 HashSet (java.util.HashSet)4 Map (java.util.Map)4 ProgramService (org.hisp.dhis.program.ProgramService)4 SMSCommandService (org.hisp.dhis.sms.command.SMSCommandService)4 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)4