Search in sources :

Example 26 with SMSCommand

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

the class SMSCommandServiceTest method testGetKeyValueParameters.

@Test
void testGetKeyValueParameters() {
    smsCommandService.save(keyValueCommandA);
    SMSCommand created = smsCommandService.getSMSCommand(keyValueCommandName);
    assertNotNull(created);
    assertEquals(keyValueCommandName, created.getName());
    assertEquals(dataSetA, created.getDataset());
    Set<DataElement> dataElements = created.getCodes().stream().map(c -> c.getDataElement()).collect(Collectors.toSet());
    assertTrue(dataElements.contains(dataElementA));
    assertFalse(dataElements.contains(dataElementC));
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) DataElementService(org.hisp.dhis.dataelement.DataElementService) DataSet(org.hisp.dhis.dataset.DataSet) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) Program(org.hisp.dhis.program.Program) CompletenessMethod(org.hisp.dhis.sms.command.CompletenessMethod) TrackedEntityAttributeService(org.hisp.dhis.trackedentity.TrackedEntityAttributeService) DataElement(org.hisp.dhis.dataelement.DataElement) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Map(java.util.Map) User(org.hisp.dhis.user.User) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ParserType(org.hisp.dhis.sms.parse.ParserType) UserService(org.hisp.dhis.user.UserService) Function(com.google.common.base.Function) SMSSpecialCharacter(org.hisp.dhis.sms.command.SMSSpecialCharacter) ImmutableMap(com.google.common.collect.ImmutableMap) UserGroup(org.hisp.dhis.user.UserGroup) Set(java.util.Set) ProgramStageService(org.hisp.dhis.program.ProgramStageService) Collectors(java.util.stream.Collectors) ProgramStage(org.hisp.dhis.program.ProgramStage) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) List(java.util.List) DhisSpringTest(org.hisp.dhis.DhisSpringTest) SMSCommandService(org.hisp.dhis.sms.command.SMSCommandService) UserGroupService(org.hisp.dhis.user.UserGroupService) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SMSCode(org.hisp.dhis.sms.command.code.SMSCode) DataSetService(org.hisp.dhis.dataset.DataSetService) ProgramService(org.hisp.dhis.program.ProgramService) SMSCommand(org.hisp.dhis.sms.command.SMSCommand) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) DataElement(org.hisp.dhis.dataelement.DataElement) SMSCommand(org.hisp.dhis.sms.command.SMSCommand) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 27 with SMSCommand

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

the class SMSCommandServiceTest method testDeleteSmsCodes.

@Test
void testDeleteSmsCodes() {
    smsCommandService.save(keyValueCommandA);
    SMSCommand commandA = smsCommandService.getSMSCommand(keyValueCommandName);
    assertEquals(2, commandA.getCodes().size());
    smsCommandService.deleteCodeSet(Sets.newHashSet(smsCodeA1), commandA.getId());
    SMSCommand updatedCommand = smsCommandService.getSMSCommand(keyValueCommandName);
    assertEquals(1, updatedCommand.getCodes().size());
    assertEquals(smsCodeA2, updatedCommand.getCodes().iterator().next());
}
Also used : SMSCommand(org.hisp.dhis.sms.command.SMSCommand) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 28 with SMSCommand

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

the class SMSCommandServiceTest method testDeleteSpecialCharacters.

@Test
void testDeleteSpecialCharacters() {
    smsCommandService.save(keyValueCommandA);
    SMSCommand createdCommand = smsCommandService.getSMSCommand(keyValueCommandName);
    assertEquals(1, createdCommand.getSpecialCharacters().size());
    smsCommandService.deleteSpecialCharacterSet(Sets.newHashSet(characterA), createdCommand.getId());
    SMSCommand updatedCommand = smsCommandService.getSMSCommand(keyValueCommandName);
    assertEquals(0, updatedCommand.getSpecialCharacters().size());
}
Also used : SMSCommand(org.hisp.dhis.sms.command.SMSCommand) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 29 with SMSCommand

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

the class SMSCommandServiceTest method testSaveTeiRegistrationParser.

@Test
void testSaveTeiRegistrationParser() {
    smsCommandService.save(teiRegistrationCommand);
    SMSCommand teiCommand = smsCommandService.getSMSCommand(teiCommandName);
    assertEquals(teiCommandName, teiCommand.getName());
    assertEquals(ParserType.TRACKED_ENTITY_REGISTRATION_PARSER, teiCommand.getParserType());
    assertEquals(programA, teiCommand.getProgram());
    testDefaults(teiCommand, defaultMessagesC);
    Set<TrackedEntityAttribute> teiAttributes = teiCommand.getCodes().stream().map(c -> c.getTrackedEntityAttribute()).collect(Collectors.toSet());
    assertTrue(teiAttributes.contains(trackedEntityAttributeA));
    assertTrue(teiAttributes.contains(trackedEntityAttributeB));
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) DataElementService(org.hisp.dhis.dataelement.DataElementService) DataSet(org.hisp.dhis.dataset.DataSet) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) Program(org.hisp.dhis.program.Program) CompletenessMethod(org.hisp.dhis.sms.command.CompletenessMethod) TrackedEntityAttributeService(org.hisp.dhis.trackedentity.TrackedEntityAttributeService) DataElement(org.hisp.dhis.dataelement.DataElement) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Map(java.util.Map) User(org.hisp.dhis.user.User) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ParserType(org.hisp.dhis.sms.parse.ParserType) UserService(org.hisp.dhis.user.UserService) Function(com.google.common.base.Function) SMSSpecialCharacter(org.hisp.dhis.sms.command.SMSSpecialCharacter) ImmutableMap(com.google.common.collect.ImmutableMap) UserGroup(org.hisp.dhis.user.UserGroup) Set(java.util.Set) ProgramStageService(org.hisp.dhis.program.ProgramStageService) Collectors(java.util.stream.Collectors) ProgramStage(org.hisp.dhis.program.ProgramStage) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) List(java.util.List) DhisSpringTest(org.hisp.dhis.DhisSpringTest) SMSCommandService(org.hisp.dhis.sms.command.SMSCommandService) UserGroupService(org.hisp.dhis.user.UserGroupService) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SMSCode(org.hisp.dhis.sms.command.code.SMSCode) DataSetService(org.hisp.dhis.dataset.DataSetService) ProgramService(org.hisp.dhis.program.ProgramService) SMSCommand(org.hisp.dhis.sms.command.SMSCommand) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) SMSCommand(org.hisp.dhis.sms.command.SMSCommand) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 30 with SMSCommand

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

the class SMSCommandServiceTest method testAddSpecialCharacters.

@Test
void testAddSpecialCharacters() {
    smsCommandService.save(keyValueCommandA);
    SMSCommand createdCommand = smsCommandService.getSMSCommand(keyValueCommandName);
    assertEquals(1, createdCommand.getSpecialCharacters().size());
    smsCommandService.addSpecialCharacterSet(Sets.newHashSet(characterB), createdCommand.getId());
    SMSCommand updatedCommand = smsCommandService.getSMSCommand(keyValueCommandName);
    assertEquals(2, updatedCommand.getSpecialCharacters().size());
}
Also used : SMSCommand(org.hisp.dhis.sms.command.SMSCommand) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

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