Skip to content

Commit

Permalink
Merge pull request #34 from indiana-university/LMSA-9344_unit_tests
Browse files Browse the repository at this point in the history
Lmsa 9344 unit tests
  • Loading branch information
dsobiera authored Sep 12, 2024
2 parents 2a3cd3f + 701472e commit b1a19bb
Show file tree
Hide file tree
Showing 7 changed files with 912 additions and 911 deletions.
11 changes: 9 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.15</version>
<version>2.7.18</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

Expand Down Expand Up @@ -62,8 +62,9 @@
<jdk.source>17</jdk.source>
<jdk.target>17</jdk.target>
<jquery.version>3.7.1</jquery.version>
<jsoup.version>1.18.1</jsoup.version>
<lms-canvas-rivet.version>5.2.5.2</lms-canvas-rivet.version>
<lms-embedded-services.version>5.2.17</lms-embedded-services.version>
<lms-embedded-services.version>5.2.42</lms-embedded-services.version>
<lms-team-spring-boot-it12>4.8</lms-team-spring-boot-it12>
<spring-cloud.version>2021.0.8</spring-cloud.version>
<webjars-locator.version>0.47</webjars-locator.version>
Expand Down Expand Up @@ -141,6 +142,12 @@
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>${jsoup.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
Expand Down Expand Up @@ -223,8 +224,6 @@ public String main(@PathVariable("courseId") String courseId, Model model, HttpS

String currentUserId = impersonationModel.getUsername() == null ? oidcTokenUtils.getUserLoginId() : impersonationModel.getUsername();

Comparator<CanvasTerm> termStartDateComparator = crosslistService.getTermStartDateComparator();

Course currentCourse = getValidatedCourse(token, session);

CanvasTerm currentTerm = currentCourse.getTerm();
Expand Down Expand Up @@ -275,7 +274,7 @@ public String main(@PathVariable("courseId") String courseId, Model model, HttpS
}

// sort it!
selectableTerms.sort(termStartDateComparator);
Collections.sort(selectableTerms);

// =============================================================================
// thread start
Expand All @@ -289,7 +288,7 @@ public String main(@PathVariable("courseId") String courseId, Model model, HttpS
int count = 0;
for (CanvasTerm canvasTerm : selectableTerms) {
if (++count <= MAX_BACKGROUND_LOADS &&
termStartDateComparator.compare(canvasTerm, currentTerm) < 1) {
canvasTerm.compareTo(currentTerm) < 1) {
log.debug("***** thread(" + threadId + ") for termId = " + canvasTerm.getId() + " " + canvasTerm.getName());
List<Course> threadUserCourses = crosslistService.getCoursesTaughtBy(currentUserId, false);
threadUserCourses = threadUserCourses.stream().filter(c -> c.getEnrollmentTermId() != null && c.getEnrollmentTermId().equals(canvasTerm.getId())).collect(Collectors.toList());
Expand Down Expand Up @@ -323,7 +322,7 @@ public String main(@PathVariable("courseId") String courseId, Model model, HttpS
}

Map<CanvasTerm, List<SectionUIDisplay>> sectionsMap =
crosslistService.buildSectionsMap(courses, termMap, termStartDateComparator, currentCourse,
crosslistService.buildSectionsMap(courses, termMap, currentCourse,
impersonationModel.isIncludeNonSisSections(), impersonationModel.isIncludeCrosslistedSections(),
impersonationModel.getUsername() != null || impersonationModel.isSelfMode(),
true);
Expand All @@ -342,8 +341,6 @@ public String main(@PathVariable("courseId") String courseId, Model model, HttpS
@Secured({LTIConstants.ADMIN_AUTHORITY, LTIConstants.INSTRUCTOR_AUTHORITY})
public String doContinue(@PathVariable("courseId") String courseId, @RequestParam("sectionList") String sectionListJson,
Model model, HttpSession session) {
Comparator<CanvasTerm> termStartDateComparator = crosslistService.getTermStartDateComparator();

List<SectionUIDisplay> sectionList = null;
try {
sectionList = Arrays.asList(objectMapper.readValue(sectionListJson, SectionUIDisplay[].class));
Expand All @@ -352,7 +349,7 @@ public String doContinue(@PathVariable("courseId") String courseId, @RequestPara
}

// Rebuild the map in case the user clicks Edit
Map<CanvasTerm,List<SectionUIDisplay>> rebuiltTermMap = new TreeMap<>(termStartDateComparator);
Map<CanvasTerm,List<SectionUIDisplay>> rebuiltTermMap = new TreeMap<>();

// get the list of terms in Canvas
List<CanvasTerm> terms = termService.getEnrollmentTerms();
Expand Down Expand Up @@ -594,7 +591,6 @@ public String doTermLoad(@PathVariable("courseId") String courseId, @PathVariabl
OidcAuthenticationToken token = getValidatedToken(courseId, courseSessionService);
OidcTokenUtils oidcTokenUtils = new OidcTokenUtils(token);
Course currentCourse = getValidatedCourse(token, session);
Comparator<CanvasTerm> termStartDateComparator = crosslistService.getTermStartDateComparator();

boolean featureEnabled = crosslistService.checkForFeature(session, currentCourse, FEATURE_MULTITERM_CROSSLISTING);
if (featureEnabled) {
Expand All @@ -621,7 +617,7 @@ public String doTermLoad(@PathVariable("courseId") String courseId, @PathVariabl
collapsedTermsList = Arrays.asList(collapsedTerms.split(","));
}

Map<CanvasTerm,List<SectionUIDisplay>> rebuiltTermMap = new TreeMap<>(termStartDateComparator);
Map<CanvasTerm,List<SectionUIDisplay>> rebuiltTermMap = new TreeMap<>();

// get the list of terms in Canvas
List<CanvasTerm> terms = termService.getEnrollmentTerms();
Expand Down Expand Up @@ -663,7 +659,6 @@ public String doTermLoad(@PathVariable("courseId") String courseId, @PathVariabl
Map<CanvasTerm, List<SectionUIDisplay>> sections = crosslistService.buildSectionsMap(
courses,
termMap,
termStartDateComparator,
currentCourse,
impersonationModel.isIncludeNonSisSections(),
impersonationModel.isIncludeCrosslistedSections(),
Expand Down Expand Up @@ -712,7 +707,6 @@ public String doUnavailableSectionsLoad(@PathVariable("courseId") String courseI
OidcAuthenticationToken token = getValidatedToken(courseId, courseSessionService);
OidcTokenUtils oidcTokenUtils = new OidcTokenUtils(token);
Course currentCourse = getValidatedCourse(token, session);
Comparator<CanvasTerm> termStartDateComparator = crosslistService.getTermStartDateComparator();

ImpersonationModel impersonationModel = courseSessionService.getAttributeFromSession(session, courseId,
CrosslistAuthenticationToken.IMPERSONATION_DATA_KEY, ImpersonationModel.class);
Expand Down Expand Up @@ -743,7 +737,6 @@ public String doUnavailableSectionsLoad(@PathVariable("courseId") String courseI
Map<CanvasTerm, List<SectionUIDisplay>> sections = crosslistService.buildSectionsMap(
courses,
termMap,
termStartDateComparator,
currentCourse,
impersonationModel.isIncludeNonSisSections(),
impersonationModel.isIncludeCrosslistedSections(),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
@Slf4j
public class CrosslistService {

public final String ALIEN_SECTION_BLOCKED_FAKE_CANVAS_TERM_STRING = "ALIEN_SECTION_BLOCKED";
public final static String ALIEN_SECTION_BLOCKED_FAKE_CANVAS_TERM_STRING = "ALIEN_SECTION_BLOCKED";

@Autowired
private CourseService courseService = null;
Expand Down Expand Up @@ -105,15 +105,14 @@ public class CrosslistService {

public Map<CanvasTerm, List<SectionUIDisplay>> buildSectionsMap(List<Course> courses,
Map<String,CanvasTerm> termMap,
Comparator<CanvasTerm> termStartDateComparator,
Course currentCourse,
boolean includeNonSisSections,
boolean includeSectionsCrosslistedElsewhere,
boolean impersonationMode,
boolean useCachedSections) {
// This map will contain the CanvasTerm for the key and a List<SectionUIDisplay> for the value
// The TreeMap with comparator will add new entries to the map in a sorted order
Map<CanvasTerm,List<SectionUIDisplay>> sectionsMap = new TreeMap<>(termStartDateComparator);
Map<CanvasTerm,List<SectionUIDisplay>> sectionsMap = new TreeMap<>();

// One should only get possible section results if it is an SIS course that the tool was launched from.
// If the launched course is manually created, one should only get possible sections IF
Expand Down Expand Up @@ -312,10 +311,6 @@ public Map<CanvasTerm, List<SectionUIDisplay>> buildSectionsMap(List<Course> cou
return sectionsMap;
}

public Comparator<CanvasTerm> getTermStartDateComparator() {
return new CanvasTermComparator();
}

// Don't change this cache key unless you also change how evict works in the CrosslistController
@Cacheable(value = CrosslistConstants.COURSES_TAUGHT_BY_CACHE_NAME, key = "#IUNetworkId + '-' + #excludeBlueprint")
public List<Course> getCoursesTaughtBy(String IUNetworkId, boolean excludeBlueprint) {
Expand Down Expand Up @@ -348,7 +343,7 @@ public boolean checkForFeature(HttpSession session, Course currentCourse, String
* Gets dummy term for terms crosslisted into a course that aren't their natural course
* @return The CanvasTerm
*/
public CanvasTerm getAlienBlockedCanvasTerm() {
public static CanvasTerm getAlienBlockedCanvasTerm() {
CanvasTerm alienSectionBlockedFakeCanvasTerm = new CanvasTerm();
alienSectionBlockedFakeCanvasTerm.setId(ALIEN_SECTION_BLOCKED_FAKE_CANVAS_TERM_STRING);
alienSectionBlockedFakeCanvasTerm.setName(ALIEN_SECTION_BLOCKED_FAKE_CANVAS_TERM_STRING);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/confirmation.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ <h2 class="rvt-ts-26" th:text="${courseTitle}">SP16-BL-MUS-A112-15890 - A112 (On
with which the section was originally associated and will no longer be visible to you.
</p>
</div>
<div th:if="${missingEtextSections}" class="rvt-alert rvt-alert--danger rvt-m-tb-md" role="alert"
<div th:if="${missingEtextSections}" id="missing-etext-sections-message" class="rvt-alert rvt-alert--danger rvt-m-tb-md" role="alert"
aria-labelledby="error-alert-title" data-rvt-alert="error">
<div class="rvt-alert__title" id="error-alert-title">Cross-listing Error</div>
<p id="error-review" class="rvt-alert__message">
Expand Down
Loading

0 comments on commit b1a19bb

Please sign in to comment.