Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,10 @@ public void globalPropertyChanged(GlobalProperty newValue) {
*/
@Override
public void globalPropertyDeleted(String propertyName) {
// TODO Auto-generated method stub

Comment on lines -700 to -701
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kindly why did you remove line?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those lines were auto-generated placeholder stubs with no actual implementation. Since I've now provided the real implementation for globalPropertyDeleted, the TODO stub was no longer needed and I removed it to keep the code clean.

if (propertyName.equals(
OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST)) {
presentationLocales = null;
}
}

/**
Expand Down
24 changes: 24 additions & 0 deletions api/src/test/java/org/openmrs/api/AdministrationServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1180,4 +1180,28 @@ public void runModuleSetupOnVersionChange_shouldExecuteLiquibaseAndStoreNewVersi
// verify hook methods must be called
verify(activator).setupOnVersionChange(previousCoreVersion, previousModuleVersion);
}

@Test
public void globalPropertyDeleted_shouldResetPresentationLocalesWhenLocaleAllowedListDeleted() {
// First get presentation locales to initialize them
AdministrationService as = Context.getAdministrationService();

// Set allowed locales so presentationLocales gets initialized
GlobalProperty gp = new GlobalProperty(
OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, "en_GB");
as.saveGlobalProperty(gp);

// Initialize presentationLocales by calling getPresentationLocales
as.getPresentationLocales();

// Now delete the global property
((GlobalPropertyListener) as).globalPropertyDeleted(
OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST);

// presentationLocales should be reset to null
// Calling getPresentationLocales again should
// reinitialize it from scratch
assertNotNull(as.getPresentationLocales());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class HibernateFormDAOTest extends BaseContextSensitiveTest {

Expand All @@ -49,19 +50,65 @@
.getForms(null, false, Collections.emptyList(), null, formFields, formFields, Arrays.asList(new Field(3)))
.size());


}

@Test
public void shouldGetFormFieldsByForm() {

Check failure on line 57 in api/src/test/java/org/openmrs/api/db/hibernate/HibernateFormDAOTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add at least one assertion to this test case.

See more on https://sonarcloud.io/project/issues?id=openmrs_openmrs-core&issues=AZ1DSrtsq48j9hUCkw8b&open=AZ1DSrtsq48j9hUCkw8b&pullRequest=6006
Form form = new Form(2);
List<FormField> formFields = dao.getFormFields(form);

Check warning on line 59 in api/src/test/java/org/openmrs/api/db/hibernate/HibernateFormDAOTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused "formFields" local variable.

See more on https://sonarcloud.io/project/issues?id=openmrs_openmrs-core&issues=AZ1DSrtsq48j9hUCkw8c&open=AZ1DSrtsq48j9hUCkw8c&pullRequest=6006

assertNotNull(formFields);

}

@Test
public void getForms_shouldReturnFormsContainingAnyFormField() {
// Test 1 - Basic: should return forms containing any form field
List<FormField> anyFormFields = Arrays.asList(new FormField(2));
List<Form> forms = dao.getForms(null, false,
Collections.emptyList(), null,
anyFormFields, Collections.emptyList(),
Collections.emptyList());
assertNotNull(forms);
assertTrue(forms.size() > 0);

// Test 2 - Empty list: should return all forms
List<Form> formsWithEmpty = dao.getForms(null, false,
Collections.emptyList(), null,
Collections.emptyList(), Collections.emptyList(),
Collections.emptyList());
assertNotNull(formsWithEmpty);

final int EXPECTED_SIZE = 2;
assertEquals(EXPECTED_SIZE, formFields.size());
for (FormField formField : formFields) {
assertEquals(form.getFormId(), formField.getForm().getFormId());
}
// Test 3 - Multiple fields: should return forms with any field
List<FormField> multipleFields = Arrays.asList(
new FormField(2), new FormField(3));
List<Form> formsMultiple = dao.getForms(null, false,
Collections.emptyList(), null,
multipleFields, Collections.emptyList(),
Collections.emptyList());
assertNotNull(formsMultiple);
assertTrue(formsMultiple.size() > 0);

// Test 4 - Non existent field: should return empty list
List<FormField> invalidFields = Arrays.asList(new FormField(999));
List<Form> formsInvalid = dao.getForms(null, false,
Collections.emptyList(), null,
invalidFields, Collections.emptyList(),
Collections.emptyList());
assertNotNull(formsInvalid);
assertTrue(formsInvalid.isEmpty());

// Edge case: multiple non-existent fields
List<FormField> multipleInvalidFields = Arrays.asList(
new FormField(997),
new FormField(998),
new FormField(999));
List<Form> formsMultipleInvalid = dao.getForms(null, false,
Collections.emptyList(), null,
multipleInvalidFields, Collections.emptyList(),
Collections.emptyList());
assertNotNull(formsMultipleInvalid);
assertTrue(formsMultipleInvalid.isEmpty());
}

}