
se.kth.iss.ug2.test.UgObjectTestData Maven / Gradle / Ivy
/*
* MIT License
*
* Copyright (c) 2017 Kungliga Tekniska högskolan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package se.kth.iss.ug2.test;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import se.kth.iss.ug2.Ug2Exception;
import se.kth.iss.ug2.Ug2Protocol;
import se.kth.iss.ug2.UgObject;
public class UgObjectTestData {
public static UgObject createGroup(String kthid, String ug1name, List members) throws Ug2Exception {
if (members == null) {
members = new LinkedList<>();
}
HashMap> values = createValuesMap(kthid, ug1name,
members, null);
return new UgObject("group", kthid, values, TestSchema.createSchema());
}
private static HashMap> createValuesMap(String kthid,
String ug1name, List members, List group_members) {
if (members == null) {
members = new LinkedList<>();
}
if (group_members == null) {
group_members = new LinkedList<>();
}
HashMap> values = new HashMap<>();
values.put("kthid", Arrays.asList(kthid));
values.put("ug1name", Arrays.asList(ug1name));
values.put("member", members);
values.put("group_member", group_members);
values.put("email_alias", Arrays.asList(new String[]{}));
return values;
}
public static UgObject createGroup(String kthid, String ug1name, List members, List group_members)
throws Ug2Exception {
HashMap> values = createValuesMap(kthid, ug1name,
members, group_members);
return new UgObject("group", kthid, values, TestSchema.createSchema());
}
public static UgObject createUgUser1() throws Ug2Exception {
return createUserUgObject("u1foobar", "Kalle",
"Anka", "kalle", Arrays.asList("101010"));
}
public static UgObject createUgUser2() throws Ug2Exception {
return createUserUgObject("u1foobaz", "Nisse",
"Tuta", "nisse", Arrays.asList("101010"));
}
public static UgObject createUgUser3() throws Ug2Exception {
return createUserUgObject("u1foobat", "Ture",
"Teknolog", "ture", Arrays.asList("101010"),
Arrays.asList("turet"), "[email protected]",
"[email protected]", null, null);
}
public static UgObject createUgUser4() throws Ug2Exception {
return createUserUgObject("u1foobas", "Ture",
"Meterolog", "turem", Arrays.asList("101010"),
Arrays.asList("turemet", "turemt"), "[email protected]",
"[email protected]", null, null);
}
public static UgObject createUgUser5() throws Ug2Exception {
return createUserUgObject("u1foobaq", "Jan",
"Bananberg", "janb", Arrays.asList("101010"),
Arrays.asList("janbanan", "jbananberg"), "[email protected]",
"[email protected]", null, null);
}
public static UgObject createUgUser(String kthid, String given, String family, String username) throws Ug2Exception {
return createUserUgObject(kthid, given, family, username, Arrays.asList("101010"));
}
public static UgObject createGroupUgObject(String kthid,
String name, String parent, List member) throws Ug2Exception {
HashMap> values = new HashMap<>();
values.put("kthid", Arrays.asList(kthid));
values.put("ug1name", Arrays.asList(name));
values.put("name_sv", Arrays.asList(new String[]{}));
values.put("name_en", Arrays.asList(new String[]{}));
values.put("member", member);
values.put("parent", Arrays.asList(parent));
return new UgObject("group", kthid, values, TestSchema.createSchema());
}
public static UgObject createUserUgObject(String kthid,
String given, String fam, String user, List personnummer) throws Ug2Exception {
List alias = Arrays.asList(new String[]{});
return createUserUgObject(kthid, given, fam, user, personnummer, alias, null, null, null, null);
}
public static UgObject createUserUgObject(String kthid, String given,
String fam, String user, List personnummer,
List alias, String email, String forward,
List kthid_search, List groups) throws Ug2Exception {
return createUserUgObject(kthid, given, fam, user, personnummer, alias,
email, forward, kthid_search, groups, "", null);
}
public static UgObject createUserUgObject(String kthid, String given,
String fam, String user, List personnummer,
List alias, String email, String forward, List kthid_search,
List groups, String primaryAffiliation,
List services) throws Ug2Exception {
if (kthid_search == null) {
kthid_search = new LinkedList<>();
kthid_search.add(kthid);
}
if (groups == null) {
groups = new LinkedList<>();
}
if (alias == null) {
alias = new LinkedList<>();
}
if (personnummer == null) {
personnummer = new LinkedList<>();
personnummer.add("");
}
if (services == null) {
services = new LinkedList<>();
}
HashMap> values = new HashMap<>();
values.put("kthid", Arrays.asList(kthid));
values.put("given_name", Arrays.asList(given));
values.put("family_name", Arrays.asList(fam));
values.put("username", Arrays.asList(user));
values.put(Ug2Protocol.ATTR_PERSONNUMMER, personnummer.subList(0, 1));
values.put("personnummer_search", personnummer);
values.put("autoname", Arrays.asList(new String[]{}));
values.put("email_forward", Arrays.asList(forward));
values.put("phone_hr", Arrays.asList(new String[]{}));
values.put("email_address", Arrays.asList(email));
values.put(Ug2Protocol.ATTR_KTHID_SEARCH, kthid_search);
values.put("alias", alias);
values.put("services", services);
values.put("primary_affiliation", Arrays.asList(primaryAffiliation));
values.put(UgObject.USERGROUPPSEUDOATTRIBUTE, groups);
return new UgObject("user", kthid, values, TestSchema.createSchema());
}
public static UgObject createUgUser6() throws Ug2Exception {
return createUserUgObject("u1qwerty",
"Malle", "Medlem", "malle", Arrays
.asList("101010"),
new LinkedList<>(), "[email protected]", "[email protected]",
new LinkedList<>(), Arrays.asList("app.pa.foo", "app.pa.bar")
);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy