src_fm_fc_ms_ff stringlengths 43 86.8k | target stringlengths 20 276k |
|---|---|
ACLFileParser { public static AuthorizationsCollector parse(File file) throws ParseException { if (file == null) { LOG.warn("parsing NULL file, so fallback on default configuration!"); return AuthorizationsCollector.emptyImmutableCollector(); } if (!file.exists()) { LOG.warn( String.format( "parsing not existing file %... | @Test public void testParseEmpty() throws ParseException { Reader conf = new StringReader(" "); AuthorizationsCollector authorizations = ACLFileParser.parse(conf); assertTrue(authorizations.isEmpty()); }
@Test public void testParseValidComment() throws ParseException { Reader conf = new StringReader("#simple comment");... |
ConfigurationParser { void parse(File file) throws ParseException { if (file == null) { LOG.warn("parsing NULL file, so fallback on default configuration!"); return; } if (!file.exists()) { LOG.warn( String.format( "parsing not existing file %s, so fallback on default configuration!", file.getAbsolutePath())); return; ... | @Test(expected = ParseException.class) public void parseInvalidComment() throws ParseException { Reader conf = new StringReader(" #simple comment"); m_parser.parse(conf); } |
BrokerInterceptor implements Interceptor { @Override public void notifyClientConnected(final MqttConnectMessage msg) { for (final InterceptHandler handler : this.handlers.get(InterceptConnectMessage.class)) { if(LOG.isDebugEnabled()){ LOG.debug("Sending MQTT CONNECT message to interceptor. CId={}, interceptorId={}", ms... | @Test public void testNotifyClientConnected() throws Exception { interceptor.notifyClientConnected(MqttMessageBuilders.connect().build()); interval(); assertEquals(40, n.get()); } |
BrokerInterceptor implements Interceptor { @Override public void notifyClientDisconnected(final String clientID, final String username) { for (final InterceptHandler handler : this.handlers.get(InterceptDisconnectMessage.class)) { if(LOG.isDebugEnabled()){ LOG.debug("Notifying MQTT client disconnection to interceptor. ... | @Test public void testNotifyClientDisconnected() throws Exception { interceptor.notifyClientDisconnected("cli1234", "cli1234"); interval(); assertEquals(50, n.get()); } |
BrokerInterceptor implements Interceptor { @Override public void notifyTopicPublished(final MoquetteMessage msg, final String clientID, final String username) { int messageId = msg.getMessageId(); String topic = msg.getTopic(); for (final InterceptHandler handler : this.handlers.get(InterceptPublishMessage.class)) { if... | @Test public void testNotifyTopicPublished() throws Exception { MqttPublishMessage msg = MqttMessageBuilders.publish().qos(MqttQoS.AT_MOST_ONCE).payload(Unpooled.copiedBuffer("Hello".getBytes())).build(); MoquetteMessage moquetteMessage = new MoquetteMessage(msg.fixedHeader(), msg.variableHeader(), msg.content()); inte... |
BrokerInterceptor implements Interceptor { @Override public void notifyTopicSubscribed(final Subscription sub, final String username) { for (final InterceptHandler handler : this.handlers.get(InterceptSubscribeMessage.class)) { if(LOG.isDebugEnabled()){ LOG.debug("Notifying MQTT SUBSCRIBE message to interceptor. CId={}... | @Test public void testNotifyTopicSubscribed() throws Exception { interceptor.notifyTopicSubscribed(new Subscription("cli1", new Topic("o2"), MqttQoS.AT_MOST_ONCE), "cli1234"); interval(); assertEquals(70, n.get()); } |
BrokerInterceptor implements Interceptor { @Override public void notifyTopicUnsubscribed(final String topic, final String clientID, final String username) { for (final InterceptHandler handler : this.handlers.get(InterceptUnsubscribeMessage.class)) { if(LOG.isDebugEnabled()){ LOG.debug("Notifying MQTT UNSUBSCRIBE messa... | @Test public void testNotifyTopicUnsubscribed() throws Exception { interceptor.notifyTopicUnsubscribed("o2", "cli1234", "cli1234"); interval(); assertEquals(80, n.get()); } |
MapDBPersistentStore implements IStore { @Override public void close() { if (this.m_db.isClosed()) { LOG.warn("MapDB store is already closed. Nothing will be done"); return; } LOG.info("Performing last commit to MapDB"); this.m_db.commit(); LOG.info("Closing MapDB store"); this.m_db.close(); LOG.info("Stopping MapDB co... | @Test public void testCloseShutdownCommitTask() throws InterruptedException { m_storageService.close(); assertTrue("Storage service scheduler can't be stopped in 3 seconds", m_storageService.m_scheduler.awaitTermination(3, TimeUnit.SECONDS)); assertTrue(m_storageService.m_scheduler.isTerminated()); } |
ProtocolProcessor { public void processSubscribe(Channel channel, MqttSubscribeMessage msg) { String clientID = NettyUtils.clientID(channel); int messageID = messageId(msg); LOG.info("Processing SUBSCRIBE message. CId={}, messageId={}", clientID, messageID); RunningSubscription executionKey = new RunningSubscription(cl... | @Test public void testSubscribe() { MqttSubscribeMessage msg = MqttMessageBuilders.subscribe().addSubscription(MqttQoS.AT_MOST_ONCE, FAKE_TOPIC) .messageId(10).build(); m_sessionStore.createNewSession(FAKE_CLIENT_ID, false); m_processor.processSubscribe(m_channel, msg); assertTrue(m_channel.readOutbound() instanceof Mq... |
ProtocolProcessor { public void processUnsubscribe(Channel channel, MqttUnsubscribeMessage msg) { List<String> topics = msg.payload().topics(); String clientID = NettyUtils.clientID(channel); LOG.info("Processing UNSUBSCRIBE message. CId={}, topics={}", clientID, topics); ClientSession clientSession = m_sessionsStore.s... | @Test public void testUnsubscribeWithBadFormattedTopic() { MqttUnsubscribeMessage msg = MqttMessageBuilders.unsubscribe().addTopicFilter(BAD_FORMATTED_TOPIC).messageId(1) .build(); m_processor.processUnsubscribe(m_channel, msg); assertFalse("If client unsubscribe with bad topic than channel must be closed", m_channel.i... |
ProtocolProcessor { static MqttQoS lowerQosToTheSubscriptionDesired(Subscription sub, MqttQoS qos) { if (qos.value() > sub.getRequestedQos().value()) { qos = sub.getRequestedQos(); } return qos; } ProtocolProcessor(); void init(SubscriptionsDirectory subscriptions, IMessagesStore storageService, ISessionsStore sessions... | @Test public void testLowerTheQosToTheRequestedBySubscription() { Subscription subQos1 = new Subscription("Sub A", new Topic("a/b"), MqttQoS.AT_LEAST_ONCE); assertEquals(MqttQoS.AT_LEAST_ONCE, lowerQosToTheSubscriptionDesired(subQos1, MqttQoS.EXACTLY_ONCE)); Subscription subQos2 = new Subscription("Sub B", new Topic("a... |
DBAuthenticator implements IAuthenticator { @Override public synchronized boolean checkValid(String clientId, String username, byte[] password) { if (username == null || password == null) { LOG.info("username or password was null"); return false; } ResultSet r = null; try { this.preparedStatement.setString(1, username)... | @Test public void Db_verifyValid() { final DBAuthenticator dbAuthenticator = new DBAuthenticator( ORG_H2_DRIVER, JDBC_H2_MEM_TEST, "SELECT PASSWORD FROM ACCOUNT WHERE LOGIN=?", SHA_256); assertTrue(dbAuthenticator.checkValid(null, "dbuser", "password".getBytes())); }
@Test public void Db_verifyInvalidLogin() { final DB... |
ChainingPrincipalResolver implements PrincipalResolver { public boolean supports(final Credential credential) { return this.chain.get(0).supports(credential); } void setChain(final List<PrincipalResolver> chain); Principal resolve(final Credential credential); boolean supports(final Credential credential); } | @Test public void testSupports() throws Exception { final Credential credential = mock(Credential.class); when(credential.getId()).thenReturn("a"); final PrincipalResolver resolver1 = mock(PrincipalResolver.class); when(resolver1.supports(eq(credential))).thenReturn(true); final PrincipalResolver resolver2 = mock(Princ... |
ChainingPrincipalResolver implements PrincipalResolver { public Principal resolve(final Credential credential) { Principal result = null; Credential input = credential; for (final PrincipalResolver resolver : this.chain) { if (result != null) { input = new IdentifiableCredential(result.getId()); } result = resolver.res... | @Test public void testResolve() throws Exception { final Credential credential = mock(Credential.class); when(credential.getId()).thenReturn("input"); final PrincipalResolver resolver1 = mock(PrincipalResolver.class); when(resolver1.supports(eq(credential))).thenReturn(true); when(resolver1.resolve((eq(credential)))).t... |
LegacyAuthenticationHandlerAdapter implements AuthenticationHandler { @Override public HandlerResult authenticate(final Credential credential) throws GeneralSecurityException, PreventedException { try { if (this.legacyHandler.authenticate(credentialsAdapter.convert(credential))) { final CredentialMetaData md; if (crede... | @Test public void testAuthenticateSuccess() throws Exception { final HandlerResult result = alwaysPassHandler.authenticate(new UsernamePasswordCredential("a", "b")); assertEquals("TestAlwaysPassAuthenticationHandler", result.getHandlerName()); }
@Test(expected = FailedLoginException.class) public void testAuthenticateF... |
JRadiusServerImpl implements RadiusServer { @Override public boolean authenticate(final String username, final String password) throws PreventedException { final AttributeList attributeList = new AttributeList(); attributeList.add(new Attr_UserName(username)); attributeList.add(new Attr_UserPassword(password)); RadiusC... | @Test public void testAuthenticate() { assertNotNull(this.radiusServer); } |
SmartOpenIdController extends DelegateController implements Serializable { @Override public boolean canHandle(final HttpServletRequest request, final HttpServletResponse response) { String openIdMode = request.getParameter("openid.mode"); if (openIdMode != null && openIdMode.equals("associate")) { logger.info("Handling... | @Test public void testCanHandle() { request.addParameter("openid.mode", "associate"); boolean canHandle = smartOpenIdController.canHandle(request, response); request.removeParameter("openid.mode"); assertEquals(true, canHandle); }
@Test public void testCannotHandle() { request.addParameter("openid.mode", "anythingElse"... |
SmartOpenIdController extends DelegateController implements Serializable { public Map<String, String> getAssociationResponse(final HttpServletRequest request) { ParameterList parameters = new ParameterList(request.getParameterMap()); final String mode = parameters.hasParameter("openid.mode") ? parameters.getParameterVa... | @Test public void testGetAssociationResponse() { request.addParameter("openid.mode", "associate"); request.addParameter("openid.session_type", "DH-SHA1"); request.addParameter("openid.assoc_type", "HMAC-SHA1"); request.addParameter("openid.dh_consumer_public", "NzKoFMyrzFn/5iJFPdX6MVvNA/BChV1/sJdnYbupDn7ptn+cerwEzyFfWF... |
AvailableForm extends BaseForm { public boolean isRegistrationForm(){ return Constants.FORM_DISCRIMINATOR_REGISTRATION.equalsIgnoreCase(getDiscriminator()) || Constants.FORM_JSON_DISCRIMINATOR_REGISTRATION.equalsIgnoreCase(getDiscriminator()) || Constants.FORM_JSON_DISCRIMINATOR_GENERIC_REGISTRATION.equalsIgnoreCase(ge... | @Test public void shouldReturnFalseIfHasNoRegistrationDiscriminator() { AvailableForm availableForm = new AvailableForm(); assertFalse(availableForm.isRegistrationForm()); for(String discriminator: nonRegistrationDiscriminators) { availableForm.setDiscriminator(discriminator); assertFalse(availableForm.isRegistrationFo... |
FormController { public List<FormData> getAllFormData(String status) throws FormDataFetchException { try { return formService.getAllFormData(status); } catch (Exception e) { throw new FormDataFetchException(e); } } FormController(MuzimaApplication muzimaApplication); int getTotalFormCount(); Form getFormByUuid(String f... | @Test public void getAllFormData_shouldReturnListOfAllFormDatas() throws Exception, FormController.FormDataFetchException { FormData formData = new FormData(); String status = "draft"; when(formService.getAllFormData(status)).thenReturn(Collections.singletonList(formData)); assertThat(formController.getAllFormData(stat... |
FormController { public List<FormData> getAllFormDataByPatientUuid(String patientUuid, String status) throws FormDataFetchException { try { return formService.getFormDataByPatient(patientUuid, status); } catch (IOException e) { throw new FormDataFetchException(e); } } FormController(MuzimaApplication muzimaApplication)... | @Test public void getAllFormDataByPatientUuid_shouldReturnAllFormDataForPatientAndGivenStatus() throws Exception, FormController.FormDataFetchException { List<FormData> formDataList = new ArrayList<>(); String patientUuid = "patientUuid"; String status = "status"; when(formService.getFormDataByPatient(patientUuid, stat... |
FormController { public CompleteForms getAllCompleteFormsForPatientUuid(String patientUuid) throws FormFetchException { CompleteForms completePatientForms = new CompleteForms(); try { List<FormData> allFormData = formService.getFormDataByPatient(patientUuid, Constants.STATUS_COMPLETE); for (FormData formData : allFormD... | @Test (expected = FormController.FormFetchException.class) public void getAllCompleteFormsForPatientUuid_shouldThrowFormFetchExceptionIfExceptionThrownByService() throws Exception, FormController.FormFetchException { doThrow(new IOException()).when(formService).getFormDataByPatient(anyString(),anyString()); formControl... |
FormController { public IncompleteForms getAllIncompleteFormsForPatientUuid(String patientUuid) throws FormFetchException { IncompleteForms incompleteForms = new IncompleteForms(); try { List<FormData> allFormData = formService.getFormDataByPatient(patientUuid, Constants.STATUS_INCOMPLETE); for (FormData formData : all... | @Test (expected = FormController.FormFetchException.class) public void getAllIncompleteFormsForPatientUuid_shouldThrowFormFetchExceptionIfExceptionThrownByService() throws Exception, FormController.FormFetchException { doThrow(new IOException()).when(formService).getFormDataByPatient(anyString(),anyString()); formContr... |
FormController { public List<FormData> getNonUploadedFormData(String templateUUID) throws FormDataFetchException { List<FormData> incompleteFormData = new ArrayList<>(); try { List<FormData> formDataByTemplateUUID = formService.getFormDataByTemplateUUID(templateUUID); for (FormData formData : formDataByTemplateUUID) { ... | @Test public void shouldFilterOutUploadedFormData() throws Exception, FormController.FormDataFetchException { String templateUUID = "templateUUID"; when(formService.getFormDataByTemplateUUID(templateUUID)).thenReturn(asList( formDataWithStatusAndDiscriminator(Constants.STATUS_COMPLETE, Constants.FORM_XML_DISCRIMINATOR_... |
LocationController { public List<Location> downloadLocationFromServerByName(String name) throws LocationDownloadException { try { return locationService.downloadLocationsByName(name); } catch (IOException e) { Log.e(getClass().getSimpleName(), "Error while searching for patients in the server", e); throw new LocationDo... | @Test public void shouldSearchOnServerForLocationsByNames() throws Exception, LocationController.LocationDownloadException { String name = "name"; List<Location> locations = new ArrayList<>(); when(locationService.downloadLocationsByName(name)).thenReturn(locations); assertThat(locationController.downloadLocationFromSe... |
LocationController { public Location downloadLocationFromServerByUuid(String uuid) throws LocationDownloadException { try { return locationService.downloadLocationByUuid(uuid); } catch (IOException e) { Log.e(getClass().getSimpleName(), "Error while searching for patients in the server", e); throw new LocationDownloadE... | @Test public void shouldSearchOnServerForLocationByUuid() throws Exception, LocationController.LocationDownloadException { String uuid = "uuid"; Location location = new Location(); when(locationService.downloadLocationByUuid(uuid)).thenReturn(location); assertThat(locationController.downloadLocationFromServerByUuid(uui... |
LocationController { public List<Location> getAllLocations() throws LocationLoadException { try { return locationService.getAllLocations(); } catch (IOException e) { throw new LocationLoadException(e); } } LocationController(LocationService locationService); List<Location> downloadLocationFromServerByName(String name);... | @Test public void getAllLocations_shouldReturnAllAvailableLocations() throws IOException, LocationController.LocationLoadException { List<Location> locations = new ArrayList<>(); when(locationService.getAllLocations()).thenReturn(locations); assertThat(locationController.getAllLocations(), is(locations)); }
@Test(expec... |
MuzimaSyncService { public int authenticate(String[] credentials) { return authenticate(credentials, false); } MuzimaSyncService(MuzimaApplication muzimaContext); int authenticate(String[] credentials); int authenticate(String[] credentials, boolean isUpdatePasswordRequired); int[] downloadForms(); int[] downloadFormTe... | @Test public void authenticate_shouldCallCloseSessionIfAuthenticationSucceed() { String[] credentials = new String[]{"username", "password", "url"}; muzimaSyncService.authenticate(credentials); verify(muzimaContext).closeSession(); }
@Test public void authenticate_shouldCallCloseSessionIfExceptionOccurred() throws Exce... |
LocationController { public Location getLocationByUuid(String uuid) throws LocationLoadException { try { return locationService.getLocationByUuid(uuid); } catch (IOException e) { throw new LocationLoadException(e); } } LocationController(LocationService locationService); List<Location> downloadLocationFromServerByName(... | @Test public void getLocationByUuid_shouldReturnLocationForId() throws Exception, LocationController.LocationLoadException { Location location = new Location(); String uuid = "uuid"; when(locationService.getLocationByUuid(uuid)).thenReturn(location); assertThat(locationController.getLocationByUuid(uuid), is(location));... |
ConceptController { public List<Concept> downloadConceptsByNames(List<String> names) throws ConceptDownloadException { HashSet<Concept> result = new HashSet<>(); for (String name : names) { List<Concept> concepts = downloadConceptsByNamePrefix(name); Iterator<Concept> iterator = concepts.iterator(); while (iterator.has... | @Test public void shouldDownloadConceptUsingNonPreferredName() throws Exception, ConceptController.ConceptDownloadException { List<Concept> concepts = new ArrayList<>(); final String nonPreferredName = "NonPreferredName"; Concept aConcept = new Concept() {{ setConceptNames(new ArrayList<ConceptName>() {{ add(new Concep... |
ConceptController { public Concept getConceptByName(String name) throws ConceptFetchException { try { List<Concept> concepts = conceptService.getConceptsByName(name); for (Concept concept : concepts) { if (concept.getName().equals(name)) { return concept; } } } catch (IOException e) { throw new ConceptFetchException(e)... | @Test public void shouldReturnAConceptThatMatchesNameExactly() throws Exception, ConceptController.ConceptFetchException { String conceptName = "conceptName"; List<Concept> conceptList = asList(createConceptByName("someName"),createConceptByName(conceptName)); when(service.getConceptsByName(conceptName)).thenReturn(con... |
ObservationController { public List<Observation> downloadObservationsByPatientUuidsAndConceptUuids(List<String> patientUuids, List<String> conceptUuids) throws DownloadObservationException { try { String paramSignature = buildParamSignature(patientUuids, conceptUuids); Date lastSyncTime = lastSyncTimeService.getLastSyn... | @Test public void shouldCheckLastSyncTimeBeforeDownloadingObservations() throws Exception, ObservationController.DownloadObservationException { List<String> patientUuids = asList("PatientUuid1", "PatientUuid2"); List<String> conceptUuids = asList("ConceptUuid1", "ConceptUuid2"); Date aDate = mock(Date.class); when(last... |
ObservationController { public void saveObservations(List<Observation> observations) throws SaveObservationException { try { observationService.saveObservations(observations); } catch (IOException e) { throw new SaveObservationException(e); } } ObservationController(ObservationService observationService, ConceptService... | @Test public void saveObservations_shouldSaveObservationsForPatient() throws Exception, ObservationController.SaveObservationException { final Concept concept1 = new Concept() {{ setUuid("concept1"); }}; final Concept concept2 = new Concept() {{ setUuid("concept2"); }}; final List<Observation> observations = buildObser... |
CohortController { public List<Cohort> getAllCohorts() throws CohortFetchException { try { return cohortService.getAllCohorts(); } catch (IOException e) { throw new CohortFetchException(e); } } CohortController(CohortService cohortService, LastSyncTimeService lastSyncTimeService, SntpService sntpService, MuzimaApplicat... | @Test public void getAllCohorts_shouldReturnAllAvailableCohorts() throws IOException, CohortController.CohortFetchException { List<Cohort> cohorts = new ArrayList<>(); when(cohortService.getAllCohorts()).thenReturn(cohorts); assertThat(controller.getAllCohorts(), is(cohorts)); }
@Test(expected = CohortController.Cohort... |
CohortController { public List<Cohort> downloadAllCohorts(String defaultLocation) throws CohortDownloadException { try { Date lastSyncTimeForCohorts = lastSyncTimeService.getLastSyncTimeFor(DOWNLOAD_COHORTS); Provider loggedInProvider = getLoggedInProvider(); List<Cohort> allCohorts = cohortService.downloadCohortsByNam... | @Test public void downloadAllCohorts_shouldReturnDownloadedCohorts() throws CohortController.CohortDownloadException, IOException { List<Cohort> downloadedCohorts = new ArrayList<>(); List<Cohort> cohorts = new ArrayList<>(); when(cohortService.downloadCohortsByName(StringUtils.EMPTY,null, null)).thenReturn(downloadedC... |
CohortController { public List<Cohort> downloadCohortsByPrefix(List<String> cohortPrefixes,String defaultLocation) throws CohortDownloadException { Provider loggedInProvider = getLoggedInProvider(); List<Cohort> filteredCohorts = new ArrayList<>(); try { Date lastSyncDateOfCohort; LastSyncTime lastSyncTime; for (String... | @Test public void shouldSaveLastSyncTimeAfterDownloadingAllCohortsWithPrefix() throws Exception, CohortController.CohortDownloadException { ArgumentCaptor<LastSyncTime> lastSyncCaptor = ArgumentCaptor.forClass(LastSyncTime.class); when(lastSyncTimeService.getLastSyncTimeFor(DOWNLOAD_COHORTS, "prefix1")).thenReturn(anot... |
CohortController { public CohortData downloadCohortDataByUuid(String uuid,String defaultLocation) throws CohortDownloadException { try { Date lastSyncDate = lastSyncTimeService.getLastSyncTimeFor(DOWNLOAD_COHORTS_DATA, uuid); Provider loggedInProvider = getLoggedInProvider(); CohortData cohortData = cohortService.downl... | @Test public void downloadCohortDataByUuid_shouldDownloadCohortByUuid() throws IOException, CohortController.CohortDownloadException { CohortData cohortData = new CohortData(); String uuid = "uuid"; when(cohortService.downloadCohortDataAndSyncDate(uuid, false, null, null, null)).thenReturn(cohortData); when(lastSyncTim... |
CohortController { public List<CohortData> downloadCohortData(String[] cohortUuids, String defaulLocation) throws CohortDownloadException { ArrayList<CohortData> allCohortData = new ArrayList<>(); for (String cohortUuid : cohortUuids) { allCohortData.add(downloadCohortDataByUuid(cohortUuid, defaulLocation)); } return a... | @Test public void downloadCohortDataAndSyncDate_shouldDownloadDeltaCohortDataBySyncDate() throws IOException, CohortController.CohortDownloadException, ProviderController.ProviderLoadException { String[] uuids = new String[]{"uuid1", "uuid2"}; CohortData cohortData1 = new CohortData(); CohortData cohortData2 = new Coho... |
CohortController { public void saveAllCohorts(List<Cohort> cohorts) throws CohortSaveException { try { cohortService.saveCohorts(cohorts); } catch (IOException e) { throw new CohortSaveException(e); } } CohortController(CohortService cohortService, LastSyncTimeService lastSyncTimeService, SntpService sntpService, Muzim... | @Test public void saveAllCohorts_shouldSaveAllCohorts() throws CohortController.CohortSaveException, IOException { ArrayList<Cohort> cohorts = new ArrayList<Cohort>() {{ add(new Cohort()); add(new Cohort()); add(new Cohort()); }}; controller.saveAllCohorts(cohorts); verify(cohortService).saveCohorts(cohorts); verifyNoM... |
CohortController { public int countAllCohorts() throws CohortFetchException { try { return cohortService.countAllCohorts(); } catch (IOException e) { throw new CohortFetchException(e); } } CohortController(CohortService cohortService, LastSyncTimeService lastSyncTimeService, SntpService sntpService, MuzimaApplication m... | @Test public void getTotalCohortsCount_shouldReturnEmptyListOfNoCohortsHaveBeenSynced() throws IOException, CohortController.CohortFetchException { when(cohortService.countAllCohorts()).thenReturn(2); assertThat(controller.countAllCohorts(), is(2)); } |
MuzimaProgressDialog { @JavascriptInterface public void show(String title) { dialog.setTitle(title); dialog.setMessage(dialog.getContext().getResources().getString(R.string.general_progress_message)); dialog.show(); } MuzimaProgressDialog(Activity activity); MuzimaProgressDialog(ProgressDialog dialog); @JavascriptInt... | @Test public void shouldShowProgressDialogWithGivenText() { dialog.show("title"); Mockito.verify(progressDialog).setCancelable(false); Mockito.verify(progressDialog).setTitle("title"); Mockito.verify(progressDialog).setMessage("This might take a while"); Mockito.verify(progressDialog).show(); } |
MuzimaProgressDialog { @JavascriptInterface public void dismiss() { if (dialog.isShowing()) { dialog.dismiss(); } } MuzimaProgressDialog(Activity activity); MuzimaProgressDialog(ProgressDialog dialog); @JavascriptInterface void show(String title); @JavascriptInterface void updateMessage(String message); @JavascriptIn... | @Test public void shouldDismissADialogOnlyWhenVisible() { when(progressDialog.isShowing()).thenReturn(true); dialog.dismiss(); Mockito.verify(progressDialog).dismiss(); }
@Test public void shouldNotCallDismissIfProgressBarISNotVisible() { when(progressDialog.isShowing()).thenReturn(false); dialog.dismiss(); Mockito.ver... |
HTMLFormDataStore { @JavascriptInterface public void saveHTML(String jsonPayload, String status) { saveHTML(jsonPayload, status, false); } HTMLFormDataStore(HTMLFormWebViewActivity formWebViewActivity, FormData formData, boolean isFormReload, MuzimaApplication application); @JavascriptInterface String getStatus(); @Jav... | @Test public void shouldNotParseIncompletedForm() throws SetupConfigurationController.SetupConfigurationFetchException { when(formWebViewActivity.getString(anyInt())).thenReturn("success"); SetupConfigurationTemplate setupConfigurationTemplate = new SetupConfigurationTemplate(); setupConfigurationTemplate.setUuid("dumm... |
FormDataStore { @JavascriptInterface public void save(String jsonData, String xmlData, String status) { formData.setXmlPayload(xmlData); formData.setJsonPayload(jsonData); formData.setStatus(status); try { if (isRegistrationComplete(status)) { Patient newPatient = formController.createNewPatient(applicationContext,form... | @Test public void save_shouldSaveFormDataWithStatus() throws FormController.FormDataSaveException { store.save("data", "xmldata", "status"); verify(controller).saveFormData(formData); verify(activity).finish(); assertThat(formData.getJsonPayload(), is("data")); assertThat(formData.getStatus(), is("status")); }
@Test pu... |
FormDataStore { @JavascriptInterface public String getFormPayload() { return formData.getJsonPayload(); } FormDataStore(FormWebViewActivity formWebViewActivity, FormController formController, FormData formData); @JavascriptInterface void save(String jsonData, String xmlData, String status); @JavascriptInterface String ... | @Test public void getFormPayload_shouldGetTheFormDataPayload() { formData.setJsonPayload("payload"); assertThat(store.getFormPayload(), is("payload")); } |
HTMLPatientJSONMapper { public String map(Patient patient, FormData formData, User loggedInUser, boolean isLoggedInUserIsDefaultProvider) { JSONObject prepopulateJSON = new JSONObject(); JSONObject patientDetails = new JSONObject(); JSONObject encounterDetails = new JSONObject(); try { patientDetails.put("patient.medic... | @Test public void shouldAddPatientDetailsOnJSONFromPatient() { Date birthdate = new Date(); SimpleDateFormat formattedDate = new SimpleDateFormat(STANDARD_DATE_FORMAT); Patient patient = patient(new Date()); HTMLPatientJSONMapper mapper = new HTMLPatientJSONMapper(); FormData formData = new FormData(); User user = new ... |
StringUtils { public static String getCommaSeparatedStringFromList(final List<String> values){ if(values == null){ return ""; } StringBuilder builder = new StringBuilder(); for (String next : values) { builder.append(next).append(","); } String commaSeparated = builder.toString(); return commaSeparated.substring(0, com... | @Test public void shouldReturnCommaSeparatedList(){ ArrayList<String> listOfStrings = new ArrayList<String>() {{ add("Patient"); add("Registration"); add("New Tag"); }}; String commaSeparatedValues = StringUtils.getCommaSeparatedStringFromList(listOfStrings); assertThat(commaSeparatedValues, is("Patient,Registration,Ne... |
PatientComparator implements Comparator<Patient> { @Override public int compare(Patient patient1, Patient patient2) { if (patient1 == null) { patient1 = new Patient(); } if (patient2 == null) { patient2 = new Patient(); } int familyNameCompareResult = StringUtils.nullSafeCompare(patient1.getFamilyName(), patient2.getFa... | @Test public void shouldSortByFamilyName() { Patient obama = patient("Obama", "Barack", "Hussein", "id1"); Patient bush = patient("Bush", "George", "W", "id2"); assertTrue(patientComparator.compare(obama, bush) > 0); }
@Test public void shouldSortByGivenNameIfFamilyNameIsSame() { Patient barack = patient("Obama", "Bara... |
MuzimaSyncService { public int[] downloadForms() { int[] result = new int[3]; try { long startDownloadForms = System.currentTimeMillis(); List<Form> allDownloadedForms = formController.downloadAllForms(); List<Form> allForms = formController.getAllAvailableForms(); int deletedFormCount = getDeletedFormCount(allDownload... | @Test public void downloadForms_shouldReplaceOldForms() throws FormController.FormFetchException, FormController.FormSaveException { List<Form> forms = new ArrayList<>(); when(formController.downloadAllForms()).thenReturn(forms); muzimaSyncService.downloadForms(); verify(formController).downloadAllForms(); verify(formC... |
MuzimaSyncService { public int[] downloadFormTemplates(String[] formIds, boolean replaceExistingTemplates) { int[] result = new int[4]; try { List<FormTemplate> formTemplates = formController.downloadFormTemplates(formIds); formTemplates.removeAll(Collections.singleton(null)); Log.i(getClass().getSimpleName(), formTemp... | @Test public void downloadFormTemplates_shouldReplaceDownloadedTemplates() throws FormController.FormFetchException, FormController.FormSaveException { String[] formTemplateUuids = new String[]{}; List<FormTemplate> formTemplates = new ArrayList<>(); when(formController.downloadFormTemplates(formTemplateUuids)).thenRet... |
MuzimaSyncService { public int[] downloadCohorts() { int[] result = new int[3]; try { List<Cohort> cohorts = downloadCohortsList(); List<Cohort> voidedCohorts = deleteVoidedCohorts(cohorts); cohorts.removeAll(voidedCohorts); cohortController.saveOrUpdateCohorts(cohorts); Log.i(getClass().getSimpleName(), "New cohorts a... | @Test public void downloadCohort_shouldDownloadAllCohortsWhenNoPrefixesAreAvailableAndReplaceOldCohorts() throws CohortController.CohortDownloadException, CohortController.CohortDeleteException, CohortController.CohortSaveException { List<Cohort> cohorts = new ArrayList<>(); when(cohortController.downloadAllCohorts(nul... |
Concepts extends ArrayList<ConceptWithObservations> { public void sortByDate() { Collections.sort(this, new Comparator<ConceptWithObservations>() { @Override public int compare(ConceptWithObservations lhs, ConceptWithObservations rhs) { return -(lhs.getObservations().get(0).getObservationDatetime() .compareTo(rhs.getOb... | @Test public void shouldSortTheConceptsByDate() { final Observation observation1 = createObservation(createConcept("c1"), "01", new Date(1)); final Observation observation2 = createObservation(createConcept("c2"), "02", new Date(3)); final Observation observation3 = createObservation(createConcept("c1"), "03", new Date... |
MuzimaSyncService { public int[] downloadPatientsForCohorts(String[] cohortUuids) { int[] result = new int[4]; int patientCount = 0; try { long startDownloadCohortData = System.currentTimeMillis(); List<CohortData> cohortDataList = cohortController.downloadCohortData(cohortUuids, getDefaultLocation()); long endDownload... | @Test public void downloadPatientsForCohorts_shouldDownloadAndReplaceCohortMembersAndPatients() throws CohortController.CohortDownloadException, CohortController.CohortReplaceException, PatientController.PatientSaveException, CohortController.CohortUpdateException, ProviderController.ProviderLoadException { String[] co... |
MuzimaSyncService { public int[] downloadObservationsForPatientsByCohortUUIDs(String[] cohortUuids, boolean replaceExistingObservation) { int[] result = new int[4]; List<Patient> patients; try { patients = patientController.getPatientsForCohorts(cohortUuids); List<String> patientlist = new ArrayList(); for (Patient pat... | @Test public void downloadObservationsForPatients_shouldDownloadObservationsForGiveCohortIdsAndSavedConcepts() throws PatientController.PatientLoadException, ObservationController.DownloadObservationException, ObservationController.ReplaceObservationException, ConceptController.ConceptFetchException, ObservationControl... |
Encounters extends ArrayList<EncounterWithObservations> { public void sortByDate() { Collections.sort(this, new Comparator<EncounterWithObservations>() { @Override public int compare(EncounterWithObservations lhs, EncounterWithObservations rhs) { if (lhs.getEncounter().getEncounterDatetime()==null) return -1; if (rhs.g... | @Test public void shouldSortTheEncountersByDate() { final Observation observation1 = createObservation(createEncounter("c1", new Date(1)), "01"); final Observation observation2 = createObservation(createEncounter("c2", new Date(3)), "02"); final Encounters encounters = new Encounters(observation1, observation2); encoun... |
MuzimaSyncService { public int[] downloadEncountersForPatientsByCohortUUIDs(String[] cohortUuids, boolean replaceExistingEncounters) { int[] result = new int[4]; List<Patient> patients; try { patients = patientController.getPatientsForCohorts(cohortUuids); List<String> patientlist = new ArrayList(); for (Patient patien... | @Test public void downloadEncountersForPatients_shouldDownloadInBatch() throws PatientController.PatientLoadException, EncounterController.ReplaceEncounterException, EncounterController.DownloadEncounterException, SetupConfigurationController.SetupConfigurationFetchException { String[] cohortUuids = new String[]{"uuid1... |
MuzimaSyncService { public int[] downloadEncountersForPatientsByPatientUUIDs(List<String> patientUuids, boolean replaceExistingEncounters) { int[] result = new int[4]; try { String activeSetupConfigUuid = null; try { SetupConfigurationTemplate setupConfigurationTemplate = setupConfigurationController.getActiveSetupConf... | @Test public void shouldDeleteVoidedEncountersWhenDownloadingEncounters() throws EncounterController.DeleteEncounterException, EncounterController.DownloadEncounterException, SetupConfigurationController.SetupConfigurationFetchException { String[] patientUuids = new String[]{"patientUuid1", "patientUuid2"}; final Patie... |
MuzimaSyncService { public void consolidatePatients() { List<Patient> allLocalPatients = patientController.getAllPatientsCreatedLocallyAndNotSynced(); for (Patient localPatient : allLocalPatients) { Patient patientFromServer = patientController.consolidateTemporaryPatient(localPatient); if (patientFromServer != null) {... | @Test public void consolidatePatients_shouldGetAllPatientsConsolidateSavePatientFromServerAndDeleteLocalPatient() throws PatientController.PatientSaveException { Patient localPatient = mock(Patient.class); Patient remotePatient = mock(Patient.class); when(patientController.consolidateTemporaryPatient(localPatient)).the... |
MuzimaSyncService { public List<Patient> updatePatientsNotPartOfCohorts() { List<Patient> patientsNotInCohorts = patientController.getPatientsNotInCohorts(); List<Patient> downloadedPatients = new ArrayList<>(); try { for (Patient patient : patientsNotInCohorts) { downloadedPatients.add(patientController.downloadPatien... | @Test public void shouldUpdatePatientsThatAreNotInCohorts() throws PatientController.PatientSaveException, PatientController.PatientDownloadException { Patient localPatient1 = patient("patientUUID1"); Patient localPatient2 = patient("patientUUID2"); Patient serverPatient1 = patient("patientUUID3"); when(patientControll... |
MuzimaSyncService { public int[] downloadPatients(String[] patientUUIDs) { int[] result = new int[2]; List<Patient> downloadedPatients; try { downloadedPatients = downloadPatientsByUUID(patientUUIDs); patientController.savePatients(downloadedPatients); Log.e(getClass().getSimpleName(), "DOWNLOADED PATIENTS."); result[0... | @Test public void shouldDownloadAndSavePatientsGivenByUUID() throws PatientController.PatientDownloadException, PatientController.PatientSaveException { Patient patient1 = patient("patientUUID1"); Patient patient2 = patient("patientUUID2"); String[] patientUUIDs = new String[]{"patientUUID1", "patientUUID2"}; when(pati... |
MuzimaSyncService { public int[] downloadObservationsForPatientsByPatientUUIDs(List<String> patientUuids, boolean replaceExistingObservations) { int[] result = new int[4]; try { List<String> conceptUuidsFromConcepts = getConceptUuidsFromConcepts(conceptController.getConcepts()); List<List<String>> slicedPatientUuids = ... | @Test public void shouldDeleteVoidedObservationsWhenDownloadingObservations() throws ObservationController.DeleteObservationException, ObservationController.DownloadObservationException, ReplaceObservationException, ConceptController.ConceptFetchException { List<String> patientUuids = Collections.singletonList("patient... |
ObservationParserUtility { public Encounter getEncounterEntity(Date encounterDateTime,String formUuid,String providerId, int locationId, String userSystemId, Patient patient, String formDataUuid) { Encounter encounter = new Encounter(); encounter.setProvider(getDummyProvider(providerId)); encounter.setUuid(getEncounter... | @Test public void shouldCreateEncounterEntityWithAppropriateValues() throws ProviderController.ProviderLoadException, FormController.FormFetchException { Date encounterDateTime = new Date(); final String formUuid = "formUuid"; String providerId = "providerId"; int locationId = 1; String userSystemId = "userSystemId"; f... |
ObservationParserUtility { public List<Concept> getNewConceptList() { return newConceptList; } ObservationParserUtility(MuzimaApplication muzimaApplication, boolean createObservationsForConceptsNotAvailableLocally); Encounter getEncounterEntity(Date encounterDateTime,String formUuid,String providerId, int locationId, ... | @Test public void shouldNotCreateNewConceptOrObservationForInvalidConceptName() { observationParserUtility = new ObservationParserUtility(muzimaApplication,true); assertThat(observationParserUtility.getNewConceptList().size(), is(0)); } |
ObservationParserUtility { public Observation getObservationEntity(Concept concept, String value) throws ConceptController.ConceptFetchException, ConceptController.ConceptParseException, ObservationController.ParseObservationException{ if (concept == null) { throw new ObservationController.ParseObservationException("Co... | @Test public void shouldCreateNumericObservation() throws ConceptController.ConceptFetchException, ConceptController.ConceptParseException, ObservationController.ParseObservationException{ Concept concept = mock(Concept.class); when(concept.isNumeric()).thenReturn(true); when(concept.isCoded()).thenReturn(false); Obser... |
HTMLFormObservationCreator { public void createAndPersistObservations(String jsonResponse,String formDataUuid) { parseJSONResponse(jsonResponse,formDataUuid); try { saveObservationsAndRelatedEntities(); } catch (ConceptController.ConceptSaveException e) { Log.e(getClass().getSimpleName(), "Error while saving concept", ... | @Test public void shouldVerifyAllObservationsAndRelatedEntitiesAreSaved() throws EncounterController.SaveEncounterException, ConceptController.ConceptSaveException, ObservationController.SaveObservationException { htmlFormObservationCreator.createAndPersistObservations(readFile(),formDataUuid); verify(encounterControll... |
HTMLConceptParser { public List<String> parse(String html) { Set<String> concepts = new HashSet<>(); Document htmlDoc = Jsoup.parse(html); Elements elements = htmlDoc.select("*:not(div)[" + DATA_CONCEPT_TAG + "]"); for (Element element : elements) { concepts.add(getConceptName(element.attr(DATA_CONCEPT_TAG))); } return... | @Test public void shouldReturnListOfConcepts() { String html = readFile(); List<String> concepts = new HTMLConceptParser().parse(html); assertThat(concepts.size(),is(7)); assertThat(concepts,hasItem("BODY PART")); assertThat(concepts,hasItem("PROCEDURES DONE THIS VISIT")); assertThat(concepts,hasItem("ANATOMIC LOCATION... |
ConceptParser { public List<String> parse(String model) { try { if (StringUtils.isEmpty(model)) { return new ArrayList<>(); } parser.setInput(new ByteArrayInputStream(model.getBytes()), null); parser.nextTag(); return readConceptName(parser); } catch (Exception e) { throw new ParseConceptException(e); } } ConceptParser... | @Test public void shouldParseConcept() { List<String> conceptNames = utils.parse(getModel("concept.xml")); assertThat(conceptNames, hasItem("PULSE")); }
@Test public void shouldParseConceptInObs() { List<String> conceptNames = utils.parse(getModel("concept_in_obs.xml")); assertThat(conceptNames, hasItem("WEIGHT (KG)"))... |
EncounterController { public List<Encounter> downloadEncountersByPatientUuids(List<String> patientUuids, String activeSetupConfigUuid) throws DownloadEncounterException { try { String paramSignature = StringUtils.getCommaSeparatedStringFromList(patientUuids); Date lastSyncTime = lastSyncTimeService.getLastSyncTimeFor(D... | @Test public void shouldGetLastSyncTimeOfEncounter() throws Exception, EncounterController.DownloadEncounterException { List<String> patientUuids = asList("patientUuid1", "patientUuid2"); Date aDate = mock(Date.class); when(lastSyncTimeService.getLastSyncTimeFor(DOWNLOAD_ENCOUNTERS,"patientUuid1,patientUuid2")).thenRet... |
PatientController { public List<Patient> getAllPatients() throws PatientLoadException { try { return patientService.getAllPatients(); } catch (IOException e) { throw new PatientLoadException(e); } } PatientController(PatientService patientService, CohortService cohortService, FormService formService,PatientTagService p... | @Test public void getAllPatients_shouldReturnAllAvailablePatients() throws IOException, PatientController.PatientLoadException { List<Patient> patients = new ArrayList<>(); when(patientService.getAllPatients()).thenReturn(patients); assertThat(patientController.getAllPatients(), is(patients)); }
@Test(expected = Patien... |
PatientController { public int countAllPatients() throws PatientLoadException { try { return patientService.countAllPatients(); } catch (IOException e) { throw new PatientLoadException(e); } } PatientController(PatientService patientService, CohortService cohortService, FormService formService,PatientTagService patient... | @Test public void getTotalPatientsCount_shouldReturnPatientsCount() throws IOException, PatientController.PatientLoadException { when(patientService.countAllPatients()).thenReturn(2); assertThat(patientController.countAllPatients(), is(2)); } |
PatientController { public void replacePatients(List<Patient> patients) throws PatientSaveException { try { patientService.updatePatients(patients); } catch (IOException e) { throw new PatientSaveException(e); } } PatientController(PatientService patientService, CohortService cohortService, FormService formService,Pati... | @Test public void replacePatients_shouldReplaceAllExistingPatientsAndAddNewPatients() throws IOException, PatientController.PatientSaveException { List<Patient> patients = buildPatients(); patientController.replacePatients(patients); verify(patientService).updatePatients(patients); verifyNoMoreInteractions(patientServi... |
PatientController { public List<Patient> getPatients(String cohortId) throws PatientLoadException { try { List<CohortMember> cohortMembers = cohortService.getCohortMembers(cohortId); return patientService.getPatientsFromCohortMembers(cohortMembers); } catch (IOException e) { throw new PatientLoadException(e); } } Patie... | @Test public void getPatientsInCohort_shouldReturnThePatientsInTheCohort() throws IOException, PatientController.PatientLoadException { String cohortId = "cohortId"; List<CohortMember> members = buildCohortMembers(cohortId); when(cohortService.getCohortMembers(cohortId)).thenReturn(members); Patient patient = new Patie... |
ConceptsByPatient extends ConceptAction { @Override Concepts get() throws ObservationController.LoadObservationException { return controller.getConceptWithObservations(patientUuid); } ConceptsByPatient(ConceptController conceptController, ObservationController controller, String patientUuid); @Override String toString(... | @Test public void shouldGetObservationsByPatientUUID() throws ObservationController.LoadObservationException { ObservationController controller = mock(ObservationController.class); ConceptController conceptController = mock(ConceptController.class); ConceptsByPatient byPatient = new ConceptsByPatient(conceptController,... |
PatientController { public List<Patient> searchPatientLocally(String term, String cohortUuid) throws PatientLoadException { try { return StringUtils.isEmpty(cohortUuid) ? patientService.searchPatients(term) : patientService.searchPatients(term, cohortUuid); } catch (IOException | ParseException e) { throw new PatientLo... | @Test public void shouldSearchWithOutCohortUUIDIsNull() throws IOException, ParseException, PatientController.PatientLoadException { String searchString = "searchString"; List<Patient> patients = new ArrayList<>(); when(patientService.searchPatients(searchString)).thenReturn(patients); assertThat(patientController.sear... |
PatientController { public Patient getPatientByUuid(String uuid) throws PatientLoadException { try { return patientService.getPatientByUuid(uuid); } catch (IOException e) { throw new PatientLoadException(e); } } PatientController(PatientService patientService, CohortService cohortService, FormService formService,Patien... | @Test public void getPatientByUuid_shouldReturnPatientForId() throws Exception, PatientController.PatientLoadException { Patient patient = new Patient(); String uuid = "uuid"; when(patientService.getPatientByUuid(uuid)).thenReturn(patient); assertThat(patientController.getPatientByUuid(uuid), is(patient)); } |
PatientController { public List<Patient> searchPatientOnServer(String name) { try { return patientService.downloadPatientsByName(name); } catch (IOException e) { Log.e(getClass().getSimpleName(), "Error while searching for patients in the server", e); } return new ArrayList<>(); } PatientController(PatientService patie... | @Test public void shouldSearchOnServerForPatientByNames() throws Exception { String name = "name"; List<Patient> patients = new ArrayList<>(); when(patientService.downloadPatientsByName(name)).thenReturn(patients); assertThat(patientController.searchPatientOnServer(name), is(patients)); verify(patientService).downloadP... |
PatientController { public Patient consolidateTemporaryPatient(Patient patient) { try { return patientService.consolidateTemporaryPatient(patient); } catch (IOException e) { Log.e(getClass().getSimpleName(), "Error while consolidating the temporary patient.", e); } return null; } PatientController(PatientService patien... | @Test public void shouldConsolidatePatients() throws Exception { Patient tempPatient = mock(Patient.class); Patient patient = mock(Patient.class); when(patientService.consolidateTemporaryPatient(tempPatient)).thenReturn(patient); assertThat(patient, is(patientController.consolidateTemporaryPatient(tempPatient))); } |
FormController { public int getTotalFormCount() throws FormFetchException { try { return formService.countAllForms(); } catch (IOException e) { throw new FormFetchException(e); } } FormController(MuzimaApplication muzimaApplication); int getTotalFormCount(); Form getFormByUuid(String formId); FormTemplate getFormTempla... | @Test public void getTotalFormCount_shouldReturnTotalAvailableForms() throws IOException, FormController.FormFetchException { when(formService.countAllForms()).thenReturn(2); assertThat(formController.getTotalFormCount(), is(2)); } |
FormController { public AvailableForms getAvailableFormByTags(List<String> tagsUuid) throws FormFetchException { return getAvailableFormByTags(tagsUuid, false); } FormController(MuzimaApplication muzimaApplication); int getTotalFormCount(); Form getFormByUuid(String formId); FormTemplate getFormTemplateByUuid(String fo... | @Test public void getAllFormByTags_shouldFetchAllFormsWithGivenTags() throws IOException, FormController.FormFetchException { List<Form> forms = buildForms(); when(formService.getAllForms()).thenReturn(forms); when(formService.isFormTemplateDownloaded(forms.get(0).getUuid())).thenReturn(false); when(formService.isFormT... |
ConceptsBySearch extends ConceptAction { @Override Concepts get() throws ObservationController.LoadObservationException { return controller.searchObservationsGroupedByConcepts(term, patientUuid); } ConceptsBySearch(ConceptController conceptController, ObservationController controller, String patientUuid, String term); ... | @Test public void shouldSearchObservationsByUuidAndTerm() throws ObservationController.LoadObservationException { ObservationController controller = mock(ObservationController.class); ConceptController conceptController = mock(ConceptController.class); ConceptsBySearch conceptsBySearch = new ConceptsBySearch(conceptCon... |
FormController { public List<Form> downloadAllForms() throws FormFetchException { try { Date lastSyncDate = lastSyncTimeService.getLastSyncTimeFor(APIName.DOWNLOAD_FORMS); List<Form> forms = formService.downloadFormsByName(StringUtils.EMPTY, lastSyncDate); LastSyncTime lastSyncTime = new LastSyncTime(APIName.DOWNLOAD_F... | @Test public void downloadAllForms_shouldDownloadAllForms() throws IOException, FormController.FormFetchException { List<Form> forms = new ArrayList<>(); when(formService.downloadFormsByName(StringUtils.EMPTY)).thenReturn(forms); when(lastSyncTimeService.getLastSyncTimeFor(DOWNLOAD_FORMS)).thenReturn(mockDate); assertT... |
FormController { public FormTemplate downloadFormTemplateByUuid(String uuid) throws FormFetchException { try { return formService.downloadFormTemplateByUuid(uuid); } catch (IOException e) { throw new FormFetchException(e); } } FormController(MuzimaApplication muzimaApplication); int getTotalFormCount(); Form getFormByU... | @Test public void downloadFormTemplateByUuid_shouldDownloadFormByUuid() throws IOException, FormController.FormFetchException { FormTemplate formTemplate = new FormTemplate(); String uuid = "uuid"; when(formService.downloadFormTemplateByUuid(uuid)).thenReturn(formTemplate); assertThat(formController.downloadFormTemplat... |
FormController { public void saveAllForms(List<Form> forms) throws FormSaveException { try { formService.saveForms(forms); } catch (IOException e) { throw new FormSaveException(e); } } FormController(MuzimaApplication muzimaApplication); int getTotalFormCount(); Form getFormByUuid(String formId); FormTemplate getFormTe... | @Test public void saveAllForms_shouldSaveAllForm() throws FormController.FormSaveException, IOException { List<Form> forms = buildForms(); formController.saveAllForms(forms); verify(formService).saveForms(forms); verifyNoMoreInteractions(formService); }
@Test(expected = FormController.FormSaveException.class) public vo... |
FormController { public List<Tag> getAllTags() throws FormFetchException { List<Tag> allTags = new ArrayList<>(); List<Form> allForms = null; try { allForms = formService.getAllForms(); } catch (IOException e) { throw new FormFetchException(e); } for (Form form : allForms) { for (Tag tag : form.getTags()) { if (!allTag... | @Test public void getAllTags_shouldFetchAllUsedTags() throws FormController.FormFetchException, IOException { when(formService.getAllForms()).thenReturn(buildForms()); List<Tag> allTags = formController.getAllTags(); assertThat(allTags.size(), is(5)); assertThat(allTags.get(0).getUuid(), is("tag1")); assertThat(allTags... |
FormController { public DownloadedForms getAllDownloadedForms() throws FormFetchException { DownloadedForms downloadedFormsByTags = new DownloadedForms(); try { List<Form> allForms = formService.getAllForms(); ArrayList<String> formUuids = getFormListAsPerConfigOrder(); for (String formUuid : formUuids) { Form form = f... | @Test public void getAllDownloadedForms_shouldReturnOnlyDownloadedForms() throws IOException, FormController.FormFetchException { List<Form> forms = buildForms(); when(formService.getAllForms()).thenReturn(forms); when(formService.isFormTemplateDownloaded(forms.get(0).getUuid())).thenReturn(true); DownloadedForms allDo... |
FormController { public boolean isFormDownloaded(Form form) throws FormFetchException { boolean downloaded; try { downloaded = formService.isFormTemplateDownloaded(form.getUuid()); } catch (IOException e) { throw new FormFetchException(e); } return downloaded; } FormController(MuzimaApplication muzimaApplication); int ... | @Test public void isFormDownloaded_shouldReturnTrueIfFromIsDownloaded() throws IOException, FormController.FormFetchException { List<Form> forms = buildForms(); List<FormTemplate> formTemplates = buildFormTemplates(); when(formService.isFormTemplateDownloaded(anyString())).thenReturn(true); assertThat(formController.is... |
FormController { public FormTemplate getFormTemplateByUuid(String formId) throws FormFetchException { try { return formService.getFormTemplateByUuid(formId); } catch (IOException e) { throw new FormFetchException(e); } } FormController(MuzimaApplication muzimaApplication); int getTotalFormCount(); Form getFormByUuid(St... | @Test public void getFormTemplateByUuid_shouldReturnForm() throws IOException, FormController.FormFetchException { List<FormTemplate> formTemplates = buildFormTemplates(); String uuid = formTemplates.get(0).getUuid(); when(formService.getFormTemplateByUuid(uuid)).thenReturn(formTemplates.get(0)); assertThat(formControl... |
FormController { public Form getFormByUuid(String formId) throws FormFetchException { try { return formService.getFormByUuid(formId); } catch (IOException e) { throw new FormFetchException(e); } } FormController(MuzimaApplication muzimaApplication); int getTotalFormCount(); Form getFormByUuid(String formId); FormTempla... | @Test public void getFormByUuid_shouldReturnForm() throws IOException, FormController.FormFetchException { List<Form> forms = buildForms(); String uuid = forms.get(0).getUuid(); when(formService.getFormByUuid(uuid)).thenReturn(forms.get(0)); assertThat(formController.getFormByUuid(uuid), is(forms.get(0))); } |
FormController { public FormData getFormDataByUuid(String formDataUuid) throws FormDataFetchException { try { return formService.getFormDataByUuid(formDataUuid); } catch (IOException e) { throw new FormDataFetchException(e); } } FormController(MuzimaApplication muzimaApplication); int getTotalFormCount(); Form getFormB... | @Test public void getFormDataByUuid_shouldReturnFormDataForAGivenId() throws Exception, FormController.FormDataFetchException { FormData formData = new FormData(); String uuid = "uuid"; when(formService.getFormDataByUuid(uuid)).thenReturn(formData); assertThat(formController.getFormDataByUuid(uuid), is(formData)); }
@T... |
FormController { public void saveFormData(FormData formData) throws FormDataSaveException { try { formData.setSaveTime(new Date()); formService.saveFormData(formData); } catch (IOException e) { throw new FormDataSaveException(e); } } FormController(MuzimaApplication muzimaApplication); int getTotalFormCount(); Form get... | @Test public void saveFormData_shouldSaveFormData() throws Exception, FormController.FormDataSaveException { FormData formData = new FormData(); formController.saveFormData(formData); verify(formService).saveFormData(formData); }
@Test(expected = FormController.FormDataSaveException.class) public void saveFormData_shou... |
EntityUtils { @SuppressWarnings({ "unchecked", "rawtypes" }) public static Class<? extends Serializable> primaryKeyClass(Class<?> entityClass) { if (entityClass.isAnnotationPresent(IdClass.class)) { return entityClass.getAnnotation(IdClass.class).value(); } Class clazz = PersistenceUnitDescriptorProvider.getInstance().... | @Test public void should_find_id_property_class() { Class<? extends Serializable> pkClass = EntityUtils.primaryKeyClass(Tee.class); Assert.assertEquals(TeeId.class, pkClass); }
@Test public void should_find_id_class() { Class<? extends Serializable> pkClass = EntityUtils.primaryKeyClass(Tee2.class); Assert.assertEquals... |
EntityRepositoryHandler implements EntityRepository<E, PK>, DelegateQueryHandler { @Override public E findBy(PK primaryKey) { Query query = context.getMethod().getAnnotation(Query.class); if (query != null && query.hints().length > 0) { Map<String, Object> hints = new HashMap<String, Object>(); for (QueryHint hint : qu... | @Test public void should_find_by_pk() throws Exception { Simple simple = testData.createSimple("testFindByPk"); Simple find = repo.findBy(simple.getId()); assertEquals(simple.getName(), find.getName()); }
@Test @SuppressWarnings("unchecked") public void should_find_by_example() throws Exception { Simple simple = testDa... |
EntityRepositoryHandler implements EntityRepository<E, PK>, DelegateQueryHandler { @Override public Optional<E> findOptionalBy(PK primaryKey) { E found = null; try { found = findBy(primaryKey); } catch (Exception e) { } return Optional.ofNullable(found); } @Override @RequiresTransaction E save(E entity); @Override @Re... | @Test public void should_find__by_pk() throws Exception { Simple simple = testData.createSimple("testFindByPk"); Optional<Simple> find = repo.findOptionalBy(simple.getId()); assertEquals(simple.getName(), find.get().getName()); } |
EntityRepositoryHandler implements EntityRepository<E, PK>, DelegateQueryHandler { @SuppressWarnings("unchecked") @Override public List<E> findAll() { return context.applyRestrictions(entityManager().createQuery(allQuery(), entityClass())).getResultList(); } @Override @RequiresTransaction E save(E entity); @Override @... | @Test public void should_find_all() { testData.createSimple("testFindAll1"); testData.createSimple("testFindAll2"); List<Simple> find = repo.findAll(); assertEquals(2, find.size()); }
@Test public void should_find_by_all_with_start_and_max() { testData.createSimple("testFindAll1"); testData.createSimple("testFindAll2")... |
EntityRepositoryHandler implements EntityRepository<E, PK>, DelegateQueryHandler { @Override public List<E> findByLike(E example, SingularAttribute<E, ?>... attributes) { return findByLike(example, -1, -1, attributes); } @Override @RequiresTransaction E save(E entity); @Override @RequiresTransaction E saveAndFlush(E e... | @Test @SuppressWarnings({ "unchecked" }) public void should_find_by_like() { testData.createSimple("testFindAll1"); testData.createSimple("testFindAll2"); Simple example = new Simple("test"); List<Simple> find = repo.findByLike(example, Simple_.name); assertEquals(2, find.size()); }
@Test @SuppressWarnings("unchecked")... |
EntityRepositoryHandler implements EntityRepository<E, PK>, DelegateQueryHandler { @Override public Long count() { return (Long) context.applyRestrictions(entityManager().createQuery(countQuery(), Long.class)) .getSingleResult(); } @Override @RequiresTransaction E save(E entity); @Override @RequiresTransaction E saveA... | @Test public void should_count_all() { testData.createSimple("testCountAll"); Long result = repo.count(); assertEquals(Long.valueOf(1), result); }
@Test @SuppressWarnings("unchecked") public void should_count_with_attributes() { Simple simple = testData.createSimple("testFindAll1", Integer.valueOf(55)); testData.create... |
EntityRepositoryHandler implements EntityRepository<E, PK>, DelegateQueryHandler { @Override public Long countLike(E example, SingularAttribute<E, ?>... attributes) { return executeCountQuery(example, true, attributes); } @Override @RequiresTransaction E save(E entity); @Override @RequiresTransaction E saveAndFlush(E ... | @Test @SuppressWarnings("unchecked") public void should_count_by_like() { testData.createSimple("testFindAll1"); testData.createSimple("testFindAll2"); Simple example = new Simple("test"); Long count = repo.countLike(example, Simple_.name); assertEquals(Long.valueOf(2), count); } |
EntityRepositoryHandler implements EntityRepository<E, PK>, DelegateQueryHandler { @Override @RequiresTransaction public void removeAndFlush(E entity) { entityManager().remove(entity); flush(); } @Override @RequiresTransaction E save(E entity); @Override @RequiresTransaction E saveAndFlush(E entity); @Override @Requir... | @Test public void should_remove_and_flush() { Simple simple = testData.createSimple("testRemoveAndFlush"); repo.removeAndFlush(simple); Simple lookup = getEntityManager().find(Simple.class, simple.getId()); assertNull(lookup); } |
EntityRepositoryHandler implements EntityRepository<E, PK>, DelegateQueryHandler { @SuppressWarnings("unchecked") @Override public PK getPrimaryKey(E entity) { return (PK) persistenceUnitUtil().getIdentifier(entity); } @Override @RequiresTransaction E save(E entity); @Override @RequiresTransaction E saveAndFlush(E ent... | @Test public void should_return_entity_primary_key() { Simple simple = testData.createSimple("should_return_entity_primary_key"); Long id = simple.getId(); Long primaryKey = repo.getPrimaryKey(simple); assertNotNull(primaryKey); assertEquals(id, primaryKey); }
@Test public void should_return_null_primary_key() { Simple... |
AuditEntityListener { @PrePersist public void persist(Object entity) { BeanManager beanManager = BeanManagerProvider.getInstance().getBeanManager(); Set<Bean<?>> beans = beanManager.getBeans(PrePersistAuditListener.class); for (Bean<?> bean : beans) { PrePersistAuditListener result = (PrePersistAuditListener) beanManag... | @Test public void should_set_creation_date() throws Exception { AuditedEntity entity = new AuditedEntity(); getEntityManager().persist(entity); getEntityManager().flush(); assertNotNull(entity.getCreated()); assertNotNull(entity.getModified()); assertEquals(entity.getCreated().getTime(), entity.getModified()); }
@Test ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.