001/* 002 * Copyright 2023 the original author or authors. 003 * <p> 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * <p> 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * <p> 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package de.cuioss.test.generator.domain; 017 018import static de.cuioss.test.generator.Generators.fixedValues; 019import static de.cuioss.test.generator.Generators.integers; 020 021import java.util.ArrayList; 022import java.util.List; 023 024import de.cuioss.test.generator.TypedGenerator; 025import de.cuioss.tools.string.Joiner; 026 027/** 028 * Generates formally correct Distinguished Names 029 * 030 * @author Oliver Wolff 031 * 032 */ 033public class DistinguishedNamesGenerator implements TypedGenerator<String> { 034 035 private final TypedGenerator<String> prefixes = fixedValues("ou", "o", "dc"); 036 private final TypedGenerator<String> values = fixedValues("proxies", "ID", "dc", "accounts", "groups", "roles", 037 "services"); 038 039 @Override 040 public String next() { 041 List<String> elements = new ArrayList<>(); 042 int count = integers(2, 12).next(); 043 for (var i = 0; i < count; i++) { 044 elements.add(prefixes.next() + "=" + values.next()); 045 } 046 return Joiner.on(',').join(elements); 047 } 048 049 @Override 050 public Class<String> getType() { 051 return String.class; 052 } 053}