Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit eb786d94 authored by Mihai BOZ's avatar Mihai BOZ
Browse files

added method to generate random value from enum, resolved other PR comments

parent 87b6e2ae
No related branches found
No related tags found
No related merge requests found
Pipeline #83215 passed with warnings
package ddsl.enums;
import java.util.Random;
public enum ResourceTypes {
OASIS1("edelivery-oasis-smp-1.0-servicegroup (smp-1)"),
OASIS2("edelivery-oasis-smp-2.0-servicegroup (oasis-bdxr-smp-2)"),
OASIS3("edelivery-oasis-cppa-3.0-cpp (cpp)");
public String getName() {
return name;
}
public final String name;
......@@ -16,12 +18,5 @@ public enum ResourceTypes {
}
public static String getRandomResourceType() {
ResourceTypes[] resourceTypes = values();
int size = resourceTypes.length;
Random random = new Random();
int index = random.nextInt(size);
return resourceTypes[index].name;
}
}
package ddsl.enums;
import java.util.Random;
public enum ResponseCertificates {
SMP_DOMAIN_02("smp_domain_02 (CN=smp_domain_02,O=digit,C=eu:000000006443d987)"),
SMP_EDDSA_448("smp_eddsa_448 (CN=smp_eddsa_448,O=digit,C=eu:000000006443fcba)"),
......@@ -10,6 +8,10 @@ public enum ResponseCertificates {
SAMPLE_KEY("sample_key (CN=demo-smp-signing-key,O=digit,C=eu:000000006443f9bc)"),
SMP_EDDSA_25519("smp_eddsa_25519 (CN=smp_eddsa_25519,O=digit,C=eu:000000006443d95d)");
public String getName() {
return name;
}
public final String name;
......@@ -17,19 +19,5 @@ public enum ResponseCertificates {
this.name = name;
}
public static String getRandomCertificate() {
ResponseCertificates[] certificates = values();
int size = certificates.length;
Random random = new Random();
int index = random.nextInt(size);
return certificates[index].name;
}
public static String getRandomCertificateWithSML() {
ResponseCertificates[] certificates = {SMP_DOMAIN_01, SMP_DOMAIN_02};
Random random = new Random();
int index = random.nextInt(2);
return certificates[index].name;
}
}
......@@ -22,14 +22,12 @@ public class SmlPage extends DComponent {
}
public boolean isDomainRegistered(DomainModel domainModel) {
String dnsRecord = domainModel.getSmlSmpId();
for (WebElement element : dnsRecords) {
String dnsRecord = domainModel.getSmlSmpId();
String elementRecords = element.getText();
if (elementRecords.contains(dnsRecord)) {
return true;
}
return false;
return elementRecords.contains(dnsRecord);
}
return false;
}
......
......@@ -2,6 +2,10 @@ package rest.models;
import ddsl.enums.ResponseCertificates;
import utils.Generator;
import utils.Utils;
import static ddsl.enums.ResponseCertificates.SMP_DOMAIN_01;
import static ddsl.enums.ResponseCertificates.SMP_DOMAIN_02;
public class DomainModel {
......@@ -22,7 +26,7 @@ public class DomainModel {
public static DomainModel generatePublicDomainModelWithoutSML() {
DomainModel domainModel = new DomainModel();
domainModel.domainCode = "AUTDom" + Generator.randomAlphaNumeric(6);
domainModel.signatureKeyAlias = ResponseCertificates.getRandomCertificate();
domainModel.signatureKeyAlias = Utils.randomEnum(ResponseCertificates.values()).getName();
domainModel.visibility = "PUBLIC";
return domainModel;
}
......@@ -30,12 +34,12 @@ public class DomainModel {
public static DomainModel generatePublicDomainModelWithSML() {
DomainModel domainModel = new DomainModel();
domainModel.domainCode = "AUTDom" + Generator.randomAlphaNumeric(6);
domainModel.signatureKeyAlias = ResponseCertificates.getRandomCertificateWithSML();
domainModel.signatureKeyAlias = Utils.randomEnum(new ResponseCertificates[]{SMP_DOMAIN_01, SMP_DOMAIN_02}).getName();
domainModel.visibility = "PUBLIC";
domainModel.smlClientCertAuth = true;
domainModel.smlSubdomain = "AUTDomSML" + Generator.randomAlphaNumeric(6);
domainModel.smlSmpId = "AUTSMLSMP" + Generator.randomAlphaNumeric(4);
domainModel.smlClientKeyAlias = ResponseCertificates.getRandomCertificateWithSML();
domainModel.smlClientKeyAlias = Utils.randomEnum(new ResponseCertificates[]{SMP_DOMAIN_01, SMP_DOMAIN_02}).getName();
return domainModel;
}
......
......@@ -12,4 +12,6 @@ public class Generator {
return builder.toString();
}
}
package utils;
import java.util.Random;
public class Utils {
public static <T extends Enum<?>> T randomEnum(T[] values) {
int x = new Random().nextInt(values.length);
return values[x];
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment