Skip to content

Commit

Permalink
CU-86b1uerqp_Generar-un-enum-de-MTs-para-validar-sus-secuencias-y-paths
Browse files Browse the repository at this point in the history
  • Loading branch information
ptorres-prowide committed Nov 15, 2024
1 parent bc7f305 commit 77b05a1
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 91 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Prowide Core - CHANGELOG

#### 9.4.19 - SNAPSHOT
* Added new `MtSequenceEnum` with all the available inner sequences of specific MT schemas

#### 9.4.18 - October 2024
* Added new `FieldEnum` with all the available field names
* Code security improvements as per CodeQL recommendations
* Added new `MtSequenceInfoEnum` with all the available inner sequences of specific MT schemas

#### 9.4.17 - June 2024
* (PW-1913) Added IBAN validation for Egypt local account structure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* @since 9.4.18
*/
@Generated
public enum MtSequenceInfoEnum {
public enum MtSequenceEnum {

MT101("A,B"),
MT102("A,B,C"),
Expand Down Expand Up @@ -121,10 +121,10 @@ public enum MtSequenceInfoEnum {
MT760("A,B,C"),
MT767("A,B,C");

private final String sequencesInfo;
private final String sequences;

MtSequenceInfoEnum(String sequencesInfo) {
this.sequencesInfo = sequencesInfo;
MtSequenceEnum(String sequences) {
this.sequences = sequences;
}

/**
Expand All @@ -134,8 +134,8 @@ public enum MtSequenceInfoEnum {
* @return A Set of sequence paths.
*
*/
public Set<String> sequencesInfo() {
return Arrays.stream(sequencesInfo.split(","))
public Set<String> sequences() {
return Arrays.stream(sequences.split(","))
.collect(Collectors.toSet());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.prowidesoftware.swift.model.mt;

import static org.junit.jupiter.api.Assertions.*;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.junit.jupiter.api.Test;

class MtSequenceEnumTest {

private static final String SEQUENCE_PATTERN = "^[A-Z](?:/[A-Z][0-9]?(?:[a-z][0-9]?[A-Za-z0-9]*)?)*$";

@Test
void testGetSequences_MT101() {
MtSequenceEnum sequence = MtSequenceEnum.MT101;
Set<String> expectedSequences = new HashSet<>(Arrays.asList("A", "B"));
assertEquals(expectedSequences, sequence.sequences());
}

@Test
void testGetSequences_MT102() {
MtSequenceEnum sequence = MtSequenceEnum.MT102;
Set<String> expectedSequences = new HashSet<>(Arrays.asList("A", "B", "C"));
assertEquals(expectedSequences, sequence.sequences());
}

@Test
void testGetSequences_MT300() {
MtSequenceEnum sequence = MtSequenceEnum.MT300;
Set<String> expectedSequences = new HashSet<>(Arrays.asList(
"A", "B", "B/B1", "B/B2", "C", "D", "D/D1", "E", "E/E1", "E/E1/E1a", "E/E1/E1a/E1a1", "F"));
assertEquals(expectedSequences, sequence.sequences());
}

@Test
void testGetSequences_MT508() {
MtSequenceEnum sequence = MtSequenceEnum.MT508;
Set<String> expectedSequences = new HashSet<>(Arrays.asList("A", "A/A1", "B", "B/B1", "C"));
assertEquals(expectedSequences, sequence.sequences());
}

@Test
void testFromFieldNameValid_MT101() {
String fieldName = "MT101";
MtSequenceEnum expectedEnum = MtSequenceEnum.MT101;
assertEquals(expectedEnum, MtSequenceEnum.valueOf(fieldName));
}

@Test
void testFromFieldNameValid_MT102() {
String fieldName = "MT102";
MtSequenceEnum expectedEnum = MtSequenceEnum.MT102;
assertEquals(expectedEnum, MtSequenceEnum.valueOf(fieldName));
}

@Test
void testFromFieldNameValid_MT508() {
String fieldName = "MT508";
MtSequenceEnum expectedEnum = MtSequenceEnum.MT508;
assertEquals(expectedEnum, MtSequenceEnum.valueOf(fieldName));
}

@Test
void testFromFieldNameInvalid() {
assertThrows(NullPointerException.class, () -> MtSequenceEnum.valueOf(null));
assertThrows(IllegalArgumentException.class, () -> MtSequenceEnum.valueOf("INVALID"));
assertThrows(IllegalArgumentException.class, () -> MtSequenceEnum.valueOf(""));
assertThrows(IllegalArgumentException.class, () -> MtSequenceEnum.valueOf("MT"));
assertThrows(IllegalArgumentException.class, () -> MtSequenceEnum.valueOf("MT999999"));
assertThrows(IllegalArgumentException.class, () -> MtSequenceEnum.valueOf("MTxxx"));
}

@Test
void testAllEnumValuesHaveSequences() {
for (MtSequenceEnum seqValue : MtSequenceEnum.values()) {
String enumName = seqValue.name();
assertNotNull(seqValue.sequences(), String.format("Sequence for enum value '%s' is null", enumName));
assertFalse(
seqValue.sequences().isEmpty(),
String.format("Sequence for enum value '%s' is empty. Expected at least one sequence.", enumName));

// Validate sequence format
Set<String> sequences = seqValue.sequences();
for (String sequence : sequences) {
assertTrue(
sequence.matches(SEQUENCE_PATTERN),
String.format(
"Sequence '%s' in %s should match format: %s", sequence, enumName, SEQUENCE_PATTERN));
}

// Check for duplicates
Set<String> uniqueSequences = new HashSet<>(sequences);
assertEquals(
sequences.size(),
uniqueSequences.size(),
String.format("Sequences in %s contain duplicates: %s", enumName, sequences));
}
}
}

This file was deleted.

0 comments on commit 77b05a1

Please sign in to comment.