/
SamlTestScenary.java
77 lines (66 loc) · 2.7 KB
/
SamlTestScenary.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* oxTrust is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text.
*
* Copyright (c) 2018, Gluu
*/
package org.gluu.oxtrust.api.test.saml;
import java.util.List;
import java.util.Random;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.gluu.oxtrust.api.client.Client;
import org.gluu.oxtrust.api.client.saml.TrustRelationshipClient;
import org.gluu.oxtrust.api.saml.SAMLTrustRelationshipShort;
import org.gluu.oxtrust.api.test.APITestException;
import org.gluu.oxtrust.model.GluuMetadataSourceType;
import org.gluu.oxtrust.model.GluuSAMLTrustRelationship;
/**
* SAML-relater test requests.
*
* @author Dmitry Ognyannikov
*/
public class SamlTestScenary {
private static final Logger logger = LogManager.getLogger(SamlTestScenary.class);
private final Client client;
public SamlTestScenary(Client client) {
this.client = client;
}
private Random random = new Random();
/**
* Run tests.
*/
public void run() throws APITestException {
TrustRelationshipClient samlClient = client.getTrustRelationshipClient();
GluuSAMLTrustRelationship trGenerated = generateRandomeSingleTrustRelationship();
// test create()
String inum = samlClient.create(trGenerated);
// test read()
GluuSAMLTrustRelationship trReaded = samlClient.read(inum);
//TODO: compare
trReaded.setDescription("description changed");
// test read()
samlClient.update(trReaded, inum);
// test list()
List<SAMLTrustRelationshipShort> trustRelationships = samlClient.list();
if (!checkListForTrustRelationship(trustRelationships, inum))
throw new APITestException("TrustRelationship really not saved");
//TODO
}
private GluuSAMLTrustRelationship generateRandomeSingleTrustRelationship() {
int randTestNumber = Math.abs(random.nextInt());
GluuSAMLTrustRelationship tr = new GluuSAMLTrustRelationship();
tr.setDisplayName("test_TrustRelationship_#" + randTestNumber);
tr.setDescription("test TrustRelationship #" + randTestNumber);
tr.setSpMetaDataSourceType(GluuMetadataSourceType.FILE);
tr.setUrl("https://ce.gluu.info");
tr.setSpMetaDataFN("38CBAF15F4E4708200029736F2AB0006BF5CFB85-sp-metadata.xml");
return tr;
}
private boolean checkListForTrustRelationship(List<SAMLTrustRelationshipShort> trustRelationships, String inum) {
for (SAMLTrustRelationshipShort tr : trustRelationships) {
if (inum.equals(tr.getInum()))
return true;
}
return false;
}
}