Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAM-46: Added Ward entity with CRUD #85

Closed
wants to merge 2 commits into from
Closed
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
@@ -0,0 +1,104 @@
/*
* This program is part of the OpenLMIS logistics management information system platform software.
* Copyright © 2017 VillageReach
*
* This program is free software: you can redistribute it and/or modify it under the terms
* of the GNU Affero General Public License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details. You should have received a copy of
* the GNU Affero General Public License along with this program. If not, see
* http://www.gnu.org/licenses.  For additional information contact [email protected].
*/

package org.openlmis.referencedata.repository;

import java.util.UUID;
import org.junit.Test;
import org.openlmis.referencedata.domain.Facility;
import org.openlmis.referencedata.domain.FacilityType;
import org.openlmis.referencedata.domain.GeographicLevel;
import org.openlmis.referencedata.domain.GeographicZone;
import org.openlmis.referencedata.domain.Ward;
import org.openlmis.referencedata.testbuilder.FacilityDataBuilder;
import org.openlmis.referencedata.testbuilder.FacilityTypeDataBuilder;
import org.openlmis.referencedata.testbuilder.GeographicLevelDataBuilder;
import org.openlmis.referencedata.testbuilder.GeographicZoneDataBuilder;
import org.openlmis.referencedata.testbuilder.WardDataBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.data.repository.CrudRepository;

@SuppressWarnings("PMD.TooManyMethods")
public class WardRepositoryIntegrationTest extends BaseCrudRepositoryIntegrationTest<Ward> {

@Autowired
private WardRepository repository;

@Autowired
private GeographicLevelRepository geographicLevelRepository;

@Autowired
private GeographicZoneRepository geographicZoneRepository;

@Autowired
private FacilityTypeRepository facilityTypeRepository;

@Autowired
private FacilityRepository facilityRepository;

@Override
CrudRepository<Ward, UUID> getRepository() {
return repository;
}

@Override
Ward generateInstance() {
return new WardDataBuilder()
.withFacility(generateFacility())
.buildAsNew();
}

@Test(expected = DataIntegrityViolationException.class)
public void shouldNotAllowForSeveralWardsWithSameCode() {
Ward ward1 = generateInstance();
Ward ward2 = generateInstance();
ward1.setCode(ward2.getCode());

repository.saveAndFlush(ward1);
repository.saveAndFlush(ward2);
}

private Facility generateFacility() {
Facility facility = new FacilityDataBuilder()
.withGeographicZone(generateGeographicZone())
.withType(generateFacilityType())
.withoutOperator()
.buildAsNew();

facilityRepository.save(facility);
return facility;
}

private GeographicLevel generateGeographicLevel() {
GeographicLevel geographicLevel = new GeographicLevelDataBuilder().buildAsNew();
geographicLevelRepository.save(geographicLevel);
return geographicLevel;
}

private GeographicZone generateGeographicZone() {
GeographicZone geographicZone =
new GeographicZoneDataBuilder().withLevel(generateGeographicLevel()).buildAsNew();
geographicZoneRepository.save(geographicZone);
return geographicZone;
}

private FacilityType generateFacilityType() {
FacilityType facilityType = new FacilityTypeDataBuilder().buildAsNew();
facilityTypeRepository.save(facilityType);
return facilityType;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
import org.openlmis.referencedata.repository.SystemNotificationRepository;
import org.openlmis.referencedata.repository.TradeItemRepository;
import org.openlmis.referencedata.repository.UserRepository;
import org.openlmis.referencedata.repository.WardRepository;
import org.openlmis.referencedata.repository.custom.impl.ProgramRedisRepository;
import org.openlmis.referencedata.repository.custom.impl.SupervisoryNodeDtoRedisRepository;
import org.openlmis.referencedata.service.AuthenticationHelper;
Expand Down Expand Up @@ -332,6 +333,9 @@ public abstract class BaseWebIntegrationTest {
@MockBean
protected DataImportService dataImportService;

@MockBean
protected WardRepository wardRepository;

/**
* Constructor for test.
*/
Expand Down
Loading
Loading