Skip to content

Commit

Permalink
feat: CARITAS-286
Browse files Browse the repository at this point in the history
* add it and unit tests for new getAgenciesTopics method of the class AgencyService
  • Loading branch information
Leandro13Silva13 committed Oct 28, 2024
1 parent edbffa1 commit 210dc42
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ public void getAgenciesByConsultingType_Should_returnResults_When_ConsultingType
super.getAgenciesByConsultingType_Should_returnResults_When_ConsultingTypeIsValid();
}

@Test
public void getAgenciesTopics_Should_ReturnResults_When_topics_exist() {
super.getAgenciesTopics_Should_ReturnResults_When_topics_exist();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class AgencyServiceITBase {
private AgencyRepository agencyRepository;
@MockBean
private ConsultingTypeManager consultingTypeManager;
@MockBean
private TopicEnrichmentService topicEnrichmentService;

public void getAgencies_Should_returnMatchingAgencies_When_postcodeAndConsultingTypeIsGiven()
throws MissingConsultingTypeException {
Expand Down Expand Up @@ -64,4 +66,10 @@ public void getAgenciesByConsultingType_Should_returnResults_When_ConsultingType
assertThat(agencies, hasSize(greaterThan(0)));
}

public void getAgenciesTopics_Should_ReturnResults_When_topics_exist() {
List<Integer> topicIds = this.agencyService.getAgenciesTopics();

assertThat(topicIds, hasSize(greaterThan(0)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static de.caritas.cob.agencyservice.testHelper.TestConstants.EMPTY_AGENCY_LIST;
import static de.caritas.cob.agencyservice.testHelper.TestConstants.FIELD_AGENCY_ID;
import static de.caritas.cob.agencyservice.testHelper.TestConstants.POSTCODE;
import static de.caritas.cob.agencyservice.testHelper.TestConstants.TOPIC_ID_LIST;
import static de.caritas.cob.agencyservice.testHelper.TestConstants.VALID_POSTCODE;
import static de.caritas.cob.agencyservice.testHelper.TestConstants.VALID_POSTCODE_LENGTH;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -46,8 +47,10 @@
import de.caritas.cob.agencyservice.consultingtypeservice.generated.web.model.RegistrationDTO;
import de.caritas.cob.agencyservice.tenantservice.generated.web.model.RestrictedTenantDTO;
import de.caritas.cob.agencyservice.tenantservice.generated.web.model.Settings;
import io.swagger.models.auth.In;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import javax.swing.text.html.Option;
import org.hamcrest.collection.IsEmptyCollection;
Expand Down Expand Up @@ -333,4 +336,26 @@ public void getAgencies_Should_searchByTopicId_When_TopicIdProvidedAndFeatureEna
verify(agencyRepository).searchWithTopic("12123", 5, 1, 2, AGE, GENDER, COUNSELLING_RELATION,
TENANT_ID);
}

@Test
public void getAgenciesTopics_Should_ReturnListOfTopicIds_When_topicsExist() {

when(agencyRepository.findAllAgenciesTopics())
.thenReturn(TOPIC_ID_LIST);

Integer result = agencyService.getAgenciesTopics().get(0);

assertEquals(TOPIC_ID_LIST.get(0), result);
}

@Test
public void getAgenciesTopics_Should_ReturnEmptyListOfTopicIds_When_topicsDontExist() {

when(agencyRepository.findAllAgenciesTopics())
.thenReturn(new ArrayList<>());

List<Integer> result = agencyService.getAgenciesTopics();

assertThat(result).isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.List;
import java.util.Map;
import org.assertj.core.util.Lists;
import org.springframework.boot.autoconfigure.kafka.KafkaProperties.Retry.Topic;

public class TestConstants {

Expand Down Expand Up @@ -165,6 +166,8 @@ public class TestConstants {
.isExternal(false)
.build();

public static final Integer TOPIC_SUCHT = 1;

public static final Agency AGENCY_KREUZBUND = new Agency(AGENCY_ID, AGENCY_NAME,
AGENCY_DESCRIPTION,
POSTCODE, "Test city", false, CONSULTING_TYPE_KREUZBUND, false, null, false, null, null, null,
Expand Down Expand Up @@ -203,6 +206,7 @@ public class TestConstants {

public static final List<Agency> EMPTY_AGENCY_LIST = new ArrayList<>();
public static final List<Agency> AGENCY_LIST = Collections.singletonList(AGENCY_SUCHT);
public static final List<Integer> TOPIC_ID_LIST = Collections.singletonList(TOPIC_SUCHT);
public static final List<Long> AGENCY_IDS_LIST = Collections.singletonList(AGENCY_ID);

public static final String VALID_CONSULTING_TYPE_QUERY = "consultingType=0";
Expand Down

0 comments on commit 210dc42

Please sign in to comment.