Advertisement
BoberDiversant

Untitled

Dec 23rd, 2019
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.59 KB | None | 0 0
  1. package tech.ivoice.client.solutions.medsi.integration;
  2.  
  3. import com.google.common.collect.ImmutableList;
  4. import org.junit.jupiter.api.BeforeEach;
  5. import org.junit.jupiter.api.Test;
  6. import tech.ivoice.client.solutions.medsi.commons.CommonPlays;
  7. import tech.ivoice.client.solutions.medsi.commons.dto.Dto;
  8. import tech.ivoice.client.solutions.medsi.components.clinic.ClinicSelection;
  9. import tech.ivoice.client.solutions.medsi.components.clinic.ClinicSelectionPlays;
  10. import tech.ivoice.client.solutions.medsi.components.clinic.utils.ClinicFilter;
  11. import tech.ivoice.client.solutions.medsi.components.clinic.utils.data.Clinic;
  12. import tech.ivoice.client.solutions.medsi.components.makeapp.AppDate;
  13. import tech.ivoice.client.solutions.medsi.components.makeapp.AppNearest;
  14. import tech.ivoice.client.solutions.medsi.components.makeapp.AppTime;
  15. import tech.ivoice.client.solutions.medsi.components.makeapp.MakeAppointment;
  16. import tech.ivoice.client.solutions.medsi.components.makeapp.plays.AppDatePlays;
  17. import tech.ivoice.client.solutions.medsi.components.makeapp.plays.AppNearestPlays;
  18. import tech.ivoice.client.solutions.medsi.components.makeapp.plays.AppPlays;
  19. import tech.ivoice.client.solutions.medsi.components.makeapp.plays.AppTimePlays;
  20. import tech.ivoice.client.solutions.medsi.components.patient.PatientComponent;
  21. import tech.ivoice.client.solutions.medsi.components.patient.PatientPlays;
  22. import tech.ivoice.client.solutions.medsi.components.specialty.SpecialtyPlays;
  23. import tech.ivoice.client.solutions.medsi.components.specialty.SpecialtySelection;
  24. import tech.ivoice.client.solutions.medsi.components.specialty.utils.SpecListCreator;
  25. import tech.ivoice.client.solutions.medsi.components.specialty.utils.SpecSearcher;
  26. import tech.ivoice.client.solutions.medsi.components.specialty.utils.Specialty;
  27. import tech.ivoice.platform.fsm.test.StateLoggedFsm;
  28. import tech.ivoice.platform.sdk.messages.Log;
  29. import tech.ivoice.platform.sdk.messages.Result;
  30. import tech.ivoice.platform.sdk.messages.SolutionMessage;
  31. import tech.ivoice.platform.sdk.messages.session.PlayCollectSpeech;
  32.  
  33. import java.util.ArrayDeque;
  34. import java.util.List;
  35.  
  36. import static org.junit.jupiter.api.Assertions.assertEquals;
  37. import static tech.ivoice.platform.extension.sdk.fsm_support.Tools.link;
  38. import static tech.ivoice.platform.sdk.messages.session.PlayCollectSpeech.Result.fullSpeech;
  39.  
  40. public class Integration_1_Test {
  41.  
  42.     private PatientComponent patientComponent;
  43.     private SpecialtySelection specialtyComponent;
  44.     private ClinicSelection clinicComponent;
  45.     private AppNearest appNearest;
  46.     private AppDate appDate;
  47.     private AppTime appTime;
  48.     private MakeAppointment makeAppointment;
  49.  
  50.     private CommonPlays commonPlays;
  51.     private PatientPlays patientPlays;
  52.     private SpecialtyPlays specialtyPlays;
  53.     private ClinicSelectionPlays clinicPlays;
  54.     private AppNearestPlays appNearestPlays;
  55.     private AppDatePlays appDatePlays;
  56.     private AppTimePlays appTimePlays;
  57.     private AppPlays makeAppPlays;
  58.  
  59.     private StateLoggedFsm fsm;
  60.     private ArrayDeque<SolutionMessage> platform;
  61.  
  62.     private void platform(SolutionMessage message) {
  63.         if (message instanceof Log)
  64.             return;
  65.         platform.addLast(message);
  66.     }
  67.  
  68.     @BeforeEach
  69.     void setUp() {
  70.         this.fsm = new StateLoggedFsm();
  71.         this.platform = new ArrayDeque<>();
  72.         this.patientComponent = new PatientComponent(this::platform);
  73.         this.specialtyComponent = new SpecialtySelection(this::platform);
  74.         this.clinicComponent = new ClinicSelection(this::platform);
  75.         this.appNearest = new AppNearest(this::platform);
  76.         this.appDate = new AppDate(this::platform);
  77.         this.appTime = new AppTime(this::platform);
  78.         this.makeAppointment = new MakeAppointment(this::platform);
  79.  
  80.         this.commonPlays = new CommonPlays();
  81.         this.patientPlays = new PatientPlays();
  82.         this.specialtyPlays = new SpecialtyPlays();
  83.         this.clinicPlays = new ClinicSelectionPlays();
  84.         this.appNearestPlays = new AppNearestPlays();
  85.         this.appDatePlays = new AppDatePlays();
  86.         this.appTimePlays = new AppTimePlays();
  87.         this.makeAppPlays = new AppPlays();
  88.  
  89.         link(patientComponent.bridgeSpecialtyComponent, specialtyComponent.entry);
  90.         link(specialtyComponent.toClinicSelection, clinicComponent.entry);
  91.         link(clinicComponent.bridgeAppNearest, appNearest.entry);
  92.         link(appNearest.bridgeMakeApp, makeAppointment.entry);
  93.         link(appNearest.bridgeAppDate, appDate.entry);
  94.         link(appDate.bridgeMakeApp, makeAppointment.entry);
  95.         link(appDate.bridgeAppTime, appTime.entry);
  96.         link(appTime.bridgeMakeApp, makeAppointment.entry);
  97.  
  98.         Dto dto = new Dto();
  99.         dto.setPhone("79133841262");
  100.         fsm.start(patientComponent.entry, dto);
  101.     }
  102.  
  103.     /**
  104.      * 1. "Запись"
  105.      * 2. "Взрослый"
  106.      * 3.  Пациент - любой  из списка выше или любой реальный
  107.      * 4. "Невролог"
  108.      * 5. "Красногорск"
  109.      * 6. Ближайшее время для записи 24.12.2019 в...
  110.      * 7. Подтверждение времени и даты записи- "НЕТ - 25.12.2019"
  111.      * 8. Есть окно в ..., удобно - "ДА"
  112.      * Запись в МИС, резюмирование
  113.      */
  114.     @Test
  115. //    @SuppressWarnings("ConstantConditions")
  116.     void test_sc1() {
  117.  
  118.         PlayCollectSpeech askAgeGrp = pollPCS();
  119.         assertEquals(patientPlays.askAgeGroup().getPlaySource(), askAgeGrp.getPlaySource());
  120.         answer(askAgeGrp, "взрослый");
  121.  
  122.         PlayCollectSpeech askName = pollPCS();
  123.         assertEquals(patientPlays.askFullName().getPlaySource(), askName.getPlaySource());
  124.         Result resultAgeGrp = pollResult();
  125.         assertEquals("взрослый", resultAgeGrp.getValue());
  126.         answer(askName, "Иванов Иван Иванович");
  127.  
  128.         PlayCollectSpeech askBd = pollPCS();
  129.         assertEquals(patientPlays.askBirthDate().getPlaySource(), askBd.getPlaySource());
  130.         Result name = pollResult();
  131.         assertEquals("Иванов Иван Иванович", name.getValue());
  132.         answer(askBd, "12 июля 2001");
  133.  
  134.  
  135.  
  136.         System.out.println(platform.toString());
  137.  
  138.  
  139.     }
  140.  
  141.     @Test
  142.     void spec() {
  143.         List<Specialty> allSpecialties =SpecListCreator.getSpecialtiesBasedOnAgeGroup("1");
  144.         List<Specialty> foundSpecialties = SpecSearcher.findSpecialty("хирург", allSpecialties);
  145.         List<Clinic> clinics = ClinicFilter.filterClinicsBySelectedSpecialty(foundSpecialties);
  146.         System.out.println();
  147.     }
  148.  
  149.     @Test
  150.     void test_sc2() {
  151.  
  152.         PlayCollectSpeech askAgeGrp = pollPCS();
  153.         assertEquals(patientPlays.askAgeGroup().getPlaySource(), askAgeGrp.getPlaySource());
  154.         answer(askAgeGrp, "взрослый");
  155.  
  156.         PlayCollectSpeech askName = pollPCS();
  157.         processQuestion(patientPlays.askFullName(), askName,
  158.                 "взрослый", "Ростовский Денис Андреевич");
  159.  
  160.         PlayCollectSpeech askBd = pollPCS();
  161.         processQuestion(patientPlays.askBirthDate(), askBd,
  162.                 "Ростовский Денис Андреевич", "20 апреля 1987");
  163.  
  164.         PlayCollectSpeech askSpecialty = pollPCS();
  165.         processQuestion(specialtyPlays.askSpecialty(), askSpecialty,
  166.                 "20 апреля 1987", "Хирург");
  167.  
  168.         PlayCollectSpeech askClinic = pollPCS();
  169.         processQuestion(clinicPlays.askClinic(), askClinic,
  170.                 "Хирург", "Солянка");
  171.  
  172.  
  173.  
  174.  
  175.         System.out.println(platform.size());
  176.         System.out.println(platform.toString());
  177.  
  178.  
  179.     }
  180.  
  181.     private void processQuestion(PlayCollectSpeech expectedAsk, PlayCollectSpeech actualAsk,
  182.                                  String expectedResultOnPreviousQuestion, String answerOnActualAsk) {
  183.         assertEquals(expectedAsk.getPlaySource(), actualAsk.getPlaySource());
  184.         Result result = pollResult();
  185.         assertEquals(expectedResultOnPreviousQuestion, result.getValue());
  186.         answer(actualAsk, answerOnActualAsk);
  187.     }
  188.  
  189.     private void answer(PlayCollectSpeech ask, String answer) {
  190.         this.fsm.process(fullSpeech(ask.getSession(), ImmutableList.of(new PlayCollectSpeech.Speech.Entry(answer, 1))));
  191.         this.fsm.process(ask.getSession().stop());
  192.     }
  193.  
  194.     private PlayCollectSpeech pollPCS() {
  195.         return (PlayCollectSpeech) platform.pollLast();
  196.     }
  197.  
  198.     private Result pollResult() {
  199.         return (Result) platform.pollLast();
  200.     }
  201.  
  202. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement