001/* 002 * Copyright © 2025 CUI-OpenSource-Software (info@cuioss.de) 003 * 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 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 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.impl; 017 018import de.cuioss.test.generator.Generators; 019import de.cuioss.test.generator.TypedGenerator; 020 021import java.net.MalformedURLException; 022import java.net.URI; 023import java.net.URL; 024 025/** 026 * Generates valid {@link URL} instances from a predefined set of well-known websites. 027 * 028 * <p>URL characteristics:</p> 029 * <ul> 030 * <li>All URLs are valid and accessible</li> 031 * <li>Mix of HTTP and HTTPS protocols</li> 032 * <li>Includes popular tech, development, and reference sites</li> 033 * </ul> 034 * 035 * <p>Available domains include:</p> 036 * <ul> 037 * <li>Development: github.com, gitlab.com, sonarcloud.io</li> 038 * <li>Technology: heise.de, stackoverflow.com</li> 039 * <li>Reference: wikipedia.org, mozilla.org</li> 040 * <li>Corporate: microsoft.com, apple.com, x-tention.com</li> 041 * </ul> 042 * 043 * <p><em>Example usage:</em></p> 044 * <pre> 045 * var generator = new URLGenerator(); 046 * URL url = generator.next(); // Returns a random URL from the predefined set 047 * </pre> 048 * 049 * <p>Note: While the generator ensures syntactically correct URLs, 050 * it does not guarantee that the URLs are currently reachable.</p> 051 * 052 * @author Oliver Wolff 053 * @see URL 054 */ 055public class URLGenerator implements TypedGenerator<URL> { 056 057 private static final TypedGenerator<String> generator = Generators.fixedValues(String.class, "https://www.heise.de", 058 "https://stackoverflow.com", "https://github.com/cuioss", "https://www.gitlab.com", "https://sonarcloud.io", 059 "https://www.eclipse.org", "https://www.sesamestreet.org/", "https://de.wikipedia.org", 060 "https://www.xing.com", "https://www.mozilla.org", "https://avm.de/", "https://www.primefaces.org/", 061 "http://getbootstrap.com", "https://x-tention.com", "https://www.microsoft.com", "https://www.apple.com", 062 "https://www.android.com"); 063 064 @Override 065 public URL next() { 066 try { 067 return URI.create(generator.next()).toURL(); 068 } catch (final MalformedURLException e) { 069 throw new IllegalStateException(e); 070 } 071 } 072 073 @Override 074 public Class<URL> getType() { 075 return URL.class; 076 } 077 078}