Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-bcl committed Aug 27, 2024
1 parent 34af795 commit 1fb5733
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 56 deletions.
33 changes: 0 additions & 33 deletions src/main/java/uk/co/bconline/ndelius/model/entity/LDUEntity.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ public class BoroughExportEntity implements Serializable {
private ProbationAreaExportEntity probationArea;

public String getExportDescription() {
return description + " (" + code + ") " + (isSelectable() ? " [Active]" : " [Inactive]");
return description + " (" + code + ")" + (isSelectable() ? "" : " [Inactive]");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ public class DistrictExportEntity implements Serializable
private BoroughExportEntity borough;

public String getExportDescription() {
return description + " (" + code + ") " + (isSelectable() ? " [Active]" : " [Inactive]");
return description + " (" + code + ")" + (isSelectable() ? "" : " [Inactive]");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDate;

import static java.time.LocalDate.now;
import static org.hibernate.annotations.CacheConcurrencyStrategy.READ_ONLY;

@Entity
@Getter
Expand All @@ -37,6 +35,6 @@ public class ProbationAreaExportEntity implements Serializable {

public String getExportDescription()
{
return description + " (" + code + ") " + ((getEndDate() != null && getEndDate().isBefore(now())) ? " [Inactive]" : " [Active]");
return description + " (" + code + ")" + ((getEndDate() != null && getEndDate().isBefore(now())) ? " [Inactive]" : "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public class TeamExportEntity implements Serializable {
@Type(type = "java.time.LocalDate")
private LocalDate endDate;

public String getExportDescription()
{
return description + " (" + code + ") " + ((getEndDate() != null && getEndDate().isBefore(now())) ? " [Inactive]" : " [Active]");
public String getExportDescription() {
return description + " (" + code + ")" + ((getEndDate() != null && getEndDate().isBefore(now())) ? " [Inactive]" : "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public interface UserRoleService
{
Set<RoleEntry> getRolesICanAssign();
Set<RoleEntry> getUserRoles(String username);

Set<String> getUserRoleNames(String username);
List<String> getAllUsersWithRole(String role);
Set<RoleEntry> getClientRoles(String clientId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public Set<RoleEntry> getUserRoles(String username) {
@Override
public Set<String> getUserRoleNames(String username) {
return stream(getAssignedRoleAssociations(username, usersBase).spliterator(), false)
.map(RoleAssociationEntry::getName)
.map(RoleAssociationEntry::getCn)
.collect(toSet());
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/data.ldif
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ dn: cn=UABT0052,cn=test.user.private,ou=Users,dc=bcl,dc=local
objectclass: top
objectclass: alias
objectclass: NDRoleAssociation
cn: UABT0051
cn: UABT0052
aliasedObjectName: cn=UABT0052,cn=ndRoleCatalogue,ou=Users,dc=bcl,dc=local

dn: cn=TestUser1,ou=Users,dc=bcl,dc=local
Expand Down
30 changes: 22 additions & 8 deletions src/main/resources/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@ INSERT INTO PROBATION_AREA(PROBATION_AREA_ID, CODE, DESCRIPTION, ORGANISATION_ID
INSERT INTO PROBATION_AREA(PROBATION_AREA_ID, CODE, DESCRIPTION, ORGANISATION_ID, ESTABLISHMENT, SELECTABLE) VALUES (PROBATION_AREA_ID_SEQ.NEXTVAL, 'NWI', 'Norwich (HMP & YOI)', ORGANISATION_ID_SEQ.CURRVAL, 'Y', 'Y');
INSERT INTO PROBATION_AREA(PROBATION_AREA_ID, CODE, DESCRIPTION, ORGANISATION_ID, ESTABLISHMENT, SELECTABLE) VALUES (PROBATION_AREA_ID_SEQ.NEXTVAL, 'PVI', 'Pentonville (HMP)', ORGANISATION_ID_SEQ.CURRVAL, 'Y', 'Y');

-- LDU/PDU
INSERT INTO BOROUGH (BOROUGH_ID, CODE, DESCRIPTION, PROBATION_AREA_ID) VALUES (BOROUGH_ID_SEQ.NEXTVAL, 'B1', 'Borough A', (SELECT PROBATION_AREA_ID FROM PROBATION_AREA WHERE CODE='N01'));
INSERT INTO BOROUGH (BOROUGH_ID, CODE, DESCRIPTION, PROBATION_AREA_ID) VALUES (BOROUGH_ID_SEQ.NEXTVAL, 'B2', 'Borough B', (SELECT PROBATION_AREA_ID FROM PROBATION_AREA WHERE CODE='N02'));
INSERT INTO LOCAL_DELIVERY_UNIT (LOCAL_DELIVERY_UNIT_ID, CODE, DESCRIPTION) VALUES (LOCAL_DELIVERY_UNIT_ID_SEQ.NEXTVAL, 'LDU1', 'Local Delivery Unit A');
INSERT INTO LOCAL_DELIVERY_UNIT (LOCAL_DELIVERY_UNIT_ID, CODE, DESCRIPTION) VALUES (LOCAL_DELIVERY_UNIT_ID_SEQ.NEXTVAL, 'LDU2', 'Local Delivery Unit B');
-- Probation Delivery Units
INSERT INTO BOROUGH (BOROUGH_ID, CODE, DESCRIPTION, SELECTABLE, PROBATION_AREA_ID)
VALUES (BOROUGH_ID_SEQ.NEXTVAL, 'B1', 'Borough A', 'N',
(SELECT PROBATION_AREA_ID FROM PROBATION_AREA WHERE CODE = 'N01'));
INSERT INTO BOROUGH (BOROUGH_ID, CODE, DESCRIPTION, SELECTABLE, PROBATION_AREA_ID)
VALUES (BOROUGH_ID_SEQ.NEXTVAL, 'B2', 'Borough B', 'Y',
(SELECT PROBATION_AREA_ID FROM PROBATION_AREA WHERE CODE = 'N02'));

-- Local Admin Units
INSERT INTO DISTRICT (DISTRICT_ID, CODE, DESCRIPTION, SELECTABLE, BOROUGH_ID)
VALUES (DISTRICT_ID_SEQ.NEXTVAL, 'LAU1', 'Local Admin Unit A', 'Y', (SELECT BOROUGH_ID FROM BOROUGH WHERE CODE = 'B1'));
INSERT INTO DISTRICT (DISTRICT_ID, CODE, DESCRIPTION, SELECTABLE, BOROUGH_ID)
VALUES (DISTRICT_ID_SEQ.NEXTVAL, 'LAU2', 'Local Admin Unit B', 'Y', (SELECT BOROUGH_ID FROM BOROUGH WHERE CODE = 'B2'));

-- Sub-contracted Providers
INSERT INTO SC_PROVIDER(SC_PROVIDER_ID, CODE, DESCRIPTION, ACTIVE_FLAG, PROVIDER_ID) VALUES (SC_PROVIDER_ID_SEQ.NEXTVAL, 'N01SC1', 'NPS London SC 1', 1, (SELECT PROBATION_AREA_ID FROM PROBATION_AREA WHERE CODE='N01'));
Expand Down Expand Up @@ -480,6 +487,7 @@ INSERT INTO USER_NOTE (USER_NOTE_ID, ROW_VERSION, USER_ID, LAST_UPDATED_USER_ID,
VALUES (USER_NOTE_ID_SEQ.NEXTVAL, 0, (SELECT USER_ID FROM USER_ WHERE DISTINGUISHED_NAME = 'Joe.Bloggs'), (SELECT USER_ID FROM USER_ WHERE DISTINGUISHED_NAME = 'Mavis.Mehler'), CURRENT_TIMESTAMP-9.9, 'Added user management roles, to allow access to UMT.');
INSERT INTO USER_NOTE (USER_NOTE_ID, ROW_VERSION, USER_ID, LAST_UPDATED_USER_ID, LAST_UPDATED_DATETIME, NOTES)
VALUES (USER_NOTE_ID_SEQ.NEXTVAL, 0, (SELECT USER_ID FROM USER_ WHERE DISTINGUISHED_NAME = 'Joe.Bloggs'), (SELECT USER_ID FROM USER_ WHERE DISTINGUISHED_NAME = '[Data Maintenance]'), CURRENT_TIMESTAMP-9.9, 'Added user management roles, to allow access to UMT.');

-- Datasets
INSERT INTO PROBATION_AREA_USER (PROBATION_AREA_ID, USER_ID) VALUES ((SELECT PROBATION_AREA_ID FROM PROBATION_AREA WHERE CODE = 'N01'), (SELECT USER_ID FROM USER_ WHERE DISTINGUISHED_NAME = 'test.user'));
INSERT INTO PROBATION_AREA_USER (PROBATION_AREA_ID, USER_ID) VALUES ((SELECT PROBATION_AREA_ID FROM PROBATION_AREA WHERE CODE = 'N02'), (SELECT USER_ID FROM USER_ WHERE DISTINGUISHED_NAME = 'test.user'));
Expand All @@ -490,9 +498,15 @@ INSERT INTO PROBATION_AREA_USER (PROBATION_AREA_ID, USER_ID) VALUES ((SELECT PRO

-- Teams
INSERT INTO TEAM (TEAM_ID, CODE, DESCRIPTION, PROBATION_AREA_ID, END_DATE) VALUES (TEAM_ID_SEQ.NEXTVAL, 'N01TST', 'Test team (Ended)', (SELECT PROBATION_AREA_ID FROM PROBATION_AREA WHERE CODE = 'N01'), CURRENT_TIMESTAMP);
INSERT INTO TEAM (TEAM_ID, CODE, DESCRIPTION, PROBATION_AREA_ID, DISTRICT_ID) VALUES (TEAM_ID_SEQ.NEXTVAL, 'N01TST', 'Test team', (SELECT PROBATION_AREA_ID FROM PROBATION_AREA WHERE CODE = 'N01'), (SELECT BOROUGH_ID FROM BOROUGH WHERE CODE = 'B2'));
INSERT INTO TEAM (TEAM_ID, CODE, DESCRIPTION, PROBATION_AREA_ID, DISTRICT_ID, LOCAL_DELIVERY_UNIT_ID) VALUES (TEAM_ID_SEQ.NEXTVAL, 'N02TST', 'Other team', (SELECT PROBATION_AREA_ID FROM PROBATION_AREA WHERE CODE = 'N02'), (SELECT BOROUGH_ID FROM BOROUGH WHERE CODE = 'B1'), (SELECT LOCAL_DELIVERY_UNIT_ID FROM LOCAL_DELIVERY_UNIT WHERE CODE = 'LDU1'));
INSERT INTO TEAM (TEAM_ID, CODE, DESCRIPTION, PROBATION_AREA_ID, LOCAL_DELIVERY_UNIT_ID) VALUES (TEAM_ID_SEQ.NEXTVAL, 'N03TST', 'Another', (SELECT PROBATION_AREA_ID FROM PROBATION_AREA WHERE CODE = 'N03'), (SELECT LOCAL_DELIVERY_UNIT_ID FROM LOCAL_DELIVERY_UNIT WHERE CODE = 'LDU1'));
INSERT INTO TEAM (TEAM_ID, CODE, DESCRIPTION, PROBATION_AREA_ID, DISTRICT_ID)
VALUES (TEAM_ID_SEQ.NEXTVAL, 'N01TST', 'Test team', (SELECT PROBATION_AREA_ID FROM PROBATION_AREA WHERE CODE = 'N01'),
(SELECT DISTRICT_ID FROM DISTRICT WHERE CODE = 'LAU2'));
INSERT INTO TEAM (TEAM_ID, CODE, DESCRIPTION, PROBATION_AREA_ID, DISTRICT_ID)
VALUES (TEAM_ID_SEQ.NEXTVAL, 'N02TST', 'Other team', (SELECT PROBATION_AREA_ID FROM PROBATION_AREA WHERE CODE = 'N02'),
(SELECT DISTRICT_ID FROM DISTRICT WHERE CODE = 'LAU1'));
INSERT INTO TEAM (TEAM_ID, CODE, DESCRIPTION, PROBATION_AREA_ID, DISTRICT_ID)
VALUES (TEAM_ID_SEQ.NEXTVAL, 'N03TST', 'Another', (SELECT PROBATION_AREA_ID FROM PROBATION_AREA WHERE CODE = 'N03'),
(SELECT DISTRICT_ID FROM DISTRICT WHERE CODE = 'LAU1'));
INSERT INTO STAFF_TEAM (STAFF_ID, TEAM_ID) VALUES ((SELECT STAFF_ID FROM STAFF WHERE OFFICER_CODE = 'N01A001'), (SELECT TEAM_ID FROM TEAM WHERE CODE = 'N01TST' AND END_DATE IS NULL));
INSERT INTO STAFF_TEAM (STAFF_ID, TEAM_ID) VALUES ((SELECT STAFF_ID FROM STAFF WHERE OFFICER_CODE = 'N01A002'), (SELECT TEAM_ID FROM TEAM WHERE CODE = 'N01TST' AND END_DATE IS NULL));
INSERT INTO STAFF_TEAM (STAFF_ID, TEAM_ID) VALUES ((SELECT STAFF_ID FROM STAFF WHERE OFFICER_CODE = 'N01A003'), (SELECT TEAM_ID FROM TEAM WHERE CODE = 'N01TST' AND END_DATE IS NULL));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import static java.time.LocalDate.now;
import static java.time.format.DateTimeFormatter.ISO_LOCAL_DATE;
import static java.time.temporal.ChronoUnit.DAYS;
import static org.hamcrest.Matchers.*;
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.asyncDispatch;
Expand Down Expand Up @@ -188,14 +187,14 @@ public void fullExportIsRestrictedToNationalAdmins() throws Exception {

@Test
public void dataIsDisplayedCorrectlyForFullExport() throws Exception {
String expectedHeader = "\"Username\",\"Forenames\",\"Surname\",\"Email\",\"Telephone Number\",\"Start Date\",\"End Date\",\"Last Accessed Delius\",\"Home Area\",\"Datasets\",\"Sector\",\"Staff Code\",\"Staff Grade\",\"Team\",\"LAU\",\"PDU\",\"Provider\",\"Role Descriptions\"";
String expectedStartDate = now().minus(10, DAYS).format(ISO_LOCAL_DATE);
String expectedHeader = "\"Username\",\"Forenames\",\"Surname\",\"Email\",\"Telephone Number\",\"Start Date\",\"End Date\",\"Last Accessed Delius\",\"Home Area\",\"Datasets\",\"Sector\",\"Staff Code\",\"Staff Grade\",\"Team\",\"LAU\",\"PDU\",\"Provider\",\"Role Names\"";
String expectedStartDate = now().minusDays(10).format(ISO_LOCAL_DATE);
String expectedLoginDate = now().format(ISO_LOCAL_DATE);// see data.sql
String[] expectedUsers = {
"\n\"Abdul.Austria\",\"Abdul\",\"Austria\",\"\",\"\",\"" + expectedStartDate + "\",\"\",\"\",\"N01\",\"\",\"Public\",\"N01A168\",\"GRADE1\",\"\",\"\",\"\",\"\",\"\"",
"\n\"Leia.Leaman\",\"Leia\",\"Leaman\",\"\",\"\",\"" + expectedStartDate + "\",\"\",\"\",\"N01\",\"\",\"Public\",\"N01A086\",\"GRADE1\",\"\",\"\",\"\",\"\",\"\"",
"\n\"Zina.Zenon\",\"Zina\",\"Zenon\",\"\",\"\",\"" + expectedStartDate + "\",\"\",\"\",\"N01\",\"\",\"Public\",\"N01A131\",\"GRADE1\",\"\",\"\",\"\",\"\",\"\"",
"\n\"test.user\",\"Test\",\"User\",\"[email protected]\",\"0123 456 789\",\"2000-01-02\",\"\",\"" + expectedLoginDate + " 00:00:00\",\"N01\",\"N01,N02,N03\",\"Public\",\"N01A001\",\"GRADE1\",\"Another (N03TST) [Active],Other team (N02TST) [Active],Test team (N01TST) [Active]\",\"Local Delivery Unit A (LDU1) [Active]\",\"Borough A (B1) [Active],Borough B (B2) [Active]\",\"NPS London (N01) [Active],NPS North East (N02) [Active]\",\"APBT001,APBT002,RDBT001,SPGADBT005,UABT0050,UMBT001\"",
"\n\"test.user\",\"Test\",\"User\",\"[email protected]\",\"0123 456 789\",\"2000-01-02\",\"\",\"" + expectedLoginDate + " 00:00:00\",\"N01\",\"N01,N02,N03\",\"Public\",\"N01A001\",\"GRADE1\",\"Another (N03TST),Other team (N02TST),Test team (N01TST)\",\"Local Admin Unit A (LAU1),Local Admin Unit B (LAU2)\",\"Borough A (B1) [Inactive],Borough B (B2)\",\"NPS London (N01),NPS North East (N02)\",\"APBT001,APBT002,RDBT001,SPGADBT005,UABT0050,UMBT001,UMBT003\"",
"\n\"test.user.private\",\"Test\",\"User (Private)\",\"[email protected]\",\"\",\"\",\"\",\"" + expectedLoginDate + " 00:00:00\",\"C01\",\"C01,C02\",\"Public\",\"\",\"\",\"\",\"\",\"\",\"\",\"UABT0052,UMBT001\""};

MvcResult asyncResult = mvc.perform(get("/api/users/export/all")
Expand Down

0 comments on commit 1fb5733

Please sign in to comment.